@aztec-labs/sequencer-client 6.0.0-rc.3 → 6.0.0

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 (78) hide show
  1. package/README.md +1 -1
  2. package/dest/client/sequencer-client.d.ts +1 -1
  3. package/dest/client/sequencer-client.d.ts.map +1 -1
  4. package/dest/client/sequencer-client.js +7 -2
  5. package/dest/config.d.ts +2 -1
  6. package/dest/config.d.ts.map +1 -1
  7. package/dest/config.js +5 -0
  8. package/dest/index.d.ts +2 -2
  9. package/dest/index.d.ts.map +1 -1
  10. package/dest/index.js +1 -1
  11. package/dest/publisher/config.d.ts +7 -4
  12. package/dest/publisher/config.d.ts.map +1 -1
  13. package/dest/publisher/config.js +12 -10
  14. package/dest/publisher/gas_constants.d.ts +39 -0
  15. package/dest/publisher/gas_constants.d.ts.map +1 -0
  16. package/dest/publisher/gas_constants.js +42 -0
  17. package/dest/publisher/index.d.ts +2 -1
  18. package/dest/publisher/index.d.ts.map +1 -1
  19. package/dest/publisher/index.js +1 -0
  20. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts +1 -1
  21. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts.map +1 -1
  22. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.js +1 -0
  23. package/dest/publisher/publisher-manager-metrics.d.ts +19 -0
  24. package/dest/publisher/publisher-manager-metrics.d.ts.map +1 -0
  25. package/dest/publisher/publisher-manager-metrics.js +67 -0
  26. package/dest/publisher/sequencer-publisher-factory.d.ts +8 -4
  27. package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
  28. package/dest/publisher/sequencer-publisher-factory.js +16 -6
  29. package/dest/publisher/sequencer-publisher-metrics.d.ts +1 -3
  30. package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
  31. package/dest/publisher/sequencer-publisher-metrics.js +0 -8
  32. package/dest/publisher/sequencer-publisher.d.ts +17 -4
  33. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  34. package/dest/publisher/sequencer-publisher.js +168 -17
  35. package/dest/publisher/write_json.d.ts +1 -1
  36. package/dest/publisher/write_json.d.ts.map +1 -1
  37. package/dest/publisher/write_json.js +3 -1
  38. package/dest/sequencer/attestation_manipulation.d.ts +24 -0
  39. package/dest/sequencer/attestation_manipulation.d.ts.map +1 -0
  40. package/dest/sequencer/attestation_manipulation.js +72 -0
  41. package/dest/sequencer/automine/automine_factory.d.ts +1 -1
  42. package/dest/sequencer/automine/automine_factory.d.ts.map +1 -1
  43. package/dest/sequencer/automine/automine_factory.js +5 -1
  44. package/dest/sequencer/checkpoint_inbox_consumption.d.ts +135 -0
  45. package/dest/sequencer/checkpoint_inbox_consumption.d.ts.map +1 -0
  46. package/dest/sequencer/checkpoint_inbox_consumption.js +275 -0
  47. package/dest/sequencer/checkpoint_proposal_job.d.ts +27 -23
  48. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
  49. package/dest/sequencer/checkpoint_proposal_job.js +323 -527
  50. package/dest/sequencer/inbox_message_selection.d.ts +17 -16
  51. package/dest/sequencer/inbox_message_selection.d.ts.map +1 -1
  52. package/dest/sequencer/inbox_message_selection.js +20 -7
  53. package/dest/sequencer/metrics.d.ts +4 -4
  54. package/dest/sequencer/metrics.d.ts.map +1 -1
  55. package/dest/sequencer/metrics.js +6 -9
  56. package/dest/sequencer/sequencer.d.ts +9 -4
  57. package/dest/sequencer/sequencer.d.ts.map +1 -1
  58. package/dest/sequencer/sequencer.js +129 -38
  59. package/package.json +23 -23
  60. package/src/client/sequencer-client.ts +6 -1
  61. package/src/config.ts +7 -0
  62. package/src/index.ts +0 -3
  63. package/src/publisher/config.ts +20 -11
  64. package/src/publisher/gas_constants.ts +51 -0
  65. package/src/publisher/index.ts +1 -0
  66. package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +1 -0
  67. package/src/publisher/publisher-manager-metrics.ts +76 -0
  68. package/src/publisher/sequencer-publisher-factory.ts +18 -7
  69. package/src/publisher/sequencer-publisher-metrics.ts +0 -12
  70. package/src/publisher/sequencer-publisher.ts +201 -24
  71. package/src/publisher/write_json.ts +3 -1
  72. package/src/sequencer/attestation_manipulation.ts +123 -0
  73. package/src/sequencer/automine/automine_factory.ts +4 -0
  74. package/src/sequencer/checkpoint_inbox_consumption.ts +340 -0
  75. package/src/sequencer/checkpoint_proposal_job.ts +434 -632
  76. package/src/sequencer/inbox_message_selection.ts +45 -24
  77. package/src/sequencer/metrics.ts +7 -9
  78. package/src/sequencer/sequencer.ts +116 -27
