consensus_simulation.sh 2.0 KB

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