Skip to content

Commit b904956

Browse files
Skip serializing blob_schedule before Fulu (#7779)
Alternative to: - #7758 Serve the `blob_schedule` field on `/eth/v1/config/spec` _only_ when Fulu is enabled. If the blob schedule is empty, we will still serve it as `[]`, so long as Fulu is enabled.
1 parent 9911f34 commit b904956

File tree

2 files changed

+51
-17
lines changed

2 files changed

+51
-17
lines changed

consensus/types/src/chain_spec.rs

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::application_domain::{ApplicationDomain, APPLICATION_DOMAIN_BUILDER};
22
use crate::blob_sidecar::BlobIdentifier;
33
use crate::data_column_sidecar::DataColumnsByRootIdentifier;
44
use crate::*;
5+
use derivative::Derivative;
56
use ethereum_hashing::hash;
67
use int_to_bytes::int_to_bytes4;
78
use safe_arith::{ArithError, SafeArith};
@@ -1472,8 +1473,17 @@ pub struct BlobParameters {
14721473
// A wrapper around a vector of BlobParameters to ensure that the vector is reverse
14731474
// sorted by epoch.
14741475
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1475-
#[derive(Debug, PartialEq, Clone)]
1476-
pub struct BlobSchedule(Vec<BlobParameters>);
1476+
#[derive(Debug, Derivative, Clone)]
1477+
#[derivative(PartialEq)]
1478+
pub struct BlobSchedule {
1479+
schedule: Vec<BlobParameters>,
1480+
// This is a hack to prevent the blob schedule being serialized on the /eth/v1/config/spec
1481+
// endpoint prior to the Fulu fork being scheduled.
1482+
//
1483+
// We can remove this once Fulu is live on mainnet.
1484+
#[derivative(PartialEq = "ignore")]
1485+
skip_serializing: bool,
1486+
}
14771487

14781488
impl<'de> Deserialize<'de> for BlobSchedule {
14791489
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
@@ -1489,30 +1499,48 @@ impl BlobSchedule {
14891499
pub fn new(mut vec: Vec<BlobParameters>) -> Self {
14901500
// reverse sort by epoch
14911501
vec.sort_by(|a, b| b.epoch.cmp(&a.epoch));
1492-
Self(vec)
1502+
Self {
1503+
schedule: vec,
1504+
skip_serializing: false,
1505+
}
14931506
}
14941507

14951508
pub fn is_empty(&self) -> bool {
1496-
self.0.is_empty()
1509+
self.schedule.is_empty()
1510+
}
1511+
1512+
pub fn skip_serializing(&self) -> bool {
1513+
self.skip_serializing
1514+
}
1515+
1516+
pub fn set_skip_serializing(&mut self) {
1517+
self.skip_serializing = true;
14971518
}
14981519

14991520
pub fn max_blobs_for_epoch(&self, epoch: Epoch) -> Option<u64> {
1500-
self.0
1521+
self.schedule
15011522
.iter()
15021523
.find(|entry| epoch >= entry.epoch)
15031524
.map(|entry| entry.max_blobs_per_block)
15041525
}
15051526

15061527
pub fn blob_parameters_for_epoch(&self, epoch: Epoch) -> Option<BlobParameters> {
1507-
self.0.iter().find(|entry| epoch >= entry.epoch).cloned()
1528+
self.schedule
1529+
.iter()
1530+
.find(|entry| epoch >= entry.epoch)
1531+
.cloned()
15081532
}
15091533

15101534
pub const fn default() -> Self {
1511-
Self(vec![])
1535+
// TODO(EIP-7892): think about what the default should be
1536+
Self {
1537+
schedule: vec![],
1538+
skip_serializing: false,
1539+
}
15121540
}
15131541

15141542
pub fn as_vec(&self) -> &Vec<BlobParameters> {
1515-
&self.0
1543+
&self.schedule
15161544
}
15171545
}
15181546

@@ -1521,7 +1549,7 @@ impl Serialize for BlobSchedule {
15211549
where
15221550
S: Serializer,
15231551
{
1524-
let mut schedule = self.0.clone();
1552+
let mut schedule = self.schedule.clone();
15251553
// reversing the list to get an ascending order
15261554
schedule.reverse();
15271555
schedule.serialize(serializer)
@@ -1533,7 +1561,7 @@ impl<'a> IntoIterator for &'a BlobSchedule {
15331561
type IntoIter = std::slice::Iter<'a, BlobParameters>;
15341562

15351563
fn into_iter(self) -> Self::IntoIter {
1536-
self.0.iter()
1564+
self.schedule.iter()
15371565
}
15381566
}
15391567

@@ -1542,7 +1570,7 @@ impl IntoIterator for BlobSchedule {
15421570
type IntoIter = std::vec::IntoIter<BlobParameters>;
15431571

15441572
fn into_iter(self) -> Self::IntoIter {
1545-
self.0.into_iter()
1573+
self.schedule.into_iter()
15461574
}
15471575
}
15481576

@@ -1747,8 +1775,8 @@ pub struct Config {
17471775
#[serde(with = "serde_utils::quoted_u64")]
17481776
custody_requirement: u64,
17491777
#[serde(default = "BlobSchedule::default")]
1750-
#[serde(skip_serializing_if = "BlobSchedule::is_empty")]
1751-
blob_schedule: BlobSchedule,
1778+
#[serde(skip_serializing_if = "BlobSchedule::skip_serializing")]
1779+
pub blob_schedule: BlobSchedule,
17521780
#[serde(default = "default_validator_custody_requirement")]
17531781
#[serde(with = "serde_utils::quoted_u64")]
17541782
validator_custody_requirement: u64,

consensus/types/src/config_and_preset.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,20 @@ pub struct ConfigAndPreset {
4343
}
4444

4545
impl ConfigAndPreset {
46-
// DEPRECATED: the `fork_name` argument is never used, we should remove it.
4746
pub fn from_chain_spec<E: EthSpec>(spec: &ChainSpec, fork_name: Option<ForkName>) -> Self {
48-
let config = Config::from_chain_spec::<E>(spec);
47+
let mut config = Config::from_chain_spec::<E>(spec);
4948
let base_preset = BasePreset::from_chain_spec::<E>(spec);
5049
let altair_preset = AltairPreset::from_chain_spec::<E>(spec);
5150
let bellatrix_preset = BellatrixPreset::from_chain_spec::<E>(spec);
5251
let capella_preset = CapellaPreset::from_chain_spec::<E>(spec);
5352
let deneb_preset = DenebPreset::from_chain_spec::<E>(spec);
5453
let extra_fields = get_extra_fields(spec);
5554

55+
// Remove blob schedule for backwards-compatibility.
56+
if spec.fulu_fork_epoch.is_none() {
57+
config.blob_schedule.set_skip_serializing();
58+
}
59+
5660
if spec.fulu_fork_epoch.is_some()
5761
|| fork_name.is_none()
5862
|| fork_name == Some(ForkName::Fulu)
@@ -140,7 +144,7 @@ pub fn get_extra_fields(spec: &ChainSpec) -> HashMap<String, Value> {
140144
#[cfg(test)]
141145
mod test {
142146
use super::*;
143-
use crate::MainnetEthSpec;
147+
use crate::{Epoch, MainnetEthSpec};
144148
use std::fs::File;
145149
use tempfile::NamedTempFile;
146150

@@ -152,7 +156,9 @@ mod test {
152156
.write(true)
153157
.open(tmp_file.as_ref())
154158
.expect("error opening file");
155-
let mainnet_spec = ChainSpec::mainnet();
159+
let mut mainnet_spec = ChainSpec::mainnet();
160+
// setting fulu_fork_epoch because we are roundtripping a fulu config
161+
mainnet_spec.fulu_fork_epoch = Some(Epoch::new(42));
156162
let mut yamlconfig =
157163
ConfigAndPreset::from_chain_spec::<MainnetEthSpec>(&mainnet_spec, None);
158164
let (k1, v1) = ("SAMPLE_HARDFORK_KEY1", "123456789");

0 commit comments

Comments
 (0)