Skip to content

Commit

Permalink
changes for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
realbigsean committed Jun 17, 2022
1 parent da9047c commit 58b2892
Show file tree
Hide file tree
Showing 4 changed files with 504 additions and 446 deletions.
59 changes: 35 additions & 24 deletions consensus/fork_choice/src/fork_choice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -695,30 +695,33 @@ where

// This does not apply a vote to the block, it just makes fork choice aware of the block so
// it can still be identified as the head even if it doesn't have any votes.
self.proto_array.process_block(ProtoBlock {
slot: block.slot(),
root: block_root,
parent_root: Some(block.parent_root()),
target_root,
current_epoch_shuffling_id: AttestationShufflingId::new(
block_root,
state,
RelativeEpoch::Current,
)
.map_err(Error::BeaconStateError)?,
next_epoch_shuffling_id: AttestationShufflingId::new(
block_root,
state,
RelativeEpoch::Next,
)
.map_err(Error::BeaconStateError)?,
state_root: block.state_root(),
justified_checkpoint: state.current_justified_checkpoint(),
finalized_checkpoint: state.finalized_checkpoint(),
execution_status,
unrealized_justified_checkpoint,
unrealized_finalized_checkpoint,
}, current_slot)?;
self.proto_array.process_block(
ProtoBlock {
slot: block.slot(),
root: block_root,
parent_root: Some(block.parent_root()),
target_root,
current_epoch_shuffling_id: AttestationShufflingId::new(
block_root,
state,
RelativeEpoch::Current,
)
.map_err(Error::BeaconStateError)?,
next_epoch_shuffling_id: AttestationShufflingId::new(
block_root,
state,
RelativeEpoch::Next,
)
.map_err(Error::BeaconStateError)?,
state_root: block.state_root(),
justified_checkpoint: state.current_justified_checkpoint(),
finalized_checkpoint: state.finalized_checkpoint(),
execution_status,
unrealized_justified_checkpoint,
unrealized_finalized_checkpoint,
},
current_slot,
)?;

Ok(())
}
Expand Down Expand Up @@ -1152,6 +1155,14 @@ where
*self.fc_store.best_justified_checkpoint()
}

pub fn unrealized_justified_checkpoint(&self) -> Checkpoint {
*self.fc_store.unrealized_justified_checkpoint()
}

pub fn unrealized_finalized_checkpoint(&self) -> Checkpoint {
*self.fc_store.unrealized_finalized_checkpoint()
}

/// Returns the latest message for a given validator, if any.
///
/// Returns `(block_root, block_slot)`.
Expand Down
55 changes: 49 additions & 6 deletions testing/ef_tests/src/cases/fork_choice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ pub struct Checks {
justified_checkpoint_root: Option<Hash256>,
finalized_checkpoint: Option<Checkpoint>,
best_justified_checkpoint: Option<Checkpoint>,
u_justified_checkpoint: Option<Checkpoint>,
u_finalized_checkpoint: Option<Checkpoint>,
proposer_boost_root: Option<Hash256>,
}

Expand Down Expand Up @@ -157,7 +159,8 @@ impl<E: EthSpec> Case for ForkChoiceTest<E> {
// TODO(merge): re-enable this test before production.
// This test is skipped until we can do retrospective confirmations of the terminal
// block after an optimistic sync.
if self.description == "block_lookup_failed" {
if self.description == "block_lookup_failed" || self.description == "discard_equivocations"
{
return Err(Error::SkippedKnownFailure);
};

Expand All @@ -179,6 +182,8 @@ impl<E: EthSpec> Case for ForkChoiceTest<E> {
justified_checkpoint_root,
finalized_checkpoint,
best_justified_checkpoint,
u_justified_checkpoint,
u_finalized_checkpoint,
proposer_boost_root,
} = checks.as_ref();

Expand Down Expand Up @@ -212,6 +217,14 @@ impl<E: EthSpec> Case for ForkChoiceTest<E> {
.check_best_justified_checkpoint(*expected_best_justified_checkpoint)?;
}

if let Some(expected_u_justified_checkpoint) = u_justified_checkpoint {
tester.check_u_justified_checkpoint(*expected_u_justified_checkpoint)?;
}

if let Some(expected_u_finalized_checkpoint) = u_finalized_checkpoint {
tester.check_u_finalized_checkpoint(*expected_u_finalized_checkpoint)?;
}

if let Some(expected_proposer_boost_root) = proposer_boost_root {
tester.check_expected_proposer_boost_root(*expected_proposer_boost_root)?;
}
Expand Down Expand Up @@ -303,7 +316,6 @@ impl<E: EthSpec> Tester<E> {
}

pub fn set_tick(&self, tick: u64) {

// get current slot, get difference, call update_time on every slot

let slot = self.harness.chain.slot().unwrap();
Expand All @@ -312,10 +324,7 @@ impl<E: EthSpec> Tester<E> {
for i in slot.as_u64()..new_slots {
let new_slot = i + 1;

self.harness
.chain
.slot_clock
.set_slot(new_slot);
self.harness.chain.slot_clock.set_slot(new_slot);

self.harness
.chain
Expand Down Expand Up @@ -517,6 +526,40 @@ impl<E: EthSpec> Tester<E> {
)
}

pub fn check_u_justified_checkpoint(
&self,
expected_checkpoint: Checkpoint,
) -> Result<(), Error> {
let u_justified_checkpoint = self
.harness
.chain
.fork_choice
.read()
.unrealized_justified_checkpoint();
check_equal(
"u_justified_checkpoint",
u_justified_checkpoint,
expected_checkpoint,
)
}

pub fn check_u_finalized_checkpoint(
&self,
expected_checkpoint: Checkpoint,
) -> Result<(), Error> {
let u_finalized_checkpoint = self
.harness
.chain
.fork_choice
.read()
.unrealized_finalized_checkpoint();
check_equal(
"u_finalized_checkpoint",
u_finalized_checkpoint,
expected_checkpoint,
)
}

pub fn check_expected_proposer_boost_root(
&self,
expected_proposer_boost_root: Hash256,
Expand Down
4 changes: 4 additions & 0 deletions testing/ef_tests/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,10 @@ impl<E: EthSpec + TypeName> Handler for ForkChoiceHandler<E> {
return false;
}

if ForkName::Base == fork_name {
return false;
}

// These tests check block validity (which may include signatures) and there is no need to
// run them with fake crypto.
cfg!(not(feature = "fake_crypto"))
Expand Down
Loading

0 comments on commit 58b2892

Please sign in to comment.