Skip to content

Commit 21a3276

Browse files
committed
custom node
fix custom node tidy Update lib.rs
1 parent 848804f commit 21a3276

File tree

6 files changed

+139
-10
lines changed

6 files changed

+139
-10
lines changed

crates/optimism/rpc/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ pub mod witness;
2121
pub use engine::OpEngineApiClient;
2222
pub use engine::{OpEngineApi, OpEngineApiServer, OP_ENGINE_CAPABILITIES};
2323
pub use error::{OpEthApiError, OpInvalidTransactionError, SequencerClientError};
24-
pub use eth::{OpEthApi, OpEthApiBuilder, OpReceiptBuilder};
24+
pub use eth::{OpEthApi, OpEthApiBuilder, OpReceiptBuilder, OpRpcTypes};
2525
pub use metrics::SequencerMetrics;
2626
pub use sequencer::SequencerClient;

examples/custom-node/src/engine.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::{
22
chainspec::CustomChainSpec,
33
evm::CustomEvmConfig,
4+
flashblock::CustomFlashblockPayload,
45
primitives::{CustomHeader, CustomNodePrimitives, CustomTransaction},
56
CustomNode,
67
};
@@ -67,14 +68,15 @@ impl ExecutionPayload for CustomExecutionData {
6768
}
6869
}
6970

