From 1393be63ff200938d4dcc331b93ef82e19203635 Mon Sep 17 00:00:00 2001 From: Lei Yang Date: Wed, 28 Aug 2019 18:12:40 -0400 Subject: [PATCH 01/29] tune for perf --- src/config.rs | 6 +++--- testbed/run.sh | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/config.rs b/src/config.rs index 16256d01..13114622 100644 --- a/src/config.rs +++ b/src/config.rs @@ -6,15 +6,15 @@ pub const NETWORK_DELAY: f32 = 1.4; // the expected block propagation delay (in // Design parameters pub const NUM_VOTER_CHAINS: u16 = 1000 as u16; // more chains means better latency pub const TX_BLOCK_SIZE: u32 = 64000; // the maximum size of a transaction block (in Bytes) -pub const TX_THROUGHPUT: u32 = 70000; // the transaction throughput we want to support (in Tx/s) +pub const TX_THROUGHPUT: u32 = 100000; // the transaction throughput we want to support (in Tx/s) pub const TX_BLOCK_TRANSACTIONS: u32 = TX_BLOCK_SIZE / AVG_TX_SIZE; pub const PROPOSER_BLOCK_TX_REFS: u32 = (TX_MINING_RATE / CHAIN_MINING_RATE * 2.0) as u32; pub const AVG_TX_SIZE: u32 = 280; // average size of a transaction (in Bytes) pub const TX_MINING_RATE: f32 = TX_THROUGHPUT as f32 / TX_BLOCK_TRANSACTIONS as f32; -pub const CHAIN_MINING_RATE: f32 = 0.074; // mining rate of the proposer chain and each voter chain in Blks/s +pub const CHAIN_MINING_RATE: f32 = 0.100; // mining rate of the proposer chain and each voter chain in Blks/s -pub const ADVERSARY_MINING_POWER: f32 = 0.43; // the adversary power we want to tolerate +pub const ADVERSARY_MINING_POWER: f32 = 0.40; // the adversary power we want to tolerate pub const LOG_EPSILON: f32 = 10.0; // -ln(1-confirmation_guarantee) pub const ALPHA: f32 = (CHAIN_MINING_RATE * NETWORK_DELAY) / (1.0 + CHAIN_MINING_RATE * NETWORK_DELAY); // alpha = orphan blocks / total blocks diff --git a/testbed/run.sh b/testbed/run.sh index e50957d3..a86a63ac 100755 --- a/testbed/run.sh +++ b/testbed/run.sh @@ -493,7 +493,7 @@ function start_transactions_single function start_mining_single { - curl -s "http://$3:$4/miner/start?lambda=258000&lazy=false" + curl -s "http://$3:$4/miner/start?lambda=532000&lazy=false" } function stop_transactions_single From d6cceb7170fd76ebd44c3bde2b8494672914666b Mon Sep 17 00:00:00 2001 From: Lei Yang Date: Thu, 29 Aug 2019 10:08:13 -0400 Subject: [PATCH 02/29] target 70k --- src/config.rs | 2 +- testbed/run.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/config.rs b/src/config.rs index 13114622..26877425 100644 --- a/src/config.rs +++ b/src/config.rs @@ -6,7 +6,7 @@ pub const NETWORK_DELAY: f32 = 1.4; // the expected block propagation delay (in // Design parameters pub const NUM_VOTER_CHAINS: u16 = 1000 as u16; // more chains means better latency pub const TX_BLOCK_SIZE: u32 = 64000; // the maximum size of a transaction block (in Bytes) -pub const TX_THROUGHPUT: u32 = 100000; // the transaction throughput we want to support (in Tx/s) +pub const TX_THROUGHPUT: u32 = 70000; // the transaction throughput we want to support (in Tx/s) pub const TX_BLOCK_TRANSACTIONS: u32 = TX_BLOCK_SIZE / AVG_TX_SIZE; pub const PROPOSER_BLOCK_TX_REFS: u32 = (TX_MINING_RATE / CHAIN_MINING_RATE * 2.0) as u32; diff --git a/testbed/run.sh b/testbed/run.sh index a86a63ac..f119dbeb 100755 --- a/testbed/run.sh +++ b/testbed/run.sh @@ -493,7 +493,7 @@ function start_transactions_single function start_mining_single { - curl -s "http://$3:$4/miner/start?lambda=532000&lazy=false" + curl -s "http://$3:$4/miner/start?lambda=246000&lazy=false" } function stop_transactions_single From 8e4c6d7643d194dbe4cab99b9f409992df0c533f Mon Sep 17 00:00:00 2001 From: Lei Yang Date: Thu, 29 Aug 2019 10:31:51 -0400 Subject: [PATCH 03/29] add command to control tx rate --- testbed/run.sh | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/testbed/run.sh b/testbed/run.sh index f119dbeb..f2d4ec5d 100755 --- a/testbed/run.sh +++ b/testbed/run.sh @@ -488,7 +488,7 @@ function start_transactions_single { curl -s "http://$3:$4/transaction-generator/set-arrival-distribution?interval=100&distribution=uniform" curl -s "http://$3:$4/transaction-generator/set-value-distribution?min=100&max=100&distribution=uniform" - curl -s "http://$3:$4/transaction-generator/start?throttle=8000" + curl -s "http://$3:$4/transaction-generator/start?throttle=2000" } function start_mining_single @@ -716,6 +716,30 @@ function show_demo ./telematics/telematics log -duration 7200 -grafana } +function set_tx_rate +{ + local nodes=`cat nodes.txt` + local num_nodes=`cat nodes.txt | wc -l` + local txrate=$1 + if [ "$1" -lt "$num_nodes" ]; then + txrate=$num_nodes + fi + local itv=`expr 1000000 / \( $txrate / $num_nodes \)` + local pids='' + for node in $nodes; do + local name + local host + local pubip + local apiport + IFS=',' read -r name host pubip _ _ apiport _ <<< "$node" + curl -s "http://$pubip:$apiport/transaction-generator/set-arrival-distribution?interval=$itv&distribution=uniform" &> /dev/null & + pids="$pids $!" + done + for pid in $pids; do + wait $pid + done +} + mkdir -p log case "$1" in help) @@ -749,6 +773,7 @@ case "$1" in show-demo Start the demo workflow stop-tx Stop generating transactions stop-mine Stop mining + tx-rate r Set transaction throughput to r Run Algorand Experiment @@ -808,6 +833,8 @@ case "$1" in show_demo ;; stop-tx) query_api stop_transactions 0 ;; + tx-rate) + set_tx_rate $2 ;; stop-mine) query_api stop_mining 0 ;; shape-traffic) From 33c73ed63faec1f9b3ddd8d2e653e58c3bb0f0b3 Mon Sep 17 00:00:00 2001 From: Lei Yang Date: Thu, 29 Aug 2019 13:52:58 -0400 Subject: [PATCH 04/29] lower security for irrelevant experiments --- src/config.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.rs b/src/config.rs index 26877425..abdfb340 100644 --- a/src/config.rs +++ b/src/config.rs @@ -14,7 +14,7 @@ pub const AVG_TX_SIZE: u32 = 280; // average size of a transaction (in Bytes) pub const TX_MINING_RATE: f32 = TX_THROUGHPUT as f32 / TX_BLOCK_TRANSACTIONS as f32; pub const CHAIN_MINING_RATE: f32 = 0.100; // mining rate of the proposer chain and each voter chain in Blks/s -pub const ADVERSARY_MINING_POWER: f32 = 0.40; // the adversary power we want to tolerate +pub const ADVERSARY_MINING_POWER: f32 = 0.20; // the adversary power we want to tolerate pub const LOG_EPSILON: f32 = 10.0; // -ln(1-confirmation_guarantee) pub const ALPHA: f32 = (CHAIN_MINING_RATE * NETWORK_DELAY) / (1.0 + CHAIN_MINING_RATE * NETWORK_DELAY); // alpha = orphan blocks / total blocks From bd37ae792b5c9739ebb8663f0898dde15db79540 Mon Sep 17 00:00:00 2001 From: Lei Yang Date: Thu, 29 Aug 2019 16:34:22 -0400 Subject: [PATCH 05/29] precompute quantile epsilon with higher precision --- src/blockchain/mod.rs | 3 ++- src/config.rs | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/blockchain/mod.rs b/src/blockchain/mod.rs index 11a7339b..0d17e047 100644 --- a/src/blockchain/mod.rs +++ b/src/blockchain/mod.rs @@ -621,7 +621,7 @@ impl BlockChain { block_votes_variance += p * (1.0-p); } // using gaussian approximation - let tmp = block_votes_mean - (2.0 * block_votes_variance * LOG_EPSILON).sqrt(); + let tmp = block_votes_mean - (block_votes_variance).sqrt() * (*QUANTILE_EPSILON); if tmp > 0.0 { block_votes_lcb += tmp; } @@ -651,6 +651,7 @@ impl BlockChain { for p_block in &proposer_blocks { // if the below condition is true, then final votes on p_block could overtake new_leader if max_vote_lcb < votes_lcb.get(p_block).unwrap() + remaining_votes && *p_block != new_leader.unwrap() { + println!("Candidate: {:?}, lb={}, second ub={}", new_leader, max_vote_lcb, votes_lcb.get(p_block).unwrap() + remaining_votes); new_leader = None; break; } diff --git a/src/config.rs b/src/config.rs index abdfb340..f6422703 100644 --- a/src/config.rs +++ b/src/config.rs @@ -14,8 +14,8 @@ pub const AVG_TX_SIZE: u32 = 280; // average size of a transaction (in Bytes) pub const TX_MINING_RATE: f32 = TX_THROUGHPUT as f32 / TX_BLOCK_TRANSACTIONS as f32; pub const CHAIN_MINING_RATE: f32 = 0.100; // mining rate of the proposer chain and each voter chain in Blks/s -pub const ADVERSARY_MINING_POWER: f32 = 0.20; // the adversary power we want to tolerate -pub const LOG_EPSILON: f32 = 10.0; // -ln(1-confirmation_guarantee) +pub const ADVERSARY_MINING_POWER: f32 = 0.40; // the adversary power we want to tolerate +pub const LOG_EPSILON: f32 = 20.0; // -ln(1-confirmation_guarantee) pub const ALPHA: f32 = (CHAIN_MINING_RATE * NETWORK_DELAY) / (1.0 + CHAIN_MINING_RATE * NETWORK_DELAY); // alpha = orphan blocks / total blocks // Do not change from here @@ -43,6 +43,8 @@ pub const PROPOSER_INDEX: u16 = 0; pub const FIRST_VOTER_INDEX: u16 = 2; lazy_static! { + pub static ref QUANTILE_EPSILON: f32 = (2.0 * LOG_EPSILON - (2.0 * LOG_EPSILON).ln() - (2.0 * 3.1416926 as f32).ln()).sqrt(); + pub static ref DEFAULT_DIFFICULTY: H256 = { let raw: [u8; 32] = [255; 32]; raw.into() From a88e2c2951d4389c8955448fcab9e463ea4d0137 Mon Sep 17 00:00:00 2001 From: Lei Yang Date: Thu, 29 Aug 2019 16:49:53 -0400 Subject: [PATCH 06/29] kill prism instances with force --- testbed/scripts/stop-prism.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testbed/scripts/stop-prism.sh b/testbed/scripts/stop-prism.sh index f5916de4..3ee2b3ef 100644 --- a/testbed/scripts/stop-prism.sh +++ b/testbed/scripts/stop-prism.sh @@ -2,7 +2,7 @@ echo "Killing Prism processes" -pkill prism +pkill -9 prism wait $! # pids=`cat /home/ubuntu/log/prism.pid` From 96690912ee9944cb3acbf95ff97fb9ccefd62823 Mon Sep 17 00:00:00 2001 From: Lei Yang Date: Fri, 30 Aug 2019 10:49:46 -0400 Subject: [PATCH 07/29] precise control over transaction throughput --- src/experiment/transaction_generator.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/experiment/transaction_generator.rs b/src/experiment/transaction_generator.rs index 46a0bcb7..217139a7 100644 --- a/src/experiment/transaction_generator.rs +++ b/src/experiment/transaction_generator.rs @@ -103,7 +103,9 @@ impl TransactionGenerator { // TODO: make it flexible let addr = self.wallet.addresses().unwrap()[0]; let mut prev_coin = None; + let mut tx_gen_start: time::Instant = time::Instant::now(); loop { + tx_gen_start = time::Instant::now(); // check the current state and try to receive control message match self.state { State::Continuous(_) | State::Step(_) => match self.control_chan.try_recv() { @@ -168,6 +170,15 @@ impl TransactionGenerator { ArrivalDistribution::Uniform(d) => d.interval, }; let interval = time::Duration::from_micros(interval); + let time_spent = time::Instant::now().duration_since(tx_gen_start); + let interval = { + if interval > time_spent { + interval - time_spent + } + else { + time::Duration::new(0, 0) + } + }; thread::sleep(interval); } }); From 3b0e8b8cae8c6bd06bae10673fce41a5b0cce4ee Mon Sep 17 00:00:00 2001 From: Lei Yang Date: Fri, 30 Aug 2019 11:07:05 -0400 Subject: [PATCH 08/29] tune for 80k tx/s --- src/config.rs | 2 +- testbed/run.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/config.rs b/src/config.rs index f6422703..3209e8fb 100644 --- a/src/config.rs +++ b/src/config.rs @@ -6,7 +6,7 @@ pub const NETWORK_DELAY: f32 = 1.4; // the expected block propagation delay (in // Design parameters pub const NUM_VOTER_CHAINS: u16 = 1000 as u16; // more chains means better latency pub const TX_BLOCK_SIZE: u32 = 64000; // the maximum size of a transaction block (in Bytes) -pub const TX_THROUGHPUT: u32 = 70000; // the transaction throughput we want to support (in Tx/s) +pub const TX_THROUGHPUT: u32 = 80000; // the transaction throughput we want to support (in Tx/s) pub const TX_BLOCK_TRANSACTIONS: u32 = TX_BLOCK_SIZE / AVG_TX_SIZE; pub const PROPOSER_BLOCK_TX_REFS: u32 = (TX_MINING_RATE / CHAIN_MINING_RATE * 2.0) as u32; diff --git a/testbed/run.sh b/testbed/run.sh index f2d4ec5d..d64d1749 100755 --- a/testbed/run.sh +++ b/testbed/run.sh @@ -493,7 +493,7 @@ function start_transactions_single function start_mining_single { - curl -s "http://$3:$4/miner/start?lambda=246000&lazy=false" + curl -s "http://$3:$4/miner/start?lambda=221000&lazy=false" } function stop_transactions_single From f4511f7839dfae8e6c47802ec6569a8d78921720 Mon Sep 17 00:00:00 2001 From: Lei Yang Date: Fri, 30 Aug 2019 13:22:08 -0400 Subject: [PATCH 09/29] show generation rate --- testbed/telematics/log.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/testbed/telematics/log.go b/testbed/telematics/log.go index e3160574..e356947c 100644 --- a/testbed/telematics/log.go +++ b/testbed/telematics/log.go @@ -39,6 +39,7 @@ type Snapshot struct { type expSnapshot struct { time int + generated_tx int confirmed_tx int confirmed_tx_blk int processed_voter int @@ -342,6 +343,7 @@ func log(interval, duration uint, nodesFile, dataDir string, grafana bool) { expStartTime = dur lastSnapshot = expSnapshot{ time: dur, + generated_tx: curr["node_9"].Generated_transactions, confirmed_tx: curr["node_0"].Confirmed_transactions, confirmed_tx_blk: curr["node_0"].Confirmed_transaction_blocks, processed_voter: curr["node_0"].Processed_voter_blocks, @@ -365,6 +367,7 @@ func log(interval, duration uint, nodesFile, dataDir string, grafana bool) { expRunning = true expStartPerf = expSnapshot{ time: dur, + generated_tx: lastSnapshot.generated_tx, confirmed_tx: lastSnapshot.confirmed_tx, confirmed_tx_blk: lastSnapshot.confirmed_tx_blk, processed_voter: lastSnapshot.processed_voter, @@ -379,6 +382,7 @@ func log(interval, duration uint, nodesFile, dataDir string, grafana bool) { if lastSnapshot.confirmed_tx != curr["node_0"].Confirmed_transactions { expStopPerf = expSnapshot{ time: dur, + generated_tx: lastSnapshot.generated_tx, confirmed_tx: lastSnapshot.confirmed_tx, confirmed_tx_blk: lastSnapshot.confirmed_tx_blk, processed_voter: lastSnapshot.processed_voter, @@ -393,6 +397,7 @@ func log(interval, duration uint, nodesFile, dataDir string, grafana bool) { lastSnapshot = expSnapshot{ time: dur, + generated_tx: curr["node_0"].Generated_transactions, confirmed_tx: curr["node_0"].Confirmed_transactions, confirmed_tx_blk: curr["node_0"].Confirmed_transaction_blocks, processed_voter: curr["node_0"].Processed_voter_blocks, @@ -431,6 +436,7 @@ func log(interval, duration uint, nodesFile, dataDir string, grafana bool) { tm.Printf("Thruput %7.7g\n", float64(expStopPerf.confirmed_tx-expStartPerf.confirmed_tx)/float64(expdur)) tm.Printf("Prop Fork %7.7g\n", float64(expStopPerf.processed_proposer-expStopPerf.proposer_len-expStartPerf.processed_proposer+expStartPerf.proposer_len)/float64(expStopPerf.processed_proposer-expStartPerf.processed_proposer)) tm.Printf("Vote Fork %7.7g\n", float64(expStopPerf.processed_voter-expStopPerf.voter_len_sum-expStartPerf.processed_voter+expStartPerf.voter_len_sum)/float64(expStopPerf.processed_voter-expStartPerf.processed_voter)) + tm.Printf("Generation %7.7g\n", float64(expStopPerf.generated_tx-expStartPerf.generated_tx)/float64(expdur)) } } else { if !expStarted { From e786ee173710e85d94a76d739482fed72515e66e Mon Sep 17 00:00:00 2001 From: Lei Yang Date: Fri, 30 Aug 2019 17:24:00 -0400 Subject: [PATCH 10/29] decouple proposer and voter mining rate --- src/config.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/config.rs b/src/config.rs index 3209e8fb..2b82ff50 100644 --- a/src/config.rs +++ b/src/config.rs @@ -8,22 +8,23 @@ pub const NUM_VOTER_CHAINS: u16 = 1000 as u16; // more chains means better laten pub const TX_BLOCK_SIZE: u32 = 64000; // the maximum size of a transaction block (in Bytes) pub const TX_THROUGHPUT: u32 = 80000; // the transaction throughput we want to support (in Tx/s) pub const TX_BLOCK_TRANSACTIONS: u32 = TX_BLOCK_SIZE / AVG_TX_SIZE; -pub const PROPOSER_BLOCK_TX_REFS: u32 = (TX_MINING_RATE / CHAIN_MINING_RATE * 2.0) as u32; +pub const PROPOSER_BLOCK_TX_REFS: u32 = (TX_MINING_RATE / PROPOSER_CHAIN_MINING_RATE * 2.0) as u32; pub const AVG_TX_SIZE: u32 = 280; // average size of a transaction (in Bytes) pub const TX_MINING_RATE: f32 = TX_THROUGHPUT as f32 / TX_BLOCK_TRANSACTIONS as f32; -pub const CHAIN_MINING_RATE: f32 = 0.100; // mining rate of the proposer chain and each voter chain in Blks/s +pub const VOTER_CHAIN_MINING_RATE: f32 = 0.100; // mining rate of the proposer chain and each voter chain in Blks/s +pub const PROPOSER_CHAIN_MINING_RATE: f32 = 0.080; pub const ADVERSARY_MINING_POWER: f32 = 0.40; // the adversary power we want to tolerate pub const LOG_EPSILON: f32 = 20.0; // -ln(1-confirmation_guarantee) -pub const ALPHA: f32 = (CHAIN_MINING_RATE * NETWORK_DELAY) / (1.0 + CHAIN_MINING_RATE * NETWORK_DELAY); // alpha = orphan blocks / total blocks +pub const ALPHA: f32 = (VOTER_CHAIN_MINING_RATE * NETWORK_DELAY) / (1.0 + VOTER_CHAIN_MINING_RATE * NETWORK_DELAY); // alpha = orphan blocks / total blocks // Do not change from here // Mining rate of each type (Proposer : Voter (all chains) : Transaction, in Blks/s) pub const RATIO: (f32, f32, f32) = ( - CHAIN_MINING_RATE, - CHAIN_MINING_RATE * (NUM_VOTER_CHAINS as f32), + PROPOSER_CHAIN_MINING_RATE, + VOTER_CHAIN_MINING_RATE * (NUM_VOTER_CHAINS as f32), TX_MINING_RATE, ); From 9e7fba4af7ef8428e32906267bb4c4e055ac7b03 Mon Sep 17 00:00:00 2001 From: Lei Yang Date: Fri, 30 Aug 2019 18:16:05 -0400 Subject: [PATCH 11/29] fix bug in voting rule --- src/miner/mod.rs | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/src/miner/mod.rs b/src/miner/mod.rs index 694459a3..47d433b6 100644 --- a/src/miner/mod.rs +++ b/src/miner/mod.rs @@ -341,21 +341,23 @@ impl Context { } } } else { - for voter_chain in new_voter_block.iter() { - let chain_id: usize = (FIRST_VOTER_INDEX + voter_chain) as usize; - let voter_parent = if let Content::Voter(c) = &self.contents[chain_id] { - c.voter_parent - } else { - unreachable!(); - }; - if let Content::Voter(c) = &mut self.contents[chain_id] { - c.votes = self - .blockchain - .unvoted_proposer(&voter_parent, &self.header.parent) - .unwrap(); - touched_content.insert(chain_id as u16); - } else { - unreachable!(); + if !new_voter_block.is_empty() { + for voter_chain in 0..NUM_VOTER_CHAINS { + let chain_id: usize = (FIRST_VOTER_INDEX + voter_chain) as usize; + let voter_parent = if let Content::Voter(c) = &self.contents[chain_id] { + c.voter_parent + } else { + unreachable!(); + }; + if let Content::Voter(c) = &mut self.contents[chain_id] { + c.votes = self + .blockchain + .unvoted_proposer(&voter_parent, &self.header.parent) + .unwrap(); + touched_content.insert(chain_id as u16); + } else { + unreachable!(); + } } } } @@ -364,6 +366,10 @@ impl Context { self.header.difficulty = self.get_difficulty(&self.header.parent); // update or rebuild the merkle tree according to what we did in the last stage + /* + // This is the logic we have been using. However, since we now scan through all voter + // chains for potential vote changes (we now vote for the block with the most votes), + // here we just reconstruct the whole merkle tree for simplicity. if new_proposer_block { // if there has been a new proposer block, simply rebuild the merkle tree self.content_merkle_tree = MerkleTree::new(&self.contents); @@ -388,9 +394,14 @@ impl Context { } } } + */ // update merkle root if anything happened in the last stage if new_proposer_block || !new_voter_block.is_empty() || new_transaction_block { + // FIXME: see the commented out section above. this line refreshes the whole merkle + // tree and should be removed if we decided to individually refresh the merkle tree + // in the previous step. + self.content_merkle_tree = MerkleTree::new(&self.contents); self.header.content_merkle_root = self.content_merkle_tree.root(); } From cd4b52cb9b26d8cd717f5a1479ed4415fc299bd4 Mon Sep 17 00:00:00 2001 From: Lei Yang Date: Fri, 30 Aug 2019 22:19:58 -0400 Subject: [PATCH 12/29] make it a little bit more efficient --- src/miner/mod.rs | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/miner/mod.rs b/src/miner/mod.rs index 47d433b6..f3fb495b 100644 --- a/src/miner/mod.rs +++ b/src/miner/mod.rs @@ -236,13 +236,18 @@ impl Context { // handle context updates let mut touched_content: BTreeSet = BTreeSet::new(); + let mut voter_shift = false; // update voter parents for voter_chain in new_voter_block.iter() { let chain_id: usize = (FIRST_VOTER_INDEX + voter_chain) as usize; let voter_parent = self.blockchain.best_voter(*voter_chain as usize); if let Content::Voter(c) = &mut self.contents[chain_id] { - c.voter_parent = voter_parent; - touched_content.insert(chain_id as u16); + if &voter_parent != &c.voter_parent { + c.voter_parent = voter_parent; + // mark that we have shifted a vote + voter_shift = true; + touched_content.insert(chain_id as u16); + } } else { unreachable!(); } @@ -366,11 +371,7 @@ impl Context { self.header.difficulty = self.get_difficulty(&self.header.parent); // update or rebuild the merkle tree according to what we did in the last stage - /* - // This is the logic we have been using. However, since we now scan through all voter - // chains for potential vote changes (we now vote for the block with the most votes), - // here we just reconstruct the whole merkle tree for simplicity. - if new_proposer_block { + if new_proposer_block || voter_shift { // if there has been a new proposer block, simply rebuild the merkle tree self.content_merkle_tree = MerkleTree::new(&self.contents); } else { @@ -394,14 +395,9 @@ impl Context { } } } - */ // update merkle root if anything happened in the last stage if new_proposer_block || !new_voter_block.is_empty() || new_transaction_block { - // FIXME: see the commented out section above. this line refreshes the whole merkle - // tree and should be removed if we decided to individually refresh the merkle tree - // in the previous step. - self.content_merkle_tree = MerkleTree::new(&self.contents); self.header.content_merkle_root = self.content_merkle_tree.root(); } From 9b6759dad178e81b111805ee726e98fc33c35d4b Mon Sep 17 00:00:00 2001 From: Lei Yang Date: Fri, 30 Aug 2019 22:27:05 -0400 Subject: [PATCH 13/29] precise control over mining rate --- src/miner/mod.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/miner/mod.rs b/src/miner/mod.rs index f3fb495b..058807e7 100644 --- a/src/miner/mod.rs +++ b/src/miner/mod.rs @@ -195,9 +195,12 @@ impl Context { } let mut rng = rand::thread_rng(); + let mut block_start = time::Instant::now(); // main mining loop loop { + block_start = time::Instant::now(); + // check and react to control signals match self.operating_state { OperatingState::Paused => { @@ -492,7 +495,10 @@ impl Context { let interval_dist = rand::distributions::Exp::new(1.0 / (i as f64)); let interval = interval_dist.sample(&mut rng); let interval = time::Duration::from_micros(interval as u64); - thread::sleep(interval); + let time_spent = time::Instant::now().duration_since(block_start); + if interval > time_spent { + thread::sleep(interval - time_spent); + } } } } From 58631a60f966238e5210dddddd19c92443a21ef8 Mon Sep 17 00:00:00 2001 From: Lei Yang Date: Sat, 31 Aug 2019 08:55:43 -0400 Subject: [PATCH 14/29] extend experiment time to 600s --- testbed/run.sh | 4 ++-- testbed/telematics/log.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/testbed/run.sh b/testbed/run.sh index d64d1749..245f530f 100755 --- a/testbed/run.sh +++ b/testbed/run.sh @@ -71,7 +71,7 @@ function start_instances tput setaf 2 echo "Instances started" tput sgr0 - curl -s --form-string "token=$PUSHOVER_TOKEN" --form-string "user=$PUSHOVER_USER" --form-string "title=EC2 Instances Launched" --form-string "message=$1 EC2 instances were just launched by user $(whoami)." https://api.pushover.net/1/messages.json &> /dev/null + #curl -s --form-string "token=$PUSHOVER_TOKEN" --form-string "user=$PUSHOVER_USER" --form-string "title=EC2 Instances Launched" --form-string "message=$1 EC2 instances were just launched by user $(whoami)." https://api.pushover.net/1/messages.json &> /dev/null } function fix_ssh_config @@ -122,7 +122,7 @@ function stop_instances tput setaf 2 echo "Instances terminated" tput sgr0 - curl -s --form-string "token=$PUSHOVER_TOKEN" --form-string "user=$PUSHOVER_USER" --form-string "title=EC2 Instances Stopped" --form-string "message=EC2 instances launched at $(date -r instances.txt) were just terminated by user $(whoami)." https://api.pushover.net/1/messages.json &> /dev/null + #curl -s --form-string "token=$PUSHOVER_TOKEN" --form-string "user=$PUSHOVER_USER" --form-string "title=EC2 Instances Stopped" --form-string "message=EC2 instances launched at $(date -r instances.txt) were just terminated by user $(whoami)." https://api.pushover.net/1/messages.json &> /dev/null } function count_instances diff --git a/testbed/telematics/log.go b/testbed/telematics/log.go index e356947c..4f024b97 100644 --- a/testbed/telematics/log.go +++ b/testbed/telematics/log.go @@ -352,7 +352,7 @@ func log(interval, duration uint, nodesFile, dataDir string, grafana bool) { proposer_len: curr["node_0"].Proposer_main_chain_length, latency_sum: curr["node_0"].Total_transaction_block_confirmation_latency, } - expStopAlarm = time.After(300 * time.Second) + expStopAlarm = time.After(600 * time.Second) case <-expStopAlarm: expStarted = true expRunning = false @@ -442,7 +442,7 @@ func log(interval, duration uint, nodesFile, dataDir string, grafana bool) { if !expStarted { tm.Printf("Hit x to start a recording\n") } else { - tm.Printf("Experiment running. Remaining time: %v seconds\n", 300-dur+expStartTime) + tm.Printf("Experiment running. Remaining time: %v seconds\n", 600-dur+expStartTime) } } tm.Flush() From 56c8ae0fd3e91b5cf4b10ed8e334955de3b08118 Mon Sep 17 00:00:00 2001 From: Lei Yang Date: Sat, 31 Aug 2019 09:05:37 -0400 Subject: [PATCH 15/29] turn up proposer rate --- src/config.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.rs b/src/config.rs index 2b82ff50..b3011fe4 100644 --- a/src/config.rs +++ b/src/config.rs @@ -13,7 +13,7 @@ pub const PROPOSER_BLOCK_TX_REFS: u32 = (TX_MINING_RATE / PROPOSER_CHAIN_MINING_ pub const AVG_TX_SIZE: u32 = 280; // average size of a transaction (in Bytes) pub const TX_MINING_RATE: f32 = TX_THROUGHPUT as f32 / TX_BLOCK_TRANSACTIONS as f32; pub const VOTER_CHAIN_MINING_RATE: f32 = 0.100; // mining rate of the proposer chain and each voter chain in Blks/s -pub const PROPOSER_CHAIN_MINING_RATE: f32 = 0.080; +pub const PROPOSER_CHAIN_MINING_RATE: f32 = 0.100; pub const ADVERSARY_MINING_POWER: f32 = 0.40; // the adversary power we want to tolerate pub const LOG_EPSILON: f32 = 20.0; // -ln(1-confirmation_guarantee) From 468ff45dc83c33bb94c0a96e567bdf8c52e3b815 Mon Sep 17 00:00:00 2001 From: Lei Yang Date: Sat, 31 Aug 2019 22:12:18 -0400 Subject: [PATCH 16/29] comparison sec=0.2 --- src/config.rs | 6 +++--- testbed/run.sh | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/config.rs b/src/config.rs index b3011fe4..52edea66 100644 --- a/src/config.rs +++ b/src/config.rs @@ -12,10 +12,10 @@ pub const PROPOSER_BLOCK_TX_REFS: u32 = (TX_MINING_RATE / PROPOSER_CHAIN_MINING_ pub const AVG_TX_SIZE: u32 = 280; // average size of a transaction (in Bytes) pub const TX_MINING_RATE: f32 = TX_THROUGHPUT as f32 / TX_BLOCK_TRANSACTIONS as f32; -pub const VOTER_CHAIN_MINING_RATE: f32 = 0.100; // mining rate of the proposer chain and each voter chain in Blks/s -pub const PROPOSER_CHAIN_MINING_RATE: f32 = 0.100; +pub const VOTER_CHAIN_MINING_RATE: f32 = 0.535; // mining rate of the proposer chain and each voter chain in Blks/s +pub const PROPOSER_CHAIN_MINING_RATE: f32 = 0.535; -pub const ADVERSARY_MINING_POWER: f32 = 0.40; // the adversary power we want to tolerate +pub const ADVERSARY_MINING_POWER: f32 = 0.20; // the adversary power we want to tolerate pub const LOG_EPSILON: f32 = 20.0; // -ln(1-confirmation_guarantee) pub const ALPHA: f32 = (VOTER_CHAIN_MINING_RATE * NETWORK_DELAY) / (1.0 + VOTER_CHAIN_MINING_RATE * NETWORK_DELAY); // alpha = orphan blocks / total blocks diff --git a/testbed/run.sh b/testbed/run.sh index 245f530f..e0f04109 100755 --- a/testbed/run.sh +++ b/testbed/run.sh @@ -488,12 +488,12 @@ function start_transactions_single { curl -s "http://$3:$4/transaction-generator/set-arrival-distribution?interval=100&distribution=uniform" curl -s "http://$3:$4/transaction-generator/set-value-distribution?min=100&max=100&distribution=uniform" - curl -s "http://$3:$4/transaction-generator/start?throttle=2000" + curl -s "http://$3:$4/transaction-generator/start?throttle=10000" } function start_mining_single { - curl -s "http://$3:$4/miner/start?lambda=221000&lazy=false" + curl -s "http://$3:$4/miner/start?lambda=112926&lazy=false" } function stop_transactions_single From b92487b9c8c11ea7959295699584ef81fb2adf5d Mon Sep 17 00:00:00 2001 From: Lei Yang Date: Sat, 31 Aug 2019 22:45:27 -0400 Subject: [PATCH 17/29] tune for 0.33 security --- src/config.rs | 8 ++++---- testbed/run.sh | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/config.rs b/src/config.rs index 52edea66..a65165a9 100644 --- a/src/config.rs +++ b/src/config.rs @@ -4,7 +4,7 @@ use crate::crypto::hash::H256; pub const NETWORK_DELAY: f32 = 1.4; // the expected block propagation delay (in seconds) // Design parameters -pub const NUM_VOTER_CHAINS: u16 = 1000 as u16; // more chains means better latency +pub const NUM_VOTER_CHAINS: u16 = 2000 as u16; // more chains means better latency pub const TX_BLOCK_SIZE: u32 = 64000; // the maximum size of a transaction block (in Bytes) pub const TX_THROUGHPUT: u32 = 80000; // the transaction throughput we want to support (in Tx/s) pub const TX_BLOCK_TRANSACTIONS: u32 = TX_BLOCK_SIZE / AVG_TX_SIZE; @@ -12,10 +12,10 @@ pub const PROPOSER_BLOCK_TX_REFS: u32 = (TX_MINING_RATE / PROPOSER_CHAIN_MINING_ pub const AVG_TX_SIZE: u32 = 280; // average size of a transaction (in Bytes) pub const TX_MINING_RATE: f32 = TX_THROUGHPUT as f32 / TX_BLOCK_TRANSACTIONS as f32; -pub const VOTER_CHAIN_MINING_RATE: f32 = 0.535; // mining rate of the proposer chain and each voter chain in Blks/s -pub const PROPOSER_CHAIN_MINING_RATE: f32 = 0.535; +pub const VOTER_CHAIN_MINING_RATE: f32 = 0.196; // mining rate of the proposer chain and each voter chain in Blks/s +pub const PROPOSER_CHAIN_MINING_RATE: f32 = 0.196; -pub const ADVERSARY_MINING_POWER: f32 = 0.20; // the adversary power we want to tolerate +pub const ADVERSARY_MINING_POWER: f32 = 0.33; // the adversary power we want to tolerate pub const LOG_EPSILON: f32 = 20.0; // -ln(1-confirmation_guarantee) pub const ALPHA: f32 = (VOTER_CHAIN_MINING_RATE * NETWORK_DELAY) / (1.0 + VOTER_CHAIN_MINING_RATE * NETWORK_DELAY); // alpha = orphan blocks / total blocks diff --git a/testbed/run.sh b/testbed/run.sh index e0f04109..777ce764 100755 --- a/testbed/run.sh +++ b/testbed/run.sh @@ -493,7 +493,7 @@ function start_transactions_single function start_mining_single { - curl -s "http://$3:$4/miner/start?lambda=112926&lazy=false" + curl -s "http://$3:$4/miner/start?lambda=134735&lazy=false" } function stop_transactions_single From 7061bc35ff4af35dd5f3c7d2712b12440296e78f Mon Sep 17 00:00:00 2001 From: Lei Yang Date: Sun, 1 Sep 2019 10:36:40 -0400 Subject: [PATCH 18/29] tune for 0.4 --- src/config.rs | 8 ++++---- testbed/run.sh | 2 +- testbed/scripts/gen_prism_payload.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/config.rs b/src/config.rs index a65165a9..61e0c628 100644 --- a/src/config.rs +++ b/src/config.rs @@ -4,7 +4,7 @@ use crate::crypto::hash::H256; pub const NETWORK_DELAY: f32 = 1.4; // the expected block propagation delay (in seconds) // Design parameters -pub const NUM_VOTER_CHAINS: u16 = 2000 as u16; // more chains means better latency +pub const NUM_VOTER_CHAINS: u16 = 1000 as u16; // more chains means better latency pub const TX_BLOCK_SIZE: u32 = 64000; // the maximum size of a transaction block (in Bytes) pub const TX_THROUGHPUT: u32 = 80000; // the transaction throughput we want to support (in Tx/s) pub const TX_BLOCK_TRANSACTIONS: u32 = TX_BLOCK_SIZE / AVG_TX_SIZE; @@ -12,10 +12,10 @@ pub const PROPOSER_BLOCK_TX_REFS: u32 = (TX_MINING_RATE / PROPOSER_CHAIN_MINING_ pub const AVG_TX_SIZE: u32 = 280; // average size of a transaction (in Bytes) pub const TX_MINING_RATE: f32 = TX_THROUGHPUT as f32 / TX_BLOCK_TRANSACTIONS as f32; -pub const VOTER_CHAIN_MINING_RATE: f32 = 0.196; // mining rate of the proposer chain and each voter chain in Blks/s -pub const PROPOSER_CHAIN_MINING_RATE: f32 = 0.196; +pub const VOTER_CHAIN_MINING_RATE: f32 = 0.097; // mining rate of the proposer chain and each voter chain in Blks/s +pub const PROPOSER_CHAIN_MINING_RATE: f32 = 0.097; -pub const ADVERSARY_MINING_POWER: f32 = 0.33; // the adversary power we want to tolerate +pub const ADVERSARY_MINING_POWER: f32 = 0.40; // the adversary power we want to tolerate pub const LOG_EPSILON: f32 = 20.0; // -ln(1-confirmation_guarantee) pub const ALPHA: f32 = (VOTER_CHAIN_MINING_RATE * NETWORK_DELAY) / (1.0 + VOTER_CHAIN_MINING_RATE * NETWORK_DELAY); // alpha = orphan blocks / total blocks diff --git a/testbed/run.sh b/testbed/run.sh index 777ce764..bc0858b2 100755 --- a/testbed/run.sh +++ b/testbed/run.sh @@ -493,7 +493,7 @@ function start_transactions_single function start_mining_single { - curl -s "http://$3:$4/miner/start?lambda=134735&lazy=false" + curl -s "http://$3:$4/miner/start?lambda=223665&lazy=false" } function stop_transactions_single diff --git a/testbed/scripts/gen_prism_payload.py b/testbed/scripts/gen_prism_payload.py index d589c5e8..cfda82b2 100644 --- a/testbed/scripts/gen_prism_payload.py +++ b/testbed/scripts/gen_prism_payload.py @@ -4,7 +4,7 @@ import subprocess template = """ -/home/ubuntu/payload/binary/prism --p2p {ip}:{p2p_port} --api {ip}:{api_port} --visual {ip}:{vis_port} --blockdb /tmp/prism/{node_name}-blockdb.rocksdb --blockchaindb /tmp/prism/{node_name}-blockchaindb.rocksdb --utxodb /tmp/prism/{node_name}-utxodb.rocksdb --walletdb /tmp/prism/{node_name}-wallet.rocksdb -vv --load-key /home/ubuntu/payload/prism-payload/{node_name}.pkcs8 {peer_opt} {fund_opt} --fund-coins=100000 --mempool-size=50000 +/home/ubuntu/payload/binary/prism --p2p {ip}:{p2p_port} --api {ip}:{api_port} --visual {ip}:{vis_port} --blockdb /tmp/prism/{node_name}-blockdb.rocksdb --blockchaindb /tmp/prism/{node_name}-blockchaindb.rocksdb --utxodb /tmp/prism/{node_name}-utxodb.rocksdb --walletdb /tmp/prism/{node_name}-wallet.rocksdb -vv --load-key /home/ubuntu/payload/prism-payload/{node_name}.pkcs8 {peer_opt} {fund_opt} --fund-coins=200000 --mempool-size=50000 """ instances_file = sys.argv[1] From ffc34c1d346542b67dbc56cc94b0e9173b9cc76b Mon Sep 17 00:00:00 2001 From: Lei Yang Date: Sun, 1 Sep 2019 11:18:16 -0400 Subject: [PATCH 19/29] tune for 0.42 --- src/config.rs | 6 +++--- testbed/run.sh | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/config.rs b/src/config.rs index 61e0c628..4ddd386a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -12,10 +12,10 @@ pub const PROPOSER_BLOCK_TX_REFS: u32 = (TX_MINING_RATE / PROPOSER_CHAIN_MINING_ pub const AVG_TX_SIZE: u32 = 280; // average size of a transaction (in Bytes) pub const TX_MINING_RATE: f32 = TX_THROUGHPUT as f32 / TX_BLOCK_TRANSACTIONS as f32; -pub const VOTER_CHAIN_MINING_RATE: f32 = 0.097; // mining rate of the proposer chain and each voter chain in Blks/s -pub const PROPOSER_CHAIN_MINING_RATE: f32 = 0.097; +pub const VOTER_CHAIN_MINING_RATE: f32 = 0.081; // mining rate of the proposer chain and each voter chain in Blks/s +pub const PROPOSER_CHAIN_MINING_RATE: f32 = 0.081; -pub const ADVERSARY_MINING_POWER: f32 = 0.40; // the adversary power we want to tolerate +pub const ADVERSARY_MINING_POWER: f32 = 0.42; // the adversary power we want to tolerate pub const LOG_EPSILON: f32 = 20.0; // -ln(1-confirmation_guarantee) pub const ALPHA: f32 = (VOTER_CHAIN_MINING_RATE * NETWORK_DELAY) / (1.0 + VOTER_CHAIN_MINING_RATE * NETWORK_DELAY); // alpha = orphan blocks / total blocks diff --git a/testbed/run.sh b/testbed/run.sh index bc0858b2..2462be23 100755 --- a/testbed/run.sh +++ b/testbed/run.sh @@ -493,7 +493,7 @@ function start_transactions_single function start_mining_single { - curl -s "http://$3:$4/miner/start?lambda=223665&lazy=false" + curl -s "http://$3:$4/miner/start?lambda=231975&lazy=false" } function stop_transactions_single From c067bd915286078dd07697d213004609cbe4ab61 Mon Sep 17 00:00:00 2001 From: Lei Yang Date: Sun, 1 Sep 2019 12:57:21 -0400 Subject: [PATCH 20/29] tune for 0.44 --- src/config.rs | 6 +++--- testbed/run.sh | 2 +- testbed/scripts/gen_prism_payload.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/config.rs b/src/config.rs index 4ddd386a..9e6dc70e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -12,10 +12,10 @@ pub const PROPOSER_BLOCK_TX_REFS: u32 = (TX_MINING_RATE / PROPOSER_CHAIN_MINING_ pub const AVG_TX_SIZE: u32 = 280; // average size of a transaction (in Bytes) pub const TX_MINING_RATE: f32 = TX_THROUGHPUT as f32 / TX_BLOCK_TRANSACTIONS as f32; -pub const VOTER_CHAIN_MINING_RATE: f32 = 0.081; // mining rate of the proposer chain and each voter chain in Blks/s -pub const PROPOSER_CHAIN_MINING_RATE: f32 = 0.081; +pub const VOTER_CHAIN_MINING_RATE: f32 = 0.054; // mining rate of the proposer chain and each voter chain in Blks/s +pub const PROPOSER_CHAIN_MINING_RATE: f32 = 0.054; -pub const ADVERSARY_MINING_POWER: f32 = 0.42; // the adversary power we want to tolerate +pub const ADVERSARY_MINING_POWER: f32 = 0.44; // the adversary power we want to tolerate pub const LOG_EPSILON: f32 = 20.0; // -ln(1-confirmation_guarantee) pub const ALPHA: f32 = (VOTER_CHAIN_MINING_RATE * NETWORK_DELAY) / (1.0 + VOTER_CHAIN_MINING_RATE * NETWORK_DELAY); // alpha = orphan blocks / total blocks diff --git a/testbed/run.sh b/testbed/run.sh index 2462be23..0e77b08b 100755 --- a/testbed/run.sh +++ b/testbed/run.sh @@ -493,7 +493,7 @@ function start_transactions_single function start_mining_single { - curl -s "http://$3:$4/miner/start?lambda=231975&lazy=false" + curl -s "http://$3:$4/miner/start?lambda=247492&lazy=false" } function stop_transactions_single diff --git a/testbed/scripts/gen_prism_payload.py b/testbed/scripts/gen_prism_payload.py index cfda82b2..4c764667 100644 --- a/testbed/scripts/gen_prism_payload.py +++ b/testbed/scripts/gen_prism_payload.py @@ -4,7 +4,7 @@ import subprocess template = """ -/home/ubuntu/payload/binary/prism --p2p {ip}:{p2p_port} --api {ip}:{api_port} --visual {ip}:{vis_port} --blockdb /tmp/prism/{node_name}-blockdb.rocksdb --blockchaindb /tmp/prism/{node_name}-blockchaindb.rocksdb --utxodb /tmp/prism/{node_name}-utxodb.rocksdb --walletdb /tmp/prism/{node_name}-wallet.rocksdb -vv --load-key /home/ubuntu/payload/prism-payload/{node_name}.pkcs8 {peer_opt} {fund_opt} --fund-coins=200000 --mempool-size=50000 +/home/ubuntu/payload/binary/prism --p2p {ip}:{p2p_port} --api {ip}:{api_port} --visual {ip}:{vis_port} --blockdb /tmp/prism/{node_name}-blockdb.rocksdb --blockchaindb /tmp/prism/{node_name}-blockchaindb.rocksdb --utxodb /tmp/prism/{node_name}-utxodb.rocksdb --walletdb /tmp/prism/{node_name}-wallet.rocksdb -vv --load-key /home/ubuntu/payload/prism-payload/{node_name}.pkcs8 {peer_opt} {fund_opt} --fund-coins=400000 --mempool-size=50000 """ instances_file = sys.argv[1] From 4e87db7676a2beca62acbf033c24f34b3c919a99 Mon Sep 17 00:00:00 2001 From: Lei Yang Date: Sun, 1 Sep 2019 13:34:48 -0400 Subject: [PATCH 21/29] tune for the other experiments --- src/config.rs | 6 +++--- testbed/run.sh | 2 +- testbed/scripts/gen_prism_payload.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/config.rs b/src/config.rs index 9e6dc70e..b3011fe4 100644 --- a/src/config.rs +++ b/src/config.rs @@ -12,10 +12,10 @@ pub const PROPOSER_BLOCK_TX_REFS: u32 = (TX_MINING_RATE / PROPOSER_CHAIN_MINING_ pub const AVG_TX_SIZE: u32 = 280; // average size of a transaction (in Bytes) pub const TX_MINING_RATE: f32 = TX_THROUGHPUT as f32 / TX_BLOCK_TRANSACTIONS as f32; -pub const VOTER_CHAIN_MINING_RATE: f32 = 0.054; // mining rate of the proposer chain and each voter chain in Blks/s -pub const PROPOSER_CHAIN_MINING_RATE: f32 = 0.054; +pub const VOTER_CHAIN_MINING_RATE: f32 = 0.100; // mining rate of the proposer chain and each voter chain in Blks/s +pub const PROPOSER_CHAIN_MINING_RATE: f32 = 0.100; -pub const ADVERSARY_MINING_POWER: f32 = 0.44; // the adversary power we want to tolerate +pub const ADVERSARY_MINING_POWER: f32 = 0.40; // the adversary power we want to tolerate pub const LOG_EPSILON: f32 = 20.0; // -ln(1-confirmation_guarantee) pub const ALPHA: f32 = (VOTER_CHAIN_MINING_RATE * NETWORK_DELAY) / (1.0 + VOTER_CHAIN_MINING_RATE * NETWORK_DELAY); // alpha = orphan blocks / total blocks diff --git a/testbed/run.sh b/testbed/run.sh index 0e77b08b..02041fb0 100755 --- a/testbed/run.sh +++ b/testbed/run.sh @@ -493,7 +493,7 @@ function start_transactions_single function start_mining_single { - curl -s "http://$3:$4/miner/start?lambda=247492&lazy=false" + curl -s "http://$3:$4/miner/start?lambda=222173&lazy=false" } function stop_transactions_single diff --git a/testbed/scripts/gen_prism_payload.py b/testbed/scripts/gen_prism_payload.py index 4c764667..d589c5e8 100644 --- a/testbed/scripts/gen_prism_payload.py +++ b/testbed/scripts/gen_prism_payload.py @@ -4,7 +4,7 @@ import subprocess template = """ -/home/ubuntu/payload/binary/prism --p2p {ip}:{p2p_port} --api {ip}:{api_port} --visual {ip}:{vis_port} --blockdb /tmp/prism/{node_name}-blockdb.rocksdb --blockchaindb /tmp/prism/{node_name}-blockchaindb.rocksdb --utxodb /tmp/prism/{node_name}-utxodb.rocksdb --walletdb /tmp/prism/{node_name}-wallet.rocksdb -vv --load-key /home/ubuntu/payload/prism-payload/{node_name}.pkcs8 {peer_opt} {fund_opt} --fund-coins=400000 --mempool-size=50000 +/home/ubuntu/payload/binary/prism --p2p {ip}:{p2p_port} --api {ip}:{api_port} --visual {ip}:{vis_port} --blockdb /tmp/prism/{node_name}-blockdb.rocksdb --blockchaindb /tmp/prism/{node_name}-blockchaindb.rocksdb --utxodb /tmp/prism/{node_name}-utxodb.rocksdb --walletdb /tmp/prism/{node_name}-wallet.rocksdb -vv --load-key /home/ubuntu/payload/prism-payload/{node_name}.pkcs8 {peer_opt} {fund_opt} --fund-coins=100000 --mempool-size=50000 """ instances_file = sys.argv[1] From 9d2bb9c404d44bff589267a55decd66dc246b4a4 Mon Sep 17 00:00:00 2001 From: Lei Yang Date: Sun, 1 Sep 2019 21:06:14 -0400 Subject: [PATCH 22/29] print out broadcast delay --- src/experiment/performance_counter.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/experiment/performance_counter.rs b/src/experiment/performance_counter.rs index 8c2750b6..c3e07054 100644 --- a/src/experiment/performance_counter.rs +++ b/src/experiment/performance_counter.rs @@ -153,6 +153,7 @@ impl Counter { }; match b.content { BlockContent::Transaction(_) => { + println!("Received Transaction Block Delay = {} ms", delay); self.total_transaction_block_delay .fetch_add(delay as usize, Ordering::Relaxed); self.total_transaction_block_squared_delay @@ -161,6 +162,7 @@ impl Counter { .fetch_add(1, Ordering::Relaxed); } BlockContent::Proposer(_) => { + println!("Received Proposer Block Delay = {} ms", delay); self.total_proposer_block_delay .fetch_add(delay as usize, Ordering::Relaxed); self.total_proposer_block_squared_delay @@ -169,6 +171,7 @@ impl Counter { .fetch_add(1, Ordering::Relaxed); } BlockContent::Voter(_) => { + println!("Received Voter Block Delay = {} ms", delay); self.total_voter_block_delay .fetch_add(delay as usize, Ordering::Relaxed); self.total_voter_block_squared_delay From eea7dd61eacbfafe68599d48111da5d53134a7e0 Mon Sep 17 00:00:00 2001 From: Lei Yang Date: Sun, 1 Sep 2019 21:15:30 -0400 Subject: [PATCH 23/29] add command to copy back logs --- testbed/.gitignore | 1 + testbed/run.sh | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/testbed/.gitignore b/testbed/.gitignore index 5dcde73c..ffa59843 100644 --- a/testbed/.gitignore +++ b/testbed/.gitignore @@ -1,5 +1,6 @@ *.svg *.png +nodelog data diff --git a/testbed/run.sh b/testbed/run.sh index 02041fb0..b7058a58 100755 --- a/testbed/run.sh +++ b/testbed/run.sh @@ -740,6 +740,25 @@ function set_tx_rate done } +function copy_log +{ + rm -rf nodelog + mkdir -p nodelog + local nodes=`cat nodes.txt` + local num_nodes=`cat nodes.txt | wc -l` + local pids='' + for node in $nodes; do + local name + local host + IFS=',' read -r name host _ _ _ _ _ <<< "$node" + (ssh $host -- "cat log/$name.log | gzip > nodelog.gzip" && scp $host:~/nodelog.gzip nodelog/$name.gzip) &> /dev/null & + pids="$pids $!" + done + for pid in $pids; do + wait $pid + done +} + mkdir -p log case "$1" in help) @@ -790,6 +809,7 @@ case "$1" in profile node f d Capture stack trace for node with frequency f and duration d flamegraph node Generate and download flamegraph for node open-dashboard Open the performance dashboard + copy-log Copy node log to nodelog/ Connect to Testbed @@ -873,6 +893,8 @@ case "$1" in scp_from_server $2 $3 $4 ;; read-log) read_log $2 ;; + copy-log) + copy_log ;; *) tput setaf 1 echo "Unrecognized subcommand '$1'" From f54336cd06b1b8640093a4af8897e4610858e243 Mon Sep 17 00:00:00 2001 From: Lei Yang Date: Mon, 2 Sep 2019 10:47:45 -0400 Subject: [PATCH 24/29] print network diameter --- testbed/scripts/generate_topo.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/testbed/scripts/generate_topo.py b/testbed/scripts/generate_topo.py index d3ec9fad..e225eb20 100644 --- a/testbed/scripts/generate_topo.py +++ b/testbed/scripts/generate_topo.py @@ -21,6 +21,8 @@ print("Unrecognized topology") sys.exit(1) +sys.stderr.write(str(nx.algorithms.distance_measures.diameter(graph))) + for node in graph.nodes(): name = "node_" + str(node) nodes.append(name) From 8ddfbe924315adba33151021719c6f0ba813cc74 Mon Sep 17 00:00:00 2001 From: Lei Yang Date: Mon, 2 Sep 2019 10:51:47 -0400 Subject: [PATCH 25/29] remove unused line --- testbed/scripts/generate_topo.py | 1 - 1 file changed, 1 deletion(-) diff --git a/testbed/scripts/generate_topo.py b/testbed/scripts/generate_topo.py index e225eb20..ff84683b 100644 --- a/testbed/scripts/generate_topo.py +++ b/testbed/scripts/generate_topo.py @@ -35,4 +35,3 @@ }) result = {"nodes": nodes, "connections": connections} print(json.dumps(result, sort_keys=True, indent=4)) -print(nx.complete_graph(100)) From 7ae9687fafb60d3be133e08711a83c6a98ce6702 Mon Sep 17 00:00:00 2001 From: Lei Yang Date: Mon, 2 Sep 2019 11:21:27 -0400 Subject: [PATCH 26/29] adjustable batch size --- testbed/run.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/testbed/run.sh b/testbed/run.sh index b7058a58..24dcb0c8 100755 --- a/testbed/run.sh +++ b/testbed/run.sh @@ -21,12 +21,13 @@ function start_instances echo "Launching $1 AWS EC2 instances" local instances="" local remaining=$1 + batchsize="100" while [ "$remaining" -gt "0" ] do - if [ "10" -gt "$remaining" ]; then + if [ "$batchsize" -gt "$remaining" ]; then local thisbatch="$remaining" else - local thisbatch="10" + local thisbatch="$batchsize" fi tput rc tput el @@ -493,7 +494,7 @@ function start_transactions_single function start_mining_single { - curl -s "http://$3:$4/miner/start?lambda=222173&lazy=false" + curl -s "http://$3:$4/miner/start?lambda=2221729&lazy=false" } function stop_transactions_single From 7bbc9fd05dc94512ca3ac4699291c2e5bbb2d27e Mon Sep 17 00:00:00 2001 From: Lei Yang Date: Mon, 2 Sep 2019 14:08:11 -0400 Subject: [PATCH 27/29] update method to fix ssh config --- testbed/run.sh | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/testbed/run.sh b/testbed/run.sh index 24dcb0c8..ca9bc400 100755 --- a/testbed/run.sh +++ b/testbed/run.sh @@ -77,14 +77,27 @@ function start_instances function fix_ssh_config { - local instances=`jq -r '.Instances[].InstanceId ' log/aws_start.log` + instances=`aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId][][]' --filters Name=instance-state-name,Values=running Name=tag-key,Values=prism --output text` rm -f instances.txt rm -f ~/.ssh/config.d/prism echo "Querying public IPs and writing to SSH config" - for instance in $instances ; + while [ 1 ] + do + rawdetails=`aws ec2 describe-instances --instance-ids $instances --query 'Reservations[*].Instances[*].{publicip:PublicIpAddress,id:InstanceId,privateip:PrivateIpAddress}[]'` + if echo $rawdetails | jq '.[].publicip' | grep null &> /dev/null ; then + echo "Waiting for public IP addresses to be assigned" + sleep 3 + continue + else + details=`echo "$rawdetails" | jq -c '.[]'` + break + fi + done + for instancedetail in $details; do - local ip=`aws ec2 describe-instances --instance-ids $instance | jq -r '.Reservations[0].Instances[0].PublicIpAddress'` - local lan=`aws ec2 describe-instances --instance-ids $instance | jq -r '.Reservations[0].Instances[0].PrivateIpAddress'` + local instance=`echo $instancedetail | jq -r '.id'` + local ip=`echo $instancedetail | jq -r '.publicip'` + local lan=`echo $instancedetail | jq -r '.privateip'` echo "$instance,$ip,$lan" >> instances.txt echo "Host $instance" >> ~/.ssh/config.d/prism echo " Hostname $ip" >> ~/.ssh/config.d/prism @@ -94,8 +107,10 @@ function fix_ssh_config echo " UserKnownHostsFile=/dev/null" >> ~/.ssh/config.d/prism echo "" >> ~/.ssh/config.d/prism done + echo "SSH config written, waiting for instances to initialize" + aws ec2 wait instance-running --instance-ids $instances tput setaf 2 - echo "SSH config written" + echo "Instances started" tput sgr0 } From 640c756496fa8ff4d64f6ad948c53634bff9367a Mon Sep 17 00:00:00 2001 From: Lei Yang Date: Mon, 2 Sep 2019 15:13:51 -0400 Subject: [PATCH 28/29] run 300 node test --- testbed/run.sh | 2 +- testbed/scripts/gen_prism_payload.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/testbed/run.sh b/testbed/run.sh index ca9bc400..56b50755 100755 --- a/testbed/run.sh +++ b/testbed/run.sh @@ -509,7 +509,7 @@ function start_transactions_single function start_mining_single { - curl -s "http://$3:$4/miner/start?lambda=2221729&lazy=false" + curl -s "http://$3:$4/miner/start?lambda=666519&lazy=false" } function stop_transactions_single diff --git a/testbed/scripts/gen_prism_payload.py b/testbed/scripts/gen_prism_payload.py index d589c5e8..226f00aa 100644 --- a/testbed/scripts/gen_prism_payload.py +++ b/testbed/scripts/gen_prism_payload.py @@ -4,7 +4,7 @@ import subprocess template = """ -/home/ubuntu/payload/binary/prism --p2p {ip}:{p2p_port} --api {ip}:{api_port} --visual {ip}:{vis_port} --blockdb /tmp/prism/{node_name}-blockdb.rocksdb --blockchaindb /tmp/prism/{node_name}-blockchaindb.rocksdb --utxodb /tmp/prism/{node_name}-utxodb.rocksdb --walletdb /tmp/prism/{node_name}-wallet.rocksdb -vv --load-key /home/ubuntu/payload/prism-payload/{node_name}.pkcs8 {peer_opt} {fund_opt} --fund-coins=100000 --mempool-size=50000 +/home/ubuntu/payload/binary/prism --p2p {ip}:{p2p_port} --api {ip}:{api_port} --visual {ip}:{vis_port} --blockdb /tmp/prism/{node_name}-blockdb.rocksdb --blockchaindb /tmp/prism/{node_name}-blockchaindb.rocksdb --utxodb /tmp/prism/{node_name}-utxodb.rocksdb --walletdb /tmp/prism/{node_name}-wallet.rocksdb -vv --load-key /home/ubuntu/payload/prism-payload/{node_name}.pkcs8 {peer_opt} {fund_opt} --fund-coins=40000 --mempool-size=50000 """ instances_file = sys.argv[1] From d42f81f90c29785e58860a63fb94332a631f1c71 Mon Sep 17 00:00:00 2001 From: Lei Yang Date: Mon, 2 Sep 2019 20:17:04 -0400 Subject: [PATCH 29/29] add template id in the other region --- testbed/run.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/testbed/run.sh b/testbed/run.sh index 56b50755..aee429b3 100755 --- a/testbed/run.sh +++ b/testbed/run.sh @@ -1,6 +1,7 @@ #!/bin/bash -LAUNCH_TEMPLATE=lt-02226ebae5fbef5f3 +#LAUNCH_TEMPLATE=lt-02226ebae5fbef5f3 # Ohio +LAUNCH_TEMPLATE=lt-09d74bbb3e4da1ff9 # N. Virginia function start_instances {