@lodestar/fork-choice 1.44.0-dev.8793c24169 → 1.44.0-dev.8d5a6a4fc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/forkChoice/fastConfirmation/data.d.ts +4 -0
- package/lib/forkChoice/fastConfirmation/data.d.ts.map +1 -0
- package/lib/forkChoice/fastConfirmation/data.js +31 -0
- package/lib/forkChoice/fastConfirmation/data.js.map +1 -0
- package/lib/forkChoice/fastConfirmation/fastConfirmationRule.d.ts +17 -0
- package/lib/forkChoice/fastConfirmation/fastConfirmationRule.d.ts.map +1 -0
- package/lib/forkChoice/fastConfirmation/fastConfirmationRule.js +129 -0
- package/lib/forkChoice/fastConfirmation/fastConfirmationRule.js.map +1 -0
- package/lib/forkChoice/fastConfirmation/index.d.ts +4 -0
- package/lib/forkChoice/fastConfirmation/index.d.ts.map +1 -0
- package/lib/forkChoice/fastConfirmation/index.js +4 -0
- package/lib/forkChoice/fastConfirmation/index.js.map +1 -0
- package/lib/forkChoice/fastConfirmation/metrics.d.ts +21 -0
- package/lib/forkChoice/fastConfirmation/metrics.d.ts.map +1 -0
- package/lib/forkChoice/fastConfirmation/metrics.js +42 -0
- package/lib/forkChoice/fastConfirmation/metrics.js.map +1 -0
- package/lib/forkChoice/fastConfirmation/rules.d.ts +9 -0
- package/lib/forkChoice/fastConfirmation/rules.d.ts.map +1 -0
- package/lib/forkChoice/fastConfirmation/rules.js +91 -0
- package/lib/forkChoice/fastConfirmation/rules.js.map +1 -0
- package/lib/forkChoice/fastConfirmation/types.d.ts +101 -0
- package/lib/forkChoice/fastConfirmation/types.d.ts.map +1 -0
- package/lib/forkChoice/fastConfirmation/types.js +12 -0
- package/lib/forkChoice/fastConfirmation/types.js.map +1 -0
- package/lib/forkChoice/fastConfirmation/utils.d.ts +47 -0
- package/lib/forkChoice/fastConfirmation/utils.d.ts.map +1 -0
- package/lib/forkChoice/fastConfirmation/utils.js +681 -0
- package/lib/forkChoice/fastConfirmation/utils.js.map +1 -0
- package/lib/forkChoice/forkChoice.d.ts +18 -0
- package/lib/forkChoice/forkChoice.d.ts.map +1 -1
- package/lib/forkChoice/forkChoice.js +111 -5
- package/lib/forkChoice/forkChoice.js.map +1 -1
- package/lib/forkChoice/interface.d.ts +14 -0
- package/lib/forkChoice/interface.d.ts.map +1 -1
- package/lib/forkChoice/safeBlocks.d.ts +2 -6
- package/lib/forkChoice/safeBlocks.d.ts.map +1 -1
- package/lib/forkChoice/safeBlocks.js +15 -7
- package/lib/forkChoice/safeBlocks.js.map +1 -1
- package/lib/forkChoice/store.d.ts +33 -2
- package/lib/forkChoice/store.d.ts.map +1 -1
- package/lib/forkChoice/store.js +37 -1
- package/lib/forkChoice/store.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/metrics.d.ts +12 -1
- package/lib/metrics.d.ts.map +1 -1
- package/lib/metrics.js +2 -0
- package/lib/metrics.js.map +1 -1
- package/lib/protoArray/protoArray.d.ts +23 -1
- package/lib/protoArray/protoArray.d.ts.map +1 -1
- package/lib/protoArray/protoArray.js +50 -4
- package/lib/protoArray/protoArray.js.map +1 -1
- package/package.json +7 -7
- package/src/forkChoice/fastConfirmation/data.ts +43 -0
- package/src/forkChoice/fastConfirmation/fastConfirmationRule.ts +159 -0
- package/src/forkChoice/fastConfirmation/index.ts +3 -0
- package/src/forkChoice/fastConfirmation/metrics.ts +44 -0
- package/src/forkChoice/fastConfirmation/rules.ts +124 -0
- package/src/forkChoice/fastConfirmation/types.ts +111 -0
- package/src/forkChoice/fastConfirmation/utils.ts +968 -0
- package/src/forkChoice/forkChoice.ts +139 -6
- package/src/forkChoice/interface.ts +15 -0
- package/src/forkChoice/safeBlocks.ts +15 -7
- package/src/forkChoice/store.ts +45 -1
- package/src/index.ts +11 -0
- package/src/metrics.ts +3 -1
- package/src/protoArray/protoArray.ts +60 -4
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import {EffectiveBalanceIncrements, IBeaconStateView} from "@lodestar/state-transition";
|
|
2
|
+
import {Epoch, RootHex, Slot, ValidatorIndex} from "@lodestar/types";
|
|
3
|
+
import {Logger} from "@lodestar/utils";
|
|
4
|
+
import {ProtoBlock} from "../../protoArray/interface.ts";
|
|
5
|
+
import {CheckpointWithHex} from "../store.ts";
|
|
6
|
+
|
|
7
|
+
export type FastConfirmationBalanceSource = {
|
|
8
|
+
state: IBeaconStateView | null;
|
|
9
|
+
balances: EffectiveBalanceIncrements;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type ForkChoiceStateGetter = (
|
|
13
|
+
opts: {stateRoot: RootHex; checkpoint?: never} | {stateRoot?: never; checkpoint: CheckpointWithHex}
|
|
14
|
+
) => IBeaconStateView | null;
|
|
15
|
+
|
|
16
|
+
type IFastConfirmationSpecStore = {
|
|
17
|
+
confirmedRoot: RootHex;
|
|
18
|
+
previousEpochObservedJustifiedCheckpoint: CheckpointWithHex;
|
|
19
|
+
currentEpochObservedJustifiedCheckpoint: CheckpointWithHex;
|
|
20
|
+
previousEpochGreatestUnrealizedCheckpoint: CheckpointWithHex;
|
|
21
|
+
previousSlotHead: RootHex;
|
|
22
|
+
currentSlotHead: RootHex;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
type IFastConfirmationAuxStore = {
|
|
26
|
+
previousEpochObservedJustifiedBalances: EffectiveBalanceIncrements;
|
|
27
|
+
currentEpochObservedJustifiedBalances: EffectiveBalanceIncrements;
|
|
28
|
+
previousEpochGreatestUnrealizedBalances: EffectiveBalanceIncrements;
|
|
29
|
+
stateGetter: ForkChoiceStateGetter;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export type IFastConfirmationStore = IFastConfirmationSpecStore & IFastConfirmationAuxStore;
|
|
33
|
+
|
|
34
|
+
export type FastConfirmationResult = {
|
|
35
|
+
confirmedRoot: RootHex;
|
|
36
|
+
didReset?: boolean;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export type FastConfirmationSnapshot = {
|
|
40
|
+
currentSlot: Slot;
|
|
41
|
+
currentEpoch: Epoch;
|
|
42
|
+
headRoot: RootHex;
|
|
43
|
+
confirmedRoot: RootHex;
|
|
44
|
+
confirmedEpoch: Epoch | null;
|
|
45
|
+
confirmedSlot: Slot | null;
|
|
46
|
+
observedJustified: CheckpointWithHex;
|
|
47
|
+
headUnrealized: CheckpointWithHex | null;
|
|
48
|
+
finalizedRoot: RootHex;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export enum FastConfirmationDecisionReason {
|
|
52
|
+
Unchanged = "unchanged",
|
|
53
|
+
ConfirmedNotFound = "confirmed_not_found",
|
|
54
|
+
ResetBehind = "reset_behind",
|
|
55
|
+
ResetNotAncestor = "reset_not_ancestor",
|
|
56
|
+
ResetChainUnsafe = "reset_chain_unsafe",
|
|
57
|
+
ObservedJustified = "observed_justified",
|
|
58
|
+
ConfirmedDescendant = "confirmed_descendant",
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export type FastConfirmationDecision = {
|
|
62
|
+
confirmedRoot: RootHex;
|
|
63
|
+
didReset: boolean;
|
|
64
|
+
reason: FastConfirmationDecisionReason;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export type FastConfirmationRule = (
|
|
68
|
+
snapshot: FastConfirmationSnapshot,
|
|
69
|
+
ctx: FastConfirmationContext,
|
|
70
|
+
store: IFastConfirmationStore,
|
|
71
|
+
cache: FastConfirmationCache,
|
|
72
|
+
decision: FastConfirmationDecision,
|
|
73
|
+
logger?: Logger
|
|
74
|
+
) => FastConfirmationDecision;
|
|
75
|
+
|
|
76
|
+
export type BalanceSourceKey = "current" | "previous";
|
|
77
|
+
|
|
78
|
+
// This cache is created once per slot
|
|
79
|
+
export type FastConfirmationCache = {
|
|
80
|
+
blockByRoot: Map<RootHex, ProtoBlock | null>;
|
|
81
|
+
ancestorRoots: Map<string, RootHex[] | null>;
|
|
82
|
+
committeeBySlot: Map<Slot, Set<ValidatorIndex>>;
|
|
83
|
+
isDescendantByRootPair: Map<string, boolean>;
|
|
84
|
+
/** voteRoot -> totalWeight, keyed by sourceKey */
|
|
85
|
+
voteWeightBySource: Map<BalanceSourceKey, Map<RootHex, number>>;
|
|
86
|
+
headState?: IBeaconStateView;
|
|
87
|
+
pulledUpHeadState?: IBeaconStateView;
|
|
88
|
+
checkpointStateByKey: Map<string, IBeaconStateView | null>;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export type FastConfirmationContext = {
|
|
92
|
+
config: {
|
|
93
|
+
CONFIRMATION_BYZANTINE_THRESHOLD: number;
|
|
94
|
+
PROPOSER_SCORE_BOOST: number;
|
|
95
|
+
};
|
|
96
|
+
getCurrentSlot(): Slot;
|
|
97
|
+
getHead(): ProtoBlock;
|
|
98
|
+
getBlock(root: RootHex): ProtoBlock | null;
|
|
99
|
+
getAncestor(root: RootHex, slot: Slot): RootHex;
|
|
100
|
+
isDescendant(ancestor: RootHex, descendant: RootHex): boolean;
|
|
101
|
+
getLatestMessage(validatorIndex: ValidatorIndex): {root: RootHex; epoch: Epoch} | null;
|
|
102
|
+
getUnrealizedJustified(): {checkpoint: CheckpointWithHex; balances: EffectiveBalanceIncrements};
|
|
103
|
+
getFinalizedCheckpoint(): CheckpointWithHex;
|
|
104
|
+
getEquivocatingIndices(): Set<ValidatorIndex>;
|
|
105
|
+
getTrackedVotesCount(): number;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export interface IFastConfirmationRule {
|
|
109
|
+
getConfirmedRoot(): RootHex;
|
|
110
|
+
onSlotStartAfterPastAttestationsApplied(ctx: FastConfirmationContext): FastConfirmationResult;
|
|
111
|
+
}
|