@aztec/aztec-node 0.0.1-commit.96dac018d → 0.0.1-commit.9badcec54

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.
@@ -1,10 +1,10 @@
1
1
  import type { EpochCache } from '@aztec/epoch-cache';
2
2
  import { createLogger } from '@aztec/foundation/log';
3
- import type { DataStoreConfig } from '@aztec/kv-store/config';
4
3
  import { createStore } from '@aztec/kv-store/lmdb-v2';
5
4
  import type { P2PClient } from '@aztec/p2p';
6
5
  import type { L2BlockSource } from '@aztec/stdlib/block';
7
6
  import type { SlasherConfig } from '@aztec/stdlib/interfaces/server';
7
+ import type { DataStoreConfig } from '@aztec/stdlib/kv-store';
8
8
 
9
9
  import type { SentinelConfig } from './config.js';
10
10
  import { Sentinel } from './sentinel.js';
@@ -88,7 +88,7 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
88
88
 
89
89
  /** Loads initial slot and initializes blockstream. We will not process anything at or before the initial slot. */
90
90
  protected async init() {
91
- this.initialSlot = this.epochCache.getEpochAndSlotNow().slot;
91
+ this.initialSlot = this.epochCache.getSlotNow();
92
92
  const startingBlock = BlockNumber(await this.archiver.getBlockNumber());
93
93
  this.logger.info(`Starting validator sentinel with initial slot ${this.initialSlot} and block ${startingBlock}`);
94
94
  this.blockStream = new L2BlockStream(this.archiver, this.l2TipsStore, this, this.logger, { startingBlock });
@@ -219,7 +219,7 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
219
219
  // Check that we have at least requiredConsecutiveEpochs and that all of them are above the inactivity threshold
220
220
  return pastEpochs
221
221
  .slice(0, requiredConsecutiveEpochs)
222
- .every(p => p.missed / p.total >= this.config.slashInactivityTargetPercentage);
222
+ .every(p => (p.total === 0 ? false : p.missed / p.total >= this.config.slashInactivityTargetPercentage));
223
223
  }
224
224
 
225
225
  protected async handleProvenPerformance(epoch: EpochNumber, performance: ValidatorsEpochPerformance) {
@@ -228,7 +228,7 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
228
228
  }
229
229
 
230
230
  const inactiveValidators = getEntries(performance)
231
- .filter(([_, { missed, total }]) => missed / total >= this.config.slashInactivityTargetPercentage)
231
+ .filter(([_, { missed, total }]) => total > 0 && missed / total >= this.config.slashInactivityTargetPercentage)
232
232
  .map(([address]) => address);
233
233
 
234
234
  this.logger.debug(`Found ${inactiveValidators.length} inactive validators in epoch ${epoch}`, {
@@ -264,7 +264,7 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
264
264
  * and we don't have that data if we were offline during the period.
265
265
  */
266
266
  public async work() {
267
- const { slot: currentSlot } = this.epochCache.getEpochAndSlotNow();
267
+ const currentSlot = this.epochCache.getSlotNow();
268
268
  try {
269
269
  // Manually sync the block stream to ensure we have the latest data.
270
270
  // Note we never `start` the blockstream, so it loops at the same pace as we do.
@@ -309,9 +309,9 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
309
309
  return false;
310
310
  }
311
311
 
312
- const archiverSlot = await this.archiver.getL2SlotNumber();
313
- if (archiverSlot === undefined || archiverSlot < targetSlot) {
314
- this.logger.debug(`Waiting for archiver to sync with L2 slot ${targetSlot}`, { archiverSlot, targetSlot });
312
+ const syncedSlot = await this.archiver.getSyncedL2SlotNumber();
313
+ if (syncedSlot === undefined || syncedSlot < targetSlot) {
314
+ this.logger.debug(`Waiting for archiver to sync with L2 slot ${targetSlot}`, { syncedSlot, targetSlot });
315
315
  return false;
316
316
  }
317
317
 
@@ -436,7 +436,7 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
436
436
  ? fromEntries(await Promise.all(validators.map(async v => [v.toString(), await this.store.getHistory(v)])))
437
437
  : await this.store.getHistories();
438
438
 
439
- const slotNow = this.epochCache.getEpochAndSlotNow().slot;
439
+ const slotNow = this.epochCache.getSlotNow();
440
440
  fromSlot ??= SlotNumber(Math.max((this.lastProcessedSlot ?? slotNow) - this.store.getHistoryLength(), 0));
441
441
  toSlot ??= this.lastProcessedSlot ?? slotNow;
442
442
 
@@ -464,7 +464,7 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
464
464
  return undefined;
465
465
  }
466
466
 
467
- const slotNow = this.epochCache.getEpochAndSlotNow().slot;
467
+ const slotNow = this.epochCache.getSlotNow();
468
468
  const effectiveFromSlot =
469
469
  fromSlot ?? SlotNumber(Math.max((this.lastProcessedSlot ?? slotNow) - this.store.getHistoryLength(), 0));
470
470
  const effectiveToSlot = toSlot ?? this.lastProcessedSlot ?? slotNow;