70-
impl TryFrom<&reth_optimism_flashblocks::FlashBlockCompleteSequence> for CustomExecutionData {
71+
impl TryFrom<&reth_optimism_flashblocks::FlashBlockCompleteSequence<CustomFlashblockPayload>>
72+
for CustomExecutionData
73+
{
7174
type Error = &'static str;
7275

7376
fn try_from(
74-
sequence: &reth_optimism_flashblocks::FlashBlockCompleteSequence,
77+
_sequence: &reth_optimism_flashblocks::FlashBlockCompleteSequence<CustomFlashblockPayload>,
7578
) -> Result<Self, Self::Error> {
76-
let inner = OpExecutionData::try_from(sequence)?;
77-
Ok(Self { inner, extension: sequence.last().diff.gas_used })
79+
todo!("convert flashblock sequence to CustomExecutionData")
7880
}
7981
}
8082

examples/custom-node/src/evm/config.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ use crate::{
22
chainspec::CustomChainSpec,
33
engine::{CustomExecutionData, CustomPayloadBuilderAttributes},
44
evm::{alloy::CustomEvmFactory, executor::CustomBlockExecutionCtx, CustomBlockAssembler},
5+
flashblock::CustomFlashblockPayloadBase,
56
primitives::{Block, CustomHeader, CustomNodePrimitives, CustomTransaction},
67
};
78
use alloy_consensus::BlockHeader;
89
use alloy_eips::{eip2718::WithEncoded, Decodable2718};
910
use alloy_evm::EvmEnv;
1011
use alloy_op_evm::OpBlockExecutionCtx;
1112
use alloy_rpc_types_engine::PayloadError;
12-
use op_alloy_rpc_types_engine::flashblock::OpFlashblockPayloadBase;
1313
use op_revm::OpSpecId;
1414
use reth_engine_primitives::ExecutableTxIterator;
1515
use reth_ethereum::{
@@ -143,9 +143,9 @@ pub struct CustomNextBlockEnvAttributes {
143143
extension: u64,
144144
}
145145

146-
impl From<OpFlashblockPayloadBase> for CustomNextBlockEnvAttributes {
147-
fn from(value: OpFlashblockPayloadBase) -> Self {
148-
Self { inner: value.into(), extension: 0 }
146+
impl From<CustomFlashblockPayloadBase> for CustomNextBlockEnvAttributes {
147+
fn from(_value: CustomFlashblockPayloadBase) -> Self {
148+
todo!("map CustomFlashblockPayloadBase fields to CustomNextBlockEnvAttributes")
149149
}
150150
}
151151

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
use crate::primitives::CustomTransaction;
2+
use alloy_consensus::{crypto::RecoveryError, transaction::Recovered};
3+
use alloy_eips::{eip2718::WithEncoded, eip4895::Withdrawals};
4+
use alloy_primitives::{Bloom, Bytes, B256};
5+
use alloy_rpc_types_engine::PayloadId;
6+
use reth_optimism_flashblocks::{FlashblockDiff, FlashblockPayload, FlashblockPayloadBase};
7+
use serde::{Deserialize, Deserializer};
8+
9+
#[derive(Debug, Clone, Default)]
10+
pub struct CustomFlashblockPayloadBase {
11+
pub parent_hash: B256,
12+
pub block_number: u64,
13+
pub timestamp: u64,
14+
}
15+
16+
impl FlashblockPayloadBase for CustomFlashblockPayloadBase {
17+
fn parent_hash(&self) -> B256 {
18+
self.parent_hash
19+
}
20+
21+
fn block_number(&self) -> u64 {
22+
self.block_number
23+
}
24+
25+
fn timestamp(&self) -> u64 {
26+
self.timestamp
27+
}
28+
}
29+
30+
#[derive(Debug, Clone, Default)]
31+
pub struct CustomFlashblockPayloadDiff {
32+
pub block_hash: B256,
33+
pub state_root: B256,
34+
pub gas_used: u64,
35+
pub logs_bloom: Bloom,
36+
pub receipts_root: B256,
37+
pub transactions: Vec<Bytes>,
38+
}
39+
40+
impl FlashblockDiff for CustomFlashblockPayloadDiff {
41+
fn block_hash(&self) -> B256 {
42+
self.block_hash
43+
}
44+
45+
fn state_root(&self) -> B256 {
46+
self.state_root
47+
}
48+
49+
fn gas_used(&self) -> u64 {
50+
self.gas_used
51+
}
52+
53+
fn logs_bloom(&self) -> &Bloom {
54+
&self.logs_bloom
55+
}
56+
57+
fn receipts_root(&self) -> B256 {
58+
self.receipts_root
59+
}
60+
61+
fn transactions_raw(&self) -> &[Bytes] {
62+
&self.transactions
63+
}
64+
65+
fn withdrawals(&self) -> Option<&Withdrawals> {
66+
None
67+
}
68+
69+
fn withdrawals_root(&self) -> Option<B256> {
70+
None
71+
}
72+
}
73+
74+
#[derive(Debug, Clone)]
75+
pub struct CustomFlashblockPayload {
76+
pub index: u64,
77+
pub payload_id: PayloadId,
78+
pub base: Option<CustomFlashblockPayloadBase>,
79+
pub diff: CustomFlashblockPayloadDiff,
80+
}
81+
82+
impl<'de> Deserialize<'de> for CustomFlashblockPayload {
83+
fn deserialize<D>(_deserializer: D) -> Result<Self, D::Error>
84+
where
85+
D: Deserializer<'de>,
86+
{
87+
todo!("implement deserialization")
88+
}
89+
}
90+
91+
impl FlashblockPayload for CustomFlashblockPayload {
92+
type Base = CustomFlashblockPayloadBase;
93+
type Diff = CustomFlashblockPayloadDiff;
94+
type SignedTx = CustomTransaction;
95+
96+
fn index(&self) -> u64 {
97+
self.index
98+
}
99+
100+
fn payload_id(&self) -> PayloadId {
101+
self.payload_id
102+
}
103+
104+
fn base(&self) -> Option<Self::Base> {
105+
self.base.clone()
106+
}
107+
108+
fn diff(&self) -> &Self::Diff {
109+
&self.diff
110+
}
111+
112+
fn block_number(&self) -> u64 {
113+
self.base.as_ref().map(|b| b.block_number()).unwrap_or(0)
114+
}
115+
116+
fn recover_transactions(
117+
&self,
118+
) -> impl Iterator<Item = Result<WithEncoded<Recovered<Self::SignedTx>>, RecoveryError>> {
119+
std::iter::from_fn(|| todo!("implement transaction recovery"))
120+
}
121+
}

examples/custom-node/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub mod chainspec;
3434
pub mod engine;
3535
pub mod engine_api;
3636
pub mod evm;
37+
pub mod flashblock;
3738
pub mod pool;
3839
pub mod primitives;
3940
pub mod rpc;

examples/custom-node/src/rpc.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
use crate::{
22
evm::CustomTxEnv,
3+
flashblock::CustomFlashblockPayload,
34
primitives::{CustomHeader, CustomTransaction},
45
};
56
use alloy_consensus::error::ValueError;
67
use alloy_evm::EvmEnv;
78
use alloy_network::TxSigner;
89
use op_alloy_consensus::OpTxEnvelope;
910
use op_alloy_rpc_types::{OpTransactionReceipt, OpTransactionRequest};
10-
use reth_op::rpc::RpcTypes;
11+
use reth_op::rpc::{OpRpcTypes, RpcTypes};
1112
use reth_rpc_api::eth::{
1213
EthTxEnvError, SignTxRequestError, SignableTxRequest, TryIntoSimTx, TryIntoTxEnv,
1314
};
@@ -17,6 +18,10 @@ use revm::context::BlockEnv;
1718
#[non_exhaustive]
1819
pub struct CustomRpcTypes;
1920

21+
impl OpRpcTypes for CustomRpcTypes {
22+
type Flashblock = CustomFlashblockPayload;
23+
}
24+
2025
impl RpcTypes for CustomRpcTypes {
2126
type Header = alloy_rpc_types_eth::Header<CustomHeader>;
2227
type Receipt = OpTransactionReceipt;

0 commit comments

Comments
 (0)