validatord: state storage moved from jsonfile to sled

This commit is contained in:
aggstam
2022-04-05 22:23:00 +03:00
parent a2e6917f3c
commit 267e1d2016
24 changed files with 93 additions and 591 deletions

View File

@@ -20,6 +20,9 @@ easy-parallel = "3.2.0"
# Crypto
rand = "0.8.5"
# Storage
sled = "0.34.7"
# Structopt dependencies for arguments parsing
serde = "1.0.136"
serde_derive = "1.0.136"

View File

@@ -1,7 +1,6 @@
#!/bin/bash
# Simulation of the consensus network for n validator nodes.
# Note: state files should be generated before executing.
nodes=4
@@ -9,7 +8,7 @@ nodes=4
bound=$(($nodes - 1))
for i in $(eval echo "{0..$bound}")
do
cp validatord_state_$i ~/.config/darkfi/validatord_state_$i
rmdir ~/.config/darkfi/validatord_db_$i
done
# PIDs array
@@ -26,7 +25,7 @@ sleep 2
bound=$(($nodes-2))
for i in $(eval echo "{1..$bound}")
do
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 &
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 &
pids[${#pids[@]}]=$!
# waiting for node to setup
sleep 2
@@ -45,7 +44,7 @@ function ctrl_c() {
bound=$(($nodes-1))
# Starting last node
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 --state ~/.config/darkfi/validatord_state_$bound
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
# 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:

View File

@@ -1,53 +0,0 @@
#!/bin/bash
# Simulation of the consensus network for n validator nodes.
# Note: state files should be generated before executing.
nodes=10
# Copying the node state files with a blockchain containing only the genesis block.
bound=$(($nodes - 1))
for i in $(eval echo "{0..$bound}")
do
cp validatord_state_$i ~/.config/darkfi/validatord_state_$i
done
# PIDs array
pids=()
# Starting node 0 (seed) in background
cargo run -- &
pids[${#pids[@]}]=$!
# Waiting for seed to setup
sleep 2
# Starting nodes 1 till second to last node in background
bound=$(($nodes-2))
for i in $(eval echo "{1..$bound}")
do
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 &
pids[${#pids[@]}]=$!
# waiting for node to setup
sleep 2
done
# Trap kill signal
trap ctrl_c INT
# On kill signal, terminate background node processes
function ctrl_c() {
for pid in ${pids[@]}
do
kill $pid
done
}
bound=$(($nodes-1))
# Starting last node
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 --state ~/.config/darkfi/validatord_state_$bound
# 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

@@ -1,34 +0,0 @@
{
"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,
"participants": []
},
"timestamp": 1648383795
}
}
]
},
"node_blockchains": [],
"unconfirmed_txs": [],
"orphan_votes": [],
"participants": {},
"pending_participants": []
}

View File

@@ -1,34 +0,0 @@
{
"id": 1,
"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,
"participants": []
},
"timestamp": 1648383795
}
}
]
},
"node_blockchains": [],
"unconfirmed_txs": [],
"orphan_votes": [],
"participants": {},
"pending_participants": []
}

View File

@@ -1,34 +0,0 @@
{
"id": 2,
"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,
"participants": []
},
"timestamp": 1648383795
}
}
]
},
"node_blockchains": [],
"unconfirmed_txs": [],
"orphan_votes": [],
"participants": {},
"pending_participants": []
}

View File

@@ -1,34 +0,0 @@
{
"id": 3,
"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,
"participants": []
},
"timestamp": 1648383795
}
}
]
},
"node_blockchains": [],
"unconfirmed_txs": [],
"orphan_votes": [],
"participants": {},
"pending_participants": []
}

View File

@@ -1,34 +0,0 @@
{
"id": 4,
"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,
"participants": []
},
"timestamp": 1648383795
}
}
]
},
"node_blockchains": [],
"unconfirmed_txs": [],
"orphan_votes": [],
"participants": {},
"pending_participants": []
}

View File

@@ -1,34 +0,0 @@
{
"id": 5,
"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,
"participants": []
},
"timestamp": 1648383795
}
}
]
},
"node_blockchains": [],
"unconfirmed_txs": [],
"orphan_votes": [],
"participants": {},
"pending_participants": []
}

View File

@@ -1,34 +0,0 @@
{
"id": 6,
"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,
"participants": []
},
"timestamp": 1648383795
}
}
]
},
"node_blockchains": [],
"unconfirmed_txs": [],
"orphan_votes": [],
"participants": {},
"pending_participants": []
}

View File

