@aztec/sequencer-client 0.0.1-commit.2f68f620 → 0.0.1-commit.3100065

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 (94) hide show
  1. package/README.md +27 -27
  2. package/dest/client/sequencer-client.d.ts +16 -3
  3. package/dest/client/sequencer-client.d.ts.map +1 -1
  4. package/dest/client/sequencer-client.js +17 -12
  5. package/dest/config.d.ts +6 -2
  6. package/dest/config.d.ts.map +1 -1
  7. package/dest/config.js +23 -14
  8. package/dest/global_variable_builder/fee_predictor.d.ts +1 -1
  9. package/dest/global_variable_builder/fee_predictor.d.ts.map +1 -1
  10. package/dest/global_variable_builder/fee_predictor.js +11 -1
  11. package/dest/global_variable_builder/fee_provider.d.ts +1 -1
  12. package/dest/global_variable_builder/fee_provider.d.ts.map +1 -1
  13. package/dest/global_variable_builder/fee_provider.js +27 -5
  14. package/dest/global_variable_builder/global_builder.d.ts +3 -16
  15. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  16. package/dest/global_variable_builder/global_builder.js +2 -25
  17. package/dest/index.d.ts +2 -2
  18. package/dest/index.d.ts.map +1 -1
  19. package/dest/index.js +1 -1
  20. package/dest/publisher/config.d.ts +5 -1
  21. package/dest/publisher/config.d.ts.map +1 -1
  22. package/dest/publisher/config.js +11 -1
  23. package/dest/publisher/l1_to_l2_messaging.d.ts +21 -0
  24. package/dest/publisher/l1_to_l2_messaging.d.ts.map +1 -0
  25. package/dest/publisher/l1_to_l2_messaging.js +70 -0
  26. package/dest/publisher/sequencer-publisher.d.ts +17 -4
  27. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  28. package/dest/publisher/sequencer-publisher.js +119 -22
  29. package/dest/publisher/write_json.d.ts +11 -0
  30. package/dest/publisher/write_json.d.ts.map +1 -0
  31. package/dest/publisher/write_json.js +57 -0
  32. package/dest/sequencer/automine/automine_factory.d.ts +5 -3
  33. package/dest/sequencer/automine/automine_factory.d.ts.map +1 -1
  34. package/dest/sequencer/automine/automine_factory.js +2 -1
  35. package/dest/sequencer/automine/automine_sequencer.d.ts +43 -5
  36. package/dest/sequencer/automine/automine_sequencer.d.ts.map +1 -1
  37. package/dest/sequencer/automine/automine_sequencer.js +199 -18
  38. package/dest/sequencer/automine/index.d.ts +3 -0
  39. package/dest/sequencer/automine/index.d.ts.map +1 -0
  40. package/dest/sequencer/automine/index.js +2 -0
  41. package/dest/sequencer/checkpoint_proposal_job.d.ts +24 -16
  42. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
  43. package/dest/sequencer/checkpoint_proposal_job.js +98 -90
  44. package/dest/sequencer/errors.d.ts +1 -8
  45. package/dest/sequencer/errors.d.ts.map +1 -1
  46. package/dest/sequencer/errors.js +0 -9
  47. package/dest/sequencer/events.d.ts +16 -5
  48. package/dest/sequencer/events.d.ts.map +1 -1
  49. package/dest/sequencer/index.d.ts +1 -3
  50. package/dest/sequencer/index.d.ts.map +1 -1
  51. package/dest/sequencer/index.js +0 -2
  52. package/dest/sequencer/requests_tracker.d.ts +22 -0
  53. package/dest/sequencer/requests_tracker.d.ts.map +1 -0
  54. package/dest/sequencer/requests_tracker.js +33 -0
  55. package/dest/sequencer/sequencer.d.ts +110 -36
  56. package/dest/sequencer/sequencer.d.ts.map +1 -1
  57. package/dest/sequencer/sequencer.js +329 -174
  58. package/dest/test/index.d.ts +3 -3
  59. package/dest/test/index.d.ts.map +1 -1
  60. package/dest/test/utils.d.ts +15 -1
  61. package/dest/test/utils.d.ts.map +1 -1
  62. package/dest/test/utils.js +18 -1
  63. package/package.json +28 -27
  64. package/src/client/sequencer-client.ts +20 -13
  65. package/src/config.ts +25 -12
  66. package/src/global_variable_builder/fee_predictor.ts +11 -1
  67. package/src/global_variable_builder/fee_provider.ts +27 -5
  68. package/src/global_variable_builder/global_builder.ts +2 -34
  69. package/src/index.ts +1 -10
  70. package/src/publisher/config.ts +22 -1
  71. package/src/publisher/l1_to_l2_messaging.ts +85 -0
  72. package/src/publisher/sequencer-publisher.ts +116 -23
  73. package/src/publisher/write_json.ts +78 -0
  74. package/src/sequencer/automine/README.md +18 -4
  75. package/src/sequencer/automine/automine_factory.ts +8 -1
  76. package/src/sequencer/automine/automine_sequencer.ts +221 -20
  77. package/src/sequencer/automine/index.ts +6 -0
  78. package/src/sequencer/checkpoint_proposal_job.ts +119 -100
  79. package/src/sequencer/errors.ts +0 -15
  80. package/src/sequencer/events.ts +16 -4
  81. package/src/sequencer/index.ts +0 -2
  82. package/src/sequencer/requests_tracker.ts +43 -0
  83. package/src/sequencer/sequencer.ts +360 -187
  84. package/src/test/index.ts +2 -2
  85. package/src/test/utils.ts +33 -0
  86. package/dest/sequencer/chain_state_overrides.d.ts +0 -61
  87. package/dest/sequencer/chain_state_overrides.d.ts.map +0 -1
  88. package/dest/sequencer/chain_state_overrides.js +0 -98
  89. package/dest/sequencer/timetable.d.ts +0 -98
  90. package/dest/sequencer/timetable.d.ts.map +0 -1
  91. package/dest/sequencer/timetable.js +0 -227
  92. package/src/sequencer/README.md +0 -243
  93. package/src/sequencer/chain_state_overrides.ts +0 -162
  94. package/src/sequencer/timetable.ts +0 -288
