@lodestar/fork-choice 1.44.0-dev.7418ddd9f7 → 1.44.0-dev.762dd5f186

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 (69) 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 +139 -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 +24 -0
  14. package/lib/forkChoice/fastConfirmation/metrics.d.ts.map +1 -0
  15. package/lib/forkChoice/fastConfirmation/metrics.js +55 -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 +114 -0
  20. package/lib/forkChoice/fastConfirmation/rules.js.map +1 -0
  21. package/lib/forkChoice/fastConfirmation/types.d.ts +115 -0
  22. package/lib/forkChoice/fastConfirmation/types.d.ts.map +1 -0
  23. package/lib/forkChoice/fastConfirmation/types.js +22 -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 +687 -0
  28. package/lib/forkChoice/fastConfirmation/utils.js.map +1 -0
  29. package/lib/forkChoice/forkChoice.d.ts +20 -2
  30. package/lib/forkChoice/forkChoice.d.ts.map +1 -1
  31. package/lib/forkChoice/forkChoice.js +115 -9
  32. package/lib/forkChoice/forkChoice.js.map +1 -1
  33. package/lib/forkChoice/interface.d.ts +16 -2
  34. package/lib/forkChoice/interface.d.ts.map +1 -1
  35. package/lib/forkChoice/safeBlocks.d.ts +2 -6
  36. package/lib/forkChoice/safeBlocks.d.ts.map +1 -1
  37. package/lib/forkChoice/safeBlocks.js +15 -7
  38. package/lib/forkChoice/safeBlocks.js.map +1 -1
  39. package/lib/forkChoice/store.d.ts +33 -2
  40. package/lib/forkChoice/store.d.ts.map +1 -1
  41. package/lib/forkChoice/store.js +37 -1
  42. package/lib/forkChoice/store.js.map +1 -1
  43. package/lib/index.d.ts +1 -0
  44. package/lib/index.d.ts.map +1 -1
  45. package/lib/index.js +1 -0
  46. package/lib/index.js.map +1 -1
  47. package/lib/metrics.d.ts +15 -1
  48. package/lib/metrics.d.ts.map +1 -1
  49. package/lib/metrics.js +2 -0
  50. package/lib/metrics.js.map +1 -1
  51. package/lib/protoArray/protoArray.d.ts +27 -5
  52. package/lib/protoArray/protoArray.d.ts.map +1 -1
  53. package/lib/protoArray/protoArray.js +73 -17
  54. package/lib/protoArray/protoArray.js.map +1 -1
  55. package/package.json +7 -7
  56. package/src/forkChoice/fastConfirmation/data.ts +43 -0
  57. package/src/forkChoice/fastConfirmation/fastConfirmationRule.ts +173 -0
  58. package/src/forkChoice/fastConfirmation/index.ts +3 -0
  59. package/src/forkChoice/fastConfirmation/metrics.ts +57 -0
  60. package/src/forkChoice/fastConfirmation/rules.ts +151 -0
  61. package/src/forkChoice/fastConfirmation/types.ts +137 -0
  62. package/src/forkChoice/fastConfirmation/utils.ts +975 -0
  63. package/src/forkChoice/forkChoice.ts +143 -9
  64. package/src/forkChoice/interface.ts +17 -1
  65. package/src/forkChoice/safeBlocks.ts +15 -7
  66. package/src/forkChoice/store.ts +45 -1
  67. package/src/index.ts +11 -0
  68. package/src/metrics.ts +3 -1
  69. package/src/protoArray/protoArray.ts +85 -16
