@aztec-labs/aztec-node 6.0.0 → 6.1.0-nightly.20261024

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.
@@ -45,23 +45,39 @@ The aggregator catches up if multiple epochs become eligible at once (e.g. after
45
45
 
46
46
  ## Six-case taxonomy
47
47
 
48
- For each slot, the proposer is assigned one of six statuses, ranked highest-confidence first:
48
+ For each slot, the proposer is assigned one of six statuses, ranked highest-confidence first. Case 5 is refined into 5a and 5b when the evidence allows it:
49
49
 
50
50
  | # | Status | Trigger | Inactive party |
51
51
  |---|---|---|---|
52
52
  | 6 | `checkpoint-mined` | `archiver.getCheckpoint({ slot })` returns a checkpoint (one covering this slot has landed on L1) | Attestors who didn't attest |
53
- | 5 | `checkpoint-valid` | `tracker.getOutcomeForSlot(slot) === 'valid'` | Attestors who didn't attest |
53
+ | 5a | `checkpoint-unpublished` | Case 5, and the proposal's parent is on L1 and a quorum of the committee attested | Attestors who didn't attest (proposer fault recorded, not yet penalized) |
54
+ | 5b | `checkpoint-orphaned` | Case 5, and the parent the proposal built on never landed on L1 (missing or different archive root), or an earlier slot landed the proposal's checkpoint number after a quorum attested it | Attestors who didn't attest, unless a different checkpoint landed in the parent's position or an earlier slot took the checkpoint number |
55
+ | 5 | `checkpoint-valid` | `tracker.getOutcomeForSlot(slot) === 'valid'`, not refined into 5a or 5b | Attestors who didn't attest |
54
56
  | 4 | `checkpoint-invalid` | `tracker.getOutcomeForSlot(slot) === 'invalid'` (re-executed and rejected) | Proposer |
55
57
  | 3 | `checkpoint-unvalidated` | `tracker.getOutcomeForSlot(slot) === 'unvalidated'` (validation aborted: missing data, timeout, etc.) | Proposer |
56
58
  | 2 | `checkpoint-missed` | `p2p.hasBlockProposalsForSlot(slot)` true (blocks seen but no checkpoint proposal observed) | Proposer |
57
59
  | 1 | `blocks-missed` | None of the above (no block proposals observed) | Proposer |
58
60
 
59
- Missing-attestor faults are only recorded in cases 5 and 6 — where the local node has positive evidence the checkpoint was valid or canonical. In cases 1–4 the proposer is at fault and no attestor penalty applies.
61
+ Missing-attestor faults are only recorded in cases 5 (including 5a and 5b) and 6 — where the local node has positive evidence the checkpoint was valid or canonical. In cases 1–4 the proposer is at fault and no attestor penalty applies. Nor does one apply when a different checkpoint landed in the parent's position or an earlier slot landed the proposal's checkpoint number: a validator that already held the landed checkpoint's blocks rejects the proposal (or the parent it builds on) as conflicting, and is right to.
62
+
63
+ ### Refining case 5: unpublished and orphaned proposals
64
+
65
+ Under proposer pipelining, the proposer for slot N+1 builds on slot N's gossiped proposal. If slot N never lands, slot N+1 cannot land either, through no fault of its own. Cases 5a and 5b separate that cascade from a proposer that simply failed to publish. When a slot has a valid re-execution outcome but no checkpoint on L1, the sentinel reads the tracker's record for the slot (`getRecordForSlot`) and checks, in order:
66
+
67
+ 1. If the slot had a proposal equivocation, or the record has no checkpoint number, parent archive root or payload hash, the status stays `checkpoint-valid`.
68
+ 2. If the parent checkpoint (`checkpointNumber - 1`) is not on L1, or its archive root differs from the proposal's `lastArchiveRoot`, the status is `checkpoint-orphaned`. The first checkpoint builds on genesis, which always counts as on L1. When a different checkpoint holds the parent's position (`parent-hash-mismatch`), no attestor is tagged `attestation-missed`: a validator that held that checkpoint's blocks rightly rejects the proposal's parent as conflicting.
69
+ 3. If a checkpoint from an earlier slot landed on L1 with the proposal's checkpoint number (`unexpected-parent-appeared`, the reason the sequencer gives when it discards its own pipelined checkpoint for this cause), the earlier slot's proposal reached the proposer too late to build on, and once it landed this proposal could not. With a quorum of attestations the status is `checkpoint-orphaned`. Below quorum it stays `checkpoint-valid`, and no attestor is tagged `attestation-missed`. Both are logged at `verbose` with the reason and the slot that took the number.
70
+ 4. If fewer than `computeQuorum(committee.length)` distinct committee members attested the proposal's payload on P2P (the proposer's own attestation counts, as it does for the sequencer; attestations for another payload in the slot do not, since the proposer could not publish them), the status stays `checkpoint-valid`: the proposer could not publish, and the attestors are at fault.
71
+ 5. Otherwise the status is `checkpoint-unpublished`, logged at `info` with the attestation count and quorum.
72
+
73
+ A checkpoint from a later slot that holds the proposal's checkpoint number does not exempt the proposer: that slot only got the number because this proposer failed to land it.
74
+
75
+ Neither `checkpoint-unpublished` nor `checkpoint-orphaned` counts toward `missedProposals` or inactivity slashing yet. Like `checkpoint-valid`, both only add to the proposer's slot total.
60
76
 
