Update GET config/spec endpoint to support Deneb config (#4708)

* Update `GET config/spec` endpoint to support Deneb config.

* Update config spec `http_api` test
This commit is contained in:
Jimmy Chen 2023-09-09 16:09:50 +10:00 committed by GitHub
parent 87ec7599fe
commit 50bf40b4bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 103 additions and 27 deletions

View File

@ -1741,9 +1741,9 @@ impl ApiTester {
pub async fn test_get_config_spec(self) -> Self { pub async fn test_get_config_spec(self) -> Self {
let result = self let result = self
.client .client
.get_config_spec::<ConfigAndPresetCapella>() .get_config_spec::<ConfigAndPresetDeneb>()
.await .await
.map(|res| ConfigAndPreset::Capella(res.data)) .map(|res| ConfigAndPreset::Deneb(res.data))
.unwrap(); .unwrap();
let expected = ConfigAndPreset::from_chain_spec::<E>(&self.chain.spec, None); let expected = ConfigAndPreset::from_chain_spec::<E>(&self.chain.spec, None);

View File

@ -0,0 +1,12 @@
# Gnosis preset - Deneb
# NOTE: The below are PLACEHOLDER values from Mainnet.
# Gnosis preset for the Deneb fork TBD: https://github.com/gnosischain/configs/tree/main/presets/gnosis
# Misc
# ---------------------------------------------------------------
# `uint64(4096)`
FIELD_ELEMENTS_PER_BLOB: 4096
# `uint64(2**12)` (= 4096)
MAX_BLOB_COMMITMENTS_PER_BLOCK: 4096
# `uint64(6)`
MAX_BLOBS_PER_BLOCK: 6

View File

@ -0,0 +1,10 @@
# Mainnet preset - Deneb
# Misc
# ---------------------------------------------------------------
# `uint64(4096)`
FIELD_ELEMENTS_PER_BLOB: 4096
# `uint64(2**12)` (= 4096)
MAX_BLOB_COMMITMENTS_PER_BLOCK: 4096
# `uint64(6)`
MAX_BLOBS_PER_BLOCK: 6

View File

@ -0,0 +1,10 @@
# Minimal preset - Deneb
# Misc
# ---------------------------------------------------------------
# [customized]
FIELD_ELEMENTS_PER_BLOB: 4
# [customized]
MAX_BLOB_COMMITMENTS_PER_BLOCK: 16
# `uint64(6)`
MAX_BLOBS_PER_BLOCK: 6

View File

@ -1,6 +1,6 @@
use crate::{ use crate::{
consts::altair, AltairPreset, BasePreset, BellatrixPreset, CapellaPreset, ChainSpec, Config, consts::altair, AltairPreset, BasePreset, BellatrixPreset, CapellaPreset, ChainSpec, Config,
EthSpec, ForkName, DenebPreset, EthSpec, ForkName,
}; };
use maplit::hashmap; use maplit::hashmap;
use serde_derive::{Deserialize, Serialize}; use serde_derive::{Deserialize, Serialize};
@ -12,7 +12,7 @@ use superstruct::superstruct;
/// ///
/// Mostly useful for the API. /// Mostly useful for the API.
#[superstruct( #[superstruct(
variants(Bellatrix, Capella), variants(Capella, Deneb),
variant_attributes(derive(Serialize, Deserialize, Debug, PartialEq, Clone)) variant_attributes(derive(Serialize, Deserialize, Debug, PartialEq, Clone))
)] )]
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] #[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
@ -27,9 +27,11 @@ pub struct ConfigAndPreset {
pub altair_preset: AltairPreset, pub altair_preset: AltairPreset,
#[serde(flatten)] #[serde(flatten)]
pub bellatrix_preset: BellatrixPreset, pub bellatrix_preset: BellatrixPreset,
#[superstruct(only(Capella))]
#[serde(flatten)] #[serde(flatten)]
pub capella_preset: CapellaPreset, pub capella_preset: CapellaPreset,
#[superstruct(only(Deneb))]
#[serde(flatten)]
pub deneb_preset: DenebPreset,
/// The `extra_fields` map allows us to gracefully decode fields intended for future hard forks. /// The `extra_fields` map allows us to gracefully decode fields intended for future hard forks.
#[serde(flatten)] #[serde(flatten)]
pub extra_fields: HashMap<String, Value>, pub extra_fields: HashMap<String, Value>,
@ -41,14 +43,24 @@ impl ConfigAndPreset {
let base_preset = BasePreset::from_chain_spec::<T>(spec); let base_preset = BasePreset::from_chain_spec::<T>(spec);
let altair_preset = AltairPreset::from_chain_spec::<T>(spec); let altair_preset = AltairPreset::from_chain_spec::<T>(spec);
let bellatrix_preset = BellatrixPreset::from_chain_spec::<T>(spec); let bellatrix_preset = BellatrixPreset::from_chain_spec::<T>(spec);
let capella_preset = CapellaPreset::from_chain_spec::<T>(spec);
let extra_fields = get_extra_fields(spec); let extra_fields = get_extra_fields(spec);
if spec.capella_fork_epoch.is_some() if spec.deneb_fork_epoch.is_some()
|| fork_name.is_none() || fork_name.is_none()
|| fork_name == Some(ForkName::Capella) || fork_name == Some(ForkName::Deneb)
{ {
let capella_preset = CapellaPreset::from_chain_spec::<T>(spec); let deneb_preset = DenebPreset::from_chain_spec::<T>(spec);
ConfigAndPreset::Deneb(ConfigAndPresetDeneb {
config,
base_preset,
altair_preset,
bellatrix_preset,
capella_preset,
deneb_preset,
extra_fields,
})
} else {
ConfigAndPreset::Capella(ConfigAndPresetCapella { ConfigAndPreset::Capella(ConfigAndPresetCapella {
config, config,
base_preset, base_preset,
@ -57,14 +69,6 @@ impl ConfigAndPreset {
capella_preset, capella_preset,
extra_fields, extra_fields,
}) })
} else {
ConfigAndPreset::Bellatrix(ConfigAndPresetBellatrix {
config,
base_preset,
altair_preset,
bellatrix_preset,
extra_fields,
})
} }
} }
} }
@ -133,8 +137,8 @@ mod test {
.write(false) .write(false)
.open(tmp_file.as_ref()) .open(tmp_file.as_ref())
.expect("error while opening the file"); .expect("error while opening the file");
let from: ConfigAndPresetCapella = let from: ConfigAndPresetDeneb =
serde_yaml::from_reader(reader).expect("error while deserializing"); serde_yaml::from_reader(reader).expect("error while deserializing");
assert_eq!(ConfigAndPreset::Capella(from), yamlconfig); assert_eq!(ConfigAndPreset::Deneb(from), yamlconfig);
} }
} }

