@aztec/sequencer-client 0.0.1-commit.181e2d196 → 0.0.1-commit.189eedb3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +281 -21
- package/dest/client/sequencer-client.d.ts +8 -3
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +51 -29
- package/dest/config.d.ts +26 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +51 -22
- package/dest/global_variable_builder/fee_predictor.d.ts +37 -0
- package/dest/global_variable_builder/fee_predictor.d.ts.map +1 -0
- package/dest/global_variable_builder/fee_predictor.js +128 -0
- package/dest/global_variable_builder/fee_provider.d.ts +21 -0
- package/dest/global_variable_builder/fee_provider.d.ts.map +1 -0
- package/dest/global_variable_builder/fee_provider.js +58 -0
- package/dest/global_variable_builder/global_builder.d.ts +14 -14
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +16 -50
- 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/index.d.ts +2 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -1
- package/dest/publisher/config.d.ts +15 -3
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +19 -4
- 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 +73 -65
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +318 -523
- package/dest/sequencer/automine/automine_factory.d.ts +54 -0
- package/dest/sequencer/automine/automine_factory.d.ts.map +1 -0
- package/dest/sequencer/automine/automine_factory.js +84 -0
- package/dest/sequencer/automine/automine_sequencer.d.ts +151 -0
- package/dest/sequencer/automine/automine_sequencer.d.ts.map +1 -0
- package/dest/sequencer/automine/automine_sequencer.js +509 -0
- package/dest/sequencer/chain_state_overrides.d.ts +61 -0
- package/dest/sequencer/chain_state_overrides.d.ts.map +1 -0
- package/dest/sequencer/chain_state_overrides.js +98 -0
- package/dest/sequencer/checkpoint_proposal_job.d.ts +60 -12
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_proposal_job.js +774 -219
- 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/events.d.ts +48 -2
- package/dest/sequencer/events.d.ts.map +1 -1
- package/dest/sequencer/index.d.ts +3 -1
- package/dest/sequencer/index.d.ts.map +1 -1
- package/dest/sequencer/index.js +2 -0
- package/dest/sequencer/metrics.d.ts +13 -10
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +45 -20
- package/dest/sequencer/sequencer.d.ts +68 -17
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +359 -119
- package/dest/sequencer/timetable.d.ts +14 -3
- package/dest/sequencer/timetable.d.ts.map +1 -1
- package/dest/sequencer/timetable.js +47 -43
- package/dest/sequencer/types.d.ts +2 -2
- package/dest/sequencer/types.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 +1 -1
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +7 -6
- package/package.json +27 -28
- package/src/client/sequencer-client.ts +71 -33
- package/src/config.ts +61 -22
- package/src/global_variable_builder/README.md +44 -0
- package/src/global_variable_builder/fee_predictor.ts +172 -0
- package/src/global_variable_builder/fee_provider.ts +75 -0
- package/src/global_variable_builder/global_builder.ts +25 -62
- package/src/global_variable_builder/index.ts +3 -1
- package/src/index.ts +10 -1
- package/src/publisher/config.ts +40 -6
- 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 +377 -568
- package/src/sequencer/README.md +162 -450
- package/src/sequencer/automine/README.md +46 -0
- package/src/sequencer/automine/automine_factory.ts +145 -0
- package/src/sequencer/automine/automine_sequencer.ts +595 -0
- package/src/sequencer/chain_state_overrides.ts +162 -0
- package/src/sequencer/checkpoint_proposal_job.ts +923 -251
- package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
- package/src/sequencer/checkpoint_voter.ts +1 -12
- package/src/sequencer/events.ts +51 -2
- package/src/sequencer/index.ts +2 -0
- package/src/sequencer/metrics.ts +57 -24
- package/src/sequencer/sequencer.ts +440 -134
- package/src/sequencer/timetable.ts +56 -51
- package/src/sequencer/types.ts +1 -1
- package/src/test/mock_checkpoint_builder.ts +51 -48
- package/src/test/utils.ts +28 -10
|
@@ -370,44 +370,52 @@ 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',
|
|
400
411
|
'propose',
|
|
401
412
|
'governance-signal',
|
|
402
|
-
'empire-slashing-signal',
|
|
403
|
-
'create-empire-payload',
|
|
404
|
-
'execute-empire-payload',
|
|
405
413
|
'vote-offenses',
|
|
406
414
|
'execute-slash'
|
|
407
415
|
];
|
|
408
416
|
// Sorting for actions such that invalidations go before proposals, and proposals go before votes
|
|
409
417
|
export const compareActions = (a, b)=>Actions.indexOf(a) - Actions.indexOf(b);
|
|
410
|
-
_dec = trackSpan('SequencerPublisher.sendRequests'), _dec1 = trackSpan('SequencerPublisher.validateBlockHeader')
|
|
418
|
+
_dec = trackSpan('SequencerPublisher.sendRequests'), _dec1 = trackSpan('SequencerPublisher.validateBlockHeader');
|
|
411
419
|
export class SequencerPublisher {
|
|
412
420
|
config;
|
|
413
421
|
static{
|
|
@@ -421,55 +429,55 @@ export class SequencerPublisher {
|
|
|
421
429
|
_dec1,
|
|
422
430
|
2,
|
|
423
431
|
"validateBlockHeader"
|
|
424
|
-
],
|
|
425
|
-
[
|
|
426
|
-
_dec2,
|
|
427
|
-
2,
|
|
428
|
-
"validateCheckpointForSubmission"
|
|
429
432
|
]
|
|
430
433
|
], []));
|
|
431
434
|
}
|
|
432
435
|
interrupted;
|
|
433
436
|
metrics;
|
|
437
|
+
bundleSimulator;
|
|
434
438
|
epochCache;
|
|
435
439
|
failedTxStore;
|
|
436
|
-
|
|
437
|
-
|
|
440
|
+
/**
|
|
441
|
+
* ABI used to decode raw revert payloads from dropped bundle entries when the original
|
|
442
|
+
* request did not carry an abi (e.g. the propose request). Merges every contract the
|
|
443
|
+
* publisher can route to so any of their custom errors decode against it.
|
|
444
|
+
*/ revertDecoderAbi;
|
|
438
445
|
lastActions;
|
|
439
|
-
isPayloadEmptyCache;
|
|
440
|
-
payloadProposedCache;
|
|
441
446
|
log;
|
|
442
447
|
ethereumSlotDuration;
|
|
448
|
+
aztecSlotDuration;
|
|
449
|
+
/** Date provider for wall-clock time. */ dateProvider;
|
|
443
450
|
blobClient;
|
|
444
|
-
/** Address to use for simulations in fisherman mode (actual proposer's address) */ proposerAddressForSimulation;
|
|
445
451
|
/** Optional callback to obtain a replacement publisher when the current one fails to send. */ getNextPublisher;
|
|
446
452
|
/** L1 fee analyzer for fisherman mode */ l1FeeAnalyzer;
|
|
447
453
|
/** 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;
|
|
454
|
+
/** Interruptible sleep used by sendRequestsAt to wait until a target timestamp. */ interruptibleSleep;
|
|
452
455
|
l1TxUtils;
|
|
453
456
|
rollupContract;
|
|
454
457
|
govProposerContract;
|
|
455
458
|
slashingProposerContract;
|
|
456
|
-
slashFactoryContract;
|
|
457
459
|
tracer;
|
|
458
460
|
requests;
|
|
459
461
|
constructor(config, deps){
|
|
460
462
|
this.config = config;
|
|
461
463
|
this.interrupted = (_initProto(this), false);
|
|
462
|
-
this.
|
|
463
|
-
|
|
464
|
+
this.revertDecoderAbi = mergeAbis([
|
|
465
|
+
RollupAbi,
|
|
466
|
+
SlashingProposerAbi,
|
|
467
|
+
EmpireBaseAbi,
|
|
468
|
+
ErrorsAbi
|
|
469
|
+
]);
|
|
464
470
|
this.lastActions = {};
|
|
465
|
-
this.
|
|
466
|
-
this.payloadProposedCache = new Set();
|
|
471
|
+
this.interruptibleSleep = new InterruptibleSleep();
|
|
467
472
|
this.requests = [];
|
|
468
473
|
this.log = deps.log ?? createLogger('sequencer:publisher');
|
|
469
474
|
this.ethereumSlotDuration = BigInt(config.ethereumSlotDuration);
|
|
475
|
+
this.aztecSlotDuration = BigInt(config.aztecSlotDuration);
|
|
476
|
+
this.dateProvider = deps.dateProvider;
|
|
470
477
|
this.epochCache = deps.epochCache;
|
|
471
478
|
this.lastActions = deps.lastActions;
|
|
472
479
|
this.blobClient = deps.blobClient;
|
|
480
|
+
this.dateProvider = deps.dateProvider;
|
|
473
481
|
const telemetry = deps.telemetry ?? getTelemetryClient();
|
|
474
482
|
this.metrics = deps.metrics ?? new SequencerPublisherMetrics(telemetry, 'SequencerPublisher');
|
|
475
483
|
this.tracer = telemetry.getTracer('SequencerPublisher');
|
|
@@ -483,15 +491,20 @@ export class SequencerPublisher {
|
|
|
483
491
|
const newSlashingProposer = await this.rollupContract.getSlashingProposer();
|
|
484
492
|
this.slashingProposerContract = newSlashingProposer;
|
|
485
493
|
});
|
|
486
|
-
this.slashFactoryContract = deps.slashFactoryContract;
|
|
487
494
|
// Initialize L1 fee analyzer for fisherman mode
|
|
488
495
|
if (config.fishermanMode) {
|
|
489
|
-
this.l1FeeAnalyzer = new L1FeeAnalyzer(this.l1TxUtils.client, deps.dateProvider,
|
|
496
|
+
this.l1FeeAnalyzer = new L1FeeAnalyzer(this.l1TxUtils.client, deps.dateProvider, this.log.createChild('fee-analyzer'));
|
|
490
497
|
}
|
|
491
498
|
// Initialize fee asset price oracle
|
|
492
|
-
this.feeAssetPriceOracle = new FeeAssetPriceOracle(this.l1TxUtils.client, this.rollupContract,
|
|
499
|
+
this.feeAssetPriceOracle = new FeeAssetPriceOracle(this.l1TxUtils.client, this.rollupContract, this.log.createChild('price-oracle'));
|
|
493
500
|
// Initialize failed L1 tx store (optional, for test networks)
|
|
494
501
|
this.failedTxStore = createL1TxFailedStore(config.l1TxFailedStore, this.log);
|
|
502
|
+
this.bundleSimulator = new SequencerBundleSimulator({
|
|
503
|
+
getL1TxUtils: ()=>this.l1TxUtils,
|
|
504
|
+
rollupContract: this.rollupContract,
|
|
505
|
+
epochCache: this.epochCache,
|
|
506
|
+
log: this.log.createChild('bundle-simulator')
|
|
507
|
+
});
|
|
495
508
|
}
|
|
496
509
|
/**
|
|
497
510
|
* Backs up a failed L1 transaction to the configured store for debugging.
|
|
@@ -514,9 +527,13 @@ export class SequencerPublisher {
|
|
|
514
527
|
}
|
|
515
528
|
/**
|
|
516
529
|
* Gets the fee asset price modifier from the oracle.
|
|
517
|
-
*
|
|
518
|
-
|
|
519
|
-
|
|
530
|
+
*
|
|
531
|
+
* @param predictedParentEthPerFeeAssetE12 - Optional predicted parent eth-per-fee-asset (E12).
|
|
532
|
+
* Pipelined proposers should pass the value from the predicted parent fee header so the
|
|
533
|
+
* modifier matches the parent L1 will use when applying it.
|
|
534
|
+
* @returns The fee asset price modifier in basis points, or 0n if the oracle query fails.
|
|
535
|
+
*/ getFeeAssetPriceModifier(predictedParentEthPerFeeAssetE12) {
|
|
536
|
+
return this.feeAssetPriceOracle.computePriceModifier(predictedParentEthPerFeeAssetE12);
|
|
520
537
|
}
|
|
521
538
|
getSenderAddress() {
|
|
522
539
|
return this.l1TxUtils.getSenderAddress();
|
|
@@ -526,17 +543,11 @@ export class SequencerPublisher {
|
|
|
526
543
|
*/ getL1FeeAnalyzer() {
|
|
527
544
|
return this.l1FeeAnalyzer;
|
|
528
545
|
}
|
|
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
546
|
addRequest(request) {
|
|
536
547
|
this.requests.push(request);
|
|
537
548
|
}
|
|
538
549
|
getCurrentL2Slot() {
|
|
539
|
-
return this.epochCache.
|
|
550
|
+
return this.epochCache.getSlotNow();
|
|
540
551
|
}
|
|
541
552
|
/**
|
|
542
553
|
* Clears all pending requests without sending them.
|
|
@@ -589,11 +600,15 @@ export class SequencerPublisher {
|
|
|
589
600
|
}
|
|
590
601
|
/**
|
|
591
602
|
* Sends all requests that are still valid.
|
|
603
|
+
* @param targetSlot - The target L2 slot for this send. When provided (the production path, via
|
|
604
|
+
* sendRequestsAt), it is threaded into bundleSimulate so the block.timestamp override matches
|
|
605
|
+
* the slot the propose is built for. When omitted, falls back to getCurrentL2Slot() for the
|
|
606
|
+
* AutomineSequencer, which publishes synchronously within the current slot.
|
|
592
607
|
* @returns one of:
|
|
593
608
|
* - A receipt and stats if the tx succeeded
|
|
594
609
|
* - a receipt and errorMsg if it failed on L1
|
|
595
610
|
* - undefined if no valid requests are found OR the tx failed to send.
|
|
596
|
-
*/ async sendRequests() {
|
|
611
|
+
*/ async sendRequests(targetSlot) {
|
|
597
612
|
const requestsToProcess = [
|
|
598
613
|
...this.requests
|
|
599
614
|
];
|
|
@@ -601,10 +616,9 @@ export class SequencerPublisher {
|
|
|
601
616
|
if (this.interrupted || requestsToProcess.length === 0) {
|
|
602
617
|
return undefined;
|
|
603
618
|
}
|
|
604
|
-
const currentL2Slot = this.getCurrentL2Slot();
|
|
619
|
+
const currentL2Slot = targetSlot ?? this.getCurrentL2Slot();
|
|
605
620
|
this.log.debug(`Sending requests on L2 slot ${currentL2Slot}`);
|
|
606
621
|
const validRequests = requestsToProcess.filter((request)=>request.lastValidL2Slot >= currentL2Slot);
|
|
607
|
-
const validActions = validRequests.map((x)=>x.action);
|
|
608
622
|
const expiredActions = requestsToProcess.filter((request)=>request.lastValidL2Slot < currentL2Slot).map((x)=>x.action);
|
|
609
623
|
if (validRequests.length !== requestsToProcess.length) {
|
|
610
624
|
this.log.warn(`Some requests were expired for slot ${currentL2Slot}`, {
|
|
@@ -622,71 +636,53 @@ export class SequencerPublisher {
|
|
|
622
636
|
this.log.debug(`No valid requests to send`);
|
|
623
637
|
return undefined;
|
|
624
638
|
}
|
|
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
|
-
}
|
|
639
|
+
// Collect earliest txTimeoutAt across all requests.
|
|
640
|
+
const gasConfigs = validRequests.filter((request)=>request.gasConfig).map((request)=>request.gasConfig);
|
|
646
641
|
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
|
-
};
|
|
642
|
+
const txTimeoutAt = txTimeoutAts.length > 0 ? new Date(Math.min(...txTimeoutAts.map((g)=>g.getTime()))) : undefined;
|
|
652
643
|
// Sort the requests so that proposals always go first
|
|
653
644
|
// This ensures the committee gets precomputed correctly
|
|
654
645
|
validRequests.sort((a, b)=>compareActions(a.action, b.action));
|
|
655
646
|
try {
|
|
656
|
-
//
|
|
657
|
-
const
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
647
|
+
// Bundle-level eth_simulateV1: filters out entries that revert and derives the gasLimit.
|
|
648
|
+
const bundleResult = await this.bundleSimulator.simulate(validRequests, currentL2Slot);
|
|
649
|
+
if (bundleResult.kind === 'aborted') {
|
|
650
|
+
this.logDroppedInSim(bundleResult.droppedRequests);
|
|
651
|
+
void this.backupDroppedInSim(bundleResult.droppedRequests);
|
|
652
|
+
return undefined;
|
|
653
|
+
}
|
|
654
|
+
const { requests, droppedRequests, gasLimit } = bundleResult.kind === 'fallback' ? {
|
|
655
|
+
requests: bundleResult.requests,
|
|
656
|
+
droppedRequests: bundleResult.droppedRequests,
|
|
657
|
+
gasLimit: MAX_L1_TX_LIMIT
|
|
658
|
+
} : bundleResult;
|
|
659
|
+
this.logDroppedInSim(droppedRequests);
|
|
660
|
+
// Compute blobConfig from survivors (not original validRequests) so that if the propose
|
|
661
|
+
// entry was dropped by bundleSimulate we don't attach a blob-typed config to a non-blob tx.
|
|
662
|
+
const [blobConfig] = requests.filter((r)=>r.blobConfig).map((r)=>r.blobConfig);
|
|
663
|
+
const txConfig = {
|
|
664
|
+
gasLimit,
|
|
665
|
+
txTimeoutAt
|
|
674
666
|
};
|
|
675
667
|
this.log.debug('Forwarding transactions', {
|
|
676
|
-
|
|
668
|
+
requests: requests.map((request)=>request.action),
|
|
677
669
|
txConfig
|
|
678
670
|
});
|
|
679
|
-
const result = await this.forwardWithPublisherRotation(
|
|
671
|
+
const result = await this.forwardWithPublisherRotation(requests, txConfig, blobConfig);
|
|
680
672
|
if (result === undefined) {
|
|
681
673
|
return undefined;
|
|
682
674
|
}
|
|
683
|
-
const { successfulActions = [], failedActions = [] } = this.callbackBundledTransactions(
|
|
675
|
+
const { successfulActions = [], failedActions = [] } = this.callbackBundledTransactions(requests, result);
|
|
676
|
+
const allFailedActions = [
|
|
677
|
+
...failedActions,
|
|
678
|
+
...droppedRequests.map((d)=>d.request.action)
|
|
679
|
+
];
|
|
684
680
|
return {
|
|
685
681
|
result,
|
|
686
682
|
expiredActions,
|
|
687
|
-
sentActions:
|
|
683
|
+
sentActions: requests.map((x)=>x.action),
|
|
688
684
|
successfulActions,
|
|
689
|
-
failedActions
|
|
685
|
+
failedActions: allFailedActions
|
|
690
686
|
};
|
|
691
687
|
} catch (err) {
|
|
692
688
|
const viemError = formatViemError(err);
|
|
@@ -700,23 +696,78 @@ export class SequencerPublisher {
|
|
|
700
696
|
}
|
|
701
697
|
}
|
|
702
698
|
}
|
|
699
|
+
/** Logs entries dropped by bundle simulation as warnings on the publisher's logger. */ logDroppedInSim(dropped) {
|
|
700
|
+
for (const drop of dropped){
|
|
701
|
+
const revertReasonDecoded = drop.revertReason ?? tryDecodeRevertReason(drop.returnData, this.revertDecoderAbi);
|
|
702
|
+
this.log.warn('Bundle entry dropped: action reverted in sim', {
|
|
703
|
+
action: drop.request.action,
|
|
704
|
+
revertReason: revertReasonDecoded ?? drop.returnData,
|
|
705
|
+
revertReasonDecoded,
|
|
706
|
+
returnData: drop.returnData
|
|
707
|
+
});
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
/** Backs up entries dropped by bundle simulation, one record per dropped action. */ async backupDroppedInSim(dropped) {
|
|
711
|
+
if (dropped.length === 0) {
|
|
712
|
+
return;
|
|
713
|
+
}
|
|
714
|
+
const l1BlockNumber = await this.l1TxUtils.getBlockNumber();
|
|
715
|
+
for (const { request: req } of dropped){
|
|
716
|
+
this.backupFailedTx({
|
|
717
|
+
id: keccak256(req.request.data),
|
|
718
|
+
failureType: 'simulation',
|
|
719
|
+
request: {
|
|
720
|
+
to: req.request.to,
|
|
721
|
+
data: req.request.data
|
|
722
|
+
},
|
|
723
|
+
l1BlockNumber: l1BlockNumber.toString(),
|
|
724
|
+
error: {
|
|
725
|
+
message: 'Bundle entry dropped: action reverted in sim'
|
|
726
|
+
},
|
|
727
|
+
context: {
|
|
728
|
+
actions: [
|
|
729
|
+
req.action
|
|
730
|
+
],
|
|
731
|
+
sender: this.getSenderAddress().toString()
|
|
732
|
+
}
|
|
733
|
+
});
|
|
734
|
+
}
|
|
735
|
+
}
|
|
703
736
|
/**
|
|
704
737
|
* Forwards transactions via Multicall3, rotating to the next available publisher if a send
|
|
705
738
|
* failure occurs (i.e. the tx never reached the chain).
|
|
706
739
|
* On-chain reverts and simulation errors are returned as-is without rotation.
|
|
707
740
|
*/ async forwardWithPublisherRotation(validRequests, txConfig, blobConfig) {
|
|
741
|
+
if (!txConfig?.gasLimit) {
|
|
742
|
+
throw new Error('gasLimit is required for bundled transactions');
|
|
743
|
+
}
|
|
744
|
+
const txConfigWithGasLimit = txConfig;
|
|
708
745
|
const triedAddresses = [];
|
|
709
746
|
let currentPublisher = this.l1TxUtils;
|
|
710
747
|
while(true){
|
|
748
|
+
if (txConfig.txTimeoutAt && new Date() > txConfig.txTimeoutAt) {
|
|
749
|
+
this.log.warn(`Tx timeout (${txConfig.txTimeoutAt.toISOString()}) elapsed; stopping publisher rotation`, {
|
|
750
|
+
triedAddresses: triedAddresses.map((a)=>a.toString())
|
|
751
|
+
});
|
|
752
|
+
return undefined;
|
|
753
|
+
}
|
|
711
754
|
triedAddresses.push(currentPublisher.getSenderAddress());
|
|
712
755
|
try {
|
|
713
|
-
const result = await Multicall3.forward(validRequests.map((r)=>r.request), currentPublisher,
|
|
756
|
+
const result = await Multicall3.forward(validRequests.map((r)=>r.request), currentPublisher, txConfigWithGasLimit, blobConfig, {
|
|
757
|
+
gasLimitRequired: true
|
|
758
|
+
});
|
|
714
759
|
this.l1TxUtils = currentPublisher;
|
|
715
760
|
return result;
|
|
716
761
|
} catch (err) {
|
|
717
762
|
if (err instanceof TimeoutError) {
|
|
718
763
|
throw err;
|
|
719
764
|
}
|
|
765
|
+
if (err instanceof MulticallForwarderRevertedError) {
|
|
766
|
+
this.log.error('Forwarder transaction reverted on-chain; not rotating publisher', err, {
|
|
767
|
+
transactionHash: err.receipt.transactionHash
|
|
768
|
+
});
|
|
769
|
+
return undefined;
|
|
770
|
+
}
|
|
720
771
|
const viemError = formatViemError(err);
|
|
721
772
|
if (!this.getNextPublisher) {
|
|
722
773
|
this.log.error('Failed to publish bundled transactions', viemError);
|
|
@@ -727,110 +778,94 @@ export class SequencerPublisher {
|
|
|
727
778
|
...triedAddresses
|
|
728
779
|
]);
|
|
729
780
|
if (!nextPublisher) {
|
|
730
|
-
this.log.error(
|
|
781
|
+
this.log.error(`All available publishers exhausted (tried ${triedAddresses.length}), failed to publish bundled transactions`, viemError, {
|
|
782
|
+
triedAddresses: triedAddresses.map((a)=>a.toString())
|
|
783
|
+
});
|
|
731
784
|
return undefined;
|
|
732
785
|
}
|
|
733
786
|
currentPublisher = nextPublisher;
|
|
734
787
|
}
|
|
735
788
|
}
|
|
736
789
|
}
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
data: r.request.data
|
|
760
|
-
})),
|
|
761
|
-
sender: this.getSenderAddress().toString()
|
|
762
|
-
}
|
|
763
|
-
});
|
|
764
|
-
return {
|
|
765
|
-
failedActions: requests.map((r)=>r.action)
|
|
766
|
-
};
|
|
767
|
-
} else {
|
|
768
|
-
this.log.verbose(`Published bundled transactions (${actionsListStr})`, {
|
|
769
|
-
result,
|
|
770
|
-
requests
|
|
790
|
+
/*
|
|
791
|
+
* Schedules sending all enqueued requests at (or after) the start of the given L2 slot.
|
|
792
|
+
* Sleeps until one L1 slot before the L2 slot boundary so the tx has a chance of being
|
|
793
|
+
* picked up by the first L1 block of the L2 slot.
|
|
794
|
+
* NB: there is a known correctness risk — being included in the L1 block right before the
|
|
795
|
+
* L2 slot starts would revert propose with HeaderLib__InvalidSlotNumber.
|
|
796
|
+
* Uses InterruptibleSleep so it can be cancelled via interrupt().
|
|
797
|
+
*/ async sendRequestsAt(targetSlot) {
|
|
798
|
+
const l1Constants = this.epochCache.getL1Constants();
|
|
799
|
+
// Start of the target L2 slot, in ms (getTimestampForSlot returns seconds).
|
|
800
|
+
const startOfTargetSlotMs = Number(getTimestampForSlot(targetSlot, l1Constants)) * 1000;
|
|
801
|
+
// Aim to be in the mempool one L1 slot before the L2 slot starts, so we have a chance of
|
|
802
|
+
// being picked up by the first L1 block of the L2 slot.
|
|
803
|
+
const submitAfterMs = startOfTargetSlotMs - Number(this.ethereumSlotDuration) * 1000;
|
|
804
|
+
if (this.interrupted) {
|
|
805
|
+
return undefined;
|
|
806
|
+
}
|
|
807
|
+
const sleepMs = submitAfterMs - this.dateProvider.now();
|
|
808
|
+
if (sleepMs > 0) {
|
|
809
|
+
this.log.debug(`Sleeping ${sleepMs}ms before sending requests`, {
|
|
810
|
+
targetSlot,
|
|
811
|
+
submitAfterMs
|
|
771
812
|
});
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
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
|
-
}
|
|
810
|
-
});
|
|
813
|
+
await this.interruptibleSleep.sleep(sleepMs);
|
|
814
|
+
}
|
|
815
|
+
if (this.interrupted) {
|
|
816
|
+
return undefined;
|
|
817
|
+
}
|
|
818
|
+
return this.sendRequests(targetSlot);
|
|
819
|
+
}
|
|
820
|
+
callbackBundledTransactions(requests, result) {
|
|
821
|
+
const actionsListStr = requests.map((r)=>r.action).join(', ');
|
|
822
|
+
this.log.verbose(`Published bundled transactions (${actionsListStr})`, {
|
|
823
|
+
result,
|
|
824
|
+
requests: requests.map((r)=>({
|
|
825
|
+
...r,
|
|
826
|
+
// Avoid logging large blob data
|
|
827
|
+
blobConfig: r.blobConfig ? {
|
|
828
|
+
...r.blobConfig,
|
|
829
|
+
blobs: r.blobConfig.blobs.map((b)=>({
|
|
830
|
+
size: trimmedBytesLength(b)
|
|
831
|
+
}))
|
|
832
|
+
} : undefined
|
|
833
|
+
}))
|
|
834
|
+
});
|
|
835
|
+
const successfulActions = [];
|
|
836
|
+
const failedActions = [];
|
|
837
|
+
for (const request of requests){
|
|
838
|
+
if (request.checkSuccess(request.request, result)) {
|
|
839
|
+
successfulActions.push(request.action);
|
|
840
|
+
} else {
|
|
841
|
+
failedActions.push(request.action);
|
|
811
842
|
}
|
|
812
|
-
return {
|
|
813
|
-
successfulActions,
|
|
814
|
-
failedActions
|
|
815
|
-
};
|
|
816
843
|
}
|
|
844
|
+
return {
|
|
845
|
+
successfulActions,
|
|
846
|
+
failedActions
|
|
847
|
+
};
|
|
817
848
|
}
|
|
818
849
|
/**
|
|
819
|
-
* @notice Will call `
|
|
850
|
+
* @notice Will call `canProposeAt` to make sure that it is possible to propose
|
|
820
851
|
* @param tipArchive - The archive to check
|
|
821
852
|
* @returns The slot and block number if it is possible to propose, undefined otherwise
|
|
822
|
-
*/
|
|
853
|
+
*/ async canProposeAt(tipArchive, msgSender, simulationOverridesPlan) {
|
|
823
854
|
// TODO: #14291 - should loop through multiple keys to check if any of them can propose
|
|
824
|
-
|
|
855
|
+
// These errors are expected when we cannot actually propose right now — usually because our
|
|
856
|
+
// local view of the chain is ahead of L1 (proposed parent hasn't landed yet, or someone
|
|
857
|
+
// else has just landed the slot, or the archive override doesn't match). We log a warn and
|
|
858
|
+
// skip the proposal; we do NOT treat these as bugs.
|
|
859
|
+
const expectedErrors = [
|
|
825
860
|
'SlotAlreadyInChain',
|
|
826
861
|
'InvalidProposer',
|
|
827
862
|
'InvalidArchive'
|
|
828
863
|
];
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
if (err instanceof FormattedViemError &&
|
|
833
|
-
this.log.warn(`Failed canProposeAtTime check with ${
|
|
864
|
+
const slotOffset = this.aztecSlotDuration;
|
|
865
|
+
const nextL1SlotTs = this.getNextL1SlotTimestamp() + slotOffset;
|
|
866
|
+
return this.rollupContract.canProposeAt(tipArchive.toBuffer(), msgSender.toString(), nextL1SlotTs, await buildSimulationOverridesStateOverride(this.rollupContract, simulationOverridesPlan)).catch((err)=>{
|
|
867
|
+
if (err instanceof FormattedViemError && expectedErrors.find((e)=>err.message.includes(e))) {
|
|
868
|
+
this.log.warn(`Failed canProposeAtTime check with ${expectedErrors.find((e)=>err.message.includes(e))}`, {
|
|
834
869
|
error: err.message
|
|
835
870
|
});
|
|
836
871
|
} else {
|
|
@@ -844,22 +879,23 @@ export class SequencerPublisher {
|
|
|
844
879
|
* @dev This is a convenience function that can be used by the sequencer to validate a "partial" header.
|
|
845
880
|
* It will throw if the block header is invalid.
|
|
846
881
|
* @param header - The block header to validate
|
|
847
|
-
*/ async validateBlockHeader(header,
|
|
882
|
+
*/ async validateBlockHeader(header, simulationOverridesPlan) {
|
|
848
883
|
const flags = {
|
|
849
884
|
ignoreDA: true,
|
|
850
885
|
ignoreSignatures: true
|
|
851
886
|
};
|
|
852
887
|
const args = [
|
|
853
888
|
header.toViem(),
|
|
854
|
-
CommitteeAttestationsAndSigners.
|
|
889
|
+
CommitteeAttestationsAndSigners.packAttestations([]),
|
|
855
890
|
[],
|
|
856
891
|
Signature.empty().toViemSignature(),
|
|
857
892
|
`0x${'0'.repeat(64)}`,
|
|
858
893
|
header.blobsHash.toString(),
|
|
859
894
|
flags
|
|
860
895
|
];
|
|
861
|
-
const
|
|
862
|
-
const
|
|
896
|
+
const l1Constants = this.epochCache.getL1Constants();
|
|
897
|
+
const ts = getLastL1SlotTimestampForL2Slot(header.slotNumber, l1Constants);
|
|
898
|
+
const stateOverrides = await buildSimulationOverridesStateOverride(this.rollupContract, simulationOverridesPlan);
|
|
863
899
|
let balance = 0n;
|
|
864
900
|
if (this.config.fishermanMode) {
|
|
865
901
|
// In fisherman mode, we can't know where the proposer is publishing from
|
|
@@ -881,7 +917,7 @@ export class SequencerPublisher {
|
|
|
881
917
|
}),
|
|
882
918
|
from: MULTI_CALL_3_ADDRESS
|
|
883
919
|
}, {
|
|
884
|
-
time: ts
|
|
920
|
+
time: ts
|
|
885
921
|
}, stateOverrides);
|
|
886
922
|
this.log.debug(`Simulated validateHeader`);
|
|
887
923
|
}
|
|
@@ -927,6 +963,7 @@ export class SequencerPublisher {
|
|
|
927
963
|
gasUsed,
|
|
928
964
|
checkpointNumber,
|
|
929
965
|
forcePendingCheckpointNumber: CheckpointNumber(checkpointNumber - 1),
|
|
966
|
+
lastArchive: validationResult.checkpoint.lastArchive,
|
|
930
967
|
reason
|
|
931
968
|
};
|
|
932
969
|
} catch (err) {
|
|
@@ -939,8 +976,8 @@ export class SequencerPublisher {
|
|
|
939
976
|
request,
|
|
940
977
|
error: viemError.message
|
|
941
978
|
});
|
|
942
|
-
const
|
|
943
|
-
if (
|
|
979
|
+
const latestProposedCheckpointNumber = await this.rollupContract.getCheckpointNumber();
|
|
980
|
+
if (latestProposedCheckpointNumber < checkpointNumber) {
|
|
944
981
|
this.log.verbose(`Checkpoint ${checkpointNumber} has already been invalidated`, {
|
|
945
982
|
...logData
|
|
946
983
|
});
|
|
@@ -990,7 +1027,7 @@ export class SequencerPublisher {
|
|
|
990
1027
|
reason
|
|
991
1028
|
};
|
|
992
1029
|
this.log.debug(`Building invalidate checkpoint ${checkpoint.checkpointNumber} request`, logData);
|
|
993
|
-
const attestationsAndSigners =
|
|
1030
|
+
const attestationsAndSigners = CommitteeAttestationsAndSigners.packAttestations(validationResult.attestations);
|
|
994
1031
|
if (reason === 'invalid-attestation') {
|
|
995
1032
|
return this.rollupContract.buildInvalidateBadAttestationRequest(checkpoint.checkpointNumber, attestationsAndSigners, committee, validationResult.invalidIndex);
|
|
996
1033
|
} else if (reason === 'insufficient-attestations') {
|
|
@@ -1000,28 +1037,7 @@ export class SequencerPublisher {
|
|
|
1000
1037
|
throw new Error(`Unknown reason for invalidation`);
|
|
1001
1038
|
}
|
|
1002
1039
|
}
|
|
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) {
|
|
1040
|
+
async enqueueCastSignalHelper(slotNumber, signalType, payload, base, signerAddress, signer) {
|
|
1025
1041
|
if (this.lastActions[signalType] && this.lastActions[signalType] === slotNumber) {
|
|
1026
1042
|
this.log.debug(`Skipping duplicate vote cast signal ${signalType} for slot ${slotNumber}`);
|
|
1027
1043
|
return false;
|
|
@@ -1041,30 +1057,26 @@ export class SequencerPublisher {
|
|
|
1041
1057
|
if (roundInfo.lastSignalSlot >= slotNumber) {
|
|
1042
1058
|
return false;
|
|
1043
1059
|
}
|
|
1044
|
-
if (await
|
|
1060
|
+
if (await base.isPayloadEmpty(payload)) {
|
|
1045
1061
|
this.log.warn(`Skipping vote cast for payload with empty code`);
|
|
1046
1062
|
return false;
|
|
1047
1063
|
}
|
|
1048
|
-
//
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
} catch (err) {
|
|
1062
|
-
this.log.warn(`Failed to check if payload ${payload} was proposed after retries, skipping signal`, err);
|
|
1063
|
-
return false;
|
|
1064
|
-
}
|
|
1064
|
+
// Skip signaling if there is already a live (non-terminal) Governance proposal for this
|
|
1065
|
+
// payload. This is intentionally not cached: a previously-live proposal may transition to
|
|
1066
|
+
// a terminal state (Dropped/Rejected/Expired/Executed), at which point we may want to re-signal
|
|
1067
|
+
// the same payload in a future round.
|
|
1068
|
+
let proposed = false;
|
|
1069
|
+
try {
|
|
1070
|
+
proposed = await base.hasActiveProposalWithPayload(payload.toString());
|
|
1071
|
+
} catch (err) {
|
|
1072
|
+
// We deliberately swallow the error and proceed to signal. Failing closed (skipping the
|
|
1073
|
+
// signal) on transient RPC errors would let a flaky L1 endpoint silence governance
|
|
1074
|
+
// participation entirely; failing open at worst produces a duplicate signal that the
|
|
1075
|
+
// contract will simply count alongside others in the round.
|
|
1076
|
+
this.log.error(`Failed to check if payload ${payload} was already proposed (signalling anyway)`, err);
|
|
1065
1077
|
}
|
|
1066
|
-
if (
|
|
1067
|
-
this.log.info(`Payload ${payload}
|
|
1078
|
+
if (proposed) {
|
|
1079
|
+
this.log.info(`Payload ${payload} has a live governance proposal, stopping signals`);
|
|
1068
1080
|
return false;
|
|
1069
1081
|
}
|
|
1070
1082
|
const cachedLastVote = this.lastActions[signalType];
|
|
@@ -1077,53 +1089,17 @@ export class SequencerPublisher {
|
|
|
1077
1089
|
signer: this.l1TxUtils.client.account?.address,
|
|
1078
1090
|
lastValidL2Slot: slotNumber
|
|
1079
1091
|
});
|
|
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
1092
|
// TODO(palla/slash): All votes (governance and slashing) should txTimeoutAt at the end of the slot.
|
|
1118
1093
|
this.addRequest({
|
|
1119
|
-
gasConfig: {
|
|
1120
|
-
gasLimit: SequencerPublisher.VOTE_GAS_GUESS
|
|
1121
|
-
},
|
|
1122
1094
|
action,
|
|
1123
1095
|
request,
|
|
1124
1096
|
lastValidL2Slot: slotNumber,
|
|
1125
1097
|
checkSuccess: (_request, result)=>{
|
|
1126
|
-
const success = result &&
|
|
1098
|
+
const success = result && extractEventSuccess(result.receipt, {
|
|
1099
|
+
address: base.address.toString(),
|
|
1100
|
+
abi: EmpireBaseAbi,
|
|
1101
|
+
eventName: 'SignalCast'
|
|
1102
|
+
});
|
|
1127
1103
|
const logData = {
|
|
1128
1104
|
...result,
|
|
1129
1105
|
slotNumber,
|
|
@@ -1142,68 +1118,20 @@ export class SequencerPublisher {
|
|
|
1142
1118
|
});
|
|
1143
1119
|
return true;
|
|
1144
1120
|
}
|
|
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
1121
|
/**
|
|
1156
1122
|
* Enqueues a governance castSignal transaction to cast a signal for a given slot number.
|
|
1157
1123
|
* @param slotNumber - The slot number to cast a signal for.
|
|
1158
|
-
* @param timestamp - The timestamp of the slot to cast a signal for.
|
|
1159
1124
|
* @returns True if the signal was successfully enqueued, false otherwise.
|
|
1160
|
-
*/ enqueueGovernanceCastSignal(governancePayload, slotNumber,
|
|
1161
|
-
return this.enqueueCastSignalHelper(slotNumber,
|
|
1125
|
+
*/ enqueueGovernanceCastSignal(governancePayload, slotNumber, signerAddress, signer) {
|
|
1126
|
+
return this.enqueueCastSignalHelper(slotNumber, 'governance-signal', governancePayload, this.govProposerContract, signerAddress, signer);
|
|
1162
1127
|
}
|
|
1163
|
-
/** Enqueues all slashing actions as returned by the slasher client. */ async enqueueSlashingActions(actions, slotNumber,
|
|
1128
|
+
/** Enqueues all slashing actions as returned by the slasher client. */ async enqueueSlashingActions(actions, slotNumber, signerAddress, signer) {
|
|
1164
1129
|
if (actions.length === 0) {
|
|
1165
1130
|
this.log.debug(`No slashing actions to enqueue for slot ${slotNumber}`);
|
|
1166
1131
|
return false;
|
|
1167
1132
|
}
|
|
1168
1133
|
for (const action of actions){
|
|
1169
1134
|
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
1135
|
case 'vote-offenses':
|
|
1208
1136
|
{
|
|
1209
1137
|
this.log.debug(`Enqueuing slashing vote for ${action.votes.length} votes at slot ${slotNumber}`, {
|
|
@@ -1212,14 +1140,17 @@ export class SequencerPublisher {
|
|
|
1212
1140
|
votesCount: action.votes.length,
|
|
1213
1141
|
signerAddress
|
|
1214
1142
|
});
|
|
1215
|
-
if (this.slashingProposerContract
|
|
1216
|
-
this.log.error('
|
|
1143
|
+
if (!this.slashingProposerContract) {
|
|
1144
|
+
this.log.error('No slashing proposer contract available');
|
|
1217
1145
|
return false;
|
|
1218
1146
|
}
|
|
1219
|
-
const tallySlashingProposer = this.slashingProposerContract;
|
|
1220
1147
|
const votes = bufferToHex(encodeSlashConsensusVotes(action.votes));
|
|
1221
|
-
const request = await
|
|
1222
|
-
|
|
1148
|
+
const request = await this.slashingProposerContract.buildVoteRequestFromSigner(votes, slotNumber, signer);
|
|
1149
|
+
this.enqueueRequest('vote-offenses', request, {
|
|
1150
|
+
address: this.slashingProposerContract.address.toString(),
|
|
1151
|
+
abi: SlashingProposerAbi,
|
|
1152
|
+
eventName: 'VoteCast'
|
|
1153
|
+
}, slotNumber);
|
|
1223
1154
|
break;
|
|
1224
1155
|
}
|
|
1225
1156
|
case 'execute-slash':
|
|
@@ -1229,13 +1160,16 @@ export class SequencerPublisher {
|
|
|
1229
1160
|
round: action.round,
|
|
1230
1161
|
signerAddress
|
|
1231
1162
|
});
|
|
1232
|
-
if (this.slashingProposerContract
|
|
1233
|
-
this.log.error('
|
|
1163
|
+
if (!this.slashingProposerContract) {
|
|
1164
|
+
this.log.error('No slashing proposer contract available');
|
|
1234
1165
|
return false;
|
|
1235
1166
|
}
|
|
1236
|
-
const
|
|
1237
|
-
|
|
1238
|
-
|
|
1167
|
+
const executeRequest = this.slashingProposerContract.buildExecuteRoundRequest(action.round, action.committees);
|
|
1168
|
+
this.enqueueRequest('execute-slash', executeRequest, {
|
|
1169
|
+
address: this.slashingProposerContract.address.toString(),
|
|
1170
|
+
abi: SlashingProposerAbi,
|
|
1171
|
+
eventName: 'RoundExecuted'
|
|
1172
|
+
}, slotNumber);
|
|
1239
1173
|
break;
|
|
1240
1174
|
}
|
|
1241
1175
|
default:
|
|
@@ -1247,7 +1181,7 @@ export class SequencerPublisher {
|
|
|
1247
1181
|
}
|
|
1248
1182
|
return true;
|
|
1249
1183
|
}
|
|
1250
|
-
/**
|
|
1184
|
+
/** Enqueues a proposal for a checkpoint on L1 */ async enqueueProposeCheckpoint(checkpoint, attestationsAndSigners, attestationsAndSignersSignature, opts = {}) {
|
|
1251
1185
|
const checkpointHeader = checkpoint.header;
|
|
1252
1186
|
const blobFields = checkpoint.toBlobFields();
|
|
1253
1187
|
const blobs = await getBlobsPerL1Block(blobFields);
|
|
@@ -1259,52 +1193,38 @@ export class SequencerPublisher {
|
|
|
1259
1193
|
attestationsAndSignersSignature,
|
|
1260
1194
|
feeAssetPriceModifier: checkpoint.feeAssetPriceModifier
|
|
1261
1195
|
};
|
|
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
1196
|
this.log.verbose(`Enqueuing checkpoint propose transaction`, {
|
|
1279
1197
|
...checkpoint.toCheckpointInfo(),
|
|
1280
|
-
|
|
1198
|
+
txTimeoutAt: opts.txTimeoutAt
|
|
1199
|
+
});
|
|
1200
|
+
await this.addProposeTx(checkpoint, proposeTxArgs, {
|
|
1201
|
+
txTimeoutAt: opts.txTimeoutAt
|
|
1281
1202
|
});
|
|
1282
|
-
await this.addProposeTx(checkpoint, proposeTxArgs, opts, ts);
|
|
1283
1203
|
}
|
|
1284
1204
|
enqueueInvalidateCheckpoint(request, opts = {}) {
|
|
1285
1205
|
if (!request) {
|
|
1286
1206
|
return;
|
|
1287
1207
|
}
|
|
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
1208
|
const { gasUsed, checkpointNumber } = request;
|
|
1291
1209
|
const logData = {
|
|
1292
1210
|
gasUsed,
|
|
1293
1211
|
checkpointNumber,
|
|
1294
|
-
gasLimit,
|
|
1295
1212
|
opts
|
|
1296
1213
|
};
|
|
1297
1214
|
this.log.verbose(`Enqueuing invalidate checkpoint request`, logData);
|
|
1298
1215
|
this.addRequest({
|
|
1299
1216
|
action: `invalidate-by-${request.reason}`,
|
|
1300
1217
|
request: request.request,
|
|
1301
|
-
gasConfig: {
|
|
1302
|
-
gasLimit,
|
|
1218
|
+
gasConfig: opts.txTimeoutAt ? {
|
|
1303
1219
|
txTimeoutAt: opts.txTimeoutAt
|
|
1304
|
-
},
|
|
1220
|
+
} : undefined,
|
|
1305
1221
|
lastValidL2Slot: SlotNumber(this.getCurrentL2Slot() + 2),
|
|
1306
1222
|
checkSuccess: (_req, result)=>{
|
|
1307
|
-
const success = result &&
|
|
1223
|
+
const success = result && extractEventSuccess(result.receipt, {
|
|
1224
|
+
address: this.rollupContract.address,
|
|
1225
|
+
abi: RollupAbi,
|
|
1226
|
+
eventName: 'CheckpointInvalidated'
|
|
1227
|
+
});
|
|
1308
1228
|
if (!success) {
|
|
1309
1229
|
this.log.warn(`Invalidate checkpoint ${request.checkpointNumber} failed`, {
|
|
1310
1230
|
...result,
|
|
@@ -1320,89 +1240,36 @@ export class SequencerPublisher {
|
|
|
1320
1240
|
}
|
|
1321
1241
|
});
|
|
1322
1242
|
}
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
};
|
|
1243
|
+
/**
|
|
1244
|
+
* Dedup-checked enqueue helper for actions that are simulated at bundle-send time rather
|
|
1245
|
+
* than at enqueue time. Validates the (action, slot) dedup key, sets `lastActions`, and
|
|
1246
|
+
* enqueues without a gasLimit so the bundle simulate sets the only gasLimit that matters.
|
|
1247
|
+
*/ enqueueRequest(action, request, eventOpts, slotNumber) {
|
|
1329
1248
|
if (this.lastActions[action] && this.lastActions[action] === slotNumber) {
|
|
1330
1249
|
this.log.debug(`Skipping duplicate action ${action} for slot ${slotNumber}`);
|
|
1331
1250
|
return false;
|
|
1332
1251
|
}
|
|
1333
1252
|
const cachedLastActionSlot = this.lastActions[action];
|
|
1334
1253
|
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);
|
|
1254
|
+
this.log.debug(`Enqueuing ${action}`, {
|
|
1255
|
+
slotNumber
|
|
1256
|
+
});
|
|
1387
1257
|
this.addRequest({
|
|
1388
1258
|
action,
|
|
1389
|
-
request
|
|
1390
|
-
gasConfig: {
|
|
1391
|
-
gasLimit
|
|
1392
|
-
},
|
|
1259
|
+
request,
|
|
1393
1260
|
lastValidL2Slot: slotNumber,
|
|
1394
|
-
checkSuccess: (
|
|
1395
|
-
const success = result && result.receipt
|
|
1261
|
+
checkSuccess: (_request, result)=>{
|
|
1262
|
+
const success = result && extractEventSuccess(result.receipt, eventOpts);
|
|
1396
1263
|
if (!success) {
|
|
1397
1264
|
this.log.warn(`Action ${action} at ${slotNumber} failed`, {
|
|
1398
1265
|
...result,
|
|
1399
|
-
|
|
1266
|
+
slotNumber
|
|
1400
1267
|
});
|
|
1401
1268
|
this.lastActions[action] = cachedLastActionSlot;
|
|
1402
1269
|
} else {
|
|
1403
1270
|
this.log.info(`Action ${action} at ${slotNumber} succeeded`, {
|
|
1404
1271
|
...result,
|
|
1405
|
-
|
|
1272
|
+
slotNumber
|
|
1406
1273
|
});
|
|
1407
1274
|
}
|
|
1408
1275
|
return !!success;
|
|
@@ -1417,13 +1284,14 @@ export class SequencerPublisher {
|
|
|
1417
1284
|
* A call to `restart` is required before you can continue publishing.
|
|
1418
1285
|
*/ interrupt() {
|
|
1419
1286
|
this.interrupted = true;
|
|
1287
|
+
this.interruptibleSleep.interrupt();
|
|
1420
1288
|
this.l1TxUtils.interrupt();
|
|
1421
1289
|
}
|
|
1422
1290
|
/** Restarts the publisher after calling `interrupt`. */ restart() {
|
|
1423
1291
|
this.interrupted = false;
|
|
1424
1292
|
this.l1TxUtils.restart();
|
|
1425
1293
|
}
|
|
1426
|
-
async prepareProposeTx(encodedData
|
|
1294
|
+
async prepareProposeTx(encodedData) {
|
|
1427
1295
|
const kzg = Blob.getViemKzgInstance();
|
|
1428
1296
|
const blobInput = getPrefixedEthBlobCommitments(encodedData.blobs);
|
|
1429
1297
|
this.log.debug('Validating blob input', {
|
|
@@ -1437,7 +1305,11 @@ export class SequencerPublisher {
|
|
|
1437
1305
|
blobEvaluationGas = BigInt(encodedData.blobs.length) * 21_000n;
|
|
1438
1306
|
this.log.debug(`Using fixed blob evaluation gas estimate in fisherman mode: ${blobEvaluationGas}`);
|
|
1439
1307
|
} else {
|
|
1440
|
-
//
|
|
1308
|
+
// We call validateBlobs via estimateGas with real blob+kzg sidecars as a consistency check
|
|
1309
|
+
// that our locally-built blob commitments match the blob data. The bundle simulate at send
|
|
1310
|
+
// time uses eth_simulateV1, which cannot carry blob inputs, so the rollup's on-chain blob
|
|
1311
|
+
// check is forced off there — making this the only pre-flight detector of a commitment/data
|
|
1312
|
+
// mismatch. The returned gas estimate is stashed on the request for the bundle path to read.
|
|
1441
1313
|
blobEvaluationGas = await this.l1TxUtils.estimateGas(this.getSenderAddress().toString(), {
|
|
1442
1314
|
to: this.rollupContract.address,
|
|
1443
1315
|
data: encodeFunctionData({
|
|
@@ -1500,109 +1372,23 @@ export class SequencerPublisher {
|
|
|
1500
1372
|
encodedData.attestationsAndSignersSignature.toViemSignature(),
|
|
1501
1373
|
blobInput
|
|
1502
1374
|
];
|
|
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
1375
|
const rollupData = encodeFunctionData({
|
|
1518
1376
|
abi: RollupAbi,
|
|
1519
1377
|
functionName: 'propose',
|
|
1520
1378
|
args
|
|
1521
1379
|
});
|
|
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
1380
|
return {
|
|
1595
|
-
|
|
1596
|
-
|
|
1381
|
+
args,
|
|
1382
|
+
blobEvaluationGas,
|
|
1383
|
+
rollupData
|
|
1597
1384
|
};
|
|
1598
1385
|
}
|
|
1599
|
-
async addProposeTx(checkpoint, encodedData, opts = {}
|
|
1386
|
+
async addProposeTx(checkpoint, encodedData, opts = {}) {
|
|
1600
1387
|
const slot = checkpoint.header.slotNumber;
|
|
1601
1388
|
const timer = new Timer();
|
|
1602
1389
|
const kzg = Blob.getViemKzgInstance();
|
|
1603
|
-
const { rollupData,
|
|
1390
|
+
const { rollupData, blobEvaluationGas } = await this.prepareProposeTx(encodedData);
|
|
1604
1391
|
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
1392
|
// Send the blobs to the blob client preemptively. This helps in tests where the sequencer mistakingly thinks that the propose
|
|
1607
1393
|
// 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
1394
|
void Promise.resolve().then(()=>this.blobClient.sendBlobsToFilestore(encodedData.blobs).catch((_err)=>{
|
|
@@ -1616,9 +1402,10 @@ export class SequencerPublisher {
|
|
|
1616
1402
|
},
|
|
1617
1403
|
lastValidL2Slot: checkpoint.header.slotNumber,
|
|
1618
1404
|
gasConfig: {
|
|
1619
|
-
|
|
1620
|
-
gasLimit
|
|
1405
|
+
txTimeoutAt: opts.txTimeoutAt,
|
|
1406
|
+
gasLimit: undefined
|
|
1621
1407
|
},
|
|
1408
|
+
blobEvaluationGas,
|
|
1622
1409
|
blobConfig: {
|
|
1623
1410
|
blobs: encodedData.blobs.map((b)=>b.data),
|
|
1624
1411
|
kzg
|
|
@@ -1628,7 +1415,11 @@ export class SequencerPublisher {
|
|
|
1628
1415
|
return false;
|
|
1629
1416
|
}
|
|
1630
1417
|
const { receipt, stats, errorMsg } = result;
|
|
1631
|
-
const success =
|
|
1418
|
+
const success = extractEventSuccess(receipt, {
|
|
1419
|
+
address: this.rollupContract.address,
|
|
1420
|
+
abi: RollupAbi,
|
|
1421
|
+
eventName: 'CheckpointProposed'
|
|
1422
|
+
});
|
|
1632
1423
|
if (success) {
|
|
1633
1424
|
const endBlock = receipt.blockNumber;
|
|
1634
1425
|
const inclusionBlocks = Number(endBlock - startBlock);
|
|
@@ -1665,4 +1456,8 @@ export class SequencerPublisher {
|
|
|
1665
1456
|
}
|
|
1666
1457
|
});
|
|
1667
1458
|
}
|
|
1459
|
+
/** Returns the timestamp of the next L1 slot boundary after now. */ getNextL1SlotTimestamp() {
|
|
1460
|
+
const l1Constants = this.epochCache.getL1Constants();
|
|
1461
|
+
return getNextL1SlotTimestamp(this.dateProvider.nowInSeconds(), l1Constants);
|
|
1462
|
+
}
|
|
1668
1463
|
}
|