mirror of
https://github.com/sigp/lighthouse.git
synced 2026-07-05 05:44:30 +00:00
Gloas alpha spec 9 (#9393)
Changes implemented Ensure bids are for a higher slot than their parent (https://github.com/ethereum/consensus-specs/pull/5302) Ignore PTC attestations for empty assigned slots (https://github.com/ethereum/consensus-specs/pull/5281) Limit should_build_on_full checks to the previous slot (https://github.com/ethereum/consensus-specs/pull/5309) Apply proposer boost if dependent roots match (https://github.com/ethereum/consensus-specs/pull/5306) Exclude slashed validators from proposing (EIP-8045) (https://github.com/ethereum/consensus-specs/pull/5115) Force the proposer to reorg late payloads (https://github.com/ethereum/consensus-specs/pull/5210) Remove support for old deposit mechanism in Fulu (https://github.com/ethereum/consensus-specs/pull/4704) Co-Authored-By: Eitan Seri-Levi <eserilev@ucsc.edu> Co-Authored-By: dapplion <35266934+dapplion@users.noreply.github.com> Co-Authored-By: Eitan Seri-Levi <eserilev@gmail.com> Co-Authored-By: Michael Sproul <michael@sigmaprime.io> Co-Authored-By: Michael Sproul <michaelsproul@users.noreply.github.com>
This commit is contained in:
@@ -3,7 +3,6 @@ use std::time::Duration;
|
||||
|
||||
use bls::Signature;
|
||||
use slot_clock::{SlotClock, TestingSlotClock};
|
||||
use state_processing::AllCaches;
|
||||
use types::{
|
||||
Domain, Epoch, EthSpec, ForkName, Hash256, MinimalEthSpec, PayloadAttestationData,
|
||||
PayloadAttestationMessage, SignedRoot, Slot,
|
||||
@@ -167,6 +166,25 @@ fn unknown_head_block() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn block_not_at_slot() {
|
||||
if !fork_name_from_env().is_some_and(|f| f.gloas_enabled()) {
|
||||
return;
|
||||
}
|
||||
let ctx = TestContext::new();
|
||||
let gossip = ctx.gossip_ctx();
|
||||
|
||||
// The genesis block is at slot 0, but the message claims slot 1. A PTC member assigned to an
|
||||
// empty slot must not attest, so this must be ignored (per consensus-specs #5281).
|
||||
let msg = make_payload_attestation(Slot::new(1), 0, ctx.genesis_block_root);
|
||||
let result = VerifiedPayloadAttestationMessage::new(msg, &gossip);
|
||||
assert!(
|
||||
matches!(result, Err(PayloadAttestationError::BlockNotAtSlot { .. })),
|
||||
"expected BlockNotAtSlot, got: {:?}",
|
||||
result
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_in_ptc() {
|
||||
if !fork_name_from_env().is_some_and(|f| f.gloas_enabled()) {
|
||||
@@ -174,7 +192,7 @@ fn not_in_ptc() {
|
||||
}
|
||||
let ctx = TestContext::new();
|
||||
let gossip = ctx.gossip_ctx();
|
||||
let slot = Slot::new(1);
|
||||
let slot = Slot::new(0);
|
||||
|
||||
let ptc_members = ctx.ptc_members(slot);
|
||||
let non_ptc_validator = (0..NUM_VALIDATORS as u64)
|
||||
@@ -196,7 +214,7 @@ fn invalid_signature() {
|
||||
}
|
||||
let ctx = TestContext::new();
|
||||
let gossip = ctx.gossip_ctx();
|
||||
let slot = Slot::new(1);
|
||||
let slot = Slot::new(0);
|
||||
|
||||
let ptc_members = ctx.ptc_members(slot);
|
||||
let validator_index = ptc_members[0] as u64;
|
||||
@@ -216,7 +234,7 @@ fn valid_payload_attestation() {
|
||||
}
|
||||
let ctx = TestContext::new();
|
||||
let gossip = ctx.gossip_ctx();
|
||||
let slot = Slot::new(1);
|
||||
let slot = Slot::new(0);
|
||||
|
||||
let ptc_members = ctx.ptc_members(slot);
|
||||
let validator_index = ptc_members[0] as u64;
|
||||
@@ -243,7 +261,7 @@ fn duplicate_after_valid() {
|
||||
}
|
||||
let ctx = TestContext::new();
|
||||
let gossip = ctx.gossip_ctx();
|
||||
let slot = Slot::new(1);
|
||||
let slot = Slot::new(0);
|
||||
|
||||
let ptc_members = ctx.ptc_members(slot);
|
||||
let validator_index = ptc_members[0] as u64;
|
||||
@@ -300,10 +318,8 @@ async fn ptc_cache_is_primed_at_gloas_fork_boundary() {
|
||||
.mock_execution_layer()
|
||||
.build();
|
||||
|
||||
harness.extend_to_slot(fork_boundary_slot).await;
|
||||
|
||||
for slot in test_slots {
|
||||
harness.chain.slot_clock.set_slot(slot.as_u64());
|
||||
harness.extend_to_slot(slot).await;
|
||||
assert!(
|
||||
harness
|
||||
.chain
|
||||
@@ -350,10 +366,9 @@ async fn ptc_cache_is_primed_at_gloas_fork_boundary() {
|
||||
}
|
||||
}
|
||||
|
||||
/// Exercises payload attestation gossip verification when the message epoch is ahead of the
|
||||
/// canonical head due to many missed slots.
|
||||
/// Check that a payload attestation whose assigned slot is empty is ignored.
|
||||
#[tokio::test]
|
||||
async fn stale_head_payload_attestation() {
|
||||
async fn stale_head_empty_slot_payload_attestation_ignored() {
|
||||
if !fork_name_from_env().is_some_and(|f| f.gloas_enabled()) {
|
||||
return;
|
||||
}
|
||||
@@ -363,9 +378,9 @@ async fn stale_head_payload_attestation() {
|
||||
let head_slot = Slot::new(slots_per_epoch);
|
||||
let missed_epochs = 4;
|
||||
let target_slot = Slot::new(slots_per_epoch * (1 + missed_epochs));
|
||||
let target_epoch = target_slot.epoch(slots_per_epoch);
|
||||
|
||||
// GIVEN a chain with blocks through epoch 1 (so the store has states).
|
||||
// Given a chain with blocks through epoch 1, then a slot clock advanced 4 epochs without
|
||||
// producing blocks (simulating missed slots).
|
||||
let harness = BeaconChainHarness::builder(E::default())
|
||||
.default_spec()
|
||||
.deterministic_keypairs(64)
|
||||
@@ -373,71 +388,30 @@ async fn stale_head_payload_attestation() {
|
||||
.mock_execution_layer()
|
||||
.build();
|
||||
harness.extend_to_slot(head_slot).await;
|
||||
|
||||
let head = harness.chain.canonical_head.cached_head();
|
||||
let head_epoch = head.snapshot.beacon_state.current_epoch();
|
||||
assert!(
|
||||
target_epoch > head_epoch + harness.spec.min_seed_lookahead,
|
||||
"precondition: message epoch must exceed head + min_seed_lookahead"
|
||||
);
|
||||
|
||||
// GIVEN a slot clock advanced to epoch 5 without producing blocks
|
||||
// (simulating missed slots during a liveness failure).
|
||||
harness.chain.slot_clock.set_slot(target_slot.as_u64());
|
||||
|
||||
// Advance a reference state to compute the PTC at the target slot.
|
||||
let mut reference_state = head.snapshot.beacon_state.clone();
|
||||
state_processing::state_advance::partial_state_advance(
|
||||
&mut reference_state,
|
||||
Some(head.snapshot.beacon_state_root()),
|
||||
target_slot,
|
||||
&harness.spec,
|
||||
)
|
||||
.expect("should advance reference state");
|
||||
reference_state
|
||||
.build_all_caches(&harness.spec)
|
||||
.expect("should build caches");
|
||||
let head = harness.chain.canonical_head.cached_head();
|
||||
|
||||
let ptc = reference_state
|
||||
.get_ptc(target_slot, &harness.spec)
|
||||
.expect("should get PTC from reference state");
|
||||
let validator_index = *ptc.0.first().expect("PTC should have at least one member") as u64;
|
||||
|
||||
// WHEN a properly-signed payload attestation from a PTC member is verified. The signature
|
||||
// domain should come from the spec fork schedule and genesis validators root, not a loaded
|
||||
// state in the verifier.
|
||||
let domain = harness.spec.get_domain(
|
||||
target_epoch,
|
||||
Domain::PTCAttester,
|
||||
&reference_state.fork(),
|
||||
reference_state.genesis_validators_root(),
|
||||
);
|
||||
// When a payload attestation for empty target slot references a stale block root
|
||||
// it is ignored because target_slot != block.slot
|
||||
let data = PayloadAttestationData {
|
||||
beacon_block_root: head.head_block_root(),
|
||||
slot: target_slot,
|
||||
payload_present: true,
|
||||
blob_data_available: true,
|
||||
};
|
||||
let message = data.signing_root(domain);
|
||||
let signature = harness.validator_keypairs[validator_index as usize]
|
||||
.sk
|
||||
.sign(message);
|
||||
let msg = PayloadAttestationMessage {
|
||||
validator_index,
|
||||
validator_index: 0,
|
||||
data,
|
||||
signature,
|
||||
signature: Signature::empty(),
|
||||
};
|
||||
|
||||
// THEN verification succeeds despite the head being 4 epochs stale.
|
||||
let result = harness
|
||||
.chain
|
||||
.verify_payload_attestation_message_for_gossip(msg);
|
||||
assert!(
|
||||
result.is_ok(),
|
||||
"expected Ok (head epoch {}, message epoch {}), got: {:?}",
|
||||
head_epoch,
|
||||
target_epoch,
|
||||
result.unwrap_err()
|
||||
matches!(result, Err(PayloadAttestationError::BlockNotAtSlot { .. })),
|
||||
"expected BlockNotAtSlot, got: {result:?}"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user