From 30ad3bb7aeaffe8736986e3376ece1acf0f868cc Mon Sep 17 00:00:00 2001 From: antiochp <30642645+antiochp@users.noreply.github.com> Date: Tue, 22 Jan 2019 12:47:18 +0000 Subject: [PATCH 1/4] fallback to empty vec of txs when building block from mineable txs --- servers/src/mining/mine_block.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/servers/src/mining/mine_block.rs b/servers/src/mining/mine_block.rs index 235433fe3..7a21cf895 100644 --- a/servers/src/mining/mine_block.rs +++ b/servers/src/mining/mine_block.rs @@ -107,8 +107,11 @@ fn build_block( // Note: do not keep the difficulty_iter in scope (it has an active batch). let difficulty = consensus::next_difficulty(head.height + 1, chain.difficulty_iter()); - // extract current transaction from the pool - let txs = tx_pool.read().prepare_mineable_transactions()?; + // Extract current "mineable" transactions from the pool. + // If this fails for *any* reason then fallback to an empty vec of txs. + // This will allow us to mine an "empty" block if the txpool is in an + // invalid (and unexpected) state. + let txs = tx_pool.read().prepare_mineable_transactions().unwrap_or(vec![]); // build the coinbase and the block itself let fees = txs.iter().map(|tx| tx.fee()).sum(); @@ -138,21 +141,18 @@ fn build_block( ); // Now set txhashset roots and sizes on the header of the block being built. - let roots_result = chain.set_txhashset_roots(&mut b); - - match roots_result { + match chain.set_txhashset_roots(&mut b) { Ok(_) => Ok((b, block_fees)), - - // If it's a duplicate commitment, it's likely trying to use - // a key that's already been derived but not in the wallet - // for some reason, allow caller to retry Err(e) => { match e.kind() { + // If this is a duplicate commitment then likely trying to use + // a key that hass already been derived but not in the wallet + // for some reason, allow caller to retry. chain::ErrorKind::DuplicateCommitment(e) => Err(Error::Chain( chain::ErrorKind::DuplicateCommitment(e).into(), )), - //Some other issue, possibly duplicate kernel + // Some other issue, possibly duplicate kernel _ => { error!("Error setting txhashset root to build a block: {:?}", e); Err(Error::Chain( From ba9a362d023a711c5433e33e0f59561dc282f897 Mon Sep 17 00:00:00 2001 From: antiochp <30642645+antiochp@users.noreply.github.com> Date: Tue, 22 Jan 2019 14:12:46 +0000 Subject: [PATCH 2/4] rustfmt --- servers/src/mining/mine_block.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/servers/src/mining/mine_block.rs b/servers/src/mining/mine_block.rs index 7a21cf895..379ac45a9 100644 --- a/servers/src/mining/mine_block.rs +++ b/servers/src/mining/mine_block.rs @@ -111,7 +111,10 @@ fn build_block( // If this fails for *any* reason then fallback to an empty vec of txs. // This will allow us to mine an "empty" block if the txpool is in an // invalid (and unexpected) state. - let txs = tx_pool.read().prepare_mineable_transactions().unwrap_or(vec![]); + let txs = tx_pool + .read() + .prepare_mineable_transactions() + .unwrap_or(vec![]); // build the coinbase and the block itself let fees = txs.iter().map(|tx| tx.fee()).sum(); From ba25592f159fa1891905df5b0aea8b6ca9099270 Mon Sep 17 00:00:00 2001 From: antiochp <30642645+antiochp@users.noreply.github.com> Date: Wed, 23 Jan 2019 10:49:16 +0000 Subject: [PATCH 3/4] log loudly if we fail to prepare txs for mining --- servers/src/mining/mine_block.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/servers/src/mining/mine_block.rs b/servers/src/mining/mine_block.rs index 379ac45a9..0e8e7632c 100644 --- a/servers/src/mining/mine_block.rs +++ b/servers/src/mining/mine_block.rs @@ -111,10 +111,14 @@ fn build_block( // If this fails for *any* reason then fallback to an empty vec of txs. // This will allow us to mine an "empty" block if the txpool is in an // invalid (and unexpected) state. - let txs = tx_pool - .read() - .prepare_mineable_transactions() - .unwrap_or(vec![]); + let txs = match tx_pool.read().prepare_mineable_transactions() { + Ok(txs) => txs, + Err(e) => { + error!("build_block: Failed to prepare mineable txs from txpool: {:?}", e); + warn!("build_block: Falling back to mining empty block."); + vec![] + } + }; // build the coinbase and the block itself let fees = txs.iter().map(|tx| tx.fee()).sum(); From 61fe1418ef48d7876450e98e4d4fb58e4554c828 Mon Sep 17 00:00:00 2001 From: antiochp <30642645+antiochp@users.noreply.github.com> Date: Wed, 23 Jan 2019 10:49:47 +0000 Subject: [PATCH 4/4] rustfmt --- servers/src/mining/mine_block.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/servers/src/mining/mine_block.rs b/servers/src/mining/mine_block.rs index 0e8e7632c..aee1f2041 100644 --- a/servers/src/mining/mine_block.rs +++ b/servers/src/mining/mine_block.rs @@ -114,7 +114,10 @@ fn build_block( let txs = match tx_pool.read().prepare_mineable_transactions() { Ok(txs) => txs, Err(e) => { - error!("build_block: Failed to prepare mineable txs from txpool: {:?}", e); + error!( + "build_block: Failed to prepare mineable txs from txpool: {:?}", + e + ); warn!("build_block: Falling back to mining empty block."); vec![] }