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
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions packages/api/src/beacon/routes/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const protoNodeSszType = new ContainerType(
parentRoot: stringType,
stateRoot: stringType,
targetRoot: stringType,
timeliness: ssz.Boolean,
justifiedEpoch: ssz.Epoch,
justifiedRoot: stringType,
finalizedEpoch: ssz.Epoch,
Expand Down
1 change: 1 addition & 0 deletions packages/api/test/unit/beacon/testData/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const testData: GenericServerTestCases<Api> = {
weight: 1,
bestChild: "1",
bestDescendant: "1",
timeliness: false,
},
],
},
Expand Down
9 changes: 6 additions & 3 deletions packages/beacon-node/src/chain/forkChoice/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
isMergeTransitionComplete,
} from "@lodestar/state-transition";

import {Logger} from "@lodestar/utils";
import {computeAnchorCheckpoint} from "../initState.js";
import {ChainEventEmitter} from "../emitter.js";
import {ChainEvent} from "../emitter.js";
Expand All @@ -35,7 +36,8 @@ export function initializeForkChoice(
currentSlot: Slot,
state: CachedBeaconStateAllForks,
opts: ForkChoiceOpts,
justifiedBalancesGetter: JustifiedBalancesGetter
justifiedBalancesGetter: JustifiedBalancesGetter,
logger?: Logger
): ForkChoice {
const {blockHeader, checkpoint} = computeAnchorCheckpoint(config, state);
const finalizedCheckpoint = {...checkpoint};
Expand Down Expand Up @@ -75,6 +77,7 @@ export function initializeForkChoice(
parentRoot: toHexString(blockHeader.parentRoot),
stateRoot: toHexString(blockHeader.stateRoot),
blockRoot: toHexString(checkpoint.root),
timeliness: true, // Optimisitcally assume is timely

justifiedEpoch: justifiedCheckpoint.epoch,
justifiedRoot: toHexString(justifiedCheckpoint.root),
Expand All @@ -95,7 +98,7 @@ export function initializeForkChoice(
},
currentSlot
),

opts
opts,
logger
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ describe(`getAttestationsForBlock vc=${vc}`, () => {
unrealizedFinalizedRoot: toHexString(finalizedCheckpoint.root),
executionPayloadBlockHash: null,
executionStatus: ExecutionStatus.PreMerge,

timeliness: false,
},
originalState.slot
);
Expand All @@ -87,6 +89,7 @@ describe(`getAttestationsForBlock vc=${vc}`, () => {
unrealizedFinalizedRoot: toHexString(finalizedCheckpoint.root),
executionPayloadBlockHash: null,
executionStatus: ExecutionStatus.PreMerge,
timeliness: false,
},
slot
);
Expand Down
2 changes: 2 additions & 0 deletions packages/beacon-node/test/utils/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,7 @@ export const zeroProtoBlock: ProtoBlock = {
unrealizedFinalizedEpoch: 0,
unrealizedFinalizedRoot: ZERO_HASH_HEX,

timeliness: false,

...{executionPayloadBlockHash: null, executionStatus: ExecutionStatus.PreMerge},
};
2 changes: 2 additions & 0 deletions packages/beacon-node/test/utils/typeGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export function generateProtoBlock(overrides: Partial<ProtoBlock> = {}): ProtoBl
unrealizedFinalizedEpoch: 0,
unrealizedFinalizedRoot: ZERO_HASH_HEX,

timeliness: false,

...{executionPayloadBlockHash: null, executionStatus: ExecutionStatus.PreMerge},

...overrides,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ export function getAttestationValidData(opts: AttestationValidDataOpts): {
unrealizedFinalizedEpoch: 0,
unrealizedFinalizedRoot: ZERO_HASH_HEX,

timeliness: false,

...{executionPayloadBlockHash: null, executionStatus: ExecutionStatus.PreMerge},
};

Expand Down
3 changes: 3 additions & 0 deletions packages/config/src/chainConfig/configs/mainnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ export const chainConfig: ChainConfig = {
// ---------------------------------------------------------------
// 40%
PROPOSER_SCORE_BOOST: 40,
REORG_HEAD_WEIGHT_THRESHOLD: 20,
REORG_PARENT_WEIGHT_THRESHOLD: 160,
REORG_MAX_EPOCHS_SINCE_FINALIZATION: 2,

// Deposit contract
// ---------------------------------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions packages/config/src/chainConfig/configs/minimal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ export const chainConfig: ChainConfig = {
// ---------------------------------------------------------------
// 40%
PROPOSER_SCORE_BOOST: 40,
REORG_HEAD_WEIGHT_THRESHOLD: 20,
REORG_PARENT_WEIGHT_THRESHOLD: 160,
REORG_MAX_EPOCHS_SINCE_FINALIZATION: 2,

// Deposit contract
// ---------------------------------------------------------------
Expand Down
6 changes: 6 additions & 0 deletions packages/config/src/chainConfig/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ export type ChainConfig = {

// Fork choice
PROPOSER_SCORE_BOOST: number;
REORG_HEAD_WEIGHT_THRESHOLD: number;
REORG_PARENT_WEIGHT_THRESHOLD: number;
REORG_MAX_EPOCHS_SINCE_FINALIZATION: number;

// Deposit contract
DEPOSIT_CHAIN_ID: number;
Expand Down Expand Up @@ -114,6 +117,9 @@ export const chainConfigTypes: SpecTypes<ChainConfig> = {

// Fork choice
PROPOSER_SCORE_BOOST: "number",
REORG_HEAD_WEIGHT_THRESHOLD: "number",
REORG_PARENT_WEIGHT_THRESHOLD: "number",
REORG_MAX_EPOCHS_SINCE_FINALIZATION: "number",

// Deposit contract
DEPOSIT_CHAIN_ID: "number",
Expand Down
Loading
Loading