Skip to content

Commit

Permalink
feat: Move taiko features to separate rpc module
Browse files Browse the repository at this point in the history
  • Loading branch information
petarvujovic98 committed Jun 12, 2024
1 parent 04096c8 commit 41823f0
Show file tree
Hide file tree
Showing 21 changed files with 327 additions and 219 deletions.
26 changes: 14 additions & 12 deletions Cargo.lock

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

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ members = [
"crates/payload/basic/",
"crates/payload/builder/",
"crates/payload/primitives",
"crates/payload/ethereum/",
"crates/payload/optimism/",
"crates/ethereum/payload",
"crates/optimism/payload",
"crates/payload/taiko/",
"crates/payload/validator/",
"crates/primitives/",
Expand Down Expand Up @@ -300,6 +300,7 @@ reth-node-core = { path = "crates/node-core" }
reth-node-ethereum = { path = "crates/ethereum/node" }
reth-node-events = { path = "crates/node/events" }
reth-node-optimism = { path = "crates/optimism/node" }
reth-node-taiko = { path = "crates/node-taiko" }
reth-optimism-consensus = { path = "crates/optimism/consensus" }
reth-optimism-payload-builder = { path = "crates/optimism/payload" }
reth-optimism-primitives = { path = "crates/optimism/primitives" }
Expand Down Expand Up @@ -328,6 +329,7 @@ reth-static-file = { path = "crates/static-file/static-file" }
reth-static-file-types = { path = "crates/static-file/types" }
reth-storage-api = { path = "crates/storage/storage-api" }
reth-storage-errors = { path = "crates/storage/errors" }
reth-taiko-payload-builder = { path = "crates/payload/taiko" }
reth-tasks = { path = "crates/tasks" }
reth-testing-utils = { path = "testing/testing-utils" }
reth-tokio-util = { path = "crates/tokio-util" }
Expand Down
1 change: 1 addition & 0 deletions crates/node-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ reth-consensus-common.workspace = true
reth-beacon-consensus.workspace = true
reth-prune-types.workspace = true
reth-stages-types.workspace = true
reth-payload-builder = { workspace = true, optional = true }

# ethereum
alloy-rpc-types-engine.workspace = true
Expand Down
2 changes: 2 additions & 0 deletions crates/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ tempfile = { workspace = true, optional = true }
thiserror.workspace = true
zstd = { version = "0.13", features = ["experimental"], optional = true }
roaring = "0.10.2"
strum.workspace = true
num_enum = "0.7.2"

# `test-utils` feature
hash-db = { version = "~0.15", optional = true }
Expand Down
9 changes: 5 additions & 4 deletions crates/primitives/src/alloy_compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ impl TryFrom<alloy_rpc_types::Block> for Block {
))
})
.collect(),
alloy_rpc_types::BlockTransactions::Hashes(_) |
alloy_rpc_types::BlockTransactions::Uncle => {
alloy_rpc_types::BlockTransactions::Hashes(_)
| alloy_rpc_types::BlockTransactions::Uncle => {
// alloy deserializes empty blocks into `BlockTransactions::Hashes`, if the tx
// root is the empty root then we can just return an empty vec.
if block.header.transactions_root == EMPTY_TRANSACTIONS {
Expand Down Expand Up @@ -127,7 +127,7 @@ impl TryFrom<alloy_rpc_types::Transaction> for Transaction {
return Err(ConversionError::Eip2718Error(
RlpError::Custom("EIP-1559 fields are present in a legacy transaction")
.into(),
))
));
}

// extract the chain id if possible
Expand All @@ -143,7 +143,7 @@ impl TryFrom<alloy_rpc_types::Transaction> for Transaction {
.map_err(|err| ConversionError::Eip2718Error(err.into()))?
.1
} else {
return Err(ConversionError::MissingChainId)
return Err(ConversionError::MissingChainId);
}
}
};
Expand Down Expand Up @@ -196,6 +196,7 @@ impl TryFrom<alloy_rpc_types::Transaction> for Transaction {
value: tx.value,
access_list: tx.access_list.ok_or(ConversionError::MissingAccessList)?,
input: tx.input,
is_anchor: false,
}))
}
Some(TxType::Eip4844) => {
Expand Down
4 changes: 3 additions & 1 deletion crates/primitives/src/chain/taiko.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::collections::BTreeMap;

use alloy_chains::Chain;
use alloy_genesis::{ChainConfig, Genesis, GenesisAccount};
use alloy_trie::HashMap;
use revm_primitives::{Address, Bytes, FixedBytes, U256};

/// Taiko Chain Configuration, sets the chain_id to the internal devnet L2A by default.
Expand Down Expand Up @@ -33,6 +32,9 @@ pub fn taiko_base_config() -> ChainConfig {
ethash: None,
clique: None,
extra_fields: Default::default(),
prague_time: None,
parlia: None,
deposit_contract_address: None,
}
}

