@lodestar/fork-choice 1.44.0-dev.985999b30c → 1.44.0-dev.a879adb124

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.
Files changed (70) hide show
  1. package/lib/forkChoice/fastConfirmation/data.d.ts +4 -0
  2. package/lib/forkChoice/fastConfirmation/data.d.ts.map +1 -0
  3. package/lib/forkChoice/fastConfirmation/data.js +31 -0
  4. package/lib/forkChoice/fastConfirmation/data.js.map +1 -0
  5. package/lib/forkChoice/fastConfirmation/fastConfirmationRule.d.ts +17 -0
  6. package/lib/forkChoice/fastConfirmation/fastConfirmationRule.d.ts.map +1 -0
  7. package/lib/forkChoice/fastConfirmation/fastConfirmationRule.js +129 -0
  8. package/lib/forkChoice/fastConfirmation/fastConfirmationRule.js.map +1 -0
  9. package/lib/forkChoice/fastConfirmation/index.d.ts +4 -0
  10. package/lib/forkChoice/fastConfirmation/index.d.ts.map +1 -0
  11. package/lib/forkChoice/fastConfirmation/index.js +4 -0
  12. package/lib/forkChoice/fastConfirmation/index.js.map +1 -0
  13. package/lib/forkChoice/fastConfirmation/metrics.d.ts +21 -0
  14. package/lib/forkChoice/fastConfirmation/metrics.d.ts.map +1 -0
  15. package/lib/forkChoice/fastConfirmation/metrics.js +42 -0
  16. package/lib/forkChoice/fastConfirmation/metrics.js.map +1 -0
  17. package/lib/forkChoice/fastConfirmation/rules.d.ts +9 -0
  18. package/lib/forkChoice/fastConfirmation/rules.d.ts.map +1 -0
  19. package/lib/forkChoice/fastConfirmation/rules.js +91 -0
  20. package/lib/forkChoice/fastConfirmation/rules.js.map +1 -0
  21. package/lib/forkChoice/fastConfirmation/types.d.ts +101 -0
  22. package/lib/forkChoice/fastConfirmation/types.d.ts.map +1 -0
  23. package/lib/forkChoice/fastConfirmation/types.js +12 -0
  24. package/lib/forkChoice/fastConfirmation/types.js.map +1 -0
  25. package/lib/forkChoice/fastConfirmation/utils.d.ts +47 -0
  26. package/lib/forkChoice/fastConfirmation/utils.d.ts.map +1 -0
  27. package/lib/forkChoice/fastConfirmation/utils.js +681 -0
  28. package/lib/forkChoice/fastConfirmation/utils.js.map +1 -0
  29. package/lib/forkChoice/forkChoice.d.ts +23 -3
  30. package/lib/forkChoice/forkChoice.d.ts.map +1 -1
  31. package/lib/forkChoice/forkChoice.js +116 -9
  32. package/lib/forkChoice/forkChoice.js.map +1 -1
  33. package/lib/forkChoice/interface.d.ts +19 -7
  34. package/lib/forkChoice/interface.d.ts.map +1 -1
  35. package/lib/forkChoice/interface.js.map +1 -1
  36. package/lib/forkChoice/safeBlocks.d.ts +2 -6
  37. package/lib/forkChoice/safeBlocks.d.ts.map +1 -1
  38. package/lib/forkChoice/safeBlocks.js +15 -7
  39. package/lib/forkChoice/safeBlocks.js.map +1 -1
  40. package/lib/forkChoice/store.d.ts +13 -2
  41. package/lib/forkChoice/store.d.ts.map +1 -1
  42. package/lib/forkChoice/store.js +29 -1
  43. package/lib/forkChoice/store.js.map +1 -1
  44. package/lib/index.d.ts +1 -0
  45. package/lib/index.d.ts.map +1 -1
  46. package/lib/index.js +1 -0
  47. package/lib/index.js.map +1 -1
  48. package/lib/metrics.d.ts +12 -1
  49. package/lib/metrics.d.ts.map +1 -1
  50. package/lib/metrics.js +2 -0
  51. package/lib/metrics.js.map +1 -1
  52. package/lib/protoArray/protoArray.d.ts +67 -20
  53. package/lib/protoArray/protoArray.d.ts.map +1 -1
  54. package/lib/protoArray/protoArray.js +170 -38
  55. package/lib/protoArray/protoArray.js.map +1 -1
  56. package/package.json +7 -7
  57. package/src/forkChoice/fastConfirmation/data.ts +43 -0
  58. package/src/forkChoice/fastConfirmation/fastConfirmationRule.ts +159 -0
  59. package/src/forkChoice/fastConfirmation/index.ts +3 -0
  60. package/src/forkChoice/fastConfirmation/metrics.ts +44 -0
  61. package/src/forkChoice/fastConfirmation/rules.ts +124 -0
  62. package/src/forkChoice/fastConfirmation/types.ts +111 -0
  63. package/src/forkChoice/fastConfirmation/utils.ts +968 -0
  64. package/src/forkChoice/forkChoice.ts +150 -10
  65. package/src/forkChoice/interface.ts +36 -7
  66. package/src/forkChoice/safeBlocks.ts +15 -7
  67. package/src/forkChoice/store.ts +34 -1
  68. package/src/index.ts +11 -0
  69. package/src/metrics.ts +3 -1
  70. package/src/protoArray/protoArray.ts +184 -41
