Simplify ConfigAndPreset (#7777)

I noticed that we are serving preset values for Fulu on mainnet nodes prior to the fork. This has already gone live in v7.1.0, but should hopefully be handled in a graceful way by API consumers.

This PR _reverts_ the serving of Fulu data prior to Fulu, by serving Fulu data only if Fulu is scheduled.
This commit is contained in:
Michael Sproul
2025-07-25 18:53:24 +10:00
committed by GitHub
parent 09065a851f
commit 134039d014
7 changed files with 41 additions and 46 deletions

View File

@@ -1,6 +1,6 @@
use crate::{
consts::altair, consts::deneb, AltairPreset, BasePreset, BellatrixPreset, CapellaPreset,
ChainSpec, Config, DenebPreset, ElectraPreset, EthSpec, ForkName, FuluPreset,
ChainSpec, Config, DenebPreset, ElectraPreset, EthSpec, FuluPreset,
};
use maplit::hashmap;
use serde::{Deserialize, Serialize};
@@ -43,7 +43,7 @@ pub struct ConfigAndPreset {
}
impl ConfigAndPreset {
pub fn from_chain_spec<E: EthSpec>(spec: &ChainSpec, fork_name: Option<ForkName>) -> Self {
pub fn from_chain_spec<E: EthSpec>(spec: &ChainSpec) -> Self {
let mut config = Config::from_chain_spec::<E>(spec);
let base_preset = BasePreset::from_chain_spec::<E>(spec);
let altair_preset = AltairPreset::from_chain_spec::<E>(spec);
@@ -52,15 +52,7 @@ impl ConfigAndPreset {
let deneb_preset = DenebPreset::from_chain_spec::<E>(spec);
let extra_fields = get_extra_fields(spec);
// Remove blob schedule for backwards-compatibility.
if spec.fulu_fork_epoch.is_none() {
config.blob_schedule.set_skip_serializing();
}
if spec.fulu_fork_epoch.is_some()
|| fork_name.is_none()
|| fork_name == Some(ForkName::Fulu)
{
if spec.is_fulu_scheduled() {
let electra_preset = ElectraPreset::from_chain_spec::<E>(spec);
let fulu_preset = FuluPreset::from_chain_spec::<E>(spec);
@@ -75,10 +67,10 @@ impl ConfigAndPreset {
fulu_preset,
extra_fields,
})
} else if spec.electra_fork_epoch.is_some()
|| fork_name.is_none()
|| fork_name == Some(ForkName::Electra)
{
} else {
// Remove blob schedule for backwards-compatibility.
config.blob_schedule.set_skip_serializing();
let electra_preset = ElectraPreset::from_chain_spec::<E>(spec);
ConfigAndPreset::Electra(ConfigAndPresetElectra {
@@ -91,16 +83,6 @@ impl ConfigAndPreset {
electra_preset,
extra_fields,
})
} else {
ConfigAndPreset::Deneb(ConfigAndPresetDeneb {
config,
base_preset,
altair_preset,
bellatrix_preset,
capella_preset,
deneb_preset,
extra_fields,
})
}
}
}
@@ -159,8 +141,7 @@ mod test {
let mut mainnet_spec = ChainSpec::mainnet();
// setting fulu_fork_epoch because we are roundtripping a fulu config
mainnet_spec.fulu_fork_epoch = Some(Epoch::new(42));
let mut yamlconfig =
ConfigAndPreset::from_chain_spec::<MainnetEthSpec>(&mainnet_spec, None);
let mut yamlconfig = ConfigAndPreset::from_chain_spec::<MainnetEthSpec>(&mainnet_spec);
let (k1, v1) = ("SAMPLE_HARDFORK_KEY1", "123456789");
let (k2, v2) = ("SAMPLE_HARDFORK_KEY2", "987654321");
let (k3, v3) = ("SAMPLE_HARDFORK_KEY3", 32);