@@ -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,EAEtB,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,CAsE5F;IAED,OAAO,CAAC,+BAA+B;IAgDvC,OAAO,CAAC,6BAA6B;CAwBtC"}
@@ -0,0 +1,139 @@
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, resetReason, didReorg, didFallback, didRestart } = 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
+ resetReason,
57
+ confirmedSlot,
58
+ confirmedEpoch,
59
+ };
60
+ if (changed) {
61
+ if (didReset) {
62
+ this.logger?.warn("Reset fast confirmation", logContext);
63
+ }
64
+ else {
65
+ this.logger?.debug("Updated fast confirmation", logContext);
66
+ }
67
+ }
68
+ else {
69
+ this.logger?.debug("Unchanged fast confirmation", logContext);
70
+ }
71
+ this.store.confirmedRoot = confirmedRoot;
72
+ this.updateFastConfirmationMetrics(ctx, { confirmedRoot, didReset, didReorg, didFallback, didRestart });
73
+ return { confirmedRoot, didReset };
74
+ }
75
+ updateFastConfirmationVariables(ctx) {
76
+ const previousSlotHead = this.store.currentSlotHead;
77
+ const currentSlotHead = ctx.getHead().blockRoot;
78
+ const currentSlot = ctx.getCurrentSlot();
79
+ const isStartSlotOfCurrentEpoch = isStartSlotOfEpoch(currentSlot);
80
+ const isLastSlotOfCurrentEpoch = isStartSlotOfEpoch(currentSlot + 1);
81
+ this.store.previousSlotHead = previousSlotHead;
82
+ this.store.currentSlotHead = currentSlotHead;
83
+ this.logger?.verbose("Updating fast confirmation variables", {
84
+ previousSlotHead,
85
+ currentSlotHead,
86
+ currentSlot,
87
+ isStartSlotOfCurrentEpoch,
88
+ isLastSlotOfCurrentEpoch,
89
+ });
90
+ // Spec step 1: freeze the greatest unrealized justified checkpoint at the
91
+ // last slot of the epoch so the next epoch consumes a stable snapshot.
92
+ if (isLastSlotOfCurrentEpoch) {
93
+ const unrealized = ctx.getUnrealizedJustified();
94
+ this.store.previousEpochGreatestUnrealizedCheckpoint = unrealized.checkpoint;
95
+ this.store.previousEpochGreatestUnrealizedBalances = unrealized.balances;
96
+ this.logger?.verbose("Updated fast confirmation greatest unrealized snapshot", {
97
+ previousEpochGreatestUnrealizedCheckpointRoot: this.store.previousEpochGreatestUnrealizedCheckpoint.rootHex,
98
+ previousEpochGreatestUnrealizedCheckpointEpoch: this.store.previousEpochGreatestUnrealizedCheckpoint.epoch,
99
+ });
100
+ }
101
+ // Spec step 2: rotate observed justified checkpoints at the first slot of
102
+ // the new epoch using the snapshot taken at the end of the previous epoch.
103
+ if (isStartSlotOfCurrentEpoch) {
104
+ this.store.previousEpochObservedJustifiedCheckpoint = this.store.currentEpochObservedJustifiedCheckpoint;
105
+ this.store.previousEpochObservedJustifiedBalances = this.store.currentEpochObservedJustifiedBalances;
106
+ this.store.currentEpochObservedJustifiedCheckpoint = this.store.previousEpochGreatestUnrealizedCheckpoint;
107
+ this.store.currentEpochObservedJustifiedBalances = this.store.previousEpochGreatestUnrealizedBalances;
108
+ this.logger?.verbose("Updated fast confirmation observed justified checkpoints", {
109
+ previousEpochObservedJustifiedCheckpointRoot: this.store.previousEpochObservedJustifiedCheckpoint.rootHex,
110
+ previousEpochObservedJustifiedCheckpointEpoch: this.store.previousEpochObservedJustifiedCheckpoint.epoch,
111
+ currentEpochObservedJustifiedCheckpointRoot: this.store.currentEpochObservedJustifiedCheckpoint.rootHex,
112
+ currentEpochObservedJustifiedCheckpointEpoch: this.store.currentEpochObservedJustifiedCheckpoint.epoch,
113
+ });
114
+ }
115
+ }
116
+ updateFastConfirmationMetrics(ctx, result) {
117
+ if (!this.metrics)
118
+ return;
119
+ const confirmedBlock = ctx.getBlock(result.confirmedRoot);
120
+ if (confirmedBlock) {
121
+ this.metrics.fastConfirmation.confirmedEpoch.set(computeEpochAtSlot(confirmedBlock.slot));
122
+ this.metrics.fastConfirmation.slot.set(confirmedBlock.slot);
123
+ }
124
+ if (result.didReset) {
125
+ this.metrics.fastConfirmation.resets.inc();
126
+ }
127
+ if (result.didReorg) {
128
+ this.metrics.fastConfirmation.reorgs.inc();
129
+ }
130
+ if (result.didFallback) {
131
+ this.metrics.fastConfirmation.fallbacks.inc();
132
+ }
133
+ if (result.didRestart) {
134
+ this.metrics.fastConfirmation.restarts.inc();
135
+ }
136
+ this.metrics.fastConfirmation.votesTracked.set(ctx.getTrackedVotesCount());
137
+ }
138
+ }
139
+ //# 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;AAC7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//# 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,24 @@
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
+ votesTracked: import("@lodestar/utils").GaugeExtra<import("@lodestar/utils").NoLabels>;
17
+ resets: import("@lodestar/utils").Counter<import("@lodestar/utils").NoLabels>;
18
+ slot: import("@lodestar/utils").GaugeExtra<import("@lodestar/utils").NoLabels>;
19
+ reorgs: import("@lodestar/utils").Counter<import("@lodestar/utils").NoLabels>;
20
+ fallbacks: import("@lodestar/utils").Counter<import("@lodestar/utils").NoLabels>;
21
+ restarts: import("@lodestar/utils").Counter<import("@lodestar/utils").NoLabels>;
22
+ };
23
+ };
24
+ //# 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;;;;;;;;;;;;;;EA6CxE"}
@@ -0,0 +1,55 @@
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
+ votesTracked: register.gauge({
28
+ name: "lodestar_fast_confirmation_votes_tracked",
29
+ help: "Number of checkpoint votes tracked by fast confirmation",
30
+ }),
31
+ resets: register.counter({
32
+ name: "lodestar_fast_confirmation_resets_total",
33
+ help: "Total number of fast confirmation resets (any cause)",
34
+ }),
35
+ // Standardized Fast Confirmation metrics
36
+ slot: register.gauge({
37
+ name: "beacon_fast_confirmation_slot",
38
+ help: "Slot of the most recent confirmed block",
39
+ }),
40
+ reorgs: register.counter({
41
+ name: "beacon_fast_confirmation_reorgs_total",
42
+ help: "Total number of confirmed block reorganizations",
43
+ }),
44
+ fallbacks: register.counter({
45
+ name: "beacon_fast_confirmation_fallbacks_total",
46
+ help: "Total number of fallbacks to finality",
47
+ }),
48
+ restarts: register.counter({
49
+ name: "beacon_fast_confirmation_restarts_total",
50
+ help: "Total number of restarts from a safe unrealized justified block",
51
+ }),
52
+ },
53
+ };
54
+ }
55
+ //# 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,YAAY,EAAE,QAAQ,CAAC,KAAK,CAAC;gBAC3B,IAAI,EAAE,0CAA0C;gBAChD,IAAI,EAAE,yDAAyD;aAChE,CAAC;YACF,MAAM,EAAE,QAAQ,CAAC,OAAO,CAAC;gBACvB,IAAI,EAAE,yCAAyC;gBAC/C,IAAI,EAAE,sDAAsD;aAC7D,CAAC;YACF,yCAAyC;YACzC,IAAI,EAAE,QAAQ,CAAC,KAAK,CAAC;gBACnB,IAAI,EAAE,+BAA+B;gBACrC,IAAI,EAAE,yCAAyC;aAChD,CAAC;YACF,MAAM,EAAE,QAAQ,CAAC,OAAO,CAAC;gBACvB,IAAI,EAAE,uCAAuC;gBAC7C,IAAI,EAAE,iDAAiD;aACxD,CAAC;YACF,SAAS,EAAE,QAAQ,CAAC,OAAO,CAAC;gBAC1B,IAAI,EAAE,0CAA0C;gBAChD,IAAI,EAAE,uCAAuC;aAC9C,CAAC;YACF,QAAQ,EAAE,QAAQ,CAAC,OAAO,CAAC;gBACzB,IAAI,EAAE,yCAAyC;gBAC/C,IAAI,EAAE,iEAAiE;aACxE,CAAC;SACH;KACF,CAAC;AAAA,CACH"}
@@ -0,0 +1,9 @@
1
+ import { Logger } from "@lodestar/utils";
2
+ import { FastConfirmationCache, FastConfirmationContext, FastConfirmationRule, FastConfirmationRunResult, 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): FastConfirmationRunResult;
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,EAGvB,oBAAoB,EACpB,yBAAyB,EACzB,wBAAwB,EACxB,sBAAsB,EAEvB,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,yBAAyB,CAoC3B"}
@@ -0,0 +1,114 @@
1
+ import { computeEpochAtSlot, isStartSlotOfEpoch } from "@lodestar/state-transition";
2
+ import { equalCheckpointWithHex } from "../store.js";
3
+ import { FastConfirmationDecisionReason, isResetReason, } 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
+ const reasonTrail = [];
87
+ for (const rule of FAST_CONFIRMATION_RULES) {
88
+ const previousDecision = decision;
89
+ decision = rule(snapshot, ctx, store, cache, decision, logger);
90
+ if (decision !== previousDecision && decision.reason !== FastConfirmationDecisionReason.Unchanged) {
91
+ reasonTrail.push(decision.reason);
92
+ }
93
+ }
94
+ logger?.debug("Fast confirmation rule outcomes", { reasonTrail: reasonTrail.join(",") });
95
+ // Detect a reorg directly from ancestry instead of the reset reason: when the confirmed block is
96
+ // both epoch-behind and not an ancestor of head, `resetIfBehindOrNotAncestorOrUnsafe` records
97
+ // `ResetBehind` (it takes precedence), so keying off `ResetNotAncestor` alone would miss reorgs
98
+ // that cross an epoch boundary.
99
+ const initialConfirmedBlock = getBlock(ctx, cache, snapshot.confirmedRoot);
100
+ const didReorg = initialConfirmedBlock !== null && !isAncestor(ctx, cache, snapshot.headRoot, snapshot.confirmedRoot);
101
+ return {
102
+ confirmedRoot: decision.confirmedRoot,
103
+ didReset: decision.didReset,
104
+ reason: decision.reason,
105
+ // Reset cause: the first reset-classified reason in the trail (only when an actual reset occurred).
106
+ resetReason: decision.didReset ? reasonTrail.find(isResetReason) : undefined,
107
+ didReorg,
108
+ // A fallback is a revert to finality: a reset whose final confirmed root is the finalized
109
+ // checkpoint. A later rule may advance the confirmed root forward, which is not a fallback.
110
+ didFallback: decision.didReset && decision.confirmedRoot === snapshot.finalizedRoot,
111
+ didRestart: reasonTrail.includes(FastConfirmationDecisionReason.ObservedJustified),
112
+ };
113
+ }
114
+ //# 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,MAAM,4BAA4B,CAAC;AAElF,OAAO,EAAC,sBAAsB,EAAC,MAAM,aAAa,CAAC;AACnD,OAAO,EAIL,8BAA8B,EAK9B,aAAa,GACd,MAAM,YAAY,CAAC;AACpB,OAAO,EAAC,6BAA6B,EAAE,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C,MAAM;QACvB,oGAAoG;QACpG,WAAW,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,SAAS;QAC5E,QAAQ;QACR,0FAA0F;QAC1F,4FAA4F;QAC5F,WAAW,EAAE,QAAQ,CAAC,QAAQ,IAAI,QAAQ,CAAC,aAAa,KAAK,QAAQ,CAAC,aAAa;QACnF,UAAU,EAAE,WAAW,CAAC,QAAQ,CAAC,8BAA8B,CAAC,iBAAiB,CAAC;KACnF,CAAC;AAAA,CACH"}
@@ -0,0 +1,115 @@
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 declare function isResetReason(reason: FastConfirmationDecisionReason): boolean;
57
+ export type FastConfirmationDecision = {
58
+ confirmedRoot: RootHex;
59
+ didReset: boolean;
60
+ reason: FastConfirmationDecisionReason;
61
+ };
62
+ export type FastConfirmationRunResult = FastConfirmationDecision & {
63
+ /**
64
+ * Cause of the reset, when one occurred.
65
+ * The `reason` attribute reports the final disposition and can be different.
66
+ */
67
+ resetReason?: FastConfirmationDecisionReason;
68
+ /** Confirmed block became non-canonical (no longer an ancestor of head) */
69
+ didReorg: boolean;
70
+ /** Confirmed block reverted to the finalized checkpoint */
71
+ didFallback: boolean;
72
+ /** Restarted confirmation from the observed unrealized justified checkpoint */
73
+ didRestart: boolean;
74
+ };
75
+ export type FastConfirmationRule = (snapshot: FastConfirmationSnapshot, ctx: FastConfirmationContext, store: IFastConfirmationStore, cache: FastConfirmationCache, decision: FastConfirmationDecision, logger?: Logger) => FastConfirmationDecision;
76
+ export type BalanceSourceKey = "current" | "previous";
77
+ export type FastConfirmationCache = {
78
+ blockByRoot: Map<RootHex, ProtoBlock | null>;
79
+ ancestorRoots: Map<string, RootHex[] | null>;
80
+ committeeBySlot: Map<Slot, Set<ValidatorIndex>>;
81
+ isDescendantByRootPair: Map<string, boolean>;
82
+ /** voteRoot -> totalWeight, keyed by sourceKey */
83
+ voteWeightBySource: Map<BalanceSourceKey, Map<RootHex, number>>;
84
+ headState?: IBeaconStateView;
85
+ pulledUpHeadState?: IBeaconStateView;
86
+ checkpointStateByKey: Map<string, IBeaconStateView | null>;
87
+ };
88
+ export type FastConfirmationContext = {
89
+ config: {
90
+ CONFIRMATION_BYZANTINE_THRESHOLD: number;
91
+ PROPOSER_SCORE_BOOST: number;
92
+ };
93
+ getCurrentSlot(): Slot;
94
+ getHead(): ProtoBlock;
95
+ getBlock(root: RootHex): ProtoBlock | null;
96
+ getAncestor(root: RootHex, slot: Slot): RootHex;
97
+ isDescendant(ancestor: RootHex, descendant: RootHex): boolean;
98
+ getLatestMessage(validatorIndex: ValidatorIndex): {
99
+ root: RootHex;
100
+ epoch: Epoch;
101
+ } | null;
102
+ getUnrealizedJustified(): {
103
+ checkpoint: CheckpointWithHex;
104
+ balances: EffectiveBalanceIncrements;
105
+ };
106
+ getFinalizedCheckpoint(): CheckpointWithHex;
107
+ getEquivocatingIndices(): Set<ValidatorIndex>;
108
+ getTrackedVotesCount(): number;
109
+ };
110
+ export interface IFastConfirmationRule {
111
+ getConfirmedRoot(): RootHex;
112
+ onSlotStartAfterPastAttestationsApplied(ctx: FastConfirmationContext): FastConfirmationResult;
113
+ }
114
+ export {};
115
+ //# 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,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C,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,22 @@
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
+ /** Reasons where the confirmed root is pulled backward (a reset), as opposed to advanced forward. */
13
+ const RESET_REASONS = new Set([
14
+ FastConfirmationDecisionReason.ConfirmedNotFound,
15
+ FastConfirmationDecisionReason.ResetBehind,
16
+ FastConfirmationDecisionReason.ResetNotAncestor,
17
+ FastConfirmationDecisionReason.ResetChainUnsafe,
18
+ ]);
19
+ export function isResetReason(reason) {
20
+ return RESET_REASONS.has(reason);
21
+ }
22
+ //# 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;AAED,qGAAqG;AACrG,MAAM,aAAa,GAAG,IAAI,GAAG,CAAiC;IAC5D,8BAA8B,CAAC,iBAAiB;IAChD,8BAA8B,CAAC,WAAW;IAC1C,8BAA8B,CAAC,gBAAgB;IAC/C,8BAA8B,CAAC,gBAAgB;CAChD,CAAC,CAAC;AAEH,MAAM,UAAU,aAAa,CAAC,MAAsC,EAAW;IAC7E,OAAO,aAAa,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;AAAA,CAClC"}