@lodestar/validator 1.46.0-dev.82546f11da → 1.46.0-dev.8c06abb877

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 (137) hide show
  1. package/lib/buckets.js +1 -2
  2. package/lib/buckets.js.map +1 -1
  3. package/lib/defaults.d.ts.map +1 -1
  4. package/lib/genesis.d.ts.map +1 -1
  5. package/lib/genesis.js +7 -3
  6. package/lib/genesis.js.map +1 -1
  7. package/lib/metrics.d.ts +2 -2
  8. package/lib/metrics.d.ts.map +1 -1
  9. package/lib/metrics.js +2 -4
  10. package/lib/metrics.js.map +1 -1
  11. package/lib/repositories/metaDataRepository.js.map +1 -1
  12. package/lib/services/attestation.d.ts +22 -1
  13. package/lib/services/attestation.d.ts.map +1 -1
  14. package/lib/services/attestation.js.map +1 -1
  15. package/lib/services/attestationDuties.d.ts +22 -1
  16. package/lib/services/attestationDuties.d.ts.map +1 -1
  17. package/lib/services/attestationDuties.js +1 -1
  18. package/lib/services/attestationDuties.js.map +1 -1
  19. package/lib/services/block.d.ts +18 -1
  20. package/lib/services/block.d.ts.map +1 -1
  21. package/lib/services/block.js.map +1 -1
  22. package/lib/services/blockDuties.d.ts +11 -1
  23. package/lib/services/blockDuties.d.ts.map +1 -1
  24. package/lib/services/blockDuties.js.map +1 -1
  25. package/lib/services/chainHeaderTracker.d.ts +6 -0
  26. package/lib/services/chainHeaderTracker.d.ts.map +1 -1
  27. package/lib/services/chainHeaderTracker.js +9 -2
  28. package/lib/services/chainHeaderTracker.js.map +1 -1
  29. package/lib/services/doppelgangerService.d.ts +1 -1
  30. package/lib/services/doppelgangerService.d.ts.map +1 -1
  31. package/lib/services/doppelgangerService.js +1 -2
  32. package/lib/services/doppelgangerService.js.map +1 -1
  33. package/lib/services/emitter.d.ts +1 -1
  34. package/lib/services/emitter.d.ts.map +1 -1
  35. package/lib/services/emitter.js +1 -2
  36. package/lib/services/emitter.js.map +1 -1
  37. package/lib/services/externalSignerSync.js.map +1 -1
  38. package/lib/services/indices.d.ts +2 -0
  39. package/lib/services/indices.d.ts.map +1 -1
  40. package/lib/services/indices.js.map +1 -1
  41. package/lib/services/prepareBeaconProposer.d.ts +2 -1
  42. package/lib/services/prepareBeaconProposer.d.ts.map +1 -1
  43. package/lib/services/prepareBeaconProposer.js.map +1 -1
  44. package/lib/services/proposerPreferences.d.ts +2 -1
  45. package/lib/services/proposerPreferences.d.ts.map +1 -1
  46. package/lib/services/proposerPreferences.js.map +1 -1
  47. package/lib/services/ptc.d.ts +2 -1
  48. package/lib/services/ptc.d.ts.map +1 -1
  49. package/lib/services/ptc.js.map +1 -1
  50. package/lib/services/ptcDuties.d.ts +2 -1
  51. package/lib/services/ptcDuties.d.ts.map +1 -1
  52. package/lib/services/ptcDuties.js.map +1 -1
  53. package/lib/services/syncCommittee.d.ts +22 -1
  54. package/lib/services/syncCommittee.d.ts.map +1 -1
  55. package/lib/services/syncCommittee.js +25 -6
  56. package/lib/services/syncCommittee.js.map +1 -1
  57. package/lib/services/syncCommitteeDuties.d.ts +22 -1
  58. package/lib/services/syncCommitteeDuties.d.ts.map +1 -1
  59. package/lib/services/syncCommitteeDuties.js.map +1 -1
  60. package/lib/services/syncingStatusTracker.d.ts +9 -1
  61. package/lib/services/syncingStatusTracker.d.ts.map +1 -1
  62. package/lib/services/syncingStatusTracker.js +13 -0
  63. package/lib/services/syncingStatusTracker.js.map +1 -1
  64. package/lib/services/utils.js.map +1 -1
  65. package/lib/services/validatorStore.js +2 -3
  66. package/lib/services/validatorStore.js.map +1 -1
  67. package/lib/slashingProtection/attestation/attestationByTargetRepository.js.map +1 -1
  68. package/lib/slashingProtection/attestation/attestationLowerBoundRepository.js.map +1 -1
  69. package/lib/slashingProtection/attestation/errors.js +1 -2
  70. package/lib/slashingProtection/attestation/errors.js.map +1 -1
  71. package/lib/slashingProtection/attestation/index.js.map +1 -1
  72. package/lib/slashingProtection/block/blockBySlotRepository.js.map +1 -1
  73. package/lib/slashingProtection/block/errors.js +1 -2
  74. package/lib/slashingProtection/block/errors.js.map +1 -1
  75. package/lib/slashingProtection/block/index.js.map +1 -1
  76. package/lib/slashingProtection/index.js.map +1 -1
  77. package/lib/slashingProtection/interchange/errors.js +1 -2
  78. package/lib/slashingProtection/interchange/errors.js.map +1 -1
  79. package/lib/slashingProtection/interchange/formats/completeV4.d.ts +1 -1
  80. package/lib/slashingProtection/interchange/formats/completeV4.d.ts.map +1 -1
  81. package/lib/slashingProtection/interchange/formats/completeV4.js.map +1 -1
  82. package/lib/slashingProtection/interchange/formats/v5.js.map +1 -1
  83. package/lib/slashingProtection/interchange/parseInterchange.js.map +1 -1
  84. package/lib/slashingProtection/interchange/serializeInterchange.js.map +1 -1
  85. package/lib/slashingProtection/minMaxSurround/distanceStoreRepository.js.map +1 -1
  86. package/lib/slashingProtection/minMaxSurround/errors.js +1 -2
  87. package/lib/slashingProtection/minMaxSurround/errors.js.map +1 -1
  88. package/lib/slashingProtection/minMaxSurround/minMaxSurround.js.map +1 -1
  89. package/lib/slashingProtection/utils.d.ts +1 -1
  90. package/lib/slashingProtection/utils.d.ts.map +1 -1
  91. package/lib/slashingProtection/utils.js.map +1 -1
  92. package/lib/util/batch.js.map +1 -1
  93. package/lib/util/difference.js.map +1 -1
  94. package/lib/util/externalSignerClient.js +1 -2
  95. package/lib/util/externalSignerClient.js.map +1 -1
  96. package/lib/util/format.js.map +1 -1
  97. package/lib/util/index.d.ts +0 -2
  98. package/lib/util/index.d.ts.map +1 -1
  99. package/lib/util/index.js +0 -2
  100. package/lib/util/index.js.map +1 -1
  101. package/lib/util/logger.d.ts +1 -1
  102. package/lib/util/logger.d.ts.map +1 -1
  103. package/lib/util/logger.js.map +1 -1
  104. package/lib/util/url.js.map +1 -1
  105. package/lib/validator.d.ts +2 -2
  106. package/lib/validator.d.ts.map +1 -1
  107. package/lib/validator.js +4 -5
  108. package/lib/validator.js.map +1 -1
  109. package/package.json +15 -15
  110. package/src/genesis.ts +6 -4
  111. package/src/services/attestation.ts +2 -2
  112. package/src/services/attestationDuties.ts +7 -2
  113. package/src/services/block.ts +2 -1
  114. package/src/services/blockDuties.ts +2 -2
  115. package/src/services/chainHeaderTracker.ts +15 -2
  116. package/src/services/doppelgangerService.ts +1 -2
  117. package/src/services/prepareBeaconProposer.ts +2 -1
  118. package/src/services/proposerPreferences.ts +2 -2
  119. package/src/services/ptc.ts +2 -1
  120. package/src/services/ptcDuties.ts +2 -2
  121. package/src/services/syncCommittee.ts +31 -8
  122. package/src/services/syncCommitteeDuties.ts +2 -1
  123. package/src/services/syncingStatusTracker.ts +15 -1
  124. package/src/services/validatorStore.ts +1 -1
  125. package/src/util/index.ts +0 -2
  126. package/src/util/logger.ts +1 -1
  127. package/src/validator.ts +10 -5
  128. package/lib/util/clock.d.ts +0 -55
  129. package/lib/util/clock.d.ts.map +0 -1
  130. package/lib/util/clock.js +0 -141
  131. package/lib/util/clock.js.map +0 -1
  132. package/lib/util/params.d.ts +0 -20
  133. package/lib/util/params.d.ts.map +0 -1
  134. package/lib/util/params.js +0 -298
  135. package/lib/util/params.js.map +0 -1
  136. package/src/util/clock.ts +0 -182
  137. package/src/util/params.ts +0 -344
