Skip to content

Commit

Permalink
fix(grpc): return bool if mempool is out of sync instead of returning…
Browse files Browse the repository at this point in the history
… an error
  • Loading branch information
stringhandler committed Dec 19, 2024
1 parent 71efa03 commit 68acc48
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
3 changes: 3 additions & 0 deletions applications/minotari_app_grpc/proto/block.proto
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,8 @@ message NewBlockTemplate {
// This flag indicates if the inputs, outputs and kernels have been sorted internally, that is, the sort() method
// has been called. This may be false even if all components are sorted.
AggregateBody body = 2;
// Sometimes the mempool has not synced to the latest tip, this flag indicates if the mempool is out of sync.
// In most cases the next call to get_new_block_template will return a block with the mempool in sync.
bool is_mempool_in_sync = 3;
}

Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ impl TryFrom<NewBlockTemplate> for grpc::NewBlockTemplate {
.collect(),
}),
header: Some(header),
is_mempool_in_sync: block.is_mempool_in_sync,
})
}
}
Expand Down Expand Up @@ -105,6 +106,7 @@ impl TryFrom<grpc::NewBlockTemplate> for NewBlockTemplate {
target_difficulty: Default::default(),
reward: Default::default(),
total_fees: Default::default(),
is_mempool_in_sync: block.is_mempool_in_sync,
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -258,18 +258,15 @@ 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 {
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()
);
return Err(CommsInterfaceError::InternalError(
"Mempool out of sync, blockchain db advanced passed current tip in mempool storage; this \
should auto correct with the next block template request"
.to_string(),
));
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 Expand Up @@ -313,6 +310,7 @@ where B: BlockchainBackend + 'static
self.get_target_difficulty_for_next_block(request.algo, constants, prev_hash)
.await?,
self.consensus_manager.get_block_reward_at(height),
is_mempool_synced,
)?;

debug!(target: LOG_TARGET,
Expand Down
5 changes: 5 additions & 0 deletions base_layer/core/src/blocks/new_block_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,17 @@ pub struct NewBlockTemplate {
pub reward: MicroMinotari,
/// The total fees is the sum of all the fees in the block.
pub total_fees: MicroMinotari,
/// Sometimes the mempool has not synced to the latest tip, this flag indicates if the mempool is out of sync.
/// In most cases the next call to get_new_block_template will return a block with the mempool in sync.
pub is_mempool_in_sync: bool,
}

impl NewBlockTemplate {
pub fn from_block(
block: Block,
target_difficulty: Difficulty,
reward: MicroMinotari,
is_mempool_in_sync: bool,
) -> Result<Self, TransactionError> {
let Block { header, body } = block;
let total_fees = body.get_total_fee()?;
Expand All @@ -67,6 +71,7 @@ impl NewBlockTemplate {
target_difficulty,
reward,
total_fees,
is_mempool_in_sync,
})
}
}
Expand Down

0 comments on commit 68acc48

Please sign in to comment.