@lodestar/validator 1.35.0-dev.e9dd48f165 → 1.35.0-dev.f45a2be721

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 (174) hide show
  1. package/lib/buckets.d.ts.map +1 -0
  2. package/lib/defaults.d.ts.map +1 -0
  3. package/lib/genesis.d.ts.map +1 -0
  4. package/lib/index.d.ts +7 -7
  5. package/lib/index.d.ts.map +1 -0
  6. package/lib/index.js +5 -5
  7. package/lib/index.js.map +1 -1
  8. package/lib/metrics.d.ts.map +1 -0
  9. package/lib/metrics.js +14 -14
  10. package/lib/metrics.js.map +1 -1
  11. package/lib/repositories/index.d.ts.map +1 -0
  12. package/lib/repositories/metaDataRepository.d.ts.map +1 -0
  13. package/lib/repositories/metaDataRepository.js +4 -3
  14. package/lib/repositories/metaDataRepository.js.map +1 -1
  15. package/lib/services/attestation.d.ts.map +1 -0
  16. package/lib/services/attestation.js +77 -60
  17. package/lib/services/attestation.js.map +1 -1
  18. package/lib/services/attestationDuties.d.ts.map +1 -0
  19. package/lib/services/attestationDuties.js +105 -98
  20. package/lib/services/attestationDuties.js.map +1 -1
  21. package/lib/services/block.d.ts.map +1 -0
  22. package/lib/services/block.js +64 -56
  23. package/lib/services/block.js.map +1 -1
  24. package/lib/services/blockDuties.d.ts +2 -2
  25. package/lib/services/blockDuties.d.ts.map +1 -0
  26. package/lib/services/blockDuties.js +35 -26
  27. package/lib/services/blockDuties.js.map +1 -1
  28. package/lib/services/chainHeaderTracker.d.ts.map +1 -0
  29. package/lib/services/chainHeaderTracker.js +30 -27
  30. package/lib/services/chainHeaderTracker.js.map +1 -1
  31. package/lib/services/doppelgangerService.d.ts.map +1 -0
  32. package/lib/services/doppelgangerService.js +52 -45
  33. package/lib/services/doppelgangerService.js.map +1 -1
  34. package/lib/services/emitter.d.ts +1 -1
  35. package/lib/services/emitter.d.ts.map +1 -0
  36. package/lib/services/externalSignerSync.d.ts.map +1 -0
  37. package/lib/services/externalSignerSync.js +1 -1
  38. package/lib/services/externalSignerSync.js.map +1 -1
  39. package/lib/services/indices.d.ts.map +1 -0
  40. package/lib/services/indices.js +8 -5
  41. package/lib/services/indices.js.map +1 -1
  42. package/lib/services/prepareBeaconProposer.d.ts.map +1 -0
  43. package/lib/services/prepareBeaconProposer.js.map +1 -1
  44. package/lib/services/syncCommittee.d.ts.map +1 -0
  45. package/lib/services/syncCommittee.js +80 -61
  46. package/lib/services/syncCommittee.js.map +1 -1
  47. package/lib/services/syncCommitteeDuties.d.ts.map +1 -0
  48. package/lib/services/syncCommitteeDuties.js +28 -23
  49. package/lib/services/syncCommitteeDuties.js.map +1 -1
  50. package/lib/services/syncingStatusTracker.d.ts.map +1 -0
  51. package/lib/services/syncingStatusTracker.js +32 -27
  52. package/lib/services/syncingStatusTracker.js.map +1 -1
  53. package/lib/services/utils.d.ts.map +1 -0
  54. package/lib/services/validatorStore.d.ts.map +1 -0
  55. package/lib/services/validatorStore.js +9 -3
  56. package/lib/services/validatorStore.js.map +1 -1
  57. package/lib/slashingProtection/attestation/attestationByTargetRepository.d.ts.map +1 -0
  58. package/lib/slashingProtection/attestation/attestationByTargetRepository.js +7 -3
  59. package/lib/slashingProtection/attestation/attestationByTargetRepository.js.map +1 -1
  60. package/lib/slashingProtection/attestation/attestationLowerBoundRepository.d.ts.map +1 -0
  61. package/lib/slashingProtection/attestation/attestationLowerBoundRepository.js +5 -3
  62. package/lib/slashingProtection/attestation/attestationLowerBoundRepository.js.map +1 -1
  63. package/lib/slashingProtection/attestation/errors.d.ts.map +1 -0
  64. package/lib/slashingProtection/attestation/index.d.ts.map +1 -0
  65. package/lib/slashingProtection/attestation/index.js +3 -0
  66. package/lib/slashingProtection/attestation/index.js.map +1 -1
  67. package/lib/slashingProtection/block/blockBySlotRepository.d.ts.map +1 -0
  68. package/lib/slashingProtection/block/blockBySlotRepository.js +7 -3
  69. package/lib/slashingProtection/block/blockBySlotRepository.js.map +1 -1
  70. package/lib/slashingProtection/block/errors.d.ts.map +1 -0
  71. package/lib/slashingProtection/block/index.d.ts.map +1 -0
  72. package/lib/slashingProtection/block/index.js +1 -0
  73. package/lib/slashingProtection/block/index.js.map +1 -1
  74. package/lib/slashingProtection/index.d.ts +1 -1
  75. package/lib/slashingProtection/index.d.ts.map +1 -0
  76. package/lib/slashingProtection/index.js +3 -0
  77. package/lib/slashingProtection/index.js.map +1 -1
  78. package/lib/slashingProtection/interchange/errors.d.ts.map +1 -0
  79. package/lib/slashingProtection/interchange/formats/completeV4.d.ts.map +1 -0
  80. package/lib/slashingProtection/interchange/formats/index.d.ts.map +1 -0
  81. package/lib/slashingProtection/interchange/formats/v5.d.ts.map +1 -0
  82. package/lib/slashingProtection/interchange/index.d.ts.map +1 -0
  83. package/lib/slashingProtection/interchange/parseInterchange.d.ts.map +1 -0
  84. package/lib/slashingProtection/interchange/serializeInterchange.d.ts.map +1 -0
  85. package/lib/slashingProtection/interchange/types.d.ts.map +1 -0
  86. package/lib/slashingProtection/interface.d.ts.map +1 -0
  87. package/lib/slashingProtection/minMaxSurround/distanceStoreRepository.d.ts.map +1 -0
  88. package/lib/slashingProtection/minMaxSurround/distanceStoreRepository.js +8 -0
  89. package/lib/slashingProtection/minMaxSurround/distanceStoreRepository.js.map +1 -1
  90. package/lib/slashingProtection/minMaxSurround/errors.d.ts.map +1 -0
  91. package/lib/slashingProtection/minMaxSurround/index.d.ts.map +1 -0
  92. package/lib/slashingProtection/minMaxSurround/interface.d.ts.map +1 -0
  93. package/lib/slashingProtection/minMaxSurround/minMaxSurround.d.ts.map +1 -0
  94. package/lib/slashingProtection/minMaxSurround/minMaxSurround.js +2 -0
  95. package/lib/slashingProtection/minMaxSurround/minMaxSurround.js.map +1 -1
  96. package/lib/slashingProtection/types.d.ts.map +1 -0
  97. package/lib/slashingProtection/utils.d.ts +1 -1
  98. package/lib/slashingProtection/utils.d.ts.map +1 -0
  99. package/lib/types.d.ts.map +1 -0
  100. package/lib/util/batch.d.ts.map +1 -0
  101. package/lib/util/clock.d.ts +3 -0
  102. package/lib/util/clock.d.ts.map +1 -0
  103. package/lib/util/clock.js +16 -9
  104. package/lib/util/clock.js.map +1 -1
  105. package/lib/util/difference.d.ts.map +1 -0
  106. package/lib/util/externalSignerClient.d.ts.map +1 -0
  107. package/lib/util/format.d.ts.map +1 -0
  108. package/lib/util/index.d.ts.map +1 -0
  109. package/lib/util/logger.d.ts.map +1 -0
  110. package/lib/util/params.d.ts.map +1 -0
  111. package/lib/util/params.js +18 -2
  112. package/lib/util/params.js.map +1 -1
  113. package/lib/util/url.d.ts.map +1 -0
  114. package/lib/validator.d.ts.map +1 -0
  115. package/lib/validator.js +16 -1
  116. package/lib/validator.js.map +1 -1
  117. package/package.json +19 -16
  118. package/src/buckets.ts +30 -0
  119. package/src/defaults.ts +8 -0
  120. package/src/genesis.ts +19 -0
  121. package/src/index.ts +22 -0
  122. package/src/metrics.ts +417 -0
  123. package/src/repositories/index.ts +1 -0
  124. package/src/repositories/metaDataRepository.ts +42 -0
  125. package/src/services/attestation.ts +362 -0
  126. package/src/services/attestationDuties.ts +406 -0
  127. package/src/services/block.ts +261 -0
  128. package/src/services/blockDuties.ts +217 -0
  129. package/src/services/chainHeaderTracker.ts +89 -0
  130. package/src/services/doppelgangerService.ts +286 -0
  131. package/src/services/emitter.ts +43 -0
  132. package/src/services/externalSignerSync.ts +81 -0
  133. package/src/services/indices.ts +165 -0
  134. package/src/services/prepareBeaconProposer.ts +119 -0
  135. package/src/services/syncCommittee.ts +338 -0
  136. package/src/services/syncCommitteeDuties.ts +337 -0
  137. package/src/services/syncingStatusTracker.ts +74 -0
  138. package/src/services/utils.ts +58 -0
  139. package/src/services/validatorStore.ts +830 -0
  140. package/src/slashingProtection/attestation/attestationByTargetRepository.ts +77 -0
  141. package/src/slashingProtection/attestation/attestationLowerBoundRepository.ts +44 -0
  142. package/src/slashingProtection/attestation/errors.ts +66 -0
  143. package/src/slashingProtection/attestation/index.ts +171 -0
  144. package/src/slashingProtection/block/blockBySlotRepository.ts +78 -0
  145. package/src/slashingProtection/block/errors.ts +28 -0
  146. package/src/slashingProtection/block/index.ts +94 -0
  147. package/src/slashingProtection/index.ts +95 -0
  148. package/src/slashingProtection/interchange/errors.ts +15 -0
  149. package/src/slashingProtection/interchange/formats/completeV4.ts +125 -0
  150. package/src/slashingProtection/interchange/formats/index.ts +7 -0
  151. package/src/slashingProtection/interchange/formats/v5.ts +120 -0
  152. package/src/slashingProtection/interchange/index.ts +5 -0
  153. package/src/slashingProtection/interchange/parseInterchange.ts +55 -0
  154. package/src/slashingProtection/interchange/serializeInterchange.ts +35 -0
  155. package/src/slashingProtection/interchange/types.ts +18 -0
  156. package/src/slashingProtection/interface.ts +28 -0
  157. package/src/slashingProtection/minMaxSurround/distanceStoreRepository.ts +57 -0
  158. package/src/slashingProtection/minMaxSurround/errors.ts +27 -0
  159. package/src/slashingProtection/minMaxSurround/index.ts +4 -0
  160. package/src/slashingProtection/minMaxSurround/interface.ts +23 -0
  161. package/src/slashingProtection/minMaxSurround/minMaxSurround.ts +104 -0
  162. package/src/slashingProtection/types.ts +12 -0
  163. package/src/slashingProtection/utils.ts +42 -0
  164. package/src/types.ts +31 -0
  165. package/src/util/batch.ts +15 -0
  166. package/src/util/clock.ts +169 -0
  167. package/src/util/difference.ts +10 -0
  168. package/src/util/externalSignerClient.ts +277 -0
  169. package/src/util/format.ts +3 -0
  170. package/src/util/index.ts +6 -0
  171. package/src/util/logger.ts +51 -0
  172. package/src/util/params.ts +320 -0
  173. package/src/util/url.ts +16 -0
  174. package/src/validator.ts +418 -0
