consensus_simulation.sh 1.9 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. 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. 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. LOG_TARGETS="!sled,!net" ./darkfid2 \
  29. -v \
  30. --consensus \
  31. --consensus-p2p-seed 127.0.0.1:6000 \
  32. --sync-p2p-seed 127.0.0.1:6020 \
  33. --consensus-p2p-accept 127.0.0.1:600$i \
  34. --consensus-p2p-external 127.0.0.1:600$i \
  35. --database ./tmp/node$i/blockchain \
  36. --rpc-listen tcp://127.0.0.1:601$i \
  37. --sync-p2p-accept 127.0.0.1:602$i \
  38. --sync-p2p-external 127.0.0.1:602$i \
  39. --wallet-path ./tmp/node$i/wallet.db &
  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. LOG_TARGETS="!sled,!net" ./darkfid2 \
  56. -v \
  57. --consensus \
  58. --consensus-p2p-seed 127.0.0.1:6000 \
  59. --sync-p2p-seed 127.0.0.1:6020 \
  60. --consensus-p2p-accept 127.0.0.1:600$bound \
  61. --consensus-p2p-external 127.0.0.1:600$bound \
  62. --database ./tmp/node$bound/blockchain \
  63. --rpc-listen tcp://127.0.0.1:601$bound \
  64. --sync-p2p-accept 127.0.0.1:602$bound \
  65. --sync-p2p-external 127.0.0.1:602$bound \
  66. --wallet-path ./tmp/node$bound/wallet.db