@lodestar/validator 1.46.0-dev.d96240a05e → 1.46.0-dev.df02c7532b

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 (123) 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.js.map +1 -1
  5. package/lib/metrics.d.ts +2 -2
  6. package/lib/metrics.d.ts.map +1 -1
  7. package/lib/metrics.js +2 -4
  8. package/lib/metrics.js.map +1 -1
  9. package/lib/repositories/metaDataRepository.js.map +1 -1
  10. package/lib/services/attestation.d.ts +22 -1
  11. package/lib/services/attestation.d.ts.map +1 -1
  12. package/lib/services/attestation.js.map +1 -1
  13. package/lib/services/attestationDuties.d.ts +22 -1
  14. package/lib/services/attestationDuties.d.ts.map +1 -1
  15. package/lib/services/attestationDuties.js +1 -1
  16. package/lib/services/attestationDuties.js.map +1 -1
  17. package/lib/services/block.d.ts +18 -1
  18. package/lib/services/block.d.ts.map +1 -1
  19. package/lib/services/block.js.map +1 -1
  20. package/lib/services/blockDuties.d.ts +11 -1
  21. package/lib/services/blockDuties.d.ts.map +1 -1
  22. package/lib/services/blockDuties.js.map +1 -1
  23. package/lib/services/chainHeaderTracker.js.map +1 -1
  24. package/lib/services/doppelgangerService.d.ts +1 -1
  25. package/lib/services/doppelgangerService.d.ts.map +1 -1
  26. package/lib/services/doppelgangerService.js +1 -2
  27. package/lib/services/doppelgangerService.js.map +1 -1
  28. package/lib/services/emitter.d.ts +1 -1
  29. package/lib/services/emitter.d.ts.map +1 -1
  30. package/lib/services/emitter.js +1 -2
  31. package/lib/services/emitter.js.map +1 -1
  32. package/lib/services/externalSignerSync.js.map +1 -1
  33. package/lib/services/indices.d.ts +2 -0
  34. package/lib/services/indices.d.ts.map +1 -1
  35. package/lib/services/indices.js.map +1 -1
  36. package/lib/services/prepareBeaconProposer.d.ts +2 -1
  37. package/lib/services/prepareBeaconProposer.d.ts.map +1 -1
  38. package/lib/services/prepareBeaconProposer.js.map +1 -1
  39. package/lib/services/proposerPreferences.d.ts +2 -1
  40. package/lib/services/proposerPreferences.d.ts.map +1 -1
  41. package/lib/services/proposerPreferences.js.map +1 -1
  42. package/lib/services/ptc.d.ts +2 -1
  43. package/lib/services/ptc.d.ts.map +1 -1
  44. package/lib/services/ptc.js.map +1 -1
  45. package/lib/services/ptcDuties.d.ts +2 -1
  46. package/lib/services/ptcDuties.d.ts.map +1 -1
  47. package/lib/services/ptcDuties.js.map +1 -1
  48. package/lib/services/syncCommittee.d.ts +21 -1
  49. package/lib/services/syncCommittee.d.ts.map +1 -1
  50. package/lib/services/syncCommittee.js.map +1 -1
  51. package/lib/services/syncCommitteeDuties.d.ts +22 -1
  52. package/lib/services/syncCommitteeDuties.d.ts.map +1 -1
  53. package/lib/services/syncCommitteeDuties.js.map +1 -1
  54. package/lib/services/syncingStatusTracker.d.ts +1 -1
  55. package/lib/services/syncingStatusTracker.d.ts.map +1 -1
  56. package/lib/services/syncingStatusTracker.js.map +1 -1
  57. package/lib/services/utils.js.map +1 -1
  58. package/lib/services/validatorStore.js +2 -3
  59. package/lib/services/validatorStore.js.map +1 -1
  60. package/lib/slashingProtection/attestation/attestationByTargetRepository.js.map +1 -1
  61. package/lib/slashingProtection/attestation/attestationLowerBoundRepository.js.map +1 -1
  62. package/lib/slashingProtection/attestation/errors.js +1 -2
  63. package/lib/slashingProtection/attestation/errors.js.map +1 -1
  64. package/lib/slashingProtection/attestation/index.js.map +1 -1
  65. package/lib/slashingProtection/block/blockBySlotRepository.js.map +1 -1
  66. package/lib/slashingProtection/block/errors.js +1 -2
  67. package/lib/slashingProtection/block/errors.js.map +1 -1
  68. package/lib/slashingProtection/block/index.js.map +1 -1
  69. package/lib/slashingProtection/index.js.map +1 -1
  70. package/lib/slashingProtection/interchange/errors.js +1 -2
  71. package/lib/slashingProtection/interchange/errors.js.map +1 -1
  72. package/lib/slashingProtection/interchange/formats/completeV4.d.ts +1 -1
  73. package/lib/slashingProtection/interchange/formats/completeV4.d.ts.map +1 -1
  74. package/lib/slashingProtection/interchange/formats/completeV4.js.map +1 -1
  75. package/lib/slashingProtection/interchange/formats/v5.js.map +1 -1
  76. package/lib/slashingProtection/interchange/parseInterchange.js.map +1 -1
  77. package/lib/slashingProtection/interchange/serializeInterchange.js.map +1 -1
  78. package/lib/slashingProtection/minMaxSurround/distanceStoreRepository.js.map +1 -1
  79. package/lib/slashingProtection/minMaxSurround/errors.js +1 -2
  80. package/lib/slashingProtection/minMaxSurround/errors.js.map +1 -1
  81. package/lib/slashingProtection/minMaxSurround/minMaxSurround.js.map +1 -1
  82. package/lib/slashingProtection/utils.d.ts +1 -1
  83. package/lib/slashingProtection/utils.d.ts.map +1 -1
  84. package/lib/slashingProtection/utils.js.map +1 -1
  85. package/lib/util/batch.js.map +1 -1
  86. package/lib/util/difference.js.map +1 -1
  87. package/lib/util/externalSignerClient.js +1 -2
  88. package/lib/util/externalSignerClient.js.map +1 -1
  89. package/lib/util/format.js.map +1 -1
  90. package/lib/util/index.d.ts +0 -1
  91. package/lib/util/index.d.ts.map +1 -1
  92. package/lib/util/index.js +0 -1
  93. package/lib/util/index.js.map +1 -1
  94. package/lib/util/logger.d.ts +1 -1
  95. package/lib/util/logger.d.ts.map +1 -1
  96. package/lib/util/logger.js.map +1 -1
  97. package/lib/util/url.js.map +1 -1
  98. package/lib/validator.d.ts +2 -2
  99. package/lib/validator.d.ts.map +1 -1
  100. package/lib/validator.js +2 -3
  101. package/lib/validator.js.map +1 -1
  102. package/package.json +15 -15
  103. package/src/services/attestation.ts +2 -2
  104. package/src/services/attestationDuties.ts +7 -2
  105. package/src/services/block.ts +2 -1
  106. package/src/services/blockDuties.ts +2 -2
  107. package/src/services/doppelgangerService.ts +1 -2
  108. package/src/services/prepareBeaconProposer.ts +2 -1
  109. package/src/services/proposerPreferences.ts +2 -2
  110. package/src/services/ptc.ts +2 -1
  111. package/src/services/ptcDuties.ts +2 -2
  112. package/src/services/syncCommittee.ts +2 -1
  113. package/src/services/syncCommitteeDuties.ts +2 -1
  114. package/src/services/syncingStatusTracker.ts +1 -1
  115. package/src/services/validatorStore.ts +1 -1
  116. package/src/util/index.ts +0 -1
  117. package/src/util/logger.ts +1 -1
  118. package/src/validator.ts +2 -3
  119. package/lib/util/clock.d.ts +0 -55
  120. package/lib/util/clock.d.ts.map +0 -1
  121. package/lib/util/clock.js +0 -141
  122. package/lib/util/clock.js.map +0 -1
  123. package/src/util/clock.ts +0 -182
