Skip to content

Commit

Permalink
Use next available key on duplicate coinbase commitment (#2737)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Hanjiang Yu authored and ignopeverell committed Apr 15, 2019
1 parent 606b465 commit 56fed50
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions servers/src/mining/mine_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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(),
);
}
Expand Down

0 comments on commit 56fed50

Please sign in to comment.