Expand Down
16 changes: 0 additions & 16 deletions crates/rpc/rpc-api/src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,20 +307,4 @@ pub trait EthApi {
keys: Vec<JsonStorageKey>,
block_number: Option<BlockId>,
) -> RpcResult<EIP1186AccountProofResponse>;

/// HeadL1Origin returns the latest L2 block's corresponding L1 origin.
#[cfg(feature = "taiko")]
#[method(name = "headL1Origin")]
async fn head_l1_origin(&self) -> RpcResult<Option<u64>>;

/// L1OriginByID returns the L2 block's corresponding L1 origin.
#[cfg(feature = "taiko")]
#[method(name = "l1OriginByID")]
async fn l1_origin_by_id(&self, block_id: u64) -> RpcResult<Option<reth_primitives::L1Origin>>;

/// GetL2ParentHeaders
#[cfg(feature = "taiko")]
#[method(name = "getL2ParentHeaders")]
async fn get_l2_parent_headers(&self, block_id: u64)
-> RpcResult<Vec<reth_primitives::Header>>;
}
3 changes: 3 additions & 0 deletions crates/rpc/rpc-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ mod optimism;
mod otterscan;
mod reth;
mod rpc;
mod taiko;
mod trace;
mod txpool;
mod validation;
Expand All @@ -53,6 +54,7 @@ pub mod servers {
otterscan::OtterscanServer,
reth::RethApiServer,
rpc::RpcApiServer,
taiko::TaikoApiServer,
trace::TraceApiServer,
txpool::TxPoolApiServer,
validation::BlockSubmissionValidationApiServer,
Expand Down Expand Up @@ -81,6 +83,7 @@ pub mod clients {
net::NetApiClient,
otterscan::OtterscanClient,
rpc::RpcApiServer,
taiko::TaikoApiClient,
trace::TraceApiClient,
txpool::TxPoolApiClient,
validation::BlockSubmissionValidationApiClient,
Expand Down
36 changes: 36 additions & 0 deletions crates/rpc/rpc-api/src/taiko.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use jsonrpsee::{core::RpcResult, proc_macros::rpc};
use reth_primitives::Address;
use reth_rpc_types::Transaction;

/// Taiko rpc interface.
#[cfg_attr(not(feature = "client"), rpc(server, namespace = "taiko"))]
#[cfg_attr(feature = "client", rpc(server, client, namespace = "taiko"))]
pub trait TaikoApi {
/// HeadL1Origin returns the latest L2 block's corresponding L1 origin.
#[method(name = "headL1Origin")]
async fn head_l1_origin(&self) -> RpcResult<Option<u64>>;

/// L1OriginByID returns the L2 block's corresponding L1 origin.
#[method(name = "l1OriginByID")]
async fn l1_origin_by_id(&self, block_id: u64) -> RpcResult<Option<reth_primitives::L1Origin>>;

/// GetL2ParentHeaders
#[method(name = "getL2ParentHeaders")]
async fn get_l2_parent_headers(&self, block_id: u64)
-> RpcResult<Vec<reth_primitives::Header>>;

/// Returns the details of all transactions currently pending for inclusion in the next
/// block(s), as well as the ones that are being scheduled for future execution only.
///
/// See [here](https://geth.ethereum.org/docs/rpc/ns-txpool#txpool_content) for more details
#[method(name = "content")]
async fn txpool_content(
&self,
beneficiary: Address,
base_fee: u64,
block_max_gas_limit: u64,
max_bytes_per_tx_list: u64,
locals: Vec<String>,
max_transactions_lists: u64,
) -> RpcResult<Vec<Vec<Transaction>>>;
}
12 changes: 0 additions & 12 deletions crates/rpc/rpc-api/src/txpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,4 @@ pub trait TxPoolApi {
/// See [here](https://geth.ethereum.org/docs/rpc/ns-txpool#txpool_content) for more details
#[method(name = "content")]
async fn txpool_content(&self) -> RpcResult<TxpoolContent>;
// TODO:(petar) implement this method
// #[method(name = "content")]
// #[cfg(feature = "taiko")]
// async fn txpool_content(
// &self,
// beneficiary: Address,
// base_fee: u64,
// block_max_gas_limit: u64,
// max_bytes_per_tx_list: u64,
// locals: Vec<String>,
// max_transactions_lists: u64,
// ) -> Result<Vec<Vec<Transaction>>>;
}
Loading

0 comments on commit 41823f0

Please sign in to comment.