package/src/util/clock.ts DELETED
@@ -1,182 +0,0 @@
1
- import {ChainForkConfig} from "@lodestar/config";
2
- import {GENESIS_SLOT, SLOTS_PER_EPOCH} from "@lodestar/params";
3
- import {computeEpochAtSlot, computeTimeAtSlot, getCurrentSlot} from "@lodestar/state-transition";
4
- import {Epoch, Slot, TimeSeconds} from "@lodestar/types";
5
- import {ErrorAborted, Logger, isErrorAborted, sleep} from "@lodestar/utils";
6
-
7
- type RunEveryFn = (slot: Slot, signal: AbortSignal) => Promise<void>;
8
-
9
- export type ClockOptions = {
10
- skipSlots?: boolean;
11
- };
12
-
13
- export interface IClock {
14
- readonly genesisTime: number;
15
- readonly secondsPerSlot: number;
16
-
17
- readonly currentEpoch: number;
18
-
19
- start(signal: AbortSignal): void;
20
- runEverySlot(fn: (slot: Slot, signal: AbortSignal) => Promise<void>): void;
21
- runEveryEpoch(fn: (epoch: Epoch, signal: AbortSignal) => Promise<void>): void;
22
- msToSlot(slot: Slot): number;
23
- msFromSlot(slot: Slot): number;
24
- secFromSlot(slot: Slot): number;
25
- getCurrentSlot(): Slot;
26
- getCurrentEpoch(): Epoch;
27
- }
28
-
29
- export enum TimeItem {
30
- Slot,
31
- Epoch,
32
- }
33
-
34
- export class Clock implements IClock {
35
- readonly genesisTime: number;
36
- readonly secondsPerSlot: number;
37
- private readonly config: ChainForkConfig;
38
- private readonly logger: Logger;
39
- private readonly fns: {timeItem: TimeItem; fn: RunEveryFn}[] = [];
40
-
41
- constructor(
42
- config: ChainForkConfig,
43
- logger: Logger,
44
- private readonly opts: {genesisTime: number} & ClockOptions
45
- ) {
46
- this.genesisTime = opts.genesisTime;
47
- this.secondsPerSlot = config.SLOT_DURATION_MS / 1000;
48
- this.config = config;
49
- this.logger = logger;
50
- }
51
-
52
- get currentEpoch(): Epoch {
53
- return computeEpochAtSlot(getCurrentSlot(this.config, this.genesisTime));
54
- }
55
-
56
- start(signal: AbortSignal): void {
57
- for (const {timeItem, fn} of this.fns) {
58
- this.runAtMostEvery(timeItem, signal, fn).catch((e: Error) => {
59
- if (!isErrorAborted(e)) {
60
- this.logger.error("runAtMostEvery", {}, e);
61
- }
62
- });
63
- }
64
- }
65
-
66
- getCurrentSlot(): Slot {
67
- return getCurrentSlot(this.config, this.genesisTime);
68
- }
69
-
70
- getCurrentEpoch(): Epoch {
71
- return computeEpochAtSlot(getCurrentSlot(this.config, this.genesisTime));
72
- }
73
-
74
- runEverySlot(fn: RunEveryFn): void {
75
- this.fns.push({timeItem: TimeItem.Slot, fn});
76
- }
77
-
78
- runEveryEpoch(fn: RunEveryFn): void {
79
- this.fns.push({timeItem: TimeItem.Epoch, fn});
80
- }
81
-
82
- /** Milliseconds from now to a specific slot */
83
- msToSlot(slot: Slot): number {
84
- return computeTimeAtSlot(this.config, slot, this.genesisTime) * 1000 - Date.now();
85
- }
86
-
87
- /** Milliseconds elapsed from a specific slot to now */
88
- msFromSlot(slot: Slot): number {
89
- return Date.now() - computeTimeAtSlot(this.config, slot, this.genesisTime) * 1000;
90
- }
91
-
92
- /** Seconds elapsed from a specific slot to now */
93
- secFromSlot(slot: Slot): number {
94
- return Date.now() / 1000 - computeTimeAtSlot(this.config, slot, this.genesisTime);
95
- }
96
-
97
- /**
98
- * If a task happens to take more than one slot to run, we might skip a slot. This is unfortunate,
99
- * however the alternative is to *always* process every slot, which has the chance of creating a
100
- * theoretically unlimited backlog of tasks. It was a conscious decision to choose to drop tasks
101
- * on an overloaded/latent system rather than overload it even more.
102
- */
103
- private async runAtMostEvery(timeItem: TimeItem, signal: AbortSignal, fn: RunEveryFn): Promise<void> {
104
- // Run immediately first
105
- let slot = getCurrentSlot(this.config, this.genesisTime);
106
- let slotOrEpoch = timeItem === TimeItem.Slot ? slot : computeEpochAtSlot(slot);
107
- while (!signal.aborted) {
108
- // Must catch fn() to ensure `sleep()` is awaited both for resolve and reject
109
- const task = fn(slotOrEpoch, signal).catch((e: Error) => {
110
- if (!isErrorAborted(e)) this.logger.error("Error on runEvery fn", {}, e);
111
- });
112
-
113
- if (timeItem !== TimeItem.Slot || this.opts.skipSlots !== false) {
114
- // await response to only continue with next task if current task finished within slot
115
- await task;
116
- }
117
-
118
- try {
119
- await sleep(this.timeUntilNext(timeItem), signal);
120
- // calling getCurrentSlot here may not be correct when we're close to the next slot
121
- // it's safe to call getCurrentSlotAround after we sleep
122
- const nextSlot = getCurrentSlotAround(this.config, this.genesisTime);
123
-
124
- if (timeItem === TimeItem.Slot) {
125
- if (nextSlot > slot + 1) {
126
- // It's not very likely that we skip more than one slot as HTTP timeout is set
127
- // to SLOT_DURATION_MS so we will fail task before skipping another slot.
128
- this.logger.warn("Skipped slot due to task taking more than one slot to run", {
129
- skippedSlot: slot + 1,
130
- });
131
- }
132
- slotOrEpoch = nextSlot;
133
- } else {
134
- slotOrEpoch = computeEpochAtSlot(nextSlot);
135
- }
136
- slot = nextSlot;
137
- } catch (e) {
138
- if (e instanceof ErrorAborted) {
139
- return;
140
- }
141
- throw e;
142
- }
143
- }
144
- }
145
-
146
- private timeUntilNext(timeItem: TimeItem): number {
147
- const milliSecondsPerSlot = this.config.SLOT_DURATION_MS;
148
- const msFromGenesis = Date.now() - this.genesisTime * 1000;
149
-
150
- if (timeItem === TimeItem.Slot) {
151
- if (msFromGenesis >= 0) {
152
- return milliSecondsPerSlot - (msFromGenesis % milliSecondsPerSlot);
153
- }
154
- return Math.abs(msFromGenesis) % milliSecondsPerSlot;
155
- }
156
- const milliSecondsPerEpoch = SLOTS_PER_EPOCH * milliSecondsPerSlot;
157
- if (msFromGenesis >= 0) {
158
- return milliSecondsPerEpoch - (msFromGenesis % milliSecondsPerEpoch);
159
- }
160
- return Math.abs(msFromGenesis) % milliSecondsPerEpoch;
161
- }
162
- }
163
-
164
- /**
165
- * Same to the spec but we use Math.round instead of Math.floor.
166
- */
167
- export function getCurrentSlotAround(config: ChainForkConfig, genesisTime: TimeSeconds): Slot {
168
- const diffInSeconds = Date.now() / 1000 - genesisTime;
169
- const slotsSinceGenesis = Math.round((diffInSeconds * 1000) / config.SLOT_DURATION_MS);
170
- return GENESIS_SLOT + slotsSinceGenesis;
171
- }
172
-
173
- // function useEventStream() {
174
- // this.stream = this.events.getEventStream([BeaconEventType.BLOCK, BeaconEventType.HEAD, BeaconEventType.CHAIN_REORG]);
175
- // pipeToEmitter(this.stream, this).catch((e: Error) => {
176
- // this.logger.error("Error on stream pipe", {}, e);
177
- // });
178
-
179
- // // On stop
180
- // this.stream.stop();
181
- // this.stream = null;
182
- // }