@@ -0,0 +1,74 @@
1
+ import {ApiClient, routes} from "@lodestar/api";
2
+ import {Slot} from "@lodestar/types";
3
+ import {Logger} from "@lodestar/utils";
4
+ import {BeaconHealth, Metrics} from "../metrics.js";
5
+ import {IClock} from "../util/clock.js";
6
+
7
+ export type SyncingStatus = routes.node.SyncingStatus;
8
+
9
+ type RunOnResyncedFn = (slot: Slot, signal: AbortSignal) => Promise<void>;
10
+
11
+ /**
12
+ * Track the syncing status of connected beacon node(s)
13
+ */
14
+ export class SyncingStatusTracker {
15
+ private prevSyncingStatus?: SyncingStatus | Error;
16
+
17
+ private readonly fns: RunOnResyncedFn[] = [];
18
+
19
+ constructor(
20
+ private readonly logger: Logger,
21
+ private readonly api: ApiClient,
22
+ private readonly clock: IClock,
23
+ private readonly metrics: Metrics | null
24
+ ) {
25
+ this.clock.runEverySlot(this.checkSyncingStatus);
26
+ }
27
+
28
+ /**
29
+ * Run function when node status changes from syncing to synced
30
+ *
31
+ * Note: does not consider if execution client is offline or syncing and
32
+ * hence it is not useful to schedule tasks that require a non-optimistic node.
33
+ */
34
+ runOnResynced(fn: RunOnResyncedFn): void {
35
+ this.fns.push(fn);
36
+ }
37
+
38
+ private checkSyncingStatus = async (slot: Slot, signal: AbortSignal): Promise<void> => {
39
+ try {
40
+ const syncingStatus = (await this.api.node.getSyncingStatus()).value();
41
+ const {isSyncing, headSlot, syncDistance, isOptimistic, elOffline} = syncingStatus;
42
+ const prevErrorOrSyncing = this.prevSyncingStatus instanceof Error || this.prevSyncingStatus?.isSyncing === true;
43
+
44
+ if (isSyncing === true) {
45
+ this.logger.warn("Node is syncing", {slot, headSlot, syncDistance});
46
+ } else if (this.prevSyncingStatus === undefined || prevErrorOrSyncing) {
47
+ this.logger.info("Node is synced", {slot, headSlot, isOptimistic, elOffline});
48
+ }
49
+ this.logger.verbose("Node syncing status", {slot, ...syncingStatus});
50
+
51
+ this.prevSyncingStatus = syncingStatus;
52
+
53
+ this.metrics?.beaconHealth.set(
54
+ !isSyncing && !isOptimistic && !elOffline ? BeaconHealth.READY : BeaconHealth.SYNCING
55
+ );
56
+
57
+ if (prevErrorOrSyncing && isSyncing === false) {
58
+ await Promise.all(
59
+ this.fns.map((fn) =>
60
+ fn(slot, signal).catch((e) => this.logger.error("Error calling resynced event handler", e))
61
+ )
62
+ );
63
+ }
64
+ } catch (e) {
65
+ // Error likely due to node being offline. In any case, handle failure to
66
+ // check syncing status the same way as if node was previously syncing
67
+ this.prevSyncingStatus = e as Error;
68
+
69
+ this.metrics?.beaconHealth.set(BeaconHealth.ERROR);
70
+
71
+ this.logger.error("Failed to check syncing status", {slot}, this.prevSyncingStatus);
72
+ }
73
+ };
74
+ }
@@ -0,0 +1,58 @@
1
+ import {SYNC_COMMITTEE_SUBNET_SIZE} from "@lodestar/params";
2
+ import {CommitteeIndex, SubcommitteeIndex} from "@lodestar/types";
3
+ import {AttDutyAndProof} from "./attestationDuties.js";
4
+ import {SyncDutyAndProofs, SyncDutySubnet, SyncSelectionProof} from "./syncCommitteeDuties.js";
5
+
6
+ /** Sync committee duty associated to a single sub committee subnet */
7
+ export type SubcommitteeDuty = {
8
+ duty: SyncDutySubnet;
9
+ selectionProof: SyncSelectionProof["selectionProof"];
10
+ };
11
+
12
+ export function groupAttDutiesByCommitteeIndex(duties: AttDutyAndProof[]): Map<CommitteeIndex, AttDutyAndProof[]> {
13
+ const dutiesByCommitteeIndex = new Map<CommitteeIndex, AttDutyAndProof[]>();
14
+
15
+ for (const dutyAndProof of duties) {
16
+ const {committeeIndex} = dutyAndProof.duty;
17
+ let dutyAndProofArr = dutiesByCommitteeIndex.get(committeeIndex);
18
+ if (!dutyAndProofArr) {
19
+ dutyAndProofArr = [];
20
+ dutiesByCommitteeIndex.set(committeeIndex, dutyAndProofArr);
21
+ }
22
+ dutyAndProofArr.push(dutyAndProof);
23
+ }
24
+
25
+ return dutiesByCommitteeIndex;
26
+ }
27
+
28
+ export function groupSyncDutiesBySubcommitteeIndex(
29
+ duties: SyncDutyAndProofs[]
30
+ ): Map<SubcommitteeIndex, SubcommitteeDuty[]> {
31
+ const dutiesBySubcommitteeIndex = new Map<SubcommitteeIndex, SubcommitteeDuty[]>();
32
+
33
+ for (const validatorDuty of duties) {
34
+ for (const {selectionProof, subcommitteeIndex} of validatorDuty.selectionProofs) {
35
+ let dutyAndProofArr = dutiesBySubcommitteeIndex.get(subcommitteeIndex);
36
+ if (!dutyAndProofArr) {
37
+ dutyAndProofArr = [];
38
+ dutiesBySubcommitteeIndex.set(subcommitteeIndex, dutyAndProofArr);
39
+ }
40
+ dutyAndProofArr.push({duty: validatorDuty.duty, selectionProof: selectionProof});
41
+ }
42
+ }
43
+
44
+ return dutiesBySubcommitteeIndex;
45
+ }
46
+
47
+ /**
48
+ * Given a list of indexes of a sync committee returns the list of unique subnet numbers the indexes are part of
49
+ */
50
+ export function syncCommitteeIndicesToSubnets(indexesInCommittee: number[]): number[] {
51
+ const subnets = new Set<number>();
52
+
53
+ for (const indexInCommittee of indexesInCommittee) {
54
+ subnets.add(Math.floor(indexInCommittee / SYNC_COMMITTEE_SUBNET_SIZE));
55
+ }
56
+
57
+ return Array.from(subnets);
58
+ }