mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-20 22:38:34 +00:00
Retrospective invalidation of exec. payloads for opt. sync (#2837)
## Issue Addressed
NA
## Proposed Changes
Adds the functionality to allow blocks to be validated/invalidated after their import as per the [optimistic sync spec](https://github.com/ethereum/consensus-specs/blob/dev/sync/optimistic.md#how-to-optimistically-import-blocks). This means:
- Updating `ProtoArray` to allow flipping the `execution_status` of ancestors/descendants based on payload validity updates.
- Creating separation between `execution_layer` and the `beacon_chain` by creating a `PayloadStatus` struct.
- Refactoring how the `execution_layer` selects a `PayloadStatus` from the multiple statuses returned from multiple EEs.
- Adding testing framework for optimistic imports.
- Add `ExecutionBlockHash(Hash256)` new-type struct to avoid confusion between *beacon block roots* and *execution payload hashes*.
- Add `merge` to [`FORKS`](c3a793fd73/Makefile (L17)) in the `Makefile` to ensure we test the beacon chain with merge settings.
- Fix some tests here that were failing due to a missing execution layer.
## TODO
- [ ] Balance tests
Co-authored-by: Mark Mackey <mark@sigmaprime.io>
This commit is contained in:
@@ -122,18 +122,24 @@ impl ForkChoiceTest {
|
||||
}
|
||||
|
||||
/// Assert there was a shutdown signal sent by the beacon chain.
|
||||
pub fn assert_shutdown_signal_sent(mut self) -> Self {
|
||||
self.harness.shutdown_receiver.close();
|
||||
let msg = self.harness.shutdown_receiver.try_next().unwrap();
|
||||
assert!(msg.is_some());
|
||||
pub fn shutdown_signal_sent(&self) -> bool {
|
||||
let mutex = self.harness.shutdown_receiver.clone();
|
||||
let mut shutdown_receiver = mutex.lock();
|
||||
|
||||
shutdown_receiver.close();
|
||||
let msg = shutdown_receiver.try_next().unwrap();
|
||||
msg.is_some()
|
||||
}
|
||||
|
||||
/// Assert there was a shutdown signal sent by the beacon chain.
|
||||
pub fn assert_shutdown_signal_sent(self) -> Self {
|
||||
assert!(self.shutdown_signal_sent());
|
||||
self
|
||||
}
|
||||
|
||||
/// Assert no shutdown was signal sent by the beacon chain.
|
||||
pub fn assert_shutdown_signal_not_sent(mut self) -> Self {
|
||||
self.harness.shutdown_receiver.close();
|
||||
let msg = self.harness.shutdown_receiver.try_next().unwrap();
|
||||
assert!(msg.is_none());
|
||||
pub fn assert_shutdown_signal_not_sent(self) -> Self {
|
||||
assert!(!self.shutdown_signal_sent());
|
||||
self
|
||||
}
|
||||
|
||||
@@ -479,6 +485,22 @@ fn is_safe_to_update(slot: Slot, spec: &ChainSpec) -> bool {
|
||||
slot % E::slots_per_epoch() < spec.safe_slots_to_update_justified
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn justified_and_finalized_blocks() {
|
||||
let tester = ForkChoiceTest::new();
|
||||
let fork_choice = tester.harness.chain.fork_choice.read();
|
||||
|
||||
let justified_checkpoint = fork_choice.justified_checkpoint();
|
||||
assert_eq!(justified_checkpoint.epoch, 0);
|
||||
assert!(justified_checkpoint.root != Hash256::zero());
|
||||
assert!(fork_choice.get_justified_block().is_ok());
|
||||
|
||||
let finalized_checkpoint = fork_choice.finalized_checkpoint();
|
||||
assert_eq!(finalized_checkpoint.epoch, 0);
|
||||
assert!(finalized_checkpoint.root != Hash256::zero());
|
||||
assert!(fork_choice.get_finalized_block().is_ok());
|
||||
}
|
||||
|
||||
/// - The new justified checkpoint descends from the current.
|
||||
/// - Current slot is within `SAFE_SLOTS_TO_UPDATE_JUSTIFIED`
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user