Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

impl reth preflight interface #441

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

1 change: 1 addition & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ clap = { workspace = true }
assert_cmd = { workspace = true }
rstest = { workspace = true }
ethers-core = { workspace = true }
env_logger = { workspace = true }

[features]
# powdr = ["dep:powdr"]
Expand Down
79 changes: 72 additions & 7 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use tracing::{debug, error, info, warn};

use crate::{
interfaces::{ProofRequest, RaikoError, RaikoResult},
preflight::{preflight, PreflightData},
preflight::{preflight, preflight_v2, PreflightData},
provider::BlockDataProvider,
};

Expand All @@ -31,18 +31,21 @@ pub struct Raiko {
l1_chain_spec: ChainSpec,
taiko_chain_spec: ChainSpec,
request: ProofRequest,
v2_preflight: bool,
}

impl Raiko {
pub fn new(
l1_chain_spec: ChainSpec,
taiko_chain_spec: ChainSpec,
request: ProofRequest,
v2_preflight: bool,
) -> Self {
Self {
l1_chain_spec,
taiko_chain_spec,
request,
v2_preflight,
}
}

Expand All @@ -63,15 +66,46 @@ impl Raiko {
pub async fn generate_input<BDP: BlockDataProvider>(
&self,
provider: BDP,
) -> RaikoResult<GuestInput> {
if self.v2_preflight {
self.generate_input_v2(provider).await
} else {
self.generate_input_v1(provider).await
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the difference between the preflight_v1() and preflight_v2()? What is the rationale behind dividing them into two separate functions?

Here is my consideration. I have tried to diff preflight_v1() and preflight_v2() and found that they are nearly the same. So I think we may not to divide them.

Also, generate_input_v1() and generate_input_v2() are in the same issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, so far they are nearly the same, I separated for easier code impl for now, after node running, there will be some updates in execute_tx part, will see if the diff is big enough or not later on.

}

// v1 uses the geth node & batched rpc calls
pub async fn generate_input_v1<BDP: BlockDataProvider>(
&self,
provider: BDP,
) -> RaikoResult<GuestInput> {
//TODO: read fork from config
let preflight_data = self.get_preflight_data();
info!("Generating input for block {}", self.request.block_number);
info!(
"Generating v1(common-batch) input for block {}",
self.request.block_number
);
preflight(provider, preflight_data)
.await
.map_err(Into::<RaikoError>::into)
}

// v2 uses the taiko node & single preflight rpc call together with the block rpc calls
pub async fn generate_input_v2<BDP: BlockDataProvider>(
&self,
provider: BDP,
) -> RaikoResult<GuestInput> {
//TODO: read fork from config
let preflight_data = self.get_preflight_data();
info!(
"Generating v2(reth-preflight) input for block {}",
self.request.block_number
);
preflight_v2(provider, preflight_data)
.await
.map_err(Into::<RaikoError>::into)
}

pub fn get_output(&self, input: &GuestInput) -> RaikoResult<GuestOutput> {
let db = create_mem_db(&mut input.clone()).unwrap();
let mut builder = RethBlockBuilder::new(input, db);
Expand Down Expand Up @@ -215,9 +249,14 @@ pub fn merge(a: &mut Value, b: &Value) {
#[cfg(test)]
mod tests {
use crate::interfaces::aggregate_proofs;
use crate::{interfaces::ProofRequest, provider::rpc::RpcBlockDataProvider, ChainSpec, Raiko};
use crate::{
interfaces::ProofRequest,
provider::{BlockDataProviderType, RethPreflightBlockDataProvider, RpcBlockDataProvider},
ChainSpec, Raiko,
};
use alloy_primitives::Address;
use alloy_provider::Provider;
use env_logger;
use raiko_lib::{
consts::{Network, SupportedChainSpecs},
input::{AggregationGuestInput, AggregationGuestOutput, BlobProofType},
Expand Down Expand Up @@ -288,10 +327,34 @@ mod tests {
taiko_chain_spec: ChainSpec,
proof_request: ProofRequest,
) -> Proof {
let provider =
RpcBlockDataProvider::new(&taiko_chain_spec.rpc, proof_request.block_number - 1)
.expect("Could not create RpcBlockDataProvider");
let raiko = Raiko::new(l1_chain_spec, taiko_chain_spec, proof_request.clone());
let v2_preflight = std::env::var("V2_PREFLIGHT")
.unwrap_or("false".to_string())
.parse()
.unwrap();
let provider = if v2_preflight {
let provider: RethPreflightBlockDataProvider = RethPreflightBlockDataProvider::new(
&taiko_chain_spec.rpc.clone(),
proof_request.block_number - 1,
)
.await
.expect("new RethPreflightBlockDataProvider should be ok");
BlockDataProviderType::PreflightRpc(provider)
} else {
let provider = RpcBlockDataProvider::new(
&taiko_chain_spec.rpc.clone(),
proof_request.block_number - 1,
)
.expect("new RpcBlockDataProvider should be ok");
BlockDataProviderType::CommonRpc(provider)
};

let raiko = Raiko::new(
l1_chain_spec,
taiko_chain_spec,
proof_request.clone(),
v2_preflight,
);

let input = raiko
.generate_input(provider)
.await
Expand Down Expand Up @@ -335,6 +398,8 @@ mod tests {

#[tokio::test(flavor = "multi_thread")]
async fn test_prove_block_taiko_a7() {
let _ = env_logger::builder().is_test(true).try_init();

let proof_type = get_proof_type_from_env();
let l1_network = Network::Holesky.to_string();
let network = Network::TaikoA7.to_string();
Expand Down
35 changes: 4 additions & 31 deletions core/src/preflight/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ use std::collections::HashSet;
use alloy_primitives::Bytes;
use raiko_lib::{
builder::RethBlockBuilder,
consts::ChainSpec,
input::{BlobProofType, GuestInput, TaikoGuestInput, TaikoProverData},
input::{GuestInput, TaikoGuestInput},
primitives::mpt::proofs_to_tries,
Measurement,
};
Expand All @@ -16,36 +15,10 @@ use crate::{

use util::{execute_txs, get_block_and_parent_data, prepare_taiko_chain_input};

mod reth_preflight;
mod util;

pub struct PreflightData {
pub block_number: u64,
pub l1_chain_spec: ChainSpec,
pub l1_inclusion_block_number: u64,
pub taiko_chain_spec: ChainSpec,
pub prover_data: TaikoProverData,
pub blob_proof_type: BlobProofType,
}

impl PreflightData {
pub fn new(
block_number: u64,
l1_inclusion_block_number: u64,
l1_chain_spec: ChainSpec,
taiko_chain_spec: ChainSpec,
prover_data: TaikoProverData,
blob_proof_type: BlobProofType,
) -> Self {
Self {
block_number,
l1_chain_spec,
l1_inclusion_block_number,
taiko_chain_spec,
prover_data,
blob_proof_type,
}
}
}
pub use reth_preflight::{preflight_v2, PreFlightRpcData};
pub use util::PreflightData;

pub async fn preflight<BDP: BlockDataProvider>(
provider: BDP,
Expand Down
Loading