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