mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-19 12:56:12 +00:00
Add is_parent_strong proposer re-org check (#5417)
* initial fork choice additions * add helper fns * add is_parent_strong * Merge branch 'unstable' of https://github.com/sigp/lighthouse into add_is_parent_strong_check * disabling proposer reorg should set parent_threshold to u64 max * add new flag, is_parent_strong check in override fcu params * cherry-pick changes * Merge branch 'unstable' of https://github.com/sigp/lighthouse into add_is_parent_strong_check * cleanup * fmt * Minor review tweaks
This commit is contained in:
@@ -4262,7 +4262,8 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
head_slot: Slot,
|
||||
canonical_head: Hash256,
|
||||
) -> Option<BlockProductionPreState<T::EthSpec>> {
|
||||
let re_org_threshold = self.config.re_org_threshold?;
|
||||
let re_org_head_threshold = self.config.re_org_head_threshold?;
|
||||
let re_org_parent_threshold = self.config.re_org_parent_threshold?;
|
||||
|
||||
if self.spec.proposer_score_boost.is_none() {
|
||||
warn!(
|
||||
@@ -4319,7 +4320,8 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
.get_proposer_head(
|
||||
slot,
|
||||
canonical_head,
|
||||
re_org_threshold,
|
||||
re_org_head_threshold,
|
||||
re_org_parent_threshold,
|
||||
&self.config.re_org_disallowed_offsets,
|
||||
self.config.re_org_max_epochs_since_finalization,
|
||||
)
|
||||
@@ -4373,7 +4375,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
"weak_head" => ?canonical_head,
|
||||
"parent" => ?re_org_parent_block,
|
||||
"head_weight" => proposer_head.head_node.weight,
|
||||
"threshold_weight" => proposer_head.re_org_weight_threshold
|
||||
"threshold_weight" => proposer_head.re_org_head_weight_threshold
|
||||
);
|
||||
|
||||
Some(pre_state)
|
||||
@@ -4593,9 +4595,14 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
let _timer = metrics::start_timer(&metrics::FORK_CHOICE_OVERRIDE_FCU_TIMES);
|
||||
|
||||
// Never override if proposer re-orgs are disabled.
|
||||
let re_org_threshold = self
|
||||
let re_org_head_threshold = self
|
||||
.config
|
||||
.re_org_threshold
|
||||
.re_org_head_threshold
|
||||
.ok_or(DoNotReOrg::ReOrgsDisabled)?;
|
||||
|
||||
let re_org_parent_threshold = self
|
||||
.config
|
||||
.re_org_parent_threshold
|
||||
.ok_or(DoNotReOrg::ReOrgsDisabled)?;
|
||||
|
||||
let head_block_root = canonical_forkchoice_params.head_root;
|
||||
@@ -4606,7 +4613,8 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
.fork_choice_read_lock()
|
||||
.get_preliminary_proposer_head(
|
||||
head_block_root,
|
||||
re_org_threshold,
|
||||
re_org_head_threshold,
|
||||
re_org_parent_threshold,
|
||||
&self.config.re_org_disallowed_offsets,
|
||||
self.config.re_org_max_epochs_since_finalization,
|
||||
)
|
||||
@@ -4674,16 +4682,27 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
}
|
||||
|
||||
// If the current slot is already equal to the proposal slot (or we are in the tail end of
|
||||
// the prior slot), then check the actual weight of the head against the re-org threshold.
|
||||
let head_weak = if fork_choice_slot == re_org_block_slot {
|
||||
info.head_node.weight < info.re_org_weight_threshold
|
||||
// the prior slot), then check the actual weight of the head against the head re-org threshold
|
||||
// and the actual weight of the parent against the parent re-org threshold.
|
||||
let (head_weak, parent_strong) = if fork_choice_slot == re_org_block_slot {
|
||||
(
|
||||
info.head_node.weight < info.re_org_head_weight_threshold,
|
||||
info.parent_node.weight > info.re_org_parent_weight_threshold,
|
||||
)
|
||||
} else {
|
||||
true
|
||||
(true, true)
|
||||
};
|
||||
if !head_weak {
|
||||
return Err(DoNotReOrg::HeadNotWeak {
|
||||
head_weight: info.head_node.weight,
|
||||
re_org_weight_threshold: info.re_org_weight_threshold,
|
||||
re_org_head_weight_threshold: info.re_org_head_weight_threshold,
|
||||
}
|
||||
.into());
|
||||
}
|
||||
if !parent_strong {
|
||||
return Err(DoNotReOrg::ParentNotStrong {
|
||||
parent_weight: info.parent_node.weight,
|
||||
re_org_parent_weight_threshold: info.re_org_parent_weight_threshold,
|
||||
}
|
||||
.into());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user