package/src/test/index.ts CHANGED
@@ -1,16 +1,16 @@
1
1
  import type { L1TxUtils } from '@aztec/ethereum/l1-tx-utils';
2
2
  import type { PublisherManager } from '@aztec/ethereum/publisher-manager';
3
3
  import type { PublicProcessorFactory } from '@aztec/simulator/server';
4
+ import type { ProposerTimetable } from '@aztec/stdlib/timetable';
4
5
  import type { FullNodeCheckpointsBuilder, ValidatorClient } from '@aztec/validator-client';
5
6
 
6
7
  import { SequencerClient } from '../client/sequencer-client.js';
7
8
  import type { SequencerPublisherFactory } from '../publisher/sequencer-publisher-factory.js';
8
9
  import { Sequencer } from '../sequencer/sequencer.js';
9
- import type { SequencerTimetable } from '../sequencer/timetable.js';
10
10
 
11
11
  class TestSequencer_ extends Sequencer {
12
12
  declare public publicProcessorFactory: PublicProcessorFactory;
13
- declare public timetable: SequencerTimetable;
13
+ declare public timetable: ProposerTimetable;
14
14
  declare public publisherFactory: SequencerPublisherFactory;
15
15
  declare public validatorClient: ValidatorClient;
16
16
  declare public checkpointsBuilder: FullNodeCheckpointsBuilder;
package/src/test/utils.ts CHANGED
@@ -8,6 +8,8 @@ import { Signature } from '@aztec/foundation/eth-signature';
8
8
  import type { P2P } from '@aztec/p2p';
9
9
  import { PublicDataWrite } from '@aztec/stdlib/avm';
10
10
  import { CommitteeAttestation, L2Block } from '@aztec/stdlib/block';
11
+ import { DEFAULT_BLOCK_DURATION_MS } from '@aztec/stdlib/config';
12
+ import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
11
13
  import { BlockProposal, CheckpointAttestation, CheckpointProposal, ConsensusPayload } from '@aztec/stdlib/p2p';
12
14
  import { CheckpointHeader } from '@aztec/stdlib/rollup';
13
15
  import {
@@ -15,6 +17,13 @@ import {
15
17
  makeAppendOnlyTreeSnapshot,
16
18
  mockTxForRollup,
17
19
  } from '@aztec/stdlib/testing';
20
+ import {
21
+ DEFAULT_CHECKPOINT_PROPOSAL_INIT_TIME,
22
+ DEFAULT_CHECKPOINT_PROPOSAL_PREPARE_TIME,
23
+ DEFAULT_MIN_BLOCK_DURATION,
24
+ DEFAULT_P2P_PROPAGATION_TIME,
25
+ ProposerTimetable,
26
+ } from '@aztec/stdlib/timetable';
18
27
  import { BlockHeader, GlobalVariables, type Tx, makeProcessedTxFromPrivateOnlyTx } from '@aztec/stdlib/tx';
19
28
 
20
29
  import type { MockProxy } from 'jest-mock-extended';
@@ -22,6 +31,28 @@ import type { MockProxy } from 'jest-mock-extended';
22
31
  // Re-export mock classes from their dedicated file
23
32
  export { MockCheckpointBuilder, MockCheckpointsBuilder } from './mock_checkpoint_builder.js';
24
33
 
34
+ /**
35
+ * Builds a {@link ProposerTimetable} for tests from a millisecond block duration and optional budgets,
36
+ * filling unset budgets with the shared `DEFAULT_*` values the sequencer config layer applies. Mirrors how
37
+ * the sequencer constructs its timetable so tests exercise the same budget resolution.
38
+ */
39
+ export function makeProposerTimetable(opts: {
40
+ l1Constants: Pick<L1RollupConstants, 'l1GenesisTime' | 'slotDuration' | 'ethereumSlotDuration'>;
41
+ blockDurationMs?: number;
42
+ minBlockDuration?: number;
43
+ p2pPropagationTime?: number;
44
+ checkpointProposalPrepareTime?: number;
45
+ }): ProposerTimetable {
46
+ return new ProposerTimetable({
47
+ l1Constants: opts.l1Constants,
48
+ blockDuration: (opts.blockDurationMs ?? DEFAULT_BLOCK_DURATION_MS) / 1000,
49
+ minBlockDuration: opts.minBlockDuration ?? DEFAULT_MIN_BLOCK_DURATION,
50
+ p2pPropagationTime: opts.p2pPropagationTime ?? DEFAULT_P2P_PROPAGATION_TIME,
51
+ checkpointProposalPrepareTime: opts.checkpointProposalPrepareTime ?? DEFAULT_CHECKPOINT_PROPOSAL_PREPARE_TIME,
52
+ checkpointProposalInitTime: DEFAULT_CHECKPOINT_PROPOSAL_INIT_TIME,
53
+ });
54
+ }
55
+
25
56
  /**
26
57
  * Creates a mock transaction with a specific seed for deterministic testing
27
58
  */
@@ -59,6 +90,7 @@ export async function makeBlock(txs: Tx[], globalVariables: GlobalVariables): Pr
59
90
  */
60
91
  export function mockPendingTxs(p2p: MockProxy<P2P>, txs: Tx[]): void {
61
92
  p2p.getPendingTxCount.mockResolvedValue(txs.length);
93
+ p2p.hasEligiblePendingTxs.mockImplementation(minCount => Promise.resolve(txs.length >= minCount));
62
94
  p2p.iteratePendingTxs.mockImplementation(() => mockTxIterator(Promise.resolve(txs)));
63
95
  p2p.iterateEligiblePendingTxs.mockImplementation(() => mockTxIterator(Promise.resolve(txs)));
64
96
  }
@@ -98,6 +130,7 @@ function createCheckpointHeaderFromBlock(block: L2Block): CheckpointHeader {
98
130
  gv.feeRecipient,
99
131
  gv.gasFees,
100
132
  block.header.totalManaUsed,
133
+ block.header.totalFees,
101
134
  );
102
135
  }
103
136
 
@@ -1,61 +0,0 @@
1
- import { RollupContract, type SimulationOverridesPlan } from '@aztec/ethereum/contracts';
2
- import { CheckpointNumber } from '@aztec/foundation/branded-types';
3
- import type { Logger } from '@aztec/foundation/log';
4
- import { type ProposedCheckpointData } from '@aztec/stdlib/checkpoint';
5
- import type { CoordinationSignatureContext } from '@aztec/stdlib/p2p';
6
- type CheckpointSimulationOverridesPlanInput = {
7
- /** Target rollup contract. */
8
- rollup: RollupContract;
9
- /** Checkpoint number to be proposed. */
10
- checkpointNumber: CheckpointNumber;
11
- /** Logger instance. */
12
- log: Logger;
13
- /**
14
- * The proposed parent checkpoint when pipelining. Its `checkpointNumber` must equal
15
- * `checkpointNumber - 1`; the helper enforces this. Mutually exclusive with
16
- * `invalidateToPendingCheckpointNumber`.
17
- */
18
- proposedCheckpointData?: ProposedCheckpointData;
19
- /**
20
- * The pending checkpoint number we'll end up at after invalidation lands. Mutually exclusive
21
- * with `proposedCheckpointData`.
22
- */
23
- invalidateToPendingCheckpointNumber?: CheckpointNumber;
24
- /**
25
- * The real on-chain pending checkpoint number (typically `syncedTo.checkpointedCheckpointNumber`).
26
- * Used as the snapshot we pin both `pending` and `proven` to avoid prunes in simulation.
27
- */
28
- checkpointedCheckpointNumber: CheckpointNumber;
29
- /**
30
- * Chain-level consensus signature context. Used to recompute the parent's `payloadDigest` for the
31
- * pipelined simulation override so it matches what `propose` will write into `tempCheckpointLogs[parent]`
32
- * once the parent lands.
33
- */
34
- signatureContext: CoordinationSignatureContext;
35
- };
36
- /**
37
- * Builds the SimulationOverridesPlan describing the simulated L1 rollup state for a checkpoint's
38
- * enqueue-time simulations: `canProposeAt` (in Sequencer.doWork) and the propose-related sims
39
- * (validateBlockHeader, simulateProposeTx). The plan reflects "as if our pipelined parent
40
- * checkpoint has landed and any required invalidation has executed" — the gap that needs to be
41
- * bridged at enqueue time.
42
- *
43
- * Pipelining (`proposedCheckpointData`) and invalidation (`invalidateToPendingCheckpointNumber`)
44
- * are mutually exclusive; passing both throws.
45
- */
46
- export declare function buildCheckpointSimulationOverridesPlan(input: CheckpointSimulationOverridesPlanInput): Promise<SimulationOverridesPlan | undefined>;
47
- type PipelinedParentFeeHeaderInput = {
48
- checkpointNumber: CheckpointNumber;
49
- proposedCheckpointData: ProposedCheckpointData;
50
- rollup: RollupContract;
51
- log: Logger;
52
- };
53
- /**
54
- * Derives the pending parent fee header used during pipelined proposal simulation. Returns
55
- * `undefined` only when no grandparent exists (i.e. the proposed parent is the genesis
56
- * checkpoint); all other failure modes (missing grandparent state, missing fee header, RPC
57
- * errors) throw so callers don't silently desync the fee-header override.
58
- */
59
- export declare function computePipelinedParentFeeHeader(input: PipelinedParentFeeHeaderInput): Promise<import("@aztec/ethereum/contracts").FeeHeader | undefined>;
60
- export {};
61
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2hhaW5fc3RhdGVfb3ZlcnJpZGVzLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvc2VxdWVuY2VyL2NoYWluX3N0YXRlX292ZXJyaWRlcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsY0FBYyxFQUE4QixLQUFLLHVCQUF1QixFQUFFLE1BQU0sMkJBQTJCLENBQUM7QUFDckgsT0FBTyxFQUFFLGdCQUFnQixFQUFFLE1BQU0saUNBQWlDLENBQUM7QUFDbkUsT0FBTyxLQUFLLEVBQUUsTUFBTSxFQUFFLE1BQU0sdUJBQXVCLENBQUM7QUFDcEQsT0FBTyxFQUFFLEtBQUssc0JBQXNCLEVBQWtDLE1BQU0sMEJBQTBCLENBQUM7QUFDdkcsT0FBTyxLQUFLLEVBQUUsNEJBQTRCLEVBQUUsTUFBTSxtQkFBbUIsQ0FBQztBQUV0RSxLQUFLLHNDQUFzQyxHQUFHO0lBQzVDLDhCQUE4QjtJQUM5QixNQUFNLEVBQUUsY0FBYyxDQUFDO0lBQ3ZCLHdDQUF3QztJQUN4QyxnQkFBZ0IsRUFBRSxnQkFBZ0IsQ0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AAK,EAAE,4BAA4B,EAAE,MAAM,mBAAmB,CAAC;AAEtE,KAAK,sCAAsC,GAAG;IAC5C,8BAA8B;IAC9B,MAAM,EAAE,cAAc,CAAC;IACvB,wCAAwC;IACxC,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,uBAAuB;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ;;;;OAIG;IACH,sBAAsB,CAAC,EAAE,sBAAsB,CAAC;IAChD;;;OAGG;IACH,mCAAmC,CAAC,EAAE,gBAAgB,CAAC;IACvD;;;OAGG;IACH,4BAA4B,EAAE,gBAAgB,CAAC;IAC/C;;;;OAIG;IACH,gBAAgB,EAAE,4BAA4B,CAAC;CAChD,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAsB,sCAAsC,CAC1D,KAAK,EAAE,sCAAsC,GAC5C,OAAO,CAAC,uBAAuB,GAAG,SAAS,CAAC,CAsD9C;AAqBD,KAAK,6BAA6B,GAAG;IACnC,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,sBAAsB,EAAE,sBAAsB,CAAC;IAC/C,MAAM,EAAE,cAAc,CAAC;IACvB,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF;;;;;GAKG;AACH,wBAAsB,+BAA+B,CAAC,KAAK,EAAE,6BAA6B,sEAwBzF"}
@@ -1,98 +0,0 @@
1
- import { RollupContract, SimulationOverridesBuilder } from '@aztec/ethereum/contracts';
2
- import { CheckpointNumber } from '@aztec/foundation/branded-types';
3
- import { computeCheckpointPayloadDigest } from '@aztec/stdlib/checkpoint';
4
- /**
5
- * Builds the SimulationOverridesPlan describing the simulated L1 rollup state for a checkpoint's
6
- * enqueue-time simulations: `canProposeAt` (in Sequencer.doWork) and the propose-related sims
7
- * (validateBlockHeader, simulateProposeTx). The plan reflects "as if our pipelined parent
8
- * checkpoint has landed and any required invalidation has executed" — the gap that needs to be
9
- * bridged at enqueue time.
10
- *
11
- * Pipelining (`proposedCheckpointData`) and invalidation (`invalidateToPendingCheckpointNumber`)
12
- * are mutually exclusive; passing both throws.
13
- */ export async function buildCheckpointSimulationOverridesPlan(input) {
14
- if (input.proposedCheckpointData && input.invalidateToPendingCheckpointNumber !== undefined) {
15
- throw new Error('Error in buildCheckpointSimulationOverridesPlan: proposedCheckpointData and invalidateToPendingCheckpointNumber are mutually exclusive');
16
- }
17
- const builder = new SimulationOverridesBuilder();
18
- const pendingCheckpointNumber = derivePendingCheckpointNumber(input);
19
- // Override the latest checkpoint number when invalidating or pipelining, so our checkpoint
20
- // follows from it. We also override the proven chain tip so we dont need to worry about
21
- // prunes kicking in that would break out simulation if there's a prune pending. We always
22
- // assume that a proof will land in time. If we don't have a pending checkpoint number to force,
23
- // we still set both tips to the current checkpoint number to avoid the prune trigger.
24
- const overridenChainTip = pendingCheckpointNumber ?? input.checkpointedCheckpointNumber;
25
- builder.withChainTips({
26
- pending: overridenChainTip,
27
- proven: overridenChainTip
28
- });
29
- if (input.proposedCheckpointData) {
30
- const { header, archive, checkpointOutHash, feeAssetPriceModifier } = input.proposedCheckpointData;
31
- builder.withPendingArchive(archive.root);
32
- // Override every locally-derivable `tempCheckpointLogs[parent]` field that L1 will eventually
33
- // write. `slotNumber` is load-bearing for `STFLib.canPruneAtTime`: without it the cell reads
34
- // slotNumber 0, the contract treats the pending tip as belonging to an expired epoch, and
35
- // `getEffectivePendingCheckpointNumber` silently collapses pending back to proven — producing
36
- // a spurious `Rollup__InvalidArchive` against the on-chain genesis archive. The other fields
37
- // (headerHash, outHash, payloadDigest) are not strictly load-bearing for `canProposeAt` /
38
- // `validateBlockHeader`, but mirroring the full cell keeps the simulation byte-faithful with
39
- // what the actual `propose()` send will observe, which is a defense against future reads
40
- // taking dependencies on them.
41
- builder.withPendingTempCheckpointLogFields({
42
- headerHash: header.hash(),
43
- outHash: checkpointOutHash,
44
- slotNumber: header.slotNumber,
45
- payloadDigest: computeCheckpointPayloadDigest({
46
- header,
47
- archiveRoot: archive.root,
48
- feeAssetPriceModifier,
49
- signatureContext: input.signatureContext
50
- })
51
- });
52
- const feeHeader = await computePipelinedParentFeeHeader({
53
- checkpointNumber: input.checkpointNumber,
54
- proposedCheckpointData: input.proposedCheckpointData,
55
- rollup: input.rollup,
56
- log: input.log
57
- });
58
- if (feeHeader) {
59
- builder.withPendingFeeHeader(feeHeader);
60
- }
61
- }
62
- return builder.build();
63
- }
64
- function derivePendingCheckpointNumber(input) {
65
- if (input.invalidateToPendingCheckpointNumber !== undefined) {
66
- return input.invalidateToPendingCheckpointNumber;
67
- }
68
- if (!input.proposedCheckpointData) {
69
- return undefined;
70
- }
71
- if (input.checkpointNumber < 1) {
72
- throw new Error(`Cannot build simulation override for checkpoint ${input.checkpointNumber}: no parent exists`);
73
- }
74
- const expectedParent = CheckpointNumber(input.checkpointNumber - 1);
75
- if (input.proposedCheckpointData.checkpointNumber !== expectedParent) {
76
- throw new Error(`Cannot build simulation override for checkpoint ${input.checkpointNumber}: proposedCheckpointData.checkpointNumber (${input.proposedCheckpointData.checkpointNumber}) does not match expected parent ${expectedParent}`);
77
- }
78
- return expectedParent;
79
- }
80
- /**
81
- * Derives the pending parent fee header used during pipelined proposal simulation. Returns
82
- * `undefined` only when no grandparent exists (i.e. the proposed parent is the genesis
83
- * checkpoint); all other failure modes (missing grandparent state, missing fee header, RPC
84
- * errors) throw so callers don't silently desync the fee-header override.
85
- */ export async function computePipelinedParentFeeHeader(input) {
86
- if (input.checkpointNumber < 2) {
87
- return undefined;
88
- }
89
- const grandparentCheckpointNumber = CheckpointNumber(input.checkpointNumber - 2);
90
- const [grandparentCheckpoint, manaTarget] = await Promise.all([
91
- input.rollup.getCheckpoint(grandparentCheckpointNumber),
92
- input.rollup.getManaTarget()
93
- ]);
94
- if (!grandparentCheckpoint?.feeHeader) {
95
- throw new Error(`Grandparent checkpoint or feeHeader missing for checkpoint ${grandparentCheckpointNumber.toString()}`);
96
- }
97
- return RollupContract.computeChildFeeHeader(grandparentCheckpoint.feeHeader, input.proposedCheckpointData.totalManaUsed, input.proposedCheckpointData.feeAssetPriceModifier, manaTarget);
98
- }
@@ -1,98 +0,0 @@
1
- import type { Logger } from '@aztec/foundation/log';
2
- import type { SequencerMetrics } from './metrics.js';
3
- import { SequencerState } from './utils.js';
4
- export declare class SequencerTimetable {
5
- private readonly metrics?;
6
- private readonly log?;
7
- private readonly checkpointTiming;
8
- /**
9
- * How late into the slot can we be to start working. Computed as the total time needed for assembling and publishing a block,
10
- * assuming an execution time equal to `minExecutionTime`, subtracted from the slot duration. This means that, if the proposer
11
- * starts building at this time, and all times hold, it will have at least `minExecutionTime` to execute txs for the block.
12
- */
13
- readonly initializeDeadline: number;
14
- /**
15
- * Fixed time offset (in seconds) when the first sub-slot starts, used as baseline for all block deadlines.
16
- * This is an estimate of how long initialization (sync + proposer check) typically takes.
17
- * If actual initialization takes longer/shorter, blocks just get less/more time accordingly.
18
- */
19
- readonly initializationOffset: number;
20
- /**
21
- * Total time needed to finalize and publish a checkpoint, including:
22
- * - Assembling the checkpoint
23
- * - Round-trip p2p propagation for the checkpoint proposal and its corresponding attestations
24
- * - Publishing to L1
25
- */
26
- readonly checkpointFinalizationTime: number;
27
- /**
28
- * How long it takes to get a published block into L1. L1 builders typically accept txs up to 4 seconds into their slot,
29
- * but we'll timeout sooner to give it more time to propagate (remember we also have blobs!). Still, when working in anvil,
30
- * we can just post in the very last second of the L1 slot and still expect the tx to be accepted.
31
- */
32
- readonly l1PublishingTime: number;
33
- /**
34
- * What's the minimum time we want to leave available for execution and reexecution (used to derive init deadline)
35
- * Defaults to half of the block duration if set, otherwise a constant.
36
- */
37
- readonly minExecutionTime: number;
38
- /** How long it takes to get ready to start building */
39
- readonly checkpointInitializationTime: number;
40
- /** How long it takes to for proposals and attestations to travel across the p2p layer (one-way) */
41
- readonly p2pPropagationTime: number;
42
- /** How much time we spend assembling a checkpoint after building the last block */
43
- readonly checkpointAssembleTime: number;
44
- /** Ethereum slot duration in seconds */
45
- readonly ethereumSlotDuration: number;
46
- /** Aztec slot duration in seconds (must be multiple of ethereum slot duration) */
47
- readonly aztecSlotDuration: number;
48
- /** Whether assertTimeLeft will throw if not enough time. */
49
- readonly enforce: boolean;
50
- /** Duration per block when building multiple blocks per slot (undefined = single block per slot) */
51
- readonly blockDuration: number | undefined;
52
- /** Maximum number of blocks that can be built in this slot configuration */
53
- readonly maxNumberOfBlocks: number;
54
- /**
55
- * How far into the target slot assembly and attestation collection can start when pipelining.
56
- * Production-like timing keeps this at zero; fast local publishing profiles can use the attestation window.
57
- */
58
- readonly pipeliningAttestationGracePeriod: number;
59
- constructor(opts: {
60
- ethereumSlotDuration: number;
61
- aztecSlotDuration: number;
62
- l1PublishingTime: number;
63
- p2pPropagationTime?: number;
64
- blockDurationMs?: number;
65
- enforce: boolean;
66
- }, metrics?: SequencerMetrics | undefined, log?: Logger | undefined);
67
- getCheckpointAssemblyDeadline(): number;
68
- getCheckpointAttestationDeadline(): number;
69
- getCheckpointAttestationStartDeadline(): number;
70
- getCheckpointPublishingDeadline(): number;
71
- getMaxAllowedTime(state: Extract<SequencerState, SequencerState.STOPPED | SequencerState.IDLE | SequencerState.SYNCHRONIZING>): undefined;
72
- getMaxAllowedTime(state: Exclude<SequencerState, SequencerState.STOPPED | SequencerState.IDLE | SequencerState.SYNCHRONIZING>): number;
73
- getMaxAllowedTime(state: SequencerState): number | undefined;
74
- assertTimeLeft(newState: SequencerState, secondsIntoSlot: number): void;
75
- /**
76
- * Determines if we can start building the next block and returns its deadline.
77
- *
78
- * The timetable divides the slot into fixed sub-slots. This method finds the next
79
- * available sub-slot that has enough time remaining to build a block.
80
- *
81
- * @param secondsIntoSlot - Current time (seconds into the slot)
82
- * @returns Object with canStart flag, deadline, and whether this is the last block
83
- */
84
- canStartNextBlock(secondsIntoSlot: number): {
85
- canStart: true;
86
- deadline: undefined;
87
- isLastBlock: true;
88
- } | {
89
- canStart: false;
90
- deadline: undefined;
91
- isLastBlock: false;
92
- } | {
93
- canStart: boolean;
94
- deadline: number;
95
- isLastBlock: boolean;
96
- };
97
- }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AEM,qCAAqC,IAAI,MAAM,CAErD;IAEM,+BAA+B,IAAI,MAAM,CAE/C;IAEM,iBAAiB,CACtB,KAAK,EAAE,OAAO,CAAC,cAAc,EAAE,cAAc,CAAC,OAAO,GAAG,cAAc,CAAC,IAAI,GAAG,cAAc,CAAC,aAAa,CAAC,GAC1G,SAAS,CAAC;IACN,iBAAiB,CACtB,KAAK,EAAE,OAAO,CAAC,cAAc,EAAE,cAAc,CAAC,OAAO,GAAG,cAAc,CAAC,IAAI,GAAG,cAAc,CAAC,aAAa,CAAC,GAC1G,MAAM,CAAC;IACH,iBAAiB,CAAC,KAAK,EAAE,cAAc,GAAG,MAAM,GAAG,SAAS,CAAC;IA4B7D,cAAc,CAAC,QAAQ,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,QAiBtE;IAED;;;;;;;;OAQG;IACI,iBAAiB,CACtB,eAAe,EAAE,MAAM,GAErB;QAAE,QAAQ,EAAE,IAAI,CAAC;QAAC,QAAQ,EAAE,SAAS,CAAC;QAAC,WAAW,EAAE,IAAI,CAAA;KAAE,GAC1D;QAAE,QAAQ,EAAE,KAAK,CAAC;QAAC,QAAQ,EAAE,SAAS,CAAC;QAAC,WAAW,EAAE,KAAK,CAAA;KAAE,GAC5D;QAAE,QAAQ,EAAE,OAAO,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,OAAO,CAAA;KAAE,CAwDhE;CACF"}
@@ -1,227 +0,0 @@
1
- import { CHECKPOINT_ASSEMBLE_TIME, CHECKPOINT_INITIALIZATION_TIME, DEFAULT_P2P_PROPAGATION_TIME, MIN_EXECUTION_TIME, createCheckpointTimingModel } from '@aztec/stdlib/timetable';
2
- import { SequencerTooSlowError } from './errors.js';
3
- import { SequencerState } from './utils.js';
4
- export class SequencerTimetable {
5
- metrics;
6
- log;
7
- checkpointTiming;
8
- /**
9
- * How late into the slot can we be to start working. Computed as the total time needed for assembling and publishing a block,
10
- * assuming an execution time equal to `minExecutionTime`, subtracted from the slot duration. This means that, if the proposer
11
- * starts building at this time, and all times hold, it will have at least `minExecutionTime` to execute txs for the block.
12
- */ initializeDeadline;
13
- /**
14
- * Fixed time offset (in seconds) when the first sub-slot starts, used as baseline for all block deadlines.
15
- * This is an estimate of how long initialization (sync + proposer check) typically takes.
16
- * If actual initialization takes longer/shorter, blocks just get less/more time accordingly.
17
- */ initializationOffset;
18
- /**
19
- * Total time needed to finalize and publish a checkpoint, including:
20
- * - Assembling the checkpoint
21
- * - Round-trip p2p propagation for the checkpoint proposal and its corresponding attestations
22
- * - Publishing to L1
23
- */ checkpointFinalizationTime;
24
- /**
25
- * How long it takes to get a published block into L1. L1 builders typically accept txs up to 4 seconds into their slot,
26
- * but we'll timeout sooner to give it more time to propagate (remember we also have blobs!). Still, when working in anvil,
27
- * we can just post in the very last second of the L1 slot and still expect the tx to be accepted.
28
- */ l1PublishingTime;
29
- /**
30
- * What's the minimum time we want to leave available for execution and reexecution (used to derive init deadline)
31
- * Defaults to half of the block duration if set, otherwise a constant.
32
- */ minExecutionTime;
33
- /** How long it takes to get ready to start building */ checkpointInitializationTime;
34
- /** How long it takes to for proposals and attestations to travel across the p2p layer (one-way) */ p2pPropagationTime;
35
- /** How much time we spend assembling a checkpoint after building the last block */ checkpointAssembleTime;
36
- /** Ethereum slot duration in seconds */ ethereumSlotDuration;
37
- /** Aztec slot duration in seconds (must be multiple of ethereum slot duration) */ aztecSlotDuration;
38
- /** Whether assertTimeLeft will throw if not enough time. */ enforce;
39
- /** Duration per block when building multiple blocks per slot (undefined = single block per slot) */ blockDuration;
40
- /** Maximum number of blocks that can be built in this slot configuration */ maxNumberOfBlocks;
41
- /**
42
- * How far into the target slot assembly and attestation collection can start when pipelining.
43
- * Production-like timing keeps this at zero; fast local publishing profiles can use the attestation window.
44
- */ pipeliningAttestationGracePeriod;
45
- constructor(opts, metrics, log){
46
- this.metrics = metrics;
47
- this.log = log;
48
- this.minExecutionTime = MIN_EXECUTION_TIME;
49
- this.checkpointInitializationTime = CHECKPOINT_INITIALIZATION_TIME;
50
- this.checkpointAssembleTime = CHECKPOINT_ASSEMBLE_TIME;
51
- this.ethereumSlotDuration = opts.ethereumSlotDuration;
52
- this.aztecSlotDuration = opts.aztecSlotDuration;
53
- this.l1PublishingTime = opts.l1PublishingTime;
54
- this.blockDuration = opts.blockDurationMs ? opts.blockDurationMs / 1000 : undefined;
55
- this.enforce = opts.enforce;
56
- this.checkpointTiming = createCheckpointTimingModel({
57
- aztecSlotDuration: this.aztecSlotDuration,
58
- ethereumSlotDuration: this.ethereumSlotDuration,
59
- blockDuration: this.blockDuration,
60
- l1PublishingTime: this.l1PublishingTime,
61
- p2pPropagationTime: opts.p2pPropagationTime ?? DEFAULT_P2P_PROPAGATION_TIME
62
- });
63
- this.p2pPropagationTime = this.checkpointTiming.p2pPropagationTime;
64
- this.checkpointAssembleTime = this.checkpointTiming.checkpointAssembleTime;
65
- this.checkpointInitializationTime = this.checkpointTiming.checkpointInitializationTime;
66
- this.minExecutionTime = this.checkpointTiming.minExecutionTime;
67
- // Calculate initialization offset - estimate of time needed for sync + proposer check
68
- // This is the baseline for all sub-slot deadlines
69
- this.initializationOffset = this.checkpointTiming.checkpointInitializationTime;
70
- this.checkpointFinalizationTime = this.checkpointTiming.checkpointFinalizationTime;
71
- this.pipeliningAttestationGracePeriod = this.checkpointTiming.pipeliningAttestationGracePeriod;
72
- this.maxNumberOfBlocks = this.checkpointTiming.calculateMaxBlocksPerSlot();
73
- this.initializeDeadline = this.checkpointTiming.initializeDeadline;
74
- this.log?.info(`Sequencer timetable initialized with ${this.maxNumberOfBlocks} blocks per slot (${this.enforce ? 'enforced' : 'not enforced'})`, {
75
- ethereumSlotDuration: this.ethereumSlotDuration,
76
- aztecSlotDuration: this.aztecSlotDuration,
77
- l1PublishingTime: this.l1PublishingTime,
78
- minExecutionTime: this.minExecutionTime,
79
- blockPrepareTime: this.checkpointInitializationTime,
80
- p2pPropagationTime: this.p2pPropagationTime,
81
- blockAssembleTime: this.checkpointAssembleTime,
82
- initializeDeadline: this.initializeDeadline,
83
- enforce: this.enforce,
84
- pipeliningAttestationGracePeriod: this.pipeliningAttestationGracePeriod,
85
- minWorkToDo: this.checkpointTiming.minimumBuildSlotWork,
86
- blockDuration: this.blockDuration,
87
- maxNumberOfBlocks: this.maxNumberOfBlocks
88
- });
89
- if (this.initializeDeadline <= 0) {
90
- throw new Error(`Block proposal initialize deadline cannot be negative (got ${this.initializeDeadline} from total time needed ${this.checkpointTiming.minimumBuildSlotWork} and a slot duration of ${this.aztecSlotDuration}).`);
91
- }
92
- }
93
- getCheckpointAssemblyDeadline() {
94
- return this.checkpointTiming.checkpointAssemblyDeadline;
95
- }
96
- getCheckpointAttestationDeadline() {
97
- return this.checkpointTiming.checkpointAttestationDeadline;
98
- }
99
- getCheckpointAttestationStartDeadline() {
100
- return this.checkpointTiming.checkpointAttestationStartDeadline;
101
- }
102
- getCheckpointPublishingDeadline() {
103
- return this.checkpointTiming.checkpointPublishingDeadline;
104
- }
105
- getMaxAllowedTime(state) {
106
- switch(state){
107
- case SequencerState.STOPPED:
108
- case SequencerState.STOPPING:
109
- case SequencerState.IDLE:
110
- case SequencerState.SYNCHRONIZING:
111
- return; // We don't really care about times for this states
112
- case SequencerState.PROPOSER_CHECK:
113
- case SequencerState.INITIALIZING_CHECKPOINT:
114
- return this.initializeDeadline;
115
- case SequencerState.WAITING_FOR_TXS:
116
- case SequencerState.CREATING_BLOCK:
117
- case SequencerState.WAITING_UNTIL_NEXT_BLOCK:
118
- return this.initializeDeadline + this.checkpointInitializationTime;
119
- case SequencerState.ASSEMBLING_CHECKPOINT:
120
- return this.getCheckpointAssemblyDeadline();
121
- case SequencerState.COLLECTING_ATTESTATIONS:
122
- return this.getCheckpointAttestationStartDeadline();
123
- case SequencerState.PUBLISHING_CHECKPOINT:
124
- return this.getCheckpointPublishingDeadline();
125
- default:
126
- {
127
- const _exhaustiveCheck = state;
128
- throw new Error(`Unexpected state: ${state}`);
129
- }
130
- }
131
- }
132
- assertTimeLeft(newState, secondsIntoSlot) {
133
- if (!this.enforce) {
134
- return;
135
- }
136
- const maxAllowedTime = this.getMaxAllowedTime(newState);
137
- if (maxAllowedTime === undefined) {
138
- return;
139
- }
140
- const bufferSeconds = maxAllowedTime - secondsIntoSlot;
141
- if (bufferSeconds < 0) {
142
- throw new SequencerTooSlowError(newState, maxAllowedTime, secondsIntoSlot);
143
- }
144
- this.metrics?.recordStateTransitionBufferMs(Math.floor(bufferSeconds * 1000), newState);
145
- this.log?.trace(`Enough time to transition to ${newState}`, {
146
- maxAllowedTime,
147
- secondsIntoSlot
148
- });
149
- }
150
- /**
151
- * Determines if we can start building the next block and returns its deadline.
152
- *
153
- * The timetable divides the slot into fixed sub-slots. This method finds the next
154
- * available sub-slot that has enough time remaining to build a block.
155
- *
156
- * @param secondsIntoSlot - Current time (seconds into the slot)
157
- * @returns Object with canStart flag, deadline, and whether this is the last block
158
- */ canStartNextBlock(secondsIntoSlot) {
159
- // When timetable enforcement is disabled, always allow starting,
160
- // and build a single block with no deadline. This is here just to
161
- // satisfy a subset of e2e tests and the sandbox that assume that the
162
- // sequencer is permanently mining every tx sent.
163
- if (!this.enforce) {
164
- return {
165
- canStart: true,
166
- deadline: undefined,
167
- isLastBlock: true
168
- };
169
- }
170
- // If no block duration is set, then we're in single-block mode, which
171
- // is handled for backwards compatibility towards another subset of e2e tests.
172
- if (this.blockDuration === undefined) {
173
- // In single block mode, execution and re-execution happen sequentially, so we need to
174
- // split the available time between them. After building, we need time for attestations and L1.
175
- const maxAllowed = this.aztecSlotDuration - this.checkpointFinalizationTime;
176
- const available = (maxAllowed - secondsIntoSlot) / 2; // Split remaining time: half for execution, half for re-execution
177
- const canStart = available >= this.minExecutionTime;
178
- const deadline = secondsIntoSlot + available;
179
- this.log?.verbose(`${canStart ? 'Can' : 'Cannot'} start single-block checkpoint at ${secondsIntoSlot}s into slot`, {
180
- secondsIntoSlot,
181
- maxAllowed,
182
- available,
183
- deadline
184
- });
185
- return {
186
- canStart,
187
- deadline,
188
- isLastBlock: true
189
- };
190
- }
191
- // Otherwise, we're in multi-block-per-slot mode, the default when running in production
192
- // Find the next available sub-slot that has enough time remaining
193
- for(let subSlot = 1; subSlot <= this.maxNumberOfBlocks; subSlot++){
194
- // Calculate end for this sub-slot
195
- const deadline = this.initializationOffset + subSlot * this.blockDuration;
196
- // Check if we have enough time to build a block with this deadline
197
- const timeUntilDeadline = deadline - secondsIntoSlot;
198
- if (timeUntilDeadline >= this.minExecutionTime) {
199
- // Found an available sub-slot! Is this the last one?
200
- const isLastBlock = subSlot === this.maxNumberOfBlocks;
201
- this.log?.verbose(`Can start ${isLastBlock ? 'last block' : 'block'} in sub-slot ${subSlot} with deadline ${deadline}s`, {
202
- secondsIntoSlot,
203
- deadline,
204
- timeUntilDeadline,
205
- subSlot,
206
- maxBlocks: this.maxNumberOfBlocks
207
- });
208
- return {
209
- canStart: true,
210
- deadline,
211
- isLastBlock
212
- };
213
- }
214
- }
215
- // No sub-slots available with enough time
216
- this.log?.verbose(`No time left to start any more blocks`, {
217
- secondsIntoSlot,
218
- maxBlocks: this.maxNumberOfBlocks,
219
- initializationOffset: this.initializationOffset
220
- });
221
- return {
222
- canStart: false,
223
- deadline: undefined,
224
- isLastBlock: false
225
- };
226
- }
227
- }