@aztec-labs/sequencer-client 6.0.0-rc.2 → 6.0.0-rc.4

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
@@ -437,8 +437,8 @@ function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
437
437
  }
438
438
  var _dec, _dec1, _dec2, _dec3, _initProto;
439
439
  import { getKzg } from '@aztec-labs/blob-lib';
440
- import { PROPOSER_PIPELINING_SLOT_OFFSET } from '@aztec-labs/epoch-cache';
441
- import { NoCommitteeError } from '@aztec-labs/ethereum/contracts';
440
+ import { PROPOSER_PIPELINING_SLOT_OFFSET, requireStableCommittee } from '@aztec-labs/epoch-cache';
441
+ import { NoAffordablePublisherError } from '@aztec-labs/ethereum/publisher-manager';
442
442
  import { CheckpointNumber, SlotNumber } from '@aztec-labs/foundation/branded-types';
443
443
  import { merge, omit, pick } from '@aztec-labs/foundation/collection';
444
444
  import { EthAddress } from '@aztec-labs/foundation/eth-address';
@@ -455,6 +455,7 @@ import { buildProposerTimetable } from '@aztec-labs/stdlib/timetable';
455
455
  import { Attributes, getTelemetryClient, trackSpan } from '@aztec-labs/telemetry-client';
456
456
  import EventEmitter from 'node:events';
457
457
  import { DefaultSequencerConfig } from '../config.js';
458
+ import { INVALIDATE_REQUIREMENT, getProposeRequirement } from '../publisher/gas_constants.js';
458
459
  import { CheckpointProposalJob } from './checkpoint_proposal_job.js';
459
460
  import { CheckpointProposalJobMetrics } from './checkpoint_proposal_job_metrics.js';
460
461
  import { CheckpointVoter } from './checkpoint_voter.js';
@@ -529,6 +530,7 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
529
530
  /** The (checkpoint, slot) of the last invalidation request we successfully simulated, to prevent
530
531
  * re-simulating and re-submitting the same invalidation across the many ticks within a single slot. */ lastInvalidationAttempt;
531
532
  /** The last epoch for which we logged a "no committee" diagnostic, to avoid per-slot log spam. */ lastEpochForNoCommitteeLog;
533
+ /** The last target slot for which we logged that its committee is not stable on L1 yet, to avoid per-tick log spam. */ lastSlotForCommitteeNotStableLog;
532
534
  /** The last slot for which we triggered a checkpoint proposal job, to prevent duplicate attempts. */ lastSlotForCheckpointProposalJob;
533
535
  /** Last successful checkpoint proposed */ lastCheckpointProposed;
534
536
  /** The last epoch for which we logged strategy comparison in fisherman mode. */ lastEpochForStrategyComparison;
@@ -828,6 +830,20 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
828
830
  };
829
831
  }
