From abd1e09780bcc9651890152b6a74540aebaa116b Mon Sep 17 00:00:00 2001 From: nicolas <48695862+merklefruit@users.noreply.github.com> Date: Sun, 18 Feb 2024 16:44:32 +0100 Subject: [PATCH] feat: added documentation, cleanup after rebase --- src/common/attributes_deposited.rs | 28 ++++++++++++++++++++-------- src/common/mod.rs | 2 ++ src/config/mod.rs | 3 ++- src/l1/blob_encoding.rs | 1 + src/l1/blob_fetcher.rs | 11 +++++++---- src/l1/config_updates.rs | 6 ++++++ src/l1/mod.rs | 7 +++++++ 7 files changed, 45 insertions(+), 13 deletions(-) diff --git a/src/common/attributes_deposited.rs b/src/common/attributes_deposited.rs index decabc34..726dc125 100644 --- a/src/common/attributes_deposited.rs +++ b/src/common/attributes_deposited.rs @@ -5,18 +5,29 @@ use ethers::{ use eyre::Result; use lazy_static::lazy_static; +/// Represents the attributes deposited transcation call #[derive(Debug)] pub struct AttributesDepositedCall { + /// block number pub number: u64, + /// block timestamp pub timestamp: u64, + /// base fee pub basefee: U256, + /// block hash pub hash: H256, + /// sequence number of the L2 block pub sequence_number: u64, + /// batcher hash (should contain an address) pub batcher_hash: H256, + /// L1 fee overhead pub fee_overhead: U256, + /// L1 fee scalar pub fee_scalar: U256, - pub blob_base_fee_scalar: u32, - pub blob_base_fee: U256, + /// Blob base fee scalar (after Ecotone) + pub blob_base_fee_scalar: Option, + /// Blob base fee (after Ecotone) + pub blob_base_fee: Option, } const L1_INFO_BEDROCK_LEN: usize = 4 + 32 * 8; @@ -104,8 +115,8 @@ impl AttributesDepositedCall { fee_scalar, // Ecotone fields are not present in Bedrock attributes deposited calls - blob_base_fee_scalar: 0, - blob_base_fee: U256::zero(), + blob_base_fee_scalar: None, + blob_base_fee: None, }) } @@ -143,7 +154,8 @@ impl AttributesDepositedCall { let fee_scalar = U256::from(fee_scalar); // up-casting for backwards compatibility cursor += 4; - let blob_base_fee_scalar = u32::from_be_bytes(calldata[cursor..cursor + 4].try_into()?); + let blob_base_fee_scalar = + Some(u32::from_be_bytes(calldata[cursor..cursor + 4].try_into()?)); cursor += 4; let sequence_number = u64::from_be_bytes(calldata[cursor..cursor + 8].try_into()?); @@ -158,7 +170,7 @@ impl AttributesDepositedCall { let basefee = U256::from_big_endian(&calldata[cursor..cursor + 32]); cursor += 32; - let blob_base_fee = U256::from_big_endian(&calldata[cursor..cursor + 32]); + let blob_base_fee = Some(U256::from_big_endian(&calldata[cursor..cursor + 32])); cursor += 32; let hash = H256::from_slice(&calldata[cursor..cursor + 32]); @@ -227,8 +239,8 @@ mod tests { ); let expected_block_number = 10519970; let expected_timestamp = 1707650412; - let expected_blob_base_fee_scalar = 862000; - let expected_blob_base_fee = U256::from(17683022066u64); + let expected_blob_base_fee_scalar = Some(862000); + let expected_blob_base_fee = Some(U256::from(17683022066u64)); // Act let call = AttributesDepositedCall::try_from_ecotone(Bytes::from_str(calldata)?); diff --git a/src/common/mod.rs b/src/common/mod.rs index 010d3477..04f67682 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -9,6 +9,8 @@ use figment::value::{Dict, Tag, Value}; use serde::{de::Error, Deserialize, Deserializer, Serialize, Serializer}; use crate::engine::ExecutionPayload; + +/// Attributes deposited transaction helpers pub mod attributes_deposited; pub use attributes_deposited::AttributesDepositedCall; diff --git a/src/config/mod.rs b/src/config/mod.rs index 1beda509..32a09779 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -102,9 +102,10 @@ pub struct CliConfig { /// The L1 RPC #[serde(skip_serializing_if = "Option::is_none")] pub l1_rpc_url: Option, - /// The L2 execution client RPC + /// The L1 beacon chain RPC URL #[serde(skip_serializing_if = "Option::is_none")] pub l1_beacon_url: Option, + /// The L2 execution client RPC #[serde(skip_serializing_if = "Option::is_none")] pub l2_rpc_url: Option, /// The L2 engine RPC diff --git a/src/l1/blob_encoding.rs b/src/l1/blob_encoding.rs index 992629a1..cd6f35ab 100644 --- a/src/l1/blob_encoding.rs +++ b/src/l1/blob_encoding.rs @@ -6,6 +6,7 @@ const ENCODING_VERSION: u8 = 0; const VERSION_OFFSET: usize = 1; const ROUNDS: usize = 1024; +/// Encodes a blob of data into a byte array pub fn decode_blob_data(blob: &[u8]) -> Result { let mut output = vec![0; MAX_BLOB_DATA_SIZE]; diff --git a/src/l1/blob_fetcher.rs b/src/l1/blob_fetcher.rs index fff18527..b09aa4a9 100644 --- a/src/l1/blob_fetcher.rs +++ b/src/l1/blob_fetcher.rs @@ -14,6 +14,8 @@ use crate::config::Config; const BLOB_CARRYING_TRANSACTION_TYPE: u64 = 3; +/// The data contained in a batcher transaction. +/// The actual source of this data can be either calldata or blobs. pub type BatcherTransactionData = Bytes; /// The blob fetcher is responsible for fetching blob data from the L1 beacon chain, @@ -29,19 +31,20 @@ pub struct BlobFetcher { seconds_per_slot: AtomicU64, } +/// A beacon chain blob sidecar object. +/// KZG commitment and proof fields are not used in the current implementation. #[derive(Debug, Deserialize)] pub struct BlobSidecar { + /// Blob index (transactions can have more than one blob) #[serde(deserialize_with = "deserialize_string_to_u64")] pub index: u64, + /// Blob data (not decoded) #[serde(deserialize_with = "deserialize_blob_bytes")] pub blob: Vec, - // kzg_commitment: String, - // kzg_proof: String, - // signed_block_header: Value, - // kzg_commitment_inclusion_proof: Vec, } impl BlobFetcher { + /// Create a new blob fetcher with the given config. pub fn new(config: Arc) -> Self { Self { config, diff --git a/src/l1/config_updates.rs b/src/l1/config_updates.rs index 54940b0b..89c86293 100644 --- a/src/l1/config_updates.rs +++ b/src/l1/config_updates.rs @@ -1,10 +1,16 @@ use ethers::types::{Address, Log, U256}; use eyre::Result; +/// Represents a system config update event +#[derive(Debug)] pub enum SystemConfigUpdate { + /// The batch sender address has been updated BatchSender(Address), + /// The fee overhead and scalar have been updated Fees(U256, U256), + /// The gas has been updated Gas(U256), + /// The unsafe block signer has been updated UnsafeBlockSigner(Address), } diff --git a/src/l1/mod.rs b/src/l1/mod.rs index 166e8749..2fb38c18 100644 --- a/src/l1/mod.rs +++ b/src/l1/mod.rs @@ -1,14 +1,21 @@ +/// Module reposnsible for listening to the L1 chain and monitoring for new +/// blocks and events. pub mod chain_watcher; pub use chain_watcher::{BlockUpdate, ChainWatcher}; +/// module responsible for parsing logs to extract system config updates pub mod config_updates; pub use config_updates::SystemConfigUpdate; +/// L1 block info pub mod l1_info; pub use l1_info::L1Info; +/// Module responsible for extracting batcher transaction data from +/// L1 batcher transaction data or blobs (after the Ecotone hardfork) pub mod blob_fetcher; pub use blob_fetcher::{BatcherTransactionData, BlobFetcher, BlobSidecar}; +/// Helper module for decoding blob data pub mod blob_encoding; pub use blob_encoding::decode_blob_data;