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

feat: chain prover force curie mode #322

Merged
merged 1 commit into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
20 changes: 10 additions & 10 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ CHAIN_ID ?= 534352
export CHAIN_ID
RUST_MIN_STACK ?= 16777216
export RUST_MIN_STACK
RUST_BACKTRACE=1
export RUST_BACKTRACE

help: ## Display this help screen
@grep -h \
Expand Down
22 changes: 20 additions & 2 deletions bin/src/chain_prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ impl BatchBuilder {
struct ChunkBuilder {
traces: Vec<BlockTrace>,
acc_row_usage_normalized: RowUsage,
block_limit: Option<usize>,
}

/// Same with production "chunk proposer"
Expand All @@ -111,9 +112,22 @@ impl ChunkBuilder {
Self {
traces: Vec::new(),
acc_row_usage_normalized: RowUsage::default(),
block_limit: None,
}
}
pub fn add(&mut self, trace: BlockTrace) -> Option<Vec<BlockTrace>> {
// Condition1: block num
if let Some(block_limit) = self.block_limit {
if self.traces.len() + 1 == block_limit {
// build chunk
let mut chunk = self.traces.clone();
chunk.push(trace.clone());
self.traces.clear();
return Some(chunk);
}
}

// Condition2: ccc
let ccc_result = {
let mut checker = CircuitCapacityChecker::new();
checker.set_light_mode(false);
Expand All @@ -137,6 +151,10 @@ impl ChunkBuilder {
// Construct chunk myself
async fn prove_by_block(l2geth: &l2geth_client::Client, begin_block: i64, end_block: i64) {
let mut chunk_builder = ChunkBuilder::new();
let force_curie = true;
if force_curie {
chunk_builder.block_limit = Some(1);
}
let mut batch_builder = BatchBuilder::new();
let (begin_block, end_block) = if begin_block == 0 && end_block == 0 {
// Blocks within last 24 hours
Expand All @@ -150,7 +168,7 @@ async fn prove_by_block(l2geth: &l2geth_client::Client, begin_block: i64, end_bl
let mut batch_begin_block = begin_block;
for block_num in begin_block..=end_block {
let trace = l2geth
.get_block_trace_by_num(block_num)
.get_block_trace_by_num(block_num, force_curie)
.await
.unwrap_or_else(|e| {
panic!("chain_prover: failed to request l2geth block-trace API for block-{block_num}: {e}")
Expand Down Expand Up @@ -263,7 +281,7 @@ async fn prove_by_batch(
let mut block_traces: Vec<BlockTrace> = vec![];
for block_num in chunk.start_block_number..=chunk.end_block_number {
let trace = l2geth
.get_block_trace_by_num(block_num)
.get_block_trace_by_num(block_num, false)
.await
.unwrap_or_else(|e| {
panic!("chain_prover: failed to request l2geth block-trace API for batch-{batch_id} chunk-{chunk_id} block-{block_num}: {e}")
Expand Down
38 changes: 32 additions & 6 deletions bin/src/l2geth_client.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use anyhow::Result;
use ethers_providers::{Http, Middleware, Provider};
use prover::BlockTrace;
use serde::Serialize;

pub struct Client {
id: String,
Expand All @@ -21,17 +22,42 @@ impl Client {
Ok(self.provider.get_block_number().await?.as_u64())
}

pub async fn get_block_trace_by_num(&self, block_num: i64) -> Result<BlockTrace> {
// when override_curie == true,
// we will force curie hard fork when tracing
pub async fn get_block_trace_by_num(
&self,
block_num: i64,
override_curie: bool,
) -> Result<BlockTrace> {
log::info!("{}: requesting trace of block {}", self.id, block_num);

let params = if override_curie {
// curl -s -H 'Content-Type: application/json' -X POST --data
// '{"jsonrpc":"2.0","method":"scroll_getBlockTraceByNumberOrHash",
// "params": ["0x485490", {"overrides": {"curieBlock":1}}], "id": 99}'
// 127.0.0.1:8545
#[derive(Serialize)]
struct ChainConfig {
#[serde(rename = "curieBlock")]
curie_block: usize,
}
#[derive(Serialize)]
struct TraceConfig {
overrides: ChainConfig,
}
let override_param = TraceConfig {
overrides: ChainConfig {
curie_block: 1, // any small value could be ok
},
};
serde_json::json!([format!("{block_num:#x}"), override_param])
} else {
serde_json::json!([format!("{block_num:#x}")])
};
let trace = self
.provider
.request(
"scroll_getBlockTraceByNumberOrHash",
[format!("{block_num:#x}")],
)
.request("scroll_getBlockTraceByNumberOrHash", params)
.await?;

Ok(trace)
}
}
Loading