feat: relax on new head in validator (#13352)

This commit is contained in:
Matthias Seitz
2024-12-13 14:59:40 +01:00
committed by GitHub
parent bed722b267
commit ed2c69295d
6 changed files with 51 additions and 25 deletions

1
Cargo.lock generated
View File

@ -8530,6 +8530,7 @@ dependencies = [
"reth-payload-util", "reth-payload-util",
"reth-payload-validator", "reth-payload-validator",
"reth-primitives", "reth-primitives",
"reth-primitives-traits",
"reth-provider", "reth-provider",
"reth-revm", "reth-revm",
"reth-rpc-server-types", "reth-rpc-server-types",

View File

@ -16,6 +16,7 @@ reth-chainspec.workspace = true
reth-db.workspace = true reth-db.workspace = true
reth-engine-local.workspace = true reth-engine-local.workspace = true
reth-primitives.workspace = true reth-primitives.workspace = true
reth-primitives-traits.workspace = true
reth-payload-builder.workspace = true reth-payload-builder.workspace = true
reth-payload-util.workspace = true reth-payload-util.workspace = true
reth-payload-validator.workspace = true reth-payload-validator.workspace = true
@ -110,25 +111,26 @@ js-tracer = [
"reth-node-builder/js-tracer" "reth-node-builder/js-tracer"
] ]
test-utils = [ test-utils = [
"reth-tasks", "reth-tasks",
"reth-e2e-test-utils", "reth-e2e-test-utils",
"alloy-genesis", "alloy-genesis",
"tokio", "tokio",
"reth-node-builder/test-utils", "reth-node-builder/test-utils",
"reth-chainspec/test-utils", "reth-chainspec/test-utils",
"reth-consensus/test-utils", "reth-consensus/test-utils",
"reth-evm/test-utils", "reth-evm/test-utils",
"reth-network/test-utils", "reth-network/test-utils",
"reth-payload-builder/test-utils", "reth-payload-builder/test-utils",
"reth-primitives/test-utils", "reth-primitives/test-utils",
"reth-revm/test-utils", "reth-revm/test-utils",
"reth-db/test-utils", "reth-db/test-utils",
"reth-provider/test-utils", "reth-provider/test-utils",
"reth-transaction-pool/test-utils", "reth-transaction-pool/test-utils",
"reth-trie-db/test-utils", "reth-trie-db/test-utils",
"revm/test-utils", "revm/test-utils",
"reth-optimism-node/test-utils", "reth-optimism-node/test-utils",
"reth-optimism-primitives/arbitrary", "reth-optimism-primitives/arbitrary",
"reth-primitives-traits/test-utils"
] ]
reth-codec = [ reth-codec = [
"reth-primitives/reth-codec", "reth-primitives/reth-codec",

View File

@ -222,7 +222,11 @@ where
self.validate_all(transactions) self.validate_all(transactions)
} }
fn on_new_head_block(&self, new_tip_block: &SealedBlock) { fn on_new_head_block<H, B>(&self, new_tip_block: &SealedBlock<H, B>)
where
H: reth_primitives_traits::BlockHeader,
B: BlockBody,
{
self.inner.on_new_head_block(new_tip_block); self.inner.on_new_head_block(new_tip_block);
self.update_l1_block_info( self.update_l1_block_info(
new_tip_block.header(), new_tip_block.header(),

View File

@ -24,7 +24,7 @@ use alloy_eips::{
}; };
use reth_chainspec::{ChainSpec, EthereumHardforks}; use reth_chainspec::{ChainSpec, EthereumHardforks};
use reth_primitives::{InvalidTransactionError, SealedBlock}; use reth_primitives::{InvalidTransactionError, SealedBlock};
use reth_primitives_traits::GotExpected; use reth_primitives_traits::{BlockBody, GotExpected};
use reth_storage_api::{AccountReader, StateProviderFactory}; use reth_storage_api::{AccountReader, StateProviderFactory};
use reth_tasks::TaskSpawner; use reth_tasks::TaskSpawner;
use std::{ use std::{
@ -106,7 +106,11 @@ where
self.validate_all(transactions) self.validate_all(transactions)
} }
fn on_new_head_block(&self, new_tip_block: &SealedBlock) { fn on_new_head_block<H, B>(&self, new_tip_block: &SealedBlock<H, B>)
where
H: reth_primitives_traits::BlockHeader,
B: BlockBody,
{
self.inner.on_new_head_block(new_tip_block.header()) self.inner.on_new_head_block(new_tip_block.header())
} }
} }

View File

@ -26,6 +26,7 @@ pub use task::{TransactionValidationTaskExecutor, ValidationTask};
pub use constants::{ pub use constants::{
DEFAULT_MAX_TX_INPUT_BYTES, MAX_CODE_BYTE_SIZE, MAX_INIT_CODE_BYTE_SIZE, TX_SLOT_BYTE_SIZE, DEFAULT_MAX_TX_INPUT_BYTES, MAX_CODE_BYTE_SIZE, MAX_INIT_CODE_BYTE_SIZE, TX_SLOT_BYTE_SIZE,
}; };
use reth_primitives_traits::{BlockBody, BlockHeader};
/// A Result type returned after checking a transaction's validity. /// A Result type returned after checking a transaction's validity.
#[derive(Debug)] #[derive(Debug)]
@ -206,7 +207,12 @@ pub trait TransactionValidator: Send + Sync {
/// Invoked when the head block changes. /// Invoked when the head block changes.
/// ///
/// This can be used to update fork specific values (timestamp). /// This can be used to update fork specific values (timestamp).
fn on_new_head_block(&self, _new_tip_block: &SealedBlock) {} fn on_new_head_block<H, B>(&self, _new_tip_block: &SealedBlock<H, B>)
where
H: BlockHeader,
B: BlockBody,
{
}
} }
impl<A, B> TransactionValidator for Either<A, B> impl<A, B> TransactionValidator for Either<A, B>
@ -237,7 +243,11 @@ where
} }
} }
fn on_new_head_block(&self, new_tip_block: &SealedBlock) { fn on_new_head_block<H, Body>(&self, new_tip_block: &SealedBlock<H, Body>)
where
H: BlockHeader,
Body: BlockBody,
{
match self { match self {
Self::Left(v) => v.on_new_head_block(new_tip_block), Self::Left(v) => v.on_new_head_block(new_tip_block),
Self::Right(v) => v.on_new_head_block(new_tip_block), Self::Right(v) => v.on_new_head_block(new_tip_block),

View File

@ -9,6 +9,7 @@ use crate::{
use futures_util::{lock::Mutex, StreamExt}; use futures_util::{lock::Mutex, StreamExt};
use reth_chainspec::ChainSpec; use reth_chainspec::ChainSpec;
use reth_primitives::SealedBlock; use reth_primitives::SealedBlock;
use reth_primitives_traits::{BlockBody, BlockHeader};
use reth_tasks::TaskSpawner; use reth_tasks::TaskSpawner;
use std::{future::Future, pin::Pin, sync::Arc}; use std::{future::Future, pin::Pin, sync::Arc};
use tokio::{ use tokio::{
@ -205,7 +206,11 @@ where
} }
} }
fn on_new_head_block(&self, new_tip_block: &SealedBlock) { fn on_new_head_block<H, B>(&self, new_tip_block: &SealedBlock<H, B>)
where
H: BlockHeader,
B: BlockBody,
{
self.validator.on_new_head_block(new_tip_block) self.validator.on_new_head_block(new_tip_block)
} }
} }