Merge branch 'sigp:stable' into stable
This commit is contained in:
477 files changed
+26608
-12324
No files matched your search
+34
-34
@@ -1,9 +1,9 @@
|
||||
[package]
|
||||
name = "lcli"
|
||||
description = "Lighthouse CLI (modeled after zcli)"
|
||||
version = "4.2.0"
|
||||
version = "4.5.0"
|
||||
authors = ["Paul Hauner <paul@paulhauner.com>"]
|
||||
edition = "2021"
|
||||
edition = { workspace = true }
|
||||
|
||||
[features]
|
||||
portable = ["bls/supranational-portable"]
|
||||
@@ -11,38 +11,38 @@ fake_crypto = ['bls/fake_crypto']
|
||||
jemalloc = ["malloc_utils/jemalloc"]
|
||||
|
||||
[dependencies]
|
||||
bls = { path = "../crypto/bls" }
|
||||
clap = "2.33.3"
|
||||
log = "0.4.11"
|
||||
serde = "1.0.116"
|
||||
serde_yaml = "0.8.13"
|
||||
serde_json = "1.0.66"
|
||||
env_logger = "0.9.0"
|
||||
types = { path = "../consensus/types" }
|
||||
state_processing = { path = "../consensus/state_processing" }
|
||||
int_to_bytes = { path = "../consensus/int_to_bytes" }
|
||||
ethereum_hashing = "1.0.0-beta.2"
|
||||
ethereum_ssz = "0.5.0"
|
||||
environment = { path = "../lighthouse/environment" }
|
||||
eth2_network_config = { path = "../common/eth2_network_config" }
|
||||
genesis = { path = "../beacon_node/genesis" }
|
||||
deposit_contract = { path = "../common/deposit_contract" }
|
||||
tree_hash = "0.5.0"
|
||||
clap_utils = { path = "../common/clap_utils" }
|
||||
lighthouse_network = { path = "../beacon_node/lighthouse_network" }
|
||||
validator_dir = { path = "../common/validator_dir", features = ["insecure_keys"] }
|
||||
lighthouse_version = { path = "../common/lighthouse_version" }
|
||||
directory = { path = "../common/directory" }
|
||||
account_utils = { path = "../common/account_utils" }
|
||||
eth2_wallet = { path = "../crypto/eth2_wallet" }
|
||||
eth1_test_rig = { path = "../testing/eth1_test_rig" }
|
||||
sensitive_url = { path = "../common/sensitive_url" }
|
||||
eth2 = { path = "../common/eth2" }
|
||||
snap = "1.0.1"
|
||||
beacon_chain = { path = "../beacon_node/beacon_chain" }
|
||||
store = { path = "../beacon_node/store" }
|
||||
malloc_utils = { path = "../common/malloc_utils" }
|
||||
rayon = "1.7.0"
|
||||
bls = { workspace = true }
|
||||
clap = { workspace = true }
|
||||
log = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
serde_yaml = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
env_logger = { workspace = true }
|
||||
types = { workspace = true }
|
||||
state_processing = { workspace = true }
|
||||
int_to_bytes = { workspace = true }
|
||||
ethereum_hashing = { workspace = true }
|
||||
ethereum_ssz = { workspace = true }
|
||||
environment = { workspace = true }
|
||||
eth2_network_config = { workspace = true }
|
||||
genesis = { workspace = true }
|
||||
deposit_contract = { workspace = true }
|
||||
tree_hash = { workspace = true }
|
||||
clap_utils = { workspace = true }
|
||||
lighthouse_network = { workspace = true }
|
||||
validator_dir = { workspace = true, features = ["insecure_keys"] }
|
||||
lighthouse_version = { workspace = true }
|
||||
directory = { workspace = true }
|
||||
account_utils = { workspace = true }
|
||||
eth2_wallet = { workspace = true }
|
||||
eth1_test_rig = { workspace = true }
|
||||
sensitive_url = { workspace = true }
|
||||
eth2 = { workspace = true }
|
||||
snap = { workspace = true }
|
||||
beacon_chain = { workspace = true }
|
||||
store = { workspace = true }
|
||||
malloc_utils = { workspace = true }
|
||||
rayon = { workspace = true }
|
||||
|
||||
[package.metadata.cargo-udeps.ignore]
|
||||
normal = ["malloc_utils"]
|
||||
+3
-3
@@ -1,8 +1,8 @@
|
||||
# `lcli` requires the full project to be in scope, so this should be built either:
|
||||
# - from the `lighthouse` dir with the command: `docker build -f ./lcli/Dockerflie .`
|
||||
# - from the current directory with the command: `docker build -f ./Dockerfile ../`
|
||||
FROM rust:1.68.2-bullseye AS builder
|
||||
RUN apt-get update && apt-get -y upgrade && apt-get install -y cmake libclang-dev protobuf-compiler
|
||||
FROM rust:1.69.0-bullseye AS builder
|
||||
RUN apt-get update && apt-get -y upgrade && apt-get install -y cmake libclang-dev
|
||||
COPY . lighthouse
|
||||
ARG PORTABLE
|
||||
ENV PORTABLE $PORTABLE
|
||||
@@ -10,4 +10,4 @@ RUN if [ "$PORTABLE" = true ] ; then export FEATURES=portable; fi && cd lighthou
|
||||
|
||||
FROM ubuntu:22.04
|
||||
RUN apt-get update && apt-get -y upgrade && apt-get clean && rm -rf /var/lib/apt/lists/*
|
||||
COPY --from=builder /usr/local/cargo/bin/lcli /usr/local/bin/lcli
|
||||
COPY --from=builder /usr/local/cargo/bin/lcli /usr/local/bin/lcli
|
||||
@@ -31,14 +31,19 @@ use clap::ArgMatches;
|
||||
use clap_utils::{parse_optional, parse_required};
|
||||
use environment::Environment;
|
||||
use eth2::{types::BlockId, BeaconNodeHttpClient, SensitiveUrl, Timeouts};
|
||||
use eth2_network_config::Eth2NetworkConfig;
|
||||
use std::path::PathBuf;
|
||||
use std::time::{Duration, Instant};
|
||||
use types::{EthSpec, FullPayload, SignedBeaconBlock};
|
||||
|
||||
const HTTP_TIMEOUT: Duration = Duration::from_secs(5);
|
||||
|
||||
pub fn run<T: EthSpec>(env: Environment<T>, matches: &ArgMatches) -> Result<(), String> {
|
||||
let spec = &T::default_spec();
|
||||
pub fn run<T: EthSpec>(
|
||||
env: Environment<T>,
|
||||
network_config: Eth2NetworkConfig,
|
||||
matches: &ArgMatches,
|
||||
) -> Result<(), String> {
|
||||
let spec = &network_config.chain_spec::<T>()?;
|
||||
let executor = env.core_context().executor;
|
||||
|
||||
/*
|
||||
|
||||
@@ -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))?;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use clap::ArgMatches;
|
||||
use lighthouse_network::{
|
||||
discovery::{build_enr, CombinedKey, CombinedKeyExt, Keypair, ENR_FILENAME},
|
||||
discovery::{build_enr, CombinedKey, CombinedKeyExt, ENR_FILENAME},
|
||||
libp2p::identity::secp256k1,
|
||||
NetworkConfig, NETWORK_KEY_FILENAME,
|
||||
};
|
||||
use std::fs::File;
|
||||
@@ -29,8 +30,8 @@ pub fn run<T: EthSpec>(matches: &ArgMatches) -> Result<(), String> {
|
||||
config.enr_udp4_port = Some(udp_port);
|
||||
config.enr_tcp6_port = Some(tcp_port);
|
||||
|
||||
let local_keypair = Keypair::generate_secp256k1();
|
||||
let enr_key = CombinedKey::from_libp2p(&local_keypair)?;
|
||||
let secp256k1_keypair = secp256k1::Keypair::generate();
|
||||
let enr_key = CombinedKey::from_secp256k1(&secp256k1_keypair);
|
||||
let enr_fork_id = EnrForkId {
|
||||
fork_digest: ChainSpec::compute_fork_digest(genesis_fork_version, Hash256::zero()),
|
||||
next_fork_version: genesis_fork_version,
|
||||
@@ -47,13 +48,10 @@ pub fn run<T: EthSpec>(matches: &ArgMatches) -> Result<(), String> {
|
||||
.write_all(enr.to_base64().as_bytes())
|
||||
.map_err(|e| format!("Unable to write ENR to {}: {:?}", ENR_FILENAME, e))?;
|
||||
|
||||
let secret_bytes = match local_keypair {
|
||||
Keypair::Secp256k1(key) => key.secret().to_bytes(),
|
||||
_ => return Err("Key is not a secp256k1 key".into()),
|
||||
};
|
||||
|
||||
let mut key_file = File::create(output_dir.join(NETWORK_KEY_FILENAME))
|
||||
.map_err(|e| format!("Unable to create {}: {:?}", NETWORK_KEY_FILENAME, e))?;
|
||||
|
||||
let secret_bytes = secp256k1_keypair.secret().to_bytes();
|
||||
key_file
|
||||
.write_all(&secret_bytes)
|
||||
.map_err(|e| format!("Unable to write key to {}: {:?}", NETWORK_KEY_FILENAME, e))?;
|
||||
|
||||
@@ -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(())
|
||||
|
||||
+117
-28
@@ -15,11 +15,13 @@ mod new_testnet;
|
||||
mod parse_ssz;
|
||||
mod replace_state_pubkeys;
|
||||
mod skip_slots;
|
||||
mod state_root;
|
||||
mod transition_blocks;
|
||||
|
||||
use clap::{App, Arg, ArgMatches, SubCommand};
|
||||
use clap_utils::parse_path_with_default_in_home_dir;
|
||||
use clap_utils::parse_optional;
|
||||
use environment::{EnvironmentBuilder, LoggerConfig};
|
||||
use eth2_network_config::Eth2NetworkConfig;
|
||||
use parse_ssz::run_parse_ssz;
|
||||
use std::path::PathBuf;
|
||||
use std::process;
|
||||
@@ -38,7 +40,6 @@ fn main() {
|
||||
.long("spec")
|
||||
.value_name("STRING")
|
||||
.takes_value(true)
|
||||
.required(true)
|
||||
.possible_values(&["minimal", "mainnet", "gnosis"])
|
||||
.default_value("mainnet")
|
||||
.global(true),
|
||||
@@ -50,7 +51,16 @@ fn main() {
|
||||
.value_name("PATH")
|
||||
.takes_value(true)
|
||||
.global(true)
|
||||
.help("The testnet dir. Defaults to ~/.lighthouse/testnet"),
|
||||
.help("The testnet dir."),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("network")
|
||||
.long("network")
|
||||
.value_name("NAME")
|
||||
.takes_value(true)
|
||||
.global(true)
|
||||
.help("The network to use. Defaults to mainnet.")
|
||||
.conflicts_with("testnet-dir")
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("skip-slots")
|
||||
@@ -126,7 +136,7 @@ fn main() {
|
||||
.takes_value(true)
|
||||
.conflicts_with("beacon-url")
|
||||
.requires("block-path")
|
||||
.help("Path to load a BeaconState from file as SSZ."),
|
||||
.help("Path to load a BeaconState from as SSZ."),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("block-path")
|
||||
@@ -135,7 +145,7 @@ fn main() {
|
||||
.takes_value(true)
|
||||
.conflicts_with("beacon-url")
|
||||
.requires("pre-state-path")
|
||||
.help("Path to load a SignedBeaconBlock from file as SSZ."),
|
||||
.help("Path to load a SignedBeaconBlock from as SSZ."),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("post-state-output-path")
|
||||
@@ -361,7 +371,6 @@ fn main() {
|
||||
.index(2)
|
||||
.value_name("BIP39_MNENMONIC")
|
||||
.takes_value(true)
|
||||
.required(true)
|
||||
.default_value(
|
||||
"replace nephew blur decorate waste convince soup column \
|
||||
orient excite play baby",
|
||||
@@ -382,7 +391,6 @@ fn main() {
|
||||
.help("The block hash used when generating an execution payload. This \
|
||||
value is used for `execution_payload_header.block_hash` as well as \
|
||||
`execution_payload_header.random`")
|
||||
.required(true)
|
||||
.default_value(
|
||||
"0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||
),
|
||||
@@ -400,7 +408,6 @@ fn main() {
|
||||
.value_name("INTEGER")
|
||||
.takes_value(true)
|
||||
.help("The base fee per gas field in the execution payload generated.")
|
||||
.required(true)
|
||||
.default_value("1000000000"),
|
||||
)
|
||||
.arg(
|
||||
@@ -409,7 +416,6 @@ fn main() {
|
||||
.value_name("INTEGER")
|
||||
.takes_value(true)
|
||||
.help("The gas limit field in the execution payload generated.")
|
||||
.required(true)
|
||||
.default_value("30000000"),
|
||||
)
|
||||
.arg(
|
||||
@@ -808,14 +814,14 @@ fn main() {
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("block-root")
|
||||
.about("Computes the block root of some block")
|
||||
.about("Computes the block root of some block.")
|
||||
.arg(
|
||||
Arg::with_name("block-path")
|
||||
.long("block-path")
|
||||
.value_name("PATH")
|
||||
.takes_value(true)
|
||||
.conflicts_with("beacon-url")
|
||||
.help("Path to load a SignedBeaconBlock from file as SSZ."),
|
||||
.help("Path to load a SignedBeaconBlock from as SSZ."),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("beacon-url")
|
||||
@@ -841,6 +847,41 @@ fn main() {
|
||||
.help("Number of repeat runs, useful for benchmarking."),
|
||||
)
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("state-root")
|
||||
.about("Computes the state root of some state.")
|
||||
.arg(
|
||||
Arg::with_name("state-path")
|
||||
.long("state-path")
|
||||
.value_name("PATH")
|
||||
.takes_value(true)
|
||||
.conflicts_with("beacon-url")
|
||||
.help("Path to load a BeaconState from as SSZ."),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("beacon-url")
|
||||
.long("beacon-url")
|
||||
.value_name("URL")
|
||||
.takes_value(true)
|
||||
.help("URL to a beacon-API provider."),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("state-id")
|
||||
.long("state-id")
|
||||
.value_name("BLOCK_ID")
|
||||
.takes_value(true)
|
||||
.requires("beacon-url")
|
||||
.help("Identifier for a state as per beacon-API standards (slot, root, etc.)"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("runs")
|
||||
.long("runs")
|
||||
.value_name("INTEGER")
|
||||
.takes_value(true)
|
||||
.default_value("1")
|
||||
.help("Number of repeat runs, useful for benchmarking."),
|
||||
)
|
||||
)
|
||||
.get_matches();
|
||||
|
||||
let result = matches
|
||||
@@ -887,41 +928,81 @@ fn run<T: EthSpec>(
|
||||
.build()
|
||||
.map_err(|e| format!("should build env: {:?}", e))?;
|
||||
|
||||
let testnet_dir = parse_path_with_default_in_home_dir(
|
||||
matches,
|
||||
"testnet-dir",
|
||||
PathBuf::from(directory::DEFAULT_ROOT_DIR).join("testnet"),
|
||||
)?;
|
||||
// Determine testnet-dir path or network name depending on CLI flags.
|
||||
let (testnet_dir, network_name) =
|
||||
if let Some(testnet_dir) = parse_optional::<PathBuf>(matches, "testnet-dir")? {
|
||||
(Some(testnet_dir), None)
|
||||
} else {
|
||||
let network_name =
|
||||
parse_optional(matches, "network")?.unwrap_or_else(|| "mainnet".to_string());
|
||||
(None, Some(network_name))
|
||||
};
|
||||
|
||||
// Lazily load either the testnet dir or the network config, as required.
|
||||
// Some subcommands like new-testnet need the testnet dir but not the network config.
|
||||
let get_testnet_dir = || testnet_dir.clone().ok_or("testnet-dir is required");
|
||||
let get_network_config = || {
|
||||
if let Some(testnet_dir) = &testnet_dir {
|
||||
Eth2NetworkConfig::load(testnet_dir.clone()).map_err(|e| {
|
||||
format!(
|
||||
"Unable to open testnet dir at {}: {}",
|
||||
testnet_dir.display(),
|
||||
e
|
||||
)
|
||||
})
|
||||
} else {
|
||||
let network_name = network_name.ok_or("no network name or testnet-dir provided")?;
|
||||
Eth2NetworkConfig::constant(&network_name)?.ok_or("invalid network name".into())
|
||||
}
|
||||
};
|
||||
|
||||
match matches.subcommand() {
|
||||
("transition-blocks", Some(matches)) => transition_blocks::run::<T>(env, matches)
|
||||
.map_err(|e| format!("Failed to transition blocks: {}", e)),
|
||||
("transition-blocks", Some(matches)) => {
|
||||
let network_config = get_network_config()?;
|
||||
transition_blocks::run::<T>(env, network_config, matches)
|
||||
.map_err(|e| format!("Failed to transition blocks: {}", e))
|
||||
}
|
||||
("skip-slots", Some(matches)) => {
|
||||
skip_slots::run::<T>(env, matches).map_err(|e| format!("Failed to skip slots: {}", e))
|
||||
let network_config = get_network_config()?;
|
||||
skip_slots::run::<T>(env, network_config, matches)
|
||||
.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)
|
||||
.map_err(|e| format!("Failed to run deploy-deposit-contract command: {}", e))
|
||||
}
|
||||
("eth1-genesis", Some(matches)) => eth1_genesis::run::<T>(env, testnet_dir, matches)
|
||||
.map_err(|e| format!("Failed to run eth1-genesis command: {}", e)),
|
||||
("interop-genesis", Some(matches)) => interop_genesis::run::<T>(testnet_dir, matches)
|
||||
.map_err(|e| format!("Failed to run interop-genesis command: {}", e)),
|
||||
("eth1-genesis", Some(matches)) => {
|
||||
let testnet_dir = get_testnet_dir()?;
|
||||
eth1_genesis::run::<T>(env, testnet_dir, matches)
|
||||
.map_err(|e| format!("Failed to run eth1-genesis command: {}", e))
|
||||
}
|
||||
("interop-genesis", Some(matches)) => {
|
||||
let testnet_dir = get_testnet_dir()?;
|
||||
interop_genesis::run::<T>(testnet_dir, matches)
|
||||
.map_err(|e| format!("Failed to run interop-genesis command: {}", e))
|
||||
}
|
||||
("change-genesis-time", Some(matches)) => {
|
||||
let testnet_dir = get_testnet_dir()?;
|
||||
change_genesis_time::run::<T>(testnet_dir, matches)
|
||||
.map_err(|e| format!("Failed to run change-genesis-time command: {}", e))
|
||||
}
|
||||
("create-payload-header", Some(matches)) => create_payload_header::run::<T>(matches)
|
||||
.map_err(|e| format!("Failed to run create-payload-header command: {}", e)),
|
||||
("replace-state-pubkeys", Some(matches)) => {
|
||||
let testnet_dir = get_testnet_dir()?;
|
||||
replace_state_pubkeys::run::<T>(testnet_dir, matches)
|
||||
.map_err(|e| format!("Failed to run replace-state-pubkeys command: {}", e))
|
||||
}
|
||||
("new-testnet", Some(matches)) => new_testnet::run::<T>(testnet_dir, matches)
|
||||
.map_err(|e| format!("Failed to run new_testnet command: {}", e)),
|
||||
("new-testnet", Some(matches)) => {
|
||||
let testnet_dir = get_testnet_dir()?;
|
||||
new_testnet::run::<T>(testnet_dir, matches)
|
||||
.map_err(|e| format!("Failed to run new_testnet command: {}", e))
|
||||
}
|
||||
("check-deposit-data", Some(matches)) => check_deposit_data::run(matches)
|
||||
.map_err(|e| format!("Failed to run check-deposit-data command: {}", e)),
|
||||
("generate-bootnode-enr", Some(matches)) => generate_bootnode_enr::run::<T>(matches)
|
||||
@@ -932,8 +1013,16 @@ fn run<T: EthSpec>(
|
||||
.map_err(|e| format!("Failed to run mnemonic-validators command: {}", e)),
|
||||
("indexed-attestations", Some(matches)) => indexed_attestations::run::<T>(matches)
|
||||
.map_err(|e| format!("Failed to run indexed-attestations command: {}", e)),
|
||||
("block-root", Some(matches)) => block_root::run::<T>(env, matches)
|
||||
.map_err(|e| format!("Failed to run block-root command: {}", e)),
|
||||
("block-root", Some(matches)) => {
|
||||
let network_config = get_network_config()?;
|
||||
block_root::run::<T>(env, network_config, matches)
|
||||
.map_err(|e| format!("Failed to run block-root command: {}", e))
|
||||
}
|
||||
("state-root", Some(matches)) => {
|
||||
let network_config = get_network_config()?;
|
||||
state_root::run::<T>(env, network_config, matches)
|
||||
.map_err(|e| format!("Failed to run state-root command: {}", e))
|
||||
}
|
||||
(other, _) => Err(format!("Unknown subcommand {}. See --help.", other)),
|
||||
}
|
||||
}
|
||||
@@ -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};
|
||||
@@ -190,7 +190,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),
|
||||
};
|
||||
|
||||
@@ -303,7 +304,7 @@ fn initialize_state_with_validators<T: EthSpec>(
|
||||
}
|
||||
|
||||
// Now that we have our validators, initialize the caches (including the committees)
|
||||
state.build_all_caches(spec).unwrap();
|
||||
state.build_caches(spec).unwrap();
|
||||
|
||||
// Set genesis validators root for domain separation and chain versioning
|
||||
*state.genesis_validators_root_mut() = state.update_validators_tree_hash_cache().unwrap();
|
||||
|
||||
+55
-16
@@ -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:?}"))?
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ use clap::ArgMatches;
|
||||
use clap_utils::{parse_optional, parse_required};
|
||||
use environment::Environment;
|
||||
use eth2::{types::StateId, BeaconNodeHttpClient, SensitiveUrl, Timeouts};
|
||||
use eth2_network_config::Eth2NetworkConfig;
|
||||
use ssz::Encode;
|
||||
use state_processing::state_advance::{complete_state_advance, partial_state_advance};
|
||||
use std::fs::File;
|
||||
@@ -59,8 +60,12 @@ use types::{BeaconState, CloneConfig, EthSpec, Hash256};
|
||||
|
||||
const HTTP_TIMEOUT: Duration = Duration::from_secs(10);
|
||||
|
||||
pub fn run<T: EthSpec>(env: Environment<T>, matches: &ArgMatches) -> Result<(), String> {
|
||||
let spec = &T::default_spec();
|
||||
pub fn run<T: EthSpec>(
|
||||
env: Environment<T>,
|
||||
network_config: Eth2NetworkConfig,
|
||||
matches: &ArgMatches,
|
||||
) -> Result<(), String> {
|
||||
let spec = &network_config.chain_spec::<T>()?;
|
||||
let executor = env.core_context().executor;
|
||||
|
||||
let output_path: Option<PathBuf> = parse_optional(matches, "output-path")?;
|
||||
@@ -109,7 +114,7 @@ pub fn run<T: EthSpec>(env: Environment<T>, matches: &ArgMatches) -> Result<(),
|
||||
let target_slot = initial_slot + slots;
|
||||
|
||||
state
|
||||
.build_all_caches(spec)
|
||||
.build_caches(spec)
|
||||
.map_err(|e| format!("Unable to build caches: {:?}", e))?;
|
||||
|
||||
let state_root = if let Some(root) = cli_state_root.or(state_root) {
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
use crate::transition_blocks::load_from_ssz_with;
|
||||
use clap::ArgMatches;
|
||||
use clap_utils::{parse_optional, parse_required};
|
||||
use environment::Environment;
|
||||
use eth2::{types::StateId, BeaconNodeHttpClient, SensitiveUrl, Timeouts};
|
||||
use eth2_network_config::Eth2NetworkConfig;
|
||||
use std::path::PathBuf;
|
||||
use std::time::{Duration, Instant};
|
||||
use types::{BeaconState, EthSpec};
|
||||
|
||||
const HTTP_TIMEOUT: Duration = Duration::from_secs(10);
|
||||
|
||||
pub fn run<T: EthSpec>(
|
||||
env: Environment<T>,
|
||||
network_config: Eth2NetworkConfig,
|
||||
matches: &ArgMatches,
|
||||
) -> Result<(), String> {
|
||||
let executor = env.core_context().executor;
|
||||
|
||||
let spec = &network_config.chain_spec::<T>()?;
|
||||
|
||||
let state_path: Option<PathBuf> = parse_optional(matches, "state-path")?;
|
||||
let beacon_url: Option<SensitiveUrl> = parse_optional(matches, "beacon-url")?;
|
||||
let runs: usize = parse_required(matches, "runs")?;
|
||||
|
||||
info!(
|
||||
"Using {} network ({} spec)",
|
||||
spec.config_name.as_deref().unwrap_or("unknown"),
|
||||
T::spec_name()
|
||||
);
|
||||
info!("Doing {} runs", runs);
|
||||
|
||||
let state = match (state_path, beacon_url) {
|
||||
(Some(state_path), None) => {
|
||||
info!("State path: {:?}", state_path);
|
||||
load_from_ssz_with(&state_path, spec, BeaconState::from_ssz_bytes)?
|
||||
}
|
||||
(None, Some(beacon_url)) => {
|
||||
let state_id: StateId = parse_required(matches, "state-id")?;
|
||||
let client = BeaconNodeHttpClient::new(beacon_url, Timeouts::set_all(HTTP_TIMEOUT));
|
||||
executor
|
||||
.handle()
|
||||
.ok_or("shutdown in progress")?
|
||||
.block_on(async move {
|
||||
client
|
||||
.get_debug_beacon_states::<T>(state_id)
|
||||
.await
|
||||
.map_err(|e| format!("Failed to download state: {:?}", e))
|
||||
})
|
||||
.map_err(|e| format!("Failed to complete task: {:?}", e))?
|
||||
.ok_or_else(|| format!("Unable to locate state at {:?}", state_id))?
|
||||
.data
|
||||
}
|
||||
_ => return Err("must supply either --state-path or --beacon-url".into()),
|
||||
};
|
||||
|
||||
/*
|
||||
* Perform the core "runs".
|
||||
*/
|
||||
let mut state_root = None;
|
||||
for i in 0..runs {
|
||||
let mut state = state.clone();
|
||||
let timer = Instant::now();
|
||||
state_root = Some(
|
||||
state
|
||||
.update_tree_hash_cache()
|
||||
.map_err(|e| format!("error computing state root: {e:?}"))?,
|
||||
);
|
||||
info!("Run {}: {:?}", i, timer.elapsed());
|
||||
}
|
||||
|
||||
if let Some(state_root) = state_root {
|
||||
info!("State root is {:?}", state_root);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -71,10 +71,12 @@ use eth2::{
|
||||
types::{BlockId, StateId},
|
||||
BeaconNodeHttpClient, SensitiveUrl, Timeouts,
|
||||
};
|
||||
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,
|
||||
BlockSignatureStrategy, ConsensusContext, StateProcessingStrategy, VerifyBlockRoot,
|
||||
block_signature_verifier::BlockSignatureVerifier, per_block_processing, BlockSignatureStrategy,
|
||||
ConsensusContext, StateProcessingStrategy, VerifyBlockRoot,
|
||||
};
|
||||
use std::borrow::Cow;
|
||||
use std::fs::File;
|
||||
@@ -94,8 +96,12 @@ struct Config {
|
||||
exclude_post_block_thc: bool,
|
||||
}
|
||||
|
||||
pub fn run<T: EthSpec>(env: Environment<T>, matches: &ArgMatches) -> Result<(), String> {
|
||||
let spec = &T::default_spec();
|
||||
pub fn run<T: EthSpec>(
|
||||
env: Environment<T>,
|
||||
network_config: Eth2NetworkConfig,
|
||||
matches: &ArgMatches,
|
||||
) -> Result<(), String> {
|
||||
let spec = &network_config.chain_spec::<T>()?;
|
||||
let executor = env.core_context().executor;
|
||||
|
||||
/*
|
||||
@@ -205,7 +211,7 @@ pub fn run<T: EthSpec>(env: Environment<T>, matches: &ArgMatches) -> Result<(),
|
||||
|
||||
if config.exclude_cache_builds {
|
||||
pre_state
|
||||
.build_all_caches(spec)
|
||||
.build_caches(spec)
|
||||
.map_err(|e| format!("Unable to build caches: {:?}", e))?;
|
||||
let state_root = pre_state
|
||||
.update_tree_hash_cache()
|
||||
@@ -303,7 +309,7 @@ fn do_transition<T: EthSpec>(
|
||||
if !config.exclude_cache_builds {
|
||||
let t = Instant::now();
|
||||
pre_state
|
||||
.build_all_caches(spec)
|
||||
.build_caches(spec)
|
||||
.map_err(|e| format!("Unable to build caches: {:?}", e))?;
|
||||
debug!("Build caches: {:?}", t.elapsed());
|
||||
|
||||
@@ -327,15 +333,13 @@ 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());
|
||||
|
||||
let t = Instant::now();
|
||||
pre_state
|
||||
.build_all_caches(spec)
|
||||
.build_caches(spec)
|
||||
.map_err(|e| format!("Unable to build caches: {:?}", e))?;
|
||||
debug!("Build all caches (again): {:?}", t.elapsed());
|
||||
|
||||
|
||||
Reference in new issue
Block a user