@lodestar/fork-choice 1.52.0-dev.6ab73fec0a → 1.52.0-dev.6c1c955421

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 (48) hide show
  1. package/lib/forkChoice/errors.d.ts +6 -1
  2. package/lib/forkChoice/errors.d.ts.map +1 -1
  3. package/lib/forkChoice/errors.js +1 -0
  4. package/lib/forkChoice/errors.js.map +1 -1
  5. package/lib/forkChoice/fastConfirmation/data.d.ts.map +1 -1
  6. package/lib/forkChoice/fastConfirmation/data.js +3 -2
  7. package/lib/forkChoice/fastConfirmation/data.js.map +1 -1
  8. package/lib/forkChoice/fastConfirmation/types.d.ts +30 -4
  9. package/lib/forkChoice/fastConfirmation/types.d.ts.map +1 -1
  10. package/lib/forkChoice/fastConfirmation/types.js.map +1 -1
  11. package/lib/forkChoice/fastConfirmation/utils.d.ts +13 -15
  12. package/lib/forkChoice/fastConfirmation/utils.d.ts.map +1 -1
  13. package/lib/forkChoice/fastConfirmation/utils.js +189 -119
  14. package/lib/forkChoice/fastConfirmation/utils.js.map +1 -1
  15. package/lib/forkChoice/forkChoice.d.ts +6 -7
  16. package/lib/forkChoice/forkChoice.d.ts.map +1 -1
  17. package/lib/forkChoice/forkChoice.js +30 -26
  18. package/lib/forkChoice/forkChoice.js.map +1 -1
  19. package/lib/forkChoice/interface.d.ts +6 -7
  20. package/lib/forkChoice/interface.d.ts.map +1 -1
  21. package/lib/forkChoice/interface.js.map +1 -1
  22. package/lib/index.d.ts +2 -2
  23. package/lib/index.d.ts.map +1 -1
  24. package/lib/index.js +1 -1
  25. package/lib/index.js.map +1 -1
  26. package/lib/protoArray/errors.d.ts +8 -10
  27. package/lib/protoArray/errors.d.ts.map +1 -1
  28. package/lib/protoArray/errors.js +7 -7
  29. package/lib/protoArray/errors.js.map +1 -1
  30. package/lib/protoArray/interface.d.ts +33 -2
  31. package/lib/protoArray/interface.d.ts.map +1 -1
  32. package/lib/protoArray/interface.js +22 -0
  33. package/lib/protoArray/interface.js.map +1 -1
  34. package/lib/protoArray/protoArray.d.ts +20 -22
  35. package/lib/protoArray/protoArray.d.ts.map +1 -1
  36. package/lib/protoArray/protoArray.js +104 -100
  37. package/lib/protoArray/protoArray.js.map +1 -1
  38. package/package.json +8 -8
  39. package/src/forkChoice/errors.ts +3 -1
  40. package/src/forkChoice/fastConfirmation/data.ts +3 -2
  41. package/src/forkChoice/fastConfirmation/types.ts +28 -4
  42. package/src/forkChoice/fastConfirmation/utils.ts +241 -167
  43. package/src/forkChoice/forkChoice.ts +31 -31
  44. package/src/forkChoice/interface.ts +6 -5
  45. package/src/index.ts +9 -1
  46. package/src/protoArray/errors.ts +8 -5
  47. package/src/protoArray/interface.ts +30 -4
  48. package/src/protoArray/protoArray.ts +106 -110
@@ -92,6 +92,7 @@ export enum ForkChoiceErrorCode {
92
92
  UNABLE_TO_SET_JUSTIFIED_CHECKPOINT = "FORKCHOICE_ERROR_UNABLE_TO_SET_JUSTIFIED_CHECKPOINT",
93
93
  AFTER_BLOCK_FAILED = "FORKCHOICE_ERROR_AFTER_BLOCK_FAILED",
94
94
  MISSING_EXECUTION_PAYLOAD_BLOCK_HASH = "FORKCHOICE_ERROR_MISSING_EXECUTION_PAYLOAD_BLOCK_HASH",
95
+ INVALID_JUSTIFIED_EXECUTION_STATUS = "FORKCHOICE_ERROR_INVALID_JUSTIFIED_EXECUTION_STATUS",
95
96
  }
96
97
 
97
98
  export type ForkChoiceErrorType =
@@ -107,6 +108,7 @@ export type ForkChoiceErrorType =
107
108
  | {code: ForkChoiceErrorCode.FORK_CHOICE_STORE_ERROR; error: Error}
108
109
  | {code: ForkChoiceErrorCode.UNABLE_TO_SET_JUSTIFIED_CHECKPOINT; error: Error}
