mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-20 05:14:35 +00:00
Merge branch 'unstable' into electra-alpha7
This commit is contained in:
@@ -25,6 +25,8 @@ excluded_paths = [
|
||||
# Intentionally omitted, as per https://github.com/sigp/lighthouse/issues/1835
|
||||
"tests/.*/.*/ssz_static/Eth1Block/",
|
||||
"tests/.*/.*/ssz_static/PowBlock/",
|
||||
# We no longer implement merge logic.
|
||||
"tests/.*/bellatrix/fork_choice/on_merge_block",
|
||||
# light_client
|
||||
"tests/.*/.*/light_client/single_merkle_proof",
|
||||
"tests/.*/.*/light_client/sync",
|
||||
@@ -46,11 +48,6 @@ excluded_paths = [
|
||||
"tests/.*/eip6110",
|
||||
"tests/.*/whisk",
|
||||
"tests/.*/eip7594",
|
||||
# TODO(electra) re-enable once https://github.com/sigp/lighthouse/issues/6002 is resolved
|
||||
"tests/.*/electra/ssz_static/LightClientUpdate",
|
||||
"tests/.*/electra/ssz_static/LightClientFinalityUpdate",
|
||||
"tests/.*/electra/ssz_static/LightClientBootstrap",
|
||||
"tests/.*/electra/merkle_proof",
|
||||
]
|
||||
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@ use crate::decode::{ssz_decode_file, ssz_decode_state, yaml_decode_file};
|
||||
use serde::Deserialize;
|
||||
use tree_hash::Hash256;
|
||||
use types::{
|
||||
BeaconBlockBody, BeaconBlockBodyDeneb, BeaconBlockBodyElectra, BeaconState, FixedVector,
|
||||
FullPayload, Unsigned,
|
||||
light_client_update, BeaconBlockBody, BeaconBlockBodyCapella, BeaconBlockBodyDeneb,
|
||||
BeaconBlockBodyElectra, BeaconState, FixedVector, FullPayload, Unsigned,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
@@ -22,13 +22,13 @@ pub struct MerkleProof {
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
#[serde(bound = "E: EthSpec")]
|
||||
pub struct MerkleProofValidity<E: EthSpec> {
|
||||
pub struct BeaconStateMerkleProofValidity<E: EthSpec> {
|
||||
pub metadata: Option<Metadata>,
|
||||
pub state: BeaconState<E>,
|
||||
pub merkle_proof: MerkleProof,
|
||||
}
|
||||
|
||||
impl<E: EthSpec> LoadCase for MerkleProofValidity<E> {
|
||||
impl<E: EthSpec> LoadCase for BeaconStateMerkleProofValidity<E> {
|
||||
fn load_from_dir(path: &Path, fork_name: ForkName) -> Result<Self, Error> {
|
||||
let spec = &testing_spec::<E>(fork_name);
|
||||
let state = ssz_decode_state(&path.join("object.ssz_snappy"), spec)?;
|
||||
@@ -49,11 +49,30 @@ impl<E: EthSpec> LoadCase for MerkleProofValidity<E> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: EthSpec> Case for MerkleProofValidity<E> {
|
||||
impl<E: EthSpec> Case for BeaconStateMerkleProofValidity<E> {
|
||||
fn result(&self, _case_index: usize, _fork_name: ForkName) -> Result<(), Error> {
|
||||
let mut state = self.state.clone();
|
||||
state.update_tree_hash_cache().unwrap();
|
||||
let Ok(proof) = state.compute_merkle_proof(self.merkle_proof.leaf_index) else {
|
||||
|
||||
let proof = match self.merkle_proof.leaf_index {
|
||||
light_client_update::CURRENT_SYNC_COMMITTEE_INDEX_ELECTRA
|
||||
| light_client_update::CURRENT_SYNC_COMMITTEE_INDEX => {
|
||||
state.compute_current_sync_committee_proof()
|
||||
}
|
||||
light_client_update::NEXT_SYNC_COMMITTEE_INDEX_ELECTRA
|
||||
| light_client_update::NEXT_SYNC_COMMITTEE_INDEX => {
|
||||
state.compute_next_sync_committee_proof()
|
||||
}
|
||||
light_client_update::FINALIZED_ROOT_INDEX_ELECTRA
|
||||
| light_client_update::FINALIZED_ROOT_INDEX => state.compute_finalized_root_proof(),
|
||||
_ => {
|
||||
return Err(Error::FailedToParseTest(
|
||||
"Could not retrieve merkle proof, invalid index".to_string(),
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
let Ok(proof) = proof else {
|
||||
return Err(Error::FailedToParseTest(
|
||||
"Could not retrieve merkle proof".to_string(),
|
||||
));
|
||||
@@ -198,3 +217,81 @@ impl<E: EthSpec> Case for KzgInclusionMerkleProofValidity<E> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
#[serde(bound = "E: EthSpec")]
|
||||
pub struct BeaconBlockBodyMerkleProofValidity<E: EthSpec> {
|
||||
pub metadata: Option<Metadata>,
|
||||
pub block_body: BeaconBlockBody<E, FullPayload<E>>,
|
||||
pub merkle_proof: MerkleProof,
|
||||
}
|
||||
|
||||
impl<E: EthSpec> LoadCase for BeaconBlockBodyMerkleProofValidity<E> {
|
||||
fn load_from_dir(path: &Path, fork_name: ForkName) -> Result<Self, Error> {
|
||||
let block_body: BeaconBlockBody<E, FullPayload<E>> = match fork_name {
|
||||
ForkName::Base | ForkName::Altair | ForkName::Bellatrix => {
|
||||
return Err(Error::InternalError(format!(
|
||||
"Beacon block body merkle proof validity test skipped for {:?}",
|
||||
fork_name
|
||||
)))
|
||||
}
|
||||
ForkName::Capella => {
|
||||
ssz_decode_file::<BeaconBlockBodyCapella<E>>(&path.join("object.ssz_snappy"))?
|
||||
.into()
|
||||
}
|
||||
ForkName::Deneb => {
|
||||
ssz_decode_file::<BeaconBlockBodyDeneb<E>>(&path.join("object.ssz_snappy"))?.into()
|
||||
}
|
||||
ForkName::Electra => {
|
||||
ssz_decode_file::<BeaconBlockBodyElectra<E>>(&path.join("object.ssz_snappy"))?
|
||||
.into()
|
||||
}
|
||||
};
|
||||
let merkle_proof = yaml_decode_file(&path.join("proof.yaml"))?;
|
||||
// Metadata does not exist in these tests but it is left like this just in case.
|
||||
let meta_path = path.join("meta.yaml");
|
||||
let metadata = if meta_path.exists() {
|
||||
Some(yaml_decode_file(&meta_path)?)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
Ok(Self {
|
||||
metadata,
|
||||
block_body,
|
||||
merkle_proof,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: EthSpec> Case for BeaconBlockBodyMerkleProofValidity<E> {
|
||||
fn result(&self, _case_index: usize, _fork_name: ForkName) -> Result<(), Error> {
|
||||
let binding = self.block_body.clone();
|
||||
let block_body = binding.to_ref();
|
||||
let Ok(proof) = block_body.block_body_merkle_proof(self.merkle_proof.leaf_index) else {
|
||||
return Err(Error::FailedToParseTest(
|
||||
"Could not retrieve merkle proof".to_string(),
|
||||
));
|
||||
};
|
||||
let proof_len = proof.len();
|
||||
let branch_len = self.merkle_proof.branch.len();
|
||||
if proof_len != branch_len {
|
||||
return Err(Error::NotEqual(format!(
|
||||
"Branches not equal in length computed: {}, expected {}",
|
||||
proof_len, branch_len
|
||||
)));
|
||||
}
|
||||
|
||||
for (i, proof_leaf) in proof.iter().enumerate().take(proof_len) {
|
||||
let expected_leaf = self.merkle_proof.branch[i];
|
||||
if *proof_leaf != expected_leaf {
|
||||
return Err(Error::NotEqual(format!(
|
||||
"Leaves not equal in merke proof computed: {}, expected: {}",
|
||||
hex::encode(proof_leaf),
|
||||
hex::encode(expected_leaf)
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -627,8 +627,8 @@ impl<E: EthSpec + TypeName> Handler for ForkChoiceHandler<E> {
|
||||
}
|
||||
|
||||
fn is_enabled_for_fork(&self, fork_name: ForkName) -> bool {
|
||||
// Merge block tests are only enabled for Bellatrix.
|
||||
if self.handler_name == "on_merge_block" && fork_name != ForkName::Bellatrix {
|
||||
// We no longer run on_merge_block tests since removing merge support.
|
||||
if self.handler_name == "on_merge_block" {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -921,10 +921,10 @@ impl<E: EthSpec> Handler for KZGRecoverCellsAndKZGProofHandler<E> {
|
||||
|
||||
#[derive(Derivative)]
|
||||
#[derivative(Default(bound = ""))]
|
||||
pub struct MerkleProofValidityHandler<E>(PhantomData<E>);
|
||||
pub struct BeaconStateMerkleProofValidityHandler<E>(PhantomData<E>);
|
||||
|
||||
impl<E: EthSpec + TypeName> Handler for MerkleProofValidityHandler<E> {
|
||||
type Case = cases::MerkleProofValidity<E>;
|
||||
impl<E: EthSpec + TypeName> Handler for BeaconStateMerkleProofValidityHandler<E> {
|
||||
type Case = cases::BeaconStateMerkleProofValidity<E>;
|
||||
|
||||
fn config_name() -> &'static str {
|
||||
E::name()
|
||||
@@ -935,15 +935,11 @@ impl<E: EthSpec + TypeName> Handler for MerkleProofValidityHandler<E> {
|
||||
}
|
||||
|
||||
fn handler_name(&self) -> String {
|
||||
"single_merkle_proof".into()
|
||||
"single_merkle_proof/BeaconState".into()
|
||||
}
|
||||
|
||||
fn is_enabled_for_fork(&self, _fork_name: ForkName) -> bool {
|
||||
// Test is skipped due to some changes in the Capella light client
|
||||
// spec.
|
||||
//
|
||||
// https://github.com/sigp/lighthouse/issues/4022
|
||||
false
|
||||
fn is_enabled_for_fork(&self, fork_name: ForkName) -> bool {
|
||||
fork_name.altair_enabled()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -967,8 +963,32 @@ impl<E: EthSpec + TypeName> Handler for KzgInclusionMerkleProofValidityHandler<E
|
||||
}
|
||||
|
||||
fn is_enabled_for_fork(&self, fork_name: ForkName) -> bool {
|
||||
// TODO(electra) re-enable for electra once merkle proof issues for electra are resolved
|
||||
fork_name.deneb_enabled() && !fork_name.electra_enabled()
|
||||
// Enabled in Deneb
|
||||
fork_name.deneb_enabled()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Derivative)]
|
||||
#[derivative(Default(bound = ""))]
|
||||
pub struct BeaconBlockBodyMerkleProofValidityHandler<E>(PhantomData<E>);
|
||||
|
||||
impl<E: EthSpec + TypeName> Handler for BeaconBlockBodyMerkleProofValidityHandler<E> {
|
||||
type Case = cases::BeaconBlockBodyMerkleProofValidity<E>;
|
||||
|
||||
fn config_name() -> &'static str {
|
||||
E::name()
|
||||
}
|
||||
|
||||
fn runner_name() -> &'static str {
|
||||
"light_client"
|
||||
}
|
||||
|
||||
fn handler_name(&self) -> String {
|
||||
"single_merkle_proof/BeaconBlockBody".into()
|
||||
}
|
||||
|
||||
fn is_enabled_for_fork(&self, fork_name: ForkName) -> bool {
|
||||
fork_name.capella_enabled()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -993,8 +1013,7 @@ impl<E: EthSpec + TypeName> Handler for LightClientUpdateHandler<E> {
|
||||
|
||||
fn is_enabled_for_fork(&self, fork_name: ForkName) -> bool {
|
||||
// Enabled in Altair
|
||||
// TODO(electra) re-enable once https://github.com/sigp/lighthouse/issues/6002 is resolved
|
||||
fork_name.altair_enabled() && fork_name != ForkName::Electra
|
||||
fork_name.altair_enabled()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -395,11 +395,10 @@ mod ssz_static {
|
||||
.run();
|
||||
SszStaticHandler::<LightClientBootstrapDeneb<MainnetEthSpec>, MainnetEthSpec>::deneb_only()
|
||||
.run();
|
||||
// TODO(electra) re-enable once https://github.com/sigp/lighthouse/issues/6002 is resolved
|
||||
// SszStaticHandler::<LightClientBootstrapElectra<MinimalEthSpec>, MinimalEthSpec>::electra_only()
|
||||
// .run();
|
||||
// SszStaticHandler::<LightClientBootstrapElectra<MainnetEthSpec>, MainnetEthSpec>::electra_only()
|
||||
// .run();
|
||||
SszStaticHandler::<LightClientBootstrapElectra<MinimalEthSpec>, MinimalEthSpec>::electra_only()
|
||||
.run();
|
||||
SszStaticHandler::<LightClientBootstrapElectra<MainnetEthSpec>, MainnetEthSpec>::electra_only()
|
||||
.run();
|
||||
}
|
||||
|
||||
// LightClientHeader has no internal indicator of which fork it is for, so we test it separately.
|
||||
@@ -475,13 +474,12 @@ mod ssz_static {
|
||||
SszStaticHandler::<LightClientFinalityUpdateDeneb<MainnetEthSpec>, MainnetEthSpec>::deneb_only(
|
||||
)
|
||||
.run();
|
||||
// TODO(electra) re-enable once https://github.com/sigp/lighthouse/issues/6002 is resolved
|
||||
// SszStaticHandler::<LightClientFinalityUpdateElectra<MinimalEthSpec>, MinimalEthSpec>::electra_only(
|
||||
// )
|
||||
// .run();
|
||||
// SszStaticHandler::<LightClientFinalityUpdateElectra<MainnetEthSpec>, MainnetEthSpec>::electra_only(
|
||||
// )
|
||||
// .run();
|
||||
SszStaticHandler::<LightClientFinalityUpdateElectra<MinimalEthSpec>, MinimalEthSpec>::electra_only(
|
||||
)
|
||||
.run();
|
||||
SszStaticHandler::<LightClientFinalityUpdateElectra<MainnetEthSpec>, MainnetEthSpec>::electra_only(
|
||||
)
|
||||
.run();
|
||||
}
|
||||
|
||||
// LightClientUpdate has no internal indicator of which fork it is for, so we test it separately.
|
||||
@@ -505,13 +503,12 @@ mod ssz_static {
|
||||
.run();
|
||||
SszStaticHandler::<LightClientUpdateDeneb<MainnetEthSpec>, MainnetEthSpec>::deneb_only()
|
||||
.run();
|
||||
// TODO(electra) re-enable once https://github.com/sigp/lighthouse/issues/6002 is resolved
|
||||
// SszStaticHandler::<LightClientUpdateElectra<MinimalEthSpec>, MinimalEthSpec>::electra_only(
|
||||
// )
|
||||
// .run();
|
||||
// SszStaticHandler::<LightClientUpdateElectra<MainnetEthSpec>, MainnetEthSpec>::electra_only(
|
||||
// )
|
||||
// .run();
|
||||
SszStaticHandler::<LightClientUpdateElectra<MinimalEthSpec>, MinimalEthSpec>::electra_only(
|
||||
)
|
||||
.run();
|
||||
SszStaticHandler::<LightClientUpdateElectra<MainnetEthSpec>, MainnetEthSpec>::electra_only(
|
||||
)
|
||||
.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -825,12 +822,6 @@ fn fork_choice_on_block() {
|
||||
ForkChoiceHandler::<MainnetEthSpec>::new("on_block").run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fork_choice_on_merge_block() {
|
||||
ForkChoiceHandler::<MinimalEthSpec>::new("on_merge_block").run();
|
||||
ForkChoiceHandler::<MainnetEthSpec>::new("on_merge_block").run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fork_choice_ex_ante() {
|
||||
ForkChoiceHandler::<MinimalEthSpec>::new("ex_ante").run();
|
||||
@@ -927,8 +918,13 @@ fn kzg_recover_cells_and_proofs() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn merkle_proof_validity() {
|
||||
MerkleProofValidityHandler::<MainnetEthSpec>::default().run();
|
||||
fn beacon_state_merkle_proof_validity() {
|
||||
BeaconStateMerkleProofValidityHandler::<MainnetEthSpec>::default().run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn beacon_block_body_merkle_proof_validity() {
|
||||
BeaconBlockBodyMerkleProofValidityHandler::<MainnetEthSpec>::default().run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user