61
77
  Each non-proposer committee member is tagged:
62
78
 
63
79
  - `attestation-sent` — attestation seen on P2P (with valid signature) or in the L1 checkpoint's attestor set
64
- - `attestation-missed` — only when proposer status is case 5 or 6 and the validator's attestation was not seen
80
+ - `attestation-missed` — only when proposer status is case 5 (including 5a and 5b) or 6 and the validator's attestation was not seen, unless a different checkpoint landed in the parent's position or an earlier slot landed the proposal's checkpoint number
65
81
  - none — otherwise
66
82
 
67
83
  ## Inactivity slashing
@@ -1,3 +1,4 @@
1
+ import { INITIAL_CHECKPOINT_NUMBER } from '@aztec-labs/constants';
1
2
  import { type EpochCache, requireStableCommittee } from '@aztec-labs/epoch-cache';
2
3
  import {
3
4
  CheckpointNumber,
@@ -22,8 +23,17 @@ import type { SlasherConfig } from '@aztec-labs/slasher/config';
22
23
  import { type L2BlockSource, getAttestationInfoFromPublishedCheckpoint } from '@aztec-labs/stdlib/block';
23
24
  import type { CheckpointReexecutionTracker } from '@aztec-labs/stdlib/checkpoint';
24
25
  import type { ChainConfig } from '@aztec-labs/stdlib/config';
25
- import { getEpochAtSlot, getSlotRangeForEpoch, getTimestampForSlot } from '@aztec-labs/stdlib/epoch-helpers';
26
- import { ConsensusPayload, type CoordinationSignatureContext } from '@aztec-labs/stdlib/p2p';
26
+ import {
27
+ computeQuorum,
28
+ getEpochAtSlot,
29
+ getSlotRangeForEpoch,
30
+ getTimestampForSlot,
31
+ } from '@aztec-labs/stdlib/epoch-helpers';
32
+ import {
33
+ type CheckpointAttestation,
34
+ ConsensusPayload,
35
+ type CoordinationSignatureContext,
36
+ } from '@aztec-labs/stdlib/p2p';
27
37
  import type {
28
38
  SingleValidatorStats,
29
39
  ValidatorStats,
@@ -45,6 +55,42 @@ export type SentinelRuntimeConfig = Pick<
45
55
  Pick<SentinelConfig, 'sentinelEpochEndBufferSlots'> &
46
56
  Pick<ChainConfig, 'l1ChainId' | 'rollupAddress'>;
47
57
 
58
+ /**
59
+ * Why a valid checkpoint proposal that never reached L1 could not have landed, regardless of its proposer.
60
+ * `unexpected-parent-appeared` matches the reason the sequencer gives when it discards its own pipelined checkpoint
61
+ * for the same cause.
62
+ */
63
+ type OrphanedProposalReason = 'parent-not-on-l1' | 'parent-hash-mismatch' | 'unexpected-parent-appeared';
64
+
65
+ const ORPHANED_PROPOSAL_REASON_DESCRIPTIONS: Record<OrphanedProposalReason, string> = {
66
+ 'parent-not-on-l1': 'the parent checkpoint it built on never landed on L1',
67
+ 'parent-hash-mismatch': 'a different checkpoint landed on L1 in place of the parent it built on',
68
+ 'unexpected-parent-appeared':
69
+ 'a checkpoint from an earlier slot landed on L1 with its checkpoint number after it was built on the previous one',
70
+ };
71
+
72
+ /** Refined status of a valid checkpoint proposal for a slot whose checkpoint never reached L1. */
73
+ type UnpublishedProposalClassification =
74
+ | { status: 'checkpoint-unpublished' }
75
+ | { status: 'checkpoint-orphaned'; reason: OrphanedProposalReason }
76
+ | {
77
+ status: 'checkpoint-valid';
78
+ reason: 'equivocation' | 'no-proposal-data' | 'below-quorum' | 'unexpected-parent-appeared';
79
+ };
80
+
81
+ /**
82
+ * Whether the classification shows the proposal conflicts with a checkpoint that landed on L1, either in its parent's
83
+ * position or in its own. A validator that already held the landed checkpoint's blocks rejects the proposal's blocks as
84
+ * conflicting, so it is right not to attest.
85
+ */
86
+ function excusesMissingAttestations(classification: UnpublishedProposalClassification | undefined): boolean {
87
+ return (
88
+ classification !== undefined &&
89
+ 'reason' in classification &&
90
+ (classification.reason === 'parent-hash-mismatch' || classification.reason === 'unexpected-parent-appeared')
91
+ );
92
+ }
93
+
48
94
  /** Maps a validator status to its category: proposer or attestation. */
49
95
  function statusToCategory(status: ValidatorStatusInSlot): ValidatorStatusType {
50
96
  switch (status) {
@@ -85,12 +131,19 @@ function statusToCategory(status: ValidatorStatusInSlot): ValidatorStatusType {
85
131
  * ## Six-case taxonomy in `getSlotActivity`
86
132
  *
87
133
  * For each slot, the sentinel assigns the proposer one of six statuses, ranked highest-confidence
88
- * first:
134
+ * first, with case 5 refined into 5a and 5b:
89
135
  *
90
136
  * - `checkpoint-mined` — a checkpoint covering this slot has landed on L1
91
137
  * (fetched on demand via `archiver.getCheckpoint({ slot })`).
138
+ * - `checkpoint-unpublished` — (5a) a valid checkpoint proposal built on a parent that is on L1
139
+ * reached quorum, yet the proposer did not land it.
140
+ * - `checkpoint-orphaned` — (5b) a valid checkpoint proposal could not land because the parent
141
+ * it built on never reached L1 (the proposer pipelining cascade), or
142
+ * because an earlier slot's checkpoint landed with its number after it
143
+ * had built on the previous one.
92
144
  * - `checkpoint-valid` — the local node re-executed a checkpoint proposal for this slot
93
- * successfully (consulted via `CheckpointReexecutionTracker`).
145
+ * successfully (consulted via `CheckpointReexecutionTracker`), and it
146
+ * could not be refined into 5a or 5b.
94
147
  * - `checkpoint-invalid` — the local node re-executed a checkpoint proposal for this slot
95
148
  * and rejected it (e.g. header/archive/out-hash mismatch, limit
96
149
  * breach). Proposer-fault.
@@ -100,9 +153,15 @@ function statusToCategory(status: ValidatorStatusInSlot): ValidatorStatusType {
100
153
  * - `checkpoint-missed` — block proposals seen on P2P but no checkpoint proposal at all.
101
154
  * - `blocks-missed` — no block proposals seen for this slot.
102
155
  *
103
- * Missing-attestor faults are recorded only in `checkpoint-mined` and `checkpoint-valid`, where
104
- * the local node has positive evidence the checkpoint was canonical or valid. In the other four
105
- * cases the proposer is at fault and no attestor penalty applies.
156
+ * Missing-attestor faults are recorded only in `checkpoint-mined` and the three valid-proposal
157
+ * statuses (`checkpoint-unpublished`, `checkpoint-orphaned`, `checkpoint-valid`), where the local
158
+ * node has positive evidence the checkpoint was canonical or valid. In the other four cases the
159
+ * proposer is at fault and no attestor penalty applies. A valid proposal that conflicts with a checkpoint
160
+ * that landed on L1, in its parent's position or its own, is also exempt: a validator holding the landed
161
+ * checkpoint's blocks rightly refuses it.
162
+ *
163
+ * `checkpoint-unpublished` and `checkpoint-orphaned` are neutral for the proposer, like
164
+ * `checkpoint-valid`: neither counts toward `missedProposals` or inactivity slashing.
106
165
  *
107
166
  * ## Re-execution tracker
108
167
  *
@@ -135,6 +194,21 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
135
194
  /** Largest epoch number for which the end-of-epoch aggregator has run. */
136
195
  protected lastEvaluatedEpoch: EpochNumber | undefined;
137
196
 
197
+ /** Bumped on every history write so cached stats are never served from before the write. */
198
+ private historyGeneration = 0;
199
+ /**
200
+ * Stats for the default window, shared by every caller until the next processed slot or history write. Computing them
201
+ * scans and deserializes the full history of every validator, while the inputs only change once per slot.
202
+ */
203
+ private defaultStatsCache:
204
+ | {
205
+ lastProcessedSlot: SlotNumber;
206
+ initialSlot: SlotNumber | undefined;
207
+ historyGeneration: number;
208
+ stats: Promise<ValidatorsStats>;
209
+ }
210
+ | undefined;
211
+
138
212
  constructor(
139
213
  protected epochCache: EpochCache,
140
214
  protected archiver: L2BlockSource,
@@ -490,8 +564,12 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
490
564
  *
491
565
  * Proposer status:
492
566
  * - case 6 `checkpoint-mined` — a checkpoint covering this slot has landed on L1.
567
+ * - case 5a `checkpoint-unpublished` — a valid proposal with its parent on L1 reached quorum but
568
+ * was not landed by the proposer.
569
+ * - case 5b `checkpoint-orphaned` — a valid proposal could not land because its parent never
570
+ * reached L1, or because an earlier slot took its checkpoint number.
493
571
  * - case 5 `checkpoint-valid` — the local node re-executed a checkpoint proposal for this
494
- * slot successfully.
572
+ * slot successfully, and it could not be refined into 5a or 5b.
495
573
  * - case 4 `checkpoint-invalid` — the local node re-executed a checkpoint proposal for this
496
574
  * slot and rejected it.
497
575
  * - case 3 `checkpoint-unvalidated` — the local node observed a checkpoint proposal for this
@@ -499,8 +577,9 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
499
577
  * - case 2 `checkpoint-missed` — block proposals seen on P2P but no checkpoint proposal.
500
578
  * - case 1 `blocks-missed` — no block proposals seen for this slot.
501
579
  *
502
- * Missing-attestor penalties apply only in cases 5 and 6, where the local node has positive
503
- * evidence the checkpoint was valid or has been canonicalised on L1.
580
+ * Missing-attestor penalties apply only in cases 5 (including 5a and 5b) and 6, where the local
581
+ * node has positive evidence the checkpoint was valid or has been canonicalised on L1, and never when
582
+ * the proposal conflicts with a checkpoint that landed in its parent's position or its own.
504
583
  */
505
584
  protected async getSlotActivity(slot: SlotNumber, epoch: EpochNumber, proposer: EthAddress, committee: EthAddress[]) {
506
585
  this.logger.debug(`Computing stats for slot ${slot} at epoch ${epoch}`, { slot, epoch, proposer, committee });
@@ -517,19 +596,24 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
517
596
  ),
518
597
  );
519
598
 
520
- // Determine the proposer status from the six-case taxonomy.
599
+ // Determine the proposer status from the six-case taxonomy. A valid proposal that never reached L1 (case 5) is
600
+ // refined into `checkpoint-unpublished` (5a) or `checkpoint-orphaned` (5b) when the evidence allows it.
521
601
  const reexecutionOutcome = this.reexecutionTracker.getOutcomeForSlot(slot);
522
602
  let status:
523
603
  | 'checkpoint-mined'
604
+ | 'checkpoint-unpublished'
605
+ | 'checkpoint-orphaned'
524
606
  | 'checkpoint-valid'
525
607
  | 'checkpoint-invalid'
526
608
  | 'checkpoint-unvalidated'
527
609
  | 'checkpoint-missed'
528
610
  | 'blocks-missed';
611
+ let classification: UnpublishedProposalClassification | undefined;
529
612
  if (checkpoint) {
530
613
  status = 'checkpoint-mined';
531
614
  } else if (reexecutionOutcome === 'valid') {
532
- status = 'checkpoint-valid';
615
+ classification = await this.classifyUnpublishedProposal(slot, proposer, committee, p2pAttested);
616
+ status = classification.status;
533
617
  } else if (reexecutionOutcome === 'invalid') {
534
618
  status = 'checkpoint-invalid';
535
619
  } else if (reexecutionOutcome === 'unvalidated') {
@@ -546,12 +630,17 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
546
630
  // A local `invalid` verdict vetoes them even for a mined checkpoint (an honest validator refuses
547
631
  // to sign what it re-executed as invalid), and so does a proposal equivocation in the slot: with
548
632
  // two conflicting proposals an honest attestor may have seen an invalid one and correctly
549
- // declined, so neither must count as a missed attestor (inactivity slashing).
633
+ // declined, so neither must count as a missed attestor (inactivity slashing). Nor does a proposal that conflicts
634
+ // with a checkpoint that landed on L1 (see excusesMissingAttestations).
550
635
  const hasEquivocation = this.reexecutionTracker.hasEquivocation(slot);
551
636
  const attestorsExpected =
552
- (status === 'checkpoint-mined' || status === 'checkpoint-valid') &&
637
+ (status === 'checkpoint-mined' ||
638
+ status === 'checkpoint-unpublished' ||
639
+ status === 'checkpoint-orphaned' ||
640
+ status === 'checkpoint-valid') &&
553
641
  reexecutionOutcome !== 'invalid' &&
554
- !hasEquivocation;
642
+ !hasEquivocation &&
643
+ !excusesMissingAttestations(classification);
555
644
  const missedAttestors = new Set(
556
645
  attestorsExpected
557
646
  ? committee.filter(v => !attestors.has(v.toString()) && !proposer.equals(v)).map(v => v.toString())
@@ -584,17 +673,156 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
584
673
  return Object.fromEntries(committee.map(v => v.toString()).map(who => [who, statusFor(who)]));
585
674
  }
586
675
 
676
+ /**
677
+ * Refines case 5 (a checkpoint proposal for the slot re-executed as valid, with no checkpoint for the slot on L1)
678
+ * into whose fault it was that the proposal did not land:
679
+ *
680
+ * - `checkpoint-orphaned` (5b) when other proposers prevented it: the parent it built on never landed on L1 (it is
681
+ * missing, or a different checkpoint holds the parent's position), or, with a quorum of attestations, an earlier
682
+ * slot's checkpoint landed with its number after it built on the previous one (`unexpected-parent-appeared`).
683
+ * The latter happens when the earlier slot's proposal reached this proposer too late to build on.
684
+ * - `checkpoint-unpublished` (5a) when its parent is on L1 and a quorum of the committee attested, so the proposer
685
+ * had everything it needed to publish. A later slot that lands the same checkpoint number does not exempt it:
686
+ * that slot only got the number because this proposer failed to land it.
687
+ * - `checkpoint-valid` (5) otherwise: the slot had an equivocation, the tracker has no parent or payload data to
688
+ * judge by, or attestations fell short of quorum. Short of quorum is a fault of the attestors, who are tagged
689
+ * `attestation-missed`, except after an unexpected parent appeared (`unexpected-parent-appeared`), when
690
+ * refusing to attest was correct.
691
+ *
692
+ * Only attestations for the proposal's own payload count toward quorum, since those are the only ones its proposer
693
+ * could have published.
694
+ */
695
+ protected async classifyUnpublishedProposal(
696
+ slot: SlotNumber,
697
+ proposer: EthAddress,
698
+ committee: EthAddress[],
699
+ p2pAttested: CheckpointAttestation[],
700
+ ): Promise<UnpublishedProposalClassification> {
701
+ if (this.reexecutionTracker.hasEquivocation(slot)) {
702
+ return { status: 'checkpoint-valid', reason: 'equivocation' };
703
+ }
704
+ const record = this.reexecutionTracker.getRecordForSlot(slot);
705
+ const checkpointNumber = record?.checkpointNumber;
706
+ const lastArchiveRoot = record?.lastArchiveRoot;
707
+ const payloadHash = record?.payloadHash;
708
+ if (checkpointNumber === undefined || lastArchiveRoot === undefined || payloadHash === undefined) {
709
+ return { status: 'checkpoint-valid', reason: 'no-proposal-data' };
710
+ }
711
+
712
+ const logData = { slot, proposer: proposer.toString(), checkpointNumber };
713
+ const orphaned = (
714
+ reason: OrphanedProposalReason,
715
+ extra: Record<string, unknown> = {},
716
+ ): UnpublishedProposalClassification => {
717
+ this.logger.verbose(
718
+ `Valid checkpoint proposal for slot ${slot} was orphaned (${reason}): ${ORPHANED_PROPOSAL_REASON_DESCRIPTIONS[reason]}`,
719
+ { ...logData, ...extra, reason },
720
+ );
721
+ return { status: 'checkpoint-orphaned', reason };
722
+ };
723
+
724
+ // The first checkpoint builds on genesis, which is always on L1.
725
+ const parentNumber = checkpointNumber - 1;
726
+ if (parentNumber >= INITIAL_CHECKPOINT_NUMBER) {
727
+ const parent = await this.archiver.getCheckpointData({ number: CheckpointNumber(parentNumber) });
728
+ if (!parent) {
729
+ return orphaned('parent-not-on-l1');
730
+ }
731
+ if (parent.archive.root.toString() !== lastArchiveRoot) {
732
+ return orphaned('parent-hash-mismatch');
733
+ }
734
+ }
735
+
736
+ // The proposer's own attestation counts, as it does when its sequencer collects attestations for L1.
737
+ const committeeMembers = new Set(committee.map(member => member.toString()));
738
+ const attestationCount = new Set(
739
+ p2pAttested
740
+ .filter(attestation => attestation.getPayloadHash() === payloadHash)
741
+ .map(attestation => attestation.getSender()?.toString())
742
+ .filter(attestor => attestor !== undefined && committeeMembers.has(attestor)),
743
+ ).size;
744
+ const quorum = computeQuorum(committee.length);
745
+
746
+ // A checkpoint landed for the slot itself would have made this case 6, so a holder of the same number comes from
747
+ // an earlier or a later slot. Only an earlier one can have stopped this proposal from landing.
748
+ const sameNumber = await this.archiver.getCheckpointData({ number: checkpointNumber });
749
+ const sameNumberSlot = sameNumber?.header.slotNumber;
750
+ if (sameNumberSlot !== undefined && sameNumberSlot < slot) {
751
+ const conflictData = { takenBySlot: sameNumberSlot, attestationCount, quorum };
752
+ if (attestationCount < quorum) {
753
+ this.logger.verbose(
754
+ `Valid checkpoint proposal for slot ${slot} fell short of quorum after checkpoint ${checkpointNumber} landed ` +
755
+ `from earlier slot ${sameNumberSlot} (unexpected-parent-appeared), so missing attestations are not counted`,
756
+ { ...logData, ...conflictData, reason: 'unexpected-parent-appeared' },
757
+ );
758
+ return { status: 'checkpoint-valid', reason: 'unexpected-parent-appeared' };
759
+ }
760
+ return orphaned('unexpected-parent-appeared', conflictData);
761
+ }
762
+
763
+ if (attestationCount < quorum) {
764
+ return { status: 'checkpoint-valid', reason: 'below-quorum' };
765
+ }
766
+
767
+ this.logger.info(`Proposer did not publish checkpoint ${checkpointNumber} for slot ${slot} despite quorum`, {
768
+ ...logData,
769
+ attestationCount,
770
+ quorum,
771
+ });
772
+ return { status: 'checkpoint-unpublished' };
773
+ }
774
+
587
775
  /** Push the status for each slot for each validator. */
588
- protected updateValidators(slot: SlotNumber, stats: Record<`0x${string}`, ValidatorStatusInSlot | undefined>) {
589
- return this.store.updateValidators(slot, stats);
776
+ protected async updateValidators(slot: SlotNumber, stats: Record<`0x${string}`, ValidatorStatusInSlot | undefined>) {
777
+ this.historyGeneration++;
778
+ try {
779
+ await this.store.updateValidators(slot, stats);
780
+ } finally {
781
+ this.historyGeneration++;
782
+ }
783
+ }
784
+
785
+ /**
786
+ * Computes stats to be returned based on stored data. Calls without arguments cover the default window ending at the
787
+ * last processed slot and are served from a cache that is refreshed whenever that slot or the stored history changes.
788
+ */
789
+ public computeStats(
790
+ args: { fromSlot?: SlotNumber; toSlot?: SlotNumber; validators?: EthAddress[] } = {},
791
+ ): Promise<ValidatorsStats> {
792
+ const isDefaultWindow = args.fromSlot === undefined && args.toSlot === undefined && args.validators === undefined;
793
+ // Before the first processed slot the default window ends at the wall-clock slot, which moves without any write.
794
+ if (!isDefaultWindow || this.lastProcessedSlot === undefined) {
795
+ return this.computeStatsUncached(args);
796
+ }
797
+
798
+ const { lastProcessedSlot, initialSlot, historyGeneration } = this;
799
+ if (
800
+ this.defaultStatsCache?.lastProcessedSlot !== lastProcessedSlot ||
801
+ this.defaultStatsCache.initialSlot !== initialSlot ||
802
+ this.defaultStatsCache.historyGeneration !== historyGeneration
803
+ ) {
804
+ const stats = this.computeStatsUncached(args);
805
+ const entry = { lastProcessedSlot, initialSlot, historyGeneration, stats };
806
+ this.defaultStatsCache = entry;
807
+ // A failed computation is dropped so the next caller retries instead of receiving the cached rejection.
808
+ stats.catch(() => {
809
+ if (this.defaultStatsCache === entry) {
810
+ this.defaultStatsCache = undefined;
811
+ }
812
+ });
813
+ }
814
+ return this.defaultStatsCache.stats;
590
815
  }
591
816
 
592
- /** Computes stats to be returned based on stored data. */
593
- public async computeStats({
817
+ private async computeStatsUncached({
594
818
  fromSlot,
595
819
  toSlot,
596
820
  validators,
597
- }: { fromSlot?: SlotNumber; toSlot?: SlotNumber; validators?: EthAddress[] } = {}): Promise<ValidatorsStats> {
821
+ }: {
822
+ fromSlot?: SlotNumber;
823
+ toSlot?: SlotNumber;
824
+ validators?: EthAddress[];
825
+ }): Promise<ValidatorsStats> {
598
826
  const histories = validators
599
827
  ? fromEntries(await Promise.all(validators.map(async v => [v.toString(), await this.store.getHistory(v)])))
600
828
  : await this.store.getHistories();
@@ -685,7 +913,15 @@ export class Sentinel extends (EventEmitter as new () => WatcherEmitter) impleme
685
913
  ): ValidatorStats {
686
914
  let history = fromSlot ? allHistory.filter(h => BigInt(h.slot) >= fromSlot) : allHistory;
687
915
  history = toSlot ? history.filter(h => BigInt(h.slot) <= toSlot) : history;
688
- const lastProposal = history.filter(h => h.status === 'checkpoint-valid' || h.status === 'checkpoint-mined').at(-1);
916
+ const lastProposal = history
917
+ .filter(
918
+ h =>
919
+ h.status === 'checkpoint-valid' ||
920
+ h.status === 'checkpoint-unpublished' ||
921
+ h.status === 'checkpoint-orphaned' ||
922
+ h.status === 'checkpoint-mined',
923
+ )
924
+ .at(-1);
689
925
  const lastAttestation = history.filter(h => h.status === 'attestation-sent').at(-1);
690
926
  return {
691
927
  address: EthAddress.fromString(address),
@@ -175,6 +175,10 @@ export class SentinelStore {
175
175
  return 7;
176
176
  case 'checkpoint-unvalidated':
177
177
  return 8;
178
+ case 'checkpoint-unpublished':
179
+ return 9;
180
+ case 'checkpoint-orphaned':
181
+ return 10;
178
182
  default: {
179
183
  const _exhaustive: never = status;
180
184
  throw new Error(`Unknown status: ${status}`);
@@ -200,6 +204,10 @@ export class SentinelStore {
200
204
  return 'checkpoint-invalid';
201
205
  case 8:
202
206
  return 'checkpoint-unvalidated';
207
+ case 9:
208
+ return 'checkpoint-unpublished';
209
+ case 10:
210
+ return 'checkpoint-orphaned';
203
211
  default:
204
212
  throw new Error(`Unknown status: ${status}`);
205
213
  }