chore: remove validate_block_regarding_chain (#8224)

This commit is contained in:
Dan Cline
2024-05-13 17:07:37 +03:00
committed by GitHub
parent 4fa6277366
commit 12f1e9c944
2 changed files with 1 additions and 40 deletions

View File

@ -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]

View File

@ -1,7 +1,6 @@
//! 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},
@ -9,7 +8,6 @@ use reth_primitives::{
},
ChainSpec, GotExpected, Hardfork, Header, SealedBlock, SealedHeader,
};
use reth_provider::{HeaderProvider, WithdrawalsProvider};
/// Validate header standalone
pub fn validate_header_standalone(
@ -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
@ -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! {
@ -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]