@@ -1,11 +1,12 @@
1
1
  import {ApiClient} from "@lodestar/api";
2
2
  import {ChainForkConfig} from "@lodestar/config";
3
3
  import {ForkName, isForkPostAltair} from "@lodestar/params";
4
+ import {IClock} from "@lodestar/state-transition";
4
5
  import {CommitteeIndex, Root, Slot, altair} from "@lodestar/types";
5
6
  import {sleep} from "@lodestar/utils";
6
7
  import {Metrics} from "../metrics.js";
7
8
  import {PubkeyHex} from "../types.js";
8
- import {IClock, LoggerVc} from "../util/index.js";
9
+ import {LoggerVc} from "../util/index.js";
9
10
  import {ChainHeaderTracker} from "./chainHeaderTracker.js";
10
11
  import {ValidatorEventEmitter} from "./emitter.js";
11
12
  import {SyncCommitteeDutiesService, SyncDutyAndProofs} from "./syncCommitteeDuties.js";
@@ -66,7 +67,16 @@ export class SyncCommitteeService {
66
67
  return;
67
68
  }
68
69
 
69
- // Fetch info first so a potential delay is absorbed by the sleep() below
70
+ // An optimistic validator MUST NOT participate in sync committees, since it has not
71
+ // fully verified the execution payload of the head block it would sign over.
72
+ // https://github.com/ethereum/consensus-specs/blob/v1.6.1/sync/optimistic.md#participating-in-sync-committees
73
+ if (this.syncingStatusTracker.isNodeOptimistic() === true) {
74
+ this.logger.debug("Skipping sync committee duties while node is optimistic", {slot});
75
+ return;
76
+ }
77
+
78
+ // Fetch info first so a potential delay is absorbed by the sleep() below.
79
+ // This signs selection proofs, so keep it after the optimistic-node gate above.
70
80
  const dutiesAtSlot = await this.dutiesService.getDutiesAtSlot(slot);
