From 56fed5093e971f109b2461ed531c305b0de0166a Mon Sep 17 00:00:00 2001 From: Hanjiang Yu Date: Tue, 16 Apr 2019 06:16:33 +0800 Subject: [PATCH] Use next available key on duplicate coinbase commitment (#2737) If a coinbase commitment hits a duplication and there is no transactions to mine, it is possible that coinbase cannot be built for quite a long time. This change tries to build coinbase with an empty key identifier immediately in this case. The listening wallet will then use the next available key to build a coinbase commitment, which is different from the previous one and is unlikely to hit the duplication. --- servers/src/mining/mine_block.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/servers/src/mining/mine_block.rs b/servers/src/mining/mine_block.rs index 7de0f3ff9e..f548149fe3 100644 --- a/servers/src/mining/mine_block.rs +++ b/servers/src/mining/mine_block.rs @@ -51,12 +51,15 @@ pub fn get_block( wallet_listener_url.clone(), ); while let Err(e) = result { + let mut new_key_id = key_id.to_owned(); match e { self::Error::Chain(c) => match c.kind() { chain::ErrorKind::DuplicateCommitment(_) => { debug!( "Duplicate commit for potential coinbase detected. Trying next derivation." ); + // use the next available key to generate a different coinbase commitment + new_key_id = None; } _ => { error!("Chain Error: {}", c); @@ -73,12 +76,18 @@ pub fn get_block( warn!("Error building new block: {:?}. Retrying.", ae); } } - thread::sleep(Duration::from_millis(100)); + + // only wait if we are still using the same key: a different coinbase commitment is unlikely + // to have duplication + if new_key_id.is_some() { + thread::sleep(Duration::from_millis(100)); + } + result = build_block( chain, tx_pool, verifier_cache.clone(), - key_id.clone(), + new_key_id, wallet_listener_url.clone(), ); }