Skip to content

Commit

Permalink
chore: remove validate_block_regarding_chain (paradigmxyz#8224)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rjected authored May 13, 2024
1 parent 4fa6277 commit 12f1e9c
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 40 deletions.
2 changes: 0 additions & 2 deletions crates/consensus/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ workspace = true
[dependencies]
# reth
reth-primitives.workspace = true
reth-interfaces.workspace = true
reth-provider.workspace = true
reth-consensus.workspace=true

[dev-dependencies]
Expand Down
39 changes: 1 addition & 38 deletions crates/consensus/common/src/validation.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
//! Collection of methods for block validation.
use reth_consensus::ConsensusError;
use reth_interfaces::RethResult;
use reth_primitives::{
constants::{
eip4844::{DATA_GAS_PER_BLOB, MAX_DATA_GAS_PER_BLOCK},
MAXIMUM_EXTRA_DATA_SIZE,
},
ChainSpec, GotExpected, Hardfork, Header, SealedBlock, SealedHeader,
};
use reth_provider::{HeaderProvider, WithdrawalsProvider};

/// Validate header standalone
pub fn validate_header_standalone(
Expand Down Expand Up @@ -110,33 +108,6 @@ pub fn validate_block_standalone(
Ok(())
}

/// Validate block with regard to chain (parent)
///
/// Checks:
/// If we already know the block.
/// If parent is known
///
/// Returns parent block header
pub fn validate_block_regarding_chain<PROV: HeaderProvider + WithdrawalsProvider>(
block: &SealedBlock,
provider: &PROV,
) -> RethResult<SealedHeader> {
let hash = block.header.hash();

// Check if block is known.
if provider.is_known(&hash)? {
return Err(ConsensusError::BlockKnown { hash, number: block.header.number }.into())
}

// Check if parent is known.
let parent = provider
.header(&block.parent_hash)?
.ok_or(ConsensusError::ParentUnknown { hash: block.parent_hash })?;

// Return parent header.
Ok(parent.seal(block.parent_hash))
}

/// Validates that the EIP-4844 header fields exist and conform to the spec. This ensures that:
///
/// * `blob_gas_used` exists as a header field
Expand Down Expand Up @@ -204,7 +175,7 @@ mod tests {
BlockNumber, Bytes, ChainSpecBuilder, Signature, Transaction, TransactionSigned, TxEip4844,
Withdrawal, Withdrawals, U256,
};
use reth_provider::AccountReader;
use reth_provider::{AccountReader, HeaderProvider, WithdrawalsProvider};
use std::ops::RangeBounds;

mock! {
Expand Down Expand Up @@ -398,22 +369,14 @@ mod tests {
assert_eq!(validate_block_standalone(&block, &chain_spec), Ok(()));
let block = create_block_with_withdrawals(&[5, 6, 7, 8, 9]);
assert_eq!(validate_block_standalone(&block, &chain_spec), Ok(()));

let (_, parent) = mock_block();
let provider = Provider::new(Some(parent.clone()));
let block = create_block_with_withdrawals(&[0, 1, 2]);
let res = validate_block_regarding_chain(&block, &provider);
assert!(res.is_ok());

// Withdrawal index should be the last withdrawal index + 1
let mut provider = Provider::new(Some(parent));
let block = create_block_with_withdrawals(&[3, 4, 5]);
provider
.withdrawals_provider
.expect_latest_withdrawal()
.return_const(Ok(Some(Withdrawal { index: 2, ..Default::default() })));
let res = validate_block_regarding_chain(&block, &provider);
assert!(res.is_ok());
}

#[test]
Expand Down

0 comments on commit 12f1e9c

Please sign in to comment.