chore(tree): CanonicalError::is_block_hash_not_found (#7675)

This commit is contained in:
Roman Krasiuk
2024-04-16 16:10:40 +02:00
committed by GitHub
parent f8fb334e35
commit 90b07427b9
2 changed files with 11 additions and 12 deletions

View File

@ -1434,12 +1434,7 @@ where
if let Err((hash, error)) =
self.try_make_sync_target_canonical(downloaded_num_hash)
{
if !matches!(
error,
CanonicalError::BlockchainTree(
BlockchainTreeError::BlockHashNotFoundInChain { .. }
)
) {
if !error.is_block_hash_not_found() {
if error.is_fatal() {
error!(target: "consensus::engine", %error, "Encountered fatal error while making sync target canonical: {:?}, {:?}", error, hash);
} else {
@ -1572,12 +1567,7 @@ where
// if we failed to make the FCU's head canonical, because we don't have that
// block yet, then we can try to make the inserted block canonical if we know
// it's part of the canonical chain: if it's the safe or the finalized block
if matches!(
err,
CanonicalError::BlockchainTree(
BlockchainTreeError::BlockHashNotFoundInChain { .. }
)
) {
if err.is_block_hash_not_found() {
// if the inserted block is the currently targeted `finalized` or `safe`
// block, we will attempt to make them canonical,
// because they are also part of the canonical chain and

View File

@ -74,6 +74,15 @@ impl CanonicalError {
pub fn is_fatal(&self) -> bool {
matches!(self, Self::CanonicalCommit(_) | Self::CanonicalRevert(_))
}
/// Returns `true` if the underlying error matches
/// [BlockchainTreeError::BlockHashNotFoundInChain].
pub fn is_block_hash_not_found(&self) -> bool {
matches!(
self,
CanonicalError::BlockchainTree(BlockchainTreeError::BlockHashNotFoundInChain { .. })
)
}
}
/// Error thrown when inserting a block failed because the block is considered invalid.