mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
fix: prevents potential arithmetic underflow (#8156)
This commit is contained in:
@ -119,7 +119,8 @@ impl AppendableChain {
|
|||||||
DB: Database + Clone,
|
DB: Database + Clone,
|
||||||
E: BlockExecutorProvider,
|
E: BlockExecutorProvider,
|
||||||
{
|
{
|
||||||
let parent_number = block.number - 1;
|
let parent_number =
|
||||||
|
block.number.checked_sub(1).ok_or(BlockchainTreeError::GenesisBlockHasNoParent)?;
|
||||||
let parent = self.blocks().get(&parent_number).ok_or(
|
let parent = self.blocks().get(&parent_number).ok_or(
|
||||||
BlockchainTreeError::BlockNumberNotFoundInChain { block_number: parent_number },
|
BlockchainTreeError::BlockNumberNotFoundInChain { block_number: parent_number },
|
||||||
)?;
|
)?;
|
||||||
|
|||||||
@ -47,6 +47,9 @@ pub enum BlockchainTreeError {
|
|||||||
/// The block hash of the block that failed to buffer.
|
/// The block hash of the block that failed to buffer.
|
||||||
block_hash: BlockHash,
|
block_hash: BlockHash,
|
||||||
},
|
},
|
||||||
|
/// Thrown when trying to access genesis parent.
|
||||||
|
#[error("genesis block has no parent")]
|
||||||
|
GenesisBlockHasNoParent,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Canonical Errors
|
/// Canonical Errors
|
||||||
@ -318,7 +321,8 @@ impl InsertBlockErrorKind {
|
|||||||
BlockchainTreeError::CanonicalChain { .. } |
|
BlockchainTreeError::CanonicalChain { .. } |
|
||||||
BlockchainTreeError::BlockNumberNotFoundInChain { .. } |
|
BlockchainTreeError::BlockNumberNotFoundInChain { .. } |
|
||||||
BlockchainTreeError::BlockHashNotFoundInChain { .. } |
|
BlockchainTreeError::BlockHashNotFoundInChain { .. } |
|
||||||
BlockchainTreeError::BlockBufferingFailed { .. } => false,
|
BlockchainTreeError::BlockBufferingFailed { .. } |
|
||||||
|
BlockchainTreeError::GenesisBlockHasNoParent => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
InsertBlockErrorKind::Provider(_) | InsertBlockErrorKind::Internal(_) => {
|
InsertBlockErrorKind::Provider(_) | InsertBlockErrorKind::Internal(_) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user