Skip to content

Commit

Permalink
fix templates
Browse files Browse the repository at this point in the history
  • Loading branch information
SWvheerden committed Jan 6, 2025
1 parent 2e3f039 commit 71e5145
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions base_layer/core/src/base_node/comms_interface/inbound_handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,16 +257,29 @@ where B: BlockchainBackend + 'static
},
NodeCommsRequest::GetNewBlockTemplate(request) => {
let best_block_header = self.blockchain_db.fetch_tip_header().await?;
let last_seen_hash = self.mempool.get_last_seen_hash().await?;
let mut is_mempool_synced = true;
if last_seen_hash != FixedHash::default() && best_block_header.hash() != &last_seen_hash {
let mut last_seen_hash = self.mempool.get_last_seen_hash().await?;
let mut is_mempool_synced = false;
let mut counter = 0;
// this will wait a max of 100ms before returning anyway with a potential broken template
// We need to ensure the mempool has seen the latest base node height before we can be confident the
// template is correct
while !is_mempool_synced && counter < 10 {
if best_block_header.hash() == &last_seen_hash {
is_mempool_synced = true;
} else {
tokio::time::sleep(std::time::Duration::from_millis(10)).await;
last_seen_hash = self.mempool.get_last_seen_hash().await?;
counter += 1;
}
}

if !is_mempool_synced {
warn!(
target: LOG_TARGET,
"Mempool out of sync - last seen hash '{}' does not match the tip hash '{}'. This condition \
should auto correct with the next block template request",
last_seen_hash, best_block_header.hash()
);
is_mempool_synced = false;
}
let mut header = BlockHeader::from_previous(best_block_header.header());
let constants = self.consensus_manager.consensus_constants(header.height);
Expand Down

0 comments on commit 71e5145

Please sign in to comment.