Skip to content

Commit

Permalink
Rename function
Browse files Browse the repository at this point in the history
  • Loading branch information
paulhauner committed Jan 27, 2023
1 parent 6590da5 commit c977fab
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 21 deletions.
4 changes: 2 additions & 2 deletions beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::beacon_proposer_cache::compute_proposer_duties_from_head;
use crate::beacon_proposer_cache::BeaconProposerCache;
use crate::block_times_cache::BlockTimesCache;
use crate::block_verification::{
check_block_is_finalized_descendant, check_block_relevancy, get_block_root,
check_block_is_finalized_checkpoint_descendant, check_block_relevancy, get_block_root,
signature_verify_chain_segment, BlockError, ExecutionPendingBlock, GossipVerifiedBlock,
IntoExecutionPendingBlock, PayloadVerificationOutcome, POS_PANDA_BANNER,
};
Expand Down Expand Up @@ -2736,7 +2736,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
let mut fork_choice = self.canonical_head.fork_choice_write_lock();

// Do not import a block that doesn't descend from the finalized root.
check_block_is_finalized_descendant(self, &fork_choice, &signed_block)?;
check_block_is_finalized_checkpoint_descendant(self, &fork_choice, &signed_block)?;

// Register the new block with the fork choice service.
{
Expand Down
6 changes: 3 additions & 3 deletions beacon_node/beacon_chain/src/block_verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ impl<T: BeaconChainTypes> GossipVerifiedBlock<T> {
// Do not process a block that doesn't descend from the finalized root.
//
// We check this *before* we load the parent so that we can return a more detailed error.
check_block_is_finalized_descendant(
check_block_is_finalized_checkpoint_descendant(
chain,
&chain.canonical_head.fork_choice_write_lock(),
&block,
Expand Down Expand Up @@ -1564,12 +1564,12 @@ fn check_block_against_finalized_slot<T: BeaconChainTypes>(
/// ## Warning
///
/// Taking a lock on the `chain.canonical_head.fork_choice` might cause a deadlock here.
pub fn check_block_is_finalized_descendant<T: BeaconChainTypes>(
pub fn check_block_is_finalized_checkpoint_descendant<T: BeaconChainTypes>(
chain: &BeaconChain<T>,
fork_choice: &BeaconForkChoice<T>,
block: &Arc<SignedBeaconBlock<T::EthSpec>>,
) -> Result<(), BlockError<T::EthSpec>> {
if fork_choice.is_descendant_of_finalized(block.parent_root()) {
if fork_choice.is_descendant_of_finalized_checkpoint(block.parent_root()) {
Ok(())
} else {
// If fork choice does *not* consider the parent to be a descendant of the finalized block,
Expand Down
16 changes: 9 additions & 7 deletions consensus/fork_choice/src/fork_choice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,7 @@ where

if store.best_justified_checkpoint().epoch > store.justified_checkpoint().epoch {
let store = &self.fc_store;
if self.is_descendant_of_finalized(store.best_justified_checkpoint().root) {
if self.is_descendant_of_finalized_checkpoint(store.best_justified_checkpoint().root) {
let store = &mut self.fc_store;
store
.set_justified_checkpoint(*store.best_justified_checkpoint())
Expand Down Expand Up @@ -1323,12 +1323,13 @@ where

/// Returns `true` if the block is known **and** a descendant of the finalized root.
pub fn contains_block(&self, block_root: &Hash256) -> bool {
self.proto_array.contains_block(block_root) && self.is_descendant_of_finalized(*block_root)
self.proto_array.contains_block(block_root)
&& self.is_descendant_of_finalized_checkpoint(*block_root)
}

/// Returns a `ProtoBlock` if the block is known **and** a descendant of the finalized root.
pub fn get_block(&self, block_root: &Hash256) -> Option<ProtoBlock> {
if self.is_descendant_of_finalized(*block_root) {
if self.is_descendant_of_finalized_checkpoint(*block_root) {
self.proto_array.get_block(block_root)
} else {
None
Expand All @@ -1337,7 +1338,7 @@ where

/// Returns an `ExecutionStatus` if the block is known **and** a descendant of the finalized root.
pub fn get_block_execution_status(&self, block_root: &Hash256) -> Option<ExecutionStatus> {
if self.is_descendant_of_finalized(*block_root) {
if self.is_descendant_of_finalized_checkpoint(*block_root) {
self.proto_array.get_block_execution_status(block_root)
} else {
None
Expand Down Expand Up @@ -1372,9 +1373,10 @@ where
})
}

/// Return `true` if `block_root` is equal to the finalized root, or a known descendant of it.
pub fn is_descendant_of_finalized(&self, block_root: Hash256) -> bool {
self.proto_array.is_finalized_descendant::<E>(block_root)
/// Return `true` if `block_root` is equal to the finalized checkpoint, or a known descendant of it.
pub fn is_descendant_of_finalized_checkpoint(&self, block_root: Hash256) -> bool {
self.proto_array
.is_finalized_checkpoint_descendant::<E>(block_root)
}

/// Returns `Ok(true)` if `block_root` has been imported optimistically or deemed invalid.
Expand Down
2 changes: 1 addition & 1 deletion consensus/proto_array/src/proto_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ impl ProtoArray {
/// ## Notes
///
/// Still returns `true` if `ancestor_root` is known and `ancestor_root == descendant_root`.
pub fn is_finalized_descendant<E: EthSpec>(&self, root: Hash256) -> bool {
pub fn is_finalized_checkpoint_descendant<E: EthSpec>(&self, root: Hash256) -> bool {
let finalized_root = self.finalized_checkpoint.root;
let finalized_slot = self
.finalized_checkpoint
Expand Down
20 changes: 12 additions & 8 deletions consensus/proto_array/src/proto_array_fork_choice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -749,9 +749,9 @@ impl ProtoArrayForkChoice {
}

/// See `ProtoArray` documentation.
pub fn is_finalized_descendant<E: EthSpec>(&self, descendant_root: Hash256) -> bool {
pub fn is_finalized_checkpoint_descendant<E: EthSpec>(&self, descendant_root: Hash256) -> bool {
self.proto_array
.is_finalized_descendant::<E>(descendant_root)
.is_finalized_checkpoint_descendant::<E>(descendant_root)
}

pub fn latest_message(&self, validator_index: usize) -> Option<(Hash256, Epoch)> {
Expand Down Expand Up @@ -999,10 +999,10 @@ mod test_compute_deltas {
assert!(!fc.is_descendant(finalized_root, not_finalized_desc));
assert!(!fc.is_descendant(finalized_root, unknown));

assert!(fc.is_finalized_descendant::<MainnetEthSpec>(finalized_root));
assert!(fc.is_finalized_descendant::<MainnetEthSpec>(finalized_desc));
assert!(!fc.is_finalized_descendant::<MainnetEthSpec>(not_finalized_desc));
assert!(!fc.is_finalized_descendant::<MainnetEthSpec>(unknown));
assert!(fc.is_finalized_checkpoint_descendant::<MainnetEthSpec>(finalized_root));
assert!(fc.is_finalized_checkpoint_descendant::<MainnetEthSpec>(finalized_desc));
assert!(!fc.is_finalized_checkpoint_descendant::<MainnetEthSpec>(not_finalized_desc));
assert!(!fc.is_finalized_checkpoint_descendant::<MainnetEthSpec>(unknown));

assert!(!fc.is_descendant(finalized_desc, not_finalized_desc));
assert!(fc.is_descendant(finalized_desc, finalized_desc));
Expand Down Expand Up @@ -1159,12 +1159,16 @@ mod test_compute_deltas {

assert!(
fc.proto_array
.is_finalized_descendant::<MainnetEthSpec>(get_block_root(canonical_slot)),
.is_finalized_checkpoint_descendant::<MainnetEthSpec>(get_block_root(
canonical_slot
)),
"the canonical block is a descendant of the finalized checkpoint"
);
assert!(
!fc.proto_array
.is_finalized_descendant::<MainnetEthSpec>(get_block_root(non_canonical_slot)),
.is_finalized_checkpoint_descendant::<MainnetEthSpec>(get_block_root(
non_canonical_slot
)),
"although the non-canonical block is a descendant of the finalized block, \
it's not a descendant of the finalized checkpoint"
);
Expand Down

0 comments on commit c977fab

Please sign in to comment.