@aztec/sequencer-client 5.0.0-private.20260319 → 5.0.0-rc.2
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.
- package/README.md +281 -21
- package/dest/client/sequencer-client.d.ts +8 -3
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +17 -32
- package/dest/config.d.ts +10 -4
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +49 -25
- package/dest/global_variable_builder/fee_predictor.d.ts +37 -0
- package/dest/global_variable_builder/fee_predictor.d.ts.map +1 -0
- package/dest/global_variable_builder/fee_predictor.js +128 -0
- package/dest/global_variable_builder/fee_provider.d.ts +21 -0
- package/dest/global_variable_builder/fee_provider.d.ts.map +1 -0
- package/dest/global_variable_builder/fee_provider.js +67 -0
- package/dest/global_variable_builder/global_builder.d.ts +13 -26
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +9 -67
- package/dest/global_variable_builder/index.d.ts +4 -2
- package/dest/global_variable_builder/index.d.ts.map +1 -1
- package/dest/global_variable_builder/index.js +2 -0
- package/dest/publisher/config.d.ts +19 -3
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +30 -5
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +3 -4
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -1
- package/dest/publisher/sequencer-bundle-simulator.d.ts +96 -0
- package/dest/publisher/sequencer-bundle-simulator.d.ts.map +1 -0
- package/dest/publisher/sequencer-bundle-simulator.js +198 -0
- package/dest/publisher/sequencer-publisher-factory.d.ts +3 -5
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-factory.js +2 -3
- package/dest/publisher/sequencer-publisher.d.ts +84 -65
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +403 -531
- package/dest/sequencer/automine/automine_factory.d.ts +56 -0
- package/dest/sequencer/automine/automine_factory.d.ts.map +1 -0
- package/dest/sequencer/automine/automine_factory.js +85 -0
- package/dest/sequencer/automine/automine_sequencer.d.ts +189 -0
- package/dest/sequencer/automine/automine_sequencer.d.ts.map +1 -0
- package/dest/sequencer/automine/automine_sequencer.js +689 -0
- package/dest/sequencer/automine/index.d.ts +3 -0
- package/dest/sequencer/automine/index.d.ts.map +1 -0
- package/dest/sequencer/automine/index.js +2 -0
- package/dest/sequencer/checkpoint_proposal_job.d.ts +73 -21
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_proposal_job.js +709 -200
- package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts +34 -0
- package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_proposal_job_metrics.js +72 -0
- package/dest/sequencer/checkpoint_voter.d.ts +1 -2
- package/dest/sequencer/checkpoint_voter.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_voter.js +2 -5
- package/dest/sequencer/errors.d.ts +1 -8
- package/dest/sequencer/errors.d.ts.map +1 -1
- package/dest/sequencer/errors.js +0 -9
- package/dest/sequencer/events.d.ts +61 -4
- package/dest/sequencer/events.d.ts.map +1 -1
- package/dest/sequencer/metrics.d.ts +9 -10
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +34 -20
- package/dest/sequencer/sequencer.d.ts +117 -30
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +483 -158
- package/dest/sequencer/types.d.ts +2 -2
- package/dest/sequencer/types.d.ts.map +1 -1
- package/dest/test/index.d.ts +3 -3
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/utils.d.ts +15 -1
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +24 -7
- package/package.json +28 -27
- package/src/client/sequencer-client.ts +29 -41
- package/src/config.ts +58 -25
- package/src/global_variable_builder/README.md +44 -0
- package/src/global_variable_builder/fee_predictor.ts +172 -0
- package/src/global_variable_builder/fee_provider.ts +80 -0
- package/src/global_variable_builder/global_builder.ts +19 -89
- package/src/global_variable_builder/index.ts +3 -1
- package/src/publisher/config.ts +62 -7
- package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +3 -1
- package/src/publisher/sequencer-bundle-simulator.ts +254 -0
- package/src/publisher/sequencer-publisher-factory.ts +3 -6
- package/src/publisher/sequencer-publisher.ts +456 -578
- package/src/sequencer/automine/README.md +60 -0
- package/src/sequencer/automine/automine_factory.ts +152 -0
- package/src/sequencer/automine/automine_sequencer.ts +795 -0
- package/src/sequencer/automine/index.ts +6 -0
- package/src/sequencer/checkpoint_proposal_job.ts +817 -225
- package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
- package/src/sequencer/checkpoint_voter.ts +1 -12
- package/src/sequencer/errors.ts +0 -15
- package/src/sequencer/events.ts +65 -4
- package/src/sequencer/metrics.ts +43 -24
- package/src/sequencer/sequencer.ts +557 -175
- package/src/sequencer/types.ts +1 -1
- package/src/test/index.ts +2 -2
- package/src/test/utils.ts +60 -10
- package/dest/sequencer/timetable.d.ts +0 -88
- package/dest/sequencer/timetable.d.ts.map +0 -1
- package/dest/sequencer/timetable.js +0 -222
- package/src/sequencer/README.md +0 -531
- package/src/sequencer/timetable.ts +0 -283
|
@@ -370,14 +370,12 @@ function applyDecs2203RFactory() {
|
|
|
370
370
|
function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
|
|
371
371
|
return (_apply_decs_2203_r = applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
|
|
372
372
|
}
|
|
373
|
-
var _dec, _dec1,
|
|
373
|
+
var _dec, _dec1, _initProto;
|
|
374
374
|
import { Blob, getBlobsPerL1Block, getPrefixedEthBlobCommitments } from '@aztec/blob-lib';
|
|
375
|
-
import { FeeAssetPriceOracle, MULTI_CALL_3_ADDRESS, Multicall3,
|
|
375
|
+
import { FeeAssetPriceOracle, MULTI_CALL_3_ADDRESS, Multicall3, MulticallForwarderRevertedError, buildSimulationOverridesStateOverride } from '@aztec/ethereum/contracts';
|
|
376
376
|
import { L1FeeAnalyzer } from '@aztec/ethereum/l1-fee-analysis';
|
|
377
377
|
import { MAX_L1_TX_LIMIT, WEI_CONST } from '@aztec/ethereum/l1-tx-utils';
|
|
378
|
-
import { FormattedViemError, formatViemError, mergeAbis, tryExtractEvent } from '@aztec/ethereum/utils';
|
|
379
|
-
import { sumBigint } from '@aztec/foundation/bigint';
|
|
380
|
-
import { toHex as toPaddedHex } from '@aztec/foundation/bigint-buffer';
|
|
378
|
+
import { FormattedViemError, formatViemError, mergeAbis, tryDecodeRevertReason, tryExtractEvent } from '@aztec/ethereum/utils';
|
|
381
379
|
import { CheckpointNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
382
380
|
import { trimmedBytesLength } from '@aztec/foundation/buffer';
|
|
383
381
|
import { pick } from '@aztec/foundation/collection';
|
|
@@ -385,30 +383,40 @@ import { TimeoutError } from '@aztec/foundation/error';
|
|
|
385
383
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
386
384
|
import { Signature } from '@aztec/foundation/eth-signature';
|
|
387
385
|
import { createLogger } from '@aztec/foundation/log';
|
|
388
|
-
import {
|
|
386
|
+
import { InterruptibleSleep } from '@aztec/foundation/sleep';
|
|
389
387
|
import { bufferToHex } from '@aztec/foundation/string';
|
|
390
388
|
import { Timer } from '@aztec/foundation/timer';
|
|
391
|
-
import { EmpireBaseAbi, ErrorsAbi, RollupAbi } from '@aztec/l1-artifacts';
|
|
389
|
+
import { EmpireBaseAbi, ErrorsAbi, RollupAbi, SlashingProposerAbi } from '@aztec/l1-artifacts';
|
|
392
390
|
import { encodeSlashConsensusVotes } from '@aztec/slasher';
|
|
393
391
|
import { CommitteeAttestationsAndSigners } from '@aztec/stdlib/block';
|
|
392
|
+
import { getLastL1SlotTimestampForL2Slot, getNextL1SlotTimestamp, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
394
393
|
import { getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
395
|
-
import { encodeFunctionData, keccak256,
|
|
394
|
+
import { encodeFunctionData, keccak256, toHex } from 'viem';
|
|
396
395
|
import { createL1TxFailedStore } from './l1_tx_failed_store/index.js';
|
|
396
|
+
import { SequencerBundleSimulator } from './sequencer-bundle-simulator.js';
|
|
397
397
|
import { SequencerPublisherMetrics } from './sequencer-publisher-metrics.js';
|
|
398
|
+
/**
|
|
399
|
+
* Returns true if the receipt indicates a successful send AND the expected event was emitted
|
|
400
|
+
* by the target contract. Both pieces are required: an aggregate3 entry that reverted will
|
|
401
|
+
* have receipt.status === 'success' but no event log.
|
|
402
|
+
*/ function extractEventSuccess(receipt, opts) {
|
|
403
|
+
if (!receipt || receipt.status !== 'success') {
|
|
404
|
+
return false;
|
|
405
|
+
}
|
|
406
|
+
return !!tryExtractEvent(receipt.logs, opts.address.toString(), opts.abi, opts.eventName);
|
|
407
|
+
}
|
|
398
408
|
export const Actions = [
|
|
399
409
|
'invalidate-by-invalid-attestation',
|
|
400
410
|
'invalidate-by-insufficient-attestations',
|
|
411
|
+
'prune',
|
|
401
412
|
'propose',
|
|
402
413
|
'governance-signal',
|
|
403
|
-
'empire-slashing-signal',
|
|
404
|
-
'create-empire-payload',
|
|
405
|
-
'execute-empire-payload',
|
|
406
414
|
'vote-offenses',
|
|
407
415
|
'execute-slash'
|
|
408
416
|
];
|
|
409
417
|
// Sorting for actions such that invalidations go before proposals, and proposals go before votes
|
|
410
418
|
export const compareActions = (a, b)=>Actions.indexOf(a) - Actions.indexOf(b);
|
|
411
|
-
_dec = trackSpan('SequencerPublisher.sendRequests'), _dec1 = trackSpan('SequencerPublisher.validateBlockHeader')
|
|
419
|
+
_dec = trackSpan('SequencerPublisher.sendRequests'), _dec1 = trackSpan('SequencerPublisher.validateBlockHeader');
|
|
412
420
|
export class SequencerPublisher {
|
|
413
421
|
config;
|
|
414
422
|
static{
|
|
@@ -422,57 +430,59 @@ export class SequencerPublisher {
|
|
|
422
430
|
_dec1,
|
|
423
431
|
2,
|
|
424
432
|
"validateBlockHeader"
|
|
425
|
-
],
|
|
426
|
-
[
|
|
427
|
-
_dec2,
|
|
428
|
-
2,
|
|
429
|
-
"validateCheckpointForSubmission"
|
|
430
433
|
]
|
|
431
434
|
], []));
|
|
432
435
|
}
|
|
433
436
|
interrupted;
|
|
434
437
|
metrics;
|
|
438
|
+
bundleSimulator;
|
|
435
439
|
epochCache;
|
|
436
440
|
failedTxStore;
|
|
437
|
-
|
|
438
|
-
|
|
441
|
+
/**
|
|
442
|
+
* ABI used to decode raw revert payloads from dropped bundle entries when the original
|
|
443
|
+
* request did not carry an abi (e.g. the propose request). Merges every contract the
|
|
444
|
+
* publisher can route to so any of their custom errors decode against it.
|
|
445
|
+
*/ revertDecoderAbi;
|
|
439
446
|
lastActions;
|
|
440
|
-
isPayloadEmptyCache;
|
|
441
|
-
payloadProposedCache;
|
|
442
447
|
log;
|
|
443
448
|
ethereumSlotDuration;
|
|
444
449
|
aztecSlotDuration;
|
|
450
|
+
previousL1BlockWaitTimeoutMs;
|
|
451
|
+
previousL1BlockWaitPollIntervalMs;
|
|
452
|
+
/** Date provider for wall-clock time. */ dateProvider;
|
|
445
453
|
blobClient;
|
|
446
|
-
/** Address to use for simulations in fisherman mode (actual proposer's address) */ proposerAddressForSimulation;
|
|
447
454
|
/** Optional callback to obtain a replacement publisher when the current one fails to send. */ getNextPublisher;
|
|
448
455
|
/** L1 fee analyzer for fisherman mode */ l1FeeAnalyzer;
|
|
449
456
|
/** Fee asset price oracle for computing price modifiers from Uniswap V4 */ feeAssetPriceOracle;
|
|
450
|
-
|
|
451
|
-
static MULTICALL_OVERHEAD_GAS_GUESS = 5000n;
|
|
452
|
-
// Gas report for VotingWithSigTest shows a max gas of 100k, but we've seen it cost 700k+ in testnet
|
|
453
|
-
static VOTE_GAS_GUESS = 800_000n;
|
|
457
|
+
/** Interruptible sleep used by sendRequestsAt to wait until a target timestamp. */ interruptibleSleep;
|
|
454
458
|
l1TxUtils;
|
|
455
459
|
rollupContract;
|
|
456
460
|
govProposerContract;
|
|
457
461
|
slashingProposerContract;
|
|
458
|
-
slashFactoryContract;
|
|
459
462
|
tracer;
|
|
460
463
|
requests;
|
|
461
464
|
constructor(config, deps){
|
|
462
465
|
this.config = config;
|
|
463
466
|
this.interrupted = (_initProto(this), false);
|
|
464
|
-
this.
|
|
465
|
-
|
|
467
|
+
this.revertDecoderAbi = mergeAbis([
|
|
468
|
+
RollupAbi,
|
|
469
|
+
SlashingProposerAbi,
|
|
470
|
+
EmpireBaseAbi,
|
|
471
|
+
ErrorsAbi
|
|
472
|
+
]);
|
|
466
473
|
this.lastActions = {};
|
|
467
|
-
this.
|
|
468
|
-
this.payloadProposedCache = new Set();
|
|
474
|
+
this.interruptibleSleep = new InterruptibleSleep();
|
|
469
475
|
this.requests = [];
|
|
470
476
|
this.log = deps.log ?? createLogger('sequencer:publisher');
|
|
471
477
|
this.ethereumSlotDuration = BigInt(config.ethereumSlotDuration);
|
|
472
478
|
this.aztecSlotDuration = BigInt(config.aztecSlotDuration);
|
|
479
|
+
this.previousL1BlockWaitTimeoutMs = config.sequencerPublisherPreviousL1BlockWaitTimeoutMs;
|
|
480
|
+
this.previousL1BlockWaitPollIntervalMs = config.sequencerPublisherPreviousL1BlockWaitPollIntervalMs;
|
|
481
|
+
this.dateProvider = deps.dateProvider;
|
|
473
482
|
this.epochCache = deps.epochCache;
|
|
474
483
|
this.lastActions = deps.lastActions;
|
|
475
484
|
this.blobClient = deps.blobClient;
|
|
485
|
+
this.dateProvider = deps.dateProvider;
|
|
476
486
|
const telemetry = deps.telemetry ?? getTelemetryClient();
|
|
477
487
|
this.metrics = deps.metrics ?? new SequencerPublisherMetrics(telemetry, 'SequencerPublisher');
|
|
478
488
|
this.tracer = telemetry.getTracer('SequencerPublisher');
|
|
@@ -486,15 +496,20 @@ export class SequencerPublisher {
|
|
|
486
496
|
const newSlashingProposer = await this.rollupContract.getSlashingProposer();
|
|
487
497
|
this.slashingProposerContract = newSlashingProposer;
|
|
488
498
|
});
|
|
489
|
-
this.slashFactoryContract = deps.slashFactoryContract;
|
|
490
499
|
// Initialize L1 fee analyzer for fisherman mode
|
|
491
500
|
if (config.fishermanMode) {
|
|
492
|
-
this.l1FeeAnalyzer = new L1FeeAnalyzer(this.l1TxUtils.client, deps.dateProvider,
|
|
501
|
+
this.l1FeeAnalyzer = new L1FeeAnalyzer(this.l1TxUtils.client, deps.dateProvider, this.log.createChild('fee-analyzer'));
|
|
493
502
|
}
|
|
494
503
|
// Initialize fee asset price oracle
|
|
495
|
-
this.feeAssetPriceOracle = new FeeAssetPriceOracle(this.l1TxUtils.client, this.rollupContract,
|
|
504
|
+
this.feeAssetPriceOracle = new FeeAssetPriceOracle(this.l1TxUtils.client, this.rollupContract, this.log.createChild('price-oracle'));
|
|
496
505
|
// Initialize failed L1 tx store (optional, for test networks)
|
|
497
506
|
this.failedTxStore = createL1TxFailedStore(config.l1TxFailedStore, this.log);
|
|
507
|
+
this.bundleSimulator = new SequencerBundleSimulator({
|
|
508
|
+
getL1TxUtils: ()=>this.l1TxUtils,
|
|
509
|
+
rollupContract: this.rollupContract,
|
|
510
|
+
epochCache: this.epochCache,
|
|
511
|
+
log: this.log.createChild('bundle-simulator')
|
|
512
|
+
});
|
|
498
513
|
}
|
|
499
514
|
/**
|
|
500
515
|
* Backs up a failed L1 transaction to the configured store for debugging.
|
|
@@ -517,9 +532,13 @@ export class SequencerPublisher {
|
|
|
517
532
|
}
|
|
518
533
|
/**
|
|
519
534
|
* Gets the fee asset price modifier from the oracle.
|
|
520
|
-
*
|
|
521
|
-
|
|
522
|
-
|
|
535
|
+
*
|
|
536
|
+
* @param predictedParentEthPerFeeAssetE12 - Optional predicted parent eth-per-fee-asset (E12).
|
|
537
|
+
* Pipelined proposers should pass the value from the predicted parent fee header so the
|
|
538
|
+
* modifier matches the parent L1 will use when applying it.
|
|
539
|
+
* @returns The fee asset price modifier in basis points, or 0n if the oracle query fails.
|
|
540
|
+
*/ getFeeAssetPriceModifier(predictedParentEthPerFeeAssetE12) {
|
|
541
|
+
return this.feeAssetPriceOracle.computePriceModifier(predictedParentEthPerFeeAssetE12);
|
|
523
542
|
}
|
|
524
543
|
getSenderAddress() {
|
|
525
544
|
return this.l1TxUtils.getSenderAddress();
|
|
@@ -529,12 +548,6 @@ export class SequencerPublisher {
|
|
|
529
548
|
*/ getL1FeeAnalyzer() {
|
|
530
549
|
return this.l1FeeAnalyzer;
|
|
531
550
|
}
|
|
532
|
-
/**
|
|
533
|
-
* Sets the proposer address to use for simulations in fisherman mode.
|
|
534
|
-
* @param proposerAddress - The actual proposer's address to use for balance lookups in simulations
|
|
535
|
-
*/ setProposerAddressForSimulation(proposerAddress) {
|
|
536
|
-
this.proposerAddressForSimulation = proposerAddress;
|
|
537
|
-
}
|
|
538
551
|
addRequest(request) {
|
|
539
552
|
this.requests.push(request);
|
|
540
553
|
}
|
|
@@ -592,11 +605,15 @@ export class SequencerPublisher {
|
|
|
592
605
|
}
|
|
593
606
|
/**
|
|
594
607
|
* Sends all requests that are still valid.
|
|
608
|
+
* @param targetSlot - The target L2 slot for this send. When provided (the production path, via
|
|
609
|
+
* sendRequestsAt), it is threaded into bundleSimulate so the block.timestamp override matches
|
|
610
|
+
* the slot the propose is built for. When omitted, falls back to getCurrentL2Slot() for the
|
|
611
|
+
* AutomineSequencer, which publishes synchronously within the current slot.
|
|
595
612
|
* @returns one of:
|
|
596
613
|
* - A receipt and stats if the tx succeeded
|
|
597
614
|
* - a receipt and errorMsg if it failed on L1
|
|
598
615
|
* - undefined if no valid requests are found OR the tx failed to send.
|
|
599
|
-
*/ async sendRequests() {
|
|
616
|
+
*/ async sendRequests(targetSlot) {
|
|
600
617
|
const requestsToProcess = [
|
|
601
618
|
...this.requests
|
|
602
619
|
];
|
|
@@ -604,10 +621,9 @@ export class SequencerPublisher {
|
|
|
604
621
|
if (this.interrupted || requestsToProcess.length === 0) {
|
|
605
622
|
return undefined;
|
|
606
623
|
}
|
|
607
|
-
const currentL2Slot = this.getCurrentL2Slot();
|
|
624
|
+
const currentL2Slot = targetSlot ?? this.getCurrentL2Slot();
|
|
608
625
|
this.log.debug(`Sending requests on L2 slot ${currentL2Slot}`);
|
|
609
626
|
const validRequests = requestsToProcess.filter((request)=>request.lastValidL2Slot >= currentL2Slot);
|
|
610
|
-
const validActions = validRequests.map((x)=>x.action);
|
|
611
627
|
const expiredActions = requestsToProcess.filter((request)=>request.lastValidL2Slot < currentL2Slot).map((x)=>x.action);
|
|
612
628
|
if (validRequests.length !== requestsToProcess.length) {
|
|
613
629
|
this.log.warn(`Some requests were expired for slot ${currentL2Slot}`, {
|
|
@@ -625,71 +641,53 @@ export class SequencerPublisher {
|
|
|
625
641
|
this.log.debug(`No valid requests to send`);
|
|
626
642
|
return undefined;
|
|
627
643
|
}
|
|
628
|
-
//
|
|
629
|
-
// find requests with gas and blob configs
|
|
630
|
-
// See https://github.com/AztecProtocol/aztec-packages/issues/11513
|
|
644
|
+
// Collect earliest txTimeoutAt across all requests.
|
|
631
645
|
const gasConfigs = validRequests.filter((request)=>request.gasConfig).map((request)=>request.gasConfig);
|
|
632
|
-
const blobConfigs = validRequests.filter((request)=>request.blobConfig).map((request)=>request.blobConfig);
|
|
633
|
-
if (blobConfigs.length > 1) {
|
|
634
|
-
throw new Error('Multiple blob configs found');
|
|
635
|
-
}
|
|
636
|
-
const blobConfig = blobConfigs[0];
|
|
637
|
-
// Merge gasConfigs. Yields the sum of gasLimits, and the earliest txTimeoutAt, or undefined if no gasConfig sets them.
|
|
638
|
-
const gasLimits = gasConfigs.map((g)=>g?.gasLimit).filter((g)=>g !== undefined);
|
|
639
|
-
let gasLimit = gasLimits.length > 0 ? sumBigint(gasLimits) : undefined; // sum
|
|
640
|
-
// Cap at L1 block gas limit so the node accepts the tx ("gas limit too high" otherwise).
|
|
641
|
-
const maxGas = MAX_L1_TX_LIMIT;
|
|
642
|
-
if (gasLimit !== undefined && gasLimit > maxGas) {
|
|
643
|
-
this.log.debug('Capping bundled tx gas limit to L1 max', {
|
|
644
|
-
requested: gasLimit,
|
|
645
|
-
capped: maxGas
|
|
646
|
-
});
|
|
647
|
-
gasLimit = maxGas;
|
|
648
|
-
}
|
|
649
646
|
const txTimeoutAts = gasConfigs.map((g)=>g?.txTimeoutAt).filter((g)=>g !== undefined);
|
|
650
|
-
const txTimeoutAt = txTimeoutAts.length > 0 ? new Date(Math.min(...txTimeoutAts.map((g)=>g.getTime()))) : undefined;
|
|
651
|
-
const txConfig = {
|
|
652
|
-
gasLimit,
|
|
653
|
-
txTimeoutAt
|
|
654
|
-
};
|
|
647
|
+
const txTimeoutAt = txTimeoutAts.length > 0 ? new Date(Math.min(...txTimeoutAts.map((g)=>g.getTime()))) : undefined;
|
|
655
648
|
// Sort the requests so that proposals always go first
|
|
656
649
|
// This ensures the committee gets precomputed correctly
|
|
657
650
|
validRequests.sort((a, b)=>compareActions(a.action, b.action));
|
|
658
651
|
try {
|
|
659
|
-
//
|
|
660
|
-
const
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
652
|
+
// Bundle-level eth_simulateV1: filters out entries that revert and derives the gasLimit.
|
|
653
|
+
const bundleResult = await this.bundleSimulator.simulate(validRequests, currentL2Slot);
|
|
654
|
+
if (bundleResult.kind === 'aborted') {
|
|
655
|
+
this.logDroppedInSim(bundleResult.droppedRequests);
|
|
656
|
+
void this.backupDroppedInSim(bundleResult.droppedRequests);
|
|
657
|
+
return undefined;
|
|
658
|
+
}
|
|
659
|
+
const { requests, droppedRequests, gasLimit } = bundleResult.kind === 'fallback' ? {
|
|
660
|
+
requests: bundleResult.requests,
|
|
661
|
+
droppedRequests: bundleResult.droppedRequests,
|
|
662
|
+
gasLimit: MAX_L1_TX_LIMIT
|
|
663
|
+
} : bundleResult;
|
|
664
|
+
this.logDroppedInSim(droppedRequests);
|
|
665
|
+
// Compute blobConfig from survivors (not original validRequests) so that if the propose
|
|
666
|
+
// entry was dropped by bundleSimulate we don't attach a blob-typed config to a non-blob tx.
|
|
667
|
+
const [blobConfig] = requests.filter((r)=>r.blobConfig).map((r)=>r.blobConfig);
|
|
668
|
+
const txConfig = {
|
|
669
|
+
gasLimit,
|
|
670
|
+
txTimeoutAt
|
|
677
671
|
};
|
|
678
672
|
this.log.debug('Forwarding transactions', {
|
|
679
|
-
|
|
673
|
+
requests: requests.map((request)=>request.action),
|
|
680
674
|
txConfig
|
|
681
675
|
});
|
|
682
|
-
const result = await this.forwardWithPublisherRotation(
|
|
676
|
+
const result = await this.forwardWithPublisherRotation(requests, txConfig, blobConfig);
|
|
683
677
|
if (result === undefined) {
|
|
684
678
|
return undefined;
|
|
685
679
|
}
|
|
686
|
-
const { successfulActions = [], failedActions = [] } = this.callbackBundledTransactions(
|
|
680
|
+
const { successfulActions = [], failedActions = [] } = this.callbackBundledTransactions(requests, result);
|
|
681
|
+
const allFailedActions = [
|
|
682
|
+
...failedActions,
|
|
683
|
+
...droppedRequests.map((d)=>d.request.action)
|
|
684
|
+
];
|
|
687
685
|
return {
|
|
688
686
|
result,
|
|
689
687
|
expiredActions,
|
|
690
|
-
sentActions:
|
|
688
|
+
sentActions: requests.map((x)=>x.action),
|
|
691
689
|
successfulActions,
|
|
692
|
-
failedActions
|
|
690
|
+
failedActions: allFailedActions
|
|
693
691
|
};
|
|
694
692
|
} catch (err) {
|
|
695
693
|
const viemError = formatViemError(err);
|
|
@@ -703,23 +701,78 @@ export class SequencerPublisher {
|
|
|
703
701
|
}
|
|
704
702
|
}
|
|
705
703
|
}
|
|
704
|
+
/** Logs entries dropped by bundle simulation as warnings on the publisher's logger. */ logDroppedInSim(dropped) {
|
|
705
|
+
for (const drop of dropped){
|
|
706
|
+
const revertReasonDecoded = drop.revertReason ?? tryDecodeRevertReason(drop.returnData, this.revertDecoderAbi);
|
|
707
|
+
this.log.warn('Bundle entry dropped: action reverted in sim', {
|
|
708
|
+
action: drop.request.action,
|
|
709
|
+
revertReason: revertReasonDecoded ?? drop.returnData,
|
|
710
|
+
revertReasonDecoded,
|
|
711
|
+
returnData: drop.returnData
|
|
712
|
+
});
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
/** Backs up entries dropped by bundle simulation, one record per dropped action. */ async backupDroppedInSim(dropped) {
|
|
716
|
+
if (dropped.length === 0) {
|
|
717
|
+
return;
|
|
718
|
+
}
|
|
719
|
+
const l1BlockNumber = await this.l1TxUtils.getBlockNumber();
|
|
720
|
+
for (const { request: req } of dropped){
|
|
721
|
+
this.backupFailedTx({
|
|
722
|
+
id: keccak256(req.request.data),
|
|
723
|
+
failureType: 'simulation',
|
|
724
|
+
request: {
|
|
725
|
+
to: req.request.to,
|
|
726
|
+
data: req.request.data
|
|
727
|
+
},
|
|
728
|
+
l1BlockNumber: l1BlockNumber.toString(),
|
|
729
|
+
error: {
|
|
730
|
+
message: 'Bundle entry dropped: action reverted in sim'
|
|
731
|
+
},
|
|
732
|
+
context: {
|
|
733
|
+
actions: [
|
|
734
|
+
req.action
|
|
735
|
+
],
|
|
736
|
+
sender: this.getSenderAddress().toString()
|
|
737
|
+
}
|
|
738
|
+
});
|
|
739
|
+
}
|
|
740
|
+
}
|
|
706
741
|
/**
|
|
707
742
|
* Forwards transactions via Multicall3, rotating to the next available publisher if a send
|
|
708
743
|
* failure occurs (i.e. the tx never reached the chain).
|
|
709
744
|
* On-chain reverts and simulation errors are returned as-is without rotation.
|
|
710
745
|
*/ async forwardWithPublisherRotation(validRequests, txConfig, blobConfig) {
|
|
746
|
+
if (!txConfig?.gasLimit) {
|
|
747
|
+
throw new Error('gasLimit is required for bundled transactions');
|
|
748
|
+
}
|
|
749
|
+
const txConfigWithGasLimit = txConfig;
|
|
711
750
|
const triedAddresses = [];
|
|
712
751
|
let currentPublisher = this.l1TxUtils;
|
|
713
752
|
while(true){
|
|
753
|
+
if (txConfig.txTimeoutAt && new Date() > txConfig.txTimeoutAt) {
|
|
754
|
+
this.log.warn(`Tx timeout (${txConfig.txTimeoutAt.toISOString()}) elapsed; stopping publisher rotation`, {
|
|
755
|
+
triedAddresses: triedAddresses.map((a)=>a.toString())
|
|
756
|
+
});
|
|
757
|
+
return undefined;
|
|
758
|
+
}
|
|
714
759
|
triedAddresses.push(currentPublisher.getSenderAddress());
|
|
715
760
|
try {
|
|
716
|
-
const result = await Multicall3.forward(validRequests.map((r)=>r.request), currentPublisher,
|
|
761
|
+
const result = await Multicall3.forward(validRequests.map((r)=>r.request), currentPublisher, txConfigWithGasLimit, blobConfig, {
|
|
762
|
+
gasLimitRequired: true
|
|
763
|
+
});
|
|
717
764
|
this.l1TxUtils = currentPublisher;
|
|
718
765
|
return result;
|
|
719
766
|
} catch (err) {
|
|
720
767
|
if (err instanceof TimeoutError) {
|
|
721
768
|
throw err;
|
|
722
769
|
}
|
|
770
|
+
if (err instanceof MulticallForwarderRevertedError) {
|
|
771
|
+
this.log.error('Forwarder transaction reverted on-chain; not rotating publisher', err, {
|
|
772
|
+
transactionHash: err.receipt.transactionHash
|
|
773
|
+
});
|
|
774
|
+
return undefined;
|
|
775
|
+
}
|
|
723
776
|
const viemError = formatViemError(err);
|
|
724
777
|
if (!this.getNextPublisher) {
|
|
725
778
|
this.log.error('Failed to publish bundled transactions', viemError);
|
|
@@ -730,121 +783,132 @@ export class SequencerPublisher {
|
|
|
730
783
|
...triedAddresses
|
|
731
784
|
]);
|
|
732
785
|
if (!nextPublisher) {
|
|
733
|
-
this.log.error(
|
|
786
|
+
this.log.error(`All available publishers exhausted (tried ${triedAddresses.length}), failed to publish bundled transactions`, viemError, {
|
|
787
|
+
triedAddresses: triedAddresses.map((a)=>a.toString())
|
|
788
|
+
});
|
|
734
789
|
return undefined;
|
|
735
790
|
}
|
|
736
791
|
currentPublisher = nextPublisher;
|
|
737
792
|
}
|
|
738
793
|
}
|
|
739
794
|
}
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
795
|
+
/*
|
|
796
|
+
* Schedules sending all enqueued requests at (or after) the start of the given L2 slot.
|
|
797
|
+
*/ async sendRequestsAt(targetSlot) {
|
|
798
|
+
await this.waitForTargetSlot(targetSlot);
|
|
799
|
+
if (this.interrupted) {
|
|
800
|
+
return undefined;
|
|
801
|
+
}
|
|
802
|
+
return this.sendRequests(targetSlot);
|
|
803
|
+
}
|
|
804
|
+
/**
|
|
805
|
+
* Sleeps until one L1 slot before the L2 slot boundary, and then waits for that L1 block
|
|
806
|
+
* to be mined, so we don't risk being included in it. If that block never gets mined after
|
|
807
|
+
* a timeout, we assume it got skipped on L1, so we send the tx anyway.
|
|
808
|
+
*/ async waitForTargetSlot(targetSlot) {
|
|
809
|
+
const l1Constants = this.epochCache.getL1Constants();
|
|
810
|
+
const nowInSeconds = this.dateProvider.nowInSeconds();
|
|
811
|
+
const startOfTargetSlotTs = getTimestampForSlot(targetSlot, l1Constants);
|
|
812
|
+
const previousL1BlockTs = startOfTargetSlotTs - this.ethereumSlotDuration;
|
|
813
|
+
const waitDeadlineTs = previousL1BlockTs + BigInt(this.previousL1BlockWaitTimeoutMs / 1000);
|
|
814
|
+
const logCtx = {
|
|
815
|
+
targetSlot,
|
|
816
|
+
startOfTargetSlotTs,
|
|
817
|
+
nowInSeconds,
|
|
818
|
+
previousL1BlockTs,
|
|
819
|
+
waitDeadlineTs
|
|
820
|
+
};
|
|
821
|
+
// Check if we are already past time
|
|
822
|
+
if (nowInSeconds >= startOfTargetSlotTs) {
|
|
823
|
+
this.log.verbose(`Target slot ${targetSlot} already started, sending requests immediately`, logCtx);
|
|
824
|
+
return;
|
|
825
|
+
}
|
|
826
|
+
// Otherwise we wait
|
|
827
|
+
this.log.debug(`Waiting for slot ${targetSlot} before sending requests`, logCtx);
|
|
828
|
+
// Wait until previous L1 block timestamp first
|
|
829
|
+
const sleepMs = (Number(previousL1BlockTs) - nowInSeconds) * 1000;
|
|
830
|
+
if (sleepMs > 0 && !this.interrupted) {
|
|
831
|
+
this.log.trace(`Sleeping ${sleepMs}ms before waiting for previous L1 block`, logCtx);
|
|
832
|
+
await this.interruptibleSleep.sleep(sleepMs);
|
|
833
|
+
}
|
|
834
|
+
// Then loop until we see the previous L1 block, so we know that we cannot be included in it.
|
|
835
|
+
// We time out after a while, once we are sure that that block is skipped in L1.
|
|
836
|
+
while(!this.interrupted){
|
|
837
|
+
try {
|
|
838
|
+
const nowInSeconds = this.dateProvider.nowInSeconds();
|
|
839
|
+
logCtx.nowInSeconds = nowInSeconds;
|
|
840
|
+
if (nowInSeconds >= waitDeadlineTs) {
|
|
841
|
+
this.log.warn(`Timed out waiting for previous L1 block before sending requests, proceeding`, logCtx);
|
|
842
|
+
return;
|
|
765
843
|
}
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
requests: requests.map((r)=>({
|
|
774
|
-
...r,
|
|
775
|
-
// Avoid logging large blob data
|
|
776
|
-
blobConfig: r.blobConfig ? {
|
|
777
|
-
...r.blobConfig,
|
|
778
|
-
blobs: r.blobConfig.blobs.map((b)=>({
|
|
779
|
-
size: trimmedBytesLength(b)
|
|
780
|
-
}))
|
|
781
|
-
} : undefined
|
|
782
|
-
}))
|
|
783
|
-
});
|
|
784
|
-
const successfulActions = [];
|
|
785
|
-
const failedActions = [];
|
|
786
|
-
for (const request of requests){
|
|
787
|
-
if (request.checkSuccess(request.request, result)) {
|
|
788
|
-
successfulActions.push(request.action);
|
|
789
|
-
} else {
|
|
790
|
-
failedActions.push(request.action);
|
|
844
|
+
const latestBlockTs = await this.l1TxUtils.getBlock().then((b)=>b.timestamp);
|
|
845
|
+
if (latestBlockTs >= previousL1BlockTs) {
|
|
846
|
+
this.log.debug(`Previous L1 block mined, proceeding to send requests`, {
|
|
847
|
+
...logCtx,
|
|
848
|
+
latestBlockTs
|
|
849
|
+
});
|
|
850
|
+
return;
|
|
791
851
|
}
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
this.backupFailedTx({
|
|
796
|
-
id: result.receipt.transactionHash,
|
|
797
|
-
failureType: 'revert',
|
|
798
|
-
request: {
|
|
799
|
-
to: MULTI_CALL_3_ADDRESS,
|
|
800
|
-
data: txContext.multicallData
|
|
801
|
-
},
|
|
802
|
-
blobData: txContext.blobData,
|
|
803
|
-
l1BlockNumber: result.receipt.blockNumber.toString(),
|
|
804
|
-
receipt: {
|
|
805
|
-
transactionHash: result.receipt.transactionHash,
|
|
806
|
-
blockNumber: result.receipt.blockNumber.toString(),
|
|
807
|
-
gasUsed: (result.receipt.gasUsed ?? 0n).toString(),
|
|
808
|
-
status: 'reverted'
|
|
809
|
-
},
|
|
810
|
-
error: {
|
|
811
|
-
message: result.errorMsg ?? 'Transaction reverted'
|
|
812
|
-
},
|
|
813
|
-
context: {
|
|
814
|
-
actions: failedActions,
|
|
815
|
-
requests: requests.filter((r)=>failedActions.includes(r.action)).map((r)=>({
|
|
816
|
-
action: r.action,
|
|
817
|
-
to: r.request.to,
|
|
818
|
-
data: r.request.data
|
|
819
|
-
})),
|
|
820
|
-
sender: this.getSenderAddress().toString()
|
|
821
|
-
}
|
|
852
|
+
this.log.trace(`Previous L1 block not mined yet, continuing to wait`, {
|
|
853
|
+
...logCtx,
|
|
854
|
+
latestBlockTs
|
|
822
855
|
});
|
|
856
|
+
} catch (err) {
|
|
857
|
+
this.log.error(`Error while waiting for previous L1 block before sending requests; retrying`, err, logCtx);
|
|
858
|
+
} finally{
|
|
859
|
+
await this.interruptibleSleep.sleep(this.previousL1BlockWaitPollIntervalMs);
|
|
823
860
|
}
|
|
824
|
-
return {
|
|
825
|
-
successfulActions,
|
|
826
|
-
failedActions
|
|
827
|
-
};
|
|
828
861
|
}
|
|
829
862
|
}
|
|
863
|
+
callbackBundledTransactions(requests, result) {
|
|
864
|
+
const actionsListStr = requests.map((r)=>r.action).join(', ');
|
|
865
|
+
this.log.verbose(`Published bundled transactions (${actionsListStr})`, {
|
|
866
|
+
result,
|
|
867
|
+
requests: requests.map((r)=>({
|
|
868
|
+
...r,
|
|
869
|
+
// Avoid logging large blob data
|
|
870
|
+
blobConfig: r.blobConfig ? {
|
|
871
|
+
...r.blobConfig,
|
|
872
|
+
blobs: r.blobConfig.blobs.map((b)=>({
|
|
873
|
+
size: trimmedBytesLength(b)
|
|
874
|
+
}))
|
|
875
|
+
} : undefined
|
|
876
|
+
}))
|
|
877
|
+
});
|
|
878
|
+
const successfulActions = [];
|
|
879
|
+
const failedActions = [];
|
|
880
|
+
for (const request of requests){
|
|
881
|
+
if (request.checkSuccess(request.request, result)) {
|
|
882
|
+
successfulActions.push(request.action);
|
|
883
|
+
} else {
|
|
884
|
+
failedActions.push(request.action);
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
return {
|
|
888
|
+
successfulActions,
|
|
889
|
+
failedActions
|
|
890
|
+
};
|
|
891
|
+
}
|
|
830
892
|
/**
|
|
831
893
|
* @notice Will call `canProposeAt` to make sure that it is possible to propose
|
|
832
894
|
* @param tipArchive - The archive to check
|
|
833
895
|
* @returns The slot and block number if it is possible to propose, undefined otherwise
|
|
834
|
-
*/ canProposeAt(tipArchive, msgSender,
|
|
896
|
+
*/ async canProposeAt(tipArchive, msgSender, simulationOverridesPlan) {
|
|
835
897
|
// TODO: #14291 - should loop through multiple keys to check if any of them can propose
|
|
836
|
-
|
|
898
|
+
// These errors are expected when we cannot actually propose right now — usually because our
|
|
899
|
+
// local view of the chain is ahead of L1 (proposed parent hasn't landed yet, or someone
|
|
900
|
+
// else has just landed the slot, or the archive override doesn't match). We log a warn and
|
|
901
|
+
// skip the proposal; we do NOT treat these as bugs.
|
|
902
|
+
const expectedErrors = [
|
|
837
903
|
'SlotAlreadyInChain',
|
|
838
904
|
'InvalidProposer',
|
|
839
905
|
'InvalidArchive'
|
|
840
906
|
];
|
|
841
|
-
const
|
|
842
|
-
const
|
|
843
|
-
return this.rollupContract.canProposeAt(tipArchive.toBuffer(), msgSender.toString(), this.
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
if (err instanceof FormattedViemError && ignoredErrors.find((e)=>err.message.includes(e))) {
|
|
847
|
-
this.log.warn(`Failed canProposeAtTime check with ${ignoredErrors.find((e)=>err.message.includes(e))}`, {
|
|
907
|
+
const slotOffset = this.aztecSlotDuration;
|
|
908
|
+
const nextL1SlotTs = this.getNextL1SlotTimestamp() + slotOffset;
|
|
909
|
+
return this.rollupContract.canProposeAt(tipArchive.toBuffer(), msgSender.toString(), nextL1SlotTs, await buildSimulationOverridesStateOverride(this.rollupContract, simulationOverridesPlan)).catch((err)=>{
|
|
910
|
+
if (err instanceof FormattedViemError && expectedErrors.find((e)=>err.message.includes(e))) {
|
|
911
|
+
this.log.warn(`Failed canProposeAtTime check with ${expectedErrors.find((e)=>err.message.includes(e))}`, {
|
|
848
912
|
error: err.message
|
|
849
913
|
});
|
|
850
914
|
} else {
|
|
@@ -858,22 +922,23 @@ export class SequencerPublisher {
|
|
|
858
922
|
* @dev This is a convenience function that can be used by the sequencer to validate a "partial" header.
|
|
859
923
|
* It will throw if the block header is invalid.
|
|
860
924
|
* @param header - The block header to validate
|
|
861
|
-
*/ async validateBlockHeader(header,
|
|
925
|
+
*/ async validateBlockHeader(header, simulationOverridesPlan) {
|
|
862
926
|
const flags = {
|
|
863
927
|
ignoreDA: true,
|
|
864
928
|
ignoreSignatures: true
|
|
865
929
|
};
|
|
866
930
|
const args = [
|
|
867
931
|
header.toViem(),
|
|
868
|
-
CommitteeAttestationsAndSigners.
|
|
932
|
+
CommitteeAttestationsAndSigners.packAttestations([]),
|
|
869
933
|
[],
|
|
870
934
|
Signature.empty().toViemSignature(),
|
|
871
935
|
`0x${'0'.repeat(64)}`,
|
|
872
936
|
header.blobsHash.toString(),
|
|
873
937
|
flags
|
|
874
938
|
];
|
|
875
|
-
const
|
|
876
|
-
const
|
|
939
|
+
const l1Constants = this.epochCache.getL1Constants();
|
|
940
|
+
const ts = getLastL1SlotTimestampForL2Slot(header.slotNumber, l1Constants);
|
|
941
|
+
const stateOverrides = await buildSimulationOverridesStateOverride(this.rollupContract, simulationOverridesPlan);
|
|
877
942
|
let balance = 0n;
|
|
878
943
|
if (this.config.fishermanMode) {
|
|
879
944
|
// In fisherman mode, we can't know where the proposer is publishing from
|
|
@@ -895,7 +960,7 @@ export class SequencerPublisher {
|
|
|
895
960
|
}),
|
|
896
961
|
from: MULTI_CALL_3_ADDRESS
|
|
897
962
|
}, {
|
|
898
|
-
time: ts
|
|
963
|
+
time: ts
|
|
899
964
|
}, stateOverrides);
|
|
900
965
|
this.log.debug(`Simulated validateHeader`);
|
|
901
966
|
}
|
|
@@ -941,6 +1006,7 @@ export class SequencerPublisher {
|
|
|
941
1006
|
gasUsed,
|
|
942
1007
|
checkpointNumber,
|
|
943
1008
|
forcePendingCheckpointNumber: CheckpointNumber(checkpointNumber - 1),
|
|
1009
|
+
lastArchive: validationResult.checkpoint.lastArchive,
|
|
944
1010
|
reason
|
|
945
1011
|
};
|
|
946
1012
|
} catch (err) {
|
|
@@ -953,8 +1019,8 @@ export class SequencerPublisher {
|
|
|
953
1019
|
request,
|
|
954
1020
|
error: viemError.message
|
|
955
1021
|
});
|
|
956
|
-
const
|
|
957
|
-
if (
|
|
1022
|
+
const latestProposedCheckpointNumber = await this.rollupContract.getCheckpointNumber();
|
|
1023
|
+
if (latestProposedCheckpointNumber < checkpointNumber) {
|
|
958
1024
|
this.log.verbose(`Checkpoint ${checkpointNumber} has already been invalidated`, {
|
|
959
1025
|
...logData
|
|
960
1026
|
});
|
|
@@ -1004,7 +1070,7 @@ export class SequencerPublisher {
|
|
|
1004
1070
|
reason
|
|
1005
1071
|
};
|
|
1006
1072
|
this.log.debug(`Building invalidate checkpoint ${checkpoint.checkpointNumber} request`, logData);
|
|
1007
|
-
const attestationsAndSigners =
|
|
1073
|
+
const attestationsAndSigners = CommitteeAttestationsAndSigners.packAttestations(validationResult.attestations);
|
|
1008
1074
|
if (reason === 'invalid-attestation') {
|
|
1009
1075
|
return this.rollupContract.buildInvalidateBadAttestationRequest(checkpoint.checkpointNumber, attestationsAndSigners, committee, validationResult.invalidIndex);
|
|
1010
1076
|
} else if (reason === 'insufficient-attestations') {
|
|
@@ -1014,30 +1080,7 @@ export class SequencerPublisher {
|
|
|
1014
1080
|
throw new Error(`Unknown reason for invalidation`);
|
|
1015
1081
|
}
|
|
1016
1082
|
}
|
|
1017
|
-
|
|
1018
|
-
// Anchor the simulation timestamp to the checkpoint's own slot start time
|
|
1019
|
-
// rather than the current L1 block timestamp, which may overshoot into the next slot if the build ran late.
|
|
1020
|
-
const ts = checkpoint.header.timestamp;
|
|
1021
|
-
const blobFields = checkpoint.toBlobFields();
|
|
1022
|
-
const blobs = await getBlobsPerL1Block(blobFields);
|
|
1023
|
-
const blobInput = getPrefixedEthBlobCommitments(blobs);
|
|
1024
|
-
const args = [
|
|
1025
|
-
{
|
|
1026
|
-
header: checkpoint.header.toViem(),
|
|
1027
|
-
archive: toHex(checkpoint.archive.root.toBuffer()),
|
|
1028
|
-
oracleInput: {
|
|
1029
|
-
feeAssetPriceModifier: checkpoint.feeAssetPriceModifier
|
|
1030
|
-
}
|
|
1031
|
-
},
|
|
1032
|
-
attestationsAndSigners.getPackedAttestations(),
|
|
1033
|
-
attestationsAndSigners.getSigners().map((signer)=>signer.toString()),
|
|
1034
|
-
attestationsAndSignersSignature.toViemSignature(),
|
|
1035
|
-
blobInput
|
|
1036
|
-
];
|
|
1037
|
-
await this.simulateProposeTx(args, ts, options);
|
|
1038
|
-
return ts;
|
|
1039
|
-
}
|
|
1040
|
-
async enqueueCastSignalHelper(slotNumber, timestamp, signalType, payload, base, signerAddress, signer) {
|
|
1083
|
+
async enqueueCastSignalHelper(slotNumber, signalType, payload, base, signerAddress, signer) {
|
|
1041
1084
|
if (this.lastActions[signalType] && this.lastActions[signalType] === slotNumber) {
|
|
1042
1085
|
this.log.debug(`Skipping duplicate vote cast signal ${signalType} for slot ${slotNumber}`);
|
|
1043
1086
|
return false;
|
|
@@ -1057,30 +1100,26 @@ export class SequencerPublisher {
|
|
|
1057
1100
|
if (roundInfo.lastSignalSlot >= slotNumber) {
|
|
1058
1101
|
return false;
|
|
1059
1102
|
}
|
|
1060
|
-
if (await
|
|
1103
|
+
if (await base.isPayloadEmpty(payload)) {
|
|
1061
1104
|
this.log.warn(`Skipping vote cast for payload with empty code`);
|
|
1062
1105
|
return false;
|
|
1063
1106
|
}
|
|
1064
|
-
//
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
} catch (err) {
|
|
1078
|
-
this.log.warn(`Failed to check if payload ${payload} was proposed after retries, skipping signal`, err);
|
|
1079
|
-
return false;
|
|
1080
|
-
}
|
|
1107
|
+
// Skip signaling if there is already a live (non-terminal) Governance proposal for this
|
|
1108
|
+
// payload. This is intentionally not cached: a previously-live proposal may transition to
|
|
1109
|
+
// a terminal state (Dropped/Rejected/Expired/Executed), at which point we may want to re-signal
|
|
1110
|
+
// the same payload in a future round.
|
|
1111
|
+
let proposed = false;
|
|
1112
|
+
try {
|
|
1113
|
+
proposed = await base.hasActiveProposalWithPayload(payload.toString());
|
|
1114
|
+
} catch (err) {
|
|
1115
|
+
// We deliberately swallow the error and proceed to signal. Failing closed (skipping the
|
|
1116
|
+
// signal) on transient RPC errors would let a flaky L1 endpoint silence governance
|
|
1117
|
+
// participation entirely; failing open at worst produces a duplicate signal that the
|
|
1118
|
+
// contract will simply count alongside others in the round.
|
|
1119
|
+
this.log.error(`Failed to check if payload ${payload} was already proposed (signalling anyway)`, err);
|
|
1081
1120
|
}
|
|
1082
|
-
if (
|
|
1083
|
-
this.log.info(`Payload ${payload}
|
|
1121
|
+
if (proposed) {
|
|
1122
|
+
this.log.info(`Payload ${payload} has a live governance proposal, stopping signals`);
|
|
1084
1123
|
return false;
|
|
1085
1124
|
}
|
|
1086
1125
|
const cachedLastVote = this.lastActions[signalType];
|
|
@@ -1093,53 +1132,17 @@ export class SequencerPublisher {
|
|
|
1093
1132
|
signer: this.l1TxUtils.client.account?.address,
|
|
1094
1133
|
lastValidL2Slot: slotNumber
|
|
1095
1134
|
});
|
|
1096
|
-
const l1BlockNumber = await this.l1TxUtils.getBlockNumber();
|
|
1097
|
-
try {
|
|
1098
|
-
await this.l1TxUtils.simulate(request, {
|
|
1099
|
-
time: timestamp
|
|
1100
|
-
}, [], mergeAbis([
|
|
1101
|
-
request.abi ?? [],
|
|
1102
|
-
ErrorsAbi
|
|
1103
|
-
]));
|
|
1104
|
-
this.log.debug(`Simulation for ${action} at slot ${slotNumber} succeeded`, {
|
|
1105
|
-
request
|
|
1106
|
-
});
|
|
1107
|
-
} catch (err) {
|
|
1108
|
-
const viemError = formatViemError(err);
|
|
1109
|
-
this.log.error(`Failed simulation for ${action} at slot ${slotNumber} (enqueuing the action anyway)`, viemError);
|
|
1110
|
-
this.backupFailedTx({
|
|
1111
|
-
id: keccak256(request.data),
|
|
1112
|
-
failureType: 'simulation',
|
|
1113
|
-
request: {
|
|
1114
|
-
to: request.to,
|
|
1115
|
-
data: request.data,
|
|
1116
|
-
value: request.value?.toString()
|
|
1117
|
-
},
|
|
1118
|
-
l1BlockNumber: l1BlockNumber.toString(),
|
|
1119
|
-
error: {
|
|
1120
|
-
message: viemError.message,
|
|
1121
|
-
name: viemError.name
|
|
1122
|
-
},
|
|
1123
|
-
context: {
|
|
1124
|
-
actions: [
|
|
1125
|
-
action
|
|
1126
|
-
],
|
|
1127
|
-
slot: slotNumber,
|
|
1128
|
-
sender: this.getSenderAddress().toString()
|
|
1129
|
-
}
|
|
1130
|
-
});
|
|
1131
|
-
// Yes, we enqueue the request anyway, in case there was a bug with the simulation itself
|
|
1132
|
-
}
|
|
1133
1135
|
// TODO(palla/slash): All votes (governance and slashing) should txTimeoutAt at the end of the slot.
|
|
1134
1136
|
this.addRequest({
|
|
1135
|
-
gasConfig: {
|
|
1136
|
-
gasLimit: SequencerPublisher.VOTE_GAS_GUESS
|
|
1137
|
-
},
|
|
1138
1137
|
action,
|
|
1139
1138
|
request,
|
|
1140
1139
|
lastValidL2Slot: slotNumber,
|
|
1141
1140
|
checkSuccess: (_request, result)=>{
|
|
1142
|
-
const success = result &&
|
|
1141
|
+
const success = result && extractEventSuccess(result.receipt, {
|
|
1142
|
+
address: base.address.toString(),
|
|
1143
|
+
abi: EmpireBaseAbi,
|
|
1144
|
+
eventName: 'SignalCast'
|
|
1145
|
+
});
|
|
1143
1146
|
const logData = {
|
|
1144
1147
|
...result,
|
|
1145
1148
|
slotNumber,
|
|
@@ -1158,68 +1161,70 @@ export class SequencerPublisher {
|
|
|
1158
1161
|
});
|
|
1159
1162
|
return true;
|
|
1160
1163
|
}
|
|
1161
|
-
async isPayloadEmpty(payload) {
|
|
1162
|
-
const key = payload.toString();
|
|
1163
|
-
const cached = this.isPayloadEmptyCache.get(key);
|
|
1164
|
-
if (cached) {
|
|
1165
|
-
return cached;
|
|
1166
|
-
}
|
|
1167
|
-
const isEmpty = !await this.l1TxUtils.getCode(payload);
|
|
1168
|
-
this.isPayloadEmptyCache.set(key, isEmpty);
|
|
1169
|
-
return isEmpty;
|
|
1170
|
-
}
|
|
1171
1164
|
/**
|
|
1172
1165
|
* Enqueues a governance castSignal transaction to cast a signal for a given slot number.
|
|
1173
1166
|
* @param slotNumber - The slot number to cast a signal for.
|
|
1174
|
-
* @param timestamp - The timestamp of the slot to cast a signal for.
|
|
1175
1167
|
* @returns True if the signal was successfully enqueued, false otherwise.
|
|
1176
|
-
*/ enqueueGovernanceCastSignal(governancePayload, slotNumber,
|
|
1177
|
-
return this.enqueueCastSignalHelper(slotNumber,
|
|
1168
|
+
*/ enqueueGovernanceCastSignal(governancePayload, slotNumber, signerAddress, signer) {
|
|
1169
|
+
return this.enqueueCastSignalHelper(slotNumber, 'governance-signal', governancePayload, this.govProposerContract, signerAddress, signer);
|
|
1178
1170
|
}
|
|
1179
|
-
/**
|
|
1171
|
+
/**
|
|
1172
|
+
* Enqueues a `prune()` transaction if the rollup is prunable at the given slot's L1 timestamp.
|
|
1173
|
+
* `prune()` is permissionless and idempotent — if the chain is no longer prunable by send time the
|
|
1174
|
+
* bundle simulation usually drops the entry; on a node without `eth_simulateV1` the bundle is sent
|
|
1175
|
+
* as-is and the prune reverts `Rollup__NothingToPrune` inside `aggregate3(allowFailure: true)`
|
|
1176
|
+
* (a failed action, never a whole-tx revert). Used by the failed-sync fallback so a stuck pending
|
|
1177
|
+
* chain (e.g. bad data blocking sync) can be wound back to recover.
|
|
1178
|
+
* @returns true if a prune request was enqueued, false otherwise.
|
|
1179
|
+
*/ async enqueuePruneIfPrunable(slotNumber) {
|
|
1180
|
+
if (this.lastActions['prune'] === slotNumber) {
|
|
1181
|
+
this.log.debug(`Skipping duplicate prune for slot ${slotNumber}`, {
|
|
1182
|
+
slotNumber
|
|
1183
|
+
});
|
|
1184
|
+
return false;
|
|
1185
|
+
}
|
|
1186
|
+
// Use the SAME timestamp the bundle simulator overrides block.timestamp with at send time
|
|
1187
|
+
// (sequencer-bundle-simulator.ts) so this upfront check and the send-time sim agree. Slot-start
|
|
1188
|
+
// and last-L1-slot both fall within the same L2 slot (and epoch, which is what `canPruneAtTime`
|
|
1189
|
+
// derives), so they agree today; matching the simulator keeps it robust if the contract ever uses
|
|
1190
|
+
// the timestamp more granularly.
|
|
1191
|
+
const ts = getLastL1SlotTimestampForL2Slot(slotNumber, this.epochCache.getL1Constants());
|
|
1192
|
+
const canPrune = await this.rollupContract.canPruneAtTime(ts).catch((err)=>{
|
|
1193
|
+
this.log.error(`Failed to check canPruneAtTime for slot ${slotNumber}`, err, {
|
|
1194
|
+
slotNumber
|
|
1195
|
+
});
|
|
1196
|
+
return false;
|
|
1197
|
+
});
|
|
1198
|
+
if (!canPrune) {
|
|
1199
|
+
this.log.debug(`Rollup not prunable at slot ${slotNumber}`, {
|
|
1200
|
+
slotNumber
|
|
1201
|
+
});
|
|
1202
|
+
return false;
|
|
1203
|
+
}
|
|
1204
|
+
const request = {
|
|
1205
|
+
to: this.rollupContract.address,
|
|
1206
|
+
data: encodeFunctionData({
|
|
1207
|
+
abi: RollupAbi,
|
|
1208
|
+
functionName: 'prune',
|
|
1209
|
+
args: []
|
|
1210
|
+
})
|
|
1211
|
+
};
|
|
1212
|
+
this.log.info(`Enqueuing rollup prune for slot ${slotNumber}`, {
|
|
1213
|
+
slotNumber
|
|
1214
|
+
});
|
|
1215
|
+
return this.enqueueRequest('prune', request, {
|
|
1216
|
+
address: this.rollupContract.address,
|
|
1217
|
+
abi: RollupAbi,
|
|
1218
|
+
eventName: 'PrunedPending'
|
|
1219
|
+
}, slotNumber);
|
|
1220
|
+
}
|
|
1221
|
+
/** Enqueues all slashing actions as returned by the slasher client. */ async enqueueSlashingActions(actions, slotNumber, signerAddress, signer) {
|
|
1180
1222
|
if (actions.length === 0) {
|
|
1181
1223
|
this.log.debug(`No slashing actions to enqueue for slot ${slotNumber}`);
|
|
1182
1224
|
return false;
|
|
1183
1225
|
}
|
|
1184
1226
|
for (const action of actions){
|
|
1185
1227
|
switch(action.type){
|
|
1186
|
-
case 'vote-empire-payload':
|
|
1187
|
-
{
|
|
1188
|
-
if (this.slashingProposerContract?.type !== 'empire') {
|
|
1189
|
-
this.log.error('Cannot vote for empire payload on non-empire slashing contract');
|
|
1190
|
-
break;
|
|
1191
|
-
}
|
|
1192
|
-
this.log.debug(`Enqueuing slashing vote for payload ${action.payload} at slot ${slotNumber}`, {
|
|
1193
|
-
signerAddress
|
|
1194
|
-
});
|
|
1195
|
-
await this.enqueueCastSignalHelper(slotNumber, timestamp, 'empire-slashing-signal', action.payload, this.slashingProposerContract, signerAddress, signer);
|
|
1196
|
-
break;
|
|
1197
|
-
}
|
|
1198
|
-
case 'create-empire-payload':
|
|
1199
|
-
{
|
|
1200
|
-
this.log.debug(`Enqueuing slashing create payload at slot ${slotNumber}`, {
|
|
1201
|
-
slotNumber,
|
|
1202
|
-
signerAddress
|
|
1203
|
-
});
|
|
1204
|
-
const request = this.slashFactoryContract.buildCreatePayloadRequest(action.data);
|
|
1205
|
-
await this.simulateAndEnqueueRequest('create-empire-payload', request, (receipt)=>!!this.slashFactoryContract.tryExtractSlashPayloadCreatedEvent(receipt.logs), slotNumber, timestamp);
|
|
1206
|
-
break;
|
|
1207
|
-
}
|
|
1208
|
-
case 'execute-empire-payload':
|
|
1209
|
-
{
|
|
1210
|
-
this.log.debug(`Enqueuing slashing execute payload at slot ${slotNumber}`, {
|
|
1211
|
-
slotNumber,
|
|
1212
|
-
signerAddress
|
|
1213
|
-
});
|
|
1214
|
-
if (this.slashingProposerContract?.type !== 'empire') {
|
|
1215
|
-
this.log.error('Cannot execute slashing payload on non-empire slashing contract');
|
|
1216
|
-
return false;
|
|
1217
|
-
}
|
|
1218
|
-
const empireSlashingProposer = this.slashingProposerContract;
|
|
1219
|
-
const request = empireSlashingProposer.buildExecuteRoundRequest(action.round);
|
|
1220
|
-
await this.simulateAndEnqueueRequest('execute-empire-payload', request, (receipt)=>!!empireSlashingProposer.tryExtractPayloadSubmittedEvent(receipt.logs), slotNumber, timestamp);
|
|
1221
|
-
break;
|
|
1222
|
-
}
|
|
1223
1228
|
case 'vote-offenses':
|
|
1224
1229
|
{
|
|
1225
1230
|
this.log.debug(`Enqueuing slashing vote for ${action.votes.length} votes at slot ${slotNumber}`, {
|
|
@@ -1228,14 +1233,17 @@ export class SequencerPublisher {
|
|
|
1228
1233
|
votesCount: action.votes.length,
|
|
1229
1234
|
signerAddress
|
|
1230
1235
|
});
|
|
1231
|
-
if (this.slashingProposerContract
|
|
1232
|
-
this.log.error('
|
|
1236
|
+
if (!this.slashingProposerContract) {
|
|
1237
|
+
this.log.error('No slashing proposer contract available');
|
|
1233
1238
|
return false;
|
|
1234
1239
|
}
|
|
1235
|
-
const tallySlashingProposer = this.slashingProposerContract;
|
|
1236
1240
|
const votes = bufferToHex(encodeSlashConsensusVotes(action.votes));
|
|
1237
|
-
const request = await
|
|
1238
|
-
|
|
1241
|
+
const request = await this.slashingProposerContract.buildVoteRequestFromSigner(votes, slotNumber, signer);
|
|
1242
|
+
this.enqueueRequest('vote-offenses', request, {
|
|
1243
|
+
address: this.slashingProposerContract.address.toString(),
|
|
1244
|
+
abi: SlashingProposerAbi,
|
|
1245
|
+
eventName: 'VoteCast'
|
|
1246
|
+
}, slotNumber);
|
|
1239
1247
|
break;
|
|
1240
1248
|
}
|
|
1241
1249
|
case 'execute-slash':
|
|
@@ -1245,13 +1253,16 @@ export class SequencerPublisher {
|
|
|
1245
1253
|
round: action.round,
|
|
1246
1254
|
signerAddress
|
|
1247
1255
|
});
|
|
1248
|
-
if (this.slashingProposerContract
|
|
1249
|
-
this.log.error('
|
|
1256
|
+
if (!this.slashingProposerContract) {
|
|
1257
|
+
this.log.error('No slashing proposer contract available');
|
|
1250
1258
|
return false;
|
|
1251
1259
|
}
|
|
1252
|
-
const
|
|
1253
|
-
|
|
1254
|
-
|
|
1260
|
+
const executeRequest = this.slashingProposerContract.buildExecuteRoundRequest(action.round, action.committees);
|
|
1261
|
+
this.enqueueRequest('execute-slash', executeRequest, {
|
|
1262
|
+
address: this.slashingProposerContract.address.toString(),
|
|
1263
|
+
abi: SlashingProposerAbi,
|
|
1264
|
+
eventName: 'RoundExecuted'
|
|
1265
|
+
}, slotNumber);
|
|
1255
1266
|
break;
|
|
1256
1267
|
}
|
|
1257
1268
|
default:
|
|
@@ -1263,7 +1274,7 @@ export class SequencerPublisher {
|
|
|
1263
1274
|
}
|
|
1264
1275
|
return true;
|
|
1265
1276
|
}
|
|
1266
|
-
/**
|
|
1277
|
+
/** Enqueues a proposal for a checkpoint on L1 */ async enqueueProposeCheckpoint(checkpoint, attestationsAndSigners, attestationsAndSignersSignature, opts = {}) {
|
|
1267
1278
|
const checkpointHeader = checkpoint.header;
|
|
1268
1279
|
const blobFields = checkpoint.toBlobFields();
|
|
1269
1280
|
const blobs = await getBlobsPerL1Block(blobFields);
|
|
@@ -1275,52 +1286,38 @@ export class SequencerPublisher {
|
|
|
1275
1286
|
attestationsAndSignersSignature,
|
|
1276
1287
|
feeAssetPriceModifier: checkpoint.feeAssetPriceModifier
|
|
1277
1288
|
};
|
|
1278
|
-
let ts;
|
|
1279
|
-
try {
|
|
1280
|
-
// @note This will make sure that we are passing the checks for our header ASSUMING that the data is also made available
|
|
1281
|
-
// This means that we can avoid the simulation issues in later checks.
|
|
1282
|
-
// By simulation issue, I mean the fact that the block.timestamp is equal to the last block, not the next, which
|
|
1283
|
-
// make time consistency checks break.
|
|
1284
|
-
// TODO(palla): Check whether we're validating twice, once here and once within addProposeTx, since we call simulateProposeTx in both places.
|
|
1285
|
-
ts = await this.validateCheckpointForSubmission(checkpoint, attestationsAndSigners, attestationsAndSignersSignature, opts);
|
|
1286
|
-
} catch (err) {
|
|
1287
|
-
this.log.error(`Checkpoint validation failed. ${err instanceof Error ? err.message : 'No error message'}`, err, {
|
|
1288
|
-
...checkpoint.getStats(),
|
|
1289
|
-
slotNumber: checkpoint.header.slotNumber,
|
|
1290
|
-
forcePendingCheckpointNumber: opts.forcePendingCheckpointNumber
|
|
1291
|
-
});
|
|
1292
|
-
throw err;
|
|
1293
|
-
}
|
|
1294
1289
|
this.log.verbose(`Enqueuing checkpoint propose transaction`, {
|
|
1295
1290
|
...checkpoint.toCheckpointInfo(),
|
|
1296
|
-
|
|
1291
|
+
txTimeoutAt: opts.txTimeoutAt
|
|
1292
|
+
});
|
|
1293
|
+
await this.addProposeTx(checkpoint, proposeTxArgs, {
|
|
1294
|
+
txTimeoutAt: opts.txTimeoutAt
|
|
1297
1295
|
});
|
|
1298
|
-
await this.addProposeTx(checkpoint, proposeTxArgs, opts, ts);
|
|
1299
1296
|
}
|
|
1300
1297
|
enqueueInvalidateCheckpoint(request, opts = {}) {
|
|
1301
1298
|
if (!request) {
|
|
1302
1299
|
return;
|
|
1303
1300
|
}
|
|
1304
|
-
// We issued the simulation against the rollup contract, so we need to account for the overhead of the multicall3
|
|
1305
|
-
const gasLimit = this.l1TxUtils.bumpGasLimit(BigInt(Math.ceil(Number(request.gasUsed) * 64 / 63)));
|
|
1306
1301
|
const { gasUsed, checkpointNumber } = request;
|
|
1307
1302
|
const logData = {
|
|
1308
1303
|
gasUsed,
|
|
1309
1304
|
checkpointNumber,
|
|
1310
|
-
gasLimit,
|
|
1311
1305
|
opts
|
|
1312
1306
|
};
|
|
1313
1307
|
this.log.verbose(`Enqueuing invalidate checkpoint request`, logData);
|
|
1314
1308
|
this.addRequest({
|
|
1315
1309
|
action: `invalidate-by-${request.reason}`,
|
|
1316
1310
|
request: request.request,
|
|
1317
|
-
gasConfig: {
|
|
1318
|
-
gasLimit,
|
|
1311
|
+
gasConfig: opts.txTimeoutAt ? {
|
|
1319
1312
|
txTimeoutAt: opts.txTimeoutAt
|
|
1320
|
-
},
|
|
1313
|
+
} : undefined,
|
|
1321
1314
|
lastValidL2Slot: SlotNumber(this.getCurrentL2Slot() + 2),
|
|
1322
1315
|
checkSuccess: (_req, result)=>{
|
|
1323
|
-
const success = result &&
|
|
1316
|
+
const success = result && extractEventSuccess(result.receipt, {
|
|
1317
|
+
address: this.rollupContract.address,
|
|
1318
|
+
abi: RollupAbi,
|
|
1319
|
+
eventName: 'CheckpointInvalidated'
|
|
1320
|
+
});
|
|
1324
1321
|
if (!success) {
|
|
1325
1322
|
this.log.warn(`Invalidate checkpoint ${request.checkpointNumber} failed`, {
|
|
1326
1323
|
...result,
|
|
@@ -1336,89 +1333,36 @@ export class SequencerPublisher {
|
|
|
1336
1333
|
}
|
|
1337
1334
|
});
|
|
1338
1335
|
}
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
};
|
|
1336
|
+
/**
|
|
1337
|
+
* Dedup-checked enqueue helper for actions that are simulated at bundle-send time rather
|
|
1338
|
+
* than at enqueue time. Validates the (action, slot) dedup key, sets `lastActions`, and
|
|
1339
|
+
* enqueues without a gasLimit so the bundle simulate sets the only gasLimit that matters.
|
|
1340
|
+
*/ enqueueRequest(action, request, eventOpts, slotNumber) {
|
|
1345
1341
|
if (this.lastActions[action] && this.lastActions[action] === slotNumber) {
|
|
1346
1342
|
this.log.debug(`Skipping duplicate action ${action} for slot ${slotNumber}`);
|
|
1347
1343
|
return false;
|
|
1348
1344
|
}
|
|
1349
1345
|
const cachedLastActionSlot = this.lastActions[action];
|
|
1350
1346
|
this.lastActions[action] = slotNumber;
|
|
1351
|
-
this.log.debug(`
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
const simulateAbi = mergeAbis([
|
|
1355
|
-
request.abi ?? [],
|
|
1356
|
-
ErrorsAbi
|
|
1357
|
-
]);
|
|
1358
|
-
try {
|
|
1359
|
-
({ gasUsed } = await this.l1TxUtils.simulate(request, {
|
|
1360
|
-
time: timestamp
|
|
1361
|
-
}, [], simulateAbi)); // TODO(palla/slash): Check the timestamp logic
|
|
1362
|
-
this.log.verbose(`Simulation for ${action} succeeded`, {
|
|
1363
|
-
...logData,
|
|
1364
|
-
request,
|
|
1365
|
-
gasUsed
|
|
1366
|
-
});
|
|
1367
|
-
} catch (err) {
|
|
1368
|
-
const viemError = formatViemError(err, simulateAbi);
|
|
1369
|
-
this.log.error(`Simulation for ${action} at ${slotNumber} failed`, viemError, logData);
|
|
1370
|
-
this.backupFailedTx({
|
|
1371
|
-
id: keccak256(request.data),
|
|
1372
|
-
failureType: 'simulation',
|
|
1373
|
-
request: {
|
|
1374
|
-
to: request.to,
|
|
1375
|
-
data: request.data,
|
|
1376
|
-
value: request.value?.toString()
|
|
1377
|
-
},
|
|
1378
|
-
l1BlockNumber: l1BlockNumber.toString(),
|
|
1379
|
-
error: {
|
|
1380
|
-
message: viemError.message,
|
|
1381
|
-
name: viemError.name
|
|
1382
|
-
},
|
|
1383
|
-
context: {
|
|
1384
|
-
actions: [
|
|
1385
|
-
action
|
|
1386
|
-
],
|
|
1387
|
-
slot: slotNumber,
|
|
1388
|
-
sender: this.getSenderAddress().toString()
|
|
1389
|
-
}
|
|
1390
|
-
});
|
|
1391
|
-
return false;
|
|
1392
|
-
}
|
|
1393
|
-
// We issued the simulation against the rollup contract, so we need to account for the overhead of the multicall3
|
|
1394
|
-
const gasLimit = this.l1TxUtils.bumpGasLimit(BigInt(Math.ceil(Number(gasUsed) * 64 / 63)));
|
|
1395
|
-
logData.gasLimit = gasLimit;
|
|
1396
|
-
// Store the ABI used for simulation on the request so Multicall3.forward can decode errors
|
|
1397
|
-
// when the tx is sent and a revert is diagnosed via simulation.
|
|
1398
|
-
const requestWithAbi = {
|
|
1399
|
-
...request,
|
|
1400
|
-
abi: simulateAbi
|
|
1401
|
-
};
|
|
1402
|
-
this.log.debug(`Enqueuing ${action}`, logData);
|
|
1347
|
+
this.log.debug(`Enqueuing ${action}`, {
|
|
1348
|
+
slotNumber
|
|
1349
|
+
});
|
|
1403
1350
|
this.addRequest({
|
|
1404
1351
|
action,
|
|
1405
|
-
request
|
|
1406
|
-
gasConfig: {
|
|
1407
|
-
gasLimit
|
|
1408
|
-
},
|
|
1352
|
+
request,
|
|
1409
1353
|
lastValidL2Slot: slotNumber,
|
|
1410
|
-
checkSuccess: (
|
|
1411
|
-
const success = result && result.receipt
|
|
1354
|
+
checkSuccess: (_request, result)=>{
|
|
1355
|
+
const success = result && extractEventSuccess(result.receipt, eventOpts);
|
|
1412
1356
|
if (!success) {
|
|
1413
1357
|
this.log.warn(`Action ${action} at ${slotNumber} failed`, {
|
|
1414
1358
|
...result,
|
|
1415
|
-
|
|
1359
|
+
slotNumber
|
|
1416
1360
|
});
|
|
1417
1361
|
this.lastActions[action] = cachedLastActionSlot;
|
|
1418
1362
|
} else {
|
|
1419
1363
|
this.log.info(`Action ${action} at ${slotNumber} succeeded`, {
|
|
1420
1364
|
...result,
|
|
1421
|
-
|
|
1365
|
+
slotNumber
|
|
1422
1366
|
});
|
|
1423
1367
|
}
|
|
1424
1368
|
return !!success;
|
|
@@ -1433,13 +1377,14 @@ export class SequencerPublisher {
|
|
|
1433
1377
|
* A call to `restart` is required before you can continue publishing.
|
|
1434
1378
|
*/ interrupt() {
|
|
1435
1379
|
this.interrupted = true;
|
|
1380
|
+
this.interruptibleSleep.interrupt();
|
|
1436
1381
|
this.l1TxUtils.interrupt();
|
|
1437
1382
|
}
|
|
1438
1383
|
/** Restarts the publisher after calling `interrupt`. */ restart() {
|
|
1439
1384
|
this.interrupted = false;
|
|
1440
1385
|
this.l1TxUtils.restart();
|
|
1441
1386
|
}
|
|
1442
|
-
async prepareProposeTx(encodedData
|
|
1387
|
+
async prepareProposeTx(encodedData) {
|
|
1443
1388
|
const kzg = Blob.getViemKzgInstance();
|
|
1444
1389
|
const blobInput = getPrefixedEthBlobCommitments(encodedData.blobs);
|
|
1445
1390
|
this.log.debug('Validating blob input', {
|
|
@@ -1453,7 +1398,11 @@ export class SequencerPublisher {
|
|
|
1453
1398
|
blobEvaluationGas = BigInt(encodedData.blobs.length) * 21_000n;
|
|
1454
1399
|
this.log.debug(`Using fixed blob evaluation gas estimate in fisherman mode: ${blobEvaluationGas}`);
|
|
1455
1400
|
} else {
|
|
1456
|
-
//
|
|
1401
|
+
// We call validateBlobs via estimateGas with real blob+kzg sidecars as a consistency check
|
|
1402
|
+
// that our locally-built blob commitments match the blob data. The bundle simulate at send
|
|
1403
|
+
// time uses eth_simulateV1, which cannot carry blob inputs, so the rollup's on-chain blob
|
|
1404
|
+
// check is forced off there — making this the only pre-flight detector of a commitment/data
|
|
1405
|
+
// mismatch. The returned gas estimate is stashed on the request for the bundle path to read.
|
|
1457
1406
|
blobEvaluationGas = await this.l1TxUtils.estimateGas(this.getSenderAddress().toString(), {
|
|
1458
1407
|
to: this.rollupContract.address,
|
|
1459
1408
|
data: encodeFunctionData({
|
|
@@ -1516,109 +1465,23 @@ export class SequencerPublisher {
|
|
|
1516
1465
|
encodedData.attestationsAndSignersSignature.toViemSignature(),
|
|
1517
1466
|
blobInput
|
|
1518
1467
|
];
|
|
1519
|
-
const { rollupData, simulationResult } = await this.simulateProposeTx(args, timestamp, options);
|
|
1520
|
-
return {
|
|
1521
|
-
args,
|
|
1522
|
-
blobEvaluationGas,
|
|
1523
|
-
rollupData,
|
|
1524
|
-
simulationResult
|
|
1525
|
-
};
|
|
1526
|
-
}
|
|
1527
|
-
/**
|
|
1528
|
-
* Simulates the propose tx with eth_simulateV1
|
|
1529
|
-
* @param args - The propose tx args
|
|
1530
|
-
* @param timestamp - The timestamp to simulate proposal at
|
|
1531
|
-
* @returns The simulation result
|
|
1532
|
-
*/ async simulateProposeTx(args, timestamp, options) {
|
|
1533
1468
|
const rollupData = encodeFunctionData({
|
|
1534
1469
|
abi: RollupAbi,
|
|
1535
1470
|
functionName: 'propose',
|
|
1536
1471
|
args
|
|
1537
1472
|
});
|
|
1538
|
-
// override the pending checkpoint number if requested
|
|
1539
|
-
const forcePendingCheckpointNumberStateDiff = (options.forcePendingCheckpointNumber !== undefined ? await this.rollupContract.makePendingCheckpointNumberOverride(options.forcePendingCheckpointNumber) : []).flatMap((override)=>override.stateDiff ?? []);
|
|
1540
|
-
const stateOverrides = [
|
|
1541
|
-
{
|
|
1542
|
-
address: this.rollupContract.address,
|
|
1543
|
-
// @note we override checkBlob to false since blobs are not part simulate()
|
|
1544
|
-
stateDiff: [
|
|
1545
|
-
{
|
|
1546
|
-
slot: toPaddedHex(RollupContract.checkBlobStorageSlot, true),
|
|
1547
|
-
value: toPaddedHex(0n, true)
|
|
1548
|
-
},
|
|
1549
|
-
...forcePendingCheckpointNumberStateDiff
|
|
1550
|
-
]
|
|
1551
|
-
}
|
|
1552
|
-
];
|
|
1553
|
-
// In fisherman mode, simulate as the proposer but with sufficient balance
|
|
1554
|
-
if (this.proposerAddressForSimulation) {
|
|
1555
|
-
stateOverrides.push({
|
|
1556
|
-
address: this.proposerAddressForSimulation.toString(),
|
|
1557
|
-
balance: 10n * WEI_CONST * WEI_CONST
|
|
1558
|
-
});
|
|
1559
|
-
}
|
|
1560
|
-
const l1BlockNumber = await this.l1TxUtils.getBlockNumber();
|
|
1561
|
-
const simulationResult = await this.l1TxUtils.simulate({
|
|
1562
|
-
to: this.rollupContract.address,
|
|
1563
|
-
data: rollupData,
|
|
1564
|
-
gas: MAX_L1_TX_LIMIT,
|
|
1565
|
-
...this.proposerAddressForSimulation && {
|
|
1566
|
-
from: this.proposerAddressForSimulation.toString()
|
|
1567
|
-
}
|
|
1568
|
-
}, {
|
|
1569
|
-
// @note we add 1n to the timestamp because geth implementation doesn't like simulation timestamp to be equal to the current block timestamp
|
|
1570
|
-
time: timestamp + 1n,
|
|
1571
|
-
// @note reth should have a 30m gas limit per block but throws errors that this tx is beyond limit so we increase here
|
|
1572
|
-
gasLimit: MAX_L1_TX_LIMIT * 2n
|
|
1573
|
-
}, stateOverrides, RollupAbi, {
|
|
1574
|
-
// @note fallback gas estimate to use if the node doesn't support simulation API
|
|
1575
|
-
fallbackGasEstimate: MAX_L1_TX_LIMIT
|
|
1576
|
-
}).catch((err)=>{
|
|
1577
|
-
// In fisherman mode, we expect ValidatorSelection__MissingProposerSignature since fisherman doesn't have proposer signature
|
|
1578
|
-
const viemError = formatViemError(err);
|
|
1579
|
-
if (this.config.fishermanMode && viemError.message?.includes('ValidatorSelection__MissingProposerSignature')) {
|
|
1580
|
-
this.log.debug(`Ignoring expected ValidatorSelection__MissingProposerSignature error in fisherman mode`);
|
|
1581
|
-
// Return a minimal simulation result with the fallback gas estimate
|
|
1582
|
-
return {
|
|
1583
|
-
gasUsed: MAX_L1_TX_LIMIT,
|
|
1584
|
-
logs: []
|
|
1585
|
-
};
|
|
1586
|
-
}
|
|
1587
|
-
this.log.error(`Failed to simulate propose tx`, viemError);
|
|
1588
|
-
this.backupFailedTx({
|
|
1589
|
-
id: keccak256(rollupData),
|
|
1590
|
-
failureType: 'simulation',
|
|
1591
|
-
request: {
|
|
1592
|
-
to: this.rollupContract.address,
|
|
1593
|
-
data: rollupData
|
|
1594
|
-
},
|
|
1595
|
-
l1BlockNumber: l1BlockNumber.toString(),
|
|
1596
|
-
error: {
|
|
1597
|
-
message: viemError.message,
|
|
1598
|
-
name: viemError.name
|
|
1599
|
-
},
|
|
1600
|
-
context: {
|
|
1601
|
-
actions: [
|
|
1602
|
-
'propose'
|
|
1603
|
-
],
|
|
1604
|
-
slot: Number(args[0].header.slotNumber),
|
|
1605
|
-
sender: this.getSenderAddress().toString()
|
|
1606
|
-
}
|
|
1607
|
-
});
|
|
1608
|
-
throw err;
|
|
1609
|
-
});
|
|
1610
1473
|
return {
|
|
1611
|
-
|
|
1612
|
-
|
|
1474
|
+
args,
|
|
1475
|
+
blobEvaluationGas,
|
|
1476
|
+
rollupData
|
|
1613
1477
|
};
|
|
1614
1478
|
}
|
|
1615
|
-
async addProposeTx(checkpoint, encodedData, opts = {}
|
|
1479
|
+
async addProposeTx(checkpoint, encodedData, opts = {}) {
|
|
1616
1480
|
const slot = checkpoint.header.slotNumber;
|
|
1617
1481
|
const timer = new Timer();
|
|
1618
1482
|
const kzg = Blob.getViemKzgInstance();
|
|
1619
|
-
const { rollupData,
|
|
1483
|
+
const { rollupData, blobEvaluationGas } = await this.prepareProposeTx(encodedData);
|
|
1620
1484
|
const startBlock = await this.l1TxUtils.getBlockNumber();
|
|
1621
|
-
const gasLimit = this.l1TxUtils.bumpGasLimit(BigInt(Math.ceil(Number(simulationResult.gasUsed) * 64 / 63)) + blobEvaluationGas + SequencerPublisher.MULTICALL_OVERHEAD_GAS_GUESS);
|
|
1622
1485
|
// Send the blobs to the blob client preemptively. This helps in tests where the sequencer mistakingly thinks that the propose
|
|
1623
1486
|
// tx fails but it does get mined. We make sure that the blobs are sent to the blob client regardless of the tx outcome.
|
|
1624
1487
|
void Promise.resolve().then(()=>this.blobClient.sendBlobsToFilestore(encodedData.blobs).catch((_err)=>{
|
|
@@ -1632,9 +1495,10 @@ export class SequencerPublisher {
|
|
|
1632
1495
|
},
|
|
1633
1496
|
lastValidL2Slot: checkpoint.header.slotNumber,
|
|
1634
1497
|
gasConfig: {
|
|
1635
|
-
|
|
1636
|
-
gasLimit
|
|
1498
|
+
txTimeoutAt: opts.txTimeoutAt,
|
|
1499
|
+
gasLimit: undefined
|
|
1637
1500
|
},
|
|
1501
|
+
blobEvaluationGas,
|
|
1638
1502
|
blobConfig: {
|
|
1639
1503
|
blobs: encodedData.blobs.map((b)=>b.data),
|
|
1640
1504
|
kzg
|
|
@@ -1644,7 +1508,11 @@ export class SequencerPublisher {
|
|
|
1644
1508
|
return false;
|
|
1645
1509
|
}
|
|
1646
1510
|
const { receipt, stats, errorMsg } = result;
|
|
1647
|
-
const success =
|
|
1511
|
+
const success = extractEventSuccess(receipt, {
|
|
1512
|
+
address: this.rollupContract.address,
|
|
1513
|
+
abi: RollupAbi,
|
|
1514
|
+
eventName: 'CheckpointProposed'
|
|
1515
|
+
});
|
|
1648
1516
|
if (success) {
|
|
1649
1517
|
const endBlock = receipt.blockNumber;
|
|
1650
1518
|
const inclusionBlocks = Number(endBlock - startBlock);
|
|
@@ -1681,4 +1549,8 @@ export class SequencerPublisher {
|
|
|
1681
1549
|
}
|
|
1682
1550
|
});
|
|
1683
1551
|
}
|
|
1552
|
+
/** Returns the timestamp of the next L1 slot boundary after now. */ getNextL1SlotTimestamp() {
|
|
1553
|
+
const l1Constants = this.epochCache.getL1Constants();
|
|
1554
|
+
return getNextL1SlotTimestamp(this.dateProvider.nowInSeconds(), l1Constants);
|
|
1555
|
+
}
|
|
1684
1556
|
}
|