71
81
  if (dutiesAtSlot.length === 0) {
72
82
  return;
@@ -82,9 +92,15 @@ export class SyncCommitteeService {
82
92
  ]);
83
93
  this.metrics?.syncCommitteeStepCallProduceMessage.observe(this.clock.secFromSlot(slot) - syncMessageDueMs / 1000);
84
94
 
85
- // Step 1. Download, sign and publish an `SyncCommitteeMessage` for each validator.
95
+ const head = await this.getHeadForSyncCommitteeMessage(slot);
96
+ if (head.executionOptimistic) {
97
+ this.logger.debug("Skipping sync committee duties while head is optimistic", {slot});
98
+ return;
99
+ }
100
+
101
+ // Step 1. Sign and publish a `SyncCommitteeMessage` for each validator.
86
102
  // Differs from AttestationService, `SyncCommitteeMessage` are equal for all
87
- const beaconBlockRoot = await this.produceAndPublishSyncCommittees(fork, slot, dutiesAtSlot);
103
+ const beaconBlockRoot = await this.produceAndPublishSyncCommittees(fork, slot, head.root, dutiesAtSlot);
88
104
 
89
105
  // Step 2. If an attestation was produced, make an aggregate.
90
106
  // First, wait until the `CONTRIBUTION_DUE_BPS` of the slot
