@aztec/aztec-node 0.0.1-commit.f2ce05ee → 0.0.1-commit.f504929

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.
@@ -36,6 +36,17 @@ import EventEmitter from 'node:events';
36
36
 
37
37
  import { SentinelStore } from './store.js';
38
38
 
39
+ /** Maps a validator status to its category: proposer or attestation. */
40
+ function statusToCategory(status: ValidatorStatusInSlot): ValidatorStatusType {
41
+ switch (status) {
42
+ case 'attestation-sent':
43
+ case 'attestation-missed':
44
+ return 'attestation';
45
+ default:
46
+ return 'proposer';
47
+ }
48
+ }
49
+
39
50
  export class Sentinel extends (EventEmitter as new () => WatcherEmitter) implements L2BlockStreamEventHandler, Watcher {
40
51
  protected runningPromise: RunningPromise;
41
52
  protected blockStream!: L2BlockStream;
@@ -128,15 +139,15 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
128
139
  return;
129
140
  }
130
141
  const blockNumber = event.block.number;
131
- const block = await this.archiver.getL2Block(blockNumber);
132
- if (!block) {
133
- this.logger.error(`Failed to get block ${blockNumber}`, { block });
142
+ const header = await this.archiver.getBlockHeader(blockNumber);
143
+ if (!header) {
144
+ this.logger.error(`Failed to get block header ${blockNumber}`);
134
145
  return;
135
146
  }
136
147
 
137
148
  // TODO(palla/slash): We should only be computing proven performance if this is
138
149
  // a full proof epoch and not a partial one, otherwise we'll end up with skewed stats.
139
- const epoch = getEpochAtSlot(block.header.getSlot(), this.epochCache.getL1Constants());
150
+ const epoch = getEpochAtSlot(header.getSlot(), this.epochCache.getL1Constants());
140
151
  this.logger.debug(`Computing proven performance for epoch ${epoch}`);
141
152
  const performance = await this.computeProvenPerformance(epoch);
142
153
  this.logger.info(`Computed proven performance for epoch ${epoch}`, performance);
@@ -147,7 +158,11 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
147
158
 
148
159
  protected async computeProvenPerformance(epoch: EpochNumber): Promise<ValidatorsEpochPerformance> {
149
160
  const [fromSlot, toSlot] = getSlotRangeForEpoch(epoch, this.epochCache.getL1Constants());
150
- const { committee } = await this.epochCache.getCommittee(fromSlot);
161
+ const { committee, isEscapeHatchOpen } = await this.epochCache.getCommittee(fromSlot);
162
+ if (isEscapeHatchOpen) {
163
+ this.logger.info(`Skipping proven performance for epoch ${epoch} - escape hatch is open`);
164
+ return {};
165
+ }
151
166
  if (!committee) {
152
167
  this.logger.trace(`No committee found for slot ${fromSlot}`);
153
168
  return {};
@@ -316,7 +331,12 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
316
331
  * and updates overall stats.
317
332
  */
318
333
  protected async processSlot(slot: SlotNumber) {
319
- const { epoch, seed, committee } = await this.epochCache.getCommittee(slot);
334
+ const { epoch, seed, committee, isEscapeHatchOpen } = await this.epochCache.getCommittee(slot);
335
+ if (isEscapeHatchOpen) {
336
+ this.logger.info(`Skipping slot ${slot} at epoch ${epoch} - escape hatch is open`);
337
+ this.lastProcessedSlot = slot;
338
+ return;
339
+ }
320
340
  if (!committee || committee.length === 0) {
321
341
  this.logger.trace(`No committee found for slot ${slot} at epoch ${epoch}`);
322
342
  this.lastProcessedSlot = slot;
@@ -336,16 +356,16 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
336
356
 
337
357
  // Check if there is an L2 block in L1 for this L2 slot
338
358
 
339
- // Here we get all attestations for the block mined at the given slot,
340
- // or all attestations for all proposals in the slot if no block was mined.
359
+ // Here we get all checkpoint attestations for the checkpoint at the given slot,
360
+ // or all checkpoint attestations for all proposals in the slot if no checkpoint was mined.
341
361
  // We gather from both p2p (contains the ones seen on the p2p layer) and archiver
342
- // (contains the ones synced from mined blocks, which we may have missed from p2p).
343
- const block = this.slotNumberToCheckpoint.get(slot);
344
- const p2pAttested = await this.p2p.getCheckpointAttestationsForSlot(slot, block?.archive);
362
+ // (contains the ones synced from mined checkpoints, which we may have missed from p2p).
363
+ const checkpoint = this.slotNumberToCheckpoint.get(slot);
364
+ const p2pAttested = await this.p2p.getCheckpointAttestationsForSlot(slot, checkpoint?.archive);
345
365
  // Filter out attestations with invalid signatures
346
366
  const p2pAttestors = p2pAttested.map(a => a.getSender()).filter((s): s is EthAddress => s !== undefined);
347
367
  const attestors = new Set(
348
- [...p2pAttestors.map(a => a.toString()), ...(block?.attestors.map(a => a.toString()) ?? [])].filter(
368
+ [...p2pAttestors.map(a => a.toString()), ...(checkpoint?.attestors.map(a => a.toString()) ?? [])].filter(
349
369
  addr => proposer.toString() !== addr, // Exclude the proposer from the attestors
350
370
  ),
351
371
  );
@@ -356,20 +376,29 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
356
376
  // But we'll leave that corner case out to reduce pressure on the node.
357
377
  // TODO(palla/slash): This breaks if a given node has more than one validator in the current committee,
358
378
  // since they will attest to their own proposal it even if it's not re-executable.
359
- const blockStatus = block ? 'mined' : attestors.size > 0 ? 'proposed' : 'missed';
360
- this.logger.debug(`Block for slot ${slot} was ${blockStatus}`, { ...block, slot });
379
+ let status: 'checkpoint-mined' | 'checkpoint-proposed' | 'checkpoint-missed' | 'blocks-missed';
380
+ if (checkpoint) {
381
+ status = 'checkpoint-mined';
382
+ } else if (attestors.size > 0) {
383
+ status = 'checkpoint-proposed';
384
+ } else {
385
+ // No checkpoint on L1 and no checkpoint attestations seen. Check if block proposals were sent for this slot.
386
+ const hasBlockProposals = await this.p2p.hasBlockProposalsForSlot(slot);
387
+ status = hasBlockProposals ? 'checkpoint-missed' : 'blocks-missed';
388
+ }
389
+ this.logger.debug(`Checkpoint status for slot ${slot}: ${status}`, { ...checkpoint, slot });
361
390
 
362
- // Get attestors that failed their duties for this block, but only if there was a block proposed
391
+ // Get attestors that failed their checkpoint attestation duties, but only if there was a checkpoint proposed or mined
363
392
  const missedAttestors = new Set(
364
- blockStatus === 'missed'
393
+ status === 'blocks-missed' || status === 'checkpoint-missed'
365
394
  ? []
366
395
  : committee.filter(v => !attestors.has(v.toString()) && !proposer.equals(v)).map(v => v.toString()),
367
396
  );
368
397
 
369
398
  this.logger.debug(`Retrieved ${attestors.size} attestors out of ${committee.length} for slot ${slot}`, {
370
- blockStatus,
399
+ status,
371
400
  proposer: proposer.toString(),
372
- ...block,
401
+ ...checkpoint,
373
402
  slot,
374
403
  attestors: [...attestors],
375
404
  missedAttestors: [...missedAttestors],
@@ -379,7 +408,7 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
379
408
  // Compute the status for each validator in the committee
380
409
  const statusFor = (who: `0x${string}`): ValidatorStatusInSlot | undefined => {
381
410
  if (who === proposer.toString()) {
382
- return `block-${blockStatus}`;
411
+ return status;
383
412
  } else if (attestors.has(who)) {
384
413
  return 'attestation-sent';
385
414
  } else if (missedAttestors.has(who)) {
@@ -472,14 +501,16 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
472
501
  ): ValidatorStats {
473
502
  let history = fromSlot ? allHistory.filter(h => BigInt(h.slot) >= fromSlot) : allHistory;
474
503
  history = toSlot ? history.filter(h => BigInt(h.slot) <= toSlot) : history;
475
- const lastProposal = history.filter(h => h.status === 'block-proposed' || h.status === 'block-mined').at(-1);
504
+ const lastProposal = history
505
+ .filter(h => h.status === 'checkpoint-proposed' || h.status === 'checkpoint-mined')
506
+ .at(-1);
476
507
  const lastAttestation = history.filter(h => h.status === 'attestation-sent').at(-1);
477
508
  return {
478
509
  address: EthAddress.fromString(address),
479
510
  lastProposal: this.computeFromSlot(lastProposal?.slot),
480
511
  lastAttestation: this.computeFromSlot(lastAttestation?.slot),
481
512
  totalSlots: history.length,
482
- missedProposals: this.computeMissed(history, 'block', ['block-missed']),
513
+ missedProposals: this.computeMissed(history, 'proposer', ['checkpoint-missed', 'blocks-missed']),
483
514
  missedAttestations: this.computeMissed(history, 'attestation', ['attestation-missed']),
484
515
  history,
485
516
  };
@@ -487,10 +518,12 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
487
518
 
488
519
  protected computeMissed(
489
520
  history: ValidatorStatusHistory,
490
- computeOverPrefix: ValidatorStatusType | undefined,
521
+ computeOverCategory: ValidatorStatusType | undefined,
491
522
  filter: ValidatorStatusInSlot[],
492
523
  ) {
493
- const relevantHistory = history.filter(h => !computeOverPrefix || h.status.startsWith(computeOverPrefix));
524
+ const relevantHistory = history.filter(
525
+ h => !computeOverCategory || statusToCategory(h.status) === computeOverCategory,
526
+ );
494
527
  const filteredHistory = relevantHistory.filter(h => filter.includes(h.status));
495
528
  return {
496
529
  currentStreak: countWhile([...relevantHistory].reverse(), h => filter.includes(h.status)),
@@ -9,7 +9,7 @@ import type {
9
9
  } from '@aztec/stdlib/validators';
10
10
 
11
11
  export class SentinelStore {
12
- public static readonly SCHEMA_VERSION = 2;
12
+ public static readonly SCHEMA_VERSION = 3;
13
13
 
14
14
  // a map from validator address to their ValidatorStatusHistory
15
15
  private readonly historyMap: AztecAsyncMap<`0x${string}`, Buffer>;
@@ -86,11 +86,7 @@ export class SentinelStore {
86
86
  });
87
87
  }
88
88
 
89
- private async pushValidatorStatusForSlot(
90
- who: EthAddress,
91
- slot: SlotNumber,
92
- status: 'block-mined' | 'block-proposed' | 'block-missed' | 'attestation-sent' | 'attestation-missed',
93
- ) {
89
+ private async pushValidatorStatusForSlot(who: EthAddress, slot: SlotNumber, status: ValidatorStatusInSlot) {
94
90
  await this.store.transactionAsync(async () => {
95
91
  const currentHistory = (await this.getHistory(who)) ?? [];
96
92
  const newHistory = [...currentHistory, { slot, status }].slice(-this.config.historyLength);
@@ -149,16 +145,18 @@ export class SentinelStore {
149
145
 
150
146
  private statusToNumber(status: ValidatorStatusInSlot): number {
151
147
  switch (status) {
152
- case 'block-mined':
148
+ case 'checkpoint-mined':
153
149
  return 1;
154
- case 'block-proposed':
150
+ case 'checkpoint-proposed':
155
151
  return 2;
156
- case 'block-missed':
152
+ case 'checkpoint-missed':
157
153
  return 3;
158
154
  case 'attestation-sent':
159
155
  return 4;
160
156
  case 'attestation-missed':
161
157
  return 5;
158
+ case 'blocks-missed':
159
+ return 6;
162
160
  default: {
163
161
  const _exhaustive: never = status;
164
162
  throw new Error(`Unknown status: ${status}`);
@@ -169,15 +167,17 @@ export class SentinelStore {
169
167
  private statusFromNumber(status: number): ValidatorStatusInSlot {
170
168
  switch (status) {
171
169
  case 1:
172
- return 'block-mined';
170
+ return 'checkpoint-mined';
173
171
  case 2:
174
- return 'block-proposed';
172
+ return 'checkpoint-proposed';
175
173
  case 3:
176
- return 'block-missed';
174
+ return 'checkpoint-missed';
177
175
  case 4:
178
176
  return 'attestation-sent';
179
177
  case 5:
180
178
  return 'attestation-missed';
179
+ case 6:
180
+ return 'blocks-missed';
181
181
  default:
182
182
  throw new Error(`Unknown status: ${status}`);
183
183
  }