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: Superchain Registry Types #247

Merged
merged 7 commits into from
Jun 13, 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
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.

25 changes: 22 additions & 3 deletions bin/programs/client/src/l2/executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,15 @@ where
.next_block_excess_blob_gas()
.or_else(|| spec_id.is_enabled_in(SpecId::ECOTONE).then_some(0))
.map(|x| BlobExcessGasAndPrice::new(x as u64));
let next_block_base_fee = parent_header
.next_block_base_fee(config.base_fee_params_at_timestamp(payload_attrs.timestamp))
.unwrap_or_default();
// If the payload attribute timestamp is past canyon activation,
// use the canyon base fee params from the rollup config.
let base_fee_params = if config.is_canyon_active(payload_attrs.timestamp) {
config.canyon_base_fee_params.unwrap_or(config.base_fee_params)
} else {
config.base_fee_params
};
let next_block_base_fee =
parent_header.next_block_base_fee(base_fee_params).unwrap_or_default();

BlockEnv {
number: U256::from(parent_header.number + 1),
Expand Down Expand Up @@ -581,6 +587,7 @@ mod test {
use super::*;
use alloy_primitives::{address, b256, hex};
use alloy_rlp::Decodable;
use kona_derive::types::{OP_BASE_FEE_PARAMS, OP_CANYON_BASE_FEE_PARAMS};
use kona_mpt::NoopTrieDBHinter;
use serde::Deserialize;
use std::{collections::HashMap, format};
Expand Down Expand Up @@ -640,6 +647,8 @@ mod test {
canyon_time: Some(0),
delta_time: Some(0),
ecotone_time: Some(0),
base_fee_params: OP_BASE_FEE_PARAMS,
canyon_base_fee_params: Some(OP_CANYON_BASE_FEE_PARAMS),
..Default::default()
};

Expand Down Expand Up @@ -691,6 +700,8 @@ mod test {
canyon_time: Some(0),
delta_time: Some(0),
ecotone_time: Some(0),
base_fee_params: OP_BASE_FEE_PARAMS,
canyon_base_fee_params: Some(OP_CANYON_BASE_FEE_PARAMS),
..Default::default()
};

Expand Down Expand Up @@ -746,6 +757,8 @@ mod test {
canyon_time: Some(0),
delta_time: Some(0),
ecotone_time: Some(0),
base_fee_params: OP_BASE_FEE_PARAMS,
canyon_base_fee_params: Some(OP_CANYON_BASE_FEE_PARAMS),
..Default::default()
};

Expand Down Expand Up @@ -808,6 +821,8 @@ mod test {
canyon_time: Some(0),
delta_time: Some(0),
ecotone_time: Some(0),
base_fee_params: OP_BASE_FEE_PARAMS,
canyon_base_fee_params: Some(OP_CANYON_BASE_FEE_PARAMS),
..Default::default()
};

Expand Down Expand Up @@ -864,6 +879,8 @@ mod test {
canyon_time: Some(0),
delta_time: Some(0),
ecotone_time: Some(0),
base_fee_params: OP_BASE_FEE_PARAMS,
canyon_base_fee_params: Some(OP_CANYON_BASE_FEE_PARAMS),
..Default::default()
};

Expand Down Expand Up @@ -929,6 +946,8 @@ mod test {
canyon_time: Some(0),
delta_time: Some(0),
ecotone_time: Some(0),
base_fee_params: OP_BASE_FEE_PARAMS,
canyon_base_fee_params: Some(OP_CANYON_BASE_FEE_PARAMS),
..Default::default()
};

Expand Down
88 changes: 27 additions & 61 deletions bin/sync/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
use alloy_primitives::{address, b256, U256};
use anyhow::{anyhow, Result};
use clap::Parser;
use kona_derive::{
online::*,
types::{BlockID, Genesis, RollupConfig, SystemConfig},
};
use kona_derive::{online::*, types::OP_MAINNET_CONFIG};
use reqwest::Url;
use std::sync::Arc;
use tracing::{debug, error, info, warn, Level};
Expand All @@ -20,11 +16,7 @@ const BEACON_URL: &str = "BEACON_URL";
async fn main() -> Result<()> {
let cfg = crate::cli::Cli::parse();
init_tracing_subscriber(cfg.v)?;
info!(target: "sync", "Initialized telemetry");

sync(cfg).await?;

Ok(())
sync(cfg).await
}

async fn sync(cli_cfg: crate::cli::Cli) -> Result<()> {
Expand All @@ -43,43 +35,57 @@ async fn sync(cli_cfg: crate::cli::Cli) -> Result<()> {
cli_cfg.beacon_url.unwrap_or_else(|| std::env::var(BEACON_URL).unwrap());

// Construct the pipeline and payload validator.
let cfg = Arc::new(new_op_mainnet_config());
let cfg = Arc::new(OP_MAINNET_CONFIG);
let start = cli_cfg.start_l2_block.unwrap_or(cfg.genesis.l2.number);
let l1_provider = AlloyChainProvider::new_http(l1_rpc_url);
let mut l1_provider = AlloyChainProvider::new_http(l1_rpc_url);
let mut l2_provider = AlloyL2ChainProvider::new_http(l2_rpc_url.clone(), cfg.clone());
let attributes =
StatefulAttributesBuilder::new(cfg.clone(), l2_provider.clone(), l1_provider.clone());
let beacon_client = OnlineBeaconClient::new_http(beacon_url);
let blob_provider =
OnlineBlobProvider::<_, SimpleSlotDerivation>::new(beacon_client, None, None);
let dap = EthereumDataSource::new(l1_provider.clone(), blob_provider, &cfg);
let mut cursor = l2_provider
.l2_block_info_by_number(start)
.await
.expect("Failed to fetch genesis L2 block info for pipeline cursor");
let tip = l1_provider
.block_info_by_number(cursor.l1_origin.number)
.await
.expect("Failed to fetch genesis L1 block info for pipeline tip");
let mut pipeline =
new_online_pipeline(cfg, l1_provider, dap, l2_provider.clone(), attributes, start).await;
new_online_pipeline(cfg, l1_provider, dap, l2_provider.clone(), attributes, tip).await;
let validator = OnlineValidator::new_http(l2_rpc_url);
let mut derived_attributes_count = 0;

// Continuously step on the pipeline and validate payloads.
loop {
info!(target: "loop", "Validated payload attributes number {}", derived_attributes_count);
info!(target: "loop", "Pending l2 safe head num: {}", pipeline.cursor.block_info.number);
match pipeline.step().await {
info!(target: "loop", "Pending l2 safe head num: {}", cursor.block_info.number);
match pipeline.step(cursor).await {
Ok(_) => info!(target: "loop", "Stepped derivation pipeline"),
Err(e) => warn!(target: "loop", "Error stepping derivation pipeline: {:?}", e),
}

if let Some(attributes) = pipeline.pop() {
if let Some(attributes) = pipeline.next_attributes() {
if !validator.validate(&attributes).await {
error!(target: "loop", "Failed payload validation: {}", attributes.parent.block_info.hash);
continue;
return Ok(());
}
derived_attributes_count += 1;
match l2_provider.l2_block_info_by_number(pipeline.cursor.block_info.number + 1).await {
Ok(bi) => pipeline.update_cursor(bi),
match l2_provider.l2_block_info_by_number(cursor.block_info.number + 1).await {
Ok(bi) => cursor = bi,
Err(e) => {
error!(target: "loop", "Failed to fetch next pending l2 safe head: {}, err: {:?}", pipeline.cursor.block_info.number + 1, e);
error!(target: "loop", "Failed to fetch next pending l2 safe head: {}, err: {:?}", cursor.block_info.number + 1, e);
}
}
dbg!(attributes);
println!(
"Validated Payload Attributes {derived_attributes_count} [L2 Block Num: {}] [L2 Timestamp: {}] [L1 Origin Block Num: {}]",
attributes.parent.block_info.number + 1,
attributes.attributes.timestamp,
pipeline.origin().unwrap().number,
);
info!(target: "loop", "attributes: {:#?}", attributes);
} else {
debug!(target: "loop", "No attributes to validate");
}
Expand All @@ -98,43 +104,3 @@ fn init_tracing_subscriber(v: u8) -> Result<()> {
.finish();
tracing::subscriber::set_global_default(subscriber).map_err(|e| anyhow!(e))
}

fn new_op_mainnet_config() -> RollupConfig {
RollupConfig {
genesis: Genesis {
l1: BlockID {
hash: b256!("438335a20d98863a4c0c97999eb2481921ccd28553eac6f913af7c12aec04108"),
number: 17_422_590_u64,
},
l2: BlockID {
hash: b256!("dbf6a80fef073de06add9b0d14026d6e5a86c85f6d102c36d3d8e9cf89c2afd3"),
number: 105_235_063_u64,
},
timestamp: 1_686_068_903_u64,
system_config: SystemConfig {
batcher_addr: address!("6887246668a3b87f54deb3b94ba47a6f63f32985"),
l1_fee_overhead: U256::from(0xbc),
l1_fee_scalar: U256::from(0xa6fe0),
gas_limit: U256::from(30_000_000_u64),
},
},
block_time: 2_u64,
max_sequencer_drift: 600_u64,
seq_window_size: 3600_u64,
channel_timeout: 300_u64,
l1_chain_id: 1_u64,
l2_chain_id: 10_u64,
regolith_time: Some(0_u64),
canyon_time: Some(1_704_992_401_u64),
delta_time: Some(1_708_560_000_u64),
ecotone_time: Some(1_710_374_401_u64),
fjord_time: Some(1_720_627_201_u64),
interop_time: None,
batch_inbox_address: address!("ff00000000000000000000000000000000000010"),
deposit_contract_address: address!("beb5fc579115071764c7423a4f12edde41f106ed"),
l1_system_config_address: address!("229047fed2591dbec1ef1118d64f7af3db9eb290"),
protocol_versions_address: address!("8062abc286f5e7d9428a0ccb9abd71e50d93b935"),
da_challenge_address: Some(address!("0000000000000000000000000000000000000000")),
blobs_enabled_l1_timestamp: None,
}
}
2 changes: 1 addition & 1 deletion crates/derive/src/online/alloy_providers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ impl L2ChainProvider for AlloyL2ChainProvider {
rollup_config: Arc<RollupConfig>,
) -> Result<SystemConfig> {
if let Some(system_config) = self.system_config_by_number_cache.get(&number) {
return Ok(*system_config);
return Ok(system_config.clone());
}

let envelope = self.payload_by_number(number).await?;
Expand Down
2 changes: 1 addition & 1 deletion crates/derive/src/online/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub use crate::{
pipeline::{DerivationPipeline, PipelineBuilder},
sources::EthereumDataSource,
stages::StatefulAttributesBuilder,
traits::{ChainProvider, L2ChainProvider, Pipeline},
traits::{ChainProvider, L2ChainProvider, OriginProvider, Pipeline},
types::RollupConfig,
};

Expand Down
20 changes: 5 additions & 15 deletions crates/derive/src/online/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ use crate::{
AttributesQueue, BatchQueue, ChannelBank, ChannelReader, FrameQueue, L1Retrieval,
L1Traversal, StatefulAttributesBuilder,
},
traits::{ChainProvider, L2ChainProvider},
types::RollupConfig,
types::{BlockInfo, RollupConfig},
};
use alloc::sync::Arc;

Expand Down Expand Up @@ -44,27 +43,18 @@ pub type OnlineAttributesQueue<DAP> = AttributesQueue<
/// Internally, this uses the [PipelineBuilder] to construct the pipeline.
pub async fn new_online_pipeline(
rollup_config: Arc<RollupConfig>,
mut chain_provider: AlloyChainProvider,
chain_provider: AlloyChainProvider,
dap_source: OnlineDataProvider,
mut l2_chain_provider: AlloyL2ChainProvider,
l2_chain_provider: AlloyL2ChainProvider,
builder: OnlineAttributesBuilder,
start_block: u64,
origin: BlockInfo,
) -> OnlinePipeline {
let cursor = l2_chain_provider
.l2_block_info_by_number(start_block)
.await
.expect("Failed to fetch genesis L2 block info for pipeline cursor");
let tip = chain_provider
.block_info_by_number(cursor.l1_origin.number)
.await
.expect("Failed to fetch genesis L1 block info for pipeline tip");
PipelineBuilder::new()
.rollup_config(rollup_config)
.dap_source(dap_source)
.l2_chain_provider(l2_chain_provider)
.chain_provider(chain_provider)
.builder(builder)
.start_cursor(cursor)
.tip(tip)
.origin(origin)
.build()
}
Loading
Loading