@aztec/sequencer-client 0.0.1-commit.f504929 → 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 +23 -5
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +63 -36
- package/dest/config.d.ts +32 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +81 -31
- 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 -26
- 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 +19 -3
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +30 -5
- 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 +3 -5
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-factory.js +2 -3
- package/dest/publisher/sequencer-publisher.d.ts +91 -69
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +445 -535
- 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 +831 -256
- 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 +14 -11
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +45 -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 +166 -39
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +616 -198
- 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/mock_checkpoint_builder.d.ts +7 -9
- package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.js +39 -30
- 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 -28
- package/src/client/sequencer-client.ts +90 -45
- package/src/config.ts +98 -31
- 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 +19 -88
- package/src/global_variable_builder/index.ts +3 -1
- package/src/publisher/config.ts +62 -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 +3 -6
- package/src/publisher/sequencer-publisher.ts +510 -584
- 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 +993 -294
- 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 +63 -25
- package/src/sequencer/requests_tracker.ts +43 -0
- package/src/sequencer/sequencer.ts +720 -220
- package/src/sequencer/types.ts +1 -1
- package/src/test/index.ts +2 -2
- package/src/test/mock_checkpoint_builder.ts +51 -48
- package/src/test/utils.ts +61 -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,44 +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 { 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';
|
|
380
|
+
import { trimmedBytesLength } from '@aztec/foundation/buffer';
|
|
382
381
|
import { pick } from '@aztec/foundation/collection';
|
|
383
382
|
import { TimeoutError } from '@aztec/foundation/error';
|
|
384
383
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
385
384
|
import { Signature } from '@aztec/foundation/eth-signature';
|
|
386
385
|
import { createLogger } from '@aztec/foundation/log';
|
|
387
|
-
import {
|
|
386
|
+
import { InterruptibleSleep } from '@aztec/foundation/sleep';
|
|
388
387
|
import { bufferToHex } from '@aztec/foundation/string';
|
|
389
388
|
import { Timer } from '@aztec/foundation/timer';
|
|
390
|
-
import { EmpireBaseAbi, ErrorsAbi, RollupAbi } from '@aztec/l1-artifacts';
|
|
389
|
+
import { EmpireBaseAbi, ErrorsAbi, RollupAbi, SlashingProposerAbi } from '@aztec/l1-artifacts';
|
|
391
390
|
import { encodeSlashConsensusVotes } from '@aztec/slasher';
|
|
392
391
|
import { CommitteeAttestationsAndSigners } from '@aztec/stdlib/block';
|
|
392
|
+
import { getLastL1SlotTimestampForL2Slot, getNextL1SlotTimestamp, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
393
393
|
import { getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
394
|
-
import { encodeFunctionData, keccak256,
|
|
394
|
+
import { encodeFunctionData, keccak256, toHex } from 'viem';
|
|
395
395
|
import { createL1TxFailedStore } from './l1_tx_failed_store/index.js';
|
|
396
|
+
import { SequencerBundleSimulator } from './sequencer-bundle-simulator.js';
|
|
396
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
|
+
}
|
|
397
408
|
export const Actions = [
|
|
398
409
|
'invalidate-by-invalid-attestation',
|
|
399
410
|
'invalidate-by-insufficient-attestations',
|
|
411
|
+
'prune',
|
|
400
412
|
'propose',
|
|
401
413
|
'governance-signal',
|
|
402
|
-
'empire-slashing-signal',
|
|
403
|
-
'create-empire-payload',
|
|
404
|
-
'execute-empire-payload',
|
|
405
414
|
'vote-offenses',
|
|
406
415
|
'execute-slash'
|
|
407
416
|
];
|
|
408
417
|
// Sorting for actions such that invalidations go before proposals, and proposals go before votes
|
|
409
418
|
export const compareActions = (a, b)=>Actions.indexOf(a) - Actions.indexOf(b);
|
|
410
|
-
_dec = trackSpan('SequencerPublisher.sendRequests'), _dec1 = trackSpan('SequencerPublisher.
|
|
419
|
+
_dec = trackSpan('SequencerPublisher.sendRequests'), _dec1 = trackSpan('SequencerPublisher.validateCheckpointHeader');
|
|
411
420
|
export class SequencerPublisher {
|
|
412
421
|
config;
|
|
413
422
|
static{
|
|
@@ -420,56 +429,60 @@ export class SequencerPublisher {
|
|
|
420
429
|
[
|
|
421
430
|
_dec1,
|
|
422
431
|
2,
|
|
423
|
-
"
|
|
424
|
-
],
|
|
425
|
-
[
|
|
426
|
-
_dec2,
|
|
427
|
-
2,
|
|
428
|
-
"validateCheckpointForSubmission"
|
|
432
|
+
"validateCheckpointHeader"
|
|
429
433
|
]
|
|
430
434
|
], []));
|
|
431
435
|
}
|
|
432
436
|
interrupted;
|
|
433
437
|
metrics;
|
|
438
|
+
bundleSimulator;
|
|
434
439
|
epochCache;
|
|
435
440
|
failedTxStore;
|
|
436
|
-
|
|
437
|
-
|
|
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;
|
|
438
446
|
lastActions;
|
|
439
|
-
isPayloadEmptyCache;
|
|
440
|
-
payloadProposedCache;
|
|
441
447
|
log;
|
|
442
448
|
ethereumSlotDuration;
|
|
449
|
+
aztecSlotDuration;
|
|
450
|
+
previousL1BlockWaitTimeoutMs;
|
|
451
|
+
previousL1BlockWaitPollIntervalMs;
|
|
452
|
+
/** Date provider for wall-clock time. */ dateProvider;
|
|
443
453
|
blobClient;
|
|
444
|
-
/** Address to use for simulations in fisherman mode (actual proposer's address) */ proposerAddressForSimulation;
|
|
445
454
|
/** Optional callback to obtain a replacement publisher when the current one fails to send. */ getNextPublisher;
|
|
446
455
|
/** L1 fee analyzer for fisherman mode */ l1FeeAnalyzer;
|
|
447
456
|
/** Fee asset price oracle for computing price modifiers from Uniswap V4 */ feeAssetPriceOracle;
|
|
448
|
-
|
|
449
|
-
static MULTICALL_OVERHEAD_GAS_GUESS = 5000n;
|
|
450
|
-
// Gas report for VotingWithSigTest shows a max gas of 100k, but we've seen it cost 700k+ in testnet
|
|
451
|
-
static VOTE_GAS_GUESS = 800_000n;
|
|
457
|
+
/** Interruptible sleep used by sendRequestsAt to wait until a target timestamp. */ interruptibleSleep;
|
|
452
458
|
l1TxUtils;
|
|
453
459
|
rollupContract;
|
|
454
460
|
govProposerContract;
|
|
455
461
|
slashingProposerContract;
|
|
456
|
-
slashFactoryContract;
|
|
457
462
|
tracer;
|
|
458
463
|
requests;
|
|
459
464
|
constructor(config, deps){
|
|
460
465
|
this.config = config;
|
|
461
466
|
this.interrupted = (_initProto(this), false);
|
|
462
|
-
this.
|
|
463
|
-
|
|
467
|
+
this.revertDecoderAbi = mergeAbis([
|
|
468
|
+
RollupAbi,
|
|
469
|
+
SlashingProposerAbi,
|
|
470
|
+
EmpireBaseAbi,
|
|
471
|
+
ErrorsAbi
|
|
472
|
+
]);
|
|
464
473
|
this.lastActions = {};
|
|
465
|
-
this.
|
|
466
|
-
this.payloadProposedCache = new Set();
|
|
474
|
+
this.interruptibleSleep = new InterruptibleSleep();
|
|
467
475
|
this.requests = [];
|
|
468
476
|
this.log = deps.log ?? createLogger('sequencer:publisher');
|
|
469
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;
|
|
470
482
|
this.epochCache = deps.epochCache;
|
|
471
483
|
this.lastActions = deps.lastActions;
|
|
472
484
|
this.blobClient = deps.blobClient;
|
|
485
|
+
this.dateProvider = deps.dateProvider;
|
|
473
486
|
const telemetry = deps.telemetry ?? getTelemetryClient();
|
|
474
487
|
this.metrics = deps.metrics ?? new SequencerPublisherMetrics(telemetry, 'SequencerPublisher');
|
|
475
488
|
this.tracer = telemetry.getTracer('SequencerPublisher');
|
|
@@ -483,15 +496,20 @@ export class SequencerPublisher {
|
|
|
483
496
|
const newSlashingProposer = await this.rollupContract.getSlashingProposer();
|
|
484
497
|
this.slashingProposerContract = newSlashingProposer;
|
|
485
498
|
});
|
|
486
|
-
this.slashFactoryContract = deps.slashFactoryContract;
|
|
487
499
|
// Initialize L1 fee analyzer for fisherman mode
|
|
488
500
|
if (config.fishermanMode) {
|
|
489
|
-
this.l1FeeAnalyzer = new L1FeeAnalyzer(this.l1TxUtils.client, deps.dateProvider,
|
|
501
|
+
this.l1FeeAnalyzer = new L1FeeAnalyzer(this.l1TxUtils.client, deps.dateProvider, this.log.createChild('fee-analyzer'));
|
|
490
502
|
}
|
|
491
503
|
// Initialize fee asset price oracle
|
|
492
|
-
this.feeAssetPriceOracle = new FeeAssetPriceOracle(this.l1TxUtils.client, this.rollupContract,
|
|
504
|
+
this.feeAssetPriceOracle = new FeeAssetPriceOracle(this.l1TxUtils.client, this.rollupContract, this.log.createChild('price-oracle'));
|
|
493
505
|
// Initialize failed L1 tx store (optional, for test networks)
|
|
494
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
|
+
});
|
|
495
513
|
}
|
|
496
514
|
/**
|
|
497
515
|
* Backs up a failed L1 transaction to the configured store for debugging.
|
|
@@ -514,9 +532,13 @@ export class SequencerPublisher {
|
|
|
514
532
|
}
|
|
515
533
|
/**
|
|
516
534
|
* Gets the fee asset price modifier from the oracle.
|
|
517
|
-
*
|
|
518
|
-
|
|
519
|
-
|
|
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);
|
|
520
542
|
}
|
|
521
543
|
getSenderAddress() {
|
|
522
544
|
return this.l1TxUtils.getSenderAddress();
|
|
@@ -526,17 +548,11 @@ export class SequencerPublisher {
|
|
|
526
548
|
*/ getL1FeeAnalyzer() {
|
|
527
549
|
return this.l1FeeAnalyzer;
|
|
528
550
|
}
|
|
529
|
-
/**
|
|
530
|
-
* Sets the proposer address to use for simulations in fisherman mode.
|
|
531
|
-
* @param proposerAddress - The actual proposer's address to use for balance lookups in simulations
|
|
532
|
-
*/ setProposerAddressForSimulation(proposerAddress) {
|
|
533
|
-
this.proposerAddressForSimulation = proposerAddress;
|
|
534
|
-
}
|
|
535
551
|
addRequest(request) {
|
|
536
552
|
this.requests.push(request);
|
|
537
553
|
}
|
|
538
554
|
getCurrentL2Slot() {
|
|
539
|
-
return this.epochCache.
|
|
555
|
+
return this.epochCache.getSlotNow();
|
|
540
556
|
}
|
|
541
557
|
/**
|
|
542
558
|
* Clears all pending requests without sending them.
|
|
@@ -589,11 +605,15 @@ export class SequencerPublisher {
|
|
|
589
605
|
}
|
|
590
606
|
/**
|
|
591
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.
|
|
592
612
|
* @returns one of:
|
|
593
613
|
* - A receipt and stats if the tx succeeded
|
|
594
614
|
* - a receipt and errorMsg if it failed on L1
|
|
595
615
|
* - undefined if no valid requests are found OR the tx failed to send.
|
|
596
|
-
*/ async sendRequests() {
|
|
616
|
+
*/ async sendRequests(targetSlot) {
|
|
597
617
|
const requestsToProcess = [
|
|
598
618
|
...this.requests
|
|
599
619
|
];
|
|
@@ -601,10 +621,9 @@ export class SequencerPublisher {
|
|
|
601
621
|
if (this.interrupted || requestsToProcess.length === 0) {
|
|
602
622
|
return undefined;
|
|
603
623
|
}
|
|
604
|
-
const currentL2Slot = this.getCurrentL2Slot();
|
|
624
|
+
const currentL2Slot = targetSlot ?? this.getCurrentL2Slot();
|
|
605
625
|
this.log.debug(`Sending requests on L2 slot ${currentL2Slot}`);
|
|
606
626
|
const validRequests = requestsToProcess.filter((request)=>request.lastValidL2Slot >= currentL2Slot);
|
|
607
|
-
const validActions = validRequests.map((x)=>x.action);
|
|
608
627
|
const expiredActions = requestsToProcess.filter((request)=>request.lastValidL2Slot < currentL2Slot).map((x)=>x.action);
|
|
609
628
|
if (validRequests.length !== requestsToProcess.length) {
|
|
610
629
|
this.log.warn(`Some requests were expired for slot ${currentL2Slot}`, {
|
|
@@ -622,71 +641,53 @@ export class SequencerPublisher {
|
|
|
622
641
|
this.log.debug(`No valid requests to send`);
|
|
623
642
|
return undefined;
|
|
624
643
|
}
|
|
625
|
-
//
|
|
626
|
-
|
|
627
|
-
// See https://github.com/AztecProtocol/aztec-packages/issues/11513
|
|
628
|
-
const gasConfigs = requestsToProcess.filter((request)=>request.gasConfig).map((request)=>request.gasConfig);
|
|
629
|
-
const blobConfigs = requestsToProcess.filter((request)=>request.blobConfig).map((request)=>request.blobConfig);
|
|
630
|
-
if (blobConfigs.length > 1) {
|
|
631
|
-
throw new Error('Multiple blob configs found');
|
|
632
|
-
}
|
|
633
|
-
const blobConfig = blobConfigs[0];
|
|
634
|
-
// Merge gasConfigs. Yields the sum of gasLimits, and the earliest txTimeoutAt, or undefined if no gasConfig sets them.
|
|
635
|
-
const gasLimits = gasConfigs.map((g)=>g?.gasLimit).filter((g)=>g !== undefined);
|
|
636
|
-
let gasLimit = gasLimits.length > 0 ? sumBigint(gasLimits) : undefined; // sum
|
|
637
|
-
// Cap at L1 block gas limit so the node accepts the tx ("gas limit too high" otherwise).
|
|
638
|
-
const maxGas = MAX_L1_TX_LIMIT;
|
|
639
|
-
if (gasLimit !== undefined && gasLimit > maxGas) {
|
|
640
|
-
this.log.debug('Capping bundled tx gas limit to L1 max', {
|
|
641
|
-
requested: gasLimit,
|
|
642
|
-
capped: maxGas
|
|
643
|
-
});
|
|
644
|
-
gasLimit = maxGas;
|
|
645
|
-
}
|
|
644
|
+
// Collect earliest txTimeoutAt across all requests.
|
|
645
|
+
const gasConfigs = validRequests.filter((request)=>request.gasConfig).map((request)=>request.gasConfig);
|
|
646
646
|
const txTimeoutAts = gasConfigs.map((g)=>g?.txTimeoutAt).filter((g)=>g !== undefined);
|
|
647
|
-
const txTimeoutAt = txTimeoutAts.length > 0 ? new Date(Math.min(...txTimeoutAts.map((g)=>g.getTime()))) : undefined;
|
|
648
|
-
const txConfig = {
|
|
649
|
-
gasLimit,
|
|
650
|
-
txTimeoutAt
|
|
651
|
-
};
|
|
647
|
+
const txTimeoutAt = txTimeoutAts.length > 0 ? new Date(Math.min(...txTimeoutAts.map((g)=>g.getTime()))) : undefined;
|
|
652
648
|
// Sort the requests so that proposals always go first
|
|
653
649
|
// This ensures the committee gets precomputed correctly
|
|
654
650
|
validRequests.sort((a, b)=>compareActions(a.action, b.action));
|
|
655
651
|
try {
|
|
656
|
-
//
|
|
657
|
-
const
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
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
|
|
674
671
|
};
|
|
675
672
|
this.log.debug('Forwarding transactions', {
|
|
676
|
-
|
|
673
|
+
requests: requests.map((request)=>request.action),
|
|
677
674
|
txConfig
|
|
678
675
|
});
|
|
679
|
-
const result = await this.forwardWithPublisherRotation(
|
|
676
|
+
const result = await this.forwardWithPublisherRotation(requests, txConfig, blobConfig);
|
|
680
677
|
if (result === undefined) {
|
|
681
678
|
return undefined;
|
|
682
679
|
}
|
|
683
|
-
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
|
+
];
|
|
684
685
|
return {
|
|
685
686
|
result,
|
|
686
687
|
expiredActions,
|
|
687
|
-
sentActions:
|
|
688
|
+
sentActions: requests.map((x)=>x.action),
|
|
688
689
|
successfulActions,
|
|
689
|
-
failedActions
|
|
690
|
+
failedActions: allFailedActions
|
|
690
691
|
};
|
|
691
692
|
} catch (err) {
|
|
692
693
|
const viemError = formatViemError(err);
|
|
@@ -700,23 +701,78 @@ export class SequencerPublisher {
|
|
|
700
701
|
}
|
|
701
702
|
}
|
|
702
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
|
+
}
|
|
703
741
|
/**
|
|
704
742
|
* Forwards transactions via Multicall3, rotating to the next available publisher if a send
|
|
705
743
|
* failure occurs (i.e. the tx never reached the chain).
|
|
706
744
|
* On-chain reverts and simulation errors are returned as-is without rotation.
|
|
707
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;
|
|
708
750
|
const triedAddresses = [];
|
|
709
751
|
let currentPublisher = this.l1TxUtils;
|
|
710
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
|
+
}
|
|
711
759
|
triedAddresses.push(currentPublisher.getSenderAddress());
|
|
712
760
|
try {
|
|
713
|
-
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
|
+
});
|
|
714
764
|
this.l1TxUtils = currentPublisher;
|
|
715
765
|
return result;
|
|
716
766
|
} catch (err) {
|
|
717
767
|
if (err instanceof TimeoutError) {
|
|
718
768
|
throw err;
|
|
719
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
|
+
}
|
|
720
776
|
const viemError = formatViemError(err);
|
|
721
777
|
if (!this.getNextPublisher) {
|
|
722
778
|
this.log.error('Failed to publish bundled transactions', viemError);
|
|
@@ -727,110 +783,132 @@ export class SequencerPublisher {
|
|
|
727
783
|
...triedAddresses
|
|
728
784
|
]);
|
|
729
785
|
if (!nextPublisher) {
|
|
730
|
-
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
|
+
});
|
|
731
789
|
return undefined;
|
|
732
790
|
}
|
|
733
791
|
currentPublisher = nextPublisher;
|
|
734
792
|
}
|
|
735
793
|
}
|
|
736
794
|
}
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
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;
|
|
762
843
|
}
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
requests
|
|
771
|
-
});
|
|
772
|
-
const successfulActions = [];
|
|
773
|
-
const failedActions = [];
|
|
774
|
-
for (const request of requests){
|
|
775
|
-
if (request.checkSuccess(request.request, result)) {
|
|
776
|
-
successfulActions.push(request.action);
|
|
777
|
-
} else {
|
|
778
|
-
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;
|
|
779
851
|
}
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
this.backupFailedTx({
|
|
784
|
-
id: result.receipt.transactionHash,
|
|
785
|
-
failureType: 'revert',
|
|
786
|
-
request: {
|
|
787
|
-
to: MULTI_CALL_3_ADDRESS,
|
|
788
|
-
data: txContext.multicallData
|
|
789
|
-
},
|
|
790
|
-
blobData: txContext.blobData,
|
|
791
|
-
l1BlockNumber: result.receipt.blockNumber.toString(),
|
|
792
|
-
receipt: {
|
|
793
|
-
transactionHash: result.receipt.transactionHash,
|
|
794
|
-
blockNumber: result.receipt.blockNumber.toString(),
|
|
795
|
-
gasUsed: (result.receipt.gasUsed ?? 0n).toString(),
|
|
796
|
-
status: 'reverted'
|
|
797
|
-
},
|
|
798
|
-
error: {
|
|
799
|
-
message: result.errorMsg ?? 'Transaction reverted'
|
|
800
|
-
},
|
|
801
|
-
context: {
|
|
802
|
-
actions: failedActions,
|
|
803
|
-
requests: requests.filter((r)=>failedActions.includes(r.action)).map((r)=>({
|
|
804
|
-
action: r.action,
|
|
805
|
-
to: r.request.to,
|
|
806
|
-
data: r.request.data
|
|
807
|
-
})),
|
|
808
|
-
sender: this.getSenderAddress().toString()
|
|
809
|
-
}
|
|
852
|
+
this.log.trace(`Previous L1 block not mined yet, continuing to wait`, {
|
|
853
|
+
...logCtx,
|
|
854
|
+
latestBlockTs
|
|
810
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);
|
|
811
860
|
}
|
|
812
|
-
return {
|
|
813
|
-
successfulActions,
|
|
814
|
-
failedActions
|
|
815
|
-
};
|
|
816
861
|
}
|
|
817
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
|
+
}
|
|
818
892
|
/**
|
|
819
|
-
* @notice Will call `
|
|
893
|
+
* @notice Will call `canProposeAt` to make sure that it is possible to propose
|
|
820
894
|
* @param tipArchive - The archive to check
|
|
821
895
|
* @returns The slot and block number if it is possible to propose, undefined otherwise
|
|
822
|
-
*/
|
|
896
|
+
*/ async canProposeAt(tipArchive, msgSender, simulationOverridesPlan) {
|
|
823
897
|
// TODO: #14291 - should loop through multiple keys to check if any of them can propose
|
|
824
|
-
|
|
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 = [
|
|
825
903
|
'SlotAlreadyInChain',
|
|
826
904
|
'InvalidProposer',
|
|
827
905
|
'InvalidArchive'
|
|
828
906
|
];
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
if (err instanceof FormattedViemError &&
|
|
833
|
-
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))}`, {
|
|
834
912
|
error: err.message
|
|
835
913
|
});
|
|
836
914
|
} else {
|
|
@@ -840,37 +918,31 @@ export class SequencerPublisher {
|
|
|
840
918
|
});
|
|
841
919
|
}
|
|
842
920
|
/**
|
|
843
|
-
* @notice Will simulate `
|
|
844
|
-
* @dev This is a convenience function that can be used by the sequencer to validate a "partial" header
|
|
845
|
-
* It will throw if the
|
|
846
|
-
* @param header - The
|
|
847
|
-
*/ 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) {
|
|
848
926
|
const flags = {
|
|
849
927
|
ignoreDA: true,
|
|
850
928
|
ignoreSignatures: true
|
|
851
929
|
};
|
|
852
930
|
const args = [
|
|
853
931
|
header.toViem(),
|
|
854
|
-
CommitteeAttestationsAndSigners.
|
|
932
|
+
CommitteeAttestationsAndSigners.packAttestations([]),
|
|
855
933
|
[],
|
|
856
934
|
Signature.empty().toViemSignature(),
|
|
857
935
|
`0x${'0'.repeat(64)}`,
|
|
858
936
|
header.blobsHash.toString(),
|
|
859
937
|
flags
|
|
860
938
|
];
|
|
861
|
-
const
|
|
862
|
-
const
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
// In fisherman mode, we can't know where the proposer is publishing from
|
|
866
|
-
// so we just add sufficient balance to the multicall3 address
|
|
867
|
-
balance = 10n * WEI_CONST * WEI_CONST; // 10 ETH
|
|
868
|
-
} else {
|
|
869
|
-
balance = await this.l1TxUtils.getSenderBalance();
|
|
870
|
-
}
|
|
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.
|
|
871
943
|
stateOverrides.push({
|
|
872
944
|
address: MULTI_CALL_3_ADDRESS,
|
|
873
|
-
balance
|
|
945
|
+
balance: 10n * WEI_CONST * WEI_CONST
|
|
874
946
|
});
|
|
875
947
|
await this.l1TxUtils.simulate({
|
|
876
948
|
to: this.rollupContract.address,
|
|
@@ -881,7 +953,7 @@ export class SequencerPublisher {
|
|
|
881
953
|
}),
|
|
882
954
|
from: MULTI_CALL_3_ADDRESS
|
|
883
955
|
}, {
|
|
884
|
-
time: ts
|
|
956
|
+
time: ts
|
|
885
957
|
}, stateOverrides);
|
|
886
958
|
this.log.debug(`Simulated validateHeader`);
|
|
887
959
|
}
|
|
@@ -927,6 +999,7 @@ export class SequencerPublisher {
|
|
|
927
999
|
gasUsed,
|
|
928
1000
|
checkpointNumber,
|
|
929
1001
|
forcePendingCheckpointNumber: CheckpointNumber(checkpointNumber - 1),
|
|
1002
|
+
lastArchive: validationResult.checkpoint.lastArchive,
|
|
930
1003
|
reason
|
|
931
1004
|
};
|
|
932
1005
|
} catch (err) {
|
|
@@ -939,8 +1012,8 @@ export class SequencerPublisher {
|
|
|
939
1012
|
request,
|
|
940
1013
|
error: viemError.message
|
|
941
1014
|
});
|
|
942
|
-
const
|
|
943
|
-
if (
|
|
1015
|
+
const latestProposedCheckpointNumber = await this.rollupContract.getCheckpointNumber();
|
|
1016
|
+
if (latestProposedCheckpointNumber < checkpointNumber) {
|
|
944
1017
|
this.log.verbose(`Checkpoint ${checkpointNumber} has already been invalidated`, {
|
|
945
1018
|
...logData
|
|
946
1019
|
});
|
|
@@ -990,7 +1063,11 @@ export class SequencerPublisher {
|
|
|
990
1063
|
reason
|
|
991
1064
|
};
|
|
992
1065
|
this.log.debug(`Building invalidate checkpoint ${checkpoint.checkpointNumber} request`, logData);
|
|
993
|
-
|
|
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;
|
|
994
1071
|
if (reason === 'invalid-attestation') {
|
|
995
1072
|
return this.rollupContract.buildInvalidateBadAttestationRequest(checkpoint.checkpointNumber, attestationsAndSigners, committee, validationResult.invalidIndex);
|
|
996
1073
|
} else if (reason === 'insufficient-attestations') {
|
|
@@ -1000,28 +1077,7 @@ export class SequencerPublisher {
|
|
|
1000
1077
|
throw new Error(`Unknown reason for invalidation`);
|
|
1001
1078
|
}
|
|
1002
1079
|
}
|
|
1003
|
-
|
|
1004
|
-
const ts = BigInt((await this.l1TxUtils.getBlock()).timestamp + this.ethereumSlotDuration);
|
|
1005
|
-
const blobFields = checkpoint.toBlobFields();
|
|
1006
|
-
const blobs = await getBlobsPerL1Block(blobFields);
|
|
1007
|
-
const blobInput = getPrefixedEthBlobCommitments(blobs);
|
|
1008
|
-
const args = [
|
|
1009
|
-
{
|
|
1010
|
-
header: checkpoint.header.toViem(),
|
|
1011
|
-
archive: toHex(checkpoint.archive.root.toBuffer()),
|
|
1012
|
-
oracleInput: {
|
|
1013
|
-
feeAssetPriceModifier: checkpoint.feeAssetPriceModifier
|
|
1014
|
-
}
|
|
1015
|
-
},
|
|
1016
|
-
attestationsAndSigners.getPackedAttestations(),
|
|
1017
|
-
attestationsAndSigners.getSigners().map((signer)=>signer.toString()),
|
|
1018
|
-
attestationsAndSignersSignature.toViemSignature(),
|
|
1019
|
-
blobInput
|
|
1020
|
-
];
|
|
1021
|
-
await this.simulateProposeTx(args, ts, options);
|
|
1022
|
-
return ts;
|
|
1023
|
-
}
|
|
1024
|
-
async enqueueCastSignalHelper(slotNumber, timestamp, signalType, payload, base, signerAddress, signer) {
|
|
1080
|
+
async enqueueCastSignalHelper(slotNumber, signalType, payload, base, signerAddress, signer) {
|
|
1025
1081
|
if (this.lastActions[signalType] && this.lastActions[signalType] === slotNumber) {
|
|
1026
1082
|
this.log.debug(`Skipping duplicate vote cast signal ${signalType} for slot ${slotNumber}`);
|
|
1027
1083
|
return false;
|
|
@@ -1033,6 +1089,17 @@ export class SequencerPublisher {
|
|
|
1033
1089
|
this.log.warn(`Cannot enqueue vote cast signal ${signalType} for address zero at slot ${slotNumber}`);
|
|
1034
1090
|
return false;
|
|
1035
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
|
+
}
|
|
1036
1103
|
const round = await base.computeRound(slotNumber);
|
|
1037
1104
|
const roundInfo = await base.getRoundInfo(this.rollupContract.address, round);
|
|
1038
1105
|
if (roundInfo.quorumReached) {
|
|
@@ -1041,30 +1108,40 @@ export class SequencerPublisher {
|
|
|
1041
1108
|
if (roundInfo.lastSignalSlot >= slotNumber) {
|
|
1042
1109
|
return false;
|
|
1043
1110
|
}
|
|
1044
|
-
if (await
|
|
1111
|
+
if (await base.isPayloadEmpty(payload)) {
|
|
1045
1112
|
this.log.warn(`Skipping vote cast for payload with empty code`);
|
|
1046
1113
|
return false;
|
|
1047
1114
|
}
|
|
1048
|
-
//
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
return false;
|
|
1064
|
-
}
|
|
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
|
+
});
|
|
1065
1130
|
}
|
|
1066
|
-
if (
|
|
1067
|
-
this.log.info(`Payload ${payload}
|
|
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
|
+
});
|
|
1068
1145
|
return false;
|
|
1069
1146
|
}
|
|
1070
1147
|
const cachedLastVote = this.lastActions[signalType];
|
|
@@ -1077,53 +1154,17 @@ export class SequencerPublisher {
|
|
|
1077
1154
|
signer: this.l1TxUtils.client.account?.address,
|
|
1078
1155
|
lastValidL2Slot: slotNumber
|
|
1079
1156
|
});
|
|
1080
|
-
const l1BlockNumber = await this.l1TxUtils.getBlockNumber();
|
|
1081
|
-
try {
|
|
1082
|
-
await this.l1TxUtils.simulate(request, {
|
|
1083
|
-
time: timestamp
|
|
1084
|
-
}, [], mergeAbis([
|
|
1085
|
-
request.abi ?? [],
|
|
1086
|
-
ErrorsAbi
|
|
1087
|
-
]));
|
|
1088
|
-
this.log.debug(`Simulation for ${action} at slot ${slotNumber} succeeded`, {
|
|
1089
|
-
request
|
|
1090
|
-
});
|
|
1091
|
-
} catch (err) {
|
|
1092
|
-
const viemError = formatViemError(err);
|
|
1093
|
-
this.log.error(`Failed simulation for ${action} at slot ${slotNumber} (enqueuing the action anyway)`, viemError);
|
|
1094
|
-
this.backupFailedTx({
|
|
1095
|
-
id: keccak256(request.data),
|
|
1096
|
-
failureType: 'simulation',
|
|
1097
|
-
request: {
|
|
1098
|
-
to: request.to,
|
|
1099
|
-
data: request.data,
|
|
1100
|
-
value: request.value?.toString()
|
|
1101
|
-
},
|
|
1102
|
-
l1BlockNumber: l1BlockNumber.toString(),
|
|
1103
|
-
error: {
|
|
1104
|
-
message: viemError.message,
|
|
1105
|
-
name: viemError.name
|
|
1106
|
-
},
|
|
1107
|
-
context: {
|
|
1108
|
-
actions: [
|
|
1109
|
-
action
|
|
1110
|
-
],
|
|
1111
|
-
slot: slotNumber,
|
|
1112
|
-
sender: this.getSenderAddress().toString()
|
|
1113
|
-
}
|
|
1114
|
-
});
|
|
1115
|
-
// Yes, we enqueue the request anyway, in case there was a bug with the simulation itself
|
|
1116
|
-
}
|
|
1117
1157
|
// TODO(palla/slash): All votes (governance and slashing) should txTimeoutAt at the end of the slot.
|
|
1118
1158
|
this.addRequest({
|
|
1119
|
-
gasConfig: {
|
|
1120
|
-
gasLimit: SequencerPublisher.VOTE_GAS_GUESS
|
|
1121
|
-
},
|
|
1122
1159
|
action,
|
|
1123
1160
|
request,
|
|
1124
1161
|
lastValidL2Slot: slotNumber,
|
|
1125
1162
|
checkSuccess: (_request, result)=>{
|
|
1126
|
-
const success = result &&
|
|
1163
|
+
const success = result && extractEventSuccess(result.receipt, {
|
|
1164
|
+
address: base.address.toString(),
|
|
1165
|
+
abi: EmpireBaseAbi,
|
|
1166
|
+
eventName: 'SignalCast'
|
|
1167
|
+
});
|
|
1127
1168
|
const logData = {
|
|
1128
1169
|
...result,
|
|
1129
1170
|
slotNumber,
|
|
@@ -1142,68 +1183,70 @@ export class SequencerPublisher {
|
|
|
1142
1183
|
});
|
|
1143
1184
|
return true;
|
|
1144
1185
|
}
|
|
1145
|
-
async isPayloadEmpty(payload) {
|
|
1146
|
-
const key = payload.toString();
|
|
1147
|
-
const cached = this.isPayloadEmptyCache.get(key);
|
|
1148
|
-
if (cached) {
|
|
1149
|
-
return cached;
|
|
1150
|
-
}
|
|
1151
|
-
const isEmpty = !await this.l1TxUtils.getCode(payload);
|
|
1152
|
-
this.isPayloadEmptyCache.set(key, isEmpty);
|
|
1153
|
-
return isEmpty;
|
|
1154
|
-
}
|
|
1155
1186
|
/**
|
|
1156
1187
|
* Enqueues a governance castSignal transaction to cast a signal for a given slot number.
|
|
1157
1188
|
* @param slotNumber - The slot number to cast a signal for.
|
|
1158
|
-
* @param timestamp - The timestamp of the slot to cast a signal for.
|
|
1159
1189
|
* @returns True if the signal was successfully enqueued, false otherwise.
|
|
1160
|
-
*/ enqueueGovernanceCastSignal(governancePayload, slotNumber,
|
|
1161
|
-
return this.enqueueCastSignalHelper(slotNumber,
|
|
1190
|
+
*/ enqueueGovernanceCastSignal(governancePayload, slotNumber, signerAddress, signer) {
|
|
1191
|
+
return this.enqueueCastSignalHelper(slotNumber, 'governance-signal', governancePayload, this.govProposerContract, signerAddress, signer);
|
|
1162
1192
|
}
|
|
1163
|
-
/**
|
|
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) {
|
|
1164
1244
|
if (actions.length === 0) {
|
|
1165
1245
|
this.log.debug(`No slashing actions to enqueue for slot ${slotNumber}`);
|
|
1166
1246
|
return false;
|
|
1167
1247
|
}
|
|
1168
1248
|
for (const action of actions){
|
|
1169
1249
|
switch(action.type){
|
|
1170
|
-
case 'vote-empire-payload':
|
|
1171
|
-
{
|
|
1172
|
-
if (this.slashingProposerContract?.type !== 'empire') {
|
|
1173
|
-
this.log.error('Cannot vote for empire payload on non-empire slashing contract');
|
|
1174
|
-
break;
|
|
1175
|
-
}
|
|
1176
|
-
this.log.debug(`Enqueuing slashing vote for payload ${action.payload} at slot ${slotNumber}`, {
|
|
1177
|
-
signerAddress
|
|
1178
|
-
});
|
|
1179
|
-
await this.enqueueCastSignalHelper(slotNumber, timestamp, 'empire-slashing-signal', action.payload, this.slashingProposerContract, signerAddress, signer);
|
|
1180
|
-
break;
|
|
1181
|
-
}
|
|
1182
|
-
case 'create-empire-payload':
|
|
1183
|
-
{
|
|
1184
|
-
this.log.debug(`Enqueuing slashing create payload at slot ${slotNumber}`, {
|
|
1185
|
-
slotNumber,
|
|
1186
|
-
signerAddress
|
|
1187
|
-
});
|
|
1188
|
-
const request = this.slashFactoryContract.buildCreatePayloadRequest(action.data);
|
|
1189
|
-
await this.simulateAndEnqueueRequest('create-empire-payload', request, (receipt)=>!!this.slashFactoryContract.tryExtractSlashPayloadCreatedEvent(receipt.logs), slotNumber, timestamp);
|
|
1190
|
-
break;
|
|
1191
|
-
}
|
|
1192
|
-
case 'execute-empire-payload':
|
|
1193
|
-
{
|
|
1194
|
-
this.log.debug(`Enqueuing slashing execute payload at slot ${slotNumber}`, {
|
|
1195
|
-
slotNumber,
|
|
1196
|
-
signerAddress
|
|
1197
|
-
});
|
|
1198
|
-
if (this.slashingProposerContract?.type !== 'empire') {
|
|
1199
|
-
this.log.error('Cannot execute slashing payload on non-empire slashing contract');
|
|
1200
|
-
return false;
|
|
1201
|
-
}
|
|
1202
|
-
const empireSlashingProposer = this.slashingProposerContract;
|
|
1203
|
-
const request = empireSlashingProposer.buildExecuteRoundRequest(action.round);
|
|
1204
|
-
await this.simulateAndEnqueueRequest('execute-empire-payload', request, (receipt)=>!!empireSlashingProposer.tryExtractPayloadSubmittedEvent(receipt.logs), slotNumber, timestamp);
|
|
1205
|
-
break;
|
|
1206
|
-
}
|
|
1207
1250
|
case 'vote-offenses':
|
|
1208
1251
|
{
|
|
1209
1252
|
this.log.debug(`Enqueuing slashing vote for ${action.votes.length} votes at slot ${slotNumber}`, {
|
|
@@ -1212,14 +1255,17 @@ export class SequencerPublisher {
|
|
|
1212
1255
|
votesCount: action.votes.length,
|
|
1213
1256
|
signerAddress
|
|
1214
1257
|
});
|
|
1215
|
-
if (this.slashingProposerContract
|
|
1216
|
-
this.log.error('
|
|
1258
|
+
if (!this.slashingProposerContract) {
|
|
1259
|
+
this.log.error('No slashing proposer contract available');
|
|
1217
1260
|
return false;
|
|
1218
1261
|
}
|
|
1219
|
-
const tallySlashingProposer = this.slashingProposerContract;
|
|
1220
1262
|
const votes = bufferToHex(encodeSlashConsensusVotes(action.votes));
|
|
1221
|
-
const request = await
|
|
1222
|
-
|
|
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);
|
|
1223
1269
|
break;
|
|
1224
1270
|
}
|
|
1225
1271
|
case 'execute-slash':
|
|
@@ -1229,13 +1275,16 @@ export class SequencerPublisher {
|
|
|
1229
1275
|
round: action.round,
|
|
1230
1276
|
signerAddress
|
|
1231
1277
|
});
|
|
1232
|
-
if (this.slashingProposerContract
|
|
1233
|
-
this.log.error('
|
|
1278
|
+
if (!this.slashingProposerContract) {
|
|
1279
|
+
this.log.error('No slashing proposer contract available');
|
|
1234
1280
|
return false;
|
|
1235
1281
|
}
|
|
1236
|
-
const
|
|
1237
|
-
|
|
1238
|
-
|
|
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);
|
|
1239
1288
|
break;
|
|
1240
1289
|
}
|
|
1241
1290
|
default:
|
|
@@ -1247,7 +1296,7 @@ export class SequencerPublisher {
|
|
|
1247
1296
|
}
|
|
1248
1297
|
return true;
|
|
1249
1298
|
}
|
|
1250
|
-
/**
|
|
1299
|
+
/** Enqueues a proposal for a checkpoint on L1 */ async enqueueProposeCheckpoint(checkpoint, attestationsAndSigners, attestationsAndSignersSignature, opts = {}) {
|
|
1251
1300
|
const checkpointHeader = checkpoint.header;
|
|
1252
1301
|
const blobFields = checkpoint.toBlobFields();
|
|
1253
1302
|
const blobs = await getBlobsPerL1Block(blobFields);
|
|
@@ -1259,52 +1308,38 @@ export class SequencerPublisher {
|
|
|
1259
1308
|
attestationsAndSignersSignature,
|
|
1260
1309
|
feeAssetPriceModifier: checkpoint.feeAssetPriceModifier
|
|
1261
1310
|
};
|
|
1262
|
-
let ts;
|
|
1263
|
-
try {
|
|
1264
|
-
// @note This will make sure that we are passing the checks for our header ASSUMING that the data is also made available
|
|
1265
|
-
// This means that we can avoid the simulation issues in later checks.
|
|
1266
|
-
// By simulation issue, I mean the fact that the block.timestamp is equal to the last block, not the next, which
|
|
1267
|
-
// make time consistency checks break.
|
|
1268
|
-
// TODO(palla): Check whether we're validating twice, once here and once within addProposeTx, since we call simulateProposeTx in both places.
|
|
1269
|
-
ts = await this.validateCheckpointForSubmission(checkpoint, attestationsAndSigners, attestationsAndSignersSignature, opts);
|
|
1270
|
-
} catch (err) {
|
|
1271
|
-
this.log.error(`Checkpoint validation failed. ${err instanceof Error ? err.message : 'No error message'}`, err, {
|
|
1272
|
-
...checkpoint.getStats(),
|
|
1273
|
-
slotNumber: checkpoint.header.slotNumber,
|
|
1274
|
-
forcePendingCheckpointNumber: opts.forcePendingCheckpointNumber
|
|
1275
|
-
});
|
|
1276
|
-
throw err;
|
|
1277
|
-
}
|
|
1278
1311
|
this.log.verbose(`Enqueuing checkpoint propose transaction`, {
|
|
1279
1312
|
...checkpoint.toCheckpointInfo(),
|
|
1280
|
-
|
|
1313
|
+
txTimeoutAt: opts.txTimeoutAt
|
|
1314
|
+
});
|
|
1315
|
+
await this.addProposeTx(checkpoint, proposeTxArgs, {
|
|
1316
|
+
txTimeoutAt: opts.txTimeoutAt
|
|
1281
1317
|
});
|
|
1282
|
-
await this.addProposeTx(checkpoint, proposeTxArgs, opts, ts);
|
|
1283
1318
|
}
|
|
1284
1319
|
enqueueInvalidateCheckpoint(request, opts = {}) {
|
|
1285
1320
|
if (!request) {
|
|
1286
1321
|
return;
|
|
1287
1322
|
}
|
|
1288
|
-
// We issued the simulation against the rollup contract, so we need to account for the overhead of the multicall3
|
|
1289
|
-
const gasLimit = this.l1TxUtils.bumpGasLimit(BigInt(Math.ceil(Number(request.gasUsed) * 64 / 63)));
|
|
1290
1323
|
const { gasUsed, checkpointNumber } = request;
|
|
1291
1324
|
const logData = {
|
|
1292
1325
|
gasUsed,
|
|
1293
1326
|
checkpointNumber,
|
|
1294
|
-
gasLimit,
|
|
1295
1327
|
opts
|
|
1296
1328
|
};
|
|
1297
1329
|
this.log.verbose(`Enqueuing invalidate checkpoint request`, logData);
|
|
1298
1330
|
this.addRequest({
|
|
1299
1331
|
action: `invalidate-by-${request.reason}`,
|
|
1300
1332
|
request: request.request,
|
|
1301
|
-
gasConfig: {
|
|
1302
|
-
gasLimit,
|
|
1333
|
+
gasConfig: opts.txTimeoutAt ? {
|
|
1303
1334
|
txTimeoutAt: opts.txTimeoutAt
|
|
1304
|
-
},
|
|
1335
|
+
} : undefined,
|
|
1305
1336
|
lastValidL2Slot: SlotNumber(this.getCurrentL2Slot() + 2),
|
|
1306
1337
|
checkSuccess: (_req, result)=>{
|
|
1307
|
-
const success = result &&
|
|
1338
|
+
const success = result && extractEventSuccess(result.receipt, {
|
|
1339
|
+
address: this.rollupContract.address,
|
|
1340
|
+
abi: RollupAbi,
|
|
1341
|
+
eventName: 'CheckpointInvalidated'
|
|
1342
|
+
});
|
|
1308
1343
|
if (!success) {
|
|
1309
1344
|
this.log.warn(`Invalidate checkpoint ${request.checkpointNumber} failed`, {
|
|
1310
1345
|
...result,
|
|
@@ -1320,89 +1355,36 @@ export class SequencerPublisher {
|
|
|
1320
1355
|
}
|
|
1321
1356
|
});
|
|
1322
1357
|
}
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
};
|
|
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) {
|
|
1329
1363
|
if (this.lastActions[action] && this.lastActions[action] === slotNumber) {
|
|
1330
1364
|
this.log.debug(`Skipping duplicate action ${action} for slot ${slotNumber}`);
|
|
1331
1365
|
return false;
|
|
1332
1366
|
}
|
|
1333
1367
|
const cachedLastActionSlot = this.lastActions[action];
|
|
1334
1368
|
this.lastActions[action] = slotNumber;
|
|
1335
|
-
this.log.debug(`
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
const simulateAbi = mergeAbis([
|
|
1339
|
-
request.abi ?? [],
|
|
1340
|
-
ErrorsAbi
|
|
1341
|
-
]);
|
|
1342
|
-
try {
|
|
1343
|
-
({ gasUsed } = await this.l1TxUtils.simulate(request, {
|
|
1344
|
-
time: timestamp
|
|
1345
|
-
}, [], simulateAbi)); // TODO(palla/slash): Check the timestamp logic
|
|
1346
|
-
this.log.verbose(`Simulation for ${action} succeeded`, {
|
|
1347
|
-
...logData,
|
|
1348
|
-
request,
|
|
1349
|
-
gasUsed
|
|
1350
|
-
});
|
|
1351
|
-
} catch (err) {
|
|
1352
|
-
const viemError = formatViemError(err, simulateAbi);
|
|
1353
|
-
this.log.error(`Simulation for ${action} at ${slotNumber} failed`, viemError, logData);
|
|
1354
|
-
this.backupFailedTx({
|
|
1355
|
-
id: keccak256(request.data),
|
|
1356
|
-
failureType: 'simulation',
|
|
1357
|
-
request: {
|
|
1358
|
-
to: request.to,
|
|
1359
|
-
data: request.data,
|
|
1360
|
-
value: request.value?.toString()
|
|
1361
|
-
},
|
|
1362
|
-
l1BlockNumber: l1BlockNumber.toString(),
|
|
1363
|
-
error: {
|
|
1364
|
-
message: viemError.message,
|
|
1365
|
-
name: viemError.name
|
|
1366
|
-
},
|
|
1367
|
-
context: {
|
|
1368
|
-
actions: [
|
|
1369
|
-
action
|
|
1370
|
-
],
|
|
1371
|
-
slot: slotNumber,
|
|
1372
|
-
sender: this.getSenderAddress().toString()
|
|
1373
|
-
}
|
|
1374
|
-
});
|
|
1375
|
-
return false;
|
|
1376
|
-
}
|
|
1377
|
-
// We issued the simulation against the rollup contract, so we need to account for the overhead of the multicall3
|
|
1378
|
-
const gasLimit = this.l1TxUtils.bumpGasLimit(BigInt(Math.ceil(Number(gasUsed) * 64 / 63)));
|
|
1379
|
-
logData.gasLimit = gasLimit;
|
|
1380
|
-
// Store the ABI used for simulation on the request so Multicall3.forward can decode errors
|
|
1381
|
-
// when the tx is sent and a revert is diagnosed via simulation.
|
|
1382
|
-
const requestWithAbi = {
|
|
1383
|
-
...request,
|
|
1384
|
-
abi: simulateAbi
|
|
1385
|
-
};
|
|
1386
|
-
this.log.debug(`Enqueuing ${action}`, logData);
|
|
1369
|
+
this.log.debug(`Enqueuing ${action}`, {
|
|
1370
|
+
slotNumber
|
|
1371
|
+
});
|
|
1387
1372
|
this.addRequest({
|
|
1388
1373
|
action,
|
|
1389
|
-
request
|
|
1390
|
-
gasConfig: {
|
|
1391
|
-
gasLimit
|
|
1392
|
-
},
|
|
1374
|
+
request,
|
|
1393
1375
|
lastValidL2Slot: slotNumber,
|
|
1394
|
-
checkSuccess: (
|
|
1395
|
-
const success = result && result.receipt
|
|
1376
|
+
checkSuccess: (_request, result)=>{
|
|
1377
|
+
const success = result && extractEventSuccess(result.receipt, eventOpts);
|
|
1396
1378
|
if (!success) {
|
|
1397
1379
|
this.log.warn(`Action ${action} at ${slotNumber} failed`, {
|
|
1398
1380
|
...result,
|
|
1399
|
-
|
|
1381
|
+
slotNumber
|
|
1400
1382
|
});
|
|
1401
1383
|
this.lastActions[action] = cachedLastActionSlot;
|
|
1402
1384
|
} else {
|
|
1403
1385
|
this.log.info(`Action ${action} at ${slotNumber} succeeded`, {
|
|
1404
1386
|
...result,
|
|
1405
|
-
|
|
1387
|
+
slotNumber
|
|
1406
1388
|
});
|
|
1407
1389
|
}
|
|
1408
1390
|
return !!success;
|
|
@@ -1417,13 +1399,14 @@ export class SequencerPublisher {
|
|
|
1417
1399
|
* A call to `restart` is required before you can continue publishing.
|
|
1418
1400
|
*/ interrupt() {
|
|
1419
1401
|
this.interrupted = true;
|
|
1402
|
+
this.interruptibleSleep.interrupt();
|
|
1420
1403
|
this.l1TxUtils.interrupt();
|
|
1421
1404
|
}
|
|
1422
1405
|
/** Restarts the publisher after calling `interrupt`. */ restart() {
|
|
1423
1406
|
this.interrupted = false;
|
|
1424
1407
|
this.l1TxUtils.restart();
|
|
1425
1408
|
}
|
|
1426
|
-
async prepareProposeTx(encodedData
|
|
1409
|
+
async prepareProposeTx(encodedData) {
|
|
1427
1410
|
const kzg = Blob.getViemKzgInstance();
|
|
1428
1411
|
const blobInput = getPrefixedEthBlobCommitments(encodedData.blobs);
|
|
1429
1412
|
this.log.debug('Validating blob input', {
|
|
@@ -1437,7 +1420,11 @@ export class SequencerPublisher {
|
|
|
1437
1420
|
blobEvaluationGas = BigInt(encodedData.blobs.length) * 21_000n;
|
|
1438
1421
|
this.log.debug(`Using fixed blob evaluation gas estimate in fisherman mode: ${blobEvaluationGas}`);
|
|
1439
1422
|
} else {
|
|
1440
|
-
//
|
|
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.
|
|
1441
1428
|
blobEvaluationGas = await this.l1TxUtils.estimateGas(this.getSenderAddress().toString(), {
|
|
1442
1429
|
to: this.rollupContract.address,
|
|
1443
1430
|
data: encodeFunctionData({
|
|
@@ -1500,109 +1487,23 @@ export class SequencerPublisher {
|
|
|
1500
1487
|
encodedData.attestationsAndSignersSignature.toViemSignature(),
|
|
1501
1488
|
blobInput
|
|
1502
1489
|
];
|
|
1503
|
-
const { rollupData, simulationResult } = await this.simulateProposeTx(args, timestamp, options);
|
|
1504
|
-
return {
|
|
1505
|
-
args,
|
|
1506
|
-
blobEvaluationGas,
|
|
1507
|
-
rollupData,
|
|
1508
|
-
simulationResult
|
|
1509
|
-
};
|
|
1510
|
-
}
|
|
1511
|
-
/**
|
|
1512
|
-
* Simulates the propose tx with eth_simulateV1
|
|
1513
|
-
* @param args - The propose tx args
|
|
1514
|
-
* @param timestamp - The timestamp to simulate proposal at
|
|
1515
|
-
* @returns The simulation result
|
|
1516
|
-
*/ async simulateProposeTx(args, timestamp, options) {
|
|
1517
1490
|
const rollupData = encodeFunctionData({
|
|
1518
1491
|
abi: RollupAbi,
|
|
1519
1492
|
functionName: 'propose',
|
|
1520
1493
|
args
|
|
1521
1494
|
});
|
|
1522
|
-
// override the pending checkpoint number if requested
|
|
1523
|
-
const forcePendingCheckpointNumberStateDiff = (options.forcePendingCheckpointNumber !== undefined ? await this.rollupContract.makePendingCheckpointNumberOverride(options.forcePendingCheckpointNumber) : []).flatMap((override)=>override.stateDiff ?? []);
|
|
1524
|
-
const stateOverrides = [
|
|
1525
|
-
{
|
|
1526
|
-
address: this.rollupContract.address,
|
|
1527
|
-
// @note we override checkBlob to false since blobs are not part simulate()
|
|
1528
|
-
stateDiff: [
|
|
1529
|
-
{
|
|
1530
|
-
slot: toPaddedHex(RollupContract.checkBlobStorageSlot, true),
|
|
1531
|
-
value: toPaddedHex(0n, true)
|
|
1532
|
-
},
|
|
1533
|
-
...forcePendingCheckpointNumberStateDiff
|
|
1534
|
-
]
|
|
1535
|
-
}
|
|
1536
|
-
];
|
|
1537
|
-
// In fisherman mode, simulate as the proposer but with sufficient balance
|
|
1538
|
-
if (this.proposerAddressForSimulation) {
|
|
1539
|
-
stateOverrides.push({
|
|
1540
|
-
address: this.proposerAddressForSimulation.toString(),
|
|
1541
|
-
balance: 10n * WEI_CONST * WEI_CONST
|
|
1542
|
-
});
|
|
1543
|
-
}
|
|
1544
|
-
const l1BlockNumber = await this.l1TxUtils.getBlockNumber();
|
|
1545
|
-
const simulationResult = await this.l1TxUtils.simulate({
|
|
1546
|
-
to: this.rollupContract.address,
|
|
1547
|
-
data: rollupData,
|
|
1548
|
-
gas: MAX_L1_TX_LIMIT,
|
|
1549
|
-
...this.proposerAddressForSimulation && {
|
|
1550
|
-
from: this.proposerAddressForSimulation.toString()
|
|
1551
|
-
}
|
|
1552
|
-
}, {
|
|
1553
|
-
// @note we add 1n to the timestamp because geth implementation doesn't like simulation timestamp to be equal to the current block timestamp
|
|
1554
|
-
time: timestamp + 1n,
|
|
1555
|
-
// @note reth should have a 30m gas limit per block but throws errors that this tx is beyond limit so we increase here
|
|
1556
|
-
gasLimit: MAX_L1_TX_LIMIT * 2n
|
|
1557
|
-
}, stateOverrides, RollupAbi, {
|
|
1558
|
-
// @note fallback gas estimate to use if the node doesn't support simulation API
|
|
1559
|
-
fallbackGasEstimate: MAX_L1_TX_LIMIT
|
|
1560
|
-
}).catch((err)=>{
|
|
1561
|
-
// In fisherman mode, we expect ValidatorSelection__MissingProposerSignature since fisherman doesn't have proposer signature
|
|
1562
|
-
const viemError = formatViemError(err);
|
|
1563
|
-
if (this.config.fishermanMode && viemError.message?.includes('ValidatorSelection__MissingProposerSignature')) {
|
|
1564
|
-
this.log.debug(`Ignoring expected ValidatorSelection__MissingProposerSignature error in fisherman mode`);
|
|
1565
|
-
// Return a minimal simulation result with the fallback gas estimate
|
|
1566
|
-
return {
|
|
1567
|
-
gasUsed: MAX_L1_TX_LIMIT,
|
|
1568
|
-
logs: []
|
|
1569
|
-
};
|
|
1570
|
-
}
|
|
1571
|
-
this.log.error(`Failed to simulate propose tx`, viemError);
|
|
1572
|
-
this.backupFailedTx({
|
|
1573
|
-
id: keccak256(rollupData),
|
|
1574
|
-
failureType: 'simulation',
|
|
1575
|
-
request: {
|
|
1576
|
-
to: this.rollupContract.address,
|
|
1577
|
-
data: rollupData
|
|
1578
|
-
},
|
|
1579
|
-
l1BlockNumber: l1BlockNumber.toString(),
|
|
1580
|
-
error: {
|
|
1581
|
-
message: viemError.message,
|
|
1582
|
-
name: viemError.name
|
|
1583
|
-
},
|
|
1584
|
-
context: {
|
|
1585
|
-
actions: [
|
|
1586
|
-
'propose'
|
|
1587
|
-
],
|
|
1588
|
-
slot: Number(args[0].header.slotNumber),
|
|
1589
|
-
sender: this.getSenderAddress().toString()
|
|
1590
|
-
}
|
|
1591
|
-
});
|
|
1592
|
-
throw err;
|
|
1593
|
-
});
|
|
1594
1495
|
return {
|
|
1595
|
-
|
|
1596
|
-
|
|
1496
|
+
args,
|
|
1497
|
+
blobEvaluationGas,
|
|
1498
|
+
rollupData
|
|
1597
1499
|
};
|
|
1598
1500
|
}
|
|
1599
|
-
async addProposeTx(checkpoint, encodedData, opts = {}
|
|
1501
|
+
async addProposeTx(checkpoint, encodedData, opts = {}) {
|
|
1600
1502
|
const slot = checkpoint.header.slotNumber;
|
|
1601
1503
|
const timer = new Timer();
|
|
1602
1504
|
const kzg = Blob.getViemKzgInstance();
|
|
1603
|
-
const { rollupData,
|
|
1505
|
+
const { rollupData, blobEvaluationGas } = await this.prepareProposeTx(encodedData);
|
|
1604
1506
|
const startBlock = await this.l1TxUtils.getBlockNumber();
|
|
1605
|
-
const gasLimit = this.l1TxUtils.bumpGasLimit(BigInt(Math.ceil(Number(simulationResult.gasUsed) * 64 / 63)) + blobEvaluationGas + SequencerPublisher.MULTICALL_OVERHEAD_GAS_GUESS);
|
|
1606
1507
|
// Send the blobs to the blob client preemptively. This helps in tests where the sequencer mistakingly thinks that the propose
|
|
1607
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.
|
|
1608
1509
|
void Promise.resolve().then(()=>this.blobClient.sendBlobsToFilestore(encodedData.blobs).catch((_err)=>{
|
|
@@ -1616,9 +1517,10 @@ export class SequencerPublisher {
|
|
|
1616
1517
|
},
|
|
1617
1518
|
lastValidL2Slot: checkpoint.header.slotNumber,
|
|
1618
1519
|
gasConfig: {
|
|
1619
|
-
|
|
1620
|
-
gasLimit
|
|
1520
|
+
txTimeoutAt: opts.txTimeoutAt,
|
|
1521
|
+
gasLimit: undefined
|
|
1621
1522
|
},
|
|
1523
|
+
blobEvaluationGas,
|
|
1622
1524
|
blobConfig: {
|
|
1623
1525
|
blobs: encodedData.blobs.map((b)=>b.data),
|
|
1624
1526
|
kzg
|
|
@@ -1628,7 +1530,11 @@ export class SequencerPublisher {
|
|
|
1628
1530
|
return false;
|
|
1629
1531
|
}
|
|
1630
1532
|
const { receipt, stats, errorMsg } = result;
|
|
1631
|
-
const success =
|
|
1533
|
+
const success = extractEventSuccess(receipt, {
|
|
1534
|
+
address: this.rollupContract.address,
|
|
1535
|
+
abi: RollupAbi,
|
|
1536
|
+
eventName: 'CheckpointProposed'
|
|
1537
|
+
});
|
|
1632
1538
|
if (success) {
|
|
1633
1539
|
const endBlock = receipt.blockNumber;
|
|
1634
1540
|
const inclusionBlocks = Number(endBlock - startBlock);
|
|
@@ -1665,4 +1571,8 @@ export class SequencerPublisher {
|
|
|
1665
1571
|
}
|
|
1666
1572
|
});
|
|
1667
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
|
+
}
|
|
1668
1578
|
}
|