Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(grpc): return bool if mempool is out of sync instead of returning… #6728

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading