Skip to content

Commit

Permalink
feat: implement proving preflight functionality and update related types
Browse files Browse the repository at this point in the history
  • Loading branch information
johntaiko committed Dec 24, 2024
1 parent a012720 commit a91261b
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 110 deletions.
4 changes: 4 additions & 0 deletions Cargo.lock

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

7 changes: 4 additions & 3 deletions crates/taiko/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ reth-errors.workspace = true
reth-rpc-types-compat.workspace = true
reth-execution-types.workspace = true
reth-revm = { workspace = true, features = ["taiko"] }
reth-consensus.workspace = true

# taiko
reth-taiko-chainspec.workspace = true
Expand All @@ -39,6 +40,7 @@ reth-taiko-evm.workspace = true
reth-taiko-payload-builder.workspace = true
reth-taiko-primitives.workspace = true
reth-taiko-forks.workspace = true
reth-execution-errors.workspace = true

# ethereum
alloy-eips.workspace = true
Expand All @@ -48,6 +50,7 @@ alloy-rpc-types-debug.workspace = true
alloy-consensus.workspace = true
alloy-network.workspace = true
revm.workspace = true
revm-primitives.workspace = true

# async
parking_lot.workspace = true
Expand All @@ -63,11 +66,9 @@ serde_json.workspace = true
# misc
jsonrpsee = { workspace = true, features = ["server", "macros"] }
serde = { workspace = true, features = ["derive"] }


# misc
thiserror.workspace = true
tracing.workspace = true
futures-util.workspace = true

[dev-dependencies]
reth-taiko-chainspec.workspace = true
Expand Down
35 changes: 21 additions & 14 deletions crates/taiko/rpc/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ use reth_provider::{
};
use reth_rpc_eth_api::TransactionCompat;
use reth_rpc_server_types::ToRpcResult;
use reth_rpc_types_compat::transaction::{from_recovered, from_recovered_with_block_context};
use reth_rpc_types_compat::transaction::from_recovered;
use reth_taiko_chainspec::TaikoChainSpec;
use reth_taiko_primitives::L1Origin;
use reth_taiko_proposer_consensus::{ProposerBuilder, ProposerClient};
use reth_tasks::TaskSpawner;
use reth_transaction_pool::{PoolConsensusTx, PoolTransaction, TransactionPool};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use tracing::debug;

use crate::implementation::{TaikoImplBuilder, TaikoImplClient};

/// Taiko rpc interface.
#[rpc(server, client, namespace = "taiko")]
pub trait TaikoApi {
Expand Down Expand Up @@ -72,16 +73,14 @@ pub trait TaikoAuthApi {
) -> RpcResult<Vec<PreBuiltTxList>>;

/// GetSyncMode returns the node sync mode.
#[method(name = "provingPreFlight")]
async fn proving_pre_flight(&self, block_id: BlockId) -> RpcResult<ProvingPreFlight> {
todo!()
}
#[method(name = "provingPreflight")]
async fn proving_preflight(&self, block_id: BlockId) -> RpcResult<ProvingPreflight>;
}

/// `PreFlight` is the pre-flight data for the proving process.
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ProvingPreFlight {
pub struct ProvingPreflight {
/// The block to be proven.
pub block: RpcBlock,
/// The parent header.
Expand Down Expand Up @@ -112,7 +111,7 @@ pub struct PreBuiltTxList {
/// Taiko API.
#[derive(Debug)]
pub struct TaikoAuthApi<Provider, Pool, BlockExecutor, Eth> {
proposer_client: ProposerClient,
taiko_impl_client: TaikoImplClient,
tx_resp_builder: Eth,
_marker: std::marker::PhantomData<(Provider, Pool, BlockExecutor)>,
}
Expand Down Expand Up @@ -140,11 +139,11 @@ where
tx_resp_builder: Eth,
) -> Self {
let chain_spec = provider.chain_spec();
let (_, proposer_client, proposer_task) =
ProposerBuilder::new(chain_spec, provider, pool, block_executor).build();
let (_, taiko_impl_client, proposer_task) =
TaikoImplBuilder::new(chain_spec, provider, pool, block_executor).build();
task_spawner.spawn(Box::pin(proposer_task));

Self { proposer_client, tx_resp_builder, _marker: Default::default() }
Self { taiko_impl_client, tx_resp_builder, _marker: Default::default() }
}
}
/// Taiko API
Expand Down Expand Up @@ -173,8 +172,9 @@ where
}

/// L1OriginByID returns the L2 block's corresponding L1 origin.
async fn l1_origin_by_id(&self, block_id: U256) -> RpcResult<L1Origin> {
let block_number = block_id.try_into().map_err(RethError::other).to_rpc_result()?;
async fn l1_origin_by_id(&self, block_id: BlockId) -> RpcResult<L1Origin> {
let block_number =
block_id.as_u64().ok_or_else(|| RethError::msg("invalid block id")).to_rpc_result()?;
let res = self.provider.get_l1_origin(block_number).to_rpc_result();
debug!(target: "rpc::taiko", ?block_number, ?res, "Read l1 origin by id");
res
Expand Down Expand Up @@ -235,7 +235,7 @@ where
"Read tx pool context"
);
let res = self
.proposer_client
.taiko_impl_client
.tx_pool_content_with_min_tip(
beneficiary,
base_fee,
Expand Down Expand Up @@ -265,4 +265,11 @@ where
debug!(target: "rpc::taiko", ?res, "Read tx pool context");
res
}

async fn proving_preflight(&self, block_id: BlockId) -> RpcResult<ProvingPreflight> {
debug!(target: "rpc::taiko", ?block_id, "Read proving preflight");
let res = self.taiko_impl_client.proving_pre_flight(block_id).await.to_rpc_result();
debug!(target: "rpc::taiko", ?res, "Read proving pre flight");
res
}
}
6 changes: 4 additions & 2 deletions crates/taiko/rpc/src/implementation/client.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
//! This includes download client implementations for auto sealing miners.
use crate::ProvingPreflight;

use super::TaikoImplMessage;
use crate::{TaskArgs, TaskResult};
use alloy_eips::BlockId;
use alloy_primitives::Address;
use reth_errors::RethError;
use reth_provider::TaskResult;
use std::fmt::Debug;
use tokio::sync::{mpsc::UnboundedSender, oneshot};

Expand Down Expand Up @@ -56,7 +58,7 @@ impl TaikoImplClient {
pub async fn proving_pre_flight(
&self,
block_id: BlockId,
) -> Result<Vec<TaskResult>, RethError> {
) -> Result<ProvingPreflight, RethError> {
let (tx, rx) = oneshot::channel();
self.tx.send(TaikoImplMessage::ProvingPreFlight { block_id, tx }).unwrap();
rx.await.unwrap()
Expand Down
42 changes: 9 additions & 33 deletions crates/taiko/rpc/src/implementation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,22 @@
//! These downloaders poll the miner, assemble the block, and return transactions that are ready to
//! be mined.
#![doc(
html_logo_url = "https://raw.githubusercontent.com/paradigmxyz/reth/main/assets/reth-docs.png",
html_favicon_url = "https://avatars0.githubusercontent.com/u/97369466?s=256",
issue_tracker_base_url = "https://github.com/paradigmxyz/reth/issues/"
)]

mod client;
mod proposer;
mod task;

pub use crate::client::ProposerClient;
use crate::ProvingPreFlight;
use alloy_eips::{eip4895::Withdrawals, eip7685::Requests, merge::BEACON_NONCE, BlockId};
use alloy_primitives::{Address, U256};
use reth_chainspec::EthereumHardforks;
use crate::ProvingPreflight;
use alloy_eips::BlockId;
use alloy_primitives::Address;
pub use client::TaikoImplClient;
use reth_consensus::noop::NoopConsensus;
use reth_errors::RethError;
use reth_evm::execute::{
BlockExecutionInput, BlockExecutionOutput, BlockExecutorProvider, Executor,
};
use reth_execution_errors::{
BlockExecutionError, BlockValidationError, InternalBlockExecutionError,
};
use reth_execution_types::TaskResult;
use reth_primitives::{
proofs, Block, BlockBody, BlockExt, Header, NodePrimitives, TransactionSigned,
};
use reth_provider::{BlockReaderIdExt, StateProviderFactory};
use reth_revm::database::StateProviderDatabase;
use reth_taiko_chainspec::TaikoChainSpec;
use reth_taiko_rpc::ProvingPreFlight;
use reth_transaction_pool::TransactionPool;
use revm_primitives::calc_excess_blob_gas;
use std::{
sync::Arc,
time::{SystemTime, UNIX_EPOCH},
};
use std::sync::Arc;
pub use task::TaikoImplTask;
use tokio::sync::oneshot;
use tracing::debug;

/// Builder type for configuring the setup
#[derive(Debug)]
Expand Down Expand Up @@ -76,11 +52,11 @@ where
#[track_caller]
pub fn build(
self,
) -> (NoopConsensus, ProposerClient, TaikoImplTask<Provider, Pool, BlockExecutor>) {
) -> (NoopConsensus, TaikoImplClient, TaikoImplTask<Provider, Pool, BlockExecutor>) {
let Self { provider: client, consensus, chain_spec, pool, block_executor: evm_config } =
self;
let (trigger_args_tx, trigger_args_rx) = tokio::sync::mpsc::unbounded_channel();
let auto_client = ProposerClient::new(trigger_args_tx);
let auto_client = TaikoImplClient::new(trigger_args_tx);
let task =
TaikoImplTask::new(Arc::clone(&chain_spec), client, pool, evm_config, trigger_args_rx);
(consensus, auto_client, task)
Expand All @@ -89,7 +65,7 @@ where

/// Message types for the proposer
#[derive(Debug)]
pub enum TaikoImplMessage {
enum TaikoImplMessage {
PoolContent {
/// Address of the beneficiary
beneficiary: Address,
Expand All @@ -111,6 +87,6 @@ pub enum TaikoImplMessage {
ProvingPreFlight {
block_id: BlockId,
/// Response channel
tx: oneshot::Sender<Result<ProvingPreFlight, RethError>>,
tx: oneshot::Sender<Result<ProvingPreflight, RethError>>,
},
}
1 change: 1 addition & 0 deletions crates/taiko/rpc/src/implementation/preflight.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

7 changes: 1 addition & 6 deletions crates/taiko/rpc/src/implementation/proposer.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use super::task::TaikoImplTask;
use crate::ProvingPreFlight;
use alloy_eips::{eip4895::Withdrawals, eip7685::Requests, merge::BEACON_NONCE};
use alloy_primitives::{Address, U256};
use reth_chainspec::EthereumHardforks;
use reth_consensus::noop::NoopConsensus;
use reth_errors::RethError;
use reth_evm::execute::{
BlockExecutionInput, BlockExecutionOutput, BlockExecutorProvider, Executor,
Expand All @@ -18,13 +15,11 @@ use reth_primitives::{
use reth_provider::{BlockReaderIdExt, StateProviderFactory};
use reth_revm::database::StateProviderDatabase;
use reth_taiko_chainspec::TaikoChainSpec;
use reth_transaction_pool::TransactionPool;
use revm_primitives::calc_excess_blob_gas;
use std::{
sync::Arc,
time::{SystemTime, UNIX_EPOCH},
};
use tokio::sync::oneshot;
use tracing::debug;

/// Fills in pre-execution header fields based on the current best block and given
Expand Down Expand Up @@ -108,7 +103,7 @@ where
///
/// This returns the header of the executed block, as well as the poststate from execution.
#[allow(clippy::too_many_arguments)]
fn build_and_execute<Provider, Executor>(
pub fn build_and_execute<Provider, Executor>(
transactions: Vec<TransactionSigned>,
ommers: Vec<Header>,
provider: &Provider,
Expand Down
Loading

0 comments on commit a91261b

Please sign in to comment.