alloy_eips/
eip7892.rs

1//! Contains constants and helper functions for [EIP-7892](https://github.com/ethereum/EIPs/tree/master/EIPS/eip-7892.md)
2
3use crate::eip7840::BlobParams;
4use alloc::vec::Vec;
5
6/// Targeted blob count with BPO1 activation
7pub const BPO1_TARGET_BLOBS_PER_BLOCK: u64 = 10;
8
9/// Max blob count with BPO1 activation
10pub const BPO1_MAX_BLOBS_PER_BLOCK: u64 = 15;
11
12/// Targeted blob count with BPO2 activation
13pub const BPO2_TARGET_BLOBS_PER_BLOCK: u64 = 14;
14
15/// Max blob count with BPO2 activation
16pub const BPO2_MAX_BLOBS_PER_BLOCK: u64 = 21;
17
18/// A scheduled blob parameter update entry.
19#[derive(Debug, Clone, PartialEq, Eq)]
20#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
21pub enum BlobScheduleEntry {
22    /// Blob parameters for the Cancun hardfork
23    Cancun(BlobParams),
24    /// Blob parameters for the Prague hardfork
25    Prague(BlobParams),
26    /// Blob parameters that take effect at a specific timestamp
27    TimestampUpdate(u64, BlobParams),
28}
29
30/// Blob parameters configuration for a chain, including scheduled updates.
31#[derive(Debug, Clone, PartialEq, Eq)]
32pub struct BlobScheduleBlobParams {
33    /// Configuration for blob-related calculations for the Cancun hardfork.
34    pub cancun: BlobParams,
35    /// Configuration for blob-related calculations for the Prague hardfork.
36    pub prague: BlobParams,
37    /// Configuration for blob-related calculations for the Osaka hardfork.
38    pub osaka: BlobParams,
39    /// Time-based scheduled updates to blob parameters.
40    ///
41    /// These are ordered by activation timestamps in natural order.
42    pub scheduled: Vec<(u64, BlobParams)>,
43}
44
45impl BlobScheduleBlobParams {
46    /// Returns the blob schedule for the ethereum mainnet.
47    pub fn mainnet() -> Self {
48        Self {
49            cancun: BlobParams::cancun(),
50            prague: BlobParams::prague(),
51            osaka: BlobParams::osaka(),
52            scheduled: Default::default(),
53        }
54    }
55
56    /// Configures the scheduled [`BlobParams`] with timestamps.
57    pub fn with_scheduled(
58        mut self,
59        scheduled: impl IntoIterator<Item = (u64, BlobParams)>,
60    ) -> Self {
61        self.scheduled = scheduled.into_iter().collect();
62        self
63    }
64
65    /// Returns the highest active blob parameters at the given timestamp.
66    ///
67    /// Note: this does only scan the entries scheduled by timestamp and not cancun or prague.
68    pub fn active_scheduled_params_at_timestamp(&self, timestamp: u64) -> Option<&BlobParams> {
69        self.scheduled.iter().rev().find(|(ts, _)| timestamp >= *ts).map(|(_, params)| params)
70    }
71
72    /// Returns the configured Cancun [`BlobParams`].
73    pub const fn cancun(&self) -> &BlobParams {
74        &self.cancun
75    }
76
77    /// Returns the configured Prague [`BlobParams`].
78    pub const fn prague(&self) -> &BlobParams {
79        &self.prague
80    }
81
82    /// Returns the configured Osaka [`BlobParams`].
83    pub const fn osaka(&self) -> &BlobParams {
84        &self.osaka
85    }
86}
87
88impl Default for BlobScheduleBlobParams {
89    fn default() -> Self {
90        Self::mainnet()
91    }
92}