feat: impl payload attributes builder (#11336)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
greged93
2024-10-03 14:27:05 +02:00
committed by GitHub
parent 601c6fe73e
commit 4960b927bc
4 changed files with 44 additions and 15 deletions

27
Cargo.lock generated
View File

@ -5158,9 +5158,9 @@ checksum = "b410bbe7e14ab526a0e86877eb47c6996a2bd7746f027ba551028c925390e4e9"
[[package]]
name = "op-alloy-consensus"
version = "0.3.2"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c662868734bd5a274c4474dc0642b5211f008367e591573277e5895333cb78f5"
checksum = "c4f7f318f885db6e1455370ca91f74b7faed152c8142f6418f0936d606e582ff"
dependencies = [
"alloy-consensus",
"alloy-eips",
@ -5176,9 +5176,9 @@ dependencies = [
[[package]]
name = "op-alloy-genesis"
version = "0.3.2"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "67b4faf4f93b34c263e66cb163a085d9da72ced1f3adb34b7bd70c6e9fc7e5d6"
checksum = "c8215c87b74d2fbbaff0fd2887868a8341df33a3c495ee01f813e5ddd5be9c46"
dependencies = [
"alloy-consensus",
"alloy-eips",
@ -5190,9 +5190,9 @@ dependencies = [
[[package]]
name = "op-alloy-network"
version = "0.3.2"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a51504fd83b75b5d5e09320a0b4657b3bf23fc8018d40038ebab4eafcd7b9a40"
checksum = "3cd514c4ccd0b3c69fa3e7050cde77db842d4c308ae48f9a3e1ce263e823e45e"
dependencies = [
"alloy-consensus",
"alloy-network",
@ -5204,9 +5204,9 @@ dependencies = [
[[package]]
name = "op-alloy-protocol"
version = "0.3.2"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "20bec4f5aff4fe44e1e5beecd988096e6b757bd4bdfe6b10bb3f08c410287348"
checksum = "fa5c397fbe35e07f9c95a571440ca2e90df754e198496d82ff4127de00b89dd9"
dependencies = [
"alloy-consensus",
"alloy-eips",
@ -5221,9 +5221,9 @@ dependencies = [
[[package]]
name = "op-alloy-rpc-types"
version = "0.3.2"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "971fb1d31a1764327e4cf27a5372d2fde5db8bead90f75a750eeab306979b34c"
checksum = "547d29c5ab957ff32e14edddb93652dad748d2ef6cbe4b0fe8615ce06b0a3ddb"
dependencies = [
"alloy-consensus",
"alloy-eips",
@ -5238,17 +5238,14 @@ dependencies = [
[[package]]
name = "op-alloy-rpc-types-engine"
version = "0.3.2"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb2b515967262eae36ccecf868ab123dd8a098476f08f28f8ab4c3db5e1ee306"
checksum = "5041122e20b76644cc690bba688671eecdc4626e6384a76eb740535d6ddcef14"
dependencies = [
"alloy-eips",
"alloy-primitives",
"alloy-rpc-types-engine",
"alloy-serde",
"derive_more 1.0.0",
"op-alloy-consensus",
"op-alloy-genesis",
"op-alloy-protocol",
"serde",
]

View File

@ -13,6 +13,7 @@ exclude.workspace = true
reth-beacon-consensus.workspace = true
reth-chain-state.workspace = true
reth-engine-tree.workspace = true
reth-ethereum-engine-primitives.workspace = true
reth-node-types.workspace = true
reth-payload-builder.workspace = true
reth-payload-primitives.workspace = true

View File

@ -1,3 +1,4 @@
//! A local engine service that can be used to drive a dev chain.
pub mod miner;
pub mod payload;
pub mod service;

View File

@ -0,0 +1,30 @@
//! The implementation of the [`PayloadAttributesBuilder`] for the
//! [`LocalEngineService`](super::service::LocalEngineService).
use alloy_primitives::{Address, B256};
use reth_ethereum_engine_primitives::EthPayloadAttributes;
use reth_payload_primitives::PayloadAttributesBuilder;
use std::{convert::Infallible, time::UNIX_EPOCH};
/// The attributes builder for local Ethereum payload.
#[derive(Debug)]
pub struct EthLocalPayloadAttributesBuilder;
impl PayloadAttributesBuilder for EthLocalPayloadAttributesBuilder {
type PayloadAttributes = EthPayloadAttributes;
type Error = Infallible;
fn build(&self) -> Result<Self::PayloadAttributes, Self::Error> {
let ts = std::time::SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("cannot be earlier than UNIX_EPOCH");
Ok(EthPayloadAttributes {
timestamp: ts.as_secs(),
prev_randao: B256::random(),
suggested_fee_recipient: Address::random(),
withdrawals: None,
parent_beacon_block_root: None,
})
}
}