simulation.sh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/bin/bash
  2. # Simulation of the consensus network for 4(hardcoded) validator nodes.
  3. # Copying the node state files with a blockchain containing only the genesis block.
  4. for i in {0..3}
  5. do
  6. cp validatord_state_$i ~/.config/darkfi/validatord_state_$i
  7. done
  8. # Starting node 0 (seed) in background
  9. cargo +nightly run -- &
  10. NODE0=$!
  11. # Waiting for seed to setup
  12. sleep 10
  13. # Starting node 1 in background
  14. cargo +nightly run -- --accept 0.0.0.0:11001 --seeds 127.0.0.1:11000 --rpc 127.0.0.1:6661 --external 127.0.0.1:11001 --id 1 --state ~/.config/darkfi/validatord_state_1 &
  15. NODE1=$!
  16. # Waiting for node 1 to setup
  17. sleep 5
  18. # Starting node 2 in background
  19. cargo +nightly run -- --accept 0.0.0.0:11002 --seeds 127.0.0.1:11000 --rpc 127.0.0.1:6662 --external 127.0.0.1:11002 --id 2 --state ~/.config/darkfi/validatord_state_2 &
  20. NODE2=$!
  21. # Waiting for node 2 to setup
  22. sleep 5
  23. # Trap kill signal
  24. trap ctrl_c INT
  25. # On kill signal, terminate background node processes
  26. function ctrl_c() {
  27. kill $NODE0
  28. kill $NODE1
  29. kill $NODE2
  30. }
  31. # Starting node 3
  32. cargo +nightly run -- --accept 0.0.0.0:11003 --seeds 127.0.0.1:11000 --rpc 127.0.0.1:6663 --external 127.0.0.1:11003 --id 3 --state ~/.config/darkfi/validatord_state_3
  33. # Node states are flushed on each node state file at epoch end (every 2 minutes).
  34. # To sugmit a TX, telnet to a node and push the json as per following example:
  35. # telnet 127.0.0.1 6661
  36. # {"jsonrpc": "2.0", "method": "receive_tx", "params": ["tx"], "id": 42}