@@ -0,0 +1,4 @@
1
+ import { FastConfirmationCache, FastConfirmationContext, FastConfirmationSnapshot, IFastConfirmationStore } from "./types.ts";
2
+ export declare function createFastConfirmationCache(): FastConfirmationCache;
3
+ export declare function buildFastConfirmationSnapshot(ctx: FastConfirmationContext, store: IFastConfirmationStore, cache: FastConfirmationCache): FastConfirmationSnapshot;
4
+ //# sourceMappingURL=data.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../../../src/forkChoice/fastConfirmation/data.ts"],"names":[],"mappings":"AACA,OAAO,EACL,qBAAqB,EACrB,uBAAuB,EACvB,wBAAwB,EACxB,sBAAsB,EACvB,MAAM,YAAY,CAAC;AAGpB,wBAAgB,2BAA2B,IAAI,qBAAqB,CASnE;AAED,wBAAgB,6BAA6B,CAC3C,GAAG,EAAE,uBAAuB,EAC5B,KAAK,EAAE,sBAAsB,EAC7B,KAAK,EAAE,qBAAqB,GAC3B,wBAAwB,CAkB1B"}
@@ -0,0 +1,31 @@
1
+ import { computeEpochAtSlot } from "@lodestar/state-transition";
2
+ import { getBlock, getUnrealizedJustification } from "./utils.js";
3
+ export function createFastConfirmationCache() {
4
+ return {
5
+ blockByRoot: new Map(),
6
+ ancestorRoots: new Map(),
7
+ committeeBySlot: new Map(),
8
+ isDescendantByRootPair: new Map(),
9
+ voteWeightBySource: new Map(),
10
+ checkpointStateByKey: new Map(),
11
+ };
12
+ }
13
+ export function buildFastConfirmationSnapshot(ctx, store, cache) {
14
+ const currentSlot = ctx.getCurrentSlot();
15
+ const currentEpoch = computeEpochAtSlot(currentSlot);
16
+ const headRoot = ctx.getHead().blockRoot;
17
+ const confirmedRoot = store.confirmedRoot;
18
+ const confirmedBlock = getBlock(ctx, cache, confirmedRoot);
19
+ return {
20
+ currentSlot,
21
+ currentEpoch,
22
+ headRoot,
23
+ confirmedRoot,
24
+ confirmedEpoch: confirmedBlock ? computeEpochAtSlot(confirmedBlock.slot) : null,
25
+ confirmedSlot: confirmedBlock?.slot ?? null,
26
+ observedJustified: store.currentEpochObservedJustifiedCheckpoint,
27
+ headUnrealized: getUnrealizedJustification(ctx, cache, headRoot),
28
+ finalizedRoot: ctx.getFinalizedCheckpoint().rootHex,
29
+ };
30
+ }
31
+ //# sourceMappingURL=data.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data.js","sourceRoot":"","sources":["../../../src/forkChoice/fastConfirmation/data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAC,MAAM,4BAA4B,CAAC;AAO9D,OAAO,EAAC,QAAQ,EAAE,0BAA0B,EAAC,MAAM,YAAY,CAAC;AAEhE,MAAM,UAAU,2BAA2B,GAA0B;IACnE,OAAO;QACL,WAAW,EAAE,IAAI,GAAG,EAAE;QACtB,aAAa,EAAE,IAAI,GAAG,EAAE;QACxB,eAAe,EAAE,IAAI,GAAG,EAAE;QAC1B,sBAAsB,EAAE,IAAI,GAAG,EAAE;QACjC,kBAAkB,EAAE,IAAI,GAAG,EAAE;QAC7B,oBAAoB,EAAE,IAAI,GAAG,EAAE;KAChC,CAAC;AAAA,CACH;AAED,MAAM,UAAU,6BAA6B,CAC3C,GAA4B,EAC5B,KAA6B,EAC7B,KAA4B,EACF;IAC1B,MAAM,WAAW,GAAG,GAAG,CAAC,cAAc,EAAE,CAAC;IACzC,MAAM,YAAY,GAAG,kBAAkB,CAAC,WAAW,CAAC,CAAC;IACrD,MAAM,QAAQ,GAAG,GAAG,CAAC,OAAO,EAAE,CAAC,SAAS,CAAC;IACzC,MAAM,aAAa,GAAG,KAAK,CAAC,aAAa,CAAC;IAC1C,MAAM,cAAc,GAAG,QAAQ,CAAC,GAAG,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC;IAE3D,OAAO;QACL,WAAW;QACX,YAAY;QACZ,QAAQ;QACR,aAAa;QACb,cAAc,EAAE,cAAc,CAAC,CAAC,CAAC,kBAAkB,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI;QAC/E,aAAa,EAAE,cAAc,EAAE,IAAI,IAAI,IAAI;QAC3C,iBAAiB,EAAE,KAAK,CAAC,uCAAuC;QAChE,cAAc,EAAE,0BAA0B,CAAC,GAAG,EAAE,KAAK,EAAE,QAAQ,CAAC;QAChE,aAAa,EAAE,GAAG,CAAC,sBAAsB,EAAE,CAAC,OAAO;KACpD,CAAC;AAAA,CACH"}
@@ -0,0 +1,17 @@
1
+ import { RootHex } from "@lodestar/types";
2
+ import { Logger } from "@lodestar/utils";
3
+ import { FastConfirmationMetrics } from "./metrics.ts";
4
+ import { FastConfirmationContext, FastConfirmationResult, IFastConfirmationRule, IFastConfirmationStore } from "./types.ts";
5
+ export * from "./metrics.ts";
6
+ export * from "./types.ts";
7
+ export declare class FastConfirmationRule implements IFastConfirmationRule {
8
+ private readonly store;
9
+ readonly metrics: FastConfirmationMetrics | null;
10
+ readonly logger?: Logger | undefined;
11
+ constructor(store: IFastConfirmationStore, metrics: FastConfirmationMetrics | null, logger?: Logger | undefined);
12
+ getConfirmedRoot(): RootHex;
13
+ onSlotStartAfterPastAttestationsApplied(ctx: FastConfirmationContext): FastConfirmationResult;
14
+ private updateFastConfirmationVariables;
15
+ private updateFastConfirmationMetrics;
16
+ }
17
+ //# sourceMappingURL=fastConfirmationRule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fastConfirmationRule.d.ts","sourceRoot":"","sources":["../../../src/forkChoice/fastConfirmation/fastConfirmationRule.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,OAAO,EAAC,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAC,MAAM,EAAuB,MAAM,iBAAiB,CAAC;AAE7D,OAAO,EAAC,uBAAuB,EAAwB,MAAM,cAAc,CAAC;AAE5E,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACtB,qBAAqB,EACrB,sBAAsB,EACvB,MAAM,YAAY,CAAC;AAEpB,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAE3B,qBAAa,oBAAqB,YAAW,qBAAqB;IAE9D,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,QAAQ,CAAC,OAAO,EAAE,uBAAuB,GAAG,IAAI;IAChD,QAAQ,CAAC,MAAM,CAAC;IAHlB,YACmB,KAAK,EAAE,sBAAsB,EACrC,OAAO,EAAE,uBAAuB,GAAG,IAAI,EACvC,MAAM,CAAC,oBAAQ,EACtB;IAEJ,gBAAgB,IAAI,OAAO,CAE1B;IAED,uCAAuC,CAAC,GAAG,EAAE,uBAAuB,GAAG,sBAAsB,CAqE5F;IAED,OAAO,CAAC,+BAA+B;IAgDvC,OAAO,CAAC,6BAA6B;CAYtC"}
@@ -0,0 +1,129 @@
1
+ import { computeEpochAtSlot, isStartSlotOfEpoch } from "@lodestar/state-transition";
2
+ import { withObservedDuration } from "@lodestar/utils";
3
+ import { buildFastConfirmationSnapshot, createFastConfirmationCache } from "./data.js";
4
+ import { FastConfirmationSteps } from "./metrics.js";
5
+ import { runFastConfirmationRules } from "./rules.js";
6
+ export * from "./metrics.js";
7
+ export * from "./types.js";
8
+ export class FastConfirmationRule {
9
+ store;
10
+ metrics;
11
+ logger;
12
+ constructor(store, metrics, logger) {
13
+ this.store = store;
14
+ this.metrics = metrics;
15
+ this.logger = logger;
16
+ }
17
+ getConfirmedRoot() {
18
+ return this.store.confirmedRoot;
19
+ }
20
+ onSlotStartAfterPastAttestationsApplied(ctx) {
21
+ const currentSlot = ctx.getCurrentSlot();
22
+ const previousConfirmedRoot = this.store.confirmedRoot;
23
+ this.logger?.debug("Running fast confirmation rule", {
24
+ slot: currentSlot,
25
+ epoch: computeEpochAtSlot(currentSlot),
26
+ });
27
+ this.updateFastConfirmationVariables(ctx);
28
+ const cache = withObservedDuration(this.metrics?.fastConfirmation.stepsDuration.startTimer({
29
+ step: FastConfirmationSteps.buildCache,
30
+ }), createFastConfirmationCache);
31
+ const snapshot = withObservedDuration(this.metrics?.fastConfirmation.stepsDuration.startTimer({
32
+ step: FastConfirmationSteps.buildSnapshot,
33
+ }), () => buildFastConfirmationSnapshot(ctx, this.store, cache));
34
+ this.logger?.verbose("Built fast confirmation snapshot", {
35
+ confirmedSlot: snapshot.confirmedSlot,
36
+ confirmedEpoch: snapshot.confirmedEpoch,
37
+ confirmedRoot: snapshot.confirmedRoot,
38
+ headRoot: snapshot.headRoot,
39
+ finalizedRoot: snapshot.finalizedRoot,
40
+ headUnrealizedRoot: snapshot.headUnrealized?.rootHex,
41
+ headUnrealizedEpoch: snapshot.headUnrealized?.epoch,
42
+ observedJustifiedRoot: snapshot.observedJustified.rootHex,
43
+ observedJustifiedEpoch: snapshot.observedJustified.epoch,
44
+ });
45
+ const { confirmedRoot, didReset, reason } = withObservedDuration(this.metrics?.fastConfirmation.stepsDuration.startTimer({ step: FastConfirmationSteps.runRules }), () => runFastConfirmationRules(snapshot, ctx, this.store, cache, this.logger));
46
+ const changed = confirmedRoot !== previousConfirmedRoot;
47
+ const confirmedBlock = cache.blockByRoot.get(confirmedRoot) ?? null;
48
+ const confirmedSlot = confirmedBlock?.slot ?? null;
49
+ const confirmedEpoch = confirmedBlock ? computeEpochAtSlot(confirmedBlock.slot) : null;
50
+ const logContext = {
51
+ previousConfirmedRoot,
52
+ confirmedRoot,
53
+ changed,
54
+ didReset,
55
+ reason,
56
+ confirmedSlot,
57
+ confirmedEpoch,
58
+ };
59
+ if (changed) {
60
+ if (didReset) {
61
+ this.logger?.warn("Reset fast confirmation", logContext);
62
+ }
63
+ else {
64
+ this.logger?.debug("Updated fast confirmation", logContext);
65
+ }
66
+ }
67
+ else {
68
+ this.logger?.debug("Unchanged fast confirmation", logContext);
69
+ }
70
+ this.store.confirmedRoot = confirmedRoot;
71
+ this.updateFastConfirmationMetrics(ctx, { confirmedRoot, didReset });
72
+ return { confirmedRoot, didReset };
73
+ }
74
+ updateFastConfirmationVariables(ctx) {
75
+ const previousSlotHead = this.store.currentSlotHead;
76
+ const currentSlotHead = ctx.getHead().blockRoot;
77
+ const currentSlot = ctx.getCurrentSlot();
78
+ const isStartSlotOfCurrentEpoch = isStartSlotOfEpoch(currentSlot);
79
+ const isLastSlotOfCurrentEpoch = isStartSlotOfEpoch(currentSlot + 1);
80
+ this.store.previousSlotHead = previousSlotHead;
81
+ this.store.currentSlotHead = currentSlotHead;
82
+ this.logger?.verbose("Updating fast confirmation variables", {
83
+ previousSlotHead,
84
+ currentSlotHead,
85
+ currentSlot,
86
+ isStartSlotOfCurrentEpoch,
87
+ isLastSlotOfCurrentEpoch,
88
+ });
89
+ // Spec step 1: freeze the greatest unrealized justified checkpoint at the
90
+ // last slot of the epoch so the next epoch consumes a stable snapshot.
91
+ if (isLastSlotOfCurrentEpoch) {
92
+ const unrealized = ctx.getUnrealizedJustified();
93
+ this.store.previousEpochGreatestUnrealizedCheckpoint = unrealized.checkpoint;
94
+ this.store.previousEpochGreatestUnrealizedBalances = unrealized.balances;
95
+ this.logger?.verbose("Updated fast confirmation greatest unrealized snapshot", {
96
+ previousEpochGreatestUnrealizedCheckpointRoot: this.store.previousEpochGreatestUnrealizedCheckpoint.rootHex,
97
+ previousEpochGreatestUnrealizedCheckpointEpoch: this.store.previousEpochGreatestUnrealizedCheckpoint.epoch,
98
+ });
99
+ }
100
+ // Spec step 2: rotate observed justified checkpoints at the first slot of
101
+ // the new epoch using the snapshot taken at the end of the previous epoch.
102
+ if (isStartSlotOfCurrentEpoch) {
103
+ this.store.previousEpochObservedJustifiedCheckpoint = this.store.currentEpochObservedJustifiedCheckpoint;
104
+ this.store.previousEpochObservedJustifiedBalances = this.store.currentEpochObservedJustifiedBalances;
105
+ this.store.currentEpochObservedJustifiedCheckpoint = this.store.previousEpochGreatestUnrealizedCheckpoint;
106
+ this.store.currentEpochObservedJustifiedBalances = this.store.previousEpochGreatestUnrealizedBalances;
107
+ this.logger?.verbose("Updated fast confirmation observed justified checkpoints", {
108
+ previousEpochObservedJustifiedCheckpointRoot: this.store.previousEpochObservedJustifiedCheckpoint.rootHex,
109
+ previousEpochObservedJustifiedCheckpointEpoch: this.store.previousEpochObservedJustifiedCheckpoint.epoch,
110
+ currentEpochObservedJustifiedCheckpointRoot: this.store.currentEpochObservedJustifiedCheckpoint.rootHex,
111
+ currentEpochObservedJustifiedCheckpointEpoch: this.store.currentEpochObservedJustifiedCheckpoint.epoch,
112
+ });
113
+ }
114
+ }
115
+ updateFastConfirmationMetrics(ctx, result) {
116
+ if (!this.metrics)
117
+ return;
118
+ const confirmedBlock = ctx.getBlock(result.confirmedRoot);
119
+ if (confirmedBlock) {
120
+ this.metrics.fastConfirmation.confirmedSlot.set(confirmedBlock.slot);
121
+ this.metrics.fastConfirmation.confirmedEpoch.set(computeEpochAtSlot(confirmedBlock.slot));
122
+ }
123
+ if (result.didReset) {
124
+ this.metrics.fastConfirmation.resets.inc();
125
+ }
126
+ this.metrics.fastConfirmation.votesTracked.set(ctx.getTrackedVotesCount());
127
+ }
128
+ }
129
+ //# sourceMappingURL=fastConfirmationRule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fastConfirmationRule.js","sourceRoot":"","sources":["../../../src/forkChoice/fastConfirmation/fastConfirmationRule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAE,kBAAkB,EAAC,MAAM,4BAA4B,CAAC;AAElF,OAAO,EAAS,oBAAoB,EAAC,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAC,6BAA6B,EAAE,2BAA2B,EAAC,MAAM,WAAW,CAAC;AACrF,OAAO,EAA0B,qBAAqB,EAAC,MAAM,cAAc,CAAC;AAC5E,OAAO,EAAC,wBAAwB,EAAC,MAAM,YAAY,CAAC;AAQpD,cAAc,cAAc,CAAC;AAC7B,c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,gBAAgB,CAAC,aAAa,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;YACrE,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,cAAc,CAAC,GAAG,CAAC,kBAAkB,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC;QAC5F,CAAC;QACD,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;YACpB,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC;QAC7C,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,oBAAoB,EAAE,CAAC,CAAC;IAAA,CAC5E;CACF"}
@@ -0,0 +1,4 @@
1
+ export * from "./fastConfirmationRule.ts";
2
+ export * from "./metrics.ts";
3
+ export * from "./types.ts";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/forkChoice/fastConfirmation/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from "./fastConfirmationRule.js";
2
+ export * from "./metrics.js";
3
+ export * from "./types.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/forkChoice/fastConfirmation/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC"}
@@ -0,0 +1,21 @@
1
+ import { MetricsRegisterExtra } from "@lodestar/utils";
2
+ export type FastConfirmationMetrics = ReturnType<typeof getFastConfirmationMetrics>;
3
+ export declare enum FastConfirmationSteps {
4
+ updateHead = "updateHead",
5
+ buildCache = "buildCache",
6
+ buildSnapshot = "buildSnapshot",
7
+ runRules = "runRules"
8
+ }
9
+ export declare function getFastConfirmationMetrics(register: MetricsRegisterExtra): {
10
+ fastConfirmation: {
11
+ totalDuration: import("@lodestar/utils").Histogram<import("@lodestar/utils").NoLabels>;
12
+ stepsDuration: import("@lodestar/utils").Histogram<{
13
+ step: FastConfirmationSteps;
14
+ }>;
15
+ confirmedEpoch: import("@lodestar/utils").GaugeExtra<import("@lodestar/utils").NoLabels>;
16
+ confirmedSlot: import("@lodestar/utils").GaugeExtra<import("@lodestar/utils").NoLabels>;
17
+ votesTracked: import("@lodestar/utils").GaugeExtra<import("@lodestar/utils").NoLabels>;
18
+ resets: import("@lodestar/utils").GaugeExtra<import("@lodestar/utils").NoLabels>;
19
+ };
20
+ };
21
+ //# sourceMappingURL=metrics.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../../../src/forkChoice/fastConfirmation/metrics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,oBAAoB,EAAC,MAAM,iBAAiB,CAAC;AAErD,MAAM,MAAM,uBAAuB,GAAG,UAAU,CAAC,OAAO,0BAA0B,CAAC,CAAC;AAEpF,oBAAY,qBAAqB;IAC/B,UAAU,eAAe;IACzB,UAAU,eAAe;IACzB,aAAa,kBAAkB;IAC/B,QAAQ,aAAa;CACtB;AAED,wBAAgB,0BAA0B,CAAC,QAAQ,EAAE,oBAAoB;;;;;;;;;;;EAgCxE"}
@@ -0,0 +1,42 @@
1
+ export { FastConfirmationSteps };
2
+ var FastConfirmationSteps;
3
+ (function (FastConfirmationSteps) {
4
+ FastConfirmationSteps["updateHead"] = "updateHead";
5
+ FastConfirmationSteps["buildCache"] = "buildCache";
6
+ FastConfirmationSteps["buildSnapshot"] = "buildSnapshot";
7
+ FastConfirmationSteps["runRules"] = "runRules";
8
+ })(FastConfirmationSteps || (FastConfirmationSteps = {}));
9
+ export function getFastConfirmationMetrics(register) {
10
+ return {
11
+ fastConfirmation: {
12
+ totalDuration: register.histogram({
13
+ name: "lodestar_fast_confirmation_duration_seconds",
14
+ help: "Time to run Fast Confirmation Rule algorithm",
15
+ buckets: [0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1, 2],
16
+ }),
17
+ stepsDuration: register.histogram({
18
+ name: "lodestar_fast_confirmation_steps_duration_seconds",
19
+ help: "Time to run Fast Confirmation Steps",
20
+ buckets: [0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1, 2],
21
+ labelNames: ["step"],
22
+ }),
23
+ confirmedEpoch: register.gauge({
24
+ name: "lodestar_fast_confirmation_confirmed_epoch",
25
+ help: "Current confirmed epoch from fast confirmation",
26
+ }),
27
+ confirmedSlot: register.gauge({
28
+ name: "lodestar_fast_confirmation_confirmed_slot",
29
+ help: "Current confirmed slot from fast confirmation",
30
+ }),
31
+ votesTracked: register.gauge({
32
+ name: "lodestar_fast_confirmation_votes_tracked",
33
+ help: "Number of checkpoint votes tracked by fast confirmation",
34
+ }),
35
+ resets: register.gauge({
36
+ name: "lodestar_fast_confirmation_resets_total",
37
+ help: "Count of fast confirmation resets due to reorgs",
38
+ }),
39
+ },
40
+ };
41
+ }
42
+ //# sourceMappingURL=metrics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metrics.js","sourceRoot":"","sources":["../../../src/forkChoice/fastConfirmation/metrics.ts"],"names":[],"mappings":"SAIY,qBAAqB;AAAjC,IAAY,qBAKX;AALD,WAAY,qBAAqB;IAC/B,kDAAyB,CAAA;IACzB,kDAAyB,CAAA;IACzB,wDAA+B,CAAA;IAC/B,8CAAqB,CAAA;AAAC,CACxB,EALY,qBAAqB,KAArB,qBAAqB,QAKhC;AAED,MAAM,UAAU,0BAA0B,CAAC,QAA8B,EAAE;IACzE,OAAO;QACL,gBAAgB,EAAE;YAChB,aAAa,EAAE,QAAQ,CAAC,SAAS,CAAC;gBAChC,IAAI,EAAE,6CAA6C;gBACnD,IAAI,EAAE,8CAA8C;gBACpD,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;aACpD,CAAC;YACF,aAAa,EAAE,QAAQ,CAAC,SAAS,CAAgC;gBAC/D,IAAI,EAAE,mDAAmD;gBACzD,IAAI,EAAE,qCAAqC;gBAC3C,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;gBACnD,UAAU,EAAE,CAAC,MAAM,CAAC;aACrB,CAAC;YACF,cAAc,EAAE,QAAQ,CAAC,KAAK,CAAC;gBAC7B,IAAI,EAAE,4CAA4C;gBAClD,IAAI,EAAE,gDAAgD;aACvD,CAAC;YACF,aAAa,EAAE,QAAQ,CAAC,KAAK,CAAC;gBAC5B,IAAI,EAAE,2CAA2C;gBACjD,IAAI,EAAE,+CAA+C;aACtD,CAAC;YACF,YAAY,EAAE,QAAQ,CAAC,KAAK,CAAC;gBAC3B,IAAI,EAAE,0CAA0C;gBAChD,IAAI,EAAE,yDAAyD;aAChE,CAAC;YACF,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC;gBACrB,IAAI,EAAE,yCAAyC;gBAC/C,IAAI,EAAE,iDAAiD;aACxD,CAAC;SACH;KACF,CAAC;AAAA,CACH"}
@@ -0,0 +1,9 @@
1
+ import { Logger } from "@lodestar/utils";
2
+ import { FastConfirmationCache, FastConfirmationContext, FastConfirmationDecision, FastConfirmationRule, FastConfirmationSnapshot, IFastConfirmationStore } from "./types.ts";
3
+ export declare const resetIfConfirmedUnavailable: FastConfirmationRule;
4
+ export declare const resetIfBehindOrNotAncestorOrUnsafe: FastConfirmationRule;
5
+ export declare const advanceIfObservedJustified: FastConfirmationRule;
6
+ export declare const advanceToLatestConfirmedDescendant: FastConfirmationRule;
7
+ export declare const FAST_CONFIRMATION_RULES: FastConfirmationRule[];
8
+ export declare function runFastConfirmationRules(snapshot: FastConfirmationSnapshot, ctx: FastConfirmationContext, store: IFastConfirmationStore, cache: FastConfirmationCache, logger?: Logger): FastConfirmationDecision;
9
+ //# sourceMappingURL=rules.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../../../src/forkChoice/fastConfirmation/rules.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,MAAM,EAAC,MAAM,iBAAiB,CAAC;AAEvC,OAAO,EACL,qBAAqB,EACrB,uBAAuB,EACvB,wBAAwB,EAExB,oBAAoB,EACpB,wBAAwB,EACxB,sBAAsB,EACvB,MAAM,YAAY,CAAC;AAGpB,eAAO,MAAM,2BAA2B,EAAE,oBAUzC,CAAC;AAEF,eAAO,MAAM,kCAAkC,EAAE,oBA4BhD,CAAC;AAEF,eAAO,MAAM,0BAA0B,EAAE,oBAkBxC,CAAC;AAEF,eAAO,MAAM,kCAAkC,EAAE,oBAmBhD,CAAC;AAEF,eAAO,MAAM,uBAAuB,EAAE,oBAAoB,EAKzD,CAAC;AAIF,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,wBAAwB,EAClC,GAAG,EAAE,uBAAuB,EAC5B,KAAK,EAAE,sBAAsB,EAC7B,KAAK,EAAE,qBAAqB,EAC5B,MAAM,CAAC,EAAE,MAAM,GACd,wBAAwB,CAW1B"}
@@ -0,0 +1,91 @@
1
+ import { computeEpochAtSlot, isStartSlotOfEpoch } from "@lodestar/state-transition";
2
+ import { equalCheckpointWithHex } from "../store.js";
3
+ import { FastConfirmationDecisionReason, } from "./types.js";
4
+ import { findLatestConfirmedDescendant, getBlock, isAncestor, isConfirmedChainSafe } from "./utils.js";
5
+ export const resetIfConfirmedUnavailable = (snapshot, ctx, _store, cache, decision) => {
6
+ const confirmedBlock = getBlock(ctx, cache, decision.confirmedRoot);
7
+ if (!confirmedBlock) {
8
+ return {
9
+ confirmedRoot: snapshot.finalizedRoot,
10
+ didReset: true,
11
+ reason: FastConfirmationDecisionReason.ConfirmedNotFound,
12
+ };
13
+ }
14
+ return decision;
15
+ };
16
+ export const resetIfBehindOrNotAncestorOrUnsafe = (snapshot, ctx, store, cache, decision, logger) => {
17
+ const confirmedBlock = getBlock(ctx, cache, decision.confirmedRoot);
18
+ if (!confirmedBlock)
19
+ return decision;
20
+ const confirmedEpoch = computeEpochAtSlot(confirmedBlock.slot);
21
+ const confirmedEpochBehindHead = confirmedEpoch + 1 < snapshot.currentEpoch;
22
+ const notAncestorOfHead = !isAncestor(ctx, cache, snapshot.headRoot, decision.confirmedRoot);
23
+ const allChildrenNotConfirmed = isStartSlotOfEpoch(snapshot.currentSlot) &&
24
+ !isConfirmedChainSafe(ctx, store, cache, decision.confirmedRoot, logger);
25
+ if (confirmedEpochBehindHead || notAncestorOfHead || allChildrenNotConfirmed) {
26
+ const didReset = decision.didReset || decision.confirmedRoot !== snapshot.finalizedRoot;
27
+ const reason = confirmedEpochBehindHead
28
+ ? FastConfirmationDecisionReason.ResetBehind
29
+ : notAncestorOfHead
30
+ ? FastConfirmationDecisionReason.ResetNotAncestor
31
+ : FastConfirmationDecisionReason.ResetChainUnsafe;
32
+ return { confirmedRoot: snapshot.finalizedRoot, didReset, reason };
33
+ }
34
+ return decision;
35
+ };
36
+ export const advanceIfObservedJustified = (snapshot, ctx, store, cache, decision) => {
37
+ if (!isStartSlotOfEpoch(snapshot.currentSlot))
38
+ return decision;
39
+ if (store.currentEpochObservedJustifiedCheckpoint.epoch + 1 !== snapshot.currentEpoch)
40
+ return decision;
41
+ if (!snapshot.headUnrealized)
42
+ return decision;
43
+ if (!equalCheckpointWithHex(store.currentEpochObservedJustifiedCheckpoint, snapshot.headUnrealized))
44
+ return decision;
45
+ const observedBlock = getBlock(ctx, cache, store.currentEpochObservedJustifiedCheckpoint.rootHex);
46
+ if (!observedBlock || computeEpochAtSlot(observedBlock.slot) + 1 < snapshot.currentEpoch)
47
+ return decision;
48
+ const confirmedSlot = getBlock(ctx, cache, decision.confirmedRoot)?.slot ?? null;
49
+ const observedSlot = observedBlock.slot;
50
+ if (confirmedSlot !== null && observedSlot !== null && confirmedSlot < observedSlot) {
51
+ return {
52
+ ...decision,
53
+ confirmedRoot: store.currentEpochObservedJustifiedCheckpoint.rootHex,
54
+ reason: FastConfirmationDecisionReason.ObservedJustified,
55
+ };
56
+ }
57
+ return decision;
58
+ };
59
+ export const advanceToLatestConfirmedDescendant = (snapshot, ctx, store, cache, decision, logger) => {
60
+ const confirmedBlock = getBlock(ctx, cache, decision.confirmedRoot);
61
+ const confirmedEpoch = confirmedBlock ? computeEpochAtSlot(confirmedBlock.slot) : null;
62
+ if (confirmedEpoch !== null && confirmedEpoch + 1 >= snapshot.currentEpoch) {
63
+ const newConfirmed = findLatestConfirmedDescendant(snapshot, ctx, store, cache, decision.confirmedRoot, logger);
64
+ return {
65
+ ...decision,
66
+ confirmedRoot: newConfirmed,
67
+ reason: FastConfirmationDecisionReason.ConfirmedDescendant,
68
+ };
69
+ }
70
+ return decision;
71
+ };
72
+ export const FAST_CONFIRMATION_RULES = [
73
+ resetIfConfirmedUnavailable,
74
+ resetIfBehindOrNotAncestorOrUnsafe,
75
+ advanceIfObservedJustified,
76
+ advanceToLatestConfirmedDescendant,
77
+ ];
78
+ // Spec mapping: this rule runner implements the `get_latest_confirmed` decision flow
79
+ // over Lodestar's snapshot/store/cache abstractions.
80
+ export function runFastConfirmationRules(snapshot, ctx, store, cache, logger) {
81
+ let decision = {
82
+ confirmedRoot: snapshot.confirmedRoot,
83
+ didReset: false,
84
+ reason: FastConfirmationDecisionReason.Unchanged,
85
+ };
86
+ for (const rule of FAST_CONFIRMATION_RULES) {
87
+ decision = rule(snapshot, ctx, store, cache, decision, logger);
88
+ }
89
+ return decision;
90
+ }
91
+ //# sourceMappingURL=rules.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rules.js","sourceRoot":"","sources":["../../../src/forkChoice/fastConfirmation/rules.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAE,kBAAkB,EAAC,MA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OAAO,QAAQ,CAAC;AAAA,CACjB,CAAC;AAEF,MAAM,CAAC,MAAM,uBAAuB,GAA2B;IAC7D,2BAA2B;IAC3B,kCAAkC;IAClC,0BAA0B;IAC1B,kCAAkC;CACnC,CAAC;AAEF,qFAAqF;AACrF,qDAAqD;AACrD,MAAM,UAAU,wBAAwB,CACtC,QAAkC,EAClC,GAA4B,EAC5B,KAA6B,EAC7B,KAA4B,EAC5B,MAAe,EACW;IAC1B,IAAI,QAAQ,GAA6B;QACvC,aAAa,EAAE,QAAQ,CAAC,aAAa;QACrC,QAAQ,EAAE,KAAK;QACf,MAAM,EAAE,8BAA8B,CAAC,SAAS;KACjD,CAAC;IAEF,KAAK,MAAM,IAAI,IAAI,uBAAuB,EAAE,CAAC;QAC3C,QAAQ,GAAG,IAAI,CAAC,QAAQ,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;IACjE,CAAC;IACD,OAAO,QAAQ,CAAC;AAAA,CACjB"}
@@ -0,0 +1,101 @@
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
+ export type FastConfirmationBalanceSource = {
7
+ state: IBeaconStateView | null;
8
+ balances: EffectiveBalanceIncrements;
9
+ };
10
+ export type ForkChoiceStateGetter = (opts: {
11
+ stateRoot: RootHex;
12
+ checkpoint?: never;
13
+ } | {
14
+ stateRoot?: never;
15
+ checkpoint: CheckpointWithHex;
16
+ }) => IBeaconStateView | null;
17
+ type IFastConfirmationSpecStore = {
18
+ confirmedRoot: RootHex;
19
+ previousEpochObservedJustifiedCheckpoint: CheckpointWithHex;
20
+ currentEpochObservedJustifiedCheckpoint: CheckpointWithHex;
21
+ previousEpochGreatestUnrealizedCheckpoint: CheckpointWithHex;
22
+ previousSlotHead: RootHex;
23
+ currentSlotHead: RootHex;
24
+ };
25
+ type IFastConfirmationAuxStore = {
26
+ previousEpochObservedJustifiedBalances: EffectiveBalanceIncrements;
27
+ currentEpochObservedJustifiedBalances: EffectiveBalanceIncrements;
28
+ previousEpochGreatestUnrealizedBalances: EffectiveBalanceIncrements;
29
+ stateGetter: ForkChoiceStateGetter;
30
+ };
31
+ export type IFastConfirmationStore = IFastConfirmationSpecStore & IFastConfirmationAuxStore;
32
+ export type FastConfirmationResult = {
33
+ confirmedRoot: RootHex;
34
+ didReset?: boolean;
35
+ };
36
+ export type FastConfirmationSnapshot = {
37
+ currentSlot: Slot;
38
+ currentEpoch: Epoch;
39
+ headRoot: RootHex;
40
+ confirmedRoot: RootHex;
41
+ confirmedEpoch: Epoch | null;
42
+ confirmedSlot: Slot | null;
43
+ observedJustified: CheckpointWithHex;
44
+ headUnrealized: CheckpointWithHex | null;
45
+ finalizedRoot: RootHex;
46
+ };
47
+ export declare enum FastConfirmationDecisionReason {
48
+ Unchanged = "unchanged",
49
+ ConfirmedNotFound = "confirmed_not_found",
50
+ ResetBehind = "reset_behind",
51
+ ResetNotAncestor = "reset_not_ancestor",
52
+ ResetChainUnsafe = "reset_chain_unsafe",
53
+ ObservedJustified = "observed_justified",
54
+ ConfirmedDescendant = "confirmed_descendant"
55
+ }
56
+ export type FastConfirmationDecision = {
57
+ confirmedRoot: RootHex;
58
+ didReset: boolean;
59
+ reason: FastConfirmationDecisionReason;
60
+ };
61
+ export type FastConfirmationRule = (snapshot: FastConfirmationSnapshot, ctx: FastConfirmationContext, store: IFastConfirmationStore, cache: FastConfirmationCache, decision: FastConfirmationDecision, logger?: Logger) => FastConfirmationDecision;
62
+ export type BalanceSourceKey = "current" | "previous";
63
+ export type FastConfirmationCache = {
64
+ blockByRoot: Map<RootHex, ProtoBlock | null>;
65
+ ancestorRoots: Map<string, RootHex[] | null>;
66
+ committeeBySlot: Map<Slot, Set<ValidatorIndex>>;
67
+ isDescendantByRootPair: Map<string, boolean>;
68
+ /** voteRoot -> totalWeight, keyed by sourceKey */
69
+ voteWeightBySource: Map<BalanceSourceKey, Map<RootHex, number>>;
70
+ headState?: IBeaconStateView;
71
+ pulledUpHeadState?: IBeaconStateView;
72
+ checkpointStateByKey: Map<string, IBeaconStateView | null>;
73
+ };
74
+ export type FastConfirmationContext = {
75
+ config: {
76
+ CONFIRMATION_BYZANTINE_THRESHOLD: number;
77
+ PROPOSER_SCORE_BOOST: number;
78
+ };
79
+ getCurrentSlot(): Slot;
80
+ getHead(): ProtoBlock;
81
+ getBlock(root: RootHex): ProtoBlock | null;
82
+ getAncestor(root: RootHex, slot: Slot): RootHex;
83
+ isDescendant(ancestor: RootHex, descendant: RootHex): boolean;
84
+ getLatestMessage(validatorIndex: ValidatorIndex): {
85
+ root: RootHex;
86
+ epoch: Epoch;
87
+ } | null;
88
+ getUnrealizedJustified(): {
89
+ checkpoint: CheckpointWithHex;
90
+ balances: EffectiveBalanceIncrements;
91
+ };
92
+ getFinalizedCheckpoint(): CheckpointWithHex;
93
+ getEquivocatingIndices(): Set<ValidatorIndex>;
94
+ getTrackedVotesCount(): number;
95
+ };
96
+ export interface IFastConfirmationRule {
97
+ getConfirmedRoot(): RootHex;
98
+ onSlotStartAfterPastAttestationsApplied(ctx: FastConfirmationContext): FastConfirmationResult;
99
+ }
100
+ export {};
101
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/forkChoice/fastConfirmation/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,0BAA0B,EAAE,gBAAgB,EAAC,MAAM,4BAA4B,CAAC;AACxF,OAAO,EAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,cAAc,EAAC,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAAC,MAAM,EAAC,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAC,UAAU,EAAC,MAAM,+BAA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AAiB,CAAC,EAAE,gBAAgB,CAAC;IACrC,oBAAoB,EAAE,GAAG,CAAC,MAAM,EAAE,gBAAgB,GAAG,IAAI,CAAC,CAAC;CAC5D,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,MAAM,EAAE;QACN,gCAAgC,EAAE,MAAM,CAAC;QACzC,oBAAoB,EAAE,MAAM,CAAC;KAC9B,CAAC;IACF,cAAc,IAAI,IAAI,CAAC;IACvB,OAAO,IAAI,UAAU,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,UAAU,GAAG,IAAI,CAAC;IAC3C,WAAW,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC;IAChD,YAAY,CAAC,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,GAAG,OAAO,CAAC;IAC9D,gBAAgB,CAAC,cAAc,EAAE,cAAc,GAAG;QAAC,IAAI,EAAE,OAAO,CAAC;QAAC,KAAK,EAAE,KAAK,CAAA;KAAC,GAAG,IAAI,CAAC;IACvF,sBAAsB,IAAI;QAAC,UAAU,EAAE,iBAAiB,CAAC;QAAC,QAAQ,EAAE,0BAA0B,CAAA;KAAC,CAAC;IAChG,sBAAsB,IAAI,iBAAiB,CAAC;IAC5C,sBAAsB,IAAI,GAAG,CAAC,cAAc,CAAC,CAAC;IAC9C,oBAAoB,IAAI,MAAM,CAAC;CAChC,CAAC;AAEF,MAAM,WAAW,qBAAqB;IACpC,gBAAgB,IAAI,OAAO,CAAC;IAC5B,uCAAuC,CAAC,GAAG,EAAE,uBAAuB,GAAG,sBAAsB,CAAC;CAC/F"}
@@ -0,0 +1,12 @@
1
+ export { FastConfirmationDecisionReason };
2
+ var FastConfirmationDecisionReason;
3
+ (function (FastConfirmationDecisionReason) {
4
+ FastConfirmationDecisionReason["Unchanged"] = "unchanged";
5
+ FastConfirmationDecisionReason["ConfirmedNotFound"] = "confirmed_not_found";
6
+ FastConfirmationDecisionReason["ResetBehind"] = "reset_behind";
7
+ FastConfirmationDecisionReason["ResetNotAncestor"] = "reset_not_ancestor";
8
+ FastConfirmationDecisionReason["ResetChainUnsafe"] = "reset_chain_unsafe";
9
+ FastConfirmationDecisionReason["ObservedJustified"] = "observed_justified";
10
+ FastConfirmationDecisionReason["ConfirmedDescendant"] = "confirmed_descendant";
11
+ })(FastConfirmationDecisionReason || (FastConfirmationDecisionReason = {}));
12
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/forkChoice/fastConfirmation/types.ts"],"names":[],"mappings":"SAkDY,8BAA8B;AAA1C,IAAY,8BAQX;AARD,WAAY,8BAA8B;IACxC,yDAAuB,CAAA;IACvB,2EAAyC,CAAA;IACzC,8DAA4B,CAAA;IAC5B,yEAAuC,CAAA;IACvC,yEAAuC,CAAA;IACvC,0EAAwC,CAAA;IACxC,8EAA4C,CAAA;AAAC,CAC/C,EARY,8BAA8B,KAA9B,8BAA8B,QAQzC"}
@@ -0,0 +1,47 @@
1
+ import { 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
+ import { type BalanceSourceKey, FastConfirmationBalanceSource, FastConfirmationCache, FastConfirmationContext, FastConfirmationSnapshot, IFastConfirmationStore } from "./types.ts";
7
+ export declare function getBlock(ctx: FastConfirmationContext, cache: FastConfirmationCache, root: RootHex): ProtoBlock | null;
8
+ export declare function getUnrealizedJustification(ctx: FastConfirmationContext, cache: FastConfirmationCache, blockRoot: RootHex): CheckpointWithHex | null;
9
+ export declare function getVotingSource(ctx: FastConfirmationContext, cache: FastConfirmationCache, blockRoot: RootHex): CheckpointWithHex | null;
10
+ export declare function getCheckpointForBlock(ctx: FastConfirmationContext, blockRoot: RootHex, epoch: Epoch): CheckpointWithHex | null;
11
+ export declare function getAncestorRoots(ctx: FastConfirmationContext, cache: FastConfirmationCache, blockRoot: RootHex, terminalRoot: RootHex): RootHex[];
12
+ export declare function isAncestor(ctx: FastConfirmationContext, cache: FastConfirmationCache, blockRoot: RootHex, ancestorRoot: RootHex): boolean;
13
+ export declare function getHeadState(ctx: FastConfirmationContext, store: IFastConfirmationStore, cache: FastConfirmationCache): IBeaconStateView;
14
+ export declare function getPulledUpHeadState(ctx: FastConfirmationContext, store: IFastConfirmationStore, cache: FastConfirmationCache): IBeaconStateView;
15
+ export declare function getCheckpointState(store: IFastConfirmationStore, cache: FastConfirmationCache, checkpoint: CheckpointWithHex): IBeaconStateView | null;
16
+ export declare function getSlotCommittee(cache: FastConfirmationCache, state: IBeaconStateView, slot: Slot): Set<ValidatorIndex>;
17
+ export declare function getBalanceSource(store: IFastConfirmationStore, cache: FastConfirmationCache, kind: "previous" | "current"): FastConfirmationBalanceSource;
18
+ export declare function getCurrentBalanceSource(store: IFastConfirmationStore, cache: FastConfirmationCache): FastConfirmationBalanceSource;
19
+ export declare function getPreviousBalanceSource(store: IFastConfirmationStore, cache: FastConfirmationCache): FastConfirmationBalanceSource;
20
+ export declare function getTotalActiveBalance(balanceSource: FastConfirmationBalanceSource): number;
21
+ export declare function estimateCommitteeWeightBetweenSlots(balanceSource: FastConfirmationBalanceSource, startSlot: Slot, endSlot: Slot): number;
22
+ export declare function adjustCommitteeWeightEstimateToEnsureSafety(estimate: number): number;
23
+ export declare function isFullValidatorSetCovered(startSlot: Slot, endSlot: Slot): boolean;
24
+ export declare function computeProposerScore(ctx: FastConfirmationContext, balanceSource: FastConfirmationBalanceSource): number;
25
+ export declare function getAttestationScore(ctx: FastConfirmationContext, cache: FastConfirmationCache, balanceSource: FastConfirmationBalanceSource, blockRoot: RootHex, sourceKey: BalanceSourceKey): number;
26
+ export declare function getBlockSupportBetweenSlots(ctx: FastConfirmationContext, store: IFastConfirmationStore, cache: FastConfirmationCache, balanceSource: FastConfirmationBalanceSource, blockRoot: RootHex, startSlot: Slot, endSlot: Slot): number;
27
+ export declare function getEquivocationScore(ctx: FastConfirmationContext, store: IFastConfirmationStore, cache: FastConfirmationCache, balanceSource: FastConfirmationBalanceSource, startSlot: Slot, endSlot: Slot): number;
28
+ export declare function computeAdversarialWeight(ctx: FastConfirmationContext, store: IFastConfirmationStore, cache: FastConfirmationCache, balanceSource: FastConfirmationBalanceSource, startSlot: Slot, endSlot: Slot): number;
29
+ export declare function getAdversarialWeight(ctx: FastConfirmationContext, store: IFastConfirmationStore, cache: FastConfirmationCache, balanceSource: FastConfirmationBalanceSource, blockRoot: RootHex): number;
30
+ export declare function computeEmptySlotSupportDiscount(ctx: FastConfirmationContext, store: IFastConfirmationStore, cache: FastConfirmationCache, balanceSource: FastConfirmationBalanceSource, blockRoot: RootHex): number;
31
+ export declare function computeSafetyThreshold(ctx: FastConfirmationContext, store: IFastConfirmationStore, cache: FastConfirmationCache, balanceSource: FastConfirmationBalanceSource, blockRoot: RootHex): {
32
+ threshold: number;
33
+ proposerScore: number;
34
+ maximumSupport: number;
35
+ supportDiscount: number;
36
+ adversarialWeight: number;
37
+ };
38
+ export declare function isOneConfirmed(ctx: FastConfirmationContext, store: IFastConfirmationStore, cache: FastConfirmationCache, balanceSource: FastConfirmationBalanceSource, blockRoot: RootHex, sourceKey: BalanceSourceKey, logger?: Logger): boolean;
39
+ export declare function getCurrentTarget(ctx: FastConfirmationContext): CheckpointWithHex | null;
40
+ export declare function getCurrentEpochState(ctx: FastConfirmationContext, store: IFastConfirmationStore, cache: FastConfirmationCache): IBeaconStateView | null;
41
+ export declare function getCurrentTargetScore(ctx: FastConfirmationContext, store: IFastConfirmationStore, cache: FastConfirmationCache): number;
42
+ export declare function computeHonestFfgSupportForCurrentTarget(ctx: FastConfirmationContext, store: IFastConfirmationStore, cache: FastConfirmationCache): number;
43
+ export declare function willNoConflictingCheckpointBeJustified(ctx: FastConfirmationContext, store: IFastConfirmationStore, cache: FastConfirmationCache): boolean;
44
+ export declare function willCurrentTargetBeJustified(ctx: FastConfirmationContext, store: IFastConfirmationStore, cache: FastConfirmationCache): boolean;
45
+ export declare function isConfirmedChainSafe(ctx: FastConfirmationContext, store: IFastConfirmationStore, cache: FastConfirmationCache, confirmedRoot: RootHex, logger?: Logger): boolean;
46
+ export declare function findLatestConfirmedDescendant(snapshot: FastConfirmationSnapshot, ctx: FastConfirmationContext, store: IFastConfirmationStore, cache: FastConfirmationCache, latestConfirmedRoot: RootHex, logger?: Logger): RootHex;
47
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/forkChoice/fastConfirmation/utils.ts"],"names":[],"mappings":"AACA,OAAO,EACL,gBAAgB,EAMjB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,cAAc,EAAC,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAAC,MAAM,EAAU,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAkB,UAAU,EAAC,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EAAC,iBAAiB,EAA8C,MAAM,aAAa,CAAC;AAC3F,OAAO,EACL,KAAK,gBAAgB,EACrB,6BAA6B,EAC7B,qBAAqB,EACrB,uBAAuB,EACvB,wBAAwB,EACxB,sBAAsB,EACvB,MAAM,YAAY,CAAC;AAcpB,wBAAgB,QAAQ,CAAC,GAAG,EAAE,uBAAuB,EAAE,KAAK,EAAE,qBAAqB,EAAE,IAAI,EAAE,OAAO,GAAG,UAAU,GAAG,IAAI,CAOrH;AAED,wBAAgB,0BAA0B,CACxC,GAAG,EAAE,uBAAuB,EAC5B,KAAK,EAAE,qBAAqB,EAC5B,SAAS,EAAE,OAAO,GACjB,iBAAiB,GAAG,IAAI,CAQ1B;AAED,wBAAgB,eAAe,CAC7B,GAAG,EAAE,uBAAuB,EAC5B,KAAK,EAAE,qBAAqB,EA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