mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: introduce iterator for default_ethereum_payload function (#11978)
This commit is contained in:
@ -33,7 +33,8 @@ use reth_primitives::{
|
||||
use reth_provider::{ChainSpecProvider, StateProviderFactory};
|
||||
use reth_revm::database::StateProviderDatabase;
|
||||
use reth_transaction_pool::{
|
||||
noop::NoopTransactionPool, BestTransactionsAttributes, TransactionPool,
|
||||
noop::NoopTransactionPool, BestTransactions, BestTransactionsAttributes, TransactionPool,
|
||||
ValidPoolTransaction,
|
||||
};
|
||||
use reth_trie::HashedPostState;
|
||||
use revm::{
|
||||
@ -45,6 +46,10 @@ use revm_primitives::calc_excess_blob_gas;
|
||||
use std::sync::Arc;
|
||||
use tracing::{debug, trace, warn};
|
||||
|
||||
type BestTransactionsIter<Pool> = Box<
|
||||
dyn BestTransactions<Item = Arc<ValidPoolTransaction<<Pool as TransactionPool>::Transaction>>>,
|
||||
>;
|
||||
|
||||
/// Ethereum payload builder
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct EthereumPayloadBuilder<EvmConfig = EthEvmConfig> {
|
||||
@ -94,7 +99,11 @@ where
|
||||
args: BuildArguments<Pool, Client, EthPayloadBuilderAttributes, EthBuiltPayload>,
|
||||
) -> Result<BuildOutcome<EthBuiltPayload>, PayloadBuilderError> {
|
||||
let (cfg_env, block_env) = self.cfg_and_block_env(&args.config, &args.config.parent_block);
|
||||
default_ethereum_payload(self.evm_config.clone(), args, cfg_env, block_env)
|
||||
|
||||
let pool = args.pool.clone();
|
||||
default_ethereum_payload(self.evm_config.clone(), args, cfg_env, block_env, |attributes| {
|
||||
pool.best_transactions_with_attributes(attributes)
|
||||
})
|
||||
}
|
||||
|
||||
fn build_empty_payload(
|
||||
@ -102,19 +111,25 @@ where
|
||||
client: &Client,
|
||||
config: PayloadConfig<Self::Attributes>,
|
||||
) -> Result<EthBuiltPayload, PayloadBuilderError> {
|
||||
let args = BuildArguments {
|
||||
let args = BuildArguments::new(
|
||||
client,
|
||||
config,
|
||||
// we use defaults here because for the empty payload we don't need to execute anything
|
||||
pool: NoopTransactionPool::default(),
|
||||
cached_reads: Default::default(),
|
||||
cancel: Default::default(),
|
||||
best_payload: None,
|
||||
};
|
||||
NoopTransactionPool::default(),
|
||||
Default::default(),
|
||||
config,
|
||||
Default::default(),
|
||||
None,
|
||||
);
|
||||
|
||||
let (cfg_env, block_env) = self.cfg_and_block_env(&args.config, &args.config.parent_block);
|
||||
default_ethereum_payload(self.evm_config.clone(), args, cfg_env, block_env)?
|
||||
.into_payload()
|
||||
.ok_or_else(|| PayloadBuilderError::MissingPayload)
|
||||
|
||||
let pool = args.pool.clone();
|
||||
|
||||
default_ethereum_payload(self.evm_config.clone(), args, cfg_env, block_env, |attributes| {
|
||||
pool.best_transactions_with_attributes(attributes)
|
||||
})?
|
||||
.into_payload()
|
||||
.ok_or_else(|| PayloadBuilderError::MissingPayload)
|
||||
}
|
||||
}
|
||||
|
||||
@ -124,16 +139,18 @@ where
|
||||
/// and configuration, this function creates a transaction payload. Returns
|
||||
/// a result indicating success with the payload or an error in case of failure.
|
||||
#[inline]
|
||||
pub fn default_ethereum_payload<EvmConfig, Pool, Client>(
|
||||
pub fn default_ethereum_payload<EvmConfig, Pool, Client, F>(
|
||||
evm_config: EvmConfig,
|
||||
args: BuildArguments<Pool, Client, EthPayloadBuilderAttributes, EthBuiltPayload>,
|
||||
initialized_cfg: CfgEnvWithHandlerCfg,
|
||||
initialized_block_env: BlockEnv,
|
||||
best_txs: F,
|
||||
) -> Result<BuildOutcome<EthBuiltPayload>, PayloadBuilderError>
|
||||
where
|
||||
EvmConfig: ConfigureEvm<Header = Header>,
|
||||
Client: StateProviderFactory + ChainSpecProvider<ChainSpec = ChainSpec>,
|
||||
Pool: TransactionPool,
|
||||
F: FnOnce(BestTransactionsAttributes) -> BestTransactionsIter<Pool>,
|
||||
{
|
||||
let BuildArguments { client, pool, mut cached_reads, config, cancel, best_payload } = args;
|
||||
|
||||
@ -153,11 +170,10 @@ where
|
||||
let mut executed_txs = Vec::new();
|
||||
let mut executed_senders = Vec::new();
|
||||
|
||||
let mut best_txs = pool.best_transactions_with_attributes(BestTransactionsAttributes::new(
|
||||
let mut best_txs = best_txs(BestTransactionsAttributes::new(
|
||||
base_fee,
|
||||
initialized_block_env.get_blob_gasprice().map(|gasprice| gasprice as u64),
|
||||
));
|
||||
|
||||
let mut total_fees = U256::ZERO;
|
||||
|
||||
let block_number = initialized_block_env.number.to::<u64>();
|
||||
|
||||
Reference in New Issue
Block a user