Skip to content

Commit f584521

Browse files
authored
chore(validator_client): Read genesis time and genesis validators root from eth2_network_config (#8638)
#5019 If there is a known eth2_network_config, we read the genesis time and validators root from the config. Co-Authored-By: Jimmy Chu <898091+jimmychu0807@users.noreply.github.com>
1 parent c913457 commit f584521

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

common/eth2_config/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ const HOLESKY_GENESIS_STATE_SOURCE: GenesisStateSource = GenesisStateSource::Url
3333
checksum: "0xd750639607c337bbb192b15c27f447732267bf72d1650180a0e44c2d93a80741",
3434
genesis_validators_root: "0x9143aa7c615a7f7115e2b6aac319c03529df8242ae705fba9df39b79c59fa8b1",
3535
genesis_state_root: "0x0ea3f6f9515823b59c863454675fefcd1d8b4f2dbe454db166206a41fda060a0",
36+
// ref: https://github.com/eth-clients/holesky/blob/main/README.md - Launch Epoch time
37+
genesis_time: 1695902400,
3638
};
3739

3840
const HOODI_GENESIS_STATE_SOURCE: GenesisStateSource = GenesisStateSource::Url {
@@ -44,6 +46,8 @@ const HOODI_GENESIS_STATE_SOURCE: GenesisStateSource = GenesisStateSource::Url {
4446
checksum: "0x7f42257ef69e055496c964a753bb07e54001ccd57ab467ef72d67af086bcfce7",
4547
genesis_validators_root: "0x212f13fc4df078b6cb7db228f1c8307566dcecf900867401a92023d7ba99cb5f",
4648
genesis_state_root: "0x2683ebc120f91f740c7bed4c866672d01e1ba51b4cc360297138465ee5df40f0",
49+
// ref: https://github.com/eth-clients/hoodi/blob/main/README.md - Launch Epoch time
50+
genesis_time: 1742213400,
4751
};
4852

4953
const CHIADO_GENESIS_STATE_SOURCE: GenesisStateSource = GenesisStateSource::Url {
@@ -52,6 +56,8 @@ const CHIADO_GENESIS_STATE_SOURCE: GenesisStateSource = GenesisStateSource::Url
5256
checksum: "0xd4a039454c7429f1dfaa7e11e397ef3d0f50d2d5e4c0e4dc04919d153aa13af1",
5357
genesis_validators_root: "0x9d642dac73058fbf39c0ae41ab1e34e4d889043cb199851ded7095bc99eb4c1e",
5458
genesis_state_root: "0xa48419160f8f146ecaa53d12a5d6e1e6af414a328afdc56b60d5002bb472a077",
59+
// ref: https://github.com/gnosischain/configs/blob/main/chiado/genesis.ssz
60+
genesis_time: 1665396300,
5561
};
5662

5763
/// The core configuration of a Lighthouse beacon node.
@@ -117,6 +123,10 @@ pub enum GenesisStateSource {
117123
///
118124
/// The format should be 0x-prefixed ASCII bytes.
119125
genesis_state_root: &'static str,
126+
/// The genesis time.
127+
///
128+
/// The format should be u64.
129+
genesis_time: u64,
120130
},
121131
}
122132

common/eth2_network_config/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,16 @@ impl Eth2NetworkConfig {
133133
self.genesis_state_source != GenesisStateSource::Unknown
134134
}
135135

136+
/// The `genesis_time` of the genesis state.
137+
pub fn genesis_time<E: EthSpec>(&self) -> Result<Option<u64>, String> {
138+
if let GenesisStateSource::Url { genesis_time, .. } = self.genesis_state_source {
139+
Ok(Some(genesis_time))
140+
} else {
141+
self.get_genesis_state_from_bytes::<E>()
142+
.map(|state| Some(state.genesis_time()))
143+
}
144+
}
145+
136146
/// The `genesis_validators_root` of the genesis state.
137147
pub fn genesis_validators_root<E: EthSpec>(&self) -> Result<Option<Hash256>, String> {
138148
if let GenesisStateSource::Url {

validator_client/src/lib.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -364,11 +364,22 @@ impl<E: EthSpec> ProductionValidatorClient<E> {
364364
context.eth2_config.spec.clone(),
365365
);
366366

367-
// Perform some potentially long-running initialization tasks.
368-
let (genesis_time, genesis_validators_root) = tokio::select! {
369-
tuple = init_from_beacon_node::<E>(&beacon_nodes, &proposer_nodes) => tuple?,
370-
() = context.executor.exit() => return Err("Shutting down".to_string())
371-
};
367+
let (genesis_time, genesis_validators_root) =
368+
if let Some(eth2_network_config) = context.eth2_network_config.as_ref() {
369+
let time = eth2_network_config
370+
.genesis_time::<E>()?
371+
.ok_or("no genesis time")?;
372+
let root = eth2_network_config
373+
.genesis_validators_root::<E>()?
374+
.ok_or("no genesis validators root")?;
375+
(time, root)
376+
} else {
377+
// Perform some potentially long-running initialization tasks.
378+
tokio::select! {
379+
tuple = init_from_beacon_node::<E>(&beacon_nodes, &proposer_nodes) => tuple?,
380+
() = context.executor.exit() => return Err("Shutting down".to_string()),
381+
}
382+
};
372383

373384
// Update the metrics server.
374385
if let Some(ctx) = &validator_metrics_ctx {

0 commit comments

Comments
 (0)