Skip to content

Commit

Permalink
Merge branch 'main' into emhane/maybe-serialize
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse committed Nov 18, 2024
2 parents 05a31ed + a84f58b commit 7f41069
Show file tree
Hide file tree
Showing 30 changed files with 205 additions and 196 deletions.
1 change: 1 addition & 0 deletions .github/assets/check_wasm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ exclude_crates=(
reth-static-file # tokio
reth-transaction-pool # c-kzg
reth-trie-parallel # tokio
reth-testing-utils
)

# Array to hold the results
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/net/network/src/transactions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2230,7 +2230,7 @@ mod tests {
.add_transaction(reth_transaction_pool::TransactionOrigin::External, tx.clone())
.await;

let request = GetPooledTransactions(vec![tx.get_hash()]);
let request = GetPooledTransactions(vec![*tx.get_hash()]);

let (send, receive) = oneshot::channel::<RequestResult<PooledTransactions>>();

Expand Down
2 changes: 1 addition & 1 deletion crates/net/network/tests/it/big_pooled_txs_req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async fn test_large_tx_req() {
tx
})
.collect();
let txs_hashes: Vec<B256> = txs.iter().map(|tx| tx.get_hash()).collect();
let txs_hashes: Vec<B256> = txs.iter().map(|tx| *tx.get_hash()).collect();

