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