mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-26 15:48:13 -05:00
Created GeneratePayloadAttributes e2e Action (#15234)
Co-authored-by: Federico Gimenez <fgimenez@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
914fc51f23
commit
d456af044e
@@ -225,6 +225,37 @@ where
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// Store payload attributes for the next block.
|
||||
#[derive(Debug, Default)]
|
||||
pub struct GeneratePayloadAttributes {}
|
||||
|
||||
impl<Engine> Action<Engine> for GeneratePayloadAttributes
|
||||
where
|
||||
Engine: EngineTypes,
|
||||
{
|
||||
fn execute<'a>(&'a mut self, env: &'a mut Environment<Engine>) -> BoxFuture<'a, Result<()>> {
|
||||
Box::pin(async move {
|
||||
let latest_block = env
|
||||
.latest_block_info
|
||||
.as_ref()
|
||||
.ok_or_else(|| eyre::eyre!("No latest block information available"))?;
|
||||
let block_number = latest_block.number;
|
||||
let timestamp = env.latest_header_time + env.block_timestamp_increment;
|
||||
let payload_attributes = alloy_rpc_types_engine::PayloadAttributes {
|
||||
timestamp,
|
||||
prev_randao: B256::random(),
|
||||
suggested_fee_recipient: alloy_primitives::Address::random(),
|
||||
withdrawals: Some(vec![]),
|
||||
parent_beacon_block_root: Some(B256::ZERO),
|
||||
};
|
||||
|
||||
env.payload_attributes.insert(latest_block.number + 1, payload_attributes);
|
||||
debug!("Stored payload attributes for block {}", block_number + 1);
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
}
|
||||
/// Action that produces a sequence of blocks using the available clients
|
||||
#[derive(Debug)]
|
||||
pub struct ProduceBlocks<Engine> {
|
||||
@@ -254,7 +285,10 @@ where
|
||||
fn execute<'a>(&'a mut self, env: &'a mut Environment<Engine>) -> BoxFuture<'a, Result<()>> {
|
||||
Box::pin(async move {
|
||||
// Create a sequence for producing a single block
|
||||
let mut sequence = Sequence::new(vec![Box::new(PickNextBlockProducer::default())]);
|
||||
let mut sequence = Sequence::new(vec![
|
||||
Box::new(PickNextBlockProducer::default()),
|
||||
Box::new(GeneratePayloadAttributes::default()),
|
||||
]);
|
||||
for _ in 0..self.num_blocks {
|
||||
sequence.execute(env).await?;
|
||||
}
|
||||
|
||||
@@ -11,9 +11,10 @@ use reth_engine_local::LocalPayloadAttributesBuilder;
|
||||
use reth_node_api::{NodeTypesWithEngine, PayloadTypes};
|
||||
use reth_rpc_layer::AuthClientService;
|
||||
use setup::Setup;
|
||||
use std::marker::PhantomData;
|
||||
use std::{collections::HashMap, marker::PhantomData};
|
||||
pub mod actions;
|
||||
pub mod setup;
|
||||
use alloy_rpc_types_engine::PayloadAttributes;
|
||||
|
||||
#[cfg(test)]
|
||||
mod examples;
|
||||
@@ -46,6 +47,12 @@ pub struct Environment<I> {
|
||||
pub latest_block_info: Option<LatestBlockInfo>,
|
||||
/// Last producer index
|
||||
pub last_producer_idx: Option<usize>,
|
||||
/// Stores payload attributes indexed by block number
|
||||
pub payload_attributes: HashMap<u64, PayloadAttributes>,
|
||||
/// Tracks the latest block header timestamp
|
||||
pub latest_header_time: u64,
|
||||
/// Defines the increment for block timestamps (default: 2 seconds)
|
||||
pub block_timestamp_increment: u64,
|
||||
}
|
||||
|
||||
impl<I> Default for Environment<I> {
|
||||
@@ -55,6 +62,9 @@ impl<I> Default for Environment<I> {
|
||||
_phantom: Default::default(),
|
||||
latest_block_info: None,
|
||||
last_producer_idx: None,
|
||||
payload_attributes: Default::default(),
|
||||
latest_header_time: 0,
|
||||
block_timestamp_increment: 2,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user