Skip to content

Commit

Permalink
Improve lcli
Browse files Browse the repository at this point in the history
  • Loading branch information
macladson committed Jan 26, 2024
1 parent bc36e97 commit 80ade56
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 19 deletions.
24 changes: 18 additions & 6 deletions lcli/src/generate_ssz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@ enum SszType<T: EthSpec> {
BaseState(BeaconStateBase<T>),
AltairState(BeaconStateAltair<T>),
BellatrixState(BeaconStateMerge<T>),
CapellaState(BeaconStateCapella<T>),
DenebState(BeaconStateDeneb<T>),
ElectraState(BeaconStateElectra<T>),
BaseBlock(BeaconBlockBase<T>),
AltairBlock(BeaconBlockAltair<T>),
BellatrixBlock(BeaconBlockMerge<T>),
CapellaBlock(BeaconBlockCapella<T>),
DenebBlock(BeaconBlockDeneb<T>),
ElectraBlock(BeaconBlockElectra<T>),
}

pub fn run_parse_json<T: EthSpec>(matches: &ArgMatches) -> Result<(), String> {
Expand All @@ -36,12 +42,18 @@ pub fn run_parse_json<T: EthSpec>(matches: &ArgMatches) -> Result<(), String> {
})?;

let bytes = match ssz_type {
SszType::BaseState(bases) => bases.as_ssz_bytes(),
SszType::AltairState(altairs) => altairs.as_ssz_bytes(),
SszType::BellatrixState(bellatrixs) => bellatrixs.as_ssz_bytes(),
SszType::BaseBlock(baseb) => baseb.as_ssz_bytes(),
SszType::AltairBlock(altairb) => altairb.as_ssz_bytes(),
SszType::BellatrixBlock(bellatrixb) => bellatrixb.as_ssz_bytes(),
SszType::BaseState(base_state) => base_state.as_ssz_bytes(),
SszType::AltairState(altair_state) => altair_state.as_ssz_bytes(),
SszType::BellatrixState(bellatrix_state) => bellatrix_state.as_ssz_bytes(),
SszType::CapellaState(capella_state) => capella_state.as_ssz_bytes(),
SszType::DenebState(deneb_state) => deneb_state.as_ssz_bytes(),
SszType::ElectraState(electra_state) => electra_state.as_ssz_bytes(),
SszType::BaseBlock(base_block) => base_block.as_ssz_bytes(),
SszType::AltairBlock(altair_block) => altair_block.as_ssz_bytes(),
SszType::BellatrixBlock(bellatrix_block) => bellatrix_block.as_ssz_bytes(),
SszType::CapellaBlock(capella_block) => capella_block.as_ssz_bytes(),
SszType::DenebBlock(deneb_block) => deneb_block.as_ssz_bytes(),
SszType::ElectraBlock(electra_block) => electra_block.as_ssz_bytes(),
};

let mut output =
Expand Down
30 changes: 23 additions & 7 deletions lcli/src/new_testnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ use ssz::Decode;
use ssz::Encode;
use state_processing::process_activations;
use state_processing::upgrade::{
upgrade_to_altair, upgrade_to_bellatrix, upgrade_to_capella, upgrade_to_electra,
upgrade_to_altair, upgrade_to_bellatrix, upgrade_to_capella, upgrade_to_deneb,
upgrade_to_electra,
};
use std::fs::File;
use std::io::Read;
Expand Down Expand Up @@ -350,14 +351,27 @@ fn initialize_state_with_validators<T: EthSpec>(
post_merge = true;
}

// Similarly, perform an upgrade to Deneb if configured from genesis.
if spec
.deneb_fork_epoch
.map_or(false, |fork_epoch| fork_epoch == T::genesis_epoch())
{
upgrade_to_deneb(&mut state, spec).unwrap();

// Remove intermediate Capella fork from `state.fork`.
state.fork_mut().previous_version = spec.deneb_fork_version;

post_merge = true;
}

