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/// A scheduled blob parameter update entry.
7#[derive(Debug, Clone, PartialEq, Eq)]
8#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
9pub enum BlobScheduleEntry {
10 /// Blob parameters for the Cancun hardfork
11 Cancun(BlobParams),
12 /// Blob parameters for the Prague hardfork
13 Prague(BlobParams),
14 /// Blob parameters that take effect at a specific timestamp
15 TimestampUpdate(u64, BlobParams),
16}
17
18/// Blob parameters configuration for a chain, including scheduled updates.
19#[derive(Debug, Clone, PartialEq, Eq)]
20pub struct BlobScheduleBlobParams {
21 /// Configuration for blob-related calculations for the Cancun hardfork.
22 pub cancun: BlobParams,
23 /// Configuration for blob-related calculations for the Prague hardfork.
24 pub prague: BlobParams,
25 /// Configuration for blob-related calculations for the Osaka hardfork.
26 pub osaka: BlobParams,
27 /// Time-based scheduled updates to blob parameters.
28 ///
29 /// These are ordered by activation timestamps in natural order.
30 pub scheduled: Vec<(u64, BlobParams)>,
31}
32
33impl BlobScheduleBlobParams {
34 /// Returns the blob schedule for the ethereum mainnet.
35 pub fn mainnet() -> Self {
36 Self {
37 cancun: BlobParams::cancun(),
38 prague: BlobParams::prague(),
39 osaka: BlobParams::osaka(),
40 scheduled: Default::default(),
41 }
42 }
43
44 /// Returns the highest active blob parameters at the given timestamp.
45 ///
46 /// Note: this does only scan the entries scheduled by timestamp and not cancun or prague.
47 pub fn active_scheduled_params_at_timestamp(&self, timestamp: u64) -> Option<&BlobParams> {
48 self.scheduled.iter().rev().find(|(ts, _)| timestamp >= *ts).map(|(_, params)| params)
49 }
50
51 /// Returns the configured Cancun [`BlobParams`].
52 pub const fn cancun(&self) -> &BlobParams {
53 &self.cancun
54 }
55
56 /// Returns the configured Prague [`BlobParams`].
57 pub const fn prague(&self) -> &BlobParams {
58 &self.prague
59 }
60
61 /// Returns the configured Osaka [`BlobParams`].
62 pub const fn osaka(&self) -> &BlobParams {
63 &self.osaka
64 }
65}
66
67impl Default for BlobScheduleBlobParams {
68 fn default() -> Self {
69 Self::mainnet()
70 }
71}