mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 19:09:54 +00:00
add use_self clippy lint (#8325)
This commit is contained in:
@ -81,17 +81,14 @@ impl CanonicalError {
|
||||
/// Returns `true` if the underlying error matches
|
||||
/// [BlockchainTreeError::BlockHashNotFoundInChain].
|
||||
pub fn is_block_hash_not_found(&self) -> bool {
|
||||
matches!(
|
||||
self,
|
||||
CanonicalError::BlockchainTree(BlockchainTreeError::BlockHashNotFoundInChain { .. })
|
||||
)
|
||||
matches!(self, Self::BlockchainTree(BlockchainTreeError::BlockHashNotFoundInChain { .. }))
|
||||
}
|
||||
|
||||
/// Returns `Some(BlockNumber)` if the underlying error matches
|
||||
/// [CanonicalError::OptimisticTargetRevert].
|
||||
pub fn optimistic_revert_block_number(&self) -> Option<BlockNumber> {
|
||||
match self {
|
||||
CanonicalError::OptimisticTargetRevert(block_number) => Some(*block_number),
|
||||
Self::OptimisticTargetRevert(block_number) => Some(*block_number),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@ -242,25 +239,25 @@ pub enum InsertBlockErrorKind {
|
||||
impl InsertBlockErrorKind {
|
||||
/// Returns true if the error is a tree error
|
||||
pub fn is_tree_error(&self) -> bool {
|
||||
matches!(self, InsertBlockErrorKind::Tree(_))
|
||||
matches!(self, Self::Tree(_))
|
||||
}
|
||||
|
||||
/// Returns true if the error is a consensus error
|
||||
pub fn is_consensus_error(&self) -> bool {
|
||||
matches!(self, InsertBlockErrorKind::Consensus(_))
|
||||
matches!(self, Self::Consensus(_))
|
||||
}
|
||||
|
||||
/// Returns true if this error is a state root error
|
||||
pub fn is_state_root_error(&self) -> bool {
|
||||
// we need to get the state root errors inside of the different variant branches
|
||||
match self {
|
||||
InsertBlockErrorKind::Execution(err) => {
|
||||
Self::Execution(err) => {
|
||||
matches!(
|
||||
err,
|
||||
BlockExecutionError::Validation(BlockValidationError::StateRoot { .. })
|
||||
)
|
||||
}
|
||||
InsertBlockErrorKind::Canonical(err) => {
|
||||
Self::Canonical(err) => {
|
||||
matches!(
|
||||
err,
|
||||
CanonicalError::Validation(BlockValidationError::StateRoot { .. }) |
|
||||
@ -270,7 +267,7 @@ impl InsertBlockErrorKind {
|
||||
)
|
||||
)
|
||||
}
|
||||
InsertBlockErrorKind::Provider(err) => {
|
||||
Self::Provider(err) => {
|
||||
matches!(
|
||||
err,
|
||||
ProviderError::StateRootMismatch(_) | ProviderError::UnwindStateRootMismatch(_)
|
||||
@ -285,9 +282,9 @@ impl InsertBlockErrorKind {
|
||||
/// This is intended to be used to determine if the block should be marked as invalid.
|
||||
pub fn is_invalid_block(&self) -> bool {
|
||||
match self {
|
||||
InsertBlockErrorKind::SenderRecovery | InsertBlockErrorKind::Consensus(_) => true,
|
||||
Self::SenderRecovery | Self::Consensus(_) => true,
|
||||
// other execution errors that are considered internal errors
|
||||
InsertBlockErrorKind::Execution(err) => {
|
||||
Self::Execution(err) => {
|
||||
match err {
|
||||
BlockExecutionError::Validation(_) | BlockExecutionError::Consensus(_) => {
|
||||
// this is caused by an invalid block
|
||||
@ -303,7 +300,7 @@ impl InsertBlockErrorKind {
|
||||
BlockExecutionError::Other(_) => false,
|
||||
}
|
||||
}
|
||||
InsertBlockErrorKind::Tree(err) => {
|
||||
Self::Tree(err) => {
|
||||
match err {
|
||||
BlockchainTreeError::PendingBlockIsFinalized { .. } => {
|
||||
// the block's number is lower than the finalized block's number
|
||||
@ -317,11 +314,11 @@ impl InsertBlockErrorKind {
|
||||
BlockchainTreeError::GenesisBlockHasNoParent => false,
|
||||
}
|
||||
}
|
||||
InsertBlockErrorKind::Provider(_) | InsertBlockErrorKind::Internal(_) => {
|
||||
Self::Provider(_) | Self::Internal(_) => {
|
||||
// any other error, such as database errors, are considered internal errors
|
||||
false
|
||||
}
|
||||
InsertBlockErrorKind::Canonical(err) => match err {
|
||||
Self::Canonical(err) => match err {
|
||||
CanonicalError::BlockchainTree(_) |
|
||||
CanonicalError::CanonicalCommit(_) |
|
||||
CanonicalError::CanonicalRevert(_) |
|
||||
@ -329,7 +326,7 @@ impl InsertBlockErrorKind {
|
||||
CanonicalError::Validation(_) => true,
|
||||
CanonicalError::Provider(_) => false,
|
||||
},
|
||||
InsertBlockErrorKind::BlockchainTree(_) => false,
|
||||
Self::BlockchainTree(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
@ -337,7 +334,7 @@ impl InsertBlockErrorKind {
|
||||
pub fn is_block_pre_merge(&self) -> bool {
|
||||
matches!(
|
||||
self,
|
||||
InsertBlockErrorKind::Execution(BlockExecutionError::Validation(
|
||||
Self::Execution(BlockExecutionError::Validation(
|
||||
BlockValidationError::BlockPreMerge { .. }
|
||||
))
|
||||
)
|
||||
@ -345,18 +342,18 @@ impl InsertBlockErrorKind {
|
||||
|
||||
/// Returns true if the error is an execution error
|
||||
pub fn is_execution_error(&self) -> bool {
|
||||
matches!(self, InsertBlockErrorKind::Execution(_))
|
||||
matches!(self, Self::Execution(_))
|
||||
}
|
||||
|
||||
/// Returns true if the error is an internal error
|
||||
pub fn is_internal(&self) -> bool {
|
||||
matches!(self, InsertBlockErrorKind::Internal(_))
|
||||
matches!(self, Self::Internal(_))
|
||||
}
|
||||
|
||||
/// Returns the error if it is a tree error
|
||||
pub fn as_tree_error(&self) -> Option<BlockchainTreeError> {
|
||||
match self {
|
||||
InsertBlockErrorKind::Tree(err) => Some(*err),
|
||||
Self::Tree(err) => Some(*err),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@ -364,7 +361,7 @@ impl InsertBlockErrorKind {
|
||||
/// Returns the error if it is a consensus error
|
||||
pub fn as_consensus_error(&self) -> Option<&ConsensusError> {
|
||||
match self {
|
||||
InsertBlockErrorKind::Consensus(err) => Some(err),
|
||||
Self::Consensus(err) => Some(err),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@ -372,7 +369,7 @@ impl InsertBlockErrorKind {
|
||||
/// Returns the error if it is an execution error
|
||||
pub fn as_execution_error(&self) -> Option<&BlockExecutionError> {
|
||||
match self {
|
||||
InsertBlockErrorKind::Execution(err) => Some(err),
|
||||
Self::Execution(err) => Some(err),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
@ -140,17 +140,17 @@ pub enum BlockValidationKind {
|
||||
impl BlockValidationKind {
|
||||
/// Returns true if the state root should be validated if possible.
|
||||
pub fn is_exhaustive(&self) -> bool {
|
||||
matches!(self, BlockValidationKind::Exhaustive)
|
||||
matches!(self, Self::Exhaustive)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for BlockValidationKind {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
BlockValidationKind::Exhaustive => {
|
||||
Self::Exhaustive => {
|
||||
write!(f, "Exhaustive")
|
||||
}
|
||||
BlockValidationKind::SkipStateRootValidation => {
|
||||
Self::SkipStateRootValidation => {
|
||||
write!(f, "SkipStateRootValidation")
|
||||
}
|
||||
}
|
||||
@ -179,22 +179,22 @@ impl CanonicalOutcome {
|
||||
/// Returns the header of the block that was made canonical.
|
||||
pub fn header(&self) -> &SealedHeader {
|
||||
match self {
|
||||
CanonicalOutcome::AlreadyCanonical { header, .. } => header,
|
||||
CanonicalOutcome::Committed { head } => head,
|
||||
Self::AlreadyCanonical { header, .. } => header,
|
||||
Self::Committed { head } => head,
|
||||
}
|
||||
}
|
||||
|
||||
/// Consumes the outcome and returns the header of the block that was made canonical.
|
||||
pub fn into_header(self) -> SealedHeader {
|
||||
match self {
|
||||
CanonicalOutcome::AlreadyCanonical { header, .. } => header,
|
||||
CanonicalOutcome::Committed { head } => head,
|
||||
Self::AlreadyCanonical { header, .. } => header,
|
||||
Self::Committed { head } => head,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns true if the block was already canonical.
|
||||
pub fn is_already_canonical(&self) -> bool {
|
||||
matches!(self, CanonicalOutcome::AlreadyCanonical { .. })
|
||||
matches!(self, Self::AlreadyCanonical { .. })
|
||||
}
|
||||
}
|
||||
|
||||
@ -241,7 +241,7 @@ impl BlockAttachment {
|
||||
/// Returns `true` if the block is canonical or a descendant of the canonical head.
|
||||
#[inline]
|
||||
pub const fn is_canonical(&self) -> bool {
|
||||
matches!(self, BlockAttachment::Canonical)
|
||||
matches!(self, Self::Canonical)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user