Skip to content

Commit

Permalink
feat: added documentation, cleanup after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
merklefruit committed Feb 18, 2024
1 parent 01413b9 commit abd1e09
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 13 deletions.
28 changes: 20 additions & 8 deletions src/common/attributes_deposited.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32>,
/// Blob base fee (after Ecotone)
pub blob_base_fee: Option<U256>,
}

const L1_INFO_BEDROCK_LEN: usize = 4 + 32 * 8;
Expand Down Expand Up @@ -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,
})
}

Expand Down Expand Up @@ -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()?);
Expand All @@ -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]);
Expand Down Expand Up @@ -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)?);
Expand Down
2 changes: 2 additions & 0 deletions src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 2 additions & 1 deletion src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,10 @@ pub struct CliConfig {
/// The L1 RPC
#[serde(skip_serializing_if = "Option::is_none")]
pub l1_rpc_url: Option<String>,
/// The L2 execution client RPC
/// The L1 beacon chain RPC URL
#[serde(skip_serializing_if = "Option::is_none")]
pub l1_beacon_url: Option<String>,
/// The L2 execution client RPC
#[serde(skip_serializing_if = "Option::is_none")]
pub l2_rpc_url: Option<String>,
/// The L2 engine RPC
Expand Down
1 change: 1 addition & 0 deletions src/l1/blob_encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Bytes> {
let mut output = vec![0; MAX_BLOB_DATA_SIZE];

Expand Down
11 changes: 7 additions & 4 deletions src/l1/blob_fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<u8>,
// kzg_commitment: String,
// kzg_proof: String,
// signed_block_header: Value,
// kzg_commitment_inclusion_proof: Vec<String>,
}

impl BlobFetcher {
/// Create a new blob fetcher with the given config.
pub fn new(config: Arc<Config>) -> Self {
Self {
config,
Expand Down
6 changes: 6 additions & 0 deletions src/l1/config_updates.rs
Original file line number Diff line number Diff line change
@@ -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),
}

Expand Down
7 changes: 7 additions & 0 deletions src/l1/mod.rs
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit abd1e09

Please sign in to comment.