@aztec/sequencer-client 0.0.1-commit.f2ce05ee → 0.0.1-commit.f5a9928
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 +283 -21
- package/dest/client/sequencer-client.d.ts +34 -11
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +77 -39
- package/dest/config.d.ts +34 -5
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +103 -39
- 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 +13 -28
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +9 -66
- 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 +51 -17
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +131 -42
- package/dest/publisher/index.d.ts +2 -1
- package/dest/publisher/index.d.ts.map +1 -1
- 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/factory.d.ts +11 -0
- package/dest/publisher/l1_tx_failed_store/factory.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/factory.js +22 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +58 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.js +1 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts +15 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.js +34 -0
- package/dest/publisher/l1_tx_failed_store/index.d.ts +4 -0
- package/dest/publisher/l1_tx_failed_store/index.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/index.js +2 -0
- 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 +11 -5
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-factory.js +27 -3
- package/dest/publisher/sequencer-publisher.d.ts +112 -71
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +571 -392
- 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 +696 -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 +75 -19
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_proposal_job.js +886 -264
- 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 +62 -5
- package/dest/sequencer/events.d.ts.map +1 -1
- package/dest/sequencer/metrics.d.ts +23 -8
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +117 -21
- 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 +181 -44
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +635 -218
- package/dest/sequencer/types.d.ts +2 -2
- package/dest/sequencer/types.d.ts.map +1 -1
- package/dest/test/index.d.ts +5 -7
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.d.ts +11 -11
- package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.js +45 -34
- package/dest/test/utils.d.ts +17 -3
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +28 -9
- package/package.json +28 -28
- package/src/client/sequencer-client.ts +110 -47
- package/src/config.ts +126 -44
- 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 +20 -89
- package/src/global_variable_builder/index.ts +3 -1
- package/src/publisher/config.ts +173 -40
- package/src/publisher/index.ts +3 -0
- package/src/publisher/l1_to_l2_messaging.ts +85 -0
- package/src/publisher/l1_tx_failed_store/factory.ts +32 -0
- package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +57 -0
- package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +46 -0
- package/src/publisher/l1_tx_failed_store/index.ts +3 -0
- package/src/publisher/sequencer-bundle-simulator.ts +254 -0
- package/src/publisher/sequencer-publisher-factory.ts +38 -9
- package/src/publisher/sequencer-publisher.ts +667 -484
- 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 +800 -0
- package/src/sequencer/automine/index.ts +6 -0
- package/src/sequencer/checkpoint_proposal_job.ts +1073 -290
- 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 +66 -5
- package/src/sequencer/metrics.ts +138 -26
- package/src/sequencer/requests_tracker.ts +43 -0
- package/src/sequencer/sequencer.ts +745 -243
- package/src/sequencer/types.ts +1 -1
- package/src/test/index.ts +4 -6
- package/src/test/mock_checkpoint_builder.ts +63 -49
- package/src/test/utils.ts +64 -10
- package/dest/sequencer/timetable.d.ts +0 -87
- package/dest/sequencer/timetable.d.ts.map +0 -1
- package/dest/sequencer/timetable.js +0 -223
- package/src/sequencer/README.md +0 -531
- package/src/sequencer/timetable.ts +0 -283
|
@@ -370,41 +370,53 @@ 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 { 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';
|
|
380
|
+
import { trimmedBytesLength } from '@aztec/foundation/buffer';
|
|
382
381
|
import { pick } from '@aztec/foundation/collection';
|
|
382
|
+
import { TimeoutError } from '@aztec/foundation/error';
|
|
383
383
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
384
384
|
import { Signature } from '@aztec/foundation/eth-signature';
|
|
385
385
|
import { createLogger } from '@aztec/foundation/log';
|
|
386
|
+
import { InterruptibleSleep } from '@aztec/foundation/sleep';
|
|
386
387
|
import { bufferToHex } from '@aztec/foundation/string';
|
|
387
388
|
import { Timer } from '@aztec/foundation/timer';
|
|
388
|
-
import { EmpireBaseAbi, ErrorsAbi, RollupAbi } from '@aztec/l1-artifacts';
|
|
389
|
+
import { EmpireBaseAbi, ErrorsAbi, RollupAbi, SlashingProposerAbi } from '@aztec/l1-artifacts';
|
|
389
390
|
import { encodeSlashConsensusVotes } from '@aztec/slasher';
|
|
390
391
|
import { CommitteeAttestationsAndSigners } from '@aztec/stdlib/block';
|
|
392
|
+
import { getLastL1SlotTimestampForL2Slot, getNextL1SlotTimestamp, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
391
393
|
import { getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
392
|
-
import { encodeFunctionData, toHex } from 'viem';
|
|
394
|
+
import { encodeFunctionData, keccak256, toHex } from 'viem';
|
|
395
|
+
import { createL1TxFailedStore } from './l1_tx_failed_store/index.js';
|
|
396
|
+
import { SequencerBundleSimulator } from './sequencer-bundle-simulator.js';
|
|
393
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
|
+
}
|
|
394
408
|
export const Actions = [
|
|
395
409
|
'invalidate-by-invalid-attestation',
|
|
396
410
|
'invalidate-by-insufficient-attestations',
|
|
411
|
+
'prune',
|
|
397
412
|
'propose',
|
|
398
413
|
'governance-signal',
|
|
399
|
-
'empire-slashing-signal',
|
|
400
|
-
'create-empire-payload',
|
|
401
|
-
'execute-empire-payload',
|
|
402
414
|
'vote-offenses',
|
|
403
415
|
'execute-slash'
|
|
404
416
|
];
|
|
405
417
|
// Sorting for actions such that invalidations go before proposals, and proposals go before votes
|
|
406
418
|
export const compareActions = (a, b)=>Actions.indexOf(a) - Actions.indexOf(b);
|
|
407
|
-
_dec = trackSpan('SequencerPublisher.sendRequests'), _dec1 = trackSpan('SequencerPublisher.
|
|
419
|
+
_dec = trackSpan('SequencerPublisher.sendRequests'), _dec1 = trackSpan('SequencerPublisher.validateCheckpointHeader');
|
|
408
420
|
export class SequencerPublisher {
|
|
409
421
|
config;
|
|
410
422
|
static{
|
|
@@ -417,55 +429,65 @@ export class SequencerPublisher {
|
|
|
417
429
|
[
|
|
418
430
|
_dec1,
|
|
419
431
|
2,
|
|
420
|
-
"
|
|
421
|
-
],
|
|
422
|
-
[
|
|
423
|
-
_dec2,
|
|
424
|
-
2,
|
|
425
|
-
"validateCheckpointForSubmission"
|
|
432
|
+
"validateCheckpointHeader"
|
|
426
433
|
]
|
|
427
434
|
], []));
|
|
428
435
|
}
|
|
429
436
|
interrupted;
|
|
430
437
|
metrics;
|
|
438
|
+
bundleSimulator;
|
|
431
439
|
epochCache;
|
|
432
|
-
|
|
433
|
-
|
|
440
|
+
failedTxStore;
|
|
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;
|
|
434
446
|
lastActions;
|
|
435
|
-
isPayloadEmptyCache;
|
|
436
447
|
log;
|
|
437
448
|
ethereumSlotDuration;
|
|
449
|
+
aztecSlotDuration;
|
|
450
|
+
previousL1BlockWaitTimeoutMs;
|
|
451
|
+
previousL1BlockWaitPollIntervalMs;
|
|
452
|
+
/** Date provider for wall-clock time. */ dateProvider;
|
|
438
453
|
blobClient;
|
|
439
|
-
/**
|
|
454
|
+
/** Optional callback to obtain a replacement publisher when the current one fails to send. */ getNextPublisher;
|
|
440
455
|
/** L1 fee analyzer for fisherman mode */ l1FeeAnalyzer;
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
// Gas report for VotingWithSigTest shows a max gas of 100k, but we've seen it cost 700k+ in testnet
|
|
444
|
-
static VOTE_GAS_GUESS = 800_000n;
|
|
456
|
+
/** Fee asset price oracle for computing price modifiers from Uniswap V4 */ feeAssetPriceOracle;
|
|
457
|
+
/** Interruptible sleep used by sendRequestsAt to wait until a target timestamp. */ interruptibleSleep;
|
|
445
458
|
l1TxUtils;
|
|
446
459
|
rollupContract;
|
|
447
460
|
govProposerContract;
|
|
448
461
|
slashingProposerContract;
|
|
449
|
-
slashFactoryContract;
|
|
450
462
|
tracer;
|
|
451
463
|
requests;
|
|
452
464
|
constructor(config, deps){
|
|
453
465
|
this.config = config;
|
|
454
466
|
this.interrupted = (_initProto(this), false);
|
|
455
|
-
this.
|
|
456
|
-
|
|
467
|
+
this.revertDecoderAbi = mergeAbis([
|
|
468
|
+
RollupAbi,
|
|
469
|
+
SlashingProposerAbi,
|
|
470
|
+
EmpireBaseAbi,
|
|
471
|
+
ErrorsAbi
|
|
472
|
+
]);
|
|
457
473
|
this.lastActions = {};
|
|
458
|
-
this.
|
|
474
|
+
this.interruptibleSleep = new InterruptibleSleep();
|
|
459
475
|
this.requests = [];
|
|
460
476
|
this.log = deps.log ?? createLogger('sequencer:publisher');
|
|
461
477
|
this.ethereumSlotDuration = BigInt(config.ethereumSlotDuration);
|
|
478
|
+
this.aztecSlotDuration = BigInt(config.aztecSlotDuration);
|
|
479
|
+
this.previousL1BlockWaitTimeoutMs = config.sequencerPublisherPreviousL1BlockWaitTimeoutMs;
|
|
480
|
+
this.previousL1BlockWaitPollIntervalMs = config.sequencerPublisherPreviousL1BlockWaitPollIntervalMs;
|
|
481
|
+
this.dateProvider = deps.dateProvider;
|
|
462
482
|
this.epochCache = deps.epochCache;
|
|
463
483
|
this.lastActions = deps.lastActions;
|
|
464
484
|
this.blobClient = deps.blobClient;
|
|
485
|
+
this.dateProvider = deps.dateProvider;
|
|
465
486
|
const telemetry = deps.telemetry ?? getTelemetryClient();
|
|
466
487
|
this.metrics = deps.metrics ?? new SequencerPublisherMetrics(telemetry, 'SequencerPublisher');
|
|
467
488
|
this.tracer = telemetry.getTracer('SequencerPublisher');
|
|
468
489
|
this.l1TxUtils = deps.l1TxUtils;
|
|
490
|
+
this.getNextPublisher = deps.getNextPublisher;
|
|
469
491
|
this.rollupContract = deps.rollupContract;
|
|
470
492
|
this.govProposerContract = deps.governanceProposerContract;
|
|
471
493
|
this.slashingProposerContract = deps.slashingProposerContract;
|
|
@@ -474,15 +496,50 @@ export class SequencerPublisher {
|
|
|
474
496
|
const newSlashingProposer = await this.rollupContract.getSlashingProposer();
|
|
475
497
|
this.slashingProposerContract = newSlashingProposer;
|
|
476
498
|
});
|
|
477
|
-
this.slashFactoryContract = deps.slashFactoryContract;
|
|
478
499
|
// Initialize L1 fee analyzer for fisherman mode
|
|
479
500
|
if (config.fishermanMode) {
|
|
480
|
-
this.l1FeeAnalyzer = new L1FeeAnalyzer(this.l1TxUtils.client, deps.dateProvider,
|
|
501
|
+
this.l1FeeAnalyzer = new L1FeeAnalyzer(this.l1TxUtils.client, deps.dateProvider, this.log.createChild('fee-analyzer'));
|
|
481
502
|
}
|
|
503
|
+
// Initialize fee asset price oracle
|
|
504
|
+
this.feeAssetPriceOracle = new FeeAssetPriceOracle(this.l1TxUtils.client, this.rollupContract, this.log.createChild('price-oracle'));
|
|
505
|
+
// Initialize failed L1 tx store (optional, for test networks)
|
|
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
|
+
});
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* Backs up a failed L1 transaction to the configured store for debugging.
|
|
516
|
+
* Does nothing if no store is configured.
|
|
517
|
+
*/ backupFailedTx(failedTx) {
|
|
518
|
+
if (!this.failedTxStore) {
|
|
519
|
+
return;
|
|
520
|
+
}
|
|
521
|
+
const tx = {
|
|
522
|
+
...failedTx,
|
|
523
|
+
timestamp: Date.now()
|
|
524
|
+
};
|
|
525
|
+
// Fire and forget - don't block on backup
|
|
526
|
+
void this.failedTxStore.then((store)=>store?.saveFailedTx(tx)).catch((err)=>{
|
|
527
|
+
this.log.warn(`Failed to backup failed L1 tx to store`, err);
|
|
528
|
+
});
|
|
482
529
|
}
|
|
483
530
|
getRollupContract() {
|
|
484
531
|
return this.rollupContract;
|
|
485
532
|
}
|
|
533
|
+
/**
|
|
534
|
+
* Gets the fee asset price modifier from the oracle.
|
|
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);
|
|
542
|
+
}
|
|
486
543
|
getSenderAddress() {
|
|
487
544
|
return this.l1TxUtils.getSenderAddress();
|
|
488
545
|
}
|
|
@@ -491,17 +548,11 @@ export class SequencerPublisher {
|
|
|
491
548
|
*/ getL1FeeAnalyzer() {
|
|
492
549
|
return this.l1FeeAnalyzer;
|
|
493
550
|
}
|
|
494
|
-
/**
|
|
495
|
-
* Sets the proposer address to use for simulations in fisherman mode.
|
|
496
|
-
* @param proposerAddress - The actual proposer's address to use for balance lookups in simulations
|
|
497
|
-
*/ setProposerAddressForSimulation(proposerAddress) {
|
|
498
|
-
this.proposerAddressForSimulation = proposerAddress;
|
|
499
|
-
}
|
|
500
551
|
addRequest(request) {
|
|
501
552
|
this.requests.push(request);
|
|
502
553
|
}
|
|
503
554
|
getCurrentL2Slot() {
|
|
504
|
-
return this.epochCache.
|
|
555
|
+
return this.epochCache.getSlotNow();
|
|
505
556
|
}
|
|
506
557
|
/**
|
|
507
558
|
* Clears all pending requests without sending them.
|
|
@@ -554,11 +605,15 @@ export class SequencerPublisher {
|
|
|
554
605
|
}
|
|
555
606
|
/**
|
|
556
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.
|
|
557
612
|
* @returns one of:
|
|
558
613
|
* - A receipt and stats if the tx succeeded
|
|
559
614
|
* - a receipt and errorMsg if it failed on L1
|
|
560
615
|
* - undefined if no valid requests are found OR the tx failed to send.
|
|
561
|
-
*/ async sendRequests() {
|
|
616
|
+
*/ async sendRequests(targetSlot) {
|
|
562
617
|
const requestsToProcess = [
|
|
563
618
|
...this.requests
|
|
564
619
|
];
|
|
@@ -566,10 +621,9 @@ export class SequencerPublisher {
|
|
|
566
621
|
if (this.interrupted || requestsToProcess.length === 0) {
|
|
567
622
|
return undefined;
|
|
568
623
|
}
|
|
569
|
-
const currentL2Slot = this.getCurrentL2Slot();
|
|
624
|
+
const currentL2Slot = targetSlot ?? this.getCurrentL2Slot();
|
|
570
625
|
this.log.debug(`Sending requests on L2 slot ${currentL2Slot}`);
|
|
571
626
|
const validRequests = requestsToProcess.filter((request)=>request.lastValidL2Slot >= currentL2Slot);
|
|
572
|
-
const validActions = validRequests.map((x)=>x.action);
|
|
573
627
|
const expiredActions = requestsToProcess.filter((request)=>request.lastValidL2Slot < currentL2Slot).map((x)=>x.action);
|
|
574
628
|
if (validRequests.length !== requestsToProcess.length) {
|
|
575
629
|
this.log.warn(`Some requests were expired for slot ${currentL2Slot}`, {
|
|
@@ -587,49 +641,53 @@ export class SequencerPublisher {
|
|
|
587
641
|
this.log.debug(`No valid requests to send`);
|
|
588
642
|
return undefined;
|
|
589
643
|
}
|
|
590
|
-
//
|
|
591
|
-
|
|
592
|
-
// See https://github.com/AztecProtocol/aztec-packages/issues/11513
|
|
593
|
-
const gasConfigs = requestsToProcess.filter((request)=>request.gasConfig).map((request)=>request.gasConfig);
|
|
594
|
-
const blobConfigs = requestsToProcess.filter((request)=>request.blobConfig).map((request)=>request.blobConfig);
|
|
595
|
-
if (blobConfigs.length > 1) {
|
|
596
|
-
throw new Error('Multiple blob configs found');
|
|
597
|
-
}
|
|
598
|
-
const blobConfig = blobConfigs[0];
|
|
599
|
-
// Merge gasConfigs. Yields the sum of gasLimits, and the earliest txTimeoutAt, or undefined if no gasConfig sets them.
|
|
600
|
-
const gasLimits = gasConfigs.map((g)=>g?.gasLimit).filter((g)=>g !== undefined);
|
|
601
|
-
let gasLimit = gasLimits.length > 0 ? sumBigint(gasLimits) : undefined; // sum
|
|
602
|
-
// Cap at L1 block gas limit so the node accepts the tx ("gas limit too high" otherwise).
|
|
603
|
-
const maxGas = MAX_L1_TX_LIMIT;
|
|
604
|
-
if (gasLimit !== undefined && gasLimit > maxGas) {
|
|
605
|
-
this.log.debug('Capping bundled tx gas limit to L1 max', {
|
|
606
|
-
requested: gasLimit,
|
|
607
|
-
capped: maxGas
|
|
608
|
-
});
|
|
609
|
-
gasLimit = maxGas;
|
|
610
|
-
}
|
|
644
|
+
// Collect earliest txTimeoutAt across all requests.
|
|
645
|
+
const gasConfigs = validRequests.filter((request)=>request.gasConfig).map((request)=>request.gasConfig);
|
|
611
646
|
const txTimeoutAts = gasConfigs.map((g)=>g?.txTimeoutAt).filter((g)=>g !== undefined);
|
|
612
|
-
const txTimeoutAt = txTimeoutAts.length > 0 ? new Date(Math.min(...txTimeoutAts.map((g)=>g.getTime()))) : undefined;
|
|
613
|
-
const txConfig = {
|
|
614
|
-
gasLimit,
|
|
615
|
-
txTimeoutAt
|
|
616
|
-
};
|
|
647
|
+
const txTimeoutAt = txTimeoutAts.length > 0 ? new Date(Math.min(...txTimeoutAts.map((g)=>g.getTime()))) : undefined;
|
|
617
648
|
// Sort the requests so that proposals always go first
|
|
618
649
|
// This ensures the committee gets precomputed correctly
|
|
619
650
|
validRequests.sort((a, b)=>compareActions(a.action, b.action));
|
|
620
651
|
try {
|
|
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
|
|
671
|
+
};
|
|
621
672
|
this.log.debug('Forwarding transactions', {
|
|
622
|
-
|
|
673
|
+
requests: requests.map((request)=>request.action),
|
|
623
674
|
txConfig
|
|
624
675
|
});
|
|
625
|
-
const result = await
|
|
626
|
-
|
|
676
|
+
const result = await this.forwardWithPublisherRotation(requests, txConfig, blobConfig);
|
|
677
|
+
if (result === undefined) {
|
|
678
|
+
return undefined;
|
|
679
|
+
}
|
|
680
|
+
const { successfulActions = [], failedActions = [] } = this.callbackBundledTransactions(requests, result);
|
|
681
|
+
const allFailedActions = [
|
|
682
|
+
...failedActions,
|
|
683
|
+
...droppedRequests.map((d)=>d.request.action)
|
|
684
|
+
];
|
|
627
685
|
return {
|
|
628
686
|
result,
|
|
629
687
|
expiredActions,
|
|
630
|
-
sentActions:
|
|
688
|
+
sentActions: requests.map((x)=>x.action),
|
|
631
689
|
successfulActions,
|
|
632
|
-
failedActions
|
|
690
|
+
failedActions: allFailedActions
|
|
633
691
|
};
|
|
634
692
|
} catch (err) {
|
|
635
693
|
const viemError = formatViemError(err);
|
|
@@ -643,49 +701,214 @@ export class SequencerPublisher {
|
|
|
643
701
|
}
|
|
644
702
|
}
|
|
645
703
|
}
|
|
646
|
-
|
|
647
|
-
const
|
|
648
|
-
|
|
649
|
-
this.log.
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
this.log.verbose(`Published bundled transactions (${actionsListStr})`, {
|
|
655
|
-
result,
|
|
656
|
-
requests
|
|
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
|
|
657
712
|
});
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
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()
|
|
665
737
|
}
|
|
738
|
+
});
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
/**
|
|
742
|
+
* Forwards transactions via Multicall3, rotating to the next available publisher if a send
|
|
743
|
+
* failure occurs (i.e. the tx never reached the chain).
|
|
744
|
+
* On-chain reverts and simulation errors are returned as-is without rotation.
|
|
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;
|
|
750
|
+
const triedAddresses = [];
|
|
751
|
+
let currentPublisher = this.l1TxUtils;
|
|
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
|
+
}
|
|
759
|
+
triedAddresses.push(currentPublisher.getSenderAddress());
|
|
760
|
+
try {
|
|
761
|
+
const result = await Multicall3.forward(validRequests.map((r)=>r.request), currentPublisher, txConfigWithGasLimit, blobConfig, {
|
|
762
|
+
gasLimitRequired: true
|
|
763
|
+
});
|
|
764
|
+
this.l1TxUtils = currentPublisher;
|
|
765
|
+
return result;
|
|
766
|
+
} catch (err) {
|
|
767
|
+
if (err instanceof TimeoutError) {
|
|
768
|
+
throw err;
|
|
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
|
+
}
|
|
776
|
+
const viemError = formatViemError(err);
|
|
777
|
+
if (!this.getNextPublisher) {
|
|
778
|
+
this.log.error('Failed to publish bundled transactions', viemError);
|
|
779
|
+
return undefined;
|
|
780
|
+
}
|
|
781
|
+
this.log.warn(`Publisher ${currentPublisher.getSenderAddress()} failed to send, rotating to next publisher`, viemError);
|
|
782
|
+
const nextPublisher = await this.getNextPublisher([
|
|
783
|
+
...triedAddresses
|
|
784
|
+
]);
|
|
785
|
+
if (!nextPublisher) {
|
|
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
|
+
});
|
|
789
|
+
return undefined;
|
|
790
|
+
}
|
|
791
|
+
currentPublisher = nextPublisher;
|
|
666
792
|
}
|
|
667
|
-
return {
|
|
668
|
-
successfulActions,
|
|
669
|
-
failedActions
|
|
670
|
-
};
|
|
671
793
|
}
|
|
672
794
|
}
|
|
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;
|
|
843
|
+
}
|
|
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;
|
|
851
|
+
}
|
|
852
|
+
this.log.trace(`Previous L1 block not mined yet, continuing to wait`, {
|
|
853
|
+
...logCtx,
|
|
854
|
+
latestBlockTs
|
|
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);
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
return {
|
|
888
|
+
successfulActions,
|
|
889
|
+
failedActions
|
|
890
|
+
};
|
|
891
|
+
}
|
|
673
892
|
/**
|
|
674
|
-
* @notice Will call `
|
|
893
|
+
* @notice Will call `canProposeAt` to make sure that it is possible to propose
|
|
675
894
|
* @param tipArchive - The archive to check
|
|
676
895
|
* @returns The slot and block number if it is possible to propose, undefined otherwise
|
|
677
|
-
*/
|
|
896
|
+
*/ async canProposeAt(tipArchive, msgSender, simulationOverridesPlan) {
|
|
678
897
|
// TODO: #14291 - should loop through multiple keys to check if any of them can propose
|
|
679
|
-
|
|
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 = [
|
|
680
903
|
'SlotAlreadyInChain',
|
|
681
904
|
'InvalidProposer',
|
|
682
905
|
'InvalidArchive'
|
|
683
906
|
];
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
if (err instanceof FormattedViemError &&
|
|
688
|
-
this.log.warn(`Failed canProposeAtTime check with ${
|
|
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))}`, {
|
|
689
912
|
error: err.message
|
|
690
913
|
});
|
|
691
914
|
} else {
|
|
@@ -695,37 +918,31 @@ export class SequencerPublisher {
|
|
|
695
918
|
});
|
|
696
919
|
}
|
|
697
920
|
/**
|
|
698
|
-
* @notice Will simulate `
|
|
699
|
-
* @dev This is a convenience function that can be used by the sequencer to validate a "partial" header
|
|
700
|
-
* It will throw if the
|
|
701
|
-
* @param header - The
|
|
702
|
-
*/ async
|
|
921
|
+
* @notice Will simulate the rollup's `validateHeaderWithAttestations` to make sure the checkpoint header is valid
|
|
922
|
+
* @dev This is a convenience function that can be used by the sequencer to validate a "partial" header,
|
|
923
|
+
* skipping the DA and signature checks. It will throw if the checkpoint header is invalid.
|
|
924
|
+
* @param header - The checkpoint header to validate
|
|
925
|
+
*/ async validateCheckpointHeader(header, simulationOverridesPlan) {
|
|
703
926
|
const flags = {
|
|
704
927
|
ignoreDA: true,
|
|
705
928
|
ignoreSignatures: true
|
|
706
929
|
};
|
|
707
930
|
const args = [
|
|
708
931
|
header.toViem(),
|
|
709
|
-
CommitteeAttestationsAndSigners.
|
|
932
|
+
CommitteeAttestationsAndSigners.packAttestations([]),
|
|
710
933
|
[],
|
|
711
934
|
Signature.empty().toViemSignature(),
|
|
712
935
|
`0x${'0'.repeat(64)}`,
|
|
713
936
|
header.blobsHash.toString(),
|
|
714
937
|
flags
|
|
715
938
|
];
|
|
716
|
-
const
|
|
717
|
-
const
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
// In fisherman mode, we can't know where the proposer is publishing from
|
|
721
|
-
// so we just add sufficient balance to the multicall3 address
|
|
722
|
-
balance = 10n * WEI_CONST * WEI_CONST; // 10 ETH
|
|
723
|
-
} else {
|
|
724
|
-
balance = await this.l1TxUtils.getSenderBalance();
|
|
725
|
-
}
|
|
939
|
+
const l1Constants = this.epochCache.getL1Constants();
|
|
940
|
+
const ts = getLastL1SlotTimestampForL2Slot(header.slotNumber, l1Constants);
|
|
941
|
+
const stateOverrides = await buildSimulationOverridesStateOverride(this.rollupContract, simulationOverridesPlan);
|
|
942
|
+
// Balance override for compatibility with providers that apply an upfront funds check to simulated calls.
|
|
726
943
|
stateOverrides.push({
|
|
727
944
|
address: MULTI_CALL_3_ADDRESS,
|
|
728
|
-
balance
|
|
945
|
+
balance: 10n * WEI_CONST * WEI_CONST
|
|
729
946
|
});
|
|
730
947
|
await this.l1TxUtils.simulate({
|
|
731
948
|
to: this.rollupContract.address,
|
|
@@ -736,7 +953,7 @@ export class SequencerPublisher {
|
|
|
736
953
|
}),
|
|
737
954
|
from: MULTI_CALL_3_ADDRESS
|
|
738
955
|
}, {
|
|
739
|
-
time: ts
|
|
956
|
+
time: ts
|
|
740
957
|
}, stateOverrides);
|
|
741
958
|
this.log.debug(`Simulated validateHeader`);
|
|
742
959
|
}
|
|
@@ -766,6 +983,7 @@ export class SequencerPublisher {
|
|
|
766
983
|
...logData,
|
|
767
984
|
request
|
|
768
985
|
});
|
|
986
|
+
const l1BlockNumber = await this.l1TxUtils.getBlockNumber();
|
|
769
987
|
try {
|
|
770
988
|
const { gasUsed } = await this.l1TxUtils.simulate(request, undefined, undefined, mergeAbis([
|
|
771
989
|
request.abi ?? [],
|
|
@@ -781,6 +999,7 @@ export class SequencerPublisher {
|
|
|
781
999
|
gasUsed,
|
|
782
1000
|
checkpointNumber,
|
|
783
1001
|
forcePendingCheckpointNumber: CheckpointNumber(checkpointNumber - 1),
|
|
1002
|
+
lastArchive: validationResult.checkpoint.lastArchive,
|
|
784
1003
|
reason
|
|
785
1004
|
};
|
|
786
1005
|
} catch (err) {
|
|
@@ -793,8 +1012,8 @@ export class SequencerPublisher {
|
|
|
793
1012
|
request,
|
|
794
1013
|
error: viemError.message
|
|
795
1014
|
});
|
|
796
|
-
const
|
|
797
|
-
if (
|
|
1015
|
+
const latestProposedCheckpointNumber = await this.rollupContract.getCheckpointNumber();
|
|
1016
|
+
if (latestProposedCheckpointNumber < checkpointNumber) {
|
|
798
1017
|
this.log.verbose(`Checkpoint ${checkpointNumber} has already been invalidated`, {
|
|
799
1018
|
...logData
|
|
800
1019
|
});
|
|
@@ -808,6 +1027,27 @@ export class SequencerPublisher {
|
|
|
808
1027
|
}
|
|
809
1028
|
// Otherwise, throw. We cannot build the next checkpoint if we cannot invalidate the previous one.
|
|
810
1029
|
this.log.error(`Simulation for invalidate checkpoint ${checkpointNumber} failed`, viemError, logData);
|
|
1030
|
+
this.backupFailedTx({
|
|
1031
|
+
id: keccak256(request.data),
|
|
1032
|
+
failureType: 'simulation',
|
|
1033
|
+
request: {
|
|
1034
|
+
to: request.to,
|
|
1035
|
+
data: request.data,
|
|
1036
|
+
value: request.value?.toString()
|
|
1037
|
+
},
|
|
1038
|
+
l1BlockNumber: l1BlockNumber.toString(),
|
|
1039
|
+
error: {
|
|
1040
|
+
message: viemError.message,
|
|
1041
|
+
name: viemError.name
|
|
1042
|
+
},
|
|
1043
|
+
context: {
|
|
1044
|
+
actions: [
|
|
1045
|
+
`invalidate-${reason}`
|
|
1046
|
+
],
|
|
1047
|
+
checkpointNumber,
|
|
1048
|
+
sender: this.getSenderAddress().toString()
|
|
1049
|
+
}
|
|
1050
|
+
});
|
|
811
1051
|
throw new Error(`Failed to simulate invalidate checkpoint ${checkpointNumber}`, {
|
|
812
1052
|
cause: viemError
|
|
813
1053
|
});
|
|
@@ -823,7 +1063,11 @@ export class SequencerPublisher {
|
|
|
823
1063
|
reason
|
|
824
1064
|
};
|
|
825
1065
|
this.log.debug(`Building invalidate checkpoint ${checkpoint.checkpointNumber} request`, logData);
|
|
826
|
-
|
|
1066
|
+
// Use the exact packed tuple posted to L1 verbatim. A repack via `packAttestations` is not a
|
|
1067
|
+
// byte-faithful inverse of `fromPacked` (a canonicalized yParity byte or an all-zero signature slot
|
|
1068
|
+
// round-trips differently), so it would diverge from the stored `attestationsHash` and revert the
|
|
1069
|
+
// invalidation.
|
|
1070
|
+
const attestationsAndSigners = validationResult.verbatimAttestations;
|
|
827
1071
|
if (reason === 'invalid-attestation') {
|
|
828
1072
|
return this.rollupContract.buildInvalidateBadAttestationRequest(checkpoint.checkpointNumber, attestationsAndSigners, committee, validationResult.invalidIndex);
|
|
829
1073
|
} else if (reason === 'insufficient-attestations') {
|
|
@@ -833,42 +1077,7 @@ export class SequencerPublisher {
|
|
|
833
1077
|
throw new Error(`Unknown reason for invalidation`);
|
|
834
1078
|
}
|
|
835
1079
|
}
|
|
836
|
-
|
|
837
|
-
const ts = BigInt((await this.l1TxUtils.getBlock()).timestamp + this.ethereumSlotDuration);
|
|
838
|
-
// TODO(palla/mbps): This should not be needed, there's no flow where we propose with zero attestations. Or is there?
|
|
839
|
-
// If we have no attestations, we still need to provide the empty attestations
|
|
840
|
-
// so that the committee is recalculated correctly
|
|
841
|
-
// const ignoreSignatures = attestationsAndSigners.attestations.length === 0;
|
|
842
|
-
// if (ignoreSignatures) {
|
|
843
|
-
// const { committee } = await this.epochCache.getCommittee(block.header.globalVariables.slotNumber);
|
|
844
|
-
// if (!committee) {
|
|
845
|
-
// this.log.warn(`No committee found for slot ${block.header.globalVariables.slotNumber}`);
|
|
846
|
-
// throw new Error(`No committee found for slot ${block.header.globalVariables.slotNumber}`);
|
|
847
|
-
// }
|
|
848
|
-
// attestationsAndSigners.attestations = committee.map(committeeMember =>
|
|
849
|
-
// CommitteeAttestation.fromAddress(committeeMember),
|
|
850
|
-
// );
|
|
851
|
-
// }
|
|
852
|
-
const blobFields = checkpoint.toBlobFields();
|
|
853
|
-
const blobs = getBlobsPerL1Block(blobFields);
|
|
854
|
-
const blobInput = getPrefixedEthBlobCommitments(blobs);
|
|
855
|
-
const args = [
|
|
856
|
-
{
|
|
857
|
-
header: checkpoint.header.toViem(),
|
|
858
|
-
archive: toHex(checkpoint.archive.root.toBuffer()),
|
|
859
|
-
oracleInput: {
|
|
860
|
-
feeAssetPriceModifier: 0n
|
|
861
|
-
}
|
|
862
|
-
},
|
|
863
|
-
attestationsAndSigners.getPackedAttestations(),
|
|
864
|
-
attestationsAndSigners.getSigners().map((signer)=>signer.toString()),
|
|
865
|
-
attestationsAndSignersSignature.toViemSignature(),
|
|
866
|
-
blobInput
|
|
867
|
-
];
|
|
868
|
-
await this.simulateProposeTx(args, ts, options);
|
|
869
|
-
return ts;
|
|
870
|
-
}
|
|
871
|
-
async enqueueCastSignalHelper(slotNumber, timestamp, signalType, payload, base, signerAddress, signer) {
|
|
1080
|
+
async enqueueCastSignalHelper(slotNumber, signalType, payload, base, signerAddress, signer) {
|
|
872
1081
|
if (this.lastActions[signalType] && this.lastActions[signalType] === slotNumber) {
|
|
873
1082
|
this.log.debug(`Skipping duplicate vote cast signal ${signalType} for slot ${slotNumber}`);
|
|
874
1083
|
return false;
|
|
@@ -880,6 +1089,17 @@ export class SequencerPublisher {
|
|
|
880
1089
|
this.log.warn(`Cannot enqueue vote cast signal ${signalType} for address zero at slot ${slotNumber}`);
|
|
881
1090
|
return false;
|
|
882
1091
|
}
|
|
1092
|
+
const canonicalRollup = await base.getRollupAddress();
|
|
1093
|
+
if (!canonicalRollup.equals(EthAddress.fromString(this.rollupContract.address))) {
|
|
1094
|
+
this.log.warn(`Rollup ${this.rollupContract.address} is not canonical, skipping governance signal`, {
|
|
1095
|
+
slotNumber,
|
|
1096
|
+
signalType,
|
|
1097
|
+
canonicalRollup,
|
|
1098
|
+
targetRollup: this.rollupContract.address,
|
|
1099
|
+
payload: payload.toString()
|
|
1100
|
+
});
|
|
1101
|
+
return false;
|
|
1102
|
+
}
|
|
883
1103
|
const round = await base.computeRound(slotNumber);
|
|
884
1104
|
const roundInfo = await base.getRoundInfo(this.rollupContract.address, round);
|
|
885
1105
|
if (roundInfo.quorumReached) {
|
|
@@ -888,10 +1108,42 @@ export class SequencerPublisher {
|
|
|
888
1108
|
if (roundInfo.lastSignalSlot >= slotNumber) {
|
|
889
1109
|
return false;
|
|
890
1110
|
}
|
|
891
|
-
if (await
|
|
1111
|
+
if (await base.isPayloadEmpty(payload)) {
|
|
892
1112
|
this.log.warn(`Skipping vote cast for payload with empty code`);
|
|
893
1113
|
return false;
|
|
894
1114
|
}
|
|
1115
|
+
// Classify the payload against the Governance proposal history so we stop signalling once its
|
|
1116
|
+
// proposal is live or was already executed, while still re-signalling one whose proposal was
|
|
1117
|
+
// merely rejected/dropped/expired.
|
|
1118
|
+
let status = 'none';
|
|
1119
|
+
try {
|
|
1120
|
+
status = await base.getPayloadProposalStatus(payload.toString());
|
|
1121
|
+
} catch (err) {
|
|
1122
|
+
// We deliberately swallow the error and proceed to signal. Failing closed (skipping the
|
|
1123
|
+
// signal) on transient RPC errors would let a flaky L1 endpoint silence governance
|
|
1124
|
+
// participation entirely; failing open at worst produces a duplicate signal that the
|
|
1125
|
+
// contract will simply count alongside others in the round.
|
|
1126
|
+
this.log.error(`Failed to check governance proposal status for payload ${payload} (signalling anyway)`, err, {
|
|
1127
|
+
slotNumber,
|
|
1128
|
+
signalType
|
|
1129
|
+
});
|
|
1130
|
+
}
|
|
1131
|
+
if (status === 'live') {
|
|
1132
|
+
this.log.info(`Payload ${payload} has a live governance proposal, stopping signals`, {
|
|
1133
|
+
slotNumber,
|
|
1134
|
+
signalType,
|
|
1135
|
+
payload: payload.toString()
|
|
1136
|
+
});
|
|
1137
|
+
return false;
|
|
1138
|
+
}
|
|
1139
|
+
if (status === 'executed' && !this.config.governanceProposerForcePayloadVote) {
|
|
1140
|
+
this.log.info(`Payload ${payload} was executed by governance within lookback, stopping signals ` + `(set GOVERNANCE_PROPOSER_FORCE_PAYLOAD_VOTE to re-signal)`, {
|
|
1141
|
+
slotNumber,
|
|
1142
|
+
signalType,
|
|
1143
|
+
payload: payload.toString()
|
|
1144
|
+
});
|
|
1145
|
+
return false;
|
|
1146
|
+
}
|
|
895
1147
|
const cachedLastVote = this.lastActions[signalType];
|
|
896
1148
|
this.lastActions[signalType] = slotNumber;
|
|
897
1149
|
const action = signalType;
|
|
@@ -902,30 +1154,17 @@ export class SequencerPublisher {
|
|
|
902
1154
|
signer: this.l1TxUtils.client.account?.address,
|
|
903
1155
|
lastValidL2Slot: slotNumber
|
|
904
1156
|
});
|
|
905
|
-
try {
|
|
906
|
-
await this.l1TxUtils.simulate(request, {
|
|
907
|
-
time: timestamp
|
|
908
|
-
}, [], mergeAbis([
|
|
909
|
-
request.abi ?? [],
|
|
910
|
-
ErrorsAbi
|
|
911
|
-
]));
|
|
912
|
-
this.log.debug(`Simulation for ${action} at slot ${slotNumber} succeeded`, {
|
|
913
|
-
request
|
|
914
|
-
});
|
|
915
|
-
} catch (err) {
|
|
916
|
-
this.log.error(`Failed simulation for ${action} at slot ${slotNumber} (enqueuing the action anyway)`, err);
|
|
917
|
-
// Yes, we enqueue the request anyway, in case there was a bug with the simulation itself
|
|
918
|
-
}
|
|
919
1157
|
// TODO(palla/slash): All votes (governance and slashing) should txTimeoutAt at the end of the slot.
|
|
920
1158
|
this.addRequest({
|
|
921
|
-
gasConfig: {
|
|
922
|
-
gasLimit: SequencerPublisher.VOTE_GAS_GUESS
|
|
923
|
-
},
|
|
924
1159
|
action,
|
|
925
1160
|
request,
|
|
926
1161
|
lastValidL2Slot: slotNumber,
|
|
927
1162
|
checkSuccess: (_request, result)=>{
|
|
928
|
-
const success = result &&
|
|
1163
|
+
const success = result && extractEventSuccess(result.receipt, {
|
|
1164
|
+
address: base.address.toString(),
|
|
1165
|
+
abi: EmpireBaseAbi,
|
|
1166
|
+
eventName: 'SignalCast'
|
|
1167
|
+
});
|
|
929
1168
|
const logData = {
|
|
930
1169
|
...result,
|
|
931
1170
|
slotNumber,
|
|
@@ -944,68 +1183,70 @@ export class SequencerPublisher {
|
|
|
944
1183
|
});
|
|
945
1184
|
return true;
|
|
946
1185
|
}
|
|
947
|
-
async isPayloadEmpty(payload) {
|
|
948
|
-
const key = payload.toString();
|
|
949
|
-
const cached = this.isPayloadEmptyCache.get(key);
|
|
950
|
-
if (cached) {
|
|
951
|
-
return cached;
|
|
952
|
-
}
|
|
953
|
-
const isEmpty = !await this.l1TxUtils.getCode(payload);
|
|
954
|
-
this.isPayloadEmptyCache.set(key, isEmpty);
|
|
955
|
-
return isEmpty;
|
|
956
|
-
}
|
|
957
1186
|
/**
|
|
958
1187
|
* Enqueues a governance castSignal transaction to cast a signal for a given slot number.
|
|
959
1188
|
* @param slotNumber - The slot number to cast a signal for.
|
|
960
|
-
* @param timestamp - The timestamp of the slot to cast a signal for.
|
|
961
1189
|
* @returns True if the signal was successfully enqueued, false otherwise.
|
|
962
|
-
*/ enqueueGovernanceCastSignal(governancePayload, slotNumber,
|
|
963
|
-
return this.enqueueCastSignalHelper(slotNumber,
|
|
1190
|
+
*/ enqueueGovernanceCastSignal(governancePayload, slotNumber, signerAddress, signer) {
|
|
1191
|
+
return this.enqueueCastSignalHelper(slotNumber, 'governance-signal', governancePayload, this.govProposerContract, signerAddress, signer);
|
|
964
1192
|
}
|
|
965
|
-
/**
|
|
1193
|
+
/**
|
|
1194
|
+
* Enqueues a `prune()` transaction if the rollup is prunable at the given slot's L1 timestamp.
|
|
1195
|
+
* `prune()` is permissionless and idempotent — if the chain is no longer prunable by send time the
|
|
1196
|
+
* bundle simulation usually drops the entry; on a node without `eth_simulateV1` the bundle is sent
|
|
1197
|
+
* as-is and the prune reverts `Rollup__NothingToPrune` inside `aggregate3(allowFailure: true)`
|
|
1198
|
+
* (a failed action, never a whole-tx revert). Used by the failed-sync fallback so a stuck pending
|
|
1199
|
+
* chain (e.g. bad data blocking sync) can be wound back to recover.
|
|
1200
|
+
* @returns true if a prune request was enqueued, false otherwise.
|
|
1201
|
+
*/ async enqueuePruneIfPrunable(slotNumber) {
|
|
1202
|
+
if (this.lastActions['prune'] === slotNumber) {
|
|
1203
|
+
this.log.debug(`Skipping duplicate prune for slot ${slotNumber}`, {
|
|
1204
|
+
slotNumber
|
|
1205
|
+
});
|
|
1206
|
+
return false;
|
|
1207
|
+
}
|
|
1208
|
+
// Use the SAME timestamp the bundle simulator overrides block.timestamp with at send time
|
|
1209
|
+
// (sequencer-bundle-simulator.ts) so this upfront check and the send-time sim agree. Slot-start
|
|
1210
|
+
// and last-L1-slot both fall within the same L2 slot (and epoch, which is what `canPruneAtTime`
|
|
1211
|
+
// derives), so they agree today; matching the simulator keeps it robust if the contract ever uses
|
|
1212
|
+
// the timestamp more granularly.
|
|
1213
|
+
const ts = getLastL1SlotTimestampForL2Slot(slotNumber, this.epochCache.getL1Constants());
|
|
1214
|
+
const canPrune = await this.rollupContract.canPruneAtTime(ts).catch((err)=>{
|
|
1215
|
+
this.log.error(`Failed to check canPruneAtTime for slot ${slotNumber}`, err, {
|
|
1216
|
+
slotNumber
|
|
1217
|
+
});
|
|
1218
|
+
return false;
|
|
1219
|
+
});
|
|
1220
|
+
if (!canPrune) {
|
|
1221
|
+
this.log.debug(`Rollup not prunable at slot ${slotNumber}`, {
|
|
1222
|
+
slotNumber
|
|
1223
|
+
});
|
|
1224
|
+
return false;
|
|
1225
|
+
}
|
|
1226
|
+
const request = {
|
|
1227
|
+
to: this.rollupContract.address,
|
|
1228
|
+
data: encodeFunctionData({
|
|
1229
|
+
abi: RollupAbi,
|
|
1230
|
+
functionName: 'prune',
|
|
1231
|
+
args: []
|
|
1232
|
+
})
|
|
1233
|
+
};
|
|
1234
|
+
this.log.info(`Enqueuing rollup prune for slot ${slotNumber}`, {
|
|
1235
|
+
slotNumber
|
|
1236
|
+
});
|
|
1237
|
+
return this.enqueueRequest('prune', request, {
|
|
1238
|
+
address: this.rollupContract.address,
|
|
1239
|
+
abi: RollupAbi,
|
|
1240
|
+
eventName: 'PrunedPending'
|
|
1241
|
+
}, slotNumber);
|
|
1242
|
+
}
|
|
1243
|
+
/** Enqueues all slashing actions as returned by the slasher client. */ async enqueueSlashingActions(actions, slotNumber, signerAddress, signer) {
|
|
966
1244
|
if (actions.length === 0) {
|
|
967
1245
|
this.log.debug(`No slashing actions to enqueue for slot ${slotNumber}`);
|
|
968
1246
|
return false;
|
|
969
1247
|
}
|
|
970
1248
|
for (const action of actions){
|
|
971
1249
|
switch(action.type){
|
|
972
|
-
case 'vote-empire-payload':
|
|
973
|
-
{
|
|
974
|
-
if (this.slashingProposerContract?.type !== 'empire') {
|
|
975
|
-
this.log.error('Cannot vote for empire payload on non-empire slashing contract');
|
|
976
|
-
break;
|
|
977
|
-
}
|
|
978
|
-
this.log.debug(`Enqueuing slashing vote for payload ${action.payload} at slot ${slotNumber}`, {
|
|
979
|
-
signerAddress
|
|
980
|
-
});
|
|
981
|
-
await this.enqueueCastSignalHelper(slotNumber, timestamp, 'empire-slashing-signal', action.payload, this.slashingProposerContract, signerAddress, signer);
|
|
982
|
-
break;
|
|
983
|
-
}
|
|
984
|
-
case 'create-empire-payload':
|
|
985
|
-
{
|
|
986
|
-
this.log.debug(`Enqueuing slashing create payload at slot ${slotNumber}`, {
|
|
987
|
-
slotNumber,
|
|
988
|
-
signerAddress
|
|
989
|
-
});
|
|
990
|
-
const request = this.slashFactoryContract.buildCreatePayloadRequest(action.data);
|
|
991
|
-
await this.simulateAndEnqueueRequest('create-empire-payload', request, (receipt)=>!!this.slashFactoryContract.tryExtractSlashPayloadCreatedEvent(receipt.logs), slotNumber, timestamp);
|
|
992
|
-
break;
|
|
993
|
-
}
|
|
994
|
-
case 'execute-empire-payload':
|
|
995
|
-
{
|
|
996
|
-
this.log.debug(`Enqueuing slashing execute payload at slot ${slotNumber}`, {
|
|
997
|
-
slotNumber,
|
|
998
|
-
signerAddress
|
|
999
|
-
});
|
|
1000
|
-
if (this.slashingProposerContract?.type !== 'empire') {
|
|
1001
|
-
this.log.error('Cannot execute slashing payload on non-empire slashing contract');
|
|
1002
|
-
return false;
|
|
1003
|
-
}
|
|
1004
|
-
const empireSlashingProposer = this.slashingProposerContract;
|
|
1005
|
-
const request = empireSlashingProposer.buildExecuteRoundRequest(action.round);
|
|
1006
|
-
await this.simulateAndEnqueueRequest('execute-empire-payload', request, (receipt)=>!!empireSlashingProposer.tryExtractPayloadSubmittedEvent(receipt.logs), slotNumber, timestamp);
|
|
1007
|
-
break;
|
|
1008
|
-
}
|
|
1009
1250
|
case 'vote-offenses':
|
|
1010
1251
|
{
|
|
1011
1252
|
this.log.debug(`Enqueuing slashing vote for ${action.votes.length} votes at slot ${slotNumber}`, {
|
|
@@ -1014,14 +1255,17 @@ export class SequencerPublisher {
|
|
|
1014
1255
|
votesCount: action.votes.length,
|
|
1015
1256
|
signerAddress
|
|
1016
1257
|
});
|
|
1017
|
-
if (this.slashingProposerContract
|
|
1018
|
-
this.log.error('
|
|
1258
|
+
if (!this.slashingProposerContract) {
|
|
1259
|
+
this.log.error('No slashing proposer contract available');
|
|
1019
1260
|
return false;
|
|
1020
1261
|
}
|
|
1021
|
-
const tallySlashingProposer = this.slashingProposerContract;
|
|
1022
1262
|
const votes = bufferToHex(encodeSlashConsensusVotes(action.votes));
|
|
1023
|
-
const request = await
|
|
1024
|
-
|
|
1263
|
+
const request = await this.slashingProposerContract.buildVoteRequestFromSigner(votes, slotNumber, signer);
|
|
1264
|
+
this.enqueueRequest('vote-offenses', request, {
|
|
1265
|
+
address: this.slashingProposerContract.address.toString(),
|
|
1266
|
+
abi: SlashingProposerAbi,
|
|
1267
|
+
eventName: 'VoteCast'
|
|
1268
|
+
}, slotNumber);
|
|
1025
1269
|
break;
|
|
1026
1270
|
}
|
|
1027
1271
|
case 'execute-slash':
|
|
@@ -1031,13 +1275,16 @@ export class SequencerPublisher {
|
|
|
1031
1275
|
round: action.round,
|
|
1032
1276
|
signerAddress
|
|
1033
1277
|
});
|
|
1034
|
-
if (this.slashingProposerContract
|
|
1035
|
-
this.log.error('
|
|
1278
|
+
if (!this.slashingProposerContract) {
|
|
1279
|
+
this.log.error('No slashing proposer contract available');
|
|
1036
1280
|
return false;
|
|
1037
1281
|
}
|
|
1038
|
-
const
|
|
1039
|
-
|
|
1040
|
-
|
|
1282
|
+
const executeRequest = this.slashingProposerContract.buildExecuteRoundRequest(action.round, action.committees);
|
|
1283
|
+
this.enqueueRequest('execute-slash', executeRequest, {
|
|
1284
|
+
address: this.slashingProposerContract.address.toString(),
|
|
1285
|
+
abi: SlashingProposerAbi,
|
|
1286
|
+
eventName: 'RoundExecuted'
|
|
1287
|
+
}, slotNumber);
|
|
1041
1288
|
break;
|
|
1042
1289
|
}
|
|
1043
1290
|
default:
|
|
@@ -1049,63 +1296,50 @@ export class SequencerPublisher {
|
|
|
1049
1296
|
}
|
|
1050
1297
|
return true;
|
|
1051
1298
|
}
|
|
1052
|
-
/**
|
|
1299
|
+
/** Enqueues a proposal for a checkpoint on L1 */ async enqueueProposeCheckpoint(checkpoint, attestationsAndSigners, attestationsAndSignersSignature, opts = {}) {
|
|
1053
1300
|
const checkpointHeader = checkpoint.header;
|
|
1054
1301
|
const blobFields = checkpoint.toBlobFields();
|
|
1055
|
-
const blobs = getBlobsPerL1Block(blobFields);
|
|
1302
|
+
const blobs = await getBlobsPerL1Block(blobFields);
|
|
1056
1303
|
const proposeTxArgs = {
|
|
1057
1304
|
header: checkpointHeader,
|
|
1058
1305
|
archive: checkpoint.archive.root.toBuffer(),
|
|
1059
1306
|
blobs,
|
|
1060
1307
|
attestationsAndSigners,
|
|
1061
|
-
attestationsAndSignersSignature
|
|
1308
|
+
attestationsAndSignersSignature,
|
|
1309
|
+
feeAssetPriceModifier: checkpoint.feeAssetPriceModifier
|
|
1062
1310
|
};
|
|
1063
|
-
let ts;
|
|
1064
|
-
try {
|
|
1065
|
-
// @note This will make sure that we are passing the checks for our header ASSUMING that the data is also made available
|
|
1066
|
-
// This means that we can avoid the simulation issues in later checks.
|
|
1067
|
-
// By simulation issue, I mean the fact that the block.timestamp is equal to the last block, not the next, which
|
|
1068
|
-
// make time consistency checks break.
|
|
1069
|
-
// TODO(palla): Check whether we're validating twice, once here and once within addProposeTx, since we call simulateProposeTx in both places.
|
|
1070
|
-
ts = await this.validateCheckpointForSubmission(checkpoint, attestationsAndSigners, attestationsAndSignersSignature, opts);
|
|
1071
|
-
} catch (err) {
|
|
1072
|
-
this.log.error(`Checkpoint validation failed. ${err instanceof Error ? err.message : 'No error message'}`, err, {
|
|
1073
|
-
...checkpoint.getStats(),
|
|
1074
|
-
slotNumber: checkpoint.header.slotNumber,
|
|
1075
|
-
forcePendingCheckpointNumber: opts.forcePendingCheckpointNumber
|
|
1076
|
-
});
|
|
1077
|
-
throw err;
|
|
1078
|
-
}
|
|
1079
1311
|
this.log.verbose(`Enqueuing checkpoint propose transaction`, {
|
|
1080
1312
|
...checkpoint.toCheckpointInfo(),
|
|
1081
|
-
|
|
1313
|
+
txTimeoutAt: opts.txTimeoutAt
|
|
1314
|
+
});
|
|
1315
|
+
await this.addProposeTx(checkpoint, proposeTxArgs, {
|
|
1316
|
+
txTimeoutAt: opts.txTimeoutAt
|
|
1082
1317
|
});
|
|
1083
|
-
await this.addProposeTx(checkpoint, proposeTxArgs, opts, ts);
|
|
1084
1318
|
}
|
|
1085
1319
|
enqueueInvalidateCheckpoint(request, opts = {}) {
|
|
1086
1320
|
if (!request) {
|
|
1087
1321
|
return;
|
|
1088
1322
|
}
|
|
1089
|
-
// We issued the simulation against the rollup contract, so we need to account for the overhead of the multicall3
|
|
1090
|
-
const gasLimit = this.l1TxUtils.bumpGasLimit(BigInt(Math.ceil(Number(request.gasUsed) * 64 / 63)));
|
|
1091
1323
|
const { gasUsed, checkpointNumber } = request;
|
|
1092
1324
|
const logData = {
|
|
1093
1325
|
gasUsed,
|
|
1094
1326
|
checkpointNumber,
|
|
1095
|
-
gasLimit,
|
|
1096
1327
|
opts
|
|
1097
1328
|
};
|
|
1098
1329
|
this.log.verbose(`Enqueuing invalidate checkpoint request`, logData);
|
|
1099
1330
|
this.addRequest({
|
|
1100
1331
|
action: `invalidate-by-${request.reason}`,
|
|
1101
1332
|
request: request.request,
|
|
1102
|
-
gasConfig: {
|
|
1103
|
-
gasLimit,
|
|
1333
|
+
gasConfig: opts.txTimeoutAt ? {
|
|
1104
1334
|
txTimeoutAt: opts.txTimeoutAt
|
|
1105
|
-
},
|
|
1335
|
+
} : undefined,
|
|
1106
1336
|
lastValidL2Slot: SlotNumber(this.getCurrentL2Slot() + 2),
|
|
1107
1337
|
checkSuccess: (_req, result)=>{
|
|
1108
|
-
const success = result &&
|
|
1338
|
+
const success = result && extractEventSuccess(result.receipt, {
|
|
1339
|
+
address: this.rollupContract.address,
|
|
1340
|
+
abi: RollupAbi,
|
|
1341
|
+
eventName: 'CheckpointInvalidated'
|
|
1342
|
+
});
|
|
1109
1343
|
if (!success) {
|
|
1110
1344
|
this.log.warn(`Invalidate checkpoint ${request.checkpointNumber} failed`, {
|
|
1111
1345
|
...result,
|
|
@@ -1121,67 +1355,36 @@ export class SequencerPublisher {
|
|
|
1121
1355
|
}
|
|
1122
1356
|
});
|
|
1123
1357
|
}
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
};
|
|
1358
|
+
/**
|
|
1359
|
+
* Dedup-checked enqueue helper for actions that are simulated at bundle-send time rather
|
|
1360
|
+
* than at enqueue time. Validates the (action, slot) dedup key, sets `lastActions`, and
|
|
1361
|
+
* enqueues without a gasLimit so the bundle simulate sets the only gasLimit that matters.
|
|
1362
|
+
*/ enqueueRequest(action, request, eventOpts, slotNumber) {
|
|
1130
1363
|
if (this.lastActions[action] && this.lastActions[action] === slotNumber) {
|
|
1131
1364
|
this.log.debug(`Skipping duplicate action ${action} for slot ${slotNumber}`);
|
|
1132
1365
|
return false;
|
|
1133
1366
|
}
|
|
1134
1367
|
const cachedLastActionSlot = this.lastActions[action];
|
|
1135
1368
|
this.lastActions[action] = slotNumber;
|
|
1136
|
-
this.log.debug(`
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
request.abi ?? [],
|
|
1140
|
-
ErrorsAbi
|
|
1141
|
-
]);
|
|
1142
|
-
try {
|
|
1143
|
-
({ gasUsed } = await this.l1TxUtils.simulate(request, {
|
|
1144
|
-
time: timestamp
|
|
1145
|
-
}, [], simulateAbi)); // TODO(palla/slash): Check the timestamp logic
|
|
1146
|
-
this.log.verbose(`Simulation for ${action} succeeded`, {
|
|
1147
|
-
...logData,
|
|
1148
|
-
request,
|
|
1149
|
-
gasUsed
|
|
1150
|
-
});
|
|
1151
|
-
} catch (err) {
|
|
1152
|
-
const viemError = formatViemError(err, simulateAbi);
|
|
1153
|
-
this.log.error(`Simulation for ${action} at ${slotNumber} failed`, viemError, logData);
|
|
1154
|
-
return false;
|
|
1155
|
-
}
|
|
1156
|
-
// We issued the simulation against the rollup contract, so we need to account for the overhead of the multicall3
|
|
1157
|
-
const gasLimit = this.l1TxUtils.bumpGasLimit(BigInt(Math.ceil(Number(gasUsed) * 64 / 63)));
|
|
1158
|
-
logData.gasLimit = gasLimit;
|
|
1159
|
-
// Store the ABI used for simulation on the request so Multicall3.forward can decode errors
|
|
1160
|
-
// when the tx is sent and a revert is diagnosed via simulation.
|
|
1161
|
-
const requestWithAbi = {
|
|
1162
|
-
...request,
|
|
1163
|
-
abi: simulateAbi
|
|
1164
|
-
};
|
|
1165
|
-
this.log.debug(`Enqueuing ${action}`, logData);
|
|
1369
|
+
this.log.debug(`Enqueuing ${action}`, {
|
|
1370
|
+
slotNumber
|
|
1371
|
+
});
|
|
1166
1372
|
this.addRequest({
|
|
1167
1373
|
action,
|
|
1168
|
-
request
|
|
1169
|
-
gasConfig: {
|
|
1170
|
-
gasLimit
|
|
1171
|
-
},
|
|
1374
|
+
request,
|
|
1172
1375
|
lastValidL2Slot: slotNumber,
|
|
1173
|
-
checkSuccess: (
|
|
1174
|
-
const success = result && result.receipt
|
|
1376
|
+
checkSuccess: (_request, result)=>{
|
|
1377
|
+
const success = result && extractEventSuccess(result.receipt, eventOpts);
|
|
1175
1378
|
if (!success) {
|
|
1176
1379
|
this.log.warn(`Action ${action} at ${slotNumber} failed`, {
|
|
1177
1380
|
...result,
|
|
1178
|
-
|
|
1381
|
+
slotNumber
|
|
1179
1382
|
});
|
|
1180
1383
|
this.lastActions[action] = cachedLastActionSlot;
|
|
1181
1384
|
} else {
|
|
1182
1385
|
this.log.info(`Action ${action} at ${slotNumber} succeeded`, {
|
|
1183
1386
|
...result,
|
|
1184
|
-
|
|
1387
|
+
slotNumber
|
|
1185
1388
|
});
|
|
1186
1389
|
}
|
|
1187
1390
|
return !!success;
|
|
@@ -1196,13 +1399,14 @@ export class SequencerPublisher {
|
|
|
1196
1399
|
* A call to `restart` is required before you can continue publishing.
|
|
1197
1400
|
*/ interrupt() {
|
|
1198
1401
|
this.interrupted = true;
|
|
1402
|
+
this.interruptibleSleep.interrupt();
|
|
1199
1403
|
this.l1TxUtils.interrupt();
|
|
1200
1404
|
}
|
|
1201
1405
|
/** Restarts the publisher after calling `interrupt`. */ restart() {
|
|
1202
1406
|
this.interrupted = false;
|
|
1203
1407
|
this.l1TxUtils.restart();
|
|
1204
1408
|
}
|
|
1205
|
-
async prepareProposeTx(encodedData
|
|
1409
|
+
async prepareProposeTx(encodedData) {
|
|
1206
1410
|
const kzg = Blob.getViemKzgInstance();
|
|
1207
1411
|
const blobInput = getPrefixedEthBlobCommitments(encodedData.blobs);
|
|
1208
1412
|
this.log.debug('Validating blob input', {
|
|
@@ -1216,7 +1420,11 @@ export class SequencerPublisher {
|
|
|
1216
1420
|
blobEvaluationGas = BigInt(encodedData.blobs.length) * 21_000n;
|
|
1217
1421
|
this.log.debug(`Using fixed blob evaluation gas estimate in fisherman mode: ${blobEvaluationGas}`);
|
|
1218
1422
|
} else {
|
|
1219
|
-
//
|
|
1423
|
+
// We call validateBlobs via estimateGas with real blob+kzg sidecars as a consistency check
|
|
1424
|
+
// that our locally-built blob commitments match the blob data. The bundle simulate at send
|
|
1425
|
+
// time uses eth_simulateV1, which cannot carry blob inputs, so the rollup's on-chain blob
|
|
1426
|
+
// check is forced off there — making this the only pre-flight detector of a commitment/data
|
|
1427
|
+
// mismatch. The returned gas estimate is stashed on the request for the bundle path to read.
|
|
1220
1428
|
blobEvaluationGas = await this.l1TxUtils.estimateGas(this.getSenderAddress().toString(), {
|
|
1221
1429
|
to: this.rollupContract.address,
|
|
1222
1430
|
data: encodeFunctionData({
|
|
@@ -1229,10 +1437,38 @@ export class SequencerPublisher {
|
|
|
1229
1437
|
}, {}, {
|
|
1230
1438
|
blobs: encodedData.blobs.map((b)=>b.data),
|
|
1231
1439
|
kzg
|
|
1232
|
-
}).catch((err)=>{
|
|
1233
|
-
const
|
|
1234
|
-
this.log.error(`Failed to validate blobs`, message, {
|
|
1235
|
-
metaMessages
|
|
1440
|
+
}).catch(async (err)=>{
|
|
1441
|
+
const viemError = formatViemError(err);
|
|
1442
|
+
this.log.error(`Failed to validate blobs`, viemError.message, {
|
|
1443
|
+
metaMessages: viemError.metaMessages
|
|
1444
|
+
});
|
|
1445
|
+
const validateBlobsData = encodeFunctionData({
|
|
1446
|
+
abi: RollupAbi,
|
|
1447
|
+
functionName: 'validateBlobs',
|
|
1448
|
+
args: [
|
|
1449
|
+
blobInput
|
|
1450
|
+
]
|
|
1451
|
+
});
|
|
1452
|
+
const l1BlockNumber = await this.l1TxUtils.getBlockNumber();
|
|
1453
|
+
this.backupFailedTx({
|
|
1454
|
+
id: keccak256(validateBlobsData),
|
|
1455
|
+
failureType: 'simulation',
|
|
1456
|
+
request: {
|
|
1457
|
+
to: this.rollupContract.address,
|
|
1458
|
+
data: validateBlobsData
|
|
1459
|
+
},
|
|
1460
|
+
blobData: encodedData.blobs.map((b)=>toHex(b.data)),
|
|
1461
|
+
l1BlockNumber: l1BlockNumber.toString(),
|
|
1462
|
+
error: {
|
|
1463
|
+
message: viemError.message,
|
|
1464
|
+
name: viemError.name
|
|
1465
|
+
},
|
|
1466
|
+
context: {
|
|
1467
|
+
actions: [
|
|
1468
|
+
'validate-blobs'
|
|
1469
|
+
],
|
|
1470
|
+
sender: this.getSenderAddress().toString()
|
|
1471
|
+
}
|
|
1236
1472
|
});
|
|
1237
1473
|
throw new Error('Failed to validate blobs');
|
|
1238
1474
|
});
|
|
@@ -1243,8 +1479,7 @@ export class SequencerPublisher {
|
|
|
1243
1479
|
header: encodedData.header.toViem(),
|
|
1244
1480
|
archive: toHex(encodedData.archive),
|
|
1245
1481
|
oracleInput: {
|
|
1246
|
-
|
|
1247
|
-
feeAssetPriceModifier: 0n
|
|
1482
|
+
feeAssetPriceModifier: encodedData.feeAssetPriceModifier
|
|
1248
1483
|
}
|
|
1249
1484
|
},
|
|
1250
1485
|
encodedData.attestationsAndSigners.getPackedAttestations(),
|
|
@@ -1252,88 +1487,23 @@ export class SequencerPublisher {
|
|
|
1252
1487
|
encodedData.attestationsAndSignersSignature.toViemSignature(),
|
|
1253
1488
|
blobInput
|
|
1254
1489
|
];
|
|
1255
|
-
const { rollupData, simulationResult } = await this.simulateProposeTx(args, timestamp, options);
|
|
1256
|
-
return {
|
|
1257
|
-
args,
|
|
1258
|
-
blobEvaluationGas,
|
|
1259
|
-
rollupData,
|
|
1260
|
-
simulationResult
|
|
1261
|
-
};
|
|
1262
|
-
}
|
|
1263
|
-
/**
|
|
1264
|
-
* Simulates the propose tx with eth_simulateV1
|
|
1265
|
-
* @param args - The propose tx args
|
|
1266
|
-
* @param timestamp - The timestamp to simulate proposal at
|
|
1267
|
-
* @returns The simulation result
|
|
1268
|
-
*/ async simulateProposeTx(args, timestamp, options) {
|
|
1269
1490
|
const rollupData = encodeFunctionData({
|
|
1270
1491
|
abi: RollupAbi,
|
|
1271
1492
|
functionName: 'propose',
|
|
1272
1493
|
args
|
|
1273
1494
|
});
|
|
1274
|
-
// override the pending checkpoint number if requested
|
|
1275
|
-
const forcePendingCheckpointNumberStateDiff = (options.forcePendingCheckpointNumber !== undefined ? await this.rollupContract.makePendingCheckpointNumberOverride(options.forcePendingCheckpointNumber) : []).flatMap((override)=>override.stateDiff ?? []);
|
|
1276
|
-
const stateOverrides = [
|
|
1277
|
-
{
|
|
1278
|
-
address: this.rollupContract.address,
|
|
1279
|
-
// @note we override checkBlob to false since blobs are not part simulate()
|
|
1280
|
-
stateDiff: [
|
|
1281
|
-
{
|
|
1282
|
-
slot: toPaddedHex(RollupContract.checkBlobStorageSlot, true),
|
|
1283
|
-
value: toPaddedHex(0n, true)
|
|
1284
|
-
},
|
|
1285
|
-
...forcePendingCheckpointNumberStateDiff
|
|
1286
|
-
]
|
|
1287
|
-
}
|
|
1288
|
-
];
|
|
1289
|
-
// In fisherman mode, simulate as the proposer but with sufficient balance
|
|
1290
|
-
if (this.proposerAddressForSimulation) {
|
|
1291
|
-
stateOverrides.push({
|
|
1292
|
-
address: this.proposerAddressForSimulation.toString(),
|
|
1293
|
-
balance: 10n * WEI_CONST * WEI_CONST
|
|
1294
|
-
});
|
|
1295
|
-
}
|
|
1296
|
-
const simulationResult = await this.l1TxUtils.simulate({
|
|
1297
|
-
to: this.rollupContract.address,
|
|
1298
|
-
data: rollupData,
|
|
1299
|
-
gas: MAX_L1_TX_LIMIT,
|
|
1300
|
-
...this.proposerAddressForSimulation && {
|
|
1301
|
-
from: this.proposerAddressForSimulation.toString()
|
|
1302
|
-
}
|
|
1303
|
-
}, {
|
|
1304
|
-
// @note we add 1n to the timestamp because geth implementation doesn't like simulation timestamp to be equal to the current block timestamp
|
|
1305
|
-
time: timestamp + 1n,
|
|
1306
|
-
// @note reth should have a 30m gas limit per block but throws errors that this tx is beyond limit so we increase here
|
|
1307
|
-
gasLimit: MAX_L1_TX_LIMIT * 2n
|
|
1308
|
-
}, stateOverrides, RollupAbi, {
|
|
1309
|
-
// @note fallback gas estimate to use if the node doesn't support simulation API
|
|
1310
|
-
fallbackGasEstimate: MAX_L1_TX_LIMIT
|
|
1311
|
-
}).catch((err)=>{
|
|
1312
|
-
// In fisherman mode, we expect ValidatorSelection__MissingProposerSignature since fisherman doesn't have proposer signature
|
|
1313
|
-
const viemError = formatViemError(err);
|
|
1314
|
-
if (this.config.fishermanMode && viemError.message?.includes('ValidatorSelection__MissingProposerSignature')) {
|
|
1315
|
-
this.log.debug(`Ignoring expected ValidatorSelection__MissingProposerSignature error in fisherman mode`);
|
|
1316
|
-
// Return a minimal simulation result with the fallback gas estimate
|
|
1317
|
-
return {
|
|
1318
|
-
gasUsed: MAX_L1_TX_LIMIT,
|
|
1319
|
-
logs: []
|
|
1320
|
-
};
|
|
1321
|
-
}
|
|
1322
|
-
this.log.error(`Failed to simulate propose tx`, viemError);
|
|
1323
|
-
throw err;
|
|
1324
|
-
});
|
|
1325
1495
|
return {
|
|
1326
|
-
|
|
1327
|
-
|
|
1496
|
+
args,
|
|
1497
|
+
blobEvaluationGas,
|
|
1498
|
+
rollupData
|
|
1328
1499
|
};
|
|
1329
1500
|
}
|
|
1330
|
-
async addProposeTx(checkpoint, encodedData, opts = {}
|
|
1501
|
+
async addProposeTx(checkpoint, encodedData, opts = {}) {
|
|
1331
1502
|
const slot = checkpoint.header.slotNumber;
|
|
1332
1503
|
const timer = new Timer();
|
|
1333
1504
|
const kzg = Blob.getViemKzgInstance();
|
|
1334
|
-
const { rollupData,
|
|
1505
|
+
const { rollupData, blobEvaluationGas } = await this.prepareProposeTx(encodedData);
|
|
1335
1506
|
const startBlock = await this.l1TxUtils.getBlockNumber();
|
|
1336
|
-
const gasLimit = this.l1TxUtils.bumpGasLimit(BigInt(Math.ceil(Number(simulationResult.gasUsed) * 64 / 63)) + blobEvaluationGas + SequencerPublisher.MULTICALL_OVERHEAD_GAS_GUESS);
|
|
1337
1507
|
// Send the blobs to the blob client preemptively. This helps in tests where the sequencer mistakingly thinks that the propose
|
|
1338
1508
|
// tx fails but it does get mined. We make sure that the blobs are sent to the blob client regardless of the tx outcome.
|
|
1339
1509
|
void Promise.resolve().then(()=>this.blobClient.sendBlobsToFilestore(encodedData.blobs).catch((_err)=>{
|
|
@@ -1347,9 +1517,10 @@ export class SequencerPublisher {
|
|
|
1347
1517
|
},
|
|
1348
1518
|
lastValidL2Slot: checkpoint.header.slotNumber,
|
|
1349
1519
|
gasConfig: {
|
|
1350
|
-
|
|
1351
|
-
gasLimit
|
|
1520
|
+
txTimeoutAt: opts.txTimeoutAt,
|
|
1521
|
+
gasLimit: undefined
|
|
1352
1522
|
},
|
|
1523
|
+
blobEvaluationGas,
|
|
1353
1524
|
blobConfig: {
|
|
1354
1525
|
blobs: encodedData.blobs.map((b)=>b.data),
|
|
1355
1526
|
kzg
|
|
@@ -1359,7 +1530,11 @@ export class SequencerPublisher {
|
|
|
1359
1530
|
return false;
|
|
1360
1531
|
}
|
|
1361
1532
|
const { receipt, stats, errorMsg } = result;
|
|
1362
|
-
const success =
|
|
1533
|
+
const success = extractEventSuccess(receipt, {
|
|
1534
|
+
address: this.rollupContract.address,
|
|
1535
|
+
abi: RollupAbi,
|
|
1536
|
+
eventName: 'CheckpointProposed'
|
|
1537
|
+
});
|
|
1363
1538
|
if (success) {
|
|
1364
1539
|
const endBlock = receipt.blockNumber;
|
|
1365
1540
|
const inclusionBlocks = Number(endBlock - startBlock);
|
|
@@ -1396,4 +1571,8 @@ export class SequencerPublisher {
|
|
|
1396
1571
|
}
|
|
1397
1572
|
});
|
|
1398
1573
|
}
|
|
1574
|
+
/** Returns the timestamp of the next L1 slot boundary after now. */ getNextL1SlotTimestamp() {
|
|
1575
|
+
const l1Constants = this.epochCache.getL1Constants();
|
|
1576
|
+
return getNextL1SlotTimestamp(this.dateProvider.nowInSeconds(), l1Constants);
|
|
1577
|
+
}
|
|
1399
1578
|
}
|