consensus_simulation.sh 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. LOG_TARGETS="!sled,!net" ./darkfid2 \
  12. -v \
  13. --consensus \
  14. --consensus-p2p-accept 127.0.0.1:6000 \
  15. --consensus-p2p-external 127.0.0.1:6000 \
  16. --database ./tmp/node0/blockchain \
  17. --rpc-listen tcp://127.0.0.1:6010 \
  18. --sync-p2p-accept 127.0.0.1:6020 \
  19. --sync-p2p-external 127.0.0.1:6020 \
  20. --wallet-path ./tmp/node0/wallet.db \
  21. -g 1650887115 &
  22. pids[${#pids[@]}]=$!
  23. # Waiting for seed to setup
  24. sleep 20
  25. # Starting nodes 1 till second to last node in background
  26. bound=$(($nodes-2))
  27. for i in $(eval echo "{1..$bound}")
  28. do
  29. LOG_TARGETS="!sled,!net" ./darkfid2 \
  30. -v \
  31. --consensus \
  32. --consensus-seed 127.0.0.1:6000 \
  33. --sync-seed 127.0.0.1:6020 \
  34. --consensus-p2p-accept 127.0.0.1:600$i \
  35. --consensus-p2p-external 127.0.0.1:600$i \
  36. --database ./tmp/node$i/blockchain \
  37. --rpc-listen tcp://127.0.0.1:601$i \
  38. --sync-p2p-accept 127.0.0.1:602$i \
  39. --sync-p2p-external 127.0.0.1:602$i \
  40. --wallet-path ./tmp/node$i/wallet.db \
  41. -g 1650887115 &
  42. pids[${#pids[@]}]=$!
  43. # waiting for node to setup
  44. sleep 20
  45. done
  46. # Trap kill signal
  47. trap ctrl_c INT
  48. # On kill signal, terminate background node processes
  49. function ctrl_c() {
  50. for pid in ${pids[@]}
  51. do
  52. kill $pid
  53. done
  54. }
  55. bound=$(($nodes-1))
  56. # Starting last node
  57. LOG_TARGETS="!sled,!net" ./darkfid2 \
  58. -v \
  59. --consensus \
  60. --consensus-seed 127.0.0.1:6000 \
  61. --sync-seed 127.0.0.1:6020 \
  62. --consensus-p2p-accept 127.0.0.1:600$bound \
  63. --consensus-p2p-external 127.0.0.1:600$bound \
  64. --database ./tmp/node$bound/blockchain \
  65. --rpc-listen tcp://127.0.0.1:601$bound \
  66. --sync-p2p-accept 127.0.0.1:602$bound \
  67. --sync-p2p-external 127.0.0.1:602$bound \
  68. --wallet-path ./tmp/node$bound/wallet.db \
  69. -g 1650887115