simulation.sh 1.6 KB

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