mirror of
https://github.com/sigp/lighthouse.git
synced 2026-06-29 10:54:24 +00:00
Use async code when interacting with EL (#3244)
## Overview
This rather extensive PR achieves two primary goals:
1. Uses the finalized/justified checkpoints of fork choice (FC), rather than that of the head state.
2. Refactors fork choice, block production and block processing to `async` functions.
Additionally, it achieves:
- Concurrent forkchoice updates to the EL and cache pruning after a new head is selected.
- Concurrent "block packing" (attestations, etc) and execution payload retrieval during block production.
- Concurrent per-block-processing and execution payload verification during block processing.
- The `Arc`-ification of `SignedBeaconBlock` during block processing (it's never mutated, so why not?):
- I had to do this to deal with sending blocks into spawned tasks.
- Previously we were cloning the beacon block at least 2 times during each block processing, these clones are either removed or turned into cheaper `Arc` clones.
- We were also `Box`-ing and un-`Box`-ing beacon blocks as they moved throughout the networking crate. This is not a big deal, but it's nice to avoid shifting things between the stack and heap.
- Avoids cloning *all the blocks* in *every chain segment* during sync.
- It also has the potential to clean up our code where we need to pass an *owned* block around so we can send it back in the case of an error (I didn't do much of this, my PR is already big enough 😅)
- The `BeaconChain::HeadSafetyStatus` struct was removed. It was an old relic from prior merge specs.
For motivation for this change, see https://github.com/sigp/lighthouse/pull/3244#issuecomment-1160963273
## Changes to `canonical_head` and `fork_choice`
Previously, the `BeaconChain` had two separate fields:
```
canonical_head: RwLock<Snapshot>,
fork_choice: RwLock<BeaconForkChoice>
```
Now, we have grouped these values under a single struct:
```
canonical_head: CanonicalHead {
cached_head: RwLock<Arc<Snapshot>>,
fork_choice: RwLock<BeaconForkChoice>
}
```
Apart from ergonomics, the only *actual* change here is wrapping the canonical head snapshot in an `Arc`. This means that we no longer need to hold the `cached_head` (`canonical_head`, in old terms) lock when we want to pull some values from it. This was done to avoid deadlock risks by preventing functions from acquiring (and holding) the `cached_head` and `fork_choice` locks simultaneously.
## Breaking Changes
### The `state` (root) field in the `finalized_checkpoint` SSE event
Consider the scenario where epoch `n` is just finalized, but `start_slot(n)` is skipped. There are two state roots we might in the `finalized_checkpoint` SSE event:
1. The state root of the finalized block, which is `get_block(finalized_checkpoint.root).state_root`.
4. The state root at slot of `start_slot(n)`, which would be the state from (1), but "skipped forward" through any skip slots.
Previously, Lighthouse would choose (2). However, we can see that when [Teku generates that event](de2b2801c8/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/events/EventSubscriptionManager.java (L171-L182)) it uses [`getStateRootFromBlockRoot`](de2b2801c8/data/provider/src/main/java/tech/pegasys/teku/api/ChainDataProvider.java (L336-L341)) which uses (1).
I have switched Lighthouse from (2) to (1). I think it's a somewhat arbitrary choice between the two, where (1) is easier to compute and is consistent with Teku.
## Notes for Reviewers
I've renamed `BeaconChain::fork_choice` to `BeaconChain::recompute_head`. Doing this helped ensure I broke all previous uses of fork choice and I also find it more descriptive. It describes an action and can't be confused with trying to get a reference to the `ForkChoice` struct.
I've changed the ordering of SSE events when a block is received. It used to be `[block, finalized, head]` and now it's `[block, head, finalized]`. It was easier this way and I don't think we were making any promises about SSE event ordering so it's not "breaking".
I've made it so fork choice will run when it's first constructed. I did this because I wanted to have a cached version of the last call to `get_head`. Ensuring `get_head` has been run *at least once* means that the cached values doesn't need to wrapped in an `Option`. This was fairly simple, it just involved passing a `slot` to the constructor so it knows *when* it's being run. When loading a fork choice from the store and a slot clock isn't handy I've just used the `slot` that was saved in the `fork_choice_store`. That seems like it would be a faithful representation of the slot when we saved it.
I added the `genesis_time: u64` to the `BeaconChain`. It's small, constant and nice to have around.
Since we're using FC for the fin/just checkpoints, we no longer get the `0x00..00` roots at genesis. You can see I had to remove a work-around in `ef-tests` here: b56be3bc2. I can't find any reason why this would be an issue, if anything I think it'll be better since the genesis-alias has caught us out a few times (0x00..00 isn't actually a real root). Edit: I did find a case where the `network` expected the 0x00..00 alias and patched it here: 3f26ac3e2.
You'll notice a lot of changes in tests. Generally, tests should be functionally equivalent. Here are the things creating the most diff-noise in tests:
- Changing tests to be `tokio::async` tests.
- Adding `.await` to fork choice, block processing and block production functions.
- Refactor of the `canonical_head` "API" provided by the `BeaconChain`. E.g., `chain.canonical_head.cached_head()` instead of `chain.canonical_head.read()`.
- Wrapping `SignedBeaconBlock` in an `Arc`.
- In the `beacon_chain/tests/block_verification`, we can't use the `lazy_static` `CHAIN_SEGMENT` variable anymore since it's generated with an async function. We just generate it in each test, not so efficient but hopefully insignificant.
I had to disable `rayon` concurrent tests in the `fork_choice` tests. This is because the use of `rayon` and `block_on` was causing a panic.
Co-authored-by: Mac L <mjladson@pm.me>
This commit is contained in:
@@ -16,9 +16,8 @@ use fork_choice::{
|
||||
};
|
||||
use store::MemoryStore;
|
||||
use types::{
|
||||
test_utils::generate_deterministic_keypair, BeaconBlock, BeaconBlockRef, BeaconState,
|
||||
ChainSpec, Checkpoint, Epoch, EthSpec, Hash256, IndexedAttestation, MainnetEthSpec, Slot,
|
||||
SubnetId,
|
||||
test_utils::generate_deterministic_keypair, BeaconBlockRef, BeaconState, ChainSpec, Checkpoint,
|
||||
Epoch, EthSpec, Hash256, IndexedAttestation, MainnetEthSpec, SignedBeaconBlock, Slot, SubnetId,
|
||||
};
|
||||
|
||||
pub type E = MainnetEthSpec;
|
||||
@@ -74,7 +73,14 @@ impl ForkChoiceTest {
|
||||
where
|
||||
T: Fn(&BeaconForkChoiceStore<E, MemoryStore<E>, MemoryStore<E>>) -> U,
|
||||
{
|
||||
func(&self.harness.chain.fork_choice.read().fc_store())
|
||||
func(
|
||||
&self
|
||||
.harness
|
||||
.chain
|
||||
.canonical_head
|
||||
.fork_choice_read_lock()
|
||||
.fc_store(),
|
||||
)
|
||||
}
|
||||
|
||||
/// Assert the epochs match.
|
||||
@@ -109,15 +115,7 @@ impl ForkChoiceTest {
|
||||
|
||||
/// Assert the given slot is greater than the head slot.
|
||||
pub fn assert_finalized_epoch_is_less_than(self, epoch: Epoch) -> Self {
|
||||
assert!(
|
||||
self.harness
|
||||
.chain
|
||||
.head_info()
|
||||
.unwrap()
|
||||
.finalized_checkpoint
|
||||
.epoch
|
||||
< epoch
|
||||
);
|
||||
assert!(self.harness.finalized_checkpoint().epoch < epoch);
|
||||
self
|
||||
}
|
||||
|
||||
@@ -150,11 +148,17 @@ impl ForkChoiceTest {
|
||||
{
|
||||
self.harness
|
||||
.chain
|
||||
.fork_choice
|
||||
.write()
|
||||
.canonical_head
|
||||
.fork_choice_write_lock()
|
||||
.update_time(self.harness.chain.slot().unwrap())
|
||||
.unwrap();
|
||||
func(self.harness.chain.fork_choice.read().queued_attestations());
|
||||
func(
|
||||
self.harness
|
||||
.chain
|
||||
.canonical_head
|
||||
.fork_choice_read_lock()
|
||||
.queued_attestations(),
|
||||
);
|
||||
self
|
||||
}
|
||||
|
||||
@@ -173,7 +177,7 @@ impl ForkChoiceTest {
|
||||
}
|
||||
|
||||
/// Build the chain whilst `predicate` returns `true` and `process_block_result` does not error.
|
||||
pub fn apply_blocks_while<F>(self, mut predicate: F) -> Result<Self, Self>
|
||||
pub async fn apply_blocks_while<F>(self, mut predicate: F) -> Result<Self, Self>
|
||||
where
|
||||
F: FnMut(BeaconBlockRef<'_, E>, &BeaconState<E>) -> bool,
|
||||
{
|
||||
@@ -182,12 +186,12 @@ impl ForkChoiceTest {
|
||||
let validators = self.harness.get_all_validators();
|
||||
loop {
|
||||
let slot = self.harness.get_current_slot();
|
||||
let (block, state_) = self.harness.make_block(state, slot);
|
||||
let (block, state_) = self.harness.make_block(state, slot).await;
|
||||
state = state_;
|
||||
if !predicate(block.message(), &state) {
|
||||
break;
|
||||
}
|
||||
if let Ok(block_hash) = self.harness.process_block_result(block.clone()) {
|
||||
if let Ok(block_hash) = self.harness.process_block_result(block.clone()).await {
|
||||
self.harness.attest_block(
|
||||
&state,
|
||||
block.state_root(),
|
||||
@@ -205,25 +209,29 @@ impl ForkChoiceTest {
|
||||
}
|
||||
|
||||
/// Apply `count` blocks to the chain (with attestations).
|
||||
pub fn apply_blocks(self, count: usize) -> Self {
|
||||
pub async fn apply_blocks(self, count: usize) -> Self {
|
||||
self.harness.advance_slot();
|
||||
self.harness.extend_chain(
|
||||
count,
|
||||
BlockStrategy::OnCanonicalHead,
|
||||
AttestationStrategy::AllValidators,
|
||||
);
|
||||
self.harness
|
||||
.extend_chain(
|
||||
count,
|
||||
BlockStrategy::OnCanonicalHead,
|
||||
AttestationStrategy::AllValidators,
|
||||
)
|
||||
.await;
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
/// Apply `count` blocks to the chain (without attestations).
|
||||
pub fn apply_blocks_without_new_attestations(self, count: usize) -> Self {
|
||||
pub async fn apply_blocks_without_new_attestations(self, count: usize) -> Self {
|
||||
self.harness.advance_slot();
|
||||
self.harness.extend_chain(
|
||||
count,
|
||||
BlockStrategy::OnCanonicalHead,
|
||||
AttestationStrategy::SomeValidators(vec![]),
|
||||
);
|
||||
self.harness
|
||||
.extend_chain(
|
||||
count,
|
||||
BlockStrategy::OnCanonicalHead,
|
||||
AttestationStrategy::SomeValidators(vec![]),
|
||||
)
|
||||
.await;
|
||||
|
||||
self
|
||||
}
|
||||
@@ -256,9 +264,9 @@ impl ForkChoiceTest {
|
||||
/// Applies a block directly to fork choice, bypassing the beacon chain.
|
||||
///
|
||||
/// Asserts the block was applied successfully.
|
||||
pub fn apply_block_directly_to_fork_choice<F>(self, mut func: F) -> Self
|
||||
pub async fn apply_block_directly_to_fork_choice<F>(self, mut func: F) -> Self
|
||||
where
|
||||
F: FnMut(&mut BeaconBlock<E>, &mut BeaconState<E>),
|
||||
F: FnMut(&mut SignedBeaconBlock<E>, &mut BeaconState<E>),
|
||||
{
|
||||
let state = self
|
||||
.harness
|
||||
@@ -269,18 +277,17 @@ impl ForkChoiceTest {
|
||||
)
|
||||
.unwrap();
|
||||
let slot = self.harness.get_current_slot();
|
||||
let (signed_block, mut state) = self.harness.make_block(state, slot);
|
||||
let (mut block, _) = signed_block.deconstruct();
|
||||
func(&mut block, &mut state);
|
||||
let (mut signed_block, mut state) = self.harness.make_block(state, slot).await;
|
||||
func(&mut signed_block, &mut state);
|
||||
let current_slot = self.harness.get_current_slot();
|
||||
self.harness
|
||||
.chain
|
||||
.fork_choice
|
||||
.write()
|
||||
.canonical_head
|
||||
.fork_choice_write_lock()
|
||||
.on_block(
|
||||
current_slot,
|
||||
&block,
|
||||
block.canonical_root(),
|
||||
signed_block.message(),
|
||||
signed_block.canonical_root(),
|
||||
Duration::from_secs(0),
|
||||
&state,
|
||||
PayloadVerificationStatus::Verified,
|
||||
@@ -293,13 +300,13 @@ impl ForkChoiceTest {
|
||||
/// Applies a block directly to fork choice, bypassing the beacon chain.
|
||||
///
|
||||
/// Asserts that an error occurred and allows inspecting it via `comparison_func`.
|
||||
pub fn apply_invalid_block_directly_to_fork_choice<F, G>(
|
||||
pub async fn apply_invalid_block_directly_to_fork_choice<F, G>(
|
||||
self,
|
||||
mut mutation_func: F,
|
||||
mut comparison_func: G,
|
||||
) -> Self
|
||||
where
|
||||
F: FnMut(&mut BeaconBlock<E>, &mut BeaconState<E>),
|
||||
F: FnMut(&mut SignedBeaconBlock<E>, &mut BeaconState<E>),
|
||||
G: FnMut(ForkChoiceError),
|
||||
{
|
||||
let state = self
|
||||
@@ -311,19 +318,18 @@ impl ForkChoiceTest {
|
||||
)
|
||||
.unwrap();
|
||||
let slot = self.harness.get_current_slot();
|
||||
let (signed_block, mut state) = self.harness.make_block(state, slot);
|
||||
let (mut block, _) = signed_block.deconstruct();
|
||||
mutation_func(&mut block, &mut state);
|
||||
let (mut signed_block, mut state) = self.harness.make_block(state, slot).await;
|
||||
mutation_func(&mut signed_block, &mut state);
|
||||
let current_slot = self.harness.get_current_slot();
|
||||
let err = self
|
||||
.harness
|
||||
.chain
|
||||
.fork_choice
|
||||
.write()
|
||||
.canonical_head
|
||||
.fork_choice_write_lock()
|
||||
.on_block(
|
||||
current_slot,
|
||||
&block,
|
||||
block.canonical_root(),
|
||||
signed_block.message(),
|
||||
signed_block.canonical_root(),
|
||||
Duration::from_secs(0),
|
||||
&state,
|
||||
PayloadVerificationStatus::Verified,
|
||||
@@ -339,7 +345,7 @@ impl ForkChoiceTest {
|
||||
/// database.
|
||||
fn check_justified_balances(&self) {
|
||||
let harness = &self.harness;
|
||||
let fc = self.harness.chain.fork_choice.read();
|
||||
let fc = self.harness.chain.canonical_head.fork_choice_read_lock();
|
||||
|
||||
let state_root = harness
|
||||
.chain
|
||||
@@ -377,7 +383,7 @@ impl ForkChoiceTest {
|
||||
/// Returns an attestation that is valid for some slot in the given `chain`.
|
||||
///
|
||||
/// Also returns some info about who created it.
|
||||
fn apply_attestation_to_chain<F, G>(
|
||||
async fn apply_attestation_to_chain<F, G>(
|
||||
self,
|
||||
delay: MutationDelay,
|
||||
mut mutation_func: F,
|
||||
@@ -387,7 +393,7 @@ impl ForkChoiceTest {
|
||||
F: FnMut(&mut IndexedAttestation<E>, &BeaconChain<EphemeralHarnessType<E>>),
|
||||
G: FnMut(Result<(), BeaconChainError>),
|
||||
{
|
||||
let head = self.harness.chain.head().expect("should get head");
|
||||
let head = self.harness.chain.head_snapshot();
|
||||
let current_slot = self.harness.chain.slot().expect("should get slot");
|
||||
|
||||
let mut attestation = self
|
||||
@@ -438,11 +444,13 @@ impl ForkChoiceTest {
|
||||
|
||||
if let MutationDelay::Blocks(slots) = delay {
|
||||
self.harness.advance_slot();
|
||||
self.harness.extend_chain(
|
||||
slots,
|
||||
BlockStrategy::OnCanonicalHead,
|
||||
AttestationStrategy::SomeValidators(vec![]),
|
||||
);
|
||||
self.harness
|
||||
.extend_chain(
|
||||
slots,
|
||||
BlockStrategy::OnCanonicalHead,
|
||||
AttestationStrategy::SomeValidators(vec![]),
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
mutation_func(
|
||||
@@ -464,17 +472,9 @@ impl ForkChoiceTest {
|
||||
pub fn check_finalized_block_is_accessible(self) -> Self {
|
||||
self.harness
|
||||
.chain
|
||||
.fork_choice
|
||||
.write()
|
||||
.get_block(
|
||||
&self
|
||||
.harness
|
||||
.chain
|
||||
.head_info()
|
||||
.unwrap()
|
||||
.finalized_checkpoint
|
||||
.root,
|
||||
)
|
||||
.canonical_head
|
||||
.fork_choice_read_lock()
|
||||
.get_block(&self.harness.finalized_checkpoint().root)
|
||||
.unwrap();
|
||||
|
||||
self
|
||||
@@ -488,7 +488,7 @@ fn is_safe_to_update(slot: Slot, spec: &ChainSpec) -> bool {
|
||||
#[test]
|
||||
fn justified_and_finalized_blocks() {
|
||||
let tester = ForkChoiceTest::new();
|
||||
let fork_choice = tester.harness.chain.fork_choice.read();
|
||||
let fork_choice = tester.harness.chain.canonical_head.fork_choice_read_lock();
|
||||
|
||||
let justified_checkpoint = fork_choice.justified_checkpoint();
|
||||
assert_eq!(justified_checkpoint.epoch, 0);
|
||||
@@ -503,44 +503,50 @@ fn justified_and_finalized_blocks() {
|
||||
|
||||
/// - The new justified checkpoint descends from the current.
|
||||
/// - Current slot is within `SAFE_SLOTS_TO_UPDATE_JUSTIFIED`
|
||||
#[test]
|
||||
fn justified_checkpoint_updates_with_descendent_inside_safe_slots() {
|
||||
#[tokio::test]
|
||||
async fn justified_checkpoint_updates_with_descendent_inside_safe_slots() {
|
||||
ForkChoiceTest::new()
|
||||
.apply_blocks_while(|_, state| state.current_justified_checkpoint().epoch == 0)
|
||||
.await
|
||||
.unwrap()
|
||||
.move_inside_safe_to_update()
|
||||
.assert_justified_epoch(0)
|
||||
.apply_blocks(1)
|
||||
.await
|
||||
.assert_justified_epoch(2);
|
||||
}
|
||||
|
||||
/// - The new justified checkpoint descends from the current.
|
||||
/// - Current slot is **not** within `SAFE_SLOTS_TO_UPDATE_JUSTIFIED`
|
||||
/// - This is **not** the first justification since genesis
|
||||
#[test]
|
||||
fn justified_checkpoint_updates_with_descendent_outside_safe_slots() {
|
||||
#[tokio::test]
|
||||
async fn justified_checkpoint_updates_with_descendent_outside_safe_slots() {
|
||||
ForkChoiceTest::new()
|
||||
.apply_blocks_while(|_, state| state.current_justified_checkpoint().epoch <= 2)
|
||||
.await
|
||||
.unwrap()
|
||||
.move_outside_safe_to_update()
|
||||
.assert_justified_epoch(2)
|
||||
.assert_best_justified_epoch(2)
|
||||
.apply_blocks(1)
|
||||
.await
|
||||
.assert_justified_epoch(3);
|
||||
}
|
||||
|
||||
/// - The new justified checkpoint descends from the current.
|
||||
/// - Current slot is **not** within `SAFE_SLOTS_TO_UPDATE_JUSTIFIED`
|
||||
/// - This is the first justification since genesis
|
||||
#[test]
|
||||
fn justified_checkpoint_updates_first_justification_outside_safe_to_update() {
|
||||
#[tokio::test]
|
||||
async fn justified_checkpoint_updates_first_justification_outside_safe_to_update() {
|
||||
ForkChoiceTest::new()
|
||||
.apply_blocks_while(|_, state| state.current_justified_checkpoint().epoch == 0)
|
||||
.await
|
||||
.unwrap()
|
||||
.move_to_next_unsafe_period()
|
||||
.assert_justified_epoch(0)
|
||||
.assert_best_justified_epoch(0)
|
||||
.apply_blocks(1)
|
||||
.await
|
||||
.assert_justified_epoch(2)
|
||||
.assert_best_justified_epoch(2);
|
||||
}
|
||||
@@ -548,12 +554,14 @@ fn justified_checkpoint_updates_first_justification_outside_safe_to_update() {
|
||||
/// - The new justified checkpoint **does not** descend from the current.
|
||||
/// - Current slot is within `SAFE_SLOTS_TO_UPDATE_JUSTIFIED`
|
||||
/// - Finalized epoch has **not** increased.
|
||||
#[test]
|
||||
fn justified_checkpoint_updates_with_non_descendent_inside_safe_slots_without_finality() {
|
||||
#[tokio::test]
|
||||
async fn justified_checkpoint_updates_with_non_descendent_inside_safe_slots_without_finality() {
|
||||
ForkChoiceTest::new()
|
||||
.apply_blocks_while(|_, state| state.current_justified_checkpoint().epoch == 0)
|
||||
.await
|
||||
.unwrap()
|
||||
.apply_blocks(1)
|
||||
.await
|
||||
.move_inside_safe_to_update()
|
||||
.assert_justified_epoch(2)
|
||||
.apply_block_directly_to_fork_choice(|_, state| {
|
||||
@@ -567,6 +575,7 @@ fn justified_checkpoint_updates_with_non_descendent_inside_safe_slots_without_fi
|
||||
.get_block_root(Epoch::new(1).start_slot(E::slots_per_epoch()))
|
||||
.unwrap();
|
||||
})
|
||||
.await
|
||||
.assert_justified_epoch(3)
|
||||
.assert_best_justified_epoch(3);
|
||||
}
|
||||
@@ -574,12 +583,14 @@ fn justified_checkpoint_updates_with_non_descendent_inside_safe_slots_without_fi
|
||||
/// - The new justified checkpoint **does not** descend from the current.
|
||||
/// - Current slot is **not** within `SAFE_SLOTS_TO_UPDATE_JUSTIFIED`.
|
||||
/// - Finalized epoch has **not** increased.
|
||||
#[test]
|
||||
fn justified_checkpoint_updates_with_non_descendent_outside_safe_slots_without_finality() {
|
||||
#[tokio::test]
|
||||
async fn justified_checkpoint_updates_with_non_descendent_outside_safe_slots_without_finality() {
|
||||
ForkChoiceTest::new()
|
||||
.apply_blocks_while(|_, state| state.current_justified_checkpoint().epoch == 0)
|
||||
.await
|
||||
.unwrap()
|
||||
.apply_blocks(1)
|
||||
.await
|
||||
.move_to_next_unsafe_period()
|
||||
.assert_justified_epoch(2)
|
||||
.apply_block_directly_to_fork_choice(|_, state| {
|
||||
@@ -593,6 +604,7 @@ fn justified_checkpoint_updates_with_non_descendent_outside_safe_slots_without_f
|
||||
.get_block_root(Epoch::new(1).start_slot(E::slots_per_epoch()))
|
||||
.unwrap();
|
||||
})
|
||||
.await
|
||||
.assert_justified_epoch(2)
|
||||
.assert_best_justified_epoch(3);
|
||||
}
|
||||
@@ -600,12 +612,14 @@ fn justified_checkpoint_updates_with_non_descendent_outside_safe_slots_without_f
|
||||
/// - The new justified checkpoint **does not** descend from the current.
|
||||
/// - Current slot is **not** within `SAFE_SLOTS_TO_UPDATE_JUSTIFIED`
|
||||
/// - Finalized epoch has increased.
|
||||
#[test]
|
||||
fn justified_checkpoint_updates_with_non_descendent_outside_safe_slots_with_finality() {
|
||||
#[tokio::test]
|
||||
async fn justified_checkpoint_updates_with_non_descendent_outside_safe_slots_with_finality() {
|
||||
ForkChoiceTest::new()
|
||||
.apply_blocks_while(|_, state| state.current_justified_checkpoint().epoch == 0)
|
||||
.await
|
||||
.unwrap()
|
||||
.apply_blocks(1)
|
||||
.await
|
||||
.move_to_next_unsafe_period()
|
||||
.assert_justified_epoch(2)
|
||||
.apply_block_directly_to_fork_choice(|_, state| {
|
||||
@@ -619,17 +633,20 @@ fn justified_checkpoint_updates_with_non_descendent_outside_safe_slots_with_fina
|
||||
.get_block_root(Epoch::new(1).start_slot(E::slots_per_epoch()))
|
||||
.unwrap();
|
||||
})
|
||||
.await
|
||||
.assert_justified_epoch(3)
|
||||
.assert_best_justified_epoch(3);
|
||||
}
|
||||
|
||||
/// Check that the balances are obtained correctly.
|
||||
#[test]
|
||||
fn justified_balances() {
|
||||
#[tokio::test]
|
||||
async fn justified_balances() {
|
||||
ForkChoiceTest::new()
|
||||
.apply_blocks_while(|_, state| state.current_justified_checkpoint().epoch == 0)
|
||||
.await
|
||||
.unwrap()
|
||||
.apply_blocks(1)
|
||||
.await
|
||||
.assert_justified_epoch(2)
|
||||
.check_justified_balances()
|
||||
}
|
||||
@@ -648,15 +665,16 @@ macro_rules! assert_invalid_block {
|
||||
/// Specification v0.12.1
|
||||
///
|
||||
/// assert block.parent_root in store.block_states
|
||||
#[test]
|
||||
fn invalid_block_unknown_parent() {
|
||||
#[tokio::test]
|
||||
async fn invalid_block_unknown_parent() {
|
||||
let junk = Hash256::from_low_u64_be(42);
|
||||
|
||||
ForkChoiceTest::new()
|
||||
.apply_blocks(2)
|
||||
.await
|
||||
.apply_invalid_block_directly_to_fork_choice(
|
||||
|block, _| {
|
||||
*block.parent_root_mut() = junk;
|
||||
*block.message_mut().parent_root_mut() = junk;
|
||||
},
|
||||
|err| {
|
||||
assert_invalid_block!(
|
||||
@@ -665,36 +683,42 @@ fn invalid_block_unknown_parent() {
|
||||
if parent == junk
|
||||
)
|
||||
},
|
||||
);
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
/// Specification v0.12.1
|
||||
///
|
||||
/// assert get_current_slot(store) >= block.slot
|
||||
#[test]
|
||||
fn invalid_block_future_slot() {
|
||||
#[tokio::test]
|
||||
async fn invalid_block_future_slot() {
|
||||
ForkChoiceTest::new()
|
||||
.apply_blocks(2)
|
||||
.await
|
||||
.apply_invalid_block_directly_to_fork_choice(
|
||||
|block, _| {
|
||||
*block.slot_mut() += 1;
|
||||
*block.message_mut().slot_mut() += 1;
|
||||
},
|
||||
|err| assert_invalid_block!(err, InvalidBlock::FutureSlot { .. }),
|
||||
);
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
/// Specification v0.12.1
|
||||
///
|
||||
/// assert block.slot > finalized_slot
|
||||
#[test]
|
||||
fn invalid_block_finalized_slot() {
|
||||
#[tokio::test]
|
||||
async fn invalid_block_finalized_slot() {
|
||||
ForkChoiceTest::new()
|
||||
.apply_blocks_while(|_, state| state.finalized_checkpoint().epoch == 0)
|
||||
.await
|
||||
.unwrap()
|
||||
.apply_blocks(1)
|
||||
.await
|
||||
.apply_invalid_block_directly_to_fork_choice(
|
||||
|block, _| {
|
||||
*block.slot_mut() = Epoch::new(2).start_slot(E::slots_per_epoch()) - 1;
|
||||
*block.message_mut().slot_mut() =
|
||||
Epoch::new(2).start_slot(E::slots_per_epoch()) - 1;
|
||||
},
|
||||
|err| {
|
||||
assert_invalid_block!(
|
||||
@@ -703,7 +727,8 @@ fn invalid_block_finalized_slot() {
|
||||
if finalized_slot == Epoch::new(2).start_slot(E::slots_per_epoch())
|
||||
)
|
||||
},
|
||||
);
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
/// Specification v0.12.1
|
||||
@@ -714,18 +739,20 @@ fn invalid_block_finalized_slot() {
|
||||
/// Note: we technically don't do this exact check, but an equivalent check. Reference:
|
||||
///
|
||||
/// https://github.com/ethereum/eth2.0-specs/pull/1884
|
||||
#[test]
|
||||
fn invalid_block_finalized_descendant() {
|
||||
#[tokio::test]
|
||||
async fn invalid_block_finalized_descendant() {
|
||||
let invalid_ancestor = Mutex::new(Hash256::zero());
|
||||
|
||||
ForkChoiceTest::new()
|
||||
.apply_blocks_while(|_, state| state.finalized_checkpoint().epoch == 0)
|
||||
.await
|
||||
.unwrap()
|
||||
.apply_blocks(1)
|
||||
.await
|
||||
.assert_finalized_epoch(2)
|
||||
.apply_invalid_block_directly_to_fork_choice(
|
||||
|block, state| {
|
||||
*block.parent_root_mut() = *state
|
||||
*block.message_mut().parent_root_mut() = *state
|
||||
.get_block_root(Epoch::new(1).start_slot(E::slots_per_epoch()))
|
||||
.unwrap();
|
||||
*invalid_ancestor.lock().unwrap() = block.parent_root();
|
||||
@@ -737,7 +764,8 @@ fn invalid_block_finalized_descendant() {
|
||||
if block_ancestor == Some(*invalid_ancestor.lock().unwrap())
|
||||
)
|
||||
},
|
||||
);
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
macro_rules! assert_invalid_attestation {
|
||||
@@ -754,23 +782,26 @@ macro_rules! assert_invalid_attestation {
|
||||
}
|
||||
|
||||
/// Ensure we can process a valid attestation.
|
||||
#[test]
|
||||
fn valid_attestation() {
|
||||
#[tokio::test]
|
||||
async fn valid_attestation() {
|
||||
ForkChoiceTest::new()
|
||||
.apply_blocks_without_new_attestations(1)
|
||||
.await
|
||||
.apply_attestation_to_chain(
|
||||
MutationDelay::NoDelay,
|
||||
|_, _| {},
|
||||
|result| assert_eq!(result.unwrap(), ()),
|
||||
);
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
/// This test is not in the specification, however we reject an attestation with an empty
|
||||
/// aggregation bitfield since it has no purpose beyond wasting our time.
|
||||
#[test]
|
||||
fn invalid_attestation_empty_bitfield() {
|
||||
#[tokio::test]
|
||||
async fn invalid_attestation_empty_bitfield() {
|
||||
ForkChoiceTest::new()
|
||||
.apply_blocks_without_new_attestations(1)
|
||||
.await
|
||||
.apply_attestation_to_chain(
|
||||
MutationDelay::NoDelay,
|
||||
|attestation, _| {
|
||||
@@ -779,7 +810,8 @@ fn invalid_attestation_empty_bitfield() {
|
||||
|result| {
|
||||
assert_invalid_attestation!(result, InvalidAttestation::EmptyAggregationBitfield)
|
||||
},
|
||||
);
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
/// Specification v0.12.1:
|
||||
@@ -787,10 +819,11 @@ fn invalid_attestation_empty_bitfield() {
|
||||
/// assert target.epoch in [expected_current_epoch, previous_epoch]
|
||||
///
|
||||
/// (tests epoch after current epoch)
|
||||
#[test]
|
||||
fn invalid_attestation_future_epoch() {
|
||||
#[tokio::test]
|
||||
async fn invalid_attestation_future_epoch() {
|
||||
ForkChoiceTest::new()
|
||||
.apply_blocks_without_new_attestations(1)
|
||||
.await
|
||||
.apply_attestation_to_chain(
|
||||
MutationDelay::NoDelay,
|
||||
|attestation, _| {
|
||||
@@ -803,7 +836,8 @@ fn invalid_attestation_future_epoch() {
|
||||
if attestation_epoch == Epoch::new(2) && current_epoch == Epoch::new(0)
|
||||
)
|
||||
},
|
||||
);
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
/// Specification v0.12.1:
|
||||
@@ -811,10 +845,11 @@ fn invalid_attestation_future_epoch() {
|
||||
/// assert target.epoch in [expected_current_epoch, previous_epoch]
|
||||
///
|
||||
/// (tests epoch prior to previous epoch)
|
||||
#[test]
|
||||
fn invalid_attestation_past_epoch() {
|
||||
#[tokio::test]
|
||||
async fn invalid_attestation_past_epoch() {
|
||||
ForkChoiceTest::new()
|
||||
.apply_blocks_without_new_attestations(E::slots_per_epoch() as usize * 3 + 1)
|
||||
.await
|
||||
.apply_attestation_to_chain(
|
||||
MutationDelay::NoDelay,
|
||||
|attestation, _| {
|
||||
@@ -827,16 +862,18 @@ fn invalid_attestation_past_epoch() {
|
||||
if attestation_epoch == Epoch::new(0) && current_epoch == Epoch::new(3)
|
||||
)
|
||||
},
|
||||
);
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
/// Specification v0.12.1:
|
||||
///
|
||||
/// assert target.epoch == compute_epoch_at_slot(attestation.data.slot)
|
||||
#[test]
|
||||
fn invalid_attestation_target_epoch() {
|
||||
#[tokio::test]
|
||||
async fn invalid_attestation_target_epoch() {
|
||||
ForkChoiceTest::new()
|
||||
.apply_blocks_without_new_attestations(E::slots_per_epoch() as usize + 1)
|
||||
.await
|
||||
.apply_attestation_to_chain(
|
||||
MutationDelay::NoDelay,
|
||||
|attestation, _| {
|
||||
@@ -849,18 +886,20 @@ fn invalid_attestation_target_epoch() {
|
||||
if target == Epoch::new(1) && slot == Slot::new(1)
|
||||
)
|
||||
},
|
||||
);
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
/// Specification v0.12.1:
|
||||
///
|
||||
/// assert target.root in store.blocks
|
||||
#[test]
|
||||
fn invalid_attestation_unknown_target_root() {
|
||||
#[tokio::test]
|
||||
async fn invalid_attestation_unknown_target_root() {
|
||||
let junk = Hash256::from_low_u64_be(42);
|
||||
|
||||
ForkChoiceTest::new()
|
||||
.apply_blocks_without_new_attestations(1)
|
||||
.await
|
||||
.apply_attestation_to_chain(
|
||||
MutationDelay::NoDelay,
|
||||
|attestation, _| {
|
||||
@@ -873,18 +912,20 @@ fn invalid_attestation_unknown_target_root() {
|
||||
if root == junk
|
||||
)
|
||||
},
|
||||
);
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
/// Specification v0.12.1:
|
||||
///
|
||||
/// assert attestation.data.beacon_block_root in store.blocks
|
||||
#[test]
|
||||
fn invalid_attestation_unknown_beacon_block_root() {
|
||||
#[tokio::test]
|
||||
async fn invalid_attestation_unknown_beacon_block_root() {
|
||||
let junk = Hash256::from_low_u64_be(42);
|
||||
|
||||
ForkChoiceTest::new()
|
||||
.apply_blocks_without_new_attestations(1)
|
||||
.await
|
||||
.apply_attestation_to_chain(
|
||||
MutationDelay::NoDelay,
|
||||
|attestation, _| {
|
||||
@@ -897,16 +938,18 @@ fn invalid_attestation_unknown_beacon_block_root() {
|
||||
if beacon_block_root == junk
|
||||
)
|
||||
},
|
||||
);
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
/// Specification v0.12.1:
|
||||
///
|
||||
/// assert store.blocks[attestation.data.beacon_block_root].slot <= attestation.data.slot
|
||||
#[test]
|
||||
fn invalid_attestation_future_block() {
|
||||
#[tokio::test]
|
||||
async fn invalid_attestation_future_block() {
|
||||
ForkChoiceTest::new()
|
||||
.apply_blocks_without_new_attestations(1)
|
||||
.await
|
||||
.apply_attestation_to_chain(
|
||||
MutationDelay::Blocks(1),
|
||||
|attestation, chain| {
|
||||
@@ -923,19 +966,21 @@ fn invalid_attestation_future_block() {
|
||||
if block == 2 && attestation == 1
|
||||
)
|
||||
},
|
||||
);
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
/// Specification v0.12.1:
|
||||
///
|
||||
/// assert target.root == get_ancestor(store, attestation.data.beacon_block_root, target_slot)
|
||||
#[test]
|
||||
fn invalid_attestation_inconsistent_ffg_vote() {
|
||||
#[tokio::test]
|
||||
async fn invalid_attestation_inconsistent_ffg_vote() {
|
||||
let local_opt = Mutex::new(None);
|
||||
let attestation_opt = Mutex::new(None);
|
||||
|
||||
ForkChoiceTest::new()
|
||||
.apply_blocks_without_new_attestations(1)
|
||||
.await
|
||||
.apply_attestation_to_chain(
|
||||
MutationDelay::NoDelay,
|
||||
|attestation, chain| {
|
||||
@@ -962,22 +1007,25 @@ fn invalid_attestation_inconsistent_ffg_vote() {
|
||||
&& local == local_opt.lock().unwrap().unwrap()
|
||||
)
|
||||
},
|
||||
);
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
/// Specification v0.12.1:
|
||||
///
|
||||
/// assert get_current_slot(store) >= attestation.data.slot + 1
|
||||
#[test]
|
||||
fn invalid_attestation_delayed_slot() {
|
||||
#[tokio::test]
|
||||
async fn invalid_attestation_delayed_slot() {
|
||||
ForkChoiceTest::new()
|
||||
.apply_blocks_without_new_attestations(1)
|
||||
.await
|
||||
.inspect_queued_attestations(|queue| assert_eq!(queue.len(), 0))
|
||||
.apply_attestation_to_chain(
|
||||
MutationDelay::NoDelay,
|
||||
|_, _| {},
|
||||
|result| assert_eq!(result.unwrap(), ()),
|
||||
)
|
||||
.await
|
||||
.inspect_queued_attestations(|queue| assert_eq!(queue.len(), 1))
|
||||
.skip_slot()
|
||||
.inspect_queued_attestations(|queue| assert_eq!(queue.len(), 0));
|
||||
@@ -985,10 +1033,11 @@ fn invalid_attestation_delayed_slot() {
|
||||
|
||||
/// Tests that the correct target root is used when the attested-to block is in a prior epoch to
|
||||
/// the attestation.
|
||||
#[test]
|
||||
fn valid_attestation_skip_across_epoch() {
|
||||
#[tokio::test]
|
||||
async fn valid_attestation_skip_across_epoch() {
|
||||
ForkChoiceTest::new()
|
||||
.apply_blocks(E::slots_per_epoch() as usize - 1)
|
||||
.await
|
||||
.skip_slots(2)
|
||||
.apply_attestation_to_chain(
|
||||
MutationDelay::NoDelay,
|
||||
@@ -999,15 +1048,18 @@ fn valid_attestation_skip_across_epoch() {
|
||||
)
|
||||
},
|
||||
|result| result.unwrap(),
|
||||
);
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_read_finalized_block() {
|
||||
#[tokio::test]
|
||||
async fn can_read_finalized_block() {
|
||||
ForkChoiceTest::new()
|
||||
.apply_blocks_while(|_, state| state.finalized_checkpoint().epoch == 0)
|
||||
.await
|
||||
.unwrap()
|
||||
.apply_blocks(1)
|
||||
.await
|
||||
.check_finalized_block_is_accessible();
|
||||
}
|
||||
|
||||
@@ -1025,8 +1077,8 @@ fn weak_subjectivity_fail_on_startup() {
|
||||
ForkChoiceTest::new_with_chain_config(chain_config);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn weak_subjectivity_pass_on_startup() {
|
||||
#[tokio::test]
|
||||
async fn weak_subjectivity_pass_on_startup() {
|
||||
let epoch = Epoch::new(0);
|
||||
let root = Hash256::zero();
|
||||
|
||||
@@ -1037,23 +1089,21 @@ fn weak_subjectivity_pass_on_startup() {
|
||||
|
||||
ForkChoiceTest::new_with_chain_config(chain_config)
|
||||
.apply_blocks(E::slots_per_epoch() as usize)
|
||||
.await
|
||||
.assert_shutdown_signal_not_sent();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn weak_subjectivity_check_passes() {
|
||||
#[tokio::test]
|
||||
async fn weak_subjectivity_check_passes() {
|
||||
let setup_harness = ForkChoiceTest::new()
|
||||
.apply_blocks_while(|_, state| state.finalized_checkpoint().epoch == 0)
|
||||
.await
|
||||
.unwrap()
|
||||
.apply_blocks(1)
|
||||
.await
|
||||
.assert_finalized_epoch(2);
|
||||
|
||||
let checkpoint = setup_harness
|
||||
.harness
|
||||
.chain
|
||||
.head_info()
|
||||
.unwrap()
|
||||
.finalized_checkpoint;
|
||||
let checkpoint = setup_harness.harness.finalized_checkpoint();
|
||||
|
||||
let chain_config = ChainConfig {
|
||||
weak_subjectivity_checkpoint: Some(checkpoint),
|
||||
@@ -1062,26 +1112,25 @@ fn weak_subjectivity_check_passes() {
|
||||
|
||||
ForkChoiceTest::new_with_chain_config(chain_config.clone())
|
||||
.apply_blocks_while(|_, state| state.finalized_checkpoint().epoch == 0)
|
||||
.await
|
||||
.unwrap()
|
||||
.apply_blocks(1)
|
||||
.await
|
||||
.assert_finalized_epoch(2)
|
||||
.assert_shutdown_signal_not_sent();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn weak_subjectivity_check_fails_early_epoch() {
|
||||
#[tokio::test]
|
||||
async fn weak_subjectivity_check_fails_early_epoch() {
|
||||
let setup_harness = ForkChoiceTest::new()
|
||||
.apply_blocks_while(|_, state| state.finalized_checkpoint().epoch == 0)
|
||||
.await
|
||||
.unwrap()
|
||||
.apply_blocks(1)
|
||||
.await
|
||||
.assert_finalized_epoch(2);
|
||||
|
||||
let mut checkpoint = setup_harness
|
||||
.harness
|
||||
.chain
|
||||
.head_info()
|
||||
.unwrap()
|
||||
.finalized_checkpoint;
|
||||
let mut checkpoint = setup_harness.harness.finalized_checkpoint();
|
||||
|
||||
checkpoint.epoch = checkpoint.epoch - 1;
|
||||
|
||||
@@ -1092,25 +1141,23 @@ fn weak_subjectivity_check_fails_early_epoch() {
|
||||
|
||||
ForkChoiceTest::new_with_chain_config(chain_config.clone())
|
||||
.apply_blocks_while(|_, state| state.finalized_checkpoint().epoch < 3)
|
||||
.await
|
||||
.unwrap_err()
|
||||
.assert_finalized_epoch_is_less_than(checkpoint.epoch)
|
||||
.assert_shutdown_signal_sent();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn weak_subjectivity_check_fails_late_epoch() {
|
||||
#[tokio::test]
|
||||
async fn weak_subjectivity_check_fails_late_epoch() {
|
||||
let setup_harness = ForkChoiceTest::new()
|
||||
.apply_blocks_while(|_, state| state.finalized_checkpoint().epoch == 0)
|
||||
.await
|
||||
.unwrap()
|
||||
.apply_blocks(1)
|
||||
.await
|
||||
.assert_finalized_epoch(2);
|
||||
|
||||
let mut checkpoint = setup_harness
|
||||
.harness
|
||||
.chain
|
||||
.head_info()
|
||||
.unwrap()
|
||||
.finalized_checkpoint;
|
||||
let mut checkpoint = setup_harness.harness.finalized_checkpoint();
|
||||
|
||||
checkpoint.epoch = checkpoint.epoch + 1;
|
||||
|
||||
@@ -1121,25 +1168,23 @@ fn weak_subjectivity_check_fails_late_epoch() {
|
||||
|
||||
ForkChoiceTest::new_with_chain_config(chain_config.clone())
|
||||
.apply_blocks_while(|_, state| state.finalized_checkpoint().epoch < 4)
|
||||
.await
|
||||
.unwrap_err()
|
||||
.assert_finalized_epoch_is_less_than(checkpoint.epoch)
|
||||
.assert_shutdown_signal_sent();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn weak_subjectivity_check_fails_incorrect_root() {
|
||||
#[tokio::test]
|
||||
async fn weak_subjectivity_check_fails_incorrect_root() {
|
||||
let setup_harness = ForkChoiceTest::new()
|
||||
.apply_blocks_while(|_, state| state.finalized_checkpoint().epoch == 0)
|
||||
.await
|
||||
.unwrap()
|
||||
.apply_blocks(1)
|
||||
.await
|
||||
.assert_finalized_epoch(2);
|
||||
|
||||
let mut checkpoint = setup_harness
|
||||
.harness
|
||||
.chain
|
||||
.head_info()
|
||||
.unwrap()
|
||||
.finalized_checkpoint;
|
||||
let mut checkpoint = setup_harness.harness.finalized_checkpoint();
|
||||
|
||||
checkpoint.root = Hash256::zero();
|
||||
|
||||
@@ -1150,27 +1195,31 @@ fn weak_subjectivity_check_fails_incorrect_root() {
|
||||
|
||||
ForkChoiceTest::new_with_chain_config(chain_config.clone())
|
||||
.apply_blocks_while(|_, state| state.finalized_checkpoint().epoch < 3)
|
||||
.await
|
||||
.unwrap_err()
|
||||
.assert_finalized_epoch_is_less_than(checkpoint.epoch)
|
||||
.assert_shutdown_signal_sent();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn weak_subjectivity_check_epoch_boundary_is_skip_slot() {
|
||||
#[tokio::test]
|
||||
async fn weak_subjectivity_check_epoch_boundary_is_skip_slot() {
|
||||
let setup_harness = ForkChoiceTest::new()
|
||||
// first two epochs
|
||||
.apply_blocks_while(|_, state| state.finalized_checkpoint().epoch == 0)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
// get the head, it will become the finalized root of epoch 4
|
||||
let checkpoint_root = setup_harness.harness.chain.head_info().unwrap().block_root;
|
||||
let checkpoint_root = setup_harness.harness.head_block_root();
|
||||
|
||||
setup_harness
|
||||
// epoch 3 will be entirely skip slots
|
||||
.skip_slots(E::slots_per_epoch() as usize)
|
||||
.apply_blocks_while(|_, state| state.finalized_checkpoint().epoch < 5)
|
||||
.await
|
||||
.unwrap()
|
||||
.apply_blocks(1)
|
||||
.await
|
||||
.assert_finalized_epoch(5);
|
||||
|
||||
// the checkpoint at epoch 4 should become the root of last block of epoch 2
|
||||
@@ -1187,31 +1236,37 @@ fn weak_subjectivity_check_epoch_boundary_is_skip_slot() {
|
||||
// recreate the chain exactly
|
||||
ForkChoiceTest::new_with_chain_config(chain_config.clone())
|
||||
.apply_blocks_while(|_, state| state.finalized_checkpoint().epoch == 0)
|
||||
.await
|
||||
.unwrap()
|
||||
.skip_slots(E::slots_per_epoch() as usize)
|
||||
.apply_blocks_while(|_, state| state.finalized_checkpoint().epoch < 5)
|
||||
.await
|
||||
.unwrap()
|
||||
.apply_blocks(1)
|
||||
.await
|
||||
.assert_finalized_epoch(5)
|
||||
.assert_shutdown_signal_not_sent();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn weak_subjectivity_check_epoch_boundary_is_skip_slot_failure() {
|
||||
#[tokio::test]
|
||||
async fn weak_subjectivity_check_epoch_boundary_is_skip_slot_failure() {
|
||||
let setup_harness = ForkChoiceTest::new()
|
||||
// first two epochs
|
||||
.apply_blocks_while(|_, state| state.finalized_checkpoint().epoch == 0)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
// get the head, it will become the finalized root of epoch 4
|
||||
let checkpoint_root = setup_harness.harness.chain.head_info().unwrap().block_root;
|
||||
let checkpoint_root = setup_harness.harness.head_block_root();
|
||||
|
||||
setup_harness
|
||||
// epoch 3 will be entirely skip slots
|
||||
.skip_slots(E::slots_per_epoch() as usize)
|
||||
.apply_blocks_while(|_, state| state.finalized_checkpoint().epoch < 5)
|
||||
.await
|
||||
.unwrap()
|
||||
.apply_blocks(1)
|
||||
.await
|
||||
.assert_finalized_epoch(5);
|
||||
|
||||
// Invalid checkpoint (epoch too early)
|
||||
@@ -1228,9 +1283,11 @@ fn weak_subjectivity_check_epoch_boundary_is_skip_slot_failure() {
|
||||
// recreate the chain exactly
|
||||
ForkChoiceTest::new_with_chain_config(chain_config.clone())
|
||||
.apply_blocks_while(|_, state| state.finalized_checkpoint().epoch == 0)
|
||||
.await
|
||||
.unwrap()
|
||||
.skip_slots(E::slots_per_epoch() as usize)
|
||||
.apply_blocks_while(|_, state| state.finalized_checkpoint().epoch < 6)
|
||||
.await
|
||||
.unwrap_err()
|
||||
.assert_finalized_epoch_is_less_than(checkpoint.epoch)
|
||||
.assert_shutdown_signal_sent();
|
||||
|
||||
Reference in New Issue
Block a user