Skip to content

Commit 1b4cde8

Browse files
committed
Refactor filter logic for tidiness
1 parent 529085c commit 1b4cde8

1 file changed

Lines changed: 19 additions & 30 deletions

File tree

consensus/proto_array/src/proto_array.rs

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -902,44 +902,33 @@ impl ProtoArray {
902902
let genesis_epoch = Epoch::new(0);
903903
let current_epoch = current_slot.epoch(E::slots_per_epoch());
904904
let node_epoch = node.slot.epoch(E::slots_per_epoch());
905+
let node_justified_checkpoint =
906+
if let Some(justified_checkpoint) = node.justified_checkpoint {
907+
justified_checkpoint
908+
} else {
909+
// The node does not have any information about the justified
910+
// checkpoint. This indicates an inconsistent proto-array.
911+
return false;
912+
};
905913

906-
let voting_source_opt = if current_epoch > node_epoch {
907-
node.unrealized_justified_checkpoint
908-
.or(node.justified_checkpoint)
909-
} else {
910-
node.justified_checkpoint
911-
};
912-
let voting_source = if let Some(checkpoint) = voting_source_opt {
913-
checkpoint
914-
} else {
915-
// The node does not have any information about the
916-
// justified/finalized checkpoint. This indicates an inconsistent
917-
// proto-array.
918-
return false;
919-
};
920-
921-
let unrealized_justification = if self.justified_checkpoint.epoch + 1 == current_epoch {
922-
// This `unrealized_justified_checkpoint` is an `Option` that can be
923-
// `None` in the scenario that we're not computing unrealized
924-
// justification (UJ). During sync we avoid this computation as an
925-
// optimisation.
926-
//
927-
// I claim that it is safe to always have `unrealized_justification
928-
// == None` under the following conditions:
929-
//
930-
// 1. All competing heads do not have UJ computed.
931-
// 2. The store is not updated as per UJ values.
914+
let voting_source = if current_epoch > node_epoch {
915+
// The block is from a prior epoch, the voting source will be pulled-up.
932916
node.unrealized_justified_checkpoint
917+
// Sometimes we don't track the unrealized justification. In
918+
// that case, just use the fully-realized justified checkpoint.
919+
.unwrap_or(node_justified_checkpoint)
933920
} else {
934-
None
921+
// The block is not from a prior epoch, therefore the voting source
922+
// is not pulled up.
923+
node_justified_checkpoint
935924
};
936925

937926
let mut correct_justified = self.justified_checkpoint.epoch == genesis_epoch
938927
|| voting_source.epoch == self.justified_checkpoint.epoch;
939928

940-
if !correct_justified {
941-
if let Some(unrealized_justification) = unrealized_justification {
942-
correct_justified = unrealized_justification.epoch
929+
if let Some(node_unrealized_justified_checkpoint) = node.unrealized_justified_checkpoint {
930+
if !correct_justified && self.justified_checkpoint.epoch + 1 == current_epoch {
931+
correct_justified = node_unrealized_justified_checkpoint.epoch
943932
>= self.justified_checkpoint.epoch
944933
&& voting_source.epoch + 2 >= current_epoch;
945934
}

0 commit comments

Comments
 (0)