// setup testnet
let mut net = Testnet::create_with(2, MockEthProvider::default()).await;
Expand Down
5 changes: 4 additions & 1 deletion crates/node/builder/src/launch/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,10 @@ where
/// This checks for OP-Mainnet and ensures we have all the necessary data to progress (past
/// bedrock height)
fn ensure_chain_specific_db_checks(&self) -> ProviderResult<()> {
if self.chain_id() == Chain::optimism_mainnet() {
if self.chain_spec().is_optimism() &&
!self.is_dev() &&
self.chain_id() == Chain::optimism_mainnet()
{
let latest = self.blockchain_db().last_block_number()?;
// bedrock height
if latest < 105235063 {
Expand Down
32 changes: 28 additions & 4 deletions crates/node/builder/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ where
}
}

impl<N, EthApi, EV> NodeAddOns<N> for RpcAddOns<N, EthApi, EV>
impl<N, EthApi, EV> RpcAddOns<N, EthApi, EV>
where
N: FullNodeComponents<
Types: ProviderNodeTypes,
Expand All @@ -408,9 +408,16 @@ where
EthApi: EthApiTypes + FullEthApiServer + AddDevSigners + Unpin + 'static,
EV: EngineValidatorBuilder<N>,
{
type Handle = RpcHandle<N, EthApi>;

async fn launch_add_ons(self, ctx: AddOnsContext<'_, N>) -> eyre::Result<Self::Handle> {
/// Launches the RPC servers with the given context and an additional hook for extending
/// modules.
pub async fn launch_add_ons_with<F>(
self,
ctx: AddOnsContext<'_, N>,
ext: F,
) -> eyre::Result<RpcHandle<N, EthApi>>
where
F: FnOnce(&mut TransportRpcModules) -> eyre::Result<()>,
{
let Self { eth_api_builder, engine_validator_builder, hooks, _pd: _ } = self;

let engine_validator = engine_validator_builder.build(&ctx).await?;
Expand Down Expand Up @@ -467,6 +474,7 @@ where

let RpcHooks { on_rpc_started, extend_rpc_modules } = hooks;

ext(ctx.modules)?;
extend_rpc_modules.extend_rpc_modules(ctx)?;

let server_config = config.rpc.rpc_server_config();
Expand Down Expand Up @@ -513,6 +521,22 @@ where
}
}

impl<N, EthApi, EV> NodeAddOns<N> for RpcAddOns<N, EthApi, EV>
where
N: FullNodeComponents<
Types: ProviderNodeTypes,
PayloadBuilder: PayloadBuilder<PayloadType = <N::Types as NodeTypesWithEngine>::Engine>,
>,
EthApi: EthApiTypes + FullEthApiServer + AddDevSigners + Unpin + 'static,
EV: EngineValidatorBuilder<N>,
{
type Handle = RpcHandle<N, EthApi>;

async fn launch_add_ons(self, ctx: AddOnsContext<'_, N>) -> eyre::Result<Self::Handle> {
self.launch_add_ons_with(ctx, |_| Ok(())).await
}
}

/// Helper trait implemented for add-ons producing [`RpcHandle`]. Used by common node launcher
/// implementations.
pub trait RethRpcAddOns<N: FullNodeComponents>:
Expand Down
1 change: 1 addition & 0 deletions crates/optimism/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ reth-evm.workspace = true
reth-revm = { workspace = true, features = ["std"] }
reth-beacon-consensus.workspace = true
reth-trie-db.workspace = true
reth-rpc-server-types.workspace = true

# op-reth
reth-optimism-payload-builder.workspace = true
Expand Down
34 changes: 23 additions & 11 deletions crates/optimism/node/src/node.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
//! Optimism Node types config.
use std::sync::Arc;

use crate::{
args::RollupArgs,
engine::OpEngineValidator,
txpool::{OpTransactionPool, OpTransactionValidator},
OpEngineTypes,
};
use alloy_consensus::Header;
use reth_basic_payload_builder::{BasicPayloadJobGenerator, BasicPayloadJobGeneratorConfig};
use reth_chainspec::{EthChainSpec, Hardforks};
Expand All @@ -23,23 +27,21 @@ use reth_optimism_chainspec::OpChainSpec;
use reth_optimism_consensus::OpBeaconConsensus;
use reth_optimism_evm::{OpEvmConfig, OpExecutionStrategyFactory};
use reth_optimism_payload_builder::builder::OpPayloadTransactions;
use reth_optimism_rpc::OpEthApi;
use reth_optimism_rpc::{
witness::{DebugExecutionWitnessApiServer, OpDebugWitnessApi},
OpEthApi,
};
use reth_payload_builder::{PayloadBuilderHandle, PayloadBuilderService};
use reth_primitives::{Block, Receipt, TransactionSigned, TxType};
use reth_provider::CanonStateSubscriptions;
use reth_rpc_server_types::RethRpcModule;
use reth_tracing::tracing::{debug, info};
use reth_transaction_pool::{
blobstore::DiskFileBlobStore, CoinbaseTipOrdering, TransactionPool,
TransactionValidationTaskExecutor,
};
use reth_trie_db::MerklePatriciaTrie;

use crate::{
args::RollupArgs,
engine::OpEngineValidator,
txpool::{OpTransactionPool, OpTransactionValidator},
OpEngineTypes,
};
use std::sync::Arc;

/// Optimism primitive types.
#[derive(Debug, Default, Clone)]
Expand Down Expand Up @@ -163,7 +165,17 @@ where
self,
ctx: reth_node_api::AddOnsContext<'_, N>,
) -> eyre::Result<Self::Handle> {
self.0.launch_add_ons(ctx).await
// install additional OP specific rpc methods
let debug_ext =
OpDebugWitnessApi::new(ctx.node.provider().clone(), ctx.node.evm_config().clone());

self.0
.launch_add_ons_with(ctx, move |modules| {
debug!(target: "reth::cli", "Installing debug payload witness rpc endpoint");
modules.merge_if_module_configured(RethRpcModule::Debug, debug_ext.into_rpc())?;
Ok(())
})
.await
}
}

Expand Down
10 changes: 9 additions & 1 deletion crates/optimism/primitives/src/tx_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use reth_primitives::transaction::{
COMPACT_EXTENDED_IDENTIFIER_FLAG, COMPACT_IDENTIFIER_EIP1559, COMPACT_IDENTIFIER_EIP2930,
COMPACT_IDENTIFIER_LEGACY,
};
use reth_primitives_traits::TxType;
use reth_primitives_traits::{InMemorySize, TxType};

/// Wrapper type for [`op_alloy_consensus::OpTxType`] to implement [`TxType`] trait.
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Display, Ord, Hash, From, Into)]
Expand Down Expand Up @@ -55,6 +55,14 @@ impl TxType for OpTxType {
}
}