View File

@ -260,6 +260,16 @@ pub trait EthSpec:
Self::MaxBlobsPerBlock::to_usize() Self::MaxBlobsPerBlock::to_usize()
} }
/// Returns the `MAX_BLOB_COMMITMENTS_PER_BLOCK` constant for this specification.
fn max_blob_commitments_per_block() -> usize {
Self::MaxBlobCommitmentsPerBlock::to_usize()
}
/// Returns the `FIELD_ELEMENTS_PER_BLOB` constant for this specification.
fn field_elements_per_blob() -> usize {
Self::FieldElementsPerBlob::to_usize()
}
fn blob_from_bytes(bytes: &[u8]) -> Result<<Self::Kzg as KzgPreset>::Blob, kzg::Error> { fn blob_from_bytes(bytes: &[u8]) -> Result<<Self::Kzg as KzgPreset>::Blob, kzg::Error> {
<Self::Kzg as KzgPreset>::Blob::from_bytes(bytes) <Self::Kzg as KzgPreset>::Blob::from_bytes(bytes)
} }

View File

@ -127,9 +127,7 @@ pub use crate::blob_sidecar::{
pub use crate::bls_to_execution_change::BlsToExecutionChange; pub use crate::bls_to_execution_change::BlsToExecutionChange;
pub use crate::chain_spec::{ChainSpec, Config, Domain}; pub use crate::chain_spec::{ChainSpec, Config, Domain};
pub use crate::checkpoint::Checkpoint; pub use crate::checkpoint::Checkpoint;
pub use crate::config_and_preset::{ pub use crate::config_and_preset::{ConfigAndPreset, ConfigAndPresetCapella, ConfigAndPresetDeneb};
ConfigAndPreset, ConfigAndPresetBellatrix, ConfigAndPresetCapella,
};
pub use crate::contribution_and_proof::ContributionAndProof; pub use crate::contribution_and_proof::ContributionAndProof;
pub use crate::deposit::{Deposit, DEPOSIT_TREE_DEPTH}; pub use crate::deposit::{Deposit, DEPOSIT_TREE_DEPTH};
pub use crate::deposit_data::DepositData; pub use crate::deposit_data::DepositData;
@ -166,7 +164,7 @@ pub use crate::payload::{
FullPayloadCapella, FullPayloadDeneb, FullPayloadMerge, FullPayloadRef, OwnedExecPayload, FullPayloadCapella, FullPayloadDeneb, FullPayloadMerge, FullPayloadRef, OwnedExecPayload,
}; };
pub use crate::pending_attestation::PendingAttestation; pub use crate::pending_attestation::PendingAttestation;
pub use crate::preset::{AltairPreset, BasePreset, BellatrixPreset, CapellaPreset}; pub use crate::preset::{AltairPreset, BasePreset, BellatrixPreset, CapellaPreset, DenebPreset};
pub use crate::proposer_preparation_data::ProposerPreparationData; pub use crate::proposer_preparation_data::ProposerPreparationData;
pub use crate::proposer_slashing::ProposerSlashing; pub use crate::proposer_slashing::ProposerSlashing;
pub use crate::relative_epoch::{Error as RelativeEpochError, RelativeEpoch}; pub use crate::relative_epoch::{Error as RelativeEpochError, RelativeEpoch};

