Skip to content

Commit

Permalink
feat: System config update event parsing (#42)
Browse files Browse the repository at this point in the history
* feat: System config update event parsing

* clean up enum
  • Loading branch information
clabby authored Feb 24, 2024
1 parent d9c45d0 commit 1ca215b
Show file tree
Hide file tree
Showing 12 changed files with 530 additions and 33 deletions.
112 changes: 112 additions & 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 crates/derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ anyhow.workspace = true
# External
alloy-primitives = { version = "0.6.3", default-features = false, features = ["rlp"] }
alloy-rlp = { version = "0.3.4", default-features = false, features = ["derive"] }
alloy-sol-types = { version = "0.6.3", default-features = false }
async-trait = "0.1.77"

# Optional
Expand Down
4 changes: 2 additions & 2 deletions crates/derive/src/stages/l1_traversal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ use anyhow::{anyhow, bail, Result};

/// The L1 traversal stage of the derivation pipeline.
#[derive(Debug, Clone, Copy)]
pub struct L1Traversal<F: ChainProvider> {
pub struct L1Traversal<Provider: ChainProvider> {
/// The current block in the traversal stage.
block: Option<BlockInfo>,
/// The data source for the traversal stage.
data_source: F,
data_source: Provider,
/// Signals whether or not the traversal stage has been completed.
done: bool,
/// The system config
Expand Down
2 changes: 0 additions & 2 deletions crates/derive/src/types/eips/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,4 @@ pub mod eip4788;
pub mod eip4844;
pub use eip4844::{calc_blob_gasprice, calc_excess_blob_gas};

pub mod deposit;

pub mod merge;
19 changes: 19 additions & 0 deletions crates/derive/src/types/genesis.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//! This module contains the [Genesis] type.

use super::{BlockId, SystemConfig};

/// Represents the genesis state of the rollup.
#[derive(Debug, Clone, Copy)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Genesis {
/// The L1 block that the rollup starts *after* (no derived transactions)
pub l1: BlockId,
/// The L2 block the rollup starts from (no transactions, pre-configured state)
pub l2: BlockId,
/// Timestamp of the L2 block.
pub timestamp: u64,
/// Initial system configuration values.
/// The L2 genesis block may not include transactions, and thus cannot encode the config values,
/// unlike later L2 blocks.
pub system_config: SystemConfig,
}
9 changes: 9 additions & 0 deletions crates/derive/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ mod rollup_config;
pub use rollup_config::RollupConfig;

mod transaction;
pub use transaction::{TxDeposit, TxEip1559, TxEip2930, TxEip4844, TxEnvelope, TxLegacy, TxType};

mod network;
pub use network::{Receipt as NetworkReceipt, Sealable, Sealed, Transaction, TxKind};

mod header;
pub use header::{Header, EMPTY_OMMER_ROOT_HASH, EMPTY_ROOT_HASH};
Expand All @@ -20,3 +22,10 @@ mod receipt;
pub use receipt::{Receipt, ReceiptWithBloom};

mod eips;
pub use eips::{
calc_blob_gasprice, calc_excess_blob_gas, calc_next_block_base_fee, eip1559, eip2718, eip2930,
eip4788, eip4844,
};

mod genesis;
pub use genesis::Genesis;
12 changes: 0 additions & 12 deletions crates/derive/src/types/network/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,3 @@ pub use transaction::{Eip1559Transaction, Signed, Transaction, TxKind};

mod receipt;
pub use receipt::Receipt;

/// A list of transactions, either hydrated or hashes.
// #[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
// #[serde(untagged)]
pub enum TransactionList<T> {
/// Hashes only.
Hashes(Vec<B256>),
/// Hydrated tx objects.
Hydrated(Vec<T>),
/// Special case for uncle response
Uncled,
}
72 changes: 71 additions & 1 deletion crates/derive/src/types/rollup_config.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
//! This module contains the [RollupConfig] type.

use super::Genesis;
use alloy_primitives::Address;

/// The Rollup configuration.
#[derive(Debug, Clone, Copy)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct RollupConfig {
/// The genesis state of the rollup.
pub genesis: Genesis,
/// The block time of the L2, in seconds.
pub block_time: u64,
/// Sequencer batches may not be more than MaxSequencerDrift seconds after
Expand All @@ -14,7 +18,7 @@ pub struct RollupConfig {
/// the L2 time may still grow beyond this difference.
pub max_sequencer_drift: u64,
/// The sequencer window size.
pub sequencer_window_size: u64,
pub seq_window_size: u64,
/// Number of L1 blocks between when a channel can be opened and when it can be closed.
pub channel_timeout: u64,
/// The L1 chain ID
Expand All @@ -25,21 +29,27 @@ pub struct RollupConfig {
/// a pre-mainnet Bedrock change that addresses findings of the Sherlock contest related to deposit attributes.
/// "Regolith" is the loose deposited rock that sits on top of Bedrock.
/// Active if regolith_time != None && L2 block timestamp >= Some(regolith_time), inactive otherwise.
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
pub regolith_time: Option<u64>,
/// `canyon_time` sets the activation time of the Canyon network upgrade.
/// Active if `canyon_time` != None && L2 block timestamp >= Some(canyon_time), inactive otherwise.
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
pub canyon_time: Option<u64>,
/// `delta_time` sets the activation time of the Delta network upgrade.
/// Active if `delta_time` != None && L2 block timestamp >= Some(delta_time), inactive otherwise.
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
pub delta_time: Option<u64>,
/// `ecotone_time` sets the activation time of the Ecotone network upgrade.
/// Active if `ecotone_time` != None && L2 block timestamp >= Some(ecotone_time), inactive otherwise.
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
pub ecotone_time: Option<u64>,
/// `fjord_time` sets the activation time of the Fjord network upgrade.
/// Active if `fjord_time` != None && L2 block timestamp >= Some(fjord_time), inactive otherwise.
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
pub fjord_time: Option<u64>,
/// `interop_time` sets the activation time for an experimental feature-set, activated like a hardfork.
/// Active if `interop_time` != None && L2 block timestamp >= Some(interop_time), inactive otherwise.
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
pub interop_time: Option<u64>,
/// `batch_inbox_address` is the L1 address that batches are sent to.
pub batch_inbox_address: Address,
Expand All @@ -50,7 +60,67 @@ pub struct RollupConfig {
/// `protocol_versions_address` is the L1 address that the protocol versions are stored at.
pub protocol_versions_address: Address,
/// `blobs_enabled_l1_timestamp` is the timestamp to start reading blobs as a batch data source. Optional.
#[cfg_attr(
feature = "serde",
serde(rename = "blobs_data", skip_serializing_if = "Option::is_none")
)]
pub blobs_enabled_l1_timestamp: Option<u64>,
/// `da_challenge_address` is the L1 address that the data availability challenge contract is stored at.
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
pub da_challenge_address: Option<Address>,
}

impl RollupConfig {
/// Returns true if Regolith is active at the given timestamp.
pub fn is_regolith_active(&self, timestamp: u64) -> bool {
self.regolith_time.map_or(false, |t| timestamp >= t)
}

/// Returns true if Canyon is active at the given timestamp.
pub fn is_canyon_active(&self, timestamp: u64) -> bool {
self.canyon_time.map_or(false, |t| timestamp >= t)
}

/// Returns true if Delta is active at the given timestamp.
pub fn is_delta_active(&self, timestamp: u64) -> bool {
self.delta_time.map_or(false, |t| timestamp >= t)
}

/// Returns true if Ecotone is active at the given timestamp.
pub fn is_ecotone_active(&self, timestamp: u64) -> bool {
self.ecotone_time.map_or(false, |t| timestamp >= t)
}

/// Returns true if Fjord is active at the given timestamp.
pub fn is_fjord_active(&self, timestamp: u64) -> bool {
self.fjord_time.map_or(false, |t| timestamp >= t)
}

/// Returns true if Interop is active at the given timestamp.
pub fn is_interop_active(&self, timestamp: u64) -> bool {
self.interop_time.map_or(false, |t| timestamp >= t)
}

/// Checks the scalar value in Ecotone.
pub fn check_ecotone_l1_system_config_scalar(scalar: [u8; 32]) -> Result<(), &'static str> {
let version_byte = scalar[0];
match version_byte {
0 => {
if scalar[1..28] != [0; 27] {
return Err("Bedrock scalar padding not empty");
}
Ok(())
}
1 => {
if scalar[1..24] != [0; 23] {
return Err("Invalid version 1 scalar padding");
}
Ok(())
}
_ => {
// ignore the event if it's an unknown scalar format
Err("Unrecognized scalar version")
}
}
}
}
Loading

0 comments on commit 1ca215b

Please sign in to comment.