Skip to content

Commit

Permalink
Refactor Taiko specific re-exports for improved code readability and …
Browse files Browse the repository at this point in the history
…maintainability
  • Loading branch information
johntaiko committed Aug 12, 2024
1 parent 1973dd4 commit 77d64ae
Show file tree
Hide file tree
Showing 26 changed files with 1,159 additions and 231 deletions.
28 changes: 28 additions & 0 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 @@ -128,7 +128,8 @@ members = [
"testing/ef-tests/",
"testing/testing-utils",
# Taiko additional crates
"crates/taiko/consensus/",
"crates/taiko/consensus/consensus",
"crates/taiko/consensus/proposer",
"crates/taiko/engine-primitives/",
"crates/taiko/evm",
"crates/taiko/node",
Expand Down Expand Up @@ -353,7 +354,8 @@ reth-trie = { path = "crates/trie/trie" }
reth-trie-common = { path = "crates/trie/common" }
reth-trie-parallel = { path = "crates/trie/parallel" }

taiko-reth-beacon-consensus = { path = "crates/taiko/consensus" }
taiko-reth-beacon-consensus = { path = "crates/taiko/consensus/consensus" }
taiko-reth-proposer-consensus = { path = "crates/taiko/consensus/proposer" }
taiko-reth-primitives = { path = "crates/taiko/primitives" }
taiko-reth-provider = { path = "crates/taiko/storage" }
taiko-reth-evm = { path = "crates/taiko/evm" }
Expand Down
6 changes: 3 additions & 3 deletions crates/blockchain-tree/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,9 @@ impl AppendableChain {
let db = StateProviderDatabase::new(&provider);
let executor = externals.executor_factory.executor(db);
let block_hash = block.hash();
let block = block.unseal();
let mut block = block.unseal();

let state = executor.execute((&block, U256::MAX).into())?;
let state = executor.execute((&mut block, U256::MAX).into())?;
let BlockExecutionOutput { state, receipts, requests, .. } = state;
externals
.consensus
Expand Down Expand Up @@ -239,7 +239,7 @@ impl AppendableChain {
return Err(ConsensusError::BodyStateRootDiff(
GotExpected { got: state_root, expected: block.state_root }.into(),
)
.into())
.into());
}

tracing::debug!(
Expand Down
4 changes: 2 additions & 2 deletions crates/consensus/auto-seal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ impl StorageInner {
&chain_spec,
);

let block = Block {
let mut block = Block {
header,
body: transactions,
ommers: ommers.clone(),
Expand All @@ -387,7 +387,7 @@ impl StorageInner {
requests: block_execution_requests,
gas_used,
..
} = executor.executor(&mut db).execute((&block, U256::ZERO).into())?;
} = executor.executor(&mut db).execute((&mut block, U256::ZERO).into())?;
let execution_outcome = ExecutionOutcome::new(
state,
receipts.into(),
Expand Down
12 changes: 6 additions & 6 deletions crates/evm/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,20 +111,20 @@ pub struct BlockExecutionOutput<T> {
#[derive(Debug)]
pub struct BlockExecutionInput<'a, Block> {
/// The block to execute.
pub block: &'a Block,
pub block: &'a mut Block,
/// The total difficulty of the block.
pub total_difficulty: U256,
}

impl<'a, Block> BlockExecutionInput<'a, Block> {
/// Creates a new input.
pub const fn new(block: &'a Block, total_difficulty: U256) -> Self {
pub fn new(block: &'a mut Block, total_difficulty: U256) -> Self {
Self { block, total_difficulty }
}
}

impl<'a, Block> From<(&'a Block, U256)> for BlockExecutionInput<'a, Block> {
fn from((block, total_difficulty): (&'a Block, U256)) -> Self {
impl<'a, Block> From<(&'a mut Block, U256)> for BlockExecutionInput<'a, Block> {
fn from((block, total_difficulty): (&'a mut Block, U256)) -> Self {
Self::new(block, total_difficulty)
}
}
Expand Down Expand Up @@ -244,14 +244,14 @@ mod tests {
let provider = TestExecutorProvider;
let db = CacheDB::<EmptyDBTyped<ProviderError>>::default();
let executor = provider.executor(db);
let block = Block {
let mut block = Block {
header: Default::default(),
body: vec![],
ommers: vec![],
withdrawals: None,
requests: None,
};
let block = BlockWithSenders::new(block, Default::default()).unwrap();
let _ = executor.execute(BlockExecutionInput::new(&block, U256::ZERO));
let _ = executor.execute(BlockExecutionInput::new(&mut block, U256::ZERO));
}
}
5 changes: 5 additions & 0 deletions crates/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,9 @@ pub trait ConfigureEvmEnv: Send + Sync + Unpin + Clone + 'static {
let after_merge = cfg.handler_cfg.spec_id >= SpecId::MERGE;
fill_block_env(block_env, chain_spec, header, after_merge);
}

/// Returns `true` if the EVM should enable the anchor transaction.
fn enable_anchor(&self) -> bool {
false
}
}
2 changes: 1 addition & 1 deletion crates/node/builder/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ where
.with_events(node.provider().clone())
.with_executor(node.task_executor().clone())
.with_evm_config(node.evm_config().clone())
.build_with_auth_server(module_config, engine_api);
.build_with_auth_server(module_config, engine_api, config.builder.clone());

let mut registry = RpcRegistry { registry };
let ctx = RpcContext {
Expand Down
14 changes: 7 additions & 7 deletions crates/primitives/src/transaction/pooled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ impl PooledTransactionsElement {
/// Returns the signature of the transaction.
pub const fn signature(&self) -> &Signature {
match self {
Self::Legacy { signature, .. } |
Self::Eip2930 { signature, .. } |
Self::Eip1559 { signature, .. } => signature,
Self::Legacy { signature, .. }
| Self::Eip2930 { signature, .. }
| Self::Eip1559 { signature, .. } => signature,
Self::BlobTransaction(blob_tx) => &blob_tx.signature,
}
}
Expand Down Expand Up @@ -183,7 +183,7 @@ impl PooledTransactionsElement {
/// `[chain_id, nonce, max_priority_fee_per_gas, ..., y_parity, r, s]`
pub fn decode_enveloped(data: &mut &[u8]) -> alloy_rlp::Result<Self> {
if data.is_empty() {
return Err(RlpError::InputTooShort)
return Err(RlpError::InputTooShort);
}

// Check if the tx is a list - tx types are less than EMPTY_LIST_CODE (0xc0)
Expand Down Expand Up @@ -493,7 +493,7 @@ impl Decodable for PooledTransactionsElement {
//
// First, we check whether or not the transaction is a legacy transaction.
if buf.is_empty() {
return Err(RlpError::InputTooShort)
return Err(RlpError::InputTooShort);
}

// keep the original buf around for legacy decoding
Expand Down Expand Up @@ -539,7 +539,7 @@ impl Decodable for PooledTransactionsElement {
// check that the bytes consumed match the payload length
let bytes_consumed = remaining_len - buf.len();
if bytes_consumed != header.payload_length {
return Err(RlpError::UnexpectedLength)
return Err(RlpError::UnexpectedLength);
}

Ok(Self::BlobTransaction(blob_tx))
Expand All @@ -551,7 +551,7 @@ impl Decodable for PooledTransactionsElement {
// check that the bytes consumed match the payload length
let bytes_consumed = remaining_len - buf.len();
if bytes_consumed != header.payload_length {
return Err(RlpError::UnexpectedLength)
return Err(RlpError::UnexpectedLength);
}

// because we checked the tx type, we can be sure that the transaction is not a
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc/rpc-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub mod servers {
};

#[cfg(feature = "taiko")]
pub use crate::taiko::TaikoApiServer;
pub use crate::taiko::{PreBuiltTxList, TaikoApiServer, TaikoAuthApiServer};
}

/// re-export of all client traits
Expand Down
54 changes: 39 additions & 15 deletions crates/rpc/rpc-api/src/taiko.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,61 @@
use jsonrpsee::{core::RpcResult, proc_macros::rpc};
use reth_primitives::Address;
use reth_rpc_types::Transaction;
use serde::{Deserialize, Serialize};
use taiko_reth_primitives::L1Origin;

/// Taiko rpc interface.
#[cfg_attr(not(feature = "client"), rpc(server, namespace = "taiko"))]
#[cfg_attr(feature = "client", rpc(server, client, namespace = "taiko"))]
#[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<L1Origin>>;
async fn l1_origin_by_id(&self, block_id: u64) -> RpcResult<L1Origin>;

/// GetL2ParentHeaders
#[method(name = "getL2ParentHeaders")]
async fn get_l2_parent_headers(&self, block_id: u64)
-> RpcResult<Vec<reth_primitives::Header>>;
/// GetSyncMode returns the node sync mode.
#[method(name = "getSyncMode")]
async fn get_sync_mode(&self) -> RpcResult<String> {
Ok("full".to_string())
}
}

/// 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(
/// Taiko rpc interface.
#[rpc(server, client, namespace = "taikoAuth")]
pub trait TaikoAuthApi {
/// Get the transaction pool content.
#[method(name = "txPoolContent")]
async fn tx_pool_content(
&self,
beneficiary: Address,
base_fee: u64,
block_max_gas_limit: u64,
max_bytes_per_tx_list: u64,
locals: Vec<String>,
local_accounts: Vec<Address>,
max_transactions_lists: u64,
) -> RpcResult<Vec<Vec<Transaction>>>;
) -> RpcResult<Vec<PreBuiltTxList>>;

/// Get the transaction pool content with the minimum tip.
#[method(name = "txPoolContentWithMinTip")]
async fn tx_pool_content_with_min_tip(
&self,
beneficiary: Address,
base_fee: u64,
block_max_gas_limit: u64,
max_bytes_per_tx_list: u64,
local_accounts: Vec<Address>,
max_transactions_lists: u64,
min_tip: u64,
) -> RpcResult<Vec<PreBuiltTxList>>;
}

/// PreBuiltTxList is a pre-built transaction list based on the latest chain state,
/// with estimated gas used / bytes.
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct PreBuiltTxList {
pub tx_list: Vec<Transaction>,
pub estimated_gas_used: u64,
pub bytes_length: u64,
}
Loading

0 comments on commit 77d64ae

Please sign in to comment.