// Similarly, perform an upgrade to Electra if configured from genesis.
if spec
.electra_fork_epoch
.map_or(false, |fork_epoch| fork_epoch == T::genesis_epoch())
{
upgrade_to_electra(&mut state, spec).unwrap();

// Remove intermediate Capella fork from `state.fork`.
// Remove intermediate Deneb fork from `state.fork`.
state.fork_mut().previous_version = spec.electra_fork_version;

post_merge = true;
Expand All @@ -367,8 +381,6 @@ fn initialize_state_with_validators<T: EthSpec>(
if post_merge {
// Override latest execution payload header.
// See https://github.com/ethereum/consensus-specs/blob/v1.1.0/specs/merge/beacon-chain.md#testing

// Currently, we only support starting from a bellatrix state
match state
.latest_execution_payload_header_mut()
.map_err(|e| format!("Failed to get execution payload header: {:?}", e))?
Expand All @@ -387,16 +399,20 @@ fn initialize_state_with_validators<T: EthSpec>(
return Err("Execution payload header must be a capella header".to_string());
}
}
ExecutionPayloadHeaderRefMut::Deneb(header_mut) => {
if let ExecutionPayloadHeader::Deneb(eph) = execution_payload_header {
*header_mut = eph;
} else {
return Err("Execution payload header must be a deneb header".to_string());
}
}
ExecutionPayloadHeaderRefMut::Electra(header_mut) => {
if let ExecutionPayloadHeader::Electra(eph) = execution_payload_header {
*header_mut = eph;
} else {
return Err("Execution payload header must be a electra header".to_string());
}
}
ExecutionPayloadHeaderRefMut::Deneb(_) => {
return Err("Cannot start genesis from a deneb state".to_string())
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions lcli/src/parse_ssz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ pub fn run_parse_ssz<T: EthSpec>(
SignedBeaconBlockElectra::<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)?
}
Expand Down
2 changes: 2 additions & 0 deletions scripts/local_testnet/setup_time.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ get_spec_preset_value() {
SLOT_PER_EPOCH=$(get_spec_preset_value $SPEC_PRESET)
echo "slot_per_epoch=$SLOT_PER_EPOCH"

echo $1

genesis_file=$1

# Update future hardforks time in the EL genesis file based on the CL genesis time
Expand Down
2 changes: 1 addition & 1 deletion scripts/local_testnet/start_local_testnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ echo "executing: ./setup.sh >> $LOG_DIR/setup.log"
./setup.sh >> $LOG_DIR/setup.log 2>&1

# Call setup_time.sh to update future hardforks time in the EL genesis file based on the CL genesis time
./setup_time.sh genesis.json
./setup_time.sh $genesis_file

# Delay to let boot_enr.yaml to be created
execute_command_add_PID bootnode.log ./bootnode.sh
Expand Down
10 changes: 5 additions & 5 deletions scripts/local_testnet/vars.env
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Path to the geth binary
GETH_BINARY=geth
EL_BOOTNODE_BINARY=bootnode
GETH_BINARY=/home/mac/work/execution/go-ethereum/build/bin/geth
EL_BOOTNODE_BINARY=/home/mac/work/execution/go-ethereum/build/bin/bootnode

# Base directories for the validator keys and secrets
DATADIR=~/.lighthouse/local-testnet
Expand Down Expand Up @@ -44,9 +44,9 @@ CHAIN_ID=4242
# Hard fork configuration
ALTAIR_FORK_EPOCH=0
BELLATRIX_FORK_EPOCH=0
CAPELLA_FORK_EPOCH=1
DENEB_FORK_EPOCH=2
ELECTRA_FORK_EPOCH=3
CAPELLA_FORK_EPOCH=0
DENEB_FORK_EPOCH=1
ELECTRA_FORK_EPOCH=999999999

TTD=0

Expand Down

0 comments on commit 80ade56

Please sign in to comment.