mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-30 04:37:13 +00:00
Gloas spec v1.7.0-alpha.5 and beacon_chain tests (#8998)
Fix database pruning post-Gloas - Fix DB pruning logic (and state summaries DAG) - Get the `beacon_chain` tests running with `FORK_NAME=gloas` 🎉 Co-Authored-By: Michael Sproul <michael@sigmaprime.io> Co-Authored-By: Jimmy Chen <jchen.tc@gmail.com> Co-Authored-By: Eitan Seri- Levi <eserilev@gmail.com> Co-Authored-By: dapplion <35266934+dapplion@users.noreply.github.com> Co-Authored-By: Eitan Seri-Levi <eserilev@ucsc.edu>
This commit is contained in:
@@ -19,9 +19,13 @@ use beacon_chain::{
|
||||
custody_context::NodeCustodyType,
|
||||
test_utils::{BeaconChainHarness, EphemeralHarnessType},
|
||||
};
|
||||
use execution_layer::{PayloadStatusV1, json_structures::JsonPayloadStatusV1Status};
|
||||
use execution_layer::{
|
||||
PayloadStatusV1, PayloadStatusV1Status, json_structures::JsonPayloadStatusV1Status,
|
||||
};
|
||||
use serde::Deserialize;
|
||||
use ssz_derive::Decode;
|
||||
use state_processing::VerifySignatures;
|
||||
use state_processing::envelope_processing::verify_execution_payload_envelope;
|
||||
use state_processing::state_advance::complete_state_advance;
|
||||
use std::future::Future;
|
||||
use std::sync::Arc;
|
||||
@@ -995,38 +999,95 @@ impl<E: EthSpec> Tester<E> {
|
||||
valid: bool,
|
||||
) -> Result<(), Error> {
|
||||
let block_root = signed_envelope.message.beacon_block_root;
|
||||
let block_hash = signed_envelope.message.payload.block_hash;
|
||||
let store = &self.harness.chain.store;
|
||||
let spec = &self.harness.chain.spec;
|
||||
|
||||
// Store the envelope in the database so that child blocks extending
|
||||
// the FULL path can load the parent's post-payload state.
|
||||
// Simulate the EL: pre-configure the mock execution engine to return VALID
|
||||
// for envelopes the test expects to be valid. Invalid envelopes are left
|
||||
// unconfigured so the mock EE's default (SYNCING) rejects them.
|
||||
let el = self.harness.mock_execution_layer.as_ref().unwrap();
|
||||
if valid {
|
||||
self.harness
|
||||
.chain
|
||||
.store
|
||||
.put_payload_envelope(&block_root, signed_envelope.clone())
|
||||
el.server.set_new_payload_status(
|
||||
block_hash,
|
||||
PayloadStatusV1 {
|
||||
status: JsonPayloadStatusV1Status::Valid.into(),
|
||||
latest_valid_hash: Some(block_hash),
|
||||
validation_error: None,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// Attempt to verify the envelope against the block's post-state.
|
||||
let verification_result = (|| {
|
||||
let block = store
|
||||
.get_blinded_block(&block_root)
|
||||
.map_err(|e| Error::InternalError(format!("Failed to load block: {e:?}")))?
|
||||
.ok_or_else(|| {
|
||||
Error::InternalError(format!("Block not found for root {block_root:?}"))
|
||||
})?;
|
||||
let block_state_root = block.state_root();
|
||||
|
||||
let state = store
|
||||
.get_hot_state(&block_state_root, CACHE_STATE_IN_TESTS)
|
||||
.map_err(|e| Error::InternalError(format!("Failed to load state: {e:?}")))?
|
||||
.ok_or_else(|| {
|
||||
Error::InternalError(format!("State not found for root {block_state_root:?}"))
|
||||
})?;
|
||||
|
||||
verify_execution_payload_envelope(
|
||||
&state,
|
||||
signed_envelope,
|
||||
VerifySignatures::True,
|
||||
block_state_root,
|
||||
spec,
|
||||
)
|
||||
.map_err(|e| {
|
||||
Error::InternalError(format!("Failed to process execution payload: {e:?}"))
|
||||
})?;
|
||||
|
||||
// Check the mock EE's response for this block hash (simulates newPayload).
|
||||
let ee_valid = el
|
||||
.server
|
||||
.ctx
|
||||
.get_new_payload_status(&block_hash)
|
||||
.and_then(|r| r.ok())
|
||||
.is_some_and(|s| s.status == PayloadStatusV1Status::Valid);
|
||||
if !ee_valid {
|
||||
return Err(Error::InternalError(format!(
|
||||
"Mock EE rejected payload with block hash {block_hash:?}",
|
||||
)));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
})();
|
||||
|
||||
if valid {
|
||||
verification_result?;
|
||||
|
||||
// Store the envelope so that child blocks can load the parent's payload.
|
||||
store
|
||||
.put_payload_envelope(&block_root, signed_envelope)
|
||||
.map_err(|e| {
|
||||
Error::InternalError(format!(
|
||||
"Failed to store payload envelope for {block_root:?}: {e:?}",
|
||||
))
|
||||
})?;
|
||||
}
|
||||
|
||||
let result = self
|
||||
.harness
|
||||
.chain
|
||||
.canonical_head
|
||||
.fork_choice_write_lock()
|
||||
.on_valid_payload_envelope_received(block_root);
|
||||
|
||||
if valid {
|
||||
result.map_err(|e| {
|
||||
Error::InternalError(format!(
|
||||
"on_execution_payload for block root {} failed: {:?}",
|
||||
block_root, e
|
||||
))
|
||||
})?;
|
||||
} else if result.is_ok() {
|
||||
self.harness
|
||||
.chain
|
||||
.canonical_head
|
||||
.fork_choice_write_lock()
|
||||
.on_valid_payload_envelope_received(block_root)
|
||||
.map_err(|e| {
|
||||
Error::InternalError(format!(
|
||||
"on_execution_payload for block root {} failed: {:?}",
|
||||
block_root, e
|
||||
))
|
||||
})?;
|
||||
} else if verification_result.is_ok() {
|
||||
return Err(Error::DidntFail(format!(
|
||||
"on_execution_payload for block root {} should have failed",
|
||||
"on_execution_payload envelope for block root {} should have failed",
|
||||
block_root
|
||||
)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user