Merge branch 'unstable' into vc-fallback

This commit is contained in:
Mac L
2024-06-27 19:28:26 +04:00
246 changed files with 7124 additions and 2866 deletions

View File

@@ -42,7 +42,9 @@ excluded_paths = [
"bls12-381-tests/deserialization_G2",
"bls12-381-tests/hash_to_G2",
"tests/.*/eip6110",
"tests/.*/whisk"
"tests/.*/whisk",
# TODO(electra): re-enable in https://github.com/sigp/lighthouse/pull/5758
"tests/.*/.*/ssz_static/IndexedAttestation"
]

View File

@@ -24,9 +24,9 @@ use std::future::Future;
use std::sync::Arc;
use std::time::Duration;
use types::{
Attestation, AttesterSlashing, BeaconBlock, BeaconState, BlobSidecar, BlobsList,
BlockImportSource, Checkpoint, ExecutionBlockHash, Hash256, IndexedAttestation, KzgProof,
ProposerPreparationData, SignedBeaconBlock, Slot, Uint256,
Attestation, AttestationRef, AttesterSlashing, AttesterSlashingRef, BeaconBlock, BeaconState,
BlobSidecar, BlobsList, BlockImportSource, Checkpoint, ExecutionBlockHash, Hash256,
IndexedAttestation, KzgProof, ProposerPreparationData, SignedBeaconBlock, Slot, Uint256,
};
#[derive(Default, Debug, PartialEq, Clone, Deserialize, Decode)]
@@ -180,12 +180,32 @@ impl<E: EthSpec> LoadCase for ForkChoiceTest<E> {
})
}
Step::Attestation { attestation } => {
ssz_decode_file(&path.join(format!("{}.ssz_snappy", attestation)))
.map(|attestation| Step::Attestation { attestation })
if fork_name.electra_enabled() {
ssz_decode_file(&path.join(format!("{}.ssz_snappy", attestation))).map(
|attestation| Step::Attestation {
attestation: Attestation::Electra(attestation),
},
)
} else {
ssz_decode_file(&path.join(format!("{}.ssz_snappy", attestation))).map(
|attestation| Step::Attestation {
attestation: Attestation::Base(attestation),
},
)
}
}
Step::AttesterSlashing { attester_slashing } => {
ssz_decode_file(&path.join(format!("{}.ssz_snappy", attester_slashing)))
.map(|attester_slashing| Step::AttesterSlashing { attester_slashing })
if fork_name.electra_enabled() {
ssz_decode_file(&path.join(format!("{}.ssz_snappy", attester_slashing)))
.map(|attester_slashing| Step::AttesterSlashing {
attester_slashing: AttesterSlashing::Electra(attester_slashing),
})
} else {
ssz_decode_file(&path.join(format!("{}.ssz_snappy", attester_slashing)))
.map(|attester_slashing| Step::AttesterSlashing {
attester_slashing: AttesterSlashing::Base(attester_slashing),
})
}
}
Step::PowBlock { pow_block } => {
ssz_decode_file(&path.join(format!("{}.ssz_snappy", pow_block)))
@@ -249,7 +269,7 @@ impl<E: EthSpec> Case for ForkChoiceTest<E> {
} => tester.process_block(block.clone(), blobs.clone(), proofs.clone(), *valid)?,
Step::Attestation { attestation } => tester.process_attestation(attestation)?,
Step::AttesterSlashing { attester_slashing } => {
tester.process_attester_slashing(attester_slashing)
tester.process_attester_slashing(attester_slashing.to_ref())
}
Step::PowBlock { pow_block } => tester.process_pow_block(pow_block),
Step::OnPayloadInfo {
@@ -575,11 +595,11 @@ impl<E: EthSpec> Tester<E> {
}
pub fn process_attestation(&self, attestation: &Attestation<E>) -> Result<(), Error> {
let (indexed_attestation, _) =
obtain_indexed_attestation_and_committees_per_slot(&self.harness.chain, attestation)
.map_err(|e| {
Error::InternalError(format!("attestation indexing failed with {:?}", e))
})?;
let (indexed_attestation, _) = obtain_indexed_attestation_and_committees_per_slot(
&self.harness.chain,
attestation.to_ref(),
)
.map_err(|e| Error::InternalError(format!("attestation indexing failed with {:?}", e)))?;
let verified_attestation: ManuallyVerifiedAttestation<EphemeralHarnessType<E>> =
ManuallyVerifiedAttestation {
attestation,
@@ -592,7 +612,7 @@ impl<E: EthSpec> Tester<E> {
.map_err(|e| Error::InternalError(format!("attestation import failed with {:?}", e)))
}
pub fn process_attester_slashing(&self, attester_slashing: &AttesterSlashing<E>) {
pub fn process_attester_slashing(&self, attester_slashing: AttesterSlashingRef<E>) {
self.harness
.chain
.canonical_head
@@ -851,8 +871,8 @@ pub struct ManuallyVerifiedAttestation<'a, T: BeaconChainTypes> {
}
impl<'a, T: BeaconChainTypes> VerifiedAttestation<T> for ManuallyVerifiedAttestation<'a, T> {
fn attestation(&self) -> &Attestation<T::EthSpec> {
self.attestation
fn attestation(&self) -> AttestationRef<T::EthSpec> {
self.attestation.to_ref()
}
fn indexed_attestation(&self) -> &IndexedAttestation<T::EthSpec> {

View File

@@ -78,8 +78,12 @@ impl<E: EthSpec> Operation<E> for Attestation<E> {
"attestation".into()
}
fn decode(path: &Path, _fork_name: ForkName, _spec: &ChainSpec) -> Result<Self, Error> {
ssz_decode_file(path)
fn decode(path: &Path, fork_name: ForkName, _spec: &ChainSpec) -> Result<Self, Error> {
if fork_name < ForkName::Electra {
Ok(Self::Base(ssz_decode_file(path)?))
} else {
Ok(Self::Electra(ssz_decode_file(path)?))
}
}
fn apply_to(
@@ -93,7 +97,7 @@ impl<E: EthSpec> Operation<E> for Attestation<E> {
match state {
BeaconState::Base(_) => base::process_attestations(
state,
&[self.clone()],
[self.clone().to_ref()].into_iter(),
VerifySignatures::True,
&mut ctxt,
spec,
@@ -106,7 +110,7 @@ impl<E: EthSpec> Operation<E> for Attestation<E> {
initialize_progressive_balances_cache(state, spec)?;
altair_deneb::process_attestation(
state,
self,
self.to_ref(),
0,
&mut ctxt,
VerifySignatures::True,
@@ -122,8 +126,15 @@ impl<E: EthSpec> Operation<E> for AttesterSlashing<E> {
"attester_slashing".into()
}
fn decode(path: &Path, _fork_name: ForkName, _spec: &ChainSpec) -> Result<Self, Error> {
ssz_decode_file(path)
fn decode(path: &Path, fork_name: ForkName, _spec: &ChainSpec) -> Result<Self, Error> {
Ok(match fork_name {
ForkName::Base
| ForkName::Altair
| ForkName::Bellatrix
| ForkName::Capella
| ForkName::Deneb => Self::Base(ssz_decode_file(path)?),
ForkName::Electra => Self::Electra(ssz_decode_file(path)?),
})
}
fn apply_to(
@@ -136,7 +147,7 @@ impl<E: EthSpec> Operation<E> for AttesterSlashing<E> {
initialize_progressive_balances_cache(state, spec)?;
process_attester_slashings(
state,
&[self.clone()],
[self.clone().to_ref()].into_iter(),
VerifySignatures::True,
&mut ctxt,
spec,

View File

@@ -229,6 +229,10 @@ impl<T, E> SszStaticHandler<T, E> {
Self::for_forks(vec![ForkName::Deneb])
}
pub fn electra_only() -> Self {
Self::for_forks(vec![ForkName::Electra])
}
pub fn altair_and_later() -> Self {
Self::for_forks(ForkName::list_all()[1..].to_vec())
}
@@ -240,6 +244,10 @@ impl<T, E> SszStaticHandler<T, E> {
pub fn capella_and_later() -> Self {
Self::for_forks(ForkName::list_all()[3..].to_vec())
}
pub fn pre_electra() -> Self {
Self::for_forks(ForkName::list_all()[0..5].to_vec())
}
}
/// Handler for SSZ types that implement `CachedTreeHash`.

View File

@@ -37,11 +37,16 @@ macro_rules! type_name_generic {
type_name!(MinimalEthSpec, "minimal");
type_name!(MainnetEthSpec, "mainnet");
type_name_generic!(AggregateAndProof);
type_name_generic!(AggregateAndProofBase, "AggregateAndProof");
type_name_generic!(AggregateAndProofElectra, "AggregateAndProof");
type_name_generic!(Attestation);
type_name_generic!(AttestationBase, "Attestation");
type_name_generic!(AttestationElectra, "Attestation");
type_name!(AttestationData);
type_name_generic!(AttesterSlashing);
type_name_generic!(AttesterSlashingBase, "AttesterSlashing");
type_name_generic!(AttesterSlashingElectra, "AttesterSlashing");
type_name_generic!(BeaconBlock);
type_name_generic!(BeaconBlockBody);
type_name_generic!(BeaconBlockBodyBase, "BeaconBlockBody");
@@ -73,6 +78,8 @@ type_name!(Fork);
type_name!(ForkData);
type_name_generic!(HistoricalBatch);
type_name_generic!(IndexedAttestation);
type_name_generic!(IndexedAttestationBase, "IndexedAttestation");
type_name_generic!(IndexedAttestationElectra, "IndexedAttestation");
type_name_generic!(LightClientBootstrap);
type_name_generic!(LightClientBootstrapAltair, "LightClientBootstrap");
type_name_generic!(LightClientBootstrapCapella, "LightClientBootstrap");
@@ -108,6 +115,8 @@ type_name_generic!(LightClientUpdateDeneb, "LightClientUpdate");
type_name_generic!(PendingAttestation);
type_name!(ProposerSlashing);
type_name_generic!(SignedAggregateAndProof);
type_name_generic!(SignedAggregateAndProofBase, "SignedAggregateAndProof");
type_name_generic!(SignedAggregateAndProofElectra, "SignedAggregateAndProof");
type_name_generic!(SignedBeaconBlock);
type_name!(SignedBeaconBlockHeader);
type_name_generic!(SignedContributionAndProof);

View File

@@ -217,12 +217,9 @@ mod ssz_static {
use ef_tests::{Handler, SszStaticHandler, SszStaticTHCHandler, SszStaticWithSpecHandler};
use types::blob_sidecar::BlobIdentifier;
use types::historical_summary::HistoricalSummary;
use types::{LightClientBootstrapAltair, *};
use types::{AttesterSlashingBase, AttesterSlashingElectra, LightClientBootstrapAltair, *};
ssz_static_test!(aggregate_and_proof, AggregateAndProof<_>);
ssz_static_test!(attestation, Attestation<_>);
ssz_static_test!(attestation_data, AttestationData);
ssz_static_test!(attester_slashing, AttesterSlashing<_>);
ssz_static_test!(beacon_block, SszStaticWithSpecHandler, BeaconBlock<_>);
ssz_static_test!(beacon_block_header, BeaconBlockHeader);
ssz_static_test!(beacon_state, SszStaticTHCHandler, BeaconState<_>);
@@ -235,10 +232,8 @@ mod ssz_static {
ssz_static_test!(fork, Fork);
ssz_static_test!(fork_data, ForkData);
ssz_static_test!(historical_batch, HistoricalBatch<_>);
ssz_static_test!(indexed_attestation, IndexedAttestation<_>);
ssz_static_test!(pending_attestation, PendingAttestation<_>);
ssz_static_test!(proposer_slashing, ProposerSlashing);
ssz_static_test!(signed_aggregate_and_proof, SignedAggregateAndProof<_>);
ssz_static_test!(
signed_beacon_block,
SszStaticWithSpecHandler,
@@ -249,6 +244,59 @@ mod ssz_static {
ssz_static_test!(signing_data, SigningData);
ssz_static_test!(validator, Validator);
ssz_static_test!(voluntary_exit, VoluntaryExit);
#[test]
fn attestation() {
SszStaticHandler::<AttestationBase<MinimalEthSpec>, MinimalEthSpec>::pre_electra().run();
SszStaticHandler::<AttestationBase<MainnetEthSpec>, MainnetEthSpec>::pre_electra().run();
SszStaticHandler::<AttestationElectra<MinimalEthSpec>, MinimalEthSpec>::electra_only()
.run();
SszStaticHandler::<AttestationElectra<MainnetEthSpec>, MainnetEthSpec>::electra_only()
.run();
}
#[test]
fn attester_slashing() {
SszStaticHandler::<AttesterSlashingBase<MinimalEthSpec>, MinimalEthSpec>::pre_electra()
.run();
SszStaticHandler::<AttesterSlashingBase<MainnetEthSpec>, MainnetEthSpec>::pre_electra()
.run();
SszStaticHandler::<AttesterSlashingElectra<MinimalEthSpec>, MinimalEthSpec>::electra_only()
.run();
SszStaticHandler::<AttesterSlashingElectra<MainnetEthSpec>, MainnetEthSpec>::electra_only()
.run();
}
#[test]
fn signed_aggregate_and_proof() {
SszStaticHandler::<SignedAggregateAndProofBase<MinimalEthSpec>, MinimalEthSpec>::pre_electra(
)
.run();
SszStaticHandler::<SignedAggregateAndProofBase<MainnetEthSpec>, MainnetEthSpec>::pre_electra(
)
.run();
SszStaticHandler::<SignedAggregateAndProofElectra<MinimalEthSpec>, MinimalEthSpec>::electra_only(
)
.run();
SszStaticHandler::<SignedAggregateAndProofElectra<MainnetEthSpec>, MainnetEthSpec>::electra_only(
)
.run();
}
#[test]
fn aggregate_and_proof() {
SszStaticHandler::<AggregateAndProofBase<MinimalEthSpec>, MinimalEthSpec>::pre_electra()
.run();
SszStaticHandler::<AggregateAndProofBase<MainnetEthSpec>, MainnetEthSpec>::pre_electra()
.run();
SszStaticHandler::<AggregateAndProofElectra<MinimalEthSpec>, MinimalEthSpec>::electra_only(
)
.run();
SszStaticHandler::<AggregateAndProofElectra<MainnetEthSpec>, MainnetEthSpec>::electra_only(
)
.run();
}
// BeaconBlockBody has no internal indicator of which fork it is for, so we test it separately.
#[test]
fn beacon_block_body() {

View File

@@ -11,7 +11,7 @@ use unused_port::unused_tcp4_port;
/// We've pinned the Nethermind version since our method of using the `master` branch to
/// find the latest tag isn't working. It appears Nethermind don't always tag on `master`.
/// We should fix this so we always pull the latest version of Nethermind.
const NETHERMIND_BRANCH: &str = "release/1.21.0";
const NETHERMIND_BRANCH: &str = "release/1.27.0";
const NETHERMIND_REPO_URL: &str = "https://github.com/NethermindEth/nethermind";
fn build_result(repo_dir: &Path) -> Output {
@@ -70,11 +70,10 @@ impl NethermindEngine {
.join("nethermind")
.join("src")
.join("Nethermind")
.join("Nethermind.Runner")
.join("artifacts")
.join("bin")
.join("Release")
.join("net7.0")
.join("linux-x64")
.join("Nethermind.Runner")
.join("release")
.join("nethermind")
}
}

View File

@@ -10,9 +10,6 @@
//! simulation uses `println` to communicate some info. It might be nice if the nodes logged to
//! easy-to-find files and stdout only contained info from the simulation.
//!
extern crate clap;
mod basic_sim;
mod checks;
mod cli;

View File

@@ -39,7 +39,7 @@ mod tests {
use tempfile::{tempdir, TempDir};
use tokio::sync::OnceCell;
use tokio::time::sleep;
use types::*;
use types::{attestation::AttestationBase, *};
use url::Url;
use validator_client::{
initialized_validators::{
@@ -542,7 +542,7 @@ mod tests {
/// Get a generic, arbitrary attestation for signing.
fn get_attestation() -> Attestation<E> {
Attestation {
Attestation::Base(AttestationBase {
aggregation_bits: BitList::with_capacity(1).unwrap(),
data: AttestationData {
slot: <_>::default(),
@@ -558,7 +558,7 @@ mod tests {
},
},
signature: AggregateSignature::empty(),
}
})
}
fn get_validator_registration(pubkey: PublicKeyBytes) -> ValidatorRegistrationData {
@@ -778,28 +778,28 @@ mod tests {
let first_attestation = || {
let mut attestation = get_attestation();
attestation.data.source.epoch = Epoch::new(1);
attestation.data.target.epoch = Epoch::new(4);
attestation.data_mut().source.epoch = Epoch::new(1);
attestation.data_mut().target.epoch = Epoch::new(4);
attestation
};
let double_vote_attestation = || {
let mut attestation = first_attestation();
attestation.data.beacon_block_root = Hash256::from_low_u64_be(1);
attestation.data_mut().beacon_block_root = Hash256::from_low_u64_be(1);
attestation
};
let surrounding_attestation = || {
let mut attestation = first_attestation();
attestation.data.source.epoch = Epoch::new(0);
attestation.data.target.epoch = Epoch::new(5);
attestation.data_mut().source.epoch = Epoch::new(0);
attestation.data_mut().target.epoch = Epoch::new(5);
attestation
};
let surrounded_attestation = || {
let mut attestation = first_attestation();
attestation.data.source.epoch = Epoch::new(2);
attestation.data.target.epoch = Epoch::new(3);
attestation.data_mut().source.epoch = Epoch::new(2);
attestation.data_mut().target.epoch = Epoch::new(3);
attestation
};