830
832
  /**
833
+ * Whether the epoch's committee is already stored on L1, so a proposal in it does not also run setupEpoch. Reads the
834
+ * latest mined L1 state; returns false if the read fails, so the proposal is costed for the more expensive case.
835
+ */ async isEpochSetUpOnL1(epoch) {
836
+ try {
837
+ return await this.rollupContract.isEpochSetUp(epoch);
838
+ } catch (err) {
839
+ this.log.warn(`Failed to read whether epoch ${epoch} is set up on L1, assuming it is not`, {
840
+ epoch,
841
+ err
842
+ });
843
+ return false;
844
+ }
845
+ }
846
+ /**
831
847
  * Prepares the checkpoint proposal by performing all necessary checks and setup.
832
848
  * This is the initial step in the main loop.
833
849
  * @returns CheckpointProposalJob if successful, undefined if we are not yet synced or are not the proposer.
@@ -860,11 +876,16 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
860
876
  // expensive multi-subsystem checkSync (and the rest of the build path) behind it. Computed once
861
877
  // here and reused for the escape-hatch voting path below. No setState/timing gate on this path:
862
878
  // the build-start deadline gate runs only on the proposer build path, before checkSync.
863
- const [canPropose, proposer] = await this.checkCanPropose(targetSlot);
879
+ const proposerCheck = await this.checkCanPropose(targetSlot);
880
+ if (proposerCheck === undefined) {
881
+ return undefined;
882
+ }
883
+ const [canPropose, proposer] = proposerCheck;
864
884
  // If escape hatch is open for the target epoch, do not start checkpoint proposal work and do not attempt invalidations.
865
885
  // Still perform governance/slashing voting (as proposer) once per slot.
866
886
  // When pipelining, we check the target epoch (slot+1's epoch) since that's the epoch we're building for.
867
- const isEscapeHatchOpen = await this.epochCache.isEscapeHatchOpen(targetEpoch);
887
+ // checkCanPropose has already skipped the slot if its committee is not stable.
888
+ const { isEscapeHatchOpen } = requireStableCommittee(await this.epochCache.lookupEscapeHatch(targetEpoch));
868
889
  if (isEscapeHatchOpen) {
869
890
  if (canPropose) {
870
891
  await this.tryVoteWhenEscapeHatchOpen({
@@ -990,7 +1011,37 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
990
1011
  // Otherwise it will be a valid attestor for the returned publisher.
991
1012
  // In fisherman mode, pass undefined to use the fisherman's own keystore instead of the actual proposer's
992
1013
  const proposerForPublisher = this.config.fishermanMode ? undefined : proposer;
993
- const { attestorAddress, publisher } = await this.publisherFactory.create(proposerForPublisher);
1014
+ // Only a publisher that can afford the proposal (plus the invalidation bundled with it, see below) is eligible, so
1015
+ // we skip the slot here rather than build and gossip a checkpoint that can never land. Fisherman nodes never send.
1016
+ const needsInvalidation = !syncedTo.hasProposedCheckpoint && !syncedTo.pendingChainValidationStatus.valid;
1017
+ const requirement = this.config.fishermanMode ? undefined : getProposeRequirement({
1018
+ withInvalidate: needsInvalidation,
1019
+ withSetupEpoch: !await this.isEpochSetUpOnL1(targetEpoch)
1020
+ });
1021
+ let created;
1022
+ try {
1023
+ created = await this.publisherFactory.create(proposerForPublisher, {
1024
+ requirement
1025
+ });
1026
+ } catch (err) {
1027
+ if (!(err instanceof NoAffordablePublisherError)) {
1028
+ throw err;
1029
+ }
1030
+ this.log.error(`Skipping checkpoint proposal for slot ${targetSlot}: no publisher can afford it, ${err.describeFunding()}`, err, {
1031
+ ...logCtx,
1032
+ proposer,
1033
+ ...err.toLogContext()
1034
+ });
1035
+ this.metrics.recordCheckpointPrecheckFailed('insufficient_publisher_balance');
1036
+ // Mark the slot as attempted so we do not re-check on every tick. Votes are cheaper and optional, so still try.
1037
+ await this.tryVoteAndPruneWhenCannotBuild({
1038
+ slot,
1039
+ targetSlot
1040
+ });
1041
+ this.lastSlotForCheckpointProposalJob = targetSlot;
1042
+ return undefined;
1043
+ }
1044
+ const { attestorAddress, publisher } = created;
994
1045
  const cleanup = _ts_add_disposable_resource(env, new DisposableStack(), false);
995
1046
  cleanup.use(publisher);
996
1047
  this.log.verbose(`Created publisher at address ${publisher.getSenderAddress()} for attestor ${attestorAddress}`);
@@ -1294,43 +1345,58 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
1294
1345
  }
1295
1346
  /**
1296
1347
  * Checks if we are the proposer for the next slot.
1297
- * @returns True if we can propose, and the proposer address (undefined if anyone can propose)
1348
+ * @returns True if we can propose, and the proposer address (undefined if anyone can propose). Undefined if the
1349
+ * target slot's committee is not stable on L1 yet, in which case the slot must be skipped altogether.
1298
1350
  */ async checkCanPropose(targetSlot) {
1299
- let proposer;
1351
+ let lookup;
1300
1352
  try {
1301
- proposer = await this.epochCache.getProposerAttesterAddressInSlot(targetSlot);
1353
+ lookup = await this.epochCache.lookupProposer(targetSlot);
1302
1354
  } catch (e) {
1303
- if (e instanceof NoCommitteeError) {
1304
- const targetEpoch = getEpochAtSlot(targetSlot, this.l1Constants);
1305
- if (this.lastEpochForNoCommitteeLog !== targetEpoch) {
1306
- this.lastEpochForNoCommitteeLog = targetEpoch;
1307
- await logMissingCommittee(targetSlot, targetEpoch, {
1308
- epochCache: this.epochCache,
1309
- rollupContract: this.rollupContract,
1310
- l2BlockSource: this.l2BlockSource,
1311
- l1Constants: this.l1Constants,
1312
- dateProvider: this.dateProvider,
1313
- logger: this.log
1314
- });
1315
- }
1316
- return [
1317
- false,
1318
- undefined
1319
- ];
1320
- }
1321
1355
  this.log.error(`Error getting proposer for target slot ${targetSlot}`, e);
1322
1356
  return [
1323
1357
  false,
1324
1358
  undefined
1325
1359
  ];
1326
1360
  }
1327
- // If proposer is undefined, then the committee is empty and anyone may propose
1328
- if (proposer === undefined) {
1329
- return [
1330
- true,
1331
- undefined
1332
- ];
1361
+ switch(lookup.state){
1362
+ case 'unstable':
1363
+ if (this.lastSlotForCommitteeNotStableLog !== targetSlot) {
1364
+ this.lastSlotForCommitteeNotStableLog = targetSlot;
1365
+ this.log.verbose(`Skipping target slot ${targetSlot}: its committee is not stable on L1 yet`, {
1366
+ targetSlot,
1367
+ epoch: lookup.epoch,
1368
+ l1BlockNumber: lookup.l1BlockNumber
1369
+ });
1370
+ }
1371
+ return undefined;
1372
+ case 'none':
1373
+ {
1374
+ const targetEpoch = getEpochAtSlot(targetSlot, this.l1Constants);
1375
+ if (this.lastEpochForNoCommitteeLog !== targetEpoch) {
1376
+ this.lastEpochForNoCommitteeLog = targetEpoch;
1377
+ await logMissingCommittee(targetSlot, targetEpoch, {
1378
+ epochCache: this.epochCache,
1379
+ rollupContract: this.rollupContract,
1380
+ l2BlockSource: this.l2BlockSource,
1381
+ l1Constants: this.l1Constants,
1382
+ dateProvider: this.dateProvider,
1383
+ logger: this.log
1384
+ });
1385
+ }
1386
+ return [
1387
+ false,
1388
+ undefined
1389
+ ];
1390
+ }
1391
+ case 'open':
1392
+ return [
1393
+ true,
1394
+ undefined
1395
+ ];
1396
+ case 'members':
1397
+ break;
1333
1398
  }
1399
+ const { proposer } = lookup;
1334
1400
  // In fisherman mode, just return the current proposer
1335
1401
  if (this.config.fishermanMode) {
1336
1402
  return [
@@ -1387,14 +1453,15 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
1387
1453
  startDeadline
1388
1454
  });
1389
1455
  // Check if we're a proposer or proposal is open
1390
- const [canPropose, proposer] = await this.checkCanPropose(targetSlot);
1391
- if (!canPropose) {
1456
+ const proposerCheck = await this.checkCanPropose(targetSlot);
1457
+ if (!proposerCheck?.[0]) {
1392
1458
  this.log.trace(`Cannot vote in slot ${slot} since we are not a proposer`, {
1393
1459
  slot,
1394
- proposer
1460
+ proposer: proposerCheck?.[1]
1395
1461
  });
1396
1462
  return;
1397
1463
  }
1464
+ const [, proposer] = proposerCheck;
1398
1465
  // Mark this slot as attempted
1399
1466
  this.lastSlotForFallbackAction = slot;
1400
1467
  // Get a publisher for voting
@@ -1555,7 +1622,13 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
1555
1622
  ourValidatorAddresses,
1556
1623
  currentSlot
1557
1624
  };
1558
- const inCurrentCommittee = ()=>this.epochCache.getCommittee(currentSlot).then((c)=>c?.committee?.some((member)=>ourValidatorAddresses.some((addr)=>addr.equals(member))));
1625
+ // Only a committee with members can include us. A committee that is not stable on L1 yet cannot tell whether we
1626
+ // are in it, so treat that as not being in it.
1627
+ const getCurrentCommittee = async ()=>{
1628
+ const lookup = await this.epochCache.getCommittee(currentSlot);
1629
+ return lookup.state === 'members' ? lookup.committee : undefined;
1630
+ };
1631
+ const inCurrentCommittee = async ()=>(await getCurrentCommittee())?.some((member)=>ourValidatorAddresses.some((addr)=>addr.equals(member)));
1559
1632
  const invalidateAsCommitteeMember = secondsBeforeInvalidatingBlockAsCommitteeMember !== undefined && secondsBeforeInvalidatingBlockAsCommitteeMember > 0 && timeSinceChainInvalid > secondsBeforeInvalidatingBlockAsCommitteeMember && await inCurrentCommittee();
1560
1633
  const invalidateAsNonCommitteeMember = secondsBeforeInvalidatingBlockAsNonCommitteeMember !== undefined && secondsBeforeInvalidatingBlockAsNonCommitteeMember > 0 && timeSinceChainInvalid > secondsBeforeInvalidatingBlockAsNonCommitteeMember;
1561
1634
  if (!invalidateAsCommitteeMember && !invalidateAsNonCommitteeMember) {
@@ -1565,7 +1638,7 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
1565
1638
  let validatorToUse;
1566
1639
  if (invalidateAsCommitteeMember) {
1567
1640
  // When invalidating as a committee member, use first validator that's actually in the committee
1568
- const { committee } = await this.epochCache.getCommittee(currentSlot);
1641
+ const committee = await getCurrentCommittee();
1569
1642
  if (committee) {
1570
1643
  const committeeSet = new Set(committee.map((addr)=>addr.toString()));
1571
1644
  validatorToUse = ourValidatorAddresses.find((addr)=>committeeSet.has(addr.toString())) ?? ourValidatorAddresses[0];
@@ -1576,7 +1649,25 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
1576
1649
  // When invalidating as a non-committee member, use the first validator
1577
1650
  validatorToUse = ourValidatorAddresses[0];
1578
1651
  }
1579
- const { publisher: createdPublisher } = await this.publisherFactory.create(validatorToUse);
1652
+ let createdPublisher;
1653
+ try {
1654
+ ({ publisher: createdPublisher } = await this.publisherFactory.create(validatorToUse, {
1655
+ requirement: this.config.fishermanMode ? undefined : INVALIDATE_REQUIREMENT
1656
+ }));
1657
+ } catch (err) {
1658
+ if (!(err instanceof NoAffordablePublisherError)) {
1659
+ throw err;
1660
+ }
1661
+ this.log.error(`Not invalidating checkpoint ${invalidCheckpointNumber} since no publisher can afford it`, err, {
1662
+ ...logData,
1663
+ ...err.toLogContext()
1664
+ });
1665
+ this.lastInvalidationAttempt = {
1666
+ slot: currentSlot,
1667
+ checkpointNumber: invalidCheckpointNumber
1668
+ };
1669
+ return;
1670
+ }
1580
1671
  const publisher = _ts_add_disposable_resource(env, createdPublisher, false);
1581
1672
  const invalidateCheckpoint = await publisher.simulateInvalidateCheckpoint(pendingChainValidationStatus);
1582
1673
  if (!invalidateCheckpoint) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec-labs/sequencer-client",
3
- "version": "6.0.0-rc.2",
3
+ "version": "6.0.0-rc.4",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./dest/index.js",
@@ -27,32 +27,32 @@
27
27
  "test:integration:run": "NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --no-cache --config jest.integration.config.json"
28
28
  },
29
29
  "dependencies": {
30
- "@aztec-foundation/l1-artifacts": "6.0.0-rc.5",
31
- "@aztec-labs/archiver": "6.0.0-rc.2",
32
- "@aztec-labs/blob-client": "6.0.0-rc.2",
33
- "@aztec-labs/blob-lib": "6.0.0-rc.2",
34
- "@aztec-labs/constants": "6.0.0-rc.2",
35
- "@aztec-labs/epoch-cache": "6.0.0-rc.2",
36
- "@aztec-labs/ethereum": "6.0.0-rc.2",
37
- "@aztec-labs/foundation": "6.0.0-rc.2",
38
- "@aztec-labs/node-keystore": "6.0.0-rc.2",
39
- "@aztec-labs/p2p": "6.0.0-rc.2",
40
- "@aztec-labs/prover-client": "6.0.0-rc.2",
41
- "@aztec-labs/simulator": "6.0.0-rc.2",
42
- "@aztec-labs/slasher": "6.0.0-rc.2",
43
- "@aztec-labs/stdlib": "6.0.0-rc.2",
44
- "@aztec-labs/telemetry-client": "6.0.0-rc.2",
45
- "@aztec-labs/validator-client": "6.0.0-rc.2",
46
- "@aztec-labs/validator-ha-signer": "6.0.0-rc.2",
30
+ "@aztec-foundation/l1-artifacts": "6.0.0-rc.7",
31
+ "@aztec-labs/archiver": "6.0.0-rc.4",
32
+ "@aztec-labs/blob-client": "6.0.0-rc.4",
33
+ "@aztec-labs/blob-lib": "6.0.0-rc.4",
34
+ "@aztec-labs/constants": "6.0.0-rc.4",
35
+ "@aztec-labs/epoch-cache": "6.0.0-rc.4",
36
+ "@aztec-labs/ethereum": "6.0.0-rc.4",
37
+ "@aztec-labs/foundation": "6.0.0-rc.4",
38
+ "@aztec-labs/node-keystore": "6.0.0-rc.4",
39
+ "@aztec-labs/p2p": "6.0.0-rc.4",
40
+ "@aztec-labs/prover-client": "6.0.0-rc.4",
41
+ "@aztec-labs/simulator": "6.0.0-rc.4",
42
+ "@aztec-labs/slasher": "6.0.0-rc.4",
43
+ "@aztec-labs/stdlib": "6.0.0-rc.4",
44
+ "@aztec-labs/telemetry-client": "6.0.0-rc.4",
45
+ "@aztec-labs/validator-client": "6.0.0-rc.4",
46
+ "@aztec-labs/validator-ha-signer": "6.0.0-rc.4",
47
47
  "lodash.chunk": "^4.2.0",
48
48
  "tslib": "^2.4.0",
49
- "viem": "npm:@aztec/viem@2.38.3",
49
+ "viem": "2.57.1",
50
50
  "zod": "~4.4.3"
51
51
  },
52
52
  "devDependencies": {
53
- "@aztec-labs/noir-protocol-circuits-types": "6.0.0-rc.2",
54
- "@aztec-labs/protocol-contracts": "6.0.0-rc.2",
55
- "@aztec-labs/world-state": "6.0.0-rc.2",
53
+ "@aztec-labs/noir-protocol-circuits-types": "6.0.0-rc.4",
54
+ "@aztec-labs/protocol-contracts": "6.0.0-rc.4",
55
+ "@aztec-labs/world-state": "6.0.0-rc.4",
56
56
  "@electric-sql/pglite": "^0.3.14",
57
57
  "@jest/globals": "^30.0.0",
58
58
  "@types/jest": "^30.0.0",
@@ -76,7 +76,7 @@
76
76
  ],
77
77
  "types": "./dest/index.d.ts",
78
78
  "engines": {
79
- "node": ">=20.10"
79
+ "node": ">=20.16"
80
80
  },
81
81
  "jest": {
82
82
  "extensionsToTreatAsEsm": [
@@ -19,6 +19,8 @@ import { FullNodeCheckpointsBuilder, NodeKeystoreAdapter, type ValidatorClient }
19
19
 
20
20
  import { type SequencerClientConfig, getPublisherConfigFromSequencerConfig } from '../config.js';
21
21
  import type { GlobalVariableBuilder } from '../global_variable_builder/index.js';
22
+ import { PROPOSE_REFERENCE_SEND } from '../publisher/gas_constants.js';
23
+ import { PublisherManagerMetrics } from '../publisher/publisher-manager-metrics.js';
22
24
  import { SequencerPublisherFactory } from '../publisher/sequencer-publisher-factory.js';
23
25
  import type { CheckpointProposalJobTestHooks } from '../sequencer/checkpoint_proposal_job_test_hooks.js';
24
26
  import { Sequencer, type SequencerConfig } from '../sequencer/index.js';
@@ -91,12 +93,15 @@ export class SequencerClient {
91
93
  const l1Metrics = new L1Metrics(
92
94
  telemetryClient.getMeter('L1PublisherMetrics'),
93
95
  publicClient,
94
- l1TxUtils.map(x => x.getSenderAddress()),
96
+ l1TxUtils.length,
95
97
  'sequencer',
96
98
  );
97
99
  const publisherManager = new PublisherManager(l1TxUtils, getPublisherConfigFromSequencerConfig(config), {
98
100
  bindings: log.getBindings(),
99
101
  funder: deps.funderL1TxUtils,
102
+ metrics: new PublisherManagerMetrics(telemetryClient, 'sequencer'),
103
+ // Fisherman nodes never send proposals, so their publishers are not expected to afford one.
104
+ referenceSend: config.fishermanMode ? undefined : PROPOSE_REFERENCE_SEND,
100
105
  });
101
106
  const rollupContract = new RollupContract(publicClient, config.rollupAddress.toString());
102
107
  const inboxContract = new InboxContract(publicClient, config.inboxAddress);
package/src/config.ts CHANGED
@@ -63,6 +63,7 @@ export const DefaultSequencerConfig = {
63
63
  injectHighSValueAttestation: false,
64
64
  injectUnrecoverableSignatureAttestation: false,
65
65
  injectYParityAttestation: false,
66
+ republishAfterFakeAttestation: false,
66
67
  fishermanMode: false,
67
68
  governanceProposerForcePayloadVote: false,
68
69
  shuffleAttestationOrdering: false,
@@ -239,6 +240,12 @@ export const sequencerConfigMappings: ConfigMappingsType<SequencerConfig> = {
239
240
  description: 'Inject a non-proposer attestation slot in yParity form in the packed L1 tuple (for testing only)',
240
241
  ...booleanConfigHelper(DefaultSequencerConfig.injectYParityAttestation),
241
242
  },
243
+ republishAfterFakeAttestation: {
244
+ description:
245
+ 'Publish the checkpoint with a fake attestation first, then invalidate it and publish it again with the ' +
246
+ 'collected attestations within the same slot (for testing only)',
247
+ ...booleanConfigHelper(DefaultSequencerConfig.republishAfterFakeAttestation),
248
+ },
242
249
  fishermanMode: {
243
250
  env: 'FISHERMAN_MODE',
244
251
  description:
package/src/index.ts CHANGED
@@ -17,9 +17,6 @@ export {
17
17
  PROTOCOL_INBOX_CONSUMPTION_CAPS,
18
18
  type StreamingMessageSource,
19
19
  getEndpointUpperBound,
20
- getOrdinaryCeiling,
21
- mustQueryEndpoint,
22
20
  resolveEndpoint,
23
- selectOrdinaryMessageEnd,
24
21
  selectSafeLocalEnd,
25
22
  } from './sequencer/inbox_message_selection.js';
@@ -5,6 +5,7 @@ import {
5
5
  type ConfigMappingsType,
6
6
  SecretValue,
7
7
  booleanConfigHelper,
8
+ floatConfigHelper,
8
9
  numberConfigHelper,
9
10
  } from '@aztec-labs/foundation/config';
10
11
  import { EthAddress } from '@aztec-labs/foundation/eth-address';
@@ -52,17 +53,17 @@ export type PublisherConfig = L1TxUtilsConfig &
52
53
  publisherAllowInvalidStates?: boolean;
53
54
  /** Whether to run in fisherman mode: builds blocks on every slot for validation without publishing to L1 */
54
55
  fishermanMode?: boolean;
55
- /** Address of the forwarder contract to wrap all L1 transactions through (for testing purposes only) */
56
- publisherForwarderAddress?: EthAddress;
57
56
  /** Store for failed L1 transaction inputs (test networks only). Format: gs://bucket/path */
58
57
  l1TxFailedStore?: string;
59
58
  /** Min ETH balance below which a publisher gets funded. Undefined = funding disabled. */
60
59
  publisherFundingThreshold?: bigint;
61
60
  /** Amount of ETH to send when funding a publisher. Undefined = funding disabled. */
62
61
  publisherFundingAmount?: bigint;
62
+ /** Warn when a publisher balance is below this multiple of the ETH required for the reference L1 send. */
63
+ publisherLowBalanceWarningMultiplier?: number;
63
64
  };
64
65
 
65
- /** Shared config mappings for publisher funding, used by both sequencer and prover publisher configs. */
66
+ /** Shared config mappings for publisher funding and balance warnings, used by both sequencer and prover configs. */
66
67
  const publisherFundingConfigMappings = {
67
68
  publisherFundingThreshold: {
68
69
  env: 'PUBLISHER_FUNDING_THRESHOLD' as const,
@@ -76,17 +77,30 @@ const publisherFundingConfigMappings = {
76
77
  'Amount of ETH to send when funding a publisher. Specified in ether (e.g. 0.5). Unset = funding disabled.',
77
78
  parseEnv: (val: string) => parseEther(val),
78
79
  },
80
+ publisherLowBalanceWarningMultiplier: {
81
+ env: 'PUBLISHER_LOW_BALANCE_WARNING_MULTIPLIER' as const,
82
+ description:
83
+ 'Warn when a publisher balance is below this multiple of the ETH required for a reference L1 send (a first-of-epoch ' +
84
+ 'proposal for sequencers, an epoch proof for provers) at current fees. Publishers that cannot afford a send are ' +
85
+ 'never used for it.',
86
+ ...floatConfigHelper(4, val => {
87
+ if (val <= 0) {
88
+ throw new Error(`PUBLISHER_LOW_BALANCE_WARNING_MULTIPLIER must be positive, got ${val}`);
89
+ }
90
+ }),
91
+ },
79
92
  };
80
93
 
81
94
  export type ProverPublisherConfig = L1TxUtilsConfig &
82
95
  BlobClientConfig & {
83
96
  fishermanMode?: boolean;
84
97
  proverPublisherAllowInvalidStates?: boolean;
85
- proverPublisherForwarderAddress?: EthAddress;
86
98
  /** Min ETH balance below which a publisher gets funded. Undefined = funding disabled. */
87
99
  publisherFundingThreshold?: bigint;
88
100
  /** Amount of ETH to send when funding a publisher. Undefined = funding disabled. */
89
101
  publisherFundingAmount?: bigint;
102
+ /** Warn when a publisher balance is below this multiple of the ETH required for the reference L1 send. */
103
+ publisherLowBalanceWarningMultiplier?: number;
90
104
  };
91
105
 
92
106
  export type SequencerPublisherConfig = L1TxUtilsConfig &
@@ -104,13 +118,14 @@ export type SequencerPublisherConfig = L1TxUtilsConfig &
104
118
  publisherFundingThreshold?: bigint;
105
119
  /** Amount of ETH to send when funding a publisher. Undefined = funding disabled. */
106
120
  publisherFundingAmount?: bigint;
121
+ /** Warn when a publisher balance is below this multiple of the ETH required for the reference L1 send. */
122
+ publisherLowBalanceWarningMultiplier?: number;
107
123
  };
108
124
 
109
125
  export function getPublisherConfigFromProverConfig(config: ProverPublisherConfig): PublisherConfig {
110
126
  return {
111
127
  ...config,
112
128
  publisherAllowInvalidStates: config.proverPublisherAllowInvalidStates,
113
- publisherForwarderAddress: config.proverPublisherForwarderAddress,
114
129
  };
115
130
  }
116
131
 
@@ -118,7 +133,6 @@ export function getPublisherConfigFromSequencerConfig(config: SequencerPublisher
118
133
  return {
119
134
  ...config,
120
135
  publisherAllowInvalidStates: config.sequencerPublisherAllowInvalidStates,
121
- publisherForwarderAddress: config.sequencerPublisherForwarderAddress,
122
136
  l1TxFailedStore: config.l1TxFailedStore,
123
137
  };
124
138
  }
@@ -211,10 +225,5 @@ export const proverPublisherConfigMappings: ConfigMappingsType<ProverPublisherCo
211
225
  'Whether to run in fisherman mode: builds blocks on every slot for validation without publishing to L1',
212
226
  ...booleanConfigHelper(false),
213
227
  },
214
- proverPublisherForwarderAddress: {
215
- env: `PROVER_PUBLISHER_FORWARDER_ADDRESS`,
216
- description: 'Address of the forwarder contract to wrap all L1 transactions through (for testing purposes only)',
217
- parseEnv: (val: string) => EthAddress.fromString(val),
218
- },
219
228
  ...publisherFundingConfigMappings,
220
229
  };
@@ -0,0 +1,51 @@
1
+ import { BLOBS_PER_CHECKPOINT } from '@aztec-labs/constants';
2
+ import type { SendCostRequirement } from '@aztec-labs/ethereum/l1-tx-utils';
3
+ import type { ReferenceSend } from '@aztec-labs/ethereum/publisher-manager';
4
+
5
+ /**
6
+ * Worst-case gas limit of a checkpoint proposal tx in an epoch that is already set up on L1, used to check that a
7
+ * publisher can afford it before building. On testnet v6 (Sepolia after Glamsterdam) the most expensive plain `propose`
8
+ * used 520k gas and was sent with a 669k gas limit, which adds the 64/63 call-forwarding factor, the gas limit buffer
9
+ * (20% by default) and the blob evaluation gas for its single blob. Each further blob adds 48 bytes of calldata and one
10
+ * hash check (under 10k gas each), so a 6-blob checkpoint needs about 720k, rounded up with margin to 750k.
11
+ */
12
+ export const PROPOSE_GAS = 750_000n;
13
+
14
+ /**
15
+ * Worst-case gas limit of the first checkpoint proposal tx of an epoch, whose `propose` also runs `setupEpoch` (samples
16
+ * the committee and stores its commitment). On testnet v6 (Sepolia after Glamsterdam) the most expensive one used 1.34M
17
+ * gas and was sent with a 1.67M gas limit for a single blob. Sized the same way as {@link PROPOSE_GAS}: about 1.72M for
18
+ * 6 blobs, rounded up to 1.75M.
19
+ */
20
+ export const PROPOSE_WITH_SETUP_EPOCH_GAS = 1_750_000n;
21
+
22
+ /**
23
+ * Worst-case gas of invalidating a checkpoint (`invalidateBadAttestation` or `invalidateInsufficientAttestations`),
24
+ * which is bundled ahead of the proposal when the pending chain is invalid. Dominated by recomputing the committee
25
+ * commitment and recovering the attestation signatures, so it grows with the committee size.
26
+ */
27
+ export const INVALIDATE_GAS = 1_000_000n;
28
+
29
+ /**
30
+ * Affordability requirement of a checkpoint proposal, optionally bundled with an invalidation of the pending chain.
31
+ * @param opts.withSetupEpoch - Whether the proposal is the first of an epoch not yet set up on L1, so it runs setupEpoch.
32
+ */
33
+ export function getProposeRequirement(opts: { withInvalidate: boolean; withSetupEpoch: boolean }): SendCostRequirement {
34
+ return {
35
+ gasLimit:
36
+ (opts.withSetupEpoch ? PROPOSE_WITH_SETUP_EPOCH_GAS : PROPOSE_GAS) + (opts.withInvalidate ? INVALIDATE_GAS : 0n),
37
+ blobCount: BLOBS_PER_CHECKPOINT,
38
+ };
39
+ }
40
+
41
+ /**
42
+ * Send the periodic publisher balance check prices to report whether a sequencer can afford to propose: a first-of-epoch
43
+ * proposal without an invalidation, so that affording one means affording any proposal that does not invalidate.
44
+ */
45
+ export const PROPOSE_REFERENCE_SEND: ReferenceSend = {
46
+ name: 'proposal',
47
+ requirement: getProposeRequirement({ withSetupEpoch: true, withInvalidate: false }),
48
+ };
49
+
50
+ /** Affordability requirement of a standalone checkpoint invalidation. */
51
+ export const INVALIDATE_REQUIREMENT: SendCostRequirement = { gasLimit: INVALIDATE_GAS, blobCount: 0 };
@@ -1,5 +1,6 @@
1
1
  export { SequencerPublisher } from './sequencer-publisher.js';
2
2
  export { SequencerPublisherFactory } from './sequencer-publisher-factory.js';
3
+ export { PublisherManagerMetrics } from './publisher-manager-metrics.js';
3
4
 
4
5
  // Used for tests
5
6
  export { SequencerPublisherMetrics } from './sequencer-publisher-metrics.js';
@@ -1,6 +1,7 @@
1
1
  import { jsonParseWithSchema, jsonStringify } from '@aztec-labs/foundation/json-rpc';
2
2
  import { type Logger, createLogger } from '@aztec-labs/foundation/log';
3
3
  import type { FileStore } from '@aztec-labs/stdlib/file-store';
4
+ import { Buffer } from 'buffer';
4
5
 
5
6
  import { type FailedL1Tx, FailedL1TxSchema, type FailedL1TxUri, type L1TxFailedStore } from './failed_tx_store.js';
6
7
 
@@ -0,0 +1,76 @@
1
+ import type { IPublisherManagerMetrics, PublisherBalanceSnapshot } from '@aztec-labs/ethereum/publisher-manager';
2
+ import {
3
+ Attributes,
4
+ type BatchObservableResult,
5
+ Metrics,
6
+ type ObservableGauge,
7
+ type TelemetryClient,
8
+ } from '@aztec-labs/telemetry-client';
9
+ import { formatEther } from 'viem';
10
+
11
+ /**
12
+ * Telemetry for the publisher balance check, labelled by whether the publishers belong to a sequencer or prover. Gauges
13
+ * are observed from the latest snapshot at export time, and are no longer observed once the publisher manager stops.
14
+ */
15
+ export class PublisherManagerMetrics implements IPublisherManagerMetrics {
16
+ private readonly balance: ObservableGauge;
17
+ private readonly deprecatedBalance: ObservableGauge;
18
+ private readonly sendsAffordable: ObservableGauge;
19
+ private readonly funderBalance: ObservableGauge;
20
+ private readonly requiredBalance: ObservableGauge;
21
+ private snapshot: PublisherBalanceSnapshot | undefined;
22
+
23
+ constructor(
24
+ client: TelemetryClient,
25
+ private readonly scope: 'sequencer' | 'prover',
26
+ ) {
27
+ const meter = client.getMeter('PublisherManager');
28
+ this.balance = meter.createObservableGauge(Metrics.L1_PUBLISHER_BALANCE);
29
+ this.deprecatedBalance = meter.createObservableGauge(Metrics.L1_BALANCE_ETH);
30
+ this.sendsAffordable = meter.createObservableGauge(Metrics.L1_PUBLISHER_SENDS_AFFORDABLE);
31
+ this.funderBalance = meter.createObservableGauge(Metrics.L1_FUNDER_BALANCE);
32
+ this.requiredBalance = meter.createObservableGauge(Metrics.L1_PUBLISHER_REQUIRED_BALANCE);
33
+ meter.addBatchObservableCallback(this.observe, [
34
+ this.balance,
35
+ this.deprecatedBalance,
36
+ this.sendsAffordable,
37
+ this.funderBalance,
38
+ this.requiredBalance,
39
+ ]);
40
+ }
41
+
42
+ public recordBalanceSnapshot(snapshot: PublisherBalanceSnapshot | undefined): void {
43
+ this.snapshot = snapshot;
44
+ }
45
+
46
+ private observe = (observer: BatchObservableResult): void => {
47
+ const { snapshot, scope } = this;
48
+ if (snapshot === undefined) {
49
+ return;
50
+ }
51
+
52
+ for (const { address, balance, sendsAffordable } of snapshot.publishers) {
53
+ const attributes = { [Attributes.SENDER_ADDRESS]: address, [Attributes.L1_TX_SCOPE]: scope };
54
+ observer.observe(this.balance, toEth(balance), attributes);
55
+ observer.observe(this.deprecatedBalance, toEth(balance), { [Attributes.L1_SENDER]: address });
56
+ if (sendsAffordable !== undefined) {
57
+ observer.observe(this.sendsAffordable, sendsAffordable, attributes);
58
+ }
59
+ }
60
+
61
+ if (snapshot.funder) {
62
+ observer.observe(this.funderBalance, toEth(snapshot.funder.balance), {
63
+ [Attributes.SENDER_ADDRESS]: snapshot.funder.address,
64
+ [Attributes.L1_TX_SCOPE]: scope,
65
+ });
66
+ }
67
+
68
+ if (snapshot.required !== undefined) {
69
+ observer.observe(this.requiredBalance, toEth(snapshot.required), { [Attributes.L1_TX_SCOPE]: scope });
70
+ }
71
+ };
72
+ }
73
+
74
+ function toEth(wei: bigint): number {
75
+ return parseFloat(formatEther(wei));
76
+ }