@@ -126,6 +142,7 @@ export class SyncCommitteeService {
126
142
  private async produceAndPublishSyncCommittees(
127
143
  fork: ForkName,
128
144
  slot: Slot,
145
+ blockRoot: Root,
129
146
  duties: SyncDutyAndProofs[]
130
147
  ): Promise<Root> {
131
148
  const logCtx = {slot};
@@ -136,10 +153,6 @@ export class SyncCommitteeService {
136
153
  // Spec: the validator should prepare a SyncCommitteeMessage for the previous slot (slot - 1)
137
154
  // as soon as they have determined the head block of slot - 1
138
155
 
139
- const blockRoot: Uint8Array =
140
- this.chainHeaderTracker.getCurrentChainHead(slot) ??
141
- (await this.api.beacon.getBlockRoot({blockId: "head"})).value().root;
142
-
143
156
  const signatures: altair.SyncCommitteeMessage[] = [];
144
157
 
145
158
  await Promise.all(
@@ -182,6 +195,16 @@ export class SyncCommitteeService {
182
195
  return blockRoot;
183
196
  }
184
197
 
198
+ private async getHeadForSyncCommitteeMessage(slot: Slot): Promise<{root: Root; executionOptimistic: boolean}> {
199
+ const cachedHead = this.chainHeaderTracker.getCurrentChainHeadData(slot);
200
+ if (cachedHead) {
201
+ return cachedHead;
202
+ }
203
+
204
+ const res = await this.api.beacon.getBlockRoot({blockId: "head"});
205
+ return {root: res.value().root, executionOptimistic: res.meta().executionOptimistic};
206
+ }
207
+
185
208
  /**
186
209
  * Performs the second step of the attesting process: downloading an aggregated `SyncCommittee`,
187
210
  * converting it into a `SignedAggregateAndProof` and returning it to the BN.
@@ -2,6 +2,7 @@ import {ApiClient, routes} from "@lodestar/api";
2
2
  import {ChainForkConfig} from "@lodestar/config";
3
3
  import {EPOCHS_PER_SYNC_COMMITTEE_PERIOD, SYNC_COMMITTEE_SUBNET_SIZE} from "@lodestar/params";
4
4
  import {
5
+ IClock,
5
6
  computeEpochAtSlot,
6
7
  computeSyncPeriodAtEpoch,
7
8
  computeSyncPeriodAtSlot,
@@ -12,7 +13,7 @@ import {BLSSignature, Epoch, Slot, SyncPeriod, ValidatorIndex} from "@lodestar/t
12
13
  import {toPubkeyHex} from "@lodestar/utils";
13
14
  import {Metrics} from "../metrics.js";
14
15
  import {PubkeyHex} from "../types.js";
15
- import {IClock, LoggerVc} from "../util/index.js";
16
+ import {LoggerVc} from "../util/index.js";
16
17
  import {SyncingStatusTracker} from "./syncingStatusTracker.js";
17
18
  import {syncCommitteeIndicesToSubnets} from "./utils.js";
18
19
  import {ValidatorStore} from "./validatorStore.js";
@@ -1,8 +1,8 @@
1
1
  import {ApiClient, routes} from "@lodestar/api";
2
+ import {IClock} from "@lodestar/state-transition";
2
3
  import {Slot} from "@lodestar/types";
3
4
  import {Logger} from "@lodestar/utils";
4
5
  import {BeaconHealth, Metrics} from "../metrics.js";
5
- import {IClock} from "../util/clock.js";
6
6
 
7
7
  export type SyncingStatus = routes.node.SyncingStatus;
8
8
 
@@ -35,6 +35,20 @@ export class SyncingStatusTracker {
35
35
  this.fns.push(fn);
36
36
  }
37
37
 
38
+ /**
39
+ * Whether the node is currently optimistic (i.e. the head block's execution payload
40
+ * has not yet been validated) based on the last successful syncing status check.
41
+ *
42
+ * Returns `undefined` if the status is not yet known (never fetched or last check
43
+ * errored); callers should not assume the node is optimistic in that case.
44
+ */
45
+ isNodeOptimistic(): boolean | undefined {
46
+ if (this.prevSyncingStatus === undefined || this.prevSyncingStatus instanceof Error) {
47
+ return undefined;
48
+ }
49
+ return this.prevSyncingStatus.isOptimistic;
50
+ }
51
+
38
52
  private checkSyncingStatus = async (slot: Slot, signal: AbortSignal): Promise<void> => {
39
53
  try {
40
54
  const syncingStatus = (await this.api.node.getSyncingStatus()).value();
@@ -738,7 +738,7 @@ export class ValidatorStore {
738
738
  proposalSlot: duty.slot,
739
739
  validatorIndex: duty.validatorIndex,
740
740
  feeRecipient: fromHex(feeRecipient),
741
- targetGasLimit: gasLimit,
741
+ targetGasLimit: BigInt(gasLimit),
742
742
  };
743
743
 
744
744
  const signingSlot = duty.slot;
package/src/util/index.ts CHANGED
@@ -1,6 +1,4 @@
1
1
  export * from "./batch.js";
2
- export * from "./clock.js";
3
2
  export * from "./difference.js";
4
3
  export * from "./logger.js";
5
- export * from "./params.js";
6
4
  export * from "./url.js";
@@ -1,6 +1,6 @@
1
1
  import {ApiError} from "@lodestar/api";
2
+ import {IClock} from "@lodestar/state-transition";
2
3
  import {LogData, Logger, isErrorAborted} from "@lodestar/utils";
3
- import {IClock} from "./clock.js";
4
4
 
5
5
  export type LoggerVc = Logger & {
6
6
  isSyncing(e: Error): void;
package/src/validator.ts CHANGED
@@ -1,6 +1,12 @@
1
1
  import {ApiClient, ApiRequestInit, defaultInit, getClient, routes} from "@lodestar/api";
2
- import {BeaconConfig, ChainForkConfig, createBeaconConfig} from "@lodestar/config";
3
- import {computeEpochAtSlot, getCurrentSlot} from "@lodestar/state-transition";
2
+ import {
3
+ BeaconConfig,
4
+ ChainForkConfig,
5
+ NotEqualParamsError,
6
+ assertEqualParams,
7
+ createBeaconConfig,
8
+ } from "@lodestar/config";
9
+ import {Clock, ClockOptions, IClock, computeEpochAtSlot, getCurrentSlot} from "@lodestar/state-transition";
4
10
  import {BLSPubkey, phase0, ssz} from "@lodestar/types";
5
11
  import {Genesis} from "@lodestar/types/phase0";
6
12
  import {Logger, toPrintableUrl, toRootHex} from "@lodestar/utils";
@@ -23,8 +29,7 @@ import {SyncingStatusTracker} from "./services/syncingStatusTracker.js";
23
29
  import {Signer, ValidatorProposerConfig, ValidatorStore, defaultOptions} from "./services/validatorStore.js";
24
30
  import {ISlashingProtection, Interchange, InterchangeFormatVersion} from "./slashingProtection/index.js";
25
31
  import {LodestarValidatorDatabaseController, ProcessShutdownCallback, PubkeyHex} from "./types.js";
26
- import {Clock, ClockOptions, IClock} from "./util/clock.js";
27
- import {NotEqualParamsError, assertEqualParams, getLoggerVc} from "./util/index.js";
32
+ import {getLoggerVc} from "./util/index.js";
28
33
 
29
34
  export type ValidatorModules = {
30
35
  opts: ValidatorOptions;
@@ -356,7 +361,7 @@ export class Validator {
356
361
 
357
362
  const res = await api.config.getSpec();
358
363
  assertEqualParams(config, res.value());
359
- logger.info("Verified connected beacon node and validator have same the config");
364
+ logger.info("Verified connected beacon node and validator have the same config");
360
365
 
361
366
  await assertEqualGenesis(opts, genesis);
362
367
  logger.info("Verified connected beacon node and validator have the same genesisValidatorRoot");
@@ -1,55 +0,0 @@
1
- import { ChainForkConfig } from "@lodestar/config";
2
- import { Epoch, Slot, TimeSeconds } from "@lodestar/types";
3
- import { Logger } from "@lodestar/utils";
4
- type RunEveryFn = (slot: Slot, signal: AbortSignal) => Promise<void>;
5
- export type ClockOptions = {
6
- skipSlots?: boolean;
7
- };
8
- export interface IClock {
9
- readonly genesisTime: number;
10
- readonly secondsPerSlot: number;
11
- readonly currentEpoch: number;
12
- start(signal: AbortSignal): void;
13
- runEverySlot(fn: (slot: Slot, signal: AbortSignal) => Promise<void>): void;
14
- runEveryEpoch(fn: (epoch: Epoch, signal: AbortSignal) => Promise<void>): void;
15
- msToSlot(slot: Slot): number;
16
- msFromSlot(slot: Slot): number;
17
- secFromSlot(slot: Slot): number;
18
- getCurrentSlot(): Slot;
19
- getCurrentEpoch(): Epoch;
20
- }
21
- export declare enum TimeItem {
22
- Slot = 0,
23
- Epoch = 1
24
- }
25
- export declare class Clock implements IClock {
26
- private readonly opts;
27
- readonly genesisTime: number;
28
- readonly secondsPerSlot: number;
29
- private readonly config;
30
- private readonly logger;
31
- private readonly fns;
32
- constructor(config: ChainForkConfig, logger: Logger, opts: {
33
- genesisTime: number;
34
- } & ClockOptions);
35
- get currentEpoch(): Epoch;
36
- start(signal: AbortSignal): void;
37
- getCurrentSlot(): Slot;
38
- getCurrentEpoch(): Epoch;
39
- runEverySlot(fn: RunEveryFn): void;
40
- runEveryEpoch(fn: RunEveryFn): void;
41
- /** Milliseconds from now to a specific slot */
42
- msToSlot(slot: Slot): number;
43
- /** Milliseconds elapsed from a specific slot to now */
44
- msFromSlot(slot: Slot): number;
45
- /** Seconds elapsed from a specific slot to now */
46
- secFromSlot(slot: Slot): number;
47
- private runAtMostEvery;
48
- private timeUntilNext;
49
- }
50
- /**
51
- * Same to the spec but we use Math.round instead of Math.floor.
52
- */
53
- export declare function getCurrentSlotAround(config: ChainForkConfig, genesisTime: TimeSeconds): Slot;
54
- export {};
55
- //# sourceMappingURL=clock.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"clock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,CAAC,IAAI;IATvB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAkB;IACzC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAA8C;IAElE,YACE,MAAM,EAAE,eAAe,EACvB,MAAM,EAAE,MAAM,EACG,IAAI,EAAE;QAAC,WAAW,EAAE,MAAM,CAAA;KAAC,GAAG,YAAY,EAM5D;IAED,IAAI,YAAY,IAAI,KAAK,CAExB;IAED,KAAK,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI,CAQ/B;IAED,cAAc,IAAI,IAAI,CAErB;IAED,eAAe,IAAI,KAAK,CAEvB;IAED,YAAY,CAAC,EAAE,EAAE,UAAU,GAAG,IAAI,CAEjC;IAED,aAAa,CAAC,EAAE,EAAE,UAAU,GAAG,IAAI,CAElC;IAED,+CAA+C;IAC/C,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAE3B;IAED,uDAAuD;IACvD,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAE7B;IAED,kDAAkD;IAClD,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAE9B;YAQa,cAAc;IA2C5B,OAAO,CAAC,aAAa;CAgBtB;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,eAAe,EAAE,WAAW,EAAE,WAAW,GAAG,IAAI,CAI5F"}
package/lib/util/clock.js DELETED
@@ -1,141 +0,0 @@
1
- import { GENESIS_SLOT, SLOTS_PER_EPOCH } from "@lodestar/params";
2
- import { computeEpochAtSlot, computeTimeAtSlot, getCurrentSlot } from "@lodestar/state-transition";
3
- import { ErrorAborted, isErrorAborted, sleep } from "@lodestar/utils";
4
- export { TimeItem };
5
- var TimeItem;
6
- (function (TimeItem) {
7
- TimeItem[TimeItem["Slot"] = 0] = "Slot";
8
- TimeItem[TimeItem["Epoch"] = 1] = "Epoch";
9
- })(TimeItem || (TimeItem = {}));
10
- export class Clock {
11
- opts;
12
- genesisTime;
13
- secondsPerSlot;
14
- config;
15
- logger;
16
- fns = [];
17
- constructor(config, logger, opts) {
18
- this.opts = opts;
19
- this.genesisTime = opts.genesisTime;
20
- this.secondsPerSlot = config.SLOT_DURATION_MS / 1000;
21
- this.config = config;
22
- this.logger = logger;
23
- }
24
- get currentEpoch() {
25
- return computeEpochAtSlot(getCurrentSlot(this.config, this.genesisTime));
26
- }
27
- start(signal) {
28
- for (const { timeItem, fn } of this.fns) {
29
- this.runAtMostEvery(timeItem, signal, fn).catch((e) => {
30
- if (!isErrorAborted(e)) {
31
- this.logger.error("runAtMostEvery", {}, e);
32
- }
33
- });
34
- }
35
- }
36
- getCurrentSlot() {
37
- return getCurrentSlot(this.config, this.genesisTime);
38
- }
39
- getCurrentEpoch() {
40
- return computeEpochAtSlot(getCurrentSlot(this.config, this.genesisTime));
41
- }
42
- runEverySlot(fn) {
43
- this.fns.push({ timeItem: TimeItem.Slot, fn });
44
- }
45
- runEveryEpoch(fn) {
46
- this.fns.push({ timeItem: TimeItem.Epoch, fn });
47
- }
48
- /** Milliseconds from now to a specific slot */
49
- msToSlot(slot) {
50
- return computeTimeAtSlot(this.config, slot, this.genesisTime) * 1000 - Date.now();
51
- }
52
- /** Milliseconds elapsed from a specific slot to now */
53
- msFromSlot(slot) {
54
- return Date.now() - computeTimeAtSlot(this.config, slot, this.genesisTime) * 1000;
55
- }
56
- /** Seconds elapsed from a specific slot to now */
57
- secFromSlot(slot) {
58
- return Date.now() / 1000 - computeTimeAtSlot(this.config, slot, this.genesisTime);
59
- }
60
- /**
61
- * If a task happens to take more than one slot to run, we might skip a slot. This is unfortunate,
62
- * however the alternative is to *always* process every slot, which has the chance of creating a
63
- * theoretically unlimited backlog of tasks. It was a conscious decision to choose to drop tasks
64
- * on an overloaded/latent system rather than overload it even more.
65
- */
66
- async runAtMostEvery(timeItem, signal, fn) {
67
- // Run immediately first
68
- let slot = getCurrentSlot(this.config, this.genesisTime);
69
- let slotOrEpoch = timeItem === TimeItem.Slot ? slot : computeEpochAtSlot(slot);
70
- while (!signal.aborted) {
71
- // Must catch fn() to ensure `sleep()` is awaited both for resolve and reject
72
- const task = fn(slotOrEpoch, signal).catch((e) => {
73
- if (!isErrorAborted(e))
74
- this.logger.error("Error on runEvery fn", {}, e);
75
- });
76
- if (timeItem !== TimeItem.Slot || this.opts.skipSlots !== false) {
77
- // await response to only continue with next task if current task finished within slot
78
- await task;
79
- }
80
- try {
81
- await sleep(this.timeUntilNext(timeItem), signal);
82
- // calling getCurrentSlot here may not be correct when we're close to the next slot
83
- // it's safe to call getCurrentSlotAround after we sleep
84
- const nextSlot = getCurrentSlotAround(this.config, this.genesisTime);
85
- if (timeItem === TimeItem.Slot) {
86
- if (nextSlot > slot + 1) {
87
- // It's not very likely that we skip more than one slot as HTTP timeout is set
88
- // to SLOT_DURATION_MS so we will fail task before skipping another slot.
89
- this.logger.warn("Skipped slot due to task taking more than one slot to run", {
90
- skippedSlot: slot + 1,
91
- });
92
- }
93
- slotOrEpoch = nextSlot;
94
- }
95
- else {
96
- slotOrEpoch = computeEpochAtSlot(nextSlot);
97
- }
98
- slot = nextSlot;
99
- }
100
- catch (e) {
101
- if (e instanceof ErrorAborted) {
102
- return;
103
- }
104
- throw e;
105
- }
106
- }
107
- }
108
- timeUntilNext(timeItem) {
109
- const milliSecondsPerSlot = this.config.SLOT_DURATION_MS;
110
- const msFromGenesis = Date.now() - this.genesisTime * 1000;
111
- if (timeItem === TimeItem.Slot) {
112
- if (msFromGenesis >= 0) {
113
- return milliSecondsPerSlot - (msFromGenesis % milliSecondsPerSlot);
114
- }
115
- return Math.abs(msFromGenesis) % milliSecondsPerSlot;
116
- }
117
- const milliSecondsPerEpoch = SLOTS_PER_EPOCH * milliSecondsPerSlot;
118
- if (msFromGenesis >= 0) {
119
- return milliSecondsPerEpoch - (msFromGenesis % milliSecondsPerEpoch);
120
- }
121
- return Math.abs(msFromGenesis) % milliSecondsPerEpoch;
122
- }
123
- }
124
- /**
125
- * Same to the spec but we use Math.round instead of Math.floor.
126
- */
127
- export function getCurrentSlotAround(config, genesisTime) {
128
- const diffInSeconds = Date.now() / 1000 - genesisTime;
129
- const slotsSinceGenesis = Math.round((diffInSeconds * 1000) / config.SLOT_DURATION_MS);
130
- return GENESIS_SLOT + slotsSinceGenesis;
131
- }
132
- // function useEventStream() {
133
- // this.stream = this.events.getEventStream([BeaconEventType.BLOCK, BeaconEventType.HEAD, BeaconEventType.CHAIN_REORG]);
134
- // pipeToEmitter(this.stream, this).catch((e: Error) => {
135
- // this.logger.error("Error on stream pipe", {}, e);
136
- // });
137
- // // On stop
138
- // this.stream.stop();
139
- // this.stream = null;
140
- // }
141
- //# sourceMappingURL=clock.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"clock.js","sourceRoot":"","sources":["../../src/util/clock.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,YAAY,EAAE,eAAe,EAAC,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAC,kBAAkB,EAAE,iBAAiB,EAAE,cAAc,EAAC,MAAM,4BAA4B,CAAC;AAEjG,OAAO,EAAC,YAAY,EAAU,cAAc,EAAE,KAAK,EAAC,MAAM,iBAAiB,CAAC;SAwBhE,QAAQ;AAApB,IAAY,QAGX;AAHD,WAAY,QAAQ;IAClB,uCAAI,CAAA;IACJ,yCAAK,CAAA;AAAC,CACR,EAHY,QAAQ,KAAR,QAAQ,QAGnB;AAED,MAAM,OAAO,KAAK;IAUG,IAAI;IATd,WAAW,CAAS;IACpB,cAAc,CAAS;IACf,MAAM,CAAkB;IACxB,MAAM,CAAS;IACf,GAAG,GAA2C,EAAE,CAAC;IAElE,YACE,MAAuB,EACvB,MAAc,EACG,IAA0C,EAC3D;oBADiB,IAAI;QAErB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAA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AQ,KAAK,QAAQ,CAAC,IAAI,EAAE,CAAC;YAC/B,IAAI,aAAa,IAAI,CAAC,EAAE,CAAC;gBACvB,OAAO,mBAAmB,GAAG,CAAC,aAAa,GAAG,mBAAmB,CAAC,CAAC;YACrE,CAAC;YACD,OAAO,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,GAAG,mBAAmB,CAAC;QACvD,CAAC;QACD,MAAM,oBAAoB,GAAG,eAAe,GAAG,mBAAmB,CAAC;QACnE,IAAI,aAAa,IAAI,CAAC,EAAE,CAAC;YACvB,OAAO,oBAAoB,GAAG,CAAC,aAAa,GAAG,oBAAoB,CAAC,CAAC;QACvE,CAAC;QACD,OAAO,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,GAAG,oBAAoB,CAAC;IAAA,CACvD;CACF;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,MAAuB,EAAE,WAAwB,EAAQ;IAC5F,MAAM,aAAa,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,GAAG,WAAW,CAAC;IACtD,MAAM,iBAAiB,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,aAAa,GAAG,IAAI,CAAC,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;IACvF,OAAO,YAAY,GAAG,iBAAiB,CAAC;AAAA,CACzC;AAED,8BAA8B;AAC9B,0HAA0H;AAC1H,2DAA2D;AAC3D,wDAAwD;AACxD,QAAQ;AAER,eAAe;AACf,wBAAwB;AACxB,wBAAwB;AACxB,IAAI"}
@@ -1,20 +0,0 @@
1
- import { ChainConfig, SpecJson } from "@lodestar/config";
2
- export declare class NotEqualParamsError extends Error {
3
- }
4
- /**
5
- * Assert localConfig values match externalSpecJson. externalSpecJson may contain more values than localConfig.
6
- *
7
- * This check ensures that the validator is connected to a beacon node of the exact same network and params.
8
- * Otherwise, signatures may be rejected, time may be un-equal and other bugs that are harder to debug caused
9
- * by different parameters.
10
- *
11
- * This check however can't compare the full config as is, since some parameters are not critical to the spec and
12
- * can be changed un-expectedly. Also, fork parameters can change un-expectedly, like their _FORK_VERSION or _EPOCH.
13
- * Note that the config API endpoint is not precisely specified, so each clients can return a different set of
14
- * parameters.
15
- *
16
- * So this check only compares a specific list of parameters that are consensus critical, ignoring the rest. Typed
17
- * config and preset ensure new parameters are labeled critical or ignore, facilitating maintenance of the list.
18
- */
19
- export declare function assertEqualParams(localConfig: ChainConfig, externalSpecJson: SpecJson): void;
20
- //# sourceMappingURL=params.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"params.d.ts","sourceRoot":"","sources":["../../src/util/params.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,WAAW,EAAE,QAAQ,EAA6C,MAAM,kBAAkB,CAAC;AAGtH,qBAAa,mBAAoB,SAAQ,KAAK;CAAG;AAIjD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,WAAW,EAAE,gBAAgB,EAAE,QAAQ,GAAG,IAAI,CAyE5F"}