@aztec/aztec-node 0.0.1-commit.5de5ca79e → 0.0.1-commit.6201a7b05

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.
@@ -3,6 +3,7 @@ import { createLogger } from '@aztec/foundation/log';
3
3
  import { createStore } from '@aztec/kv-store/lmdb-v2';
4
4
  import type { P2PClient } from '@aztec/p2p';
5
5
  import type { L2BlockSource } from '@aztec/stdlib/block';
6
+ import type { ChainConfig } from '@aztec/stdlib/config';
6
7
  import type { SlasherConfig } from '@aztec/stdlib/interfaces/server';
7
8
  import type { DataStoreConfig } from '@aztec/stdlib/kv-store';
8
9
 
@@ -14,7 +15,7 @@ export async function createSentinel(
14
15
  epochCache: EpochCache,
15
16
  archiver: L2BlockSource,
16
17
  p2p: P2PClient,
17
- config: SentinelConfig & DataStoreConfig & SlasherConfig,
18
+ config: SentinelConfig & DataStoreConfig & SlasherConfig & Pick<ChainConfig, 'l1ChainId' | 'l1Contracts'>,
18
19
  logger = createLogger('node:sentinel'),
19
20
  ): Promise<Sentinel | undefined> {
20
21
  if (!config.sentinelEnabled) {
@@ -21,7 +21,9 @@ import {
21
21
  type L2BlockStreamEventHandler,
22
22
  getAttestationInfoFromPublishedCheckpoint,
23
23
  } from '@aztec/stdlib/block';
24
+ import type { ChainConfig } from '@aztec/stdlib/config';
24
25
  import { getEpochAtSlot, getSlotRangeForEpoch, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
26
+ import type { CoordinationSignatureContext } from '@aztec/stdlib/p2p';
25
27
  import type {
26
28
  SingleValidatorStats,
27
29
  ValidatorStats,
@@ -36,6 +38,12 @@ import EventEmitter from 'node:events';
36
38
 
37
39
  import { SentinelStore } from './store.js';
38
40
 
41
+ export type SentinelRuntimeConfig = Pick<
42
+ SlasherConfig,
43
+ 'slashInactivityTargetPercentage' | 'slashInactivityPenalty' | 'slashInactivityConsecutiveEpochThreshold'
44
+ > &
45
+ Pick<ChainConfig, 'l1ChainId' | 'l1Contracts'>;
46
+
39
47
  /** Maps a validator status to its category: proposer or attestation. */
40
48
  function statusToCategory(status: ValidatorStatusInSlot): ValidatorStatusType {
41
49
  switch (status) {
@@ -65,10 +73,7 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
65
73
  protected archiver: L2BlockSource,
66
74
  protected p2p: P2PClient,
67
75
  protected store: SentinelStore,
68
- protected config: Pick<
69
- SlasherConfig,
70
- 'slashInactivityTargetPercentage' | 'slashInactivityPenalty' | 'slashInactivityConsecutiveEpochThreshold'
71
- >,
76
+ protected config: SentinelRuntimeConfig,
72
77
  protected logger = createLogger('node:sentinel'),
73
78
  ) {
74
79
  super();
@@ -77,6 +82,13 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
77
82
  this.runningPromise = new RunningPromise(this.work.bind(this), logger, interval);
78
83
  }
79
84
 
85
+ private getSignatureContext(): CoordinationSignatureContext {
86
+ return {
87
+ chainId: this.config.l1ChainId,
88
+ rollupAddress: this.config.l1Contracts.rollupAddress,
89
+ };
90
+ }
91
+
80
92
  public updateConfig(config: Partial<SlasherConfig>) {
81
93
  this.config = { ...this.config, ...config };
82
94
  }
@@ -117,7 +129,7 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
117
129
  this.slotNumberToCheckpoint.set(checkpoint.checkpoint.header.slotNumber, {
118
130
  checkpointNumber: checkpoint.checkpoint.number,
119
131
  archive: checkpoint.checkpoint.archive.root.toString(),
120
- attestors: getAttestationInfoFromPublishedCheckpoint(checkpoint)
132
+ attestors: getAttestationInfoFromPublishedCheckpoint(checkpoint, this.getSignatureContext())
121
133
  .filter(a => a.status === 'recovered-from-signature')
122
134
  .map(a => a.address!),
123
135
  });
@@ -219,7 +231,7 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
219
231
  // Check that we have at least requiredConsecutiveEpochs and that all of them are above the inactivity threshold
220
232
  return pastEpochs
221
233
  .slice(0, requiredConsecutiveEpochs)
222
- .every(p => p.missed / p.total >= this.config.slashInactivityTargetPercentage);
234
+ .every(p => (p.total === 0 ? false : p.missed / p.total >= this.config.slashInactivityTargetPercentage));
223
235
  }
224
236
 
225
237
  protected async handleProvenPerformance(epoch: EpochNumber, performance: ValidatorsEpochPerformance) {
@@ -228,7 +240,7 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
228
240
  }
229
241
 
230
242
  const inactiveValidators = getEntries(performance)
231
- .filter(([_, { missed, total }]) => missed / total >= this.config.slashInactivityTargetPercentage)
243
+ .filter(([_, { missed, total }]) => total > 0 && missed / total >= this.config.slashInactivityTargetPercentage)
232
244
  .map(([address]) => address);
233
245
 
234
246
  this.logger.debug(`Found ${inactiveValidators.length} inactive validators in epoch ${epoch}`, {