109
110
  | {code: ForkChoiceErrorCode.AFTER_BLOCK_FAILED; error: Error}
110
- | {code: ForkChoiceErrorCode.MISSING_EXECUTION_PAYLOAD_BLOCK_HASH; root: RootHex; slot: Slot};
111
+ | {code: ForkChoiceErrorCode.MISSING_EXECUTION_PAYLOAD_BLOCK_HASH; root: RootHex; slot: Slot}
112
+ | {code: ForkChoiceErrorCode.INVALID_JUSTIFIED_EXECUTION_STATUS; epoch: Epoch; root: RootHex};
111
113
 
112
114
  export class ForkChoiceError extends LodestarError<ForkChoiceErrorType> {}
@@ -11,10 +11,11 @@ export function createFastConfirmationCache(): FastConfirmationCache {
11
11
  return {
12
12
  blockByRoot: new Map(),
13
13
  ancestorRoots: new Map(),
14
- committeeBySlot: new Map(),
14
+ committeeSweepByEndSlot: new Map(),
15
+ participantsByRange: new Map(),
15
16
  isDescendantByRootPair: new Map(),
16
17
  voteWeightBySource: new Map(),
17
- totalActiveBalanceByKey: new Map(),
18
+ activeBalancesByKey: new Map(),
18
19
  checkpointStateByKey: new Map(),
19
20
  };
20
21
  }
@@ -9,7 +9,13 @@ export type FastConfirmationBalanceSource = {
9
9
  balances: EffectiveBalanceIncrements;
10
10
  };
11
11
 
12
- export type TotalActiveBalanceCacheKey = IBeaconStateView | EffectiveBalanceIncrements;
12
+ export type BalanceSourceCacheKey = IBeaconStateView | EffectiveBalanceIncrements;
13
+
14
+ /**
15
+ * Effective balances of the validators active at the balance source epoch, slashed included, their sum,
16
+ * and the sum over the unslashed ones (`calculate_committee_fraction`)
17
+ */
18
+ export type ActiveBalances = {balances: EffectiveBalanceIncrements; total: number; unslashedTotal: number};
13
19
 
14
20
  export type ForkChoiceStateGetter = (
15
21
  opts: {stateRoot: RootHex; checkpoint?: never} | {stateRoot?: never; checkpoint: CheckpointWithHex}
@@ -103,16 +109,34 @@ export type FastConfirmationRule = (
103
109
 
104
110
  export type BalanceSourceKey = "current" | "previous";
105
111
 
112
+ /**
113
+ * Committees of the slots ending at a fixed slot, swept backwards one slot at a time over the head
114
+ * state shuffling. A validator is recorded at the latest slot it is assigned to, so the committees of
115
+ * any range ending at that slot are a prefix of `order` with no duplicates, even when the range
116
+ * crosses an epoch boundary and the two epochs' committees overlap.
117
+ */
118
+ export type CommitteeSweep = {
119
+ /** Marks validators already placed in `order`, indexed by validator index */
120
+ seen: Uint8Array;
121
+ /** Validators of the end slot, then those first seen one slot earlier, and so on */
122
+ order: Uint32Array;
123
+ /** Length of the `order` prefix covering the last `i + 1` slots, for each swept slot `i` */
124
+ lengths: number[];
125
+ /** Committee weight of the last `i + 1` slots, per balance source, filled on demand */
126
+ weightsByKey: Map<BalanceSourceCacheKey, number[]>;
127
+ };
128
+
106
129
  // This cache is created once per slot
107
130
  export type FastConfirmationCache = {
108
131
  blockByRoot: Map<RootHex, ProtoBlock | null>;
109
132
  ancestorRoots: Map<string, RootHex[] | null>;
110
- committeeBySlot: Map<Slot, Set<ValidatorIndex>>;
133
+ committeeSweepByEndSlot: Map<Slot, CommitteeSweep>;
134
+ participantsByRange: Map<string, Uint32Array>;
111
135
  isDescendantByRootPair: Map<string, boolean>;
112
136
  /** voteRoot -> totalWeight, keyed by sourceKey */
113
137
  voteWeightBySource: Map<BalanceSourceKey, Map<RootHex, number>>;
114
- /** total active balance, keyed by the balance source's state or balances reference */
115
- totalActiveBalanceByKey: Map<TotalActiveBalanceCacheKey, number>;
138
+ /** active balances and their total, keyed by the balance source's state or balances reference */
139
+ activeBalancesByKey: Map<BalanceSourceCacheKey, ActiveBalances>;
116
140
  headState?: IBeaconStateView;
117
141
  pulledUpHeadState?: IBeaconStateView;
118
142
  checkpointStateByKey: Map<string, IBeaconStateView | null>;