impl InMemorySize for OpTxType {
/// Calculates a heuristic for the in-memory size of the [`OpTxType`].
#[inline]
fn size(&self) -> usize {
core::mem::size_of::<Self>()
}
}

impl From<OpTxType> for U8 {
fn from(tx_type: OpTxType) -> Self {
Self::from(u8::from(tx_type))
Expand Down
2 changes: 1 addition & 1 deletion crates/optimism/rpc/src/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use reth_optimism_chainspec::OpChainSpec;
use reth_optimism_payload_builder::OpPayloadBuilder;
use reth_primitives::SealedHeader;
use reth_provider::{BlockReaderIdExt, ProviderError, ProviderResult, StateProviderFactory};
use reth_rpc_api::DebugExecutionWitnessApiServer;
pub use reth_rpc_api::DebugExecutionWitnessApiServer;
use reth_rpc_server_types::{result::internal_rpc_err, ToRpcResult};
use std::{fmt::Debug, sync::Arc};

Expand Down
4 changes: 2 additions & 2 deletions crates/primitives-traits/src/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
use alloc::vec::Vec;
use core::fmt;

use alloy_consensus::TxReceipt;
use alloy_primitives::B256;
use reth_codecs::Compact;

use crate::MaybeSerde;
use crate::InMemorySize;

/// Helper trait that unifies all behaviour required by receipt to support full node operations.
pub trait FullReceipt: Receipt + Compact {}
Expand All @@ -27,6 +26,7 @@ pub trait Receipt:
+ alloy_rlp::Encodable
+ alloy_rlp::Decodable
+ MaybeSerde
+ InMemorySize
{
/// Returns transaction type.
fn tx_type(&self) -> u8;
Expand Down
3 changes: 2 additions & 1 deletion crates/primitives-traits/src/transaction/signed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use alloy_primitives::{keccak256, Address, PrimitiveSignature, TxHash, B256};
use reth_codecs::Compact;
use revm_primitives::TxEnv;

use crate::{FullTransaction, MaybeArbitrary, MaybeSerde, Transaction};
use crate::{FullTransaction, InMemorySize, MaybeSerde, MaybeArbitrary, Transaction};

/// Helper trait that unifies all behaviour required by block to support full node operations.
pub trait FullSignedTx: SignedTransaction<Transaction: FullTransaction> + Compact {}
Expand All @@ -34,6 +34,7 @@ pub trait SignedTransaction:
+ alloy_consensus::Transaction
+ MaybeSerde
+ MaybeArbitrary
+ InMemorySize
{
/// Transaction type that is signed.
type Transaction: Transaction;
Expand Down
3 changes: 3 additions & 0 deletions crates/primitives-traits/src/tx_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use core::fmt;
use alloy_primitives::{U64, U8};
use reth_codecs::Compact;

use crate::InMemorySize;

/// Helper trait that unifies all behaviour required by transaction type ID to support full node
/// operations.
pub trait FullTxType: TxType + Compact {}
Expand All @@ -29,6 +31,7 @@ pub trait TxType:
+ TryFrom<U64>
+ alloy_rlp::Encodable
+ alloy_rlp::Decodable
+ InMemorySize
{
/// Returns `true` if this is a legacy transaction.
fn is_legacy(&self) -> bool;
Expand Down
4 changes: 2 additions & 2 deletions crates/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ arbitrary = { workspace = true, features = ["derive"], optional = true }

[dev-dependencies]
# eth
reth-chainspec.workspace = true
reth-chainspec = { workspace = true, features = ["arbitrary"] }
reth-codecs = { workspace = true, features = ["test-utils"] }
reth-primitives-traits = { workspace = true, features = ["arbitrary"] }
reth-testing-utils.workspace = true
reth-trie-common.workspace = true
reth-trie-common = { workspace = true, features = ["arbitrary"] }
revm-primitives = { workspace = true, features = ["arbitrary"] }

alloy-eips = { workspace = true, features = ["arbitrary"] }
Expand Down
17 changes: 17 additions & 0 deletions crates/primitives/src/receipt.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use alloc::{vec, vec::Vec};
use core::cmp::Ordering;
use reth_primitives_traits::InMemorySize;

use alloy_consensus::{
constants::{EIP1559_TX_TYPE_ID, EIP2930_TX_TYPE_ID, EIP4844_TX_TYPE_ID, EIP7702_TX_TYPE_ID},
Expand Down Expand Up @@ -109,6 +110,22 @@ impl ReceiptExt for Receipt {
}
}

impl InMemorySize for Receipt {
/// Calculates a heuristic for the in-memory size of the [Receipt].
#[inline]
fn size(&self) -> usize {
let total_size = self.tx_type.size() +
core::mem::size_of::<bool>() +
core::mem::size_of::<u64>() +
self.logs.capacity() * core::mem::size_of::<Log>();

#[cfg(feature = "optimism")]
return total_size + 2 * core::mem::size_of::<Option<u64>>();
#[cfg(not(feature = "optimism"))]
total_size
}
}

/// A collection of receipts organized as a two-dimensional vector.
#[derive(
Clone,
Expand Down
14 changes: 8 additions & 6 deletions crates/primitives/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1274,12 +1274,6 @@ impl TransactionSigned {
initial_tx
}

/// Calculate a heuristic for the in-memory size of the [`TransactionSigned`].
#[inline]
pub fn size(&self) -> usize {
mem::size_of::<TxHash>() + self.transaction.size() + mem::size_of::<Signature>()
}

/// Decodes legacy transaction from the data buffer into a tuple.
///
/// This expects `rlp(legacy_tx)`
Expand Down Expand Up @@ -1447,6 +1441,14 @@ impl SignedTransaction for TransactionSigned {
}
}

impl InMemorySize for TransactionSigned {
/// Calculate a heuristic for the in-memory size of the [`TransactionSigned`].
#[inline]
fn size(&self) -> usize {
mem::size_of::<TxHash>() + self.transaction.size() + mem::size_of::<Signature>()
}
}

impl alloy_consensus::Transaction for TransactionSigned {
fn chain_id(&self) -> Option<ChainId> {
self.deref().chain_id()
Expand Down
9 changes: 9 additions & 0 deletions crates/primitives/src/transaction/tx_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use alloy_consensus::constants::{
use alloy_primitives::{U64, U8};
use alloy_rlp::{Decodable, Encodable};
use derive_more::Display;
use reth_primitives_traits::InMemorySize;
use serde::{Deserialize, Serialize};

/// Identifier parameter for legacy transaction
Expand Down Expand Up @@ -118,6 +119,14 @@ impl reth_primitives_traits::TxType for TxType {
}
}

impl InMemorySize for TxType {
/// Calculates a heuristic for the in-memory size of the [`TxType`].
#[inline]
fn size(&self) -> usize {
core::mem::size_of::<Self>()
}
}

impl From<TxType> for u8 {
fn from(value: TxType) -> Self {
match value {
Expand Down
23 changes: 23 additions & 0 deletions crates/rpc/rpc-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1999,6 +1999,29 @@ impl TransportRpcModules {
&self.config
}

/// Merge the given [`Methods`] in all configured transport modules if the given
/// [`RethRpcModule`] is configured for the transport.
///
/// Fails if any of the methods in other is present already.
pub fn merge_if_module_configured(
&mut self,
module: RethRpcModule,
other: impl Into<Methods>,
) -> Result<(), RegisterMethodError> {
let other = other.into();
if self.module_config().contains_http(&module) {
self.merge_http(other.clone())?;
}
if self.module_config().contains_ws(&module) {
self.merge_ws(other.clone())?;
}
if self.module_config().contains_ipc(&module) {
self.merge_ipc(other)?;
}

Ok(())
}

/// Merge the given [Methods] in the configured http methods.
///
/// Fails if any of the methods in other is present already.
Expand Down
Loading

0 comments on commit 7f41069

Please sign in to comment.