simulation.sh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/bin/bash
  2. # Simulation of the consensus network for n validator nodes.
  3. # Note: state files should be generated before executing.
  4. nodes=4
  5. # Copying the node state files with a blockchain containing only the genesis block.
  6. bound=$(($nodes - 1))
  7. for i in $(eval echo "{0..$bound}")
  8. do
  9. cp validatord_state_$i ~/.config/darkfi/validatord_state_$i
  10. done
  11. # PIDs array
  12. pids=()
  13. # Starting node 0 (seed) in background
  14. cargo run -- --nodes $nodes &
  15. pids[${#pids[@]}]=$!
  16. # Waiting for seed to setup
  17. sleep 2
  18. # Starting nodes 1 till second to last node in background
  19. bound=$(($nodes-2))
  20. for i in $(eval echo "{1..$bound}")
  21. do
  22. 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 --state ~/.config/darkfi/validatord_state_$i --nodes $nodes &
  23. pids[${#pids[@]}]=$!
  24. # waiting for node to setup
  25. sleep 2
  26. done
  27. # Trap kill signal
  28. trap ctrl_c INT
  29. # On kill signal, terminate background node processes
  30. function ctrl_c() {
  31. for pid in ${pids[@]}
  32. do
  33. kill $pid
  34. done
  35. }
  36. bound=$(($nodes-1))
  37. # Starting last node
  38. 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 3 --state ~/.config/darkfi/validatord_state_$bound --nodes $nodes
  39. # Node states are flushed on each node state file at epoch end (every 2 minutes).
  40. # To sugmit a TX, telnet to a node and push the json as per following example:
  41. # telnet 127.0.0.1 6661
  42. # {"jsonrpc": "2.0", "method": "receive_tx", "params": ["tx"], "id": 42}