@@ -1,34 +0,0 @@
{
"id": 7,
"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,
"participants": []
},
"timestamp": 1648383795
}
}
]
},
"node_blockchains": [],
"unconfirmed_txs": [],
"orphan_votes": [],
"participants": {},
"pending_participants": []
}

View File

@@ -1,34 +0,0 @@
{
"id": 8,
"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,
"participants": []
},
"timestamp": 1648383795
}
}
]
},
"node_blockchains": [],
"unconfirmed_txs": [],
"orphan_votes": [],
"participants": {},
"pending_participants": []
}

View File

@@ -1,34 +0,0 @@
{
"id": 9,
"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,
"participants": []
},
"timestamp": 1648383795
}
}
]
},
"node_blockchains": [],
"unconfirmed_txs": [],
"orphan_votes": [],
"participants": {},
"pending_participants": []
}

View File

@@ -1,34 +0,0 @@
{
"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,
"participants": []
},
"timestamp": 1648383795
}
}
]
},
"node_blockchains": [],
"unconfirmed_txs": [],
"orphan_votes": [],
"participants": {},
"pending_participants": []
}

View File

@@ -1,34 +0,0 @@
{
"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,
"participants": []
},
"timestamp": 1648383795
}
}
]
},
"node_blockchains": [],
"unconfirmed_txs": [],
"orphan_votes": [],
"participants": {},
"pending_participants": []
}

View File

@@ -1,34 +0,0 @@
{
"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,
"participants": []
},
"timestamp": 1648383795
}
}
]
},
"node_blockchains": [],
"unconfirmed_txs": [],
"orphan_votes": [],
"participants": {},
"pending_participants": []
}

View File

@@ -1,34 +0,0 @@
{
"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,
"participants": []
},
"timestamp": 1648383795
}
}
]
},
"node_blockchains": [],
"unconfirmed_txs": [],
"orphan_votes": [],
"participants": {},
"pending_participants": []
}

View File

@@ -79,9 +79,12 @@ struct Opt {
#[structopt(long, default_value = "FOOBAR")]
/// Password for the created TLS identity
password: String,
#[structopt(long, default_value = "~/.config/darkfi/validatord_state_0")]
/// Path to the state file
state: String,
#[structopt(long, default_value = "1648383795")]
/// Timestamp of the genesis block creation
genesis: i64,
#[structopt(long, default_value = "~/.config/darkfi/validatord_db_0")]
/// Path to the sled database folder
database: String,
#[structopt(long, default_value = "0")]
/// Node ID, used only for testing
id: u64,
@@ -93,7 +96,7 @@ struct Opt {
verbose: u8,
}
async fn proposal_task(p2p: net::P2pPtr, state: StatePtr, state_path: &PathBuf) {
async fn proposal_task(p2p: net::P2pPtr, state: StatePtr, database: &sled::Db) {
// Node signals the network that it starts participating
let participant =
Participant::new(state.read().unwrap().id, state.read().unwrap().get_current_epoch());
@@ -155,7 +158,7 @@ async fn proposal_task(p2p: net::P2pPtr, state: StatePtr, state_path: &PathBuf)
Err(e) => error!("Broadcast failed. Error: {:?}", e),
}
let result = state.read().unwrap().save(state_path);
let result = state.read().unwrap().save(database);
match result {
Ok(()) => (),
Err(e) => {
@@ -186,9 +189,11 @@ async fn start(executor: Arc<Executor<'_>>, opts: &Opt) -> Result<()> {
};
// State setup
let state_path = expand_path(&opts.state).unwrap();
let genesis = opts.genesis;
let database_path = expand_path(&opts.database).unwrap();
let database = sled::open(database_path).unwrap();
let id = opts.id.clone();
let state = State::load_current_state(id, &state_path).unwrap();
let state = State::load_current_state(genesis, id, &database).unwrap();
// P2P registry setup
let p2p = net::P2p::new(network_settings).await;
@@ -255,7 +260,7 @@ async fn start(executor: Arc<Executor<'_>>, opts: &Opt) -> Result<()> {
.spawn(async move { listen_and_serve(rpc_server_config, rpc_interface, ex3).await })
.detach();
proposal_task(p2p, state, &state_path).await;
proposal_task(p2p, state, &database).await;
Ok(())
}

View File

@@ -38,8 +38,11 @@ identity = "~/.config/darkfi/validatord_identity.pfx"
# Password for the created TLS identity. (Unused if serve_tls=false)
password = "FOOBAR"
# Path to the state file
state = "~/.config/darkfi/validatord_state_0"
# Timestamp of the genesis block creation
genesis = 1648383795
# Path to the sled database folder
database = "~/.config/darkfi/validatord_db_0"
# Node ID, used only for testing
id = 0