@@ -0,0 +1,72 @@
1
+ import { randomInt } from '@aztec-labs/foundation/crypto/random';
2
+ import { flipSignature, generateRecoverableSignature, generateUnrecoverableSignature } from '@aztec-labs/foundation/crypto/secp256k1-signer';
3
+ import { unfreeze } from '@aztec-labs/foundation/types';
4
+ import { CommitteeAttestationsAndSigners, MaliciousCommitteeAttestationsAndSigners, MaliciousYParityCommitteeAttestationsAndSigners } from '@aztec-labs/stdlib/block';
5
+ /** Whether any test-only attestation attack is configured. */ export function hasAttestationManipulation(config) {
6
+ return !!(config.injectFakeAttestation || config.injectHighSValueAttestation || config.injectUnrecoverableSignatureAttestation || config.injectYParityAttestation || config.shuffleAttestationOrdering);
7
+ }
8
+ /** Breaks the attestations before publishing based on attack configs. */ export function manipulateAttestations(input) {
9
+ const { config, epochCache, signatureContext, log, slotNumber, epoch, seed, committee, attestations } = input;
10
+ // Compute the proposer index in the committee, since we dont want to tweak it.
11
+ // Otherwise, the L1 rollup contract will reject the block outright.
12
+ const proposerIndex = Number(epochCache.computeProposerIndex(slotNumber, epoch, seed, BigInt(committee.length)));
13
+ if (config.injectFakeAttestation || config.injectHighSValueAttestation || config.injectUnrecoverableSignatureAttestation) {
14
+ // Find non-empty attestations that are not from the proposer
15
+ const nonProposerIndices = [];
16
+ for(let i = 0; i < attestations.length; i++){
17
+ if (!attestations[i].signature.isEmpty() && i !== proposerIndex) {
18
+ nonProposerIndices.push(i);
19
+ }
20
+ }
21
+ if (nonProposerIndices.length > 0) {
22
+ const targetIndex = nonProposerIndices[randomInt(nonProposerIndices.length)];
23
+ if (config.injectHighSValueAttestation) {
24
+ log.warn(`Injecting high-s value attestation in checkpoint for slot ${slotNumber} at index ${targetIndex}`);
25
+ unfreeze(attestations[targetIndex]).signature = flipSignature(attestations[targetIndex].signature);
26
+ } else if (config.injectUnrecoverableSignatureAttestation) {
27
+ log.warn(`Injecting unrecoverable signature attestation in checkpoint for slot ${slotNumber} at index ${targetIndex}`);
28
+ unfreeze(attestations[targetIndex]).signature = generateUnrecoverableSignature();
29
+ } else {
30
+ log.warn(`Injecting fake attestation in checkpoint for slot ${slotNumber} at index ${targetIndex}`);
31
+ unfreeze(attestations[targetIndex]).signature = generateRecoverableSignature();
32
+ }
33
+ }
34
+ return new CommitteeAttestationsAndSigners(attestations, signatureContext);
35
+ }
36
+ if (config.injectYParityAttestation) {
37
+ // Force every non-proposer signed slot's recovery byte to yParity (v ∈ {0, 1}) form in the packed L1
38
+ // tuple, after packAttestations has canonicalized it. The proposer's own slot is left canonical so
39
+ // propose() still passes verifyProposer. Models a malicious proposer landing a checkpoint L1 accepts
40
+ // but that can never be proven (ECDSA.recover rejects v ∉ {27, 28}).
41
+ log.warn(`Injecting yParity attestations in checkpoint for slot ${slotNumber} (proposer #${proposerIndex})`);
42
+ return new MaliciousYParityCommitteeAttestationsAndSigners(attestations, proposerIndex, signatureContext);
43
+ }
44
+ if (config.shuffleAttestationOrdering) {
45
+ log.warn(`Shuffling attestation ordering in checkpoint for slot ${slotNumber} (proposer #${proposerIndex})`);
46
+ const shuffled = [
47
+ ...attestations
48
+ ];
49
+ // Find two non-proposer positions that both have non-empty signatures to swap.
50
+ // This ensures the bitmap doesn't change, so the MaliciousCommitteeAttestationsAndSigners
51
+ // signers array stays correctly aligned with L1's committee reconstruction.
52
+ const swappable = [];
53
+ for(let k = 0; k < shuffled.length; k++){
54
+ if (!shuffled[k].signature.isEmpty() && k !== proposerIndex) {
55
+ swappable.push(k);
56
+ }
57
+ }
58
+ if (swappable.length >= 2) {
59
+ const [i, j] = [
60
+ swappable[0],
61
+ swappable[1]
62
+ ];
63
+ [shuffled[i], shuffled[j]] = [
64
+ shuffled[j],
65
+ shuffled[i]
66
+ ];
67
+ }
68
+ const signers = new CommitteeAttestationsAndSigners(attestations, signatureContext).getSigners();
69
+ return new MaliciousCommitteeAttestationsAndSigners(shuffled, signers, signatureContext);
70
+ }
71
+ return new CommitteeAttestationsAndSigners(attestations, signatureContext);
72
+ }
@@ -53,4 +53,4 @@ export type CreateAutomineSequencerArgs = {
53
53
  * and starts the publisher manager before returning.
54
54
  */
55
55
  export declare function createAutomineSequencer({ config, l1TxUtils, funderL1TxUtils, publicClient, rollupContract, epochCache, blobClient, telemetry, dateProvider, keyStoreManager, validatorClient, checkpointsBuilder, globalVariableBuilder, worldStateSynchronizer, archiver, p2pClient, l1Constants, autoSettle, log }: CreateAutomineSequencerArgs): Promise<AutomineSequencer>;
56
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXV0b21pbmVfZmFjdG9yeS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL3NlcXVlbmNlci9hdXRvbWluZS9hdXRvbWluZV9mYWN0b3J5LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLFFBQVEsRUFBRSxNQUFNLHNCQUFzQixDQUFDO0FBQ3JELE9BQU8sS0FBSyxFQUFFLG1CQUFtQixFQUFFLE1BQU0sZ0NBQWdDLENBQUM7QUFDMUUsT0FBTyxLQUFLLEVBQUUsVUFBVSxFQUFFLE1BQU0seUJBQXlCLENBQUM7QUFDMUQsT0FBTyxFQUE2QyxLQUFLLGNBQWMsRUFBRSxNQUFNLGdDQUFnQyxDQUFDO0FBQ2hILE9BQU8sS0FBSyxFQUFFLFNBQVMsRUFBRSxNQ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,EACN,YAAY,GACZ,UAAU,GACV,uBAAuB,GACvB,eAAe,GACf,iCAAiC,GACjC,WAAW,GACX,MAAM,GACN,QAAQ,CACX,CAAC;IACJ,SAAS,EAAE,GAAG,GAAG,IAAI,CAAC,iBAAiB,EAAE,MAAM,CAAC,CAAC;IACjD,WAAW,EAAE;QAAE,aAAa,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAC;QAAC,oBAAoB,EAAE,MAAM,CAAC;QAAC,eAAe,EAAE,MAAM,CAAA;KAAE,CAAC;IACpH,kFAAkF;IAClF,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF;;;;;;GAMG;AACH,wBAAsB,uBAAuB,CAAC,EAC5C,MAAM,EACN,SAAS,EACT,eAAe,EACf,YAAY,EACZ,cAAc,EACd,UAAU,EACV,UAAU,EACV,SAAS,EACT,YAAY,EACZ,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,qBAAqB,EACrB,sBAAsB,EACtB,QAAQ,EACR,SAAS,EACT,WAAW,EACX,UAAU,EACV,GAAG,EACJ,EAAE,2BAA2B,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAwE1D"}
1
+ {"version":3,"file":"automine_factory.d.ts","sourceRoot":"","sources":["../../../src/sequencer/automine/automine_factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAC1E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAA6C,KAAK,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAGlE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,KAAK,EAAE,MAAM,EAAE,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AC;IACjC,kBAAkB,EAAE,0BAA0B,CAAC;IAC/C,qBAAqB,EAAE,qBAAqB,CAAC;IAC7C,sBAAsB,EAAE,sBAAsB,CAAC;IAC/C,QAAQ,EAAE,aAAa,GACrB,mBAAmB,GACnB,IAAI,CACF,QAAQ,EACN,YAAY,GACZ,UAAU,GACV,uBAAuB,GACvB,eAAe,GACf,iCAAiC,GACjC,WAAW,GACX,MAAM,GACN,QAAQ,CACX,CAAC;IACJ,SAAS,EAAE,GAAG,GAAG,IAAI,CAAC,iBAAiB,EAAE,MAAM,CAAC,CAAC;IACjD,WAAW,EAAE;QAAE,aAAa,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAC;QAAC,oBAAoB,EAAE,MAAM,CAAC;QAAC,eAAe,EAAE,MAAM,CAAA;KAAE,CAAC;IACpH,kFAAkF;IAClF,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF;;;;;;GAMG;AACH,wBAAsB,uBAAuB,CAAC,EAC5C,MAAM,EACN,SAAS,EACT,eAAe,EACf,YAAY,EACZ,cAAc,EACd,UAAU,EACV,UAAU,EACV,SAAS,EACT,YAAY,EACZ,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,qBAAqB,EACrB,sBAAsB,EACtB,QAAQ,EACR,SAAS,EACT,WAAW,EACX,UAAU,EACV,GAAG,EACJ,EAAE,2BAA2B,GAAG,OAAO,CAAC,iBAAiB,CAAC,CA0E1D"}
@@ -3,6 +3,8 @@ import { PublisherManager } from '@aztec-labs/ethereum/publisher-manager';
3
3
  import { EthCheatCodes } from '@aztec-labs/ethereum/test';
4
4
  import { NodeKeystoreAdapter } from '@aztec-labs/validator-client';
5
5
  import { getPublisherConfigFromSequencerConfig } from '../../config.js';
6
+ import { PROPOSE_REFERENCE_SEND } from '../../publisher/gas_constants.js';
7
+ import { PublisherManagerMetrics } from '../../publisher/publisher-manager-metrics.js';
6
8
  import { SequencerPublisherFactory } from '../../publisher/sequencer-publisher-factory.js';
7
9
  import { AutomineSequencer } from './automine_sequencer.js';
8
10
  /**
@@ -14,7 +16,9 @@ import { AutomineSequencer } from './automine_sequencer.js';
14
16
  */ export async function createAutomineSequencer({ config, l1TxUtils, funderL1TxUtils, publicClient, rollupContract, epochCache, blobClient, telemetry, dateProvider, keyStoreManager, validatorClient, checkpointsBuilder, globalVariableBuilder, worldStateSynchronizer, archiver, p2pClient, l1Constants, autoSettle, log }) {
15
17
  const publisherManager = new PublisherManager(l1TxUtils, getPublisherConfigFromSequencerConfig(config), {
16
18
  bindings: log.getBindings(),
17
- funder: funderL1TxUtils
19
+ funder: funderL1TxUtils,
20
+ metrics: new PublisherManagerMetrics(telemetry, 'sequencer'),
21
+ referenceSend: config.fishermanMode ? undefined : PROPOSE_REFERENCE_SEND
18
22
  });
19
23
  const governanceProposerContract = new GovernanceProposerContract(publicClient, config.governanceProposerAddress.toString());
20
24
  const publisherFactory = new SequencerPublisherFactory(config, {
@@ -0,0 +1,135 @@
1
+ import type { BlockNumber, CheckpointNumber, SlotNumber } from '@aztec-labs/foundation/branded-types';
2
+ import type { Logger } from '@aztec-labs/foundation/log';
3
+ import { type DateProvider } from '@aztec-labs/foundation/timer';
4
+ import type { MerkleTreeReadOperations } from '@aztec-labs/stdlib/interfaces/server';
5
+ import { InboxMessagePrefixRef, type InboxMessageRange } from '@aztec-labs/stdlib/messaging';
6
+ import { type InboxEndpointResolver, type StreamingMessageSource } from './inbox_message_selection.js';
7
+ /** Cap on the Inbox endpoint read a block makes near the checkpoint cap, well under a sub-slot. */
8
+ export declare const INBOX_ENDPOINT_READ_TIMEOUT_MS = 2000;
9
+ /** What a block's streaming message selection decided. */
10
+ export type StreamingBundleSelection = {
11
+ /** Build the block over this range; the block signs `range.end` as its prefix reference. */
12
+ kind: 'consume';
13
+ range: InboxMessageRange;
14
+ } | {
15
+ /** No checkpoint ending this way can be published; give up the slot without signing anything more. */
16
+ kind: 'abort';
17
+ reason: string;
18
+ context?: Record<string, unknown>;
19
+ };
20
+ /** What the forced tail block, built after the sub-slot schedule ran out, has to do to end on a live bucket end. */
21
+ export type ForcedEndpointDecision = {
22
+ /** Build one message-only block over this range, ending on the endpoint, before `deadline`. */
23
+ kind: 'consume';
24
+ range: InboxMessageRange;
25
+ deadline: Date;
26
+ } | {
27
+ /** The cursor already sits on a live bucket end; the checkpoint publishes as it stands. */
28
+ kind: 'already-at-endpoint';
29
+ } | {
30
+ /** No live bucket end is reachable; the checkpoint has to be abandoned. */
31
+ kind: 'abort';
32
+ reason: string;
33
+ context: Record<string, unknown>;
34
+ };
35
+ /** Collaborators of {@link CheckpointInboxConsumption}. */
36
+ export type CheckpointInboxConsumptionDeps = {
37
+ messageSource: StreamingMessageSource;
38
+ inbox: InboxEndpointResolver;
39
+ dateProvider: DateProvider;
40
+ log: Logger;
41
+ /** Fields prepended to every log line the consumption emits. */
42
+ logContext: {
43
+ slot: SlotNumber;
44
+ checkpointNumber: CheckpointNumber;
45
+ };
46
+ };
47
+ /**
48
+ * Streaming Inbox consumption of one checkpoint: the cursor and every range decision made from it. Consumption starts
49
+ * from the parent checkpoint's consumed message prefix and advances one block at a time, greedily on the local log
50
+ * while the step stays clear of the checkpoint cap and against a live L1 bucket end once it does not.
51
+ *
52
+ * Invariants:
53
+ * - Nothing is cached across attempts: every selection re-derives from the current cursor and the current local view,
54
+ * so a block that fails to build and is retried is offered the same messages again.
55
+ * - Each selection reads the cursor and the local synced position once, at its start, and decides only from those.
56
+ * - Selections never modify the cursor. Only {@link commit} does, after a block built over the selected range, and it
57
+ * replaces the cursor rather than modifying the position in place. An endpoint lookup that lost its timeout race
58
+ * and keeps running therefore only ever reads a position that stays valid.
59
+ */
60
+ export declare class CheckpointInboxConsumption {
61
+ /** Cumulative Inbox message count consumed as of the parent checkpoint; the per-checkpoint cap origin. */
62
+ readonly checkpointStartTotalMsgCount: bigint;
63
+ /** The message prefix consumed so far (the parent checkpoint's until a block of this checkpoint builds). */
64
+ private cursor;
65
+ private readonly deps;
66
+ private constructor();
67
+ /**
68
+ * Starts consumption at the parent checkpoint's consumed message prefix. The parent's cumulative consumed total is
69
+ * the L1-to-L2 message tree leaf count of the fork this checkpoint builds on (compact indexing makes leaf count equal
70
+ * cumulative message count), and the local message log serves the prefix hash at that count. Genesis is the
71
+ * `total = 0` case with a zero hash.
72
+ */
73
+ static start(fork: Pick<MerkleTreeReadOperations, 'getTreeInfo'>, deps: CheckpointInboxConsumptionDeps): Promise<CheckpointInboxConsumption>;
74
+ /** Cumulative chain total consumed through the cursor (not this checkpoint's delta). */
75
+ get consumedTotalMsgCount(): bigint;
76
+ /** Whether any block of this checkpoint has advanced the cursor past the checkpoint start. */
77
+ get hasConsumedInThisCheckpoint(): boolean;
78
+ /**
79
+ * Selects the message range the next block consumes. Does not advance the cursor; the caller commits the range
80
+ * only after the block builds successfully.
81
+ *
82
+ * Selection is greedy on the local log: every message the archiver has observed, up to the per-block and
83
+ * checkpoint caps. A block consults L1 only when it is the checkpoint's final block, whose position must be a live
84
+ * L1 bucket end, or when its prospective end would pass the threshold one bucket below the cap and could leave the
85
+ * last legal endpoint behind. The lookup is bounded by the checkpoint cap on a non-final block, so a mandatory
86
+ * bucket beyond this block's own reach is not stranded by a nearer endpoint, and additionally by one block's
87
+ * capacity on the final block. A non-final block then ends at the further of what the lookup allows and the safe
88
+ * local step, so consulting L1 never consumes less than staying below the threshold would have, and it may
89
+ * legitimately end inside a bucket. The final block instead ends exactly on the resolved boundary, so whenever the
90
+ * last live boundary within reach sits behind the safe local step it consumes fewer messages than the local log
91
+ * alone would allow. Nothing is retained: the next attempt decides again.
92
+ *
93
+ * An endpoint that cannot be resolved on a non-final block (local lag, no live endpoint yet) leaves the block with
94
+ * that safe local step and is retried on the next block; on the final block it abandons the checkpoint. A local
95
+ * prefix that no longer matches the cursor means the blocks already signed were built on messages the local log
96
+ * has since replaced, which also abandons the checkpoint.
97
+ */
98
+ selectRange(opts: {
99
+ isFinalBlock: boolean;
100
+ buildDeadline: number;
101
+ }): Promise<StreamingBundleSelection>;
102
+ /**
103
+ * Decides the forced tail block that ends the checkpoint at a live L1 bucket end after the sub-slot schedule ran out
104
+ * mid-checkpoint, resolving the endpoint the way the checkpoint's final block would. Does not advance the cursor.
105
+ * The deadline is taken from `getDeadline` only once the local view has been read, so it reflects the time the
106
+ * lookup actually starts at.
107
+ */
108
+ resolveForcedEndpoint(opts: {
109
+ blockNumber: BlockNumber;
110
+ getDeadline: () => {
111
+ deadline: Date;
112
+ pastLastBlockBuildTime: boolean;
113
+ };
114
+ }): Promise<ForcedEndpointDecision>;
115
+ /**
116
+ * Advances the cursor to `range.end` after a block built over `range`, and returns the prefix reference that block
117
+ * signs. A block that consumed nothing re-signs the cursor's prefix. Throws if the range does not start at the
118
+ * cursor, which would mean it was not selected from the current cursor.
119
+ */
120
+ commit(range: InboxMessageRange): InboxMessagePrefixRef;
121
+ /** The consumption fields reported when a checkpoint is abandoned. */
122
+ toLogContext(): {
123
+ checkpointStartTotalMsgCount: bigint;
124
+ consumedTotalMsgCount: bigint;
125
+ inboxRollingHash: string;
126
+ };
127
+ private takeSnapshot;
128
+ private readRange;
129
+ /**
130
+ * Runs the single Inbox endpoint query of an endpoint block within the block's build deadline. The lookup gets at
131
+ * least a millisecond even past the deadline, and any failure, a timeout included, reads as no live endpoint.
132
+ */
133
+ private resolveEndpointWithinDeadline;
134
+ }
135
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2hlY2twb2ludF9pbmJveF9jb25zdW1wdGlvbi5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3NlcXVlbmNlci9jaGVja3BvaW50X2luYm94X2NvbnN1bXB0aW9uLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE9BQU8sS0FBSyxFQUFFLFdBQVcsRUFBRSxnQkFBZ0IsRUFBRSxVQUFVLEVBQUUsTUFBTSxzQ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labs/foundation/timer';
3
+ import { InboxMessagePrefixRef } from '@aztec-labs/stdlib/messaging';
4
+ import { MerkleTreeId } from '@aztec-labs/stdlib/trees';
5
+ import { PROTOCOL_INBOX_CONSUMPTION_CAPS, getEndpointUpperBound, mustQueryEndpoint, resolveEndpoint, selectGreedyEnd, selectSafeLocalEnd } from './inbox_message_selection.js';
6
+ /** Cap on the Inbox endpoint read a block makes near the checkpoint cap, well under a sub-slot. */ export const INBOX_ENDPOINT_READ_TIMEOUT_MS = 2_000;
7
+ /**
8
+ * Streaming Inbox consumption of one checkpoint: the cursor and every range decision made from it. Consumption starts
9
+ * from the parent checkpoint's consumed message prefix and advances one block at a time, greedily on the local log
10
+ * while the step stays clear of the checkpoint cap and against a live L1 bucket end once it does not.
11
+ *
12
+ * Invariants:
13
+ * - Nothing is cached across attempts: every selection re-derives from the current cursor and the current local view,
14
+ * so a block that fails to build and is retried is offered the same messages again.
15
+ * - Each selection reads the cursor and the local synced position once, at its start, and decides only from those.
16
+ * - Selections never modify the cursor. Only {@link commit} does, after a block built over the selected range, and it
17
+ * replaces the cursor rather than modifying the position in place. An endpoint lookup that lost its timeout race
18
+ * and keeps running therefore only ever reads a position that stays valid.
19
+ */ export class CheckpointInboxConsumption {
20
+ checkpointStartTotalMsgCount;
21
+ cursor;
22
+ deps;
23
+ constructor(/** Cumulative Inbox message count consumed as of the parent checkpoint; the per-checkpoint cap origin. */ checkpointStartTotalMsgCount, /** The message prefix consumed so far (the parent checkpoint's until a block of this checkpoint builds). */ cursor, deps){
24
+ this.checkpointStartTotalMsgCount = checkpointStartTotalMsgCount;
25
+ this.cursor = cursor;
26
+ this.deps = deps;
27
+ }
28
+ /**
29
+ * Starts consumption at the parent checkpoint's consumed message prefix. The parent's cumulative consumed total is
30
+ * the L1-to-L2 message tree leaf count of the fork this checkpoint builds on (compact indexing makes leaf count equal
31
+ * cumulative message count), and the local message log serves the prefix hash at that count. Genesis is the
32
+ * `total = 0` case with a zero hash.
33
+ */ static async start(fork, deps) {
34
+ const checkpointStartTotalMsgCount = (await fork.getTreeInfo(MerkleTreeId.L1_TO_L2_MESSAGE_TREE)).size;
35
+ const cursor = await deps.messageSource.getMessagePosition(checkpointStartTotalMsgCount);
36
+ if (cursor === undefined) {
37
+ throw new Error(`Streaming inbox: cannot resolve the Inbox message prefix at cumulative total ${checkpointStartTotalMsgCount} ` + `(checkpoint ${deps.logContext.checkpointNumber}); local Inbox view has not synced it`);
38
+ }
39
+ return new CheckpointInboxConsumption(checkpointStartTotalMsgCount, cursor, deps);
40
+ }
41
+ /** Cumulative chain total consumed through the cursor (not this checkpoint's delta). */ get consumedTotalMsgCount() {
42
+ return this.cursor.totalMessageCount;
43
+ }
44
+ /** Whether any block of this checkpoint has advanced the cursor past the checkpoint start. */ get hasConsumedInThisCheckpoint() {
45
+ return this.cursor.totalMessageCount > this.checkpointStartTotalMsgCount;
46
+ }
47
+ /**
48
+ * Selects the message range the next block consumes. Does not advance the cursor; the caller commits the range
49
+ * only after the block builds successfully.
50
+ *
51
+ * Selection is greedy on the local log: every message the archiver has observed, up to the per-block and
52
+ * checkpoint caps. A block consults L1 only when it is the checkpoint's final block, whose position must be a live
53
+ * L1 bucket end, or when its prospective end would pass the threshold one bucket below the cap and could leave the
54
+ * last legal endpoint behind. The lookup is bounded by the checkpoint cap on a non-final block, so a mandatory
55
+ * bucket beyond this block's own reach is not stranded by a nearer endpoint, and additionally by one block's
56
+ * capacity on the final block. A non-final block then ends at the further of what the lookup allows and the safe
57
+ * local step, so consulting L1 never consumes less than staying below the threshold would have, and it may
58
+ * legitimately end inside a bucket. The final block instead ends exactly on the resolved boundary, so whenever the
59
+ * last live boundary within reach sits behind the safe local step it consumes fewer messages than the local log
60
+ * alone would allow. Nothing is retained: the next attempt decides again.
61
+ *
62
+ * An endpoint that cannot be resolved on a non-final block (local lag, no live endpoint yet) leaves the block with
63
+ * that safe local step and is retried on the next block; on the final block it abandons the checkpoint. A local
64
+ * prefix that no longer matches the cursor means the blocks already signed were built on messages the local log
65
+ * has since replaced, which also abandons the checkpoint.
66
+ */ async selectRange(opts) {
67
+ const snapshot = await this.takeSnapshot();
68
+ const { cursor, cursorCount, localSyncedCount, checkpointStartCount, caps } = snapshot;
69
+ const greedyEnd = selectGreedyEnd(snapshot);
70
+ if (!mustQueryEndpoint({
71
+ prospectiveEnd: greedyEnd,
72
+ checkpointStartCount,
73
+ isFinalBlock: opts.isFinalBlock,
74
+ caps
75
+ })) {
76
+ return this.readRange(cursor, greedyEnd);
77
+ }
78
+ const upperBound = getEndpointUpperBound({
79
+ ...snapshot,
80
+ isFinalBlock: opts.isFinalBlock
81
+ });
82
+ const resolved = await this.resolveEndpointWithinDeadline(cursor, upperBound, opts.buildDeadline);
83
+ const safeLocalEnd = selectSafeLocalEnd(snapshot);
84
+ if (!resolved.ok) {
85
+ if (resolved.reason === 'local_prefix_changed') {
86
+ return {
87
+ kind: 'abort',
88
+ reason: 'inbox_prefix_reorged',
89
+ context: {
90
+ upperBound
91
+ }
92
+ };
93
+ }
94
+ if (opts.isFinalBlock) {
95
+ return {
96
+ kind: 'abort',
97
+ reason: 'inbox_completion_unresolved',
98
+ context: {
99
+ cause: resolved.reason,
100
+ upperBound,
101
+ endpointTotal: resolved.endpointTotal,
102
+ localSyncedCount
103
+ }
104
+ };
105
+ }
106
+ this.deps.log.warn(`Streaming Inbox endpoint not resolvable yet, taking the safe local step`, {
107
+ ...this.deps.logContext,
108
+ cause: resolved.reason,
109
+ cursorTotalMsgCount: cursorCount,
110
+ localSyncedCount,
111
+ upperBound,
112
+ endpointTotal: resolved.endpointTotal,
113
+ safeLocalEnd
114
+ });
115
+ return this.readRange(cursor, safeLocalEnd);
116
+ }
117
+ const endpointTotal = resolved.endpoint.totalMessageCount;
118
+ const endpointEnd = minBigint(cursorCount + BigInt(caps.perBlockCap), endpointTotal);
119
+ // The final block has to land on the endpoint, so it takes it even when the safe local step reaches further; any
120
+ // other block takes the further of the two, so consulting L1 never consumes less than staying below the
121
+ // threshold would have.
122
+ const end = opts.isFinalBlock ? endpointEnd : maxBigint(safeLocalEnd, endpointEnd);
123
+ this.deps.log.verbose(`Streaming Inbox resolved endpoint ${endpointTotal}, consuming through ${end}`, {
124
+ ...this.deps.logContext,
125
+ cursorTotalMsgCount: cursorCount,
126
+ localSyncedCount,
127
+ upperBound,
128
+ endpointTotalMsgCount: endpointTotal,
129
+ bucketSeq: resolved.bucketSeq,
130
+ end
131
+ });
132
+ // An end short of or past the endpoint needs its own read, so the signed hash is the one at `end` and never the
133
+ // endpoint's; landing exactly on the endpoint reuses the snapshot the resolver already read and checked against
134
+ // the cursor's hash.
135
+ return end === endpointTotal ? {
136
+ kind: 'consume',
137
+ range: resolved.range
138
+ } : this.readRange(cursor, end);
139
+ }
140
+ /**
141
+ * Decides the forced tail block that ends the checkpoint at a live L1 bucket end after the sub-slot schedule ran out
142
+ * mid-checkpoint, resolving the endpoint the way the checkpoint's final block would. Does not advance the cursor.
143
+ * The deadline is taken from `getDeadline` only once the local view has been read, so it reflects the time the
144
+ * lookup actually starts at.
145
+ */ async resolveForcedEndpoint(opts) {
146
+ const snapshot = await this.takeSnapshot();
147
+ const { cursor, cursorCount, localSyncedCount } = snapshot;
148
+ const upperBound = getEndpointUpperBound({
149
+ ...snapshot,
150
+ isFinalBlock: true
151
+ });
152
+ const { deadline, pastLastBlockBuildTime } = opts.getDeadline();
153
+ this.deps.log.warn(`Ending checkpoint ${this.deps.logContext.checkpointNumber} with a forced Inbox endpoint block`, {
154
+ ...this.deps.logContext,
155
+ blockNumber: opts.blockNumber,
156
+ cursorTotalMsgCount: cursorCount,
157
+ upperBound,
158
+ deadline: deadline.toISOString(),
159
+ pastLastBlockBuildTime
160
+ });
161
+ const resolved = await this.resolveEndpointWithinDeadline(cursor, upperBound, deadline.getTime() / 1000);
162
+ if (!resolved.ok) {
163
+ return {
164
+ kind: 'abort',
165
+ reason: resolved.reason === 'local_prefix_changed' ? 'inbox_prefix_reorged' : 'inbox_completion_unresolved',
166
+ context: {
167
+ cause: resolved.reason,
168
+ upperBound,
169
+ endpointTotal: resolved.endpointTotal,
170
+ localSyncedCount
171
+ }
172
+ };
173
+ }
174
+ if (resolved.endpoint.totalMessageCount === cursorCount) {
175
+ this.deps.log.verbose(`Checkpoint ${this.deps.logContext.checkpointNumber} already ends at a live Inbox bucket end`, {
176
+ ...this.deps.logContext,
177
+ cursorTotalMsgCount: cursorCount
178
+ });
179
+ return {
180
+ kind: 'already-at-endpoint'
181
+ };
182
+ }
183
+ return {
184
+ kind: 'consume',
185
+ range: resolved.range,
186
+ deadline
187
+ };
188
+ }
189
+ /**
190
+ * Advances the cursor to `range.end` after a block built over `range`, and returns the prefix reference that block
191
+ * signs. A block that consumed nothing re-signs the cursor's prefix. Throws if the range does not start at the
192
+ * cursor, which would mean it was not selected from the current cursor.
193
+ */ commit(range) {
194
+ if (range.start.totalMessageCount !== this.cursor.totalMessageCount || !range.start.rollingHash.equals(this.cursor.rollingHash)) {
195
+ throw new Error(`Streaming inbox: cannot commit a range starting at message total ${range.start.totalMessageCount} ` + `with the cursor at ${this.cursor.totalMessageCount} (checkpoint ${this.deps.logContext.checkpointNumber})`);
196
+ }
197
+ this.cursor = range.end;
198
+ return InboxMessagePrefixRef.fromPosition(this.cursor);
199
+ }
200
+ /** The consumption fields reported when a checkpoint is abandoned. */ toLogContext() {
201
+ return {
202
+ checkpointStartTotalMsgCount: this.checkpointStartTotalMsgCount,
203
+ consumedTotalMsgCount: this.cursor.totalMessageCount,
204
+ inboxRollingHash: this.cursor.rollingHash.toString()
205
+ };
206
+ }
207
+ async takeSnapshot() {
208
+ const cursor = this.cursor;
209
+ const localSyncedCount = (await this.deps.messageSource.getSyncedMessagePosition()).totalMessageCount;
210
+ return {
211
+ cursor,
212
+ cursorCount: cursor.totalMessageCount,
213
+ localSyncedCount,
214
+ checkpointStartCount: this.checkpointStartTotalMsgCount,
215
+ caps: PROTOCOL_INBOX_CONSUMPTION_CAPS
216
+ };
217
+ }
218
+ /**
219
+ * Reads the messages from the cursor to `end` together with the positions at both ends from one snapshot of the
220
+ * local log, and checks that the log still starts where the cursor says: the blocks signed so far were built on
221
+ * that prefix, so a changed prefix (a content-changing L1 reorg) means the checkpoint cannot continue. A range the
222
+ * log can no longer serve whole is the same condition.
223
+ */ async readRange(cursor, end) {
224
+ let range;
225
+ try {
226
+ range = await this.deps.messageSource.getL1ToL2MessageRange(cursor.totalMessageCount, end);
227
+ } catch (err) {
228
+ return {
229
+ kind: 'abort',
230
+ reason: 'inbox_range_unavailable',
231
+ context: {
232
+ end,
233
+ error: err instanceof Error ? err.message : String(err)
234
+ }
235
+ };
236
+ }
237
+ if (!range.start.rollingHash.equals(cursor.rollingHash)) {
238
+ return {
239
+ kind: 'abort',
240
+ reason: 'inbox_prefix_reorged',
241
+ context: {
242
+ end,
243
+ localPrefixHash: range.start.rollingHash.toString()
244
+ }
245
+ };
246
+ }
247
+ return {
248
+ kind: 'consume',
249
+ range
250
+ };
251
+ }
252
+ /**
253
+ * Runs the single Inbox endpoint query of an endpoint block within the block's build deadline. The lookup gets at
254
+ * least a millisecond even past the deadline, and any failure, a timeout included, reads as no live endpoint.
255
+ */ resolveEndpointWithinDeadline(cursor, upperBound, buildDeadline) {
256
+ const remainingMs = buildDeadline * 1000 - this.deps.dateProvider.now();
257
+ const timeoutMs = Math.max(1, Math.min(INBOX_ENDPOINT_READ_TIMEOUT_MS, remainingMs));
258
+ return executeTimeout(()=>resolveEndpoint({
259
+ inbox: this.deps.inbox,
260
+ messageSource: this.deps.messageSource,
261
+ cursor,
262
+ upperBound
263
+ }), timeoutMs, `Inbox endpoint lookup at or before message total ${upperBound}`).catch((err)=>{
264
+ this.deps.log.warn(`Inbox endpoint lookup failed, treating the endpoint as unresolved: ${err}`, {
265
+ ...this.deps.logContext,
266
+ upperBound
267
+ });
268
+ return {
269
+ ok: false,
270
+ reason: 'no_live_endpoint',
271
+ upperBound
272
+ };
273
+ });
274
+ }
275
+ }