consensus_simulation.sh 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/bin/bash
  2. # Simulation of the consensus network for n(>2) nodes.
  3. nodes=4
  4. # moving one folder up
  5. cd ..
  6. # compiling bin
  7. make BINS=darkfid2
  8. # PIDs array
  9. pids=()
  10. # Starting node 0 (seed) in background
  11. ./darkfid2 \
  12. --consensus \
  13. --consensus-p2p-accept 127.0.0.1:6000 \
  14. --consensus-p2p-external 127.0.0.1:6000 \
  15. --database ./tmp/node0/blockchain \
  16. --rpc-listen tcp://127.0.0.1:6010 \
  17. --sync-p2p-accept 127.0.0.1:6020 \
  18. --sync-p2p-external 127.0.0.1:6020 \
  19. --wallet-path ./tmp/node0/wallet.db \
  20. -g 1650887115 &
  21. pids[${#pids[@]}]=$!
  22. # Waiting for seed to setup
  23. sleep 20
  24. # Starting nodes 1 till second to last node in background
  25. bound=$(($nodes-2))
  26. for i in $(eval echo "{1..$bound}")
  27. do
  28. ./darkfid2 \
  29. --consensus \
  30. --consensus-seed 127.0.0.1:6000 \
  31. --sync-seed 127.0.0.1:6020 \
  32. --consensus-p2p-accept 127.0.0.1:600$i \
  33. --consensus-p2p-external 127.0.0.1:600$i \
  34. --database ./tmp/node$i/blockchain \
  35. --rpc-listen tcp://127.0.0.1:601$i \
  36. --sync-p2p-accept 127.0.0.1:602$i \
  37. --sync-p2p-external 127.0.0.1:602$i \
  38. --wallet-path ./tmp/node$i/wallet.db \
  39. -g 1650887115 &
  40. pids[${#pids[@]}]=$!
  41. # waiting for node to setup
  42. sleep 20
  43. done
  44. # Trap kill signal
  45. trap ctrl_c INT
  46. # On kill signal, terminate background node processes
  47. function ctrl_c() {
  48. for pid in ${pids[@]}
  49. do
  50. kill $pid
  51. done
  52. }
  53. bound=$(($nodes-1))
  54. # Starting last node
  55. ./darkfid2 \
  56. --consensus \
  57. --consensus-seed 127.0.0.1:6000 \
  58. --sync-seed 127.0.0.1:6020 \
  59. --consensus-p2p-accept 127.0.0.1:600$bound \
  60. --consensus-p2p-external 127.0.0.1:600$bound \
  61. --database ./tmp/node$bound/blockchain \
  62. --rpc-listen tcp://127.0.0.1:601$bound \
  63. --sync-p2p-accept 127.0.0.1:602$bound \
  64. --sync-p2p-external 127.0.0.1:602$bound \
  65. --wallet-path ./tmp/node$bound/wallet.db \
  66. -g 1650887115