Merge remote-tracking branch 'origin/unstable' into tree-states

This commit is contained in:
Michael Sproul
2023-09-13 11:25:18 +10:00
250 changed files with 13730 additions and 5455 deletions

View File

@@ -49,7 +49,7 @@ pub fn run<T: EthSpec>(
.wait_for_genesis_state::<T>(ETH1_GENESIS_UPDATE_INTERVAL, spec)
.await
.map(move |genesis_state| {
eth2_network_config.genesis_state_bytes = Some(genesis_state.as_ssz_bytes());
eth2_network_config.genesis_state_bytes = Some(genesis_state.as_ssz_bytes().into());
eth2_network_config.force_write_to_file(testnet_dir)
})
.map_err(|e| format!("Failed to find genesis: {}", e))?;

View File

@@ -42,7 +42,7 @@ pub fn run<T: EthSpec>(testnet_dir: PathBuf, matches: &ArgMatches) -> Result<(),
&spec,
)?;
eth2_network_config.genesis_state_bytes = Some(genesis_state.as_ssz_bytes());
eth2_network_config.genesis_state_bytes = Some(genesis_state.as_ssz_bytes().into());
eth2_network_config.force_write_to_file(testnet_dir)?;
Ok(())

View File

@@ -985,7 +985,9 @@ fn run<T: EthSpec>(
.map_err(|e| format!("Failed to skip slots: {}", e))
}
("pretty-ssz", Some(matches)) => {
run_parse_ssz::<T>(matches).map_err(|e| format!("Failed to pretty print hex: {}", e))
let network_config = get_network_config()?;
run_parse_ssz::<T>(network_config, matches)
.map_err(|e| format!("Failed to pretty print hex: {}", e))
}
("deploy-deposit-contract", Some(matches)) => {
deploy_deposit_contract::run::<T>(env, matches)

View File

@@ -1,7 +1,7 @@
use account_utils::eth2_keystore::keypair_from_secret;
use clap::ArgMatches;
use clap_utils::{parse_optional, parse_required, parse_ssz_optional};
use eth2_network_config::Eth2NetworkConfig;
use eth2_network_config::{Eth2NetworkConfig, GenesisStateSource};
use eth2_wallet::bip39::Seed;
use eth2_wallet::bip39::{Language, Mnemonic};
use eth2_wallet::{recover_validator_secret_from_mnemonic, KeyType};
@@ -191,7 +191,8 @@ pub fn run<T: EthSpec>(testnet_dir_path: PathBuf, matches: &ArgMatches) -> Resul
let testnet = Eth2NetworkConfig {
deposit_contract_deploy_block,
boot_enr: Some(vec![]),
genesis_state_bytes,
genesis_state_bytes: genesis_state_bytes.map(Into::into),
genesis_state_source: GenesisStateSource::IncludedBytes,
config: Config::from_chain_spec::<T>(&spec),
};

View File

@@ -1,5 +1,6 @@
use clap::ArgMatches;
use clap_utils::parse_required;
use eth2_network_config::Eth2NetworkConfig;
use serde::Serialize;
use snap::raw::Decoder;
use ssz::Decode;
@@ -26,7 +27,10 @@ impl FromStr for OutputFormat {
}
}
pub fn run_parse_ssz<T: EthSpec>(matches: &ArgMatches) -> Result<(), String> {
pub fn run_parse_ssz<T: EthSpec>(
network_config: Eth2NetworkConfig,
matches: &ArgMatches,
) -> Result<(), String> {
let type_str = matches.value_of("type").ok_or("No type supplied")?;
let filename = matches.value_of("ssz-file").ok_or("No file supplied")?;
let format = parse_required(matches, "format")?;
@@ -44,44 +48,79 @@ pub fn run_parse_ssz<T: EthSpec>(matches: &ArgMatches) -> Result<(), String> {
bytes
};
info!("Using {} spec", T::spec_name());
info!("Type: {:?}", type_str);
let spec = &network_config.chain_spec::<T>()?;
info!(
"Using {} network config ({} preset)",
spec.config_name.as_deref().unwrap_or("unknown"),
T::spec_name()
);
info!("Type: {type_str}");
// More fork-specific decoders may need to be added in future, but shouldn't be 100% necessary,
// as the fork-generic decoder will always be available (requires correct --network flag).
match type_str {
"signed_block_base" => decode_and_print::<SignedBeaconBlockBase<T>>(&bytes, format)?,
"signed_block_altair" => decode_and_print::<SignedBeaconBlockAltair<T>>(&bytes, format)?,
"signed_block_merge" => decode_and_print::<SignedBeaconBlockMerge<T>>(&bytes, format)?,
"block_base" => decode_and_print::<BeaconBlockBase<T>>(&bytes, format)?,
"block_altair" => decode_and_print::<BeaconBlockAltair<T>>(&bytes, format)?,
"block_merge" => decode_and_print::<BeaconBlockMerge<T>>(&bytes, format)?,
"state_base" => decode_and_print::<BeaconStateBase<T>>(&bytes, format)?,
"state_altair" => decode_and_print::<BeaconStateAltair<T>>(&bytes, format)?,
"state_merge" => decode_and_print::<BeaconStateMerge<T>>(&bytes, format)?,
"SignedBeaconBlock" => decode_and_print::<SignedBeaconBlock<T>>(
&bytes,
|bytes| SignedBeaconBlock::from_ssz_bytes(bytes, spec),
format,
)?,
"SignedBeaconBlockBase" | "SignedBeaconBlockPhase0" => {
decode_and_print(&bytes, SignedBeaconBlockBase::<T>::from_ssz_bytes, format)?
}
"SignedBeaconBlockAltair" => {
decode_and_print(&bytes, SignedBeaconBlockAltair::<T>::from_ssz_bytes, format)?
}
"SignedBeaconBlockMerge" | "SignedBeaconBlockBellatrix" => {
decode_and_print(&bytes, SignedBeaconBlockMerge::<T>::from_ssz_bytes, format)?
}
"SignedBeaconBlockCapella" => decode_and_print(
&bytes,
SignedBeaconBlockCapella::<T>::from_ssz_bytes,
format,
)?,
"BeaconState" => decode_and_print::<BeaconState<T>>(
&bytes,
|bytes| BeaconState::from_ssz_bytes(bytes, spec),
format,
)?,
"BeaconStateBase" | "BeaconStatePhase0" => {
decode_and_print(&bytes, BeaconStateBase::<T>::from_ssz_bytes, format)?
}
"BeaconStateAltair" => {
decode_and_print(&bytes, BeaconStateAltair::<T>::from_ssz_bytes, format)?
}
"BeaconStateMerge" | "BeaconStateBellatrix" => {
decode_and_print(&bytes, BeaconStateMerge::<T>::from_ssz_bytes, format)?
}
"BeaconStateCapella" => {
decode_and_print(&bytes, BeaconStateCapella::<T>::from_ssz_bytes, format)?
}
other => return Err(format!("Unknown type: {}", other)),
};
Ok(())
}
fn decode_and_print<T: Decode + Serialize>(
fn decode_and_print<T: Serialize>(
bytes: &[u8],
decoder: impl FnOnce(&[u8]) -> Result<T, ssz::DecodeError>,
output_format: OutputFormat,
) -> Result<(), String> {
let item = T::from_ssz_bytes(bytes).map_err(|e| format!("SSZ decode failed: {:?}", e))?;
let item = decoder(bytes).map_err(|e| format!("SSZ decode failed: {e:?}"))?;
match output_format {
OutputFormat::Json => {
println!(
"{}",
serde_json::to_string(&item)
.map_err(|e| format!("Unable to write object to JSON: {:?}", e))?
.map_err(|e| format!("Unable to write object to JSON: {e:?}"))?
);
}
OutputFormat::Yaml => {
println!(
"{}",
serde_yaml::to_string(&item)
.map_err(|e| format!("Unable to write object to YAML: {:?}", e))?
.map_err(|e| format!("Unable to write object to YAML: {e:?}"))?
);
}
}

View File

@@ -73,9 +73,10 @@ use eth2::{
};
use eth2_network_config::Eth2NetworkConfig;
use ssz::Encode;
use state_processing::state_advance::complete_state_advance;
use state_processing::{
block_signature_verifier::BlockSignatureVerifier, per_block_processing, per_slot_processing,
AllCaches, BlockSignatureStrategy, ConsensusContext, StateProcessingStrategy, VerifyBlockRoot,
block_signature_verifier::BlockSignatureVerifier, per_block_processing, AllCaches,
BlockSignatureStrategy, ConsensusContext, StateProcessingStrategy, VerifyBlockRoot,
};
use std::borrow::Cow;
use std::fs::File;
@@ -341,10 +342,8 @@ fn do_transition<T: EthSpec>(
// Transition the parent state to the block slot.
let t = Instant::now();
for i in pre_state.slot().as_u64()..block.slot().as_u64() {
per_slot_processing(&mut pre_state, Some(state_root), spec)
.map_err(|e| format!("Failed to advance slot on iteration {}: {:?}", i, e))?;
}
complete_state_advance(&mut pre_state, Some(state_root), block.slot(), spec)
.map_err(|e| format!("Unable to perform complete advance: {e:?}"))?;
debug!("Slot processing: {:?}", t.elapsed());
// Slot and epoch processing should keep the caches fully primed.