simulation.sh 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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.
  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 -- --accept 0.0.0.0:1100$i --seeds 127.0.0.1:11000 --rpc 127.0.0.1:666$i --external 127.0.0.1:1100$i --id $i --database ~/.config/darkfi/validatord_db_$i &
  22. pids[${#pids[@]}]=$!
  23. # waiting for node to setup
  24. sleep 2
  25. done
  26. # Trap kill signal
  27. trap ctrl_c INT
  28. # On kill signal, terminate background node processes
  29. function ctrl_c() {
  30. for pid in ${pids[@]}
  31. do
  32. kill $pid
  33. done
  34. }
  35. bound=$(($nodes-1))
  36. # Starting last node
  37. cargo run -- --accept 0.0.0.0:1100$bound --seeds 127.0.0.1:11000 --rpc 127.0.0.1:666$bound --external 127.0.0.1:1100$bound --id $bound --database ~/.config/darkfi/validatord_db_$bound
  38. # Node states are flushed on each node state file at epoch end (every 2 minutes).
  39. # To sugmit a TX, telnet to a node and push the json as per following example:
  40. # telnet 127.0.0.1 6661
  41. # {"jsonrpc": "2.0", "method": "receive_tx", "params": ["tx"], "id": 42}