Skip to content

Commit

Permalink
Download genesis beacon states for testnets from network instead of l…
Browse files Browse the repository at this point in the history
…oading from `eth2-cache` (#16).

Pruned configs for old unused testnets.

Run tests that use data from `eth2-cache` module only with '--features eth2-cache' feature flag.
  • Loading branch information
povi committed Mar 15, 2024
1 parent 6037d7f commit ffb4e80
Show file tree
Hide file tree
Showing 20 changed files with 108 additions and 489 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions builder_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ types = { workspace = true }
eth2_cache_utils = { workspace = true }
serde_json = { workspace = true }
test-case = { workspace = true }

[features]
eth2-cache = []
1 change: 1 addition & 0 deletions builder_api/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ mod tests {
43, [42, 21, 0] => Err(BuilderApiError::RollingEpochMissingBlocks { missing_blocks: 30 });
"more missing blocks than allowed in first gap alone"
)]
#[cfg(feature = "eth2-cache")]
fn circuit_breaker_conditions(
slot: Slot,
nonempty_slots: impl IntoIterator<Item = Slot>,
Expand Down
2 changes: 1 addition & 1 deletion eth1_api/src/eth1_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ mod tests {
// The block seems to be from the Kintsugi testnet. There's no block explorer still serving
// Kintsugi blocks to confirm it, but the block number and timestamp suggest that execution
// layer genesis happened around 2021-12-15, just before the `MIN_GENESIS_TIME` of Kintsugi.
let config = Arc::new(Config::kintsugi());
let config = Arc::new(Config::mainnet());
let auth = Arc::default();
let server_url = server.url("/").parse()?;

Expand Down
3 changes: 3 additions & 0 deletions fork_choice_control/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,6 @@ spec_test_utils = { workspace = true }
tap = { workspace = true }
test-generator = { workspace = true }
unwrap_none = { workspace = true }

[features]
eth2-cache = []
5 changes: 5 additions & 0 deletions fork_choice_control/src/extra_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ use crate::{
// <https://github.com/ethereum/consensus-specs/issues/1887>.
// The bug would only manifest starting with the first slot of the next epoch.
#[test]
#[cfg(feature = "eth2-cache")]
fn processes_old_attestations_from_medalla_in_a_future_slot() {
let config = Arc::new(Config::medalla());
let genesis_state = medalla::GENESIS_BEACON_STATE.force().clone_arc();
Expand All @@ -64,6 +65,7 @@ fn processes_old_attestations_from_medalla_in_a_future_slot() {
}

#[test]
#[cfg(feature = "eth2-cache")]
fn processes_blocks_from_medalla_in_their_slots() {
let config = Arc::new(Config::medalla());
let genesis_state = medalla::GENESIS_BEACON_STATE.force().clone_arc();
Expand All @@ -88,6 +90,7 @@ fn processes_blocks_from_medalla_in_their_slots() {
// The blocks were not actually invalid.
// We had missed the change to the type of `WithdrawalV1.amount` in `execution-apis`.
#[test]
#[cfg(feature = "eth2-cache")]
fn handles_invalid_blocks_from_withdrawal_devnet_3() -> Result<()> {
let config = Arc::new(Config::withdrawal_devnet_3());

Expand Down Expand Up @@ -175,6 +178,7 @@ fn handles_invalid_blocks_from_withdrawal_devnet_3() -> Result<()> {
// `Store::head` was being called while the `Store` was in an inconsistent state.
// That made `assert!(no_viable_segments)` fail, though the end result may have been unaffected.
#[test]
#[cfg(feature = "eth2-cache")]
fn handles_blocks_after_non_genesis_anchor_in_their_slots() {
let config = Arc::new(Config::mainnet());
let anchor_state = mainnet::ALTAIR_BEACON_STATE.force().clone_arc();
Expand Down Expand Up @@ -211,6 +215,7 @@ fn handles_blocks_after_non_genesis_anchor_in_their_slots() {
}

#[test]
#[cfg(feature = "eth2-cache")]
fn handles_blocks_after_non_genesis_anchor_in_a_future_slot() {
let config = Arc::new(Config::mainnet());
let anchor_state = mainnet::ALTAIR_BEACON_STATE.force().clone_arc();
Expand Down
1 change: 1 addition & 0 deletions fork_choice_control/src/storage_back_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ mod tests {
use super::*;

#[test]
#[cfg(feature = "eth2-cache")]
fn test_archive_back_sync_states() -> Result<()> {
let genesis_state = mainnet::GENESIS_BEACON_STATE.force().clone_arc();
let blocks = mainnet::BEACON_BLOCKS_UP_TO_SLOT_128.force();
Expand Down
11 changes: 0 additions & 11 deletions grandine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,31 +77,20 @@ logger-parse-env = []
preset-any = []

preset-mainnet = ['preset-any']
preset-medalla = ['preset-any']
preset-minimal = ['preset-any']

network-any = []

network-goerli = ['network-any', 'preset-mainnet']
network-kiln = ['network-any', 'preset-mainnet']
network-kintsugi = ['network-any', 'preset-mainnet']
network-mainnet = ['network-any', 'preset-mainnet']
network-pyrmont = ['network-any', 'preset-mainnet']
network-ropsten = ['network-any', 'preset-mainnet']
network-sepolia = ['network-any', 'preset-mainnet']
network-shadow = ['network-any', 'preset-mainnet']
network-withdrawals = ['network-any', 'preset-mainnet']
network-holesky = ['network-any', 'preset-mainnet']

network-medalla = ['network-any', 'preset-medalla']

default-networks = [
'network-goerli',
'network-kiln',
'network-mainnet',
'network-ropsten',
'network-sepolia',
'network-shadow',
'network-withdrawals',
'network-holesky',
]
34 changes: 8 additions & 26 deletions grandine/src/grandine_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ struct ChainOptions {
/// Load genesis state from SSZ_FILE
#[clap(long, value_name = "SSZ_FILE")]
genesis_state_file: Option<PathBuf>,

/// Download genesis state from specified URL
#[clap(long, value_name = "URL")]
genesis_state_download_url: Option<Url>,
}

#[derive(Args)]
Expand Down Expand Up @@ -710,23 +714,11 @@ struct ValidatorOptions {
enum Network {
#[cfg(any(feature = "network-mainnet", test))]
Mainnet,
#[cfg(any(feature = "network-medalla", test))]
Medalla,
#[cfg(any(feature = "network-pyrmont", test))]
Pyrmont,
#[cfg(any(feature = "network-goerli", test))]
#[clap(alias = "prater")]
Goerli,
#[cfg(any(feature = "network-kintsugi", test))]
Kintsugi,
#[cfg(any(feature = "network-kiln", test))]
Kiln,
#[cfg(any(feature = "network-ropsten", test))]
Ropsten,
#[cfg(any(feature = "network-sepolia", test))]
Sepolia,
#[cfg(any(feature = "network-withdrawals", test))]
Withdrawals,
#[cfg(any(feature = "network-holesky", test))]
Holesky,
Custom,
Expand All @@ -743,22 +735,10 @@ impl Network {
match self {
#[cfg(any(feature = "network-mainnet", test))]
Self::Mainnet => Some(PredefinedNetwork::Mainnet),
#[cfg(any(feature = "network-medalla", test))]
Self::Medalla => Some(PredefinedNetwork::Medalla),
#[cfg(any(feature = "network-pyrmont", test))]
Self::Pyrmont => Some(PredefinedNetwork::Pyrmont),
#[cfg(any(feature = "network-goerli", test))]
Self::Goerli => Some(PredefinedNetwork::Goerli),
#[cfg(any(feature = "network-kintsugi", test))]
Self::Kintsugi => Some(PredefinedNetwork::Kintsugi),
#[cfg(any(feature = "network-kiln", test))]
Self::Kiln => Some(PredefinedNetwork::Kiln),
#[cfg(any(feature = "network-ropsten", test))]
Self::Ropsten => Some(PredefinedNetwork::Ropsten),
#[cfg(any(feature = "network-sepolia", test))]
Self::Sepolia => Some(PredefinedNetwork::Sepolia),
#[cfg(any(feature = "network-withdrawals", test))]
Self::Withdrawals => Some(PredefinedNetwork::Withdrawals),
#[cfg(any(feature = "network-holesky", test))]
Self::Holesky => Some(PredefinedNetwork::Holesky),
Self::Custom => None,
Expand Down Expand Up @@ -797,6 +777,7 @@ impl GrandineArgs {
terminal_block_hash_activation_epoch_override,
mut deposit_contract_starting_block,
mut genesis_state_file,
genesis_state_download_url,
} = chain_options;

let BeaconNodeOptions {
Expand Down Expand Up @@ -1131,6 +1112,7 @@ impl GrandineArgs {
chain_config: Arc::new(chain_config),
deposit_contract_starting_block,
genesis_state_file,
genesis_state_download_url,
checkpoint_sync_url,
force_checkpoint_sync,
back_sync,
Expand Down Expand Up @@ -1569,14 +1551,14 @@ mod tests {
fn predefined_network_with_customizations() {
let config = config_from_args([
"--network",
"pyrmont",
"sepolia",
"--deposit-contract-starting-block",
"0",
"--genesis-state-file",
"custom.ssz",
]);

assert_eq!(config.predefined_network, Some(PredefinedNetwork::Pyrmont));
assert_eq!(config.predefined_network, Some(PredefinedNetwork::Sepolia));
assert_eq!(config.deposit_contract_starting_block, Some(0));
assert_eq!(config.genesis_state_file, Some(PathBuf::from("custom.ssz")));
}
Expand Down
1 change: 1 addition & 0 deletions grandine/src/grandine_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub struct GrandineConfig {
pub chain_config: Arc<ChainConfig>,
pub deposit_contract_starting_block: Option<ExecutionBlockNumber>,
pub genesis_state_file: Option<PathBuf>,
pub genesis_state_download_url: Option<Url>,
pub checkpoint_sync_url: Option<Url>,
pub force_checkpoint_sync: bool,
pub back_sync: bool,
Expand Down
13 changes: 12 additions & 1 deletion grandine/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ struct Context {
store_config: StoreConfig,
deposit_contract_starting_block: Option<ExecutionBlockNumber>,
genesis_state_file: Option<PathBuf>,
genesis_state_download_url: Option<Url>,
validator_config: Arc<ValidatorConfig>,
checkpoint_sync_url: Option<Url>,
force_checkpoint_sync: bool,
Expand Down Expand Up @@ -129,6 +130,7 @@ impl Context {
store_config,
mut deposit_contract_starting_block,
genesis_state_file,
genesis_state_download_url,
validator_config,
checkpoint_sync_url,
force_checkpoint_sync,
Expand Down Expand Up @@ -209,6 +211,7 @@ impl Context {
.clone()
.unwrap_or_default(),
checkpoint_sync_url.clone(),
genesis_state_download_url,
&eth1_chain,
)
.await?;
Expand Down Expand Up @@ -312,6 +315,7 @@ fn try_main() -> Result<()> {
chain_config,
deposit_contract_starting_block,
genesis_state_file,
genesis_state_download_url,
checkpoint_sync_url,
force_checkpoint_sync,
back_sync,
Expand Down Expand Up @@ -437,6 +441,7 @@ fn try_main() -> Result<()> {
store_config,
deposit_contract_starting_block,
genesis_state_file,
genesis_state_download_url,
validator_config,
checkpoint_sync_url,
force_checkpoint_sync,
Expand Down Expand Up @@ -659,6 +664,7 @@ async fn genesis_provider<P: Preset>(
client: &Client,
store_directory: PathBuf,
checkpoint_sync_url: Option<Url>,
genesis_state_download_url: Option<Url>,
eth1_chain: &Eth1Chain,
) -> Result<GenesisProvider<P>> {
if let Some(file_path) = genesis_state_file {
Expand All @@ -669,7 +675,12 @@ async fn genesis_provider<P: Preset>(

if let Some(predefined_network) = predefined_network {
return predefined_network
.genesis_provider::<P>(client, store_directory.as_path(), checkpoint_sync_url)
.genesis_provider::<P>(
client,
store_directory.as_path(),
checkpoint_sync_url,
genesis_state_download_url,
)
.await;
}

Expand Down
Loading

0 comments on commit ffb4e80

Please sign in to comment.