mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: integrate OpPrimitives (#13556)
This commit is contained in:
@ -43,7 +43,7 @@ reth-optimism-rpc.workspace = true
|
||||
reth-optimism-chainspec.workspace = true
|
||||
reth-optimism-consensus.workspace = true
|
||||
reth-optimism-forks.workspace = true
|
||||
reth-optimism-primitives = { workspace = true, features = ["serde"] }
|
||||
reth-optimism-primitives = { workspace = true, features = ["serde", "serde-bincode-compat"] }
|
||||
|
||||
# revm with required optimism features
|
||||
revm = { workspace = true, features = ["secp256k1", "blst", "c-kzg"] }
|
||||
@ -88,6 +88,7 @@ alloy-consensus.workspace = true
|
||||
futures.workspace = true
|
||||
|
||||
[features]
|
||||
default = ["reth-codec"]
|
||||
optimism = [
|
||||
"reth-primitives/optimism",
|
||||
"reth-provider/optimism",
|
||||
|
||||
@ -38,23 +38,12 @@ pub struct RollupArgs {
|
||||
#[arg(long = "rollup.discovery.v4", default_value = "false")]
|
||||
pub discovery_v4: bool,
|
||||
|
||||
/// Enable the experimental engine features on reth binary
|
||||
///
|
||||
/// DEPRECATED: experimental engine is default now, use --engine.legacy to enable the legacy
|
||||
/// functionality
|
||||
#[arg(long = "engine.experimental", default_value = "false")]
|
||||
pub experimental: bool,
|
||||
|
||||
/// Enable the legacy engine on reth binary
|
||||
#[arg(long = "engine.legacy", default_value = "false")]
|
||||
pub legacy: bool,
|
||||
|
||||
/// Configure persistence threshold for engine experimental.
|
||||
#[arg(long = "engine.persistence-threshold", conflicts_with = "legacy", default_value_t = DEFAULT_PERSISTENCE_THRESHOLD)]
|
||||
#[arg(long = "engine.persistence-threshold", default_value_t = DEFAULT_PERSISTENCE_THRESHOLD)]
|
||||
pub persistence_threshold: u64,
|
||||
|
||||
/// Configure the target number of blocks to keep in memory.
|
||||
#[arg(long = "engine.memory-block-buffer-target", conflicts_with = "legacy", default_value_t = DEFAULT_MEMORY_BLOCK_BUFFER_TARGET)]
|
||||
#[arg(long = "engine.memory-block-buffer-target", default_value_t = DEFAULT_MEMORY_BLOCK_BUFFER_TARGET)]
|
||||
pub memory_block_buffer_target: u64,
|
||||
}
|
||||
|
||||
@ -66,8 +55,6 @@ impl Default for RollupArgs {
|
||||
enable_genesis_walkback: false,
|
||||
compute_pending_block: false,
|
||||
discovery_v4: false,
|
||||
experimental: false,
|
||||
legacy: false,
|
||||
persistence_threshold: DEFAULT_PERSISTENCE_THRESHOLD,
|
||||
memory_block_buffer_target: DEFAULT_MEMORY_BLOCK_BUFFER_TARGET,
|
||||
}
|
||||
|
||||
@ -18,8 +18,9 @@ use reth_node_api::{
|
||||
use reth_optimism_chainspec::OpChainSpec;
|
||||
use reth_optimism_forks::{OpHardfork, OpHardforks};
|
||||
use reth_optimism_payload_builder::{OpBuiltPayload, OpPayloadBuilderAttributes};
|
||||
use reth_optimism_primitives::OpBlock;
|
||||
use reth_payload_validator::ExecutionPayloadValidator;
|
||||
use reth_primitives::{Block, SealedBlockFor};
|
||||
use reth_primitives::SealedBlockFor;
|
||||
use reth_rpc_types_compat::engine::payload::block_to_payload;
|
||||
use std::sync::Arc;
|
||||
|
||||
@ -38,7 +39,7 @@ impl<T: PayloadTypes> PayloadTypes for OpEngineTypes<T> {
|
||||
|
||||
impl<T: PayloadTypes> EngineTypes for OpEngineTypes<T>
|
||||
where
|
||||
T::BuiltPayload: BuiltPayload<Primitives: NodePrimitives<Block = reth_primitives::Block>>
|
||||
T::BuiltPayload: BuiltPayload<Primitives: NodePrimitives<Block = OpBlock>>
|
||||
+ TryInto<ExecutionPayloadV1>
|
||||
+ TryInto<ExecutionPayloadEnvelopeV2>
|
||||
+ TryInto<OpExecutionPayloadEnvelopeV3>
|
||||
@ -89,7 +90,7 @@ impl OpEngineValidator {
|
||||
}
|
||||
|
||||
impl PayloadValidator for OpEngineValidator {
|
||||
type Block = Block;
|
||||
type Block = OpBlock;
|
||||
|
||||
fn ensure_well_formed_payload(
|
||||
&self,
|
||||
|
||||
@ -6,12 +6,12 @@ use crate::{
|
||||
txpool::{OpTransactionPool, OpTransactionValidator},
|
||||
OpEngineTypes,
|
||||
};
|
||||
use alloy_consensus::Header;
|
||||
use op_alloy_consensus::OpPooledTransaction;
|
||||
use reth_basic_payload_builder::{BasicPayloadJobGenerator, BasicPayloadJobGeneratorConfig};
|
||||
use reth_chainspec::{EthChainSpec, Hardforks};
|
||||
use reth_evm::{execute::BasicBlockExecutorProvider, ConfigureEvm};
|
||||
use reth_network::{NetworkConfig, NetworkHandle, NetworkManager, NetworkPrimitives, PeersInfo};
|
||||
use reth_node_api::{AddOnsContext, EngineValidator, FullNodeComponents, NodeAddOns, TxTy};
|
||||
use reth_node_api::{AddOnsContext, FullNodeComponents, HeaderTy, NodeAddOns, TxTy};
|
||||
use reth_node_builder::{
|
||||
components::{
|
||||
ComponentsBuilder, ConsensusBuilder, ExecutorBuilder, NetworkBuilder,
|
||||
@ -28,14 +28,13 @@ use reth_optimism_payload_builder::{
|
||||
builder::OpPayloadTransactions,
|
||||
config::{OpBuilderConfig, OpDAConfig},
|
||||
};
|
||||
use reth_optimism_primitives::OpPrimitives;
|
||||
use reth_optimism_primitives::{OpPrimitives, OpReceipt, OpTransactionSigned};
|
||||
use reth_optimism_rpc::{
|
||||
miner::{MinerApiExtServer, OpMinerExtApi},
|
||||
witness::{DebugExecutionWitnessApiServer, OpDebugWitnessApi},
|
||||
OpEthApi, SequencerClient,
|
||||
};
|
||||
use reth_payload_builder::{PayloadBuilderHandle, PayloadBuilderService};
|
||||
use reth_primitives::{PooledTransaction, TransactionSigned};
|
||||
use reth_provider::{CanonStateSubscriptions, EthStorage};
|
||||
use reth_rpc_server_types::RethRpcModule;
|
||||
use reth_tracing::tracing::{debug, info};
|
||||
@ -47,7 +46,7 @@ use reth_trie_db::MerklePatriciaTrie;
|
||||
use std::sync::Arc;
|
||||
|
||||
/// Storage implementation for Optimism.
|
||||
pub type OpStorage = EthStorage;
|
||||
pub type OpStorage = EthStorage<OpTransactionSigned>;
|
||||
|
||||
/// Type configuration for a regular Optimism node.
|
||||
#[derive(Debug, Default, Clone)]
|
||||
@ -192,7 +191,6 @@ where
|
||||
Engine = OpEngineTypes,
|
||||
>,
|
||||
>,
|
||||
OpEngineValidator: EngineValidator<<N::Types as NodeTypesWithEngine>::Engine>,
|
||||
{
|
||||
type Handle = RpcHandle<N, OpEthApi<N>>;
|
||||
|
||||
@ -242,7 +240,6 @@ where
|
||||
Engine = OpEngineTypes,
|
||||
>,
|
||||
>,
|
||||
OpEngineValidator: EngineValidator<<N::Types as NodeTypesWithEngine>::Engine>,
|
||||
{
|
||||
type EthApi = OpEthApi<N>;
|
||||
|
||||
@ -488,7 +485,7 @@ where
|
||||
Pool: TransactionPool<Transaction: PoolTransaction<Consensus = TxTy<Node::Types>>>
|
||||
+ Unpin
|
||||
+ 'static,
|
||||
Evm: ConfigureEvm<Header = Header, Transaction = TransactionSigned>,
|
||||
Evm: ConfigureEvm<Header = HeaderTy<Node::Types>, Transaction = TxTy<Node::Types>>,
|
||||
{
|
||||
let payload_builder = reth_optimism_payload_builder::OpPayloadBuilder::with_builder_config(
|
||||
evm_config,
|
||||
@ -603,7 +600,10 @@ impl<Node, Pool> NetworkBuilder<Node, Pool> for OpNetworkBuilder
|
||||
where
|
||||
Node: FullNodeTypes<Types: NodeTypes<ChainSpec = OpChainSpec, Primitives = OpPrimitives>>,
|
||||
Pool: TransactionPool<
|
||||
Transaction: PoolTransaction<Consensus = TxTy<Node::Types>, Pooled = PooledTransaction>,
|
||||
Transaction: PoolTransaction<
|
||||
Consensus = TxTy<Node::Types>,
|
||||
Pooled = OpPooledTransaction,
|
||||
>,
|
||||
> + Unpin
|
||||
+ 'static,
|
||||
{
|
||||
@ -667,9 +667,9 @@ pub struct OpNetworkPrimitives;
|
||||
|
||||
impl NetworkPrimitives for OpNetworkPrimitives {
|
||||
type BlockHeader = alloy_consensus::Header;
|
||||
type BlockBody = reth_primitives::BlockBody;
|
||||
type Block = reth_primitives::Block;
|
||||
type BroadcastedTransaction = reth_primitives::TransactionSigned;
|
||||
type PooledTransaction = reth_primitives::PooledTransaction;
|
||||
type Receipt = reth_primitives::Receipt;
|
||||
type BlockBody = reth_primitives::BlockBody<OpTransactionSigned>;
|
||||
type Block = reth_primitives::Block<OpTransactionSigned>;
|
||||
type BroadcastedTransaction = OpTransactionSigned;
|
||||
type PooledTransaction = OpPooledTransaction;
|
||||
type Receipt = OpReceipt;
|
||||
}
|
||||
|
||||
@ -9,10 +9,10 @@ use parking_lot::RwLock;
|
||||
use reth_chainspec::ChainSpec;
|
||||
use reth_node_api::{Block, BlockBody};
|
||||
use reth_optimism_evm::RethL1BlockInfo;
|
||||
use reth_optimism_primitives::OpTransactionSigned;
|
||||
use reth_optimism_primitives::{OpBlock, OpTransactionSigned};
|
||||
use reth_primitives::{
|
||||
transaction::TransactionConversionError, GotExpected, InvalidTransactionError, RecoveredTx,
|
||||
SealedBlock, TransactionSigned,
|
||||
SealedBlock,
|
||||
};
|
||||
use reth_primitives_traits::SignedTransaction;
|
||||
use reth_provider::{BlockReaderIdExt, StateProviderFactory};
|
||||
@ -30,8 +30,8 @@ use std::sync::{
|
||||
|
||||
/// Type alias for default optimism transaction pool
|
||||
pub type OpTransactionPool<Client, S> = Pool<
|
||||
TransactionValidationTaskExecutor<OpTransactionValidator<Client, EthPooledTransaction>>,
|
||||
CoinbaseTipOrdering<EthPooledTransaction>,
|
||||
TransactionValidationTaskExecutor<OpTransactionValidator<Client, OpPooledTransaction>>,
|
||||
CoinbaseTipOrdering<OpPooledTransaction>,
|
||||
S,
|
||||
>;
|
||||
|
||||
@ -39,6 +39,13 @@ pub type OpTransactionPool<Client, S> = Pool<
|
||||
#[derive(Debug, Clone, derive_more::Deref)]
|
||||
pub struct OpPooledTransaction(EthPooledTransaction<OpTransactionSigned>);
|
||||
|
||||
impl OpPooledTransaction {
|
||||
/// Create new instance of [Self].
|
||||
pub fn new(transaction: RecoveredTx<OpTransactionSigned>, encoded_length: usize) -> Self {
|
||||
Self(EthPooledTransaction::new(transaction, encoded_length))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<RecoveredTx<op_alloy_consensus::OpPooledTransaction>> for OpPooledTransaction {
|
||||
fn from(tx: RecoveredTx<op_alloy_consensus::OpPooledTransaction>) -> Self {
|
||||
let encoded_len = tx.encode_2718_len();
|
||||
@ -241,7 +248,7 @@ impl<Client, Tx> OpTransactionValidator<Client, Tx> {
|
||||
impl<Client, Tx> OpTransactionValidator<Client, Tx>
|
||||
where
|
||||
Client: StateProviderFactory + BlockReaderIdExt,
|
||||
Tx: EthPoolTransaction<Consensus = TransactionSigned>,
|
||||
Tx: EthPoolTransaction<Consensus = OpTransactionSigned>,
|
||||
{
|
||||
/// Create a new [`OpTransactionValidator`].
|
||||
pub fn new(inner: EthTransactionValidator<Client, Tx>) -> Self {
|
||||
@ -373,8 +380,8 @@ where
|
||||
|
||||
impl<Client, Tx> TransactionValidator for OpTransactionValidator<Client, Tx>
|
||||
where
|
||||
Client: StateProviderFactory + BlockReaderIdExt<Block = reth_primitives::Block>,
|
||||
Tx: EthPoolTransaction<Consensus = TransactionSigned>,
|
||||
Client: StateProviderFactory + BlockReaderIdExt<Block = OpBlock>,
|
||||
Tx: EthPoolTransaction<Consensus = OpTransactionSigned>,
|
||||
{
|
||||
type Transaction = Tx;
|
||||
|
||||
@ -417,16 +424,17 @@ pub struct OpL1BlockInfo {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::txpool::OpTransactionValidator;
|
||||
use crate::txpool::{OpPooledTransaction, OpTransactionValidator};
|
||||
use alloy_eips::eip2718::Encodable2718;
|
||||
use alloy_primitives::{PrimitiveSignature as Signature, TxKind, U256};
|
||||
use op_alloy_consensus::TxDeposit;
|
||||
use op_alloy_consensus::{OpTypedTransaction, TxDeposit};
|
||||
use reth_chainspec::MAINNET;
|
||||
use reth_primitives::{RecoveredTx, Transaction, TransactionSigned};
|
||||
use reth_optimism_primitives::OpTransactionSigned;
|
||||
use reth_primitives::RecoveredTx;
|
||||
use reth_provider::test_utils::MockEthProvider;
|
||||
use reth_transaction_pool::{
|
||||
blobstore::InMemoryBlobStore, validate::EthTransactionValidatorBuilder,
|
||||
EthPooledTransaction, TransactionOrigin, TransactionValidationOutcome,
|
||||
blobstore::InMemoryBlobStore, validate::EthTransactionValidatorBuilder, TransactionOrigin,
|
||||
TransactionValidationOutcome,
|
||||
};
|
||||
#[test]
|
||||
fn validate_optimism_transaction() {
|
||||
@ -439,7 +447,7 @@ mod tests {
|
||||
|
||||
let origin = TransactionOrigin::External;
|
||||
let signer = Default::default();
|
||||
let deposit_tx = Transaction::Deposit(TxDeposit {
|
||||
let deposit_tx = OpTypedTransaction::Deposit(TxDeposit {
|
||||
source_hash: Default::default(),
|
||||
from: signer,
|
||||
to: TxKind::Create,
|
||||
@ -450,10 +458,10 @@ mod tests {
|
||||
input: Default::default(),
|
||||
});
|
||||
let signature = Signature::test_signature();
|
||||
let signed_tx = TransactionSigned::new_unhashed(deposit_tx, signature);
|
||||
let signed_tx = OpTransactionSigned::new_unhashed(deposit_tx, signature);
|
||||
let signed_recovered = RecoveredTx::from_signed_transaction(signed_tx, signer);
|
||||
let len = signed_recovered.encode_2718_len();
|
||||
let pooled_tx = EthPooledTransaction::new(signed_recovered, len);
|
||||
let pooled_tx = OpPooledTransaction::new(signed_recovered, len);
|
||||
let outcome = validator.validate_one(origin, pooled_tx);
|
||||
|
||||
let err = match outcome {
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
//! Node builder setup tests.
|
||||
|
||||
use reth_db::test_utils::create_test_rw_db;
|
||||
use reth_node_api::FullNodeComponents;
|
||||
use reth_node_api::{FullNodeComponents, NodeTypesWithDBAdapter};
|
||||
use reth_node_builder::{Node, NodeBuilder, NodeConfig};
|
||||
use reth_optimism_chainspec::BASE_MAINNET;
|
||||
use reth_optimism_node::{args::RollupArgs, OpNode};
|
||||
use reth_provider::providers::BlockchainProvider2;
|
||||
|
||||
#[test]
|
||||
fn test_basic_setup() {
|
||||
@ -15,7 +16,7 @@ fn test_basic_setup() {
|
||||
let op_node = OpNode::new(args);
|
||||
let _builder = NodeBuilder::new(config)
|
||||
.with_database(db)
|
||||
.with_types::<OpNode>()
|
||||
.with_types_and_provider::<OpNode, BlockchainProvider2<NodeTypesWithDBAdapter<OpNode, _>>>()
|
||||
.with_components(op_node.components())
|
||||
.with_add_ons(op_node.add_ons())
|
||||
.on_component_initialized(move |ctx| {
|
||||
|
||||
@ -4,6 +4,7 @@ use alloy_consensus::TxEip1559;
|
||||
use alloy_genesis::Genesis;
|
||||
use alloy_network::TxSignerSync;
|
||||
use alloy_primitives::{Address, ChainId, TxKind};
|
||||
use op_alloy_consensus::OpTypedTransaction;
|
||||
use reth_chainspec::EthChainSpec;
|
||||
use reth_db::test_utils::create_test_rw_db_with_path;
|
||||
use reth_e2e_test_utils::{
|
||||
@ -25,9 +26,9 @@ use reth_optimism_node::{
|
||||
OpEngineTypes, OpNode,
|
||||
};
|
||||
use reth_optimism_payload_builder::builder::OpPayloadTransactions;
|
||||
use reth_optimism_primitives::OpPrimitives;
|
||||
use reth_optimism_primitives::{OpPrimitives, OpTransactionSigned};
|
||||
use reth_payload_util::{PayloadTransactions, PayloadTransactionsChain, PayloadTransactionsFixed};
|
||||
use reth_primitives::{RecoveredTx, SealedBlock, Transaction, TransactionSigned};
|
||||
use reth_primitives::RecoveredTx;
|
||||
use reth_provider::providers::BlockchainProvider2;
|
||||
use reth_tasks::TaskManager;
|
||||
use reth_transaction_pool::{pool::BestPayloadTransactions, PoolTransaction};
|
||||
@ -44,10 +45,10 @@ impl OpPayloadTransactions for CustomTxPriority {
|
||||
&self,
|
||||
pool: Pool,
|
||||
attr: reth_transaction_pool::BestTransactionsAttributes,
|
||||
) -> impl PayloadTransactions<Transaction = TransactionSigned>
|
||||
) -> impl PayloadTransactions<Transaction = OpTransactionSigned>
|
||||
where
|
||||
Pool: reth_transaction_pool::TransactionPool<
|
||||
Transaction: PoolTransaction<Consensus = TransactionSigned>,
|
||||
Transaction: PoolTransaction<Consensus = OpTransactionSigned>,
|
||||
>,
|
||||
{
|
||||
// Block composition:
|
||||
@ -67,7 +68,10 @@ impl OpPayloadTransactions for CustomTxPriority {
|
||||
};
|
||||
let signature = sender.sign_transaction_sync(&mut end_of_block_tx).unwrap();
|
||||
let end_of_block_tx = RecoveredTx::from_signed_transaction(
|
||||
TransactionSigned::new_unhashed(Transaction::Eip1559(end_of_block_tx), signature),
|
||||
OpTransactionSigned::new_unhashed(
|
||||
OpTypedTransaction::Eip1559(end_of_block_tx),
|
||||
signature,
|
||||
),
|
||||
sender.address(),
|
||||
);
|
||||
|
||||
@ -182,12 +186,14 @@ async fn test_custom_block_priority_config() {
|
||||
.unwrap();
|
||||
assert_eq!(block_payloads.len(), 1);
|
||||
let (block_payload, _) = block_payloads.first().unwrap();
|
||||
let block_payload: SealedBlock = block_payload.block().clone();
|
||||
let block_payload = block_payload.block().clone();
|
||||
assert_eq!(block_payload.body.transactions.len(), 2); // L1 block info tx + end-of-block custom tx
|
||||
|
||||
// Check that last transaction in the block looks like a transfer to a random address.
|
||||
let end_of_block_tx = block_payload.body.transactions.last().unwrap();
|
||||
let end_of_block_tx = end_of_block_tx.transaction.as_eip1559().unwrap();
|
||||
let OpTypedTransaction::Eip1559(end_of_block_tx) = &end_of_block_tx.transaction else {
|
||||
panic!("expected EIP-1559 transaction");
|
||||
};
|
||||
assert_eq!(end_of_block_tx.nonce, 1);
|
||||
assert_eq!(end_of_block_tx.gas_limit, 21_000);
|
||||
assert!(end_of_block_tx.input.is_empty());
|
||||
|
||||
Reference in New Issue
Block a user