View File

@ -205,6 +205,27 @@ impl CapellaPreset {
} }
} }
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[serde(rename_all = "UPPERCASE")]
pub struct DenebPreset {
#[serde(with = "serde_utils::quoted_u64")]
pub max_blobs_per_block: u64,
#[serde(with = "serde_utils::quoted_u64")]
pub max_blob_commitments_per_block: u64,
#[serde(with = "serde_utils::quoted_u64")]
pub field_elements_per_blob: u64,
}
impl DenebPreset {
pub fn from_chain_spec<T: EthSpec>(_spec: &ChainSpec) -> Self {
Self {
max_blobs_per_block: T::max_blobs_per_block() as u64,
max_blob_commitments_per_block: T::max_blob_commitments_per_block() as u64,
field_elements_per_blob: T::field_elements_per_blob() as u64,
}
}
}
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::*; use super::*;
@ -243,6 +264,9 @@ mod test {
let capella: CapellaPreset = preset_from_file(&preset_name, "capella.yaml"); let capella: CapellaPreset = preset_from_file(&preset_name, "capella.yaml");
assert_eq!(capella, CapellaPreset::from_chain_spec::<E>(&spec)); assert_eq!(capella, CapellaPreset::from_chain_spec::<E>(&spec));
let deneb: DenebPreset = preset_from_file(&preset_name, "deneb.yaml");
assert_eq!(deneb, DenebPreset::from_chain_spec::<E>(&spec));
} }
#[test] #[test]

View File

@ -296,6 +296,14 @@ impl<E: EthSpec> CandidateBeaconNode<E> {
"endpoint_capella_fork_epoch" => ?beacon_node_spec.capella_fork_epoch, "endpoint_capella_fork_epoch" => ?beacon_node_spec.capella_fork_epoch,
"hint" => UPDATE_REQUIRED_LOG_HINT, "hint" => UPDATE_REQUIRED_LOG_HINT,
); );
} else if beacon_node_spec.deneb_fork_epoch != spec.deneb_fork_epoch {
warn!(
log,
"Beacon node has mismatched Deneb fork epoch";
"endpoint" => %self.beacon_node,
"endpoint_deneb_fork_epoch" => ?beacon_node_spec.deneb_fork_epoch,
"hint" => UPDATE_REQUIRED_LOG_HINT,
);
} }
Ok(()) Ok(())

View File

@ -249,9 +249,9 @@ impl ApiTester {
pub async fn test_get_lighthouse_spec(self) -> Self { pub async fn test_get_lighthouse_spec(self) -> Self {
let result = self let result = self
.client .client
.get_lighthouse_spec::<ConfigAndPresetBellatrix>() .get_lighthouse_spec::<ConfigAndPresetCapella>()
.await .await
.map(|res| ConfigAndPreset::Bellatrix(res.data)) .map(|res| ConfigAndPreset::Capella(res.data))
.unwrap(); .unwrap();
let expected = ConfigAndPreset::from_chain_spec::<E>(&E::default_spec(), None); let expected = ConfigAndPreset::from_chain_spec::<E>(&E::default_spec(), None);

View File

@ -205,9 +205,9 @@ impl ApiTester {
pub async fn test_get_lighthouse_spec(self) -> Self { pub async fn test_get_lighthouse_spec(self) -> Self {
let result = self let result = self
.client .client
.get_lighthouse_spec::<ConfigAndPresetCapella>() .get_lighthouse_spec::<ConfigAndPresetDeneb>()
.await .await
.map(|res| ConfigAndPreset::Capella(res.data)) .map(|res| ConfigAndPreset::Deneb(res.data))
.unwrap(); .unwrap();
let expected = ConfigAndPreset::from_chain_spec::<E>(&E::default_spec(), None); let expected = ConfigAndPreset::from_chain_spec::<E>(&E::default_spec(), None);