validatord: proper 4 node local simulation impl added

This commit is contained in:
aggstam
2022-03-27 16:26:34 +03:00
committed by parazyd
parent 2498ef316f
commit 2247faefdc
7 changed files with 184 additions and 28 deletions

View File

@@ -1,18 +0,0 @@
// In a terminal start a seed node
$ cargo +nightly run --
// In a new terminal start node 1
$ 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/validator_state_1
// In a new terminal start node 2
$ 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/validator_state_2
// In a new terminal start node 3
$ 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/validator_state_3
// In a new terminal, telnet to one of the nodes and submit a tx json command
$ telnet 127.0.0.1 6661
json: {"jsonrpc": "2.0", "method": "receive_tx", "params": ["tx"], "id": 42}
// verify they all hold the same tx in the state file of each node

View File

@@ -0,0 +1,48 @@
#!/bin/bash
# Simulation of the consensus network for 4(hardcoded) validator nodes.
# Copying the node state files with a blockchain containing only the genesis block.
for i in {0..3}
do
cp validatord_state_$i ~/.config/darkfi/validatord_state_$i
done
# Starting node 0 (seed) in background
cargo +nightly run -- &
NODE0=$!
# Waiting for seed to setup
sleep 10
# Starting node 1 in background
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 &
NODE1=$!
# Waiting for node 1 to setup
sleep 5
# Starting node 2 in background
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 &
NODE2=$!
# Waiting for node 2 to setup
sleep 5
# Trap kill signal
trap ctrl_c INT
# On kill signal, terminate background node processes
function ctrl_c() {
kill $NODE0
kill $NODE1
kill $NODE2
}
# Starting node 3
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
# Node states are flushed on each node state file at epoch end (every 2 minutes).
# To sugmit a TX, telnet to a node and push the json as per following example:
# telnet 127.0.0.1 6661
# {"jsonrpc": "2.0", "method": "receive_tx", "params": ["tx"], "id": 42}

View File

@@ -0,0 +1,30 @@
{
"id": 0,
"genesis_time": 1648383795,
"secret_key": "22c1a9eae232ec84096c90896e763087a36b3eb55f3de599d5d3f7bba280a11e",
"public_key": "ad50d94b531da6864b32bed5001fde813e745841202b45d9f892e05d57593d19",
"canonical_blockchain": {
"blocks": [
{
"st": "⊥",
"sl": 0,
"txs": [],
"metadata": {
"om": {
"proof": "proof",
"r": "r",
"s": "s"
},
"sm": {
"votes": [],
"notarized": true,
"finalized": true
},
"timestamp": 1648383795
}
}
]
},
"node_blockchains": [],
"unconfirmed_txs": []
}

View File

@@ -0,0 +1,30 @@
{
"id": 1,
"genesis_time": 1648383795,
"secret_key": "56d954a063168d30e93e3c1afc16d12af3e8c048fca87b930146efb02f7f4c26",
"public_key": "4537911dc67e1dc828fe507d3fd25dcaf0b5c10a4b8dce5cee9aef8c91057fab",
"canonical_blockchain": {
"blocks": [
{
"st": "⊥",
"sl": 0,
"txs": [],
"metadata": {
"om": {
"proof": "proof",
"r": "r",
"s": "s"
},
"sm": {
"votes": [],
"notarized": true,
"finalized": true
},
"timestamp": 1648383795
}
}
]
},
"node_blockchains": [],
"unconfirmed_txs": []
}

View File

@@ -0,0 +1,30 @@
{
"id": 2,
"genesis_time": 1648383795,
"secret_key": "840a0e56c7bf4fa88e677244e3a3a8bd7c7cc9b0f591bb1ab6a5c9ac95d2f015",
"public_key": "469e7cdf2b72c2a6be5cfcec4a7694137660bc8d57f6f961b630c397b07bbf14",
"canonical_blockchain": {
"blocks": [
{
"st": "⊥",
"sl": 0,
"txs": [],
"metadata": {
"om": {
"proof": "proof",
"r": "r",
"s": "s"
},
"sm": {
"votes": [],
"notarized": true,
"finalized": true
},
"timestamp": 1648383795
}
}
]
},
"node_blockchains": [],
"unconfirmed_txs": []
}

View File

@@ -0,0 +1,30 @@
{
"id": 3,
"genesis_time": 1648383795,
"secret_key": "8403caeceb6b91284363ed3074af5a565bd9eeb75a5ad46b7522d3ac4074c400",
"public_key": "6e487af2f92f37b29b5bf05f75670c0f6b5813fd7d16a6f7b8bed6325370a5af",
"canonical_blockchain": {
"blocks": [
{
"st": "⊥",
"sl": 0,
"txs": [],
"metadata": {
"om": {
"proof": "proof",
"r": "r",
"s": "s"
},
"sm": {
"votes": [],
"notarized": true,
"finalized": true
},
"timestamp": 1648383795
}
}
]
},
"node_blockchains": [],
"unconfirmed_txs": []
}

View File

@@ -4,37 +4,43 @@
## your daemon properly.
# Configuration file to use
config = "validatord_config.toml"
config = "~/.config/darkfi/validatord_config.toml"
# Accept address
accept = "0.0.0.0:9999"
accept = "0.0.0.0:11000"
# Seed nodes
#seeds = "127.0.0.1:9999"
#seeds = "127.0.0.1:11000"
# Manual connections
#connect = "127.0.0.1:9999"
#connect = "127.0.0.1:11000"
# Connection slots
#slots = 5
slots = 5
# External address
#external = "127.0.0.1:11004"
external = "127.0.0.1:11000"
# Logfile path
#log = "/tmp/darkfid.log"
# The endpoint where validatord will bind its RPC socket
rpc = "127.0.0.1:8000"
rpc = "127.0.0.1:6660"
# Whether to listen with TLS or plain TCP
serve_tls = false
tls = false
# Path to DER-formatted PKCS#12 archive. (Unused if serve_tls=false)
# This can be created using openssl:
# openssl pkcs12 -export -out validatord_identity.pfx -inkey key.pem -in cert.pem -certfile validator_certs.pem
tls_identity_path = "~/.config/darkfi/validatord_identity.pfx"
identity = "~/.config/darkfi/validatord_identity.pfx"
# Password for the created TLS identity. (Unused if serve_tls=false)
tls_identity_password = "FOOBAR"
password = "FOOBAR"
# Path to the state file
state = "~/.config/darkfi/validatord_state_0"
# Node ID, used only for testing
id = 0