Skip to content

Commit

Permalink
rpc batching for accounts/storage accesses
Browse files Browse the repository at this point in the history
  • Loading branch information
Brechtpd committed Apr 22, 2024
1 parent f237da6 commit 07b4f1b
Show file tree
Hide file tree
Showing 5 changed files with 334 additions and 196 deletions.
34 changes: 27 additions & 7 deletions host/src/preflight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ use anyhow::{anyhow, bail, Result};
use c_kzg::{Blob, KzgCommitment};
use hashbrown::HashSet;
use raiko_lib::{
builder::{prepare::TaikoHeaderPrepStrategy, BlockBuilder, TkoTxExecStrategy},
builder::{
prepare::TaikoHeaderPrepStrategy, BlockBuilder, OptimisticDatabase, TkoTxExecStrategy,
},
consts::{get_network_spec, Network},
input::{
decode_anchor, proposeBlockCall, taiko_a6::BlockProposed as TestnetBlockProposed,
Expand All @@ -28,7 +30,7 @@ use raiko_primitives::{
};
use serde::{Deserialize, Serialize};

use crate::provider_db::{MeasuredProviderDb, ProviderDb};
use crate::provider_db::ProviderDb;

pub fn preflight(
rpc_url: Option<String>,
Expand All @@ -41,6 +43,7 @@ pub fn preflight(
let provider = ProviderBuilder::new().provider(RootProvider::new_http(
reqwest::Url::parse(&rpc_url.clone().unwrap()).expect("invalid rpc url"),
));
let is_local = provider.client().is_local();

let measurement = Measurement::start("Fetching block data...", true);

Expand Down Expand Up @@ -189,13 +192,30 @@ pub fn preflight(
network,
parent_block.header.number.unwrap().try_into().unwrap(),
)?;

let mut builder = BlockBuilder::new(&input)
.with_db(MeasuredProviderDb::new(provider_db))
.prepare_header::<TaikoHeaderPrepStrategy>()?
.execute_transactions::<TkoTxExecStrategy>()?;
.with_db(provider_db)
.prepare_header::<TaikoHeaderPrepStrategy>()?;

// Optimize data gathering by executing the transactions multiple times so data can be requested in batches
let max_iterations = if is_local { 1 } else { 50 };
let mut done = false;
let mut num_iterations = 0;
while !done {
println!("Execution iteration {num_iterations}...");
builder.mut_db().unwrap().optimistic = if num_iterations + 1 < max_iterations {
true
} else {
false
};
builder = builder.execute_transactions::<TkoTxExecStrategy>()?;
if builder.mut_db().unwrap().fetch_data() {
done = true;
}
num_iterations += 1;
}
builder = builder.prepare_header::<TaikoHeaderPrepStrategy>()?;
let provider_db = builder.mut_db().unwrap();
provider_db.print_report();
let provider_db = provider_db.db();

// Gather inclusion proofs for the initial and final state
let measurement = Measurement::start("Fetching storage proofs...", true);
Expand Down
Loading

0 comments on commit 07b4f1b

Please sign in to comment.