simulation.sh 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/bin/bash
  2. # Simulation of the consensus network for n validator nodes.
  3. nodes=4
  4. # Copying the node state files with a blockchain containing only the genesis block. Uncomment for fresh runs.
  5. #bound=$(($nodes - 1))
  6. #for i in $(eval echo "{0..$bound}")
  7. #do
  8. # rm -rf ~/.config/darkfi/validatord_db_$i
  9. #done
  10. # PIDs array
  11. pids=()
  12. # Starting node 0 (seed) in background
  13. cargo run -- &
  14. pids[${#pids[@]}]=$!
  15. # Waiting for seed to setup
  16. sleep 2
  17. # Starting nodes 1 till second to last node in background
  18. bound=$(($nodes-2))
  19. for i in $(eval echo "{1..$bound}")
  20. do
  21. cargo run -- \
  22. --accept 0.0.0.0:1100$i \
  23. --caccept 0.0.0.0:1200$i \
  24. --seeds 127.0.0.1:11000 \
  25. --cseeds 127.0.0.1:12000 \
  26. --rpc 127.0.0.1:666$i \
  27. --external 127.0.0.1:1100$i \
  28. --cexternal 127.0.0.1:1200$i \
  29. --id $i \
  30. --database ~/.config/darkfi/validatord_db_$i &
  31. pids[${#pids[@]}]=$!
  32. # waiting for node to setup
  33. sleep 2
  34. done
  35. # Trap kill signal
  36. trap ctrl_c INT
  37. # On kill signal, terminate background node processes
  38. function ctrl_c() {
  39. for pid in ${pids[@]}
  40. do
  41. kill $pid
  42. done
  43. }
  44. bound=$(($nodes-1))
  45. # Starting last node
  46. cargo run -- \
  47. --accept 0.0.0.0:1100$bound \
  48. --caccept 0.0.0.0:1200$bound \
  49. --seeds 127.0.0.1:11000 \
  50. --cseeds 127.0.0.1:12000 \
  51. --rpc 127.0.0.1:666$bound \
  52. --external 127.0.0.1:1100$bound \
  53. --cexternal 127.0.0.1:1200$bound \
  54. --id $bound \
  55. --database ~/.config/darkfi/validatord_db_$bound
  56. # Node states are flushed on each node state file at epoch end (every 2 minutes).
  57. # To sugmit a TX, telnet to a node and push the json as per following example:
  58. # telnet 127.0.0.1 6661
  59. # {"jsonrpc": "2.0", "method": "receive_tx", "params": ["tx"], "id": 42}