Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: introduce proposer boost reorg to fork choice #6581

Merged
merged 11 commits into from
Apr 3, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 12 additions & 18 deletions packages/fork-choice/src/forkChoice/forkChoice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export class ForkChoice implements IForkChoice {
*
* https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.4/specs/bellatrix/fork-choice.md#should_override_forkchoice_update
*/
predictProposerHead(headBlock: ProtoBlock, secFromSlot: number, currentSlot?: Slot): ProtoBlock {
predictProposerHead(headBlock: ProtoBlock, currentSlot?: Slot): ProtoBlock {
// Skip re-org attempt if proposer boost (reorg) are disabled
if (!this.opts?.proposerBoostEnabled) {
this.logger?.verbose("No proposer boot reorg prediction since the related flags are disabled");
Expand All @@ -190,7 +190,7 @@ export class ForkChoice implements IForkChoice {
return headBlock;
}

const {prelimProposerHead} = this.getPreliminaryProposerHead(headBlock, parentBlock, secFromSlot, proposalSlot);
const {prelimProposerHead} = this.getPreliminaryProposerHead(headBlock, parentBlock, proposalSlot);

if (prelimProposerHead === headBlock) {
return headBlock;
Expand Down Expand Up @@ -234,17 +234,21 @@ export class ForkChoice implements IForkChoice {
return {proposerHead, isHeadTimely, notReorgedReason: NotReorgedReason.ParentBlockNotAvailable};
}

const {prelimProposerHead, prelimNotReorgedReason} = this.getPreliminaryProposerHead(
headBlock,
parentBlock,
secFromSlot,
slot
);
const {prelimProposerHead, prelimNotReorgedReason} = this.getPreliminaryProposerHead(headBlock, parentBlock, slot);

if (prelimProposerHead === headBlock && prelimNotReorgedReason !== undefined) {
return {proposerHead, isHeadTimely, notReorgedReason: prelimNotReorgedReason};
}

// -No reorg if we are not proposing on time.-
// Note: Skipping this check as store.time in Lodestar is stored in slot and not unix time
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this comment

// https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.4/specs/phase0/fork-choice.md#is_proposing_on_time
const proposerReorgCutoff = this.config.SECONDS_PER_SLOT / INTERVALS_PER_SLOT / 2;
const isProposingOnTime = secFromSlot <= proposerReorgCutoff;
if (!isProposingOnTime) {
return {proposerHead, isHeadTimely, notReorgedReason: NotReorgedReason.NotProposingOnTime};
}

// No reorg if attempted reorg is more than a single slot
// Half of single_slot_reorg check in the spec is done in getPreliminaryProposerHead()
const currentTimeOk = headBlock.slot + 1 === slot;
Expand Down Expand Up @@ -1350,7 +1354,6 @@ export class ForkChoice implements IForkChoice {
private getPreliminaryProposerHead(
headBlock: ProtoBlock,
parentBlock: ProtoBlock,
secFromSlot: number,
slot: Slot
): {prelimProposerHead: ProtoBlock; prelimNotReorgedReason?: NotReorgedReason} {
let prelimProposerHead = headBlock;
Expand Down Expand Up @@ -1385,15 +1388,6 @@ export class ForkChoice implements IForkChoice {
return {prelimProposerHead, prelimNotReorgedReason: NotReorgedReason.ChainLongUnfinality};
}

// -No reorg if we are not proposing on time.-
// Note: Skipping this check as store.time in Lodestar is stored in slot and not unix time
// https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.4/specs/phase0/fork-choice.md#is_proposing_on_time
const proposerReorgCutoff = this.config.SECONDS_PER_SLOT / INTERVALS_PER_SLOT / 2;
const isProposingOnTime = secFromSlot <= proposerReorgCutoff;
if (!isProposingOnTime) {
return {prelimProposerHead, prelimNotReorgedReason: NotReorgedReason.NotProposingOnTime};
}

// No reorg if this reorg spans more than a single slot
const parentSlotOk = parentBlock.slot + 1 === headBlock.slot;
if (!parentSlotOk) {
Expand Down
Loading