consensus_simulation.sh 2.0 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. # PIDs array
  7. pids=()
  8. # Starting node 0 (seed) in background
  9. LOG_TARGETS="!sled,!net" ./darkfid \
  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. --clock-sync &
  20. pids[${#pids[@]}]=$!
  21. # Waiting for seed to setup
  22. sleep 20
  23. # Starting nodes 1 till second to last node in background
  24. bound=$(($nodes-2))
  25. for i in $(eval echo "{1..$bound}")
  26. do
  27. LOG_TARGETS="!sled,!net" ./darkfid \
  28. -v \
  29. --consensus \
  30. --consensus-p2p-seed tcp://127.0.0.1:6000 \
  31. --sync-p2p-seed tcp://127.0.0.1:6020 \
  32. --consensus-p2p-accept tcp://127.0.0.1:600$i \
  33. --consensus-p2p-external tcp://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 tcp://127.0.0.1:602$i \
  37. --sync-p2p-external tcp://127.0.0.1:602$i \
  38. --wallet-path ./tmp/node$i/wallet.db \
  39. --clock-sync &
  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" ./darkfid \
  56. -v \
  57. --consensus \
  58. --consensus-p2p-seed tcp://127.0.0.1:6000 \
  59. --sync-p2p-seed tcp://127.0.0.1:6020 \
  60. --consensus-p2p-accept tcp://127.0.0.1:600$bound \
  61. --consensus-p2p-external tcp://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 tcp://127.0.0.1:602$bound \
  65. --sync-p2p-external tcp://127.0.0.1:602$bound \
  66. --wallet-path ./tmp/node$bound/wallet.db \
  67. --clock-sync