@aztec/sequencer-client 0.0.1-commit.343b43af6 → 0.0.1-commit.350e0a4d
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 +23 -16
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +49 -94
- package/dest/config.d.ts +10 -2
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +61 -25
- package/dest/global_variable_builder/fee_predictor.d.ts +37 -0
- package/dest/global_variable_builder/fee_predictor.d.ts.map +1 -0
- package/dest/global_variable_builder/fee_predictor.js +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 +50 -11
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -1
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.js +68 -1
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts +2 -2
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts.map +1 -1
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.js +4 -2
- package/dest/publisher/l1_tx_failed_store/index.d.ts +2 -2
- package/dest/publisher/l1_tx_failed_store/index.d.ts.map +1 -1
- package/dest/publisher/l1_tx_failed_store/index.js +1 -0
- package/dest/publisher/sequencer-bundle-simulator.d.ts +96 -0
- package/dest/publisher/sequencer-bundle-simulator.d.ts.map +1 -0
- package/dest/publisher/sequencer-bundle-simulator.js +198 -0
- package/dest/publisher/sequencer-publisher-factory.d.ts +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 +103 -67
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +621 -525
- package/dest/publisher/write_json.d.ts +11 -0
- package/dest/publisher/write_json.d.ts.map +1 -0
- package/dest/publisher/write_json.js +57 -0
- package/dest/sequencer/automine/automine_factory.d.ts +56 -0
- package/dest/sequencer/automine/automine_factory.d.ts.map +1 -0
- package/dest/sequencer/automine/automine_factory.js +85 -0
- package/dest/sequencer/automine/automine_sequencer.d.ts +189 -0
- package/dest/sequencer/automine/automine_sequencer.d.ts.map +1 -0
- package/dest/sequencer/automine/automine_sequencer.js +690 -0
- package/dest/sequencer/automine/index.d.ts +3 -0
- package/dest/sequencer/automine/index.d.ts.map +1 -0
- package/dest/sequencer/automine/index.js +2 -0
- package/dest/sequencer/checkpoint_proposal_job.d.ts +75 -17
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_proposal_job.js +795 -239
- 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 +62 -5
- package/dest/sequencer/events.d.ts.map +1 -1
- 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/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 +159 -35
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +585 -188
- 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 +4 -4
- package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
- package/dest/test/utils.d.ts +15 -1
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +25 -7
- package/package.json +30 -29
- package/src/client/sequencer-client.ts +70 -124
- package/src/config.ts +71 -22
- 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 +117 -8
- package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +4 -3
- package/src/publisher/l1_tx_failed_store/index.ts +1 -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 +720 -600
- package/src/publisher/write_json.ts +78 -0
- package/src/sequencer/README.md +162 -450
- package/src/sequencer/automine/README.md +60 -0
- package/src/sequencer/automine/automine_factory.ts +152 -0
- package/src/sequencer/automine/automine_sequencer.ts +796 -0
- package/src/sequencer/automine/index.ts +6 -0
- package/src/sequencer/checkpoint_proposal_job.ts +958 -265
- package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
- package/src/sequencer/checkpoint_voter.ts +1 -12
- package/src/sequencer/events.ts +66 -5
- package/src/sequencer/metrics.ts +57 -24
- package/src/sequencer/requests_tracker.ts +43 -0
- package/src/sequencer/sequencer.ts +690 -209
- package/src/sequencer/types.ts +1 -1
- package/src/test/index.ts +2 -2
- package/src/test/mock_checkpoint_builder.ts +3 -3
- package/src/test/utils.ts +61 -10
- package/dest/sequencer/timetable.d.ts +0 -88
- package/dest/sequencer/timetable.d.ts.map +0 -1
- package/dest/sequencer/timetable.js +0 -222
- package/src/sequencer/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,
|
|
376
|
-
import { L1FeeAnalyzer } from '@aztec/ethereum/l1-fee-analysis';
|
|
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';
|
|
375
|
+
import { FeeAssetPriceOracle, MULTI_CALL_3_ADDRESS, Multicall3, MulticallForwarderRevertedError, buildSimulationOverridesStateOverride } from '@aztec/ethereum/contracts';
|
|
376
|
+
import { L1FeeAnalyzer, captureWindowBlockFees } from '@aztec/ethereum/l1-fee-analysis';
|
|
377
|
+
import { L1TxTimeoutError, MAX_L1_TX_LIMIT, WEI_CONST } from '@aztec/ethereum/l1-tx-utils';
|
|
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.validateBlockHeader')
|
|
419
|
+
_dec = trackSpan('SequencerPublisher.sendRequests'), _dec1 = trackSpan('SequencerPublisher.validateBlockHeader');
|
|
411
420
|
export class SequencerPublisher {
|
|
412
421
|
config;
|
|
413
422
|
static{
|
|
@@ -421,55 +430,59 @@ export class SequencerPublisher {
|
|
|
421
430
|
_dec1,
|
|
422
431
|
2,
|
|
423
432
|
"validateBlockHeader"
|
|
424
|
-
],
|
|
425
|
-
[
|
|
426
|
-
_dec2,
|
|
427
|
-
2,
|
|
428
|
-
"validateCheckpointForSubmission"
|
|
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,40 +496,116 @@ 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
|
-
*
|
|
498
|
-
*
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
}
|
|
515
|
+
* Logs the gas-pricing data of a failed L1 transaction at warn — so underpricing is diagnosable
|
|
516
|
+
* from logs even with no failed-tx store configured — and backs the record up to the store when
|
|
517
|
+
* one is. When captureFeeSummary is true, also records the fee data of the already-mined L1
|
|
518
|
+
* blocks in the target slot's inclusion window.
|
|
519
|
+
*/ backupFailedTx(failedTx, opts) {
|
|
503
520
|
const tx = {
|
|
504
521
|
...failedTx,
|
|
505
522
|
timestamp: Date.now()
|
|
506
523
|
};
|
|
507
524
|
// Fire and forget - don't block on backup
|
|
508
|
-
void
|
|
509
|
-
|
|
510
|
-
|
|
525
|
+
void (async ()=>{
|
|
526
|
+
try {
|
|
527
|
+
// Prefer a pre-captured summary (shared across a batch of failures in the same slot) so we
|
|
528
|
+
// don't re-read the fee window per record. A capture error must not lose the record itself.
|
|
529
|
+
const feeSummary = opts?.sharedFeeSummary ?? (opts?.captureFeeSummary ? await this.captureFeeEnvironment(opts.targetSlot).catch(()=>undefined) : undefined);
|
|
530
|
+
if (feeSummary) {
|
|
531
|
+
tx.gasInfo = {
|
|
532
|
+
...tx.gasInfo,
|
|
533
|
+
...feeSummary
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
if (tx.gasInfo) {
|
|
537
|
+
this.log.warn(`Gas pricing data for failed L1 tx (${tx.failureType})`, {
|
|
538
|
+
failureType: tx.failureType,
|
|
539
|
+
actions: tx.context.actions,
|
|
540
|
+
slot: tx.context.slot,
|
|
541
|
+
...tx.gasInfo,
|
|
542
|
+
...tx.timing
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
const store = await this.failedTxStore;
|
|
546
|
+
if (store) {
|
|
547
|
+
await store.saveFailedTx(tx);
|
|
548
|
+
}
|
|
549
|
+
} catch (err) {
|
|
550
|
+
this.log.warn(`Failed to backup failed L1 tx to store`, err);
|
|
551
|
+
}
|
|
552
|
+
})();
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
* Captures per-block fee data for the L1 blocks in the target slot's inclusion window (the blocks the
|
|
556
|
+
* tx could have landed in) for underpricing diagnostics. Reads only already-mined blocks, so it never
|
|
557
|
+
* waits on the chain. Safe to call off the critical path: the underlying capture never throws, and this
|
|
558
|
+
* returns undefined when there is no target slot or the window is not yet mined (e.g. an early send
|
|
559
|
+
* failure), in which case the record simply carries no window data.
|
|
560
|
+
*/ async captureFeeEnvironment(targetL2Slot) {
|
|
561
|
+
if (targetL2Slot === undefined) {
|
|
562
|
+
return undefined;
|
|
563
|
+
}
|
|
564
|
+
const l1Constants = this.epochCache.getL1Constants();
|
|
565
|
+
// The inclusion window is [start of slot N, start of slot N+1): all L1 blocks that can include a tx
|
|
566
|
+
// for this L2 slot. getTimestampForSlot returns seconds, matching block.timestamp.
|
|
567
|
+
const windowStartS = getTimestampForSlot(targetL2Slot, l1Constants);
|
|
568
|
+
const windowEndS = getTimestampForSlot(SlotNumber(Number(targetL2Slot) + 1), l1Constants);
|
|
569
|
+
const windowBlocks = await captureWindowBlockFees(this.l1TxUtils.client, windowStartS, windowEndS);
|
|
570
|
+
if (windowBlocks.length === 0) {
|
|
571
|
+
return undefined;
|
|
572
|
+
}
|
|
573
|
+
return {
|
|
574
|
+
windowBlocks
|
|
575
|
+
};
|
|
576
|
+
}
|
|
577
|
+
/** Computes timing info relative to the L2 slot deadline. */ computeTimingInfo(targetL2Slot) {
|
|
578
|
+
if (targetL2Slot === undefined) {
|
|
579
|
+
return undefined;
|
|
580
|
+
}
|
|
581
|
+
const l1Constants = this.epochCache.getL1Constants();
|
|
582
|
+
const slotDeadlineS = getTimestampForSlot(SlotNumber(Number(targetL2Slot) + 1), l1Constants);
|
|
583
|
+
const slotDeadlineMs = Number(slotDeadlineS) * 1000;
|
|
584
|
+
return {
|
|
585
|
+
targetL2Slot: Number(targetL2Slot),
|
|
586
|
+
slotDeadlineTimestampS: slotDeadlineS,
|
|
587
|
+
msUntilSlotDeadline: slotDeadlineMs - this.dateProvider.now()
|
|
588
|
+
};
|
|
589
|
+
}
|
|
590
|
+
/**
|
|
591
|
+
* Builds an id for a synthetic failure record (send-error/timeout) that has no on-chain tx hash.
|
|
592
|
+
* Includes the failure time so each attempt — including retries of the same slot — is stored as its
|
|
593
|
+
* own record rather than overwriting the previous one.
|
|
594
|
+
*/ failureRecordId(actions, targetSlot) {
|
|
595
|
+
return keccak256(toHex(`${actions.join(',')}:${targetSlot ?? ''}:${Date.now()}`));
|
|
511
596
|
}
|
|
512
597
|
getRollupContract() {
|
|
513
598
|
return this.rollupContract;
|
|
514
599
|
}
|
|
515
600
|
/**
|
|
516
601
|
* Gets the fee asset price modifier from the oracle.
|
|
517
|
-
*
|
|
518
|
-
|
|
519
|
-
|
|
602
|
+
*
|
|
603
|
+
* @param predictedParentEthPerFeeAssetE12 - Optional predicted parent eth-per-fee-asset (E12).
|
|
604
|
+
* Pipelined proposers should pass the value from the predicted parent fee header so the
|
|
605
|
+
* modifier matches the parent L1 will use when applying it.
|
|
606
|
+
* @returns The fee asset price modifier in basis points, or 0n if the oracle query fails.
|
|
607
|
+
*/ getFeeAssetPriceModifier(predictedParentEthPerFeeAssetE12) {
|
|
608
|
+
return this.feeAssetPriceOracle.computePriceModifier(predictedParentEthPerFeeAssetE12);
|
|
520
609
|
}
|
|
521
610
|
getSenderAddress() {
|
|
522
611
|
return this.l1TxUtils.getSenderAddress();
|
|
@@ -526,17 +615,11 @@ export class SequencerPublisher {
|
|
|
526
615
|
*/ getL1FeeAnalyzer() {
|
|
527
616
|
return this.l1FeeAnalyzer;
|
|
528
617
|
}
|
|
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
618
|
addRequest(request) {
|
|
536
619
|
this.requests.push(request);
|
|
537
620
|
}
|
|
538
621
|
getCurrentL2Slot() {
|
|
539
|
-
return this.epochCache.
|
|
622
|
+
return this.epochCache.getSlotNow();
|
|
540
623
|
}
|
|
541
624
|
/**
|
|
542
625
|
* Clears all pending requests without sending them.
|
|
@@ -589,11 +672,15 @@ export class SequencerPublisher {
|
|
|
589
672
|
}
|
|
590
673
|
/**
|
|
591
674
|
* Sends all requests that are still valid.
|
|
675
|
+
* @param targetSlot - The target L2 slot for this send. When provided (the production path, via
|
|
676
|
+
* sendRequestsAt), it is threaded into bundleSimulate so the block.timestamp override matches
|
|
677
|
+
* the slot the propose is built for. When omitted, falls back to getCurrentL2Slot() for the
|
|
678
|
+
* AutomineSequencer, which publishes synchronously within the current slot.
|
|
592
679
|
* @returns one of:
|
|
593
680
|
* - A receipt and stats if the tx succeeded
|
|
594
681
|
* - a receipt and errorMsg if it failed on L1
|
|
595
682
|
* - undefined if no valid requests are found OR the tx failed to send.
|
|
596
|
-
*/ async sendRequests() {
|
|
683
|
+
*/ async sendRequests(targetSlot) {
|
|
597
684
|
const requestsToProcess = [
|
|
598
685
|
...this.requests
|
|
599
686
|
];
|
|
@@ -601,10 +688,9 @@ export class SequencerPublisher {
|
|
|
601
688
|
if (this.interrupted || requestsToProcess.length === 0) {
|
|
602
689
|
return undefined;
|
|
603
690
|
}
|
|
604
|
-
const currentL2Slot = this.getCurrentL2Slot();
|
|
691
|
+
const currentL2Slot = targetSlot ?? this.getCurrentL2Slot();
|
|
605
692
|
this.log.debug(`Sending requests on L2 slot ${currentL2Slot}`);
|
|
606
693
|
const validRequests = requestsToProcess.filter((request)=>request.lastValidL2Slot >= currentL2Slot);
|
|
607
|
-
const validActions = validRequests.map((x)=>x.action);
|
|
608
694
|
const expiredActions = requestsToProcess.filter((request)=>request.lastValidL2Slot < currentL2Slot).map((x)=>x.action);
|
|
609
695
|
if (validRequests.length !== requestsToProcess.length) {
|
|
610
696
|
this.log.warn(`Some requests were expired for slot ${currentL2Slot}`, {
|
|
@@ -622,75 +708,98 @@ export class SequencerPublisher {
|
|
|
622
708
|
this.log.debug(`No valid requests to send`);
|
|
623
709
|
return undefined;
|
|
624
710
|
}
|
|
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
|
-
}
|
|
711
|
+
// Collect earliest txTimeoutAt across all requests.
|
|
712
|
+
const gasConfigs = validRequests.filter((request)=>request.gasConfig).map((request)=>request.gasConfig);
|
|
646
713
|
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
|
-
};
|
|
714
|
+
const txTimeoutAt = txTimeoutAts.length > 0 ? new Date(Math.min(...txTimeoutAts.map((g)=>g.getTime()))) : undefined;
|
|
652
715
|
// Sort the requests so that proposals always go first
|
|
653
716
|
// This ensures the committee gets precomputed correctly
|
|
654
717
|
validRequests.sort((a, b)=>compareActions(a.action, b.action));
|
|
655
718
|
try {
|
|
656
|
-
//
|
|
657
|
-
const
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
719
|
+
// Bundle-level eth_simulateV1: filters out entries that revert and derives the gasLimit.
|
|
720
|
+
const bundleResult = await this.bundleSimulator.simulate(validRequests, currentL2Slot);
|
|
721
|
+
if (bundleResult.kind === 'aborted') {
|
|
722
|
+
this.logDroppedInSim(bundleResult.droppedRequests);
|
|
723
|
+
void this.backupDroppedInSim(bundleResult.droppedRequests, currentL2Slot).catch((err)=>this.log.error(`Failed to backup requests dropped in simulation`, err));
|
|
724
|
+
return undefined;
|
|
725
|
+
}
|
|
726
|
+
const { requests, droppedRequests, gasLimit } = bundleResult.kind === 'fallback' ? {
|
|
727
|
+
requests: bundleResult.requests,
|
|
728
|
+
droppedRequests: bundleResult.droppedRequests,
|
|
729
|
+
gasLimit: MAX_L1_TX_LIMIT
|
|
730
|
+
} : bundleResult;
|
|
731
|
+
this.logDroppedInSim(droppedRequests);
|
|
732
|
+
// Compute blobConfig from survivors (not original validRequests) so that if the propose
|
|
733
|
+
// entry was dropped by bundleSimulate we don't attach a blob-typed config to a non-blob tx.
|
|
734
|
+
const [blobConfig] = requests.filter((r)=>r.blobConfig).map((r)=>r.blobConfig);
|
|
735
|
+
const txConfig = {
|
|
736
|
+
gasLimit,
|
|
737
|
+
txTimeoutAt
|
|
674
738
|
};
|
|
675
739
|
this.log.debug('Forwarding transactions', {
|
|
676
|
-
|
|
740
|
+
requests: requests.map((request)=>request.action),
|
|
677
741
|
txConfig
|
|
678
742
|
});
|
|
679
|
-
const result = await this.forwardWithPublisherRotation(
|
|
743
|
+
const result = await this.forwardWithPublisherRotation(requests, txConfig, blobConfig, currentL2Slot);
|
|
680
744
|
if (result === undefined) {
|
|
681
745
|
return undefined;
|
|
682
746
|
}
|
|
683
|
-
const { successfulActions = [], failedActions = [] } = this.callbackBundledTransactions(
|
|
747
|
+
const { successfulActions = [], failedActions = [] } = this.callbackBundledTransactions(requests, result);
|
|
748
|
+
const allFailedActions = [
|
|
749
|
+
...failedActions,
|
|
750
|
+
...droppedRequests.map((d)=>d.request.action)
|
|
751
|
+
];
|
|
684
752
|
return {
|
|
685
753
|
result,
|
|
686
754
|
expiredActions,
|
|
687
|
-
sentActions:
|
|
755
|
+
sentActions: requests.map((x)=>x.action),
|
|
688
756
|
successfulActions,
|
|
689
|
-
failedActions
|
|
757
|
+
failedActions: allFailedActions
|
|
690
758
|
};
|
|
691
759
|
} catch (err) {
|
|
692
760
|
const viemError = formatViemError(err);
|
|
693
761
|
this.log.error(`Failed to publish bundled transactions`, viemError);
|
|
762
|
+
if (err instanceof TimeoutError) {
|
|
763
|
+
const timeoutState = err instanceof L1TxTimeoutError ? err.txState : undefined;
|
|
764
|
+
void (async ()=>{
|
|
765
|
+
// The RPC is likely degraded right after a timeout, so back up without the block number
|
|
766
|
+
// rather than leaking an unhandled rejection.
|
|
767
|
+
const l1BlockNumber = await this.l1TxUtils.getBlockNumber().catch(()=>0n);
|
|
768
|
+
this.backupFailedTx({
|
|
769
|
+
id: this.failureRecordId(validRequests.map((r)=>r.action), currentL2Slot),
|
|
770
|
+
failureType: 'timeout',
|
|
771
|
+
request: {
|
|
772
|
+
to: MULTI_CALL_3_ADDRESS,
|
|
773
|
+
data: '0x'
|
|
774
|
+
},
|
|
775
|
+
l1BlockNumber,
|
|
776
|
+
error: {
|
|
777
|
+
message: viemError.message,
|
|
778
|
+
name: 'TimeoutError'
|
|
779
|
+
},
|
|
780
|
+
context: {
|
|
781
|
+
actions: validRequests.map((r)=>r.action),
|
|
782
|
+
requests: validRequests.filter((r)=>r.request.to !== null).map((r)=>({
|
|
783
|
+
action: r.action,
|
|
784
|
+
to: r.request.to,
|
|
785
|
+
data: r.request.data
|
|
786
|
+
})),
|
|
787
|
+
sender: this.getSenderAddress().toString(),
|
|
788
|
+
slot: Number(currentL2Slot)
|
|
789
|
+
},
|
|
790
|
+
timing: this.computeTimingInfo(currentL2Slot),
|
|
791
|
+
gasInfo: timeoutState ? {
|
|
792
|
+
sentGasPriceLadder: timeoutState.gasPriceHistory,
|
|
793
|
+
attempts: timeoutState.attempts,
|
|
794
|
+
gasLimit: timeoutState.gasLimit,
|
|
795
|
+
nonce: timeoutState.nonce
|
|
796
|
+
} : undefined
|
|
797
|
+
}, {
|
|
798
|
+
captureFeeSummary: true,
|
|
799
|
+
targetSlot: currentL2Slot
|
|
800
|
+
});
|
|
801
|
+
})();
|
|
802
|
+
}
|
|
694
803
|
return undefined;
|
|
695
804
|
} finally{
|
|
696
805
|
try {
|
|
@@ -700,26 +809,96 @@ export class SequencerPublisher {
|
|
|
700
809
|
}
|
|
701
810
|
}
|
|
702
811
|
}
|
|
812
|
+
/** Logs entries dropped by bundle simulation as warnings on the publisher's logger. */ logDroppedInSim(dropped) {
|
|
813
|
+
for (const drop of dropped){
|
|
814
|
+
const revertReasonDecoded = drop.revertReason ?? tryDecodeRevertReason(drop.returnData, this.revertDecoderAbi);
|
|
815
|
+
this.log.warn('Bundle entry dropped: action reverted in sim', {
|
|
816
|
+
action: drop.request.action,
|
|
817
|
+
revertReason: revertReasonDecoded ?? drop.returnData,
|
|
818
|
+
revertReasonDecoded,
|
|
819
|
+
returnData: drop.returnData
|
|
820
|
+
});
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
/** Backs up entries dropped by bundle simulation, one record per dropped action. */ async backupDroppedInSim(dropped, targetSlot) {
|
|
824
|
+
if (dropped.length === 0) {
|
|
825
|
+
return;
|
|
826
|
+
}
|
|
827
|
+
// Invoked as `void backupDroppedInSim(...)` on the publish path, so it must not throw.
|
|
828
|
+
try {
|
|
829
|
+
const l1BlockNumber = await this.l1TxUtils.getBlockNumber();
|
|
830
|
+
// Every dropped entry failed in the same slot against the same L1 fee conditions, so capture
|
|
831
|
+
// the fee environment once and share it rather than re-reading the window per entry.
|
|
832
|
+
const sharedFeeSummary = await this.captureFeeEnvironment(targetSlot).catch(()=>undefined);
|
|
833
|
+
const timing = this.computeTimingInfo(targetSlot);
|
|
834
|
+
for (const { request: req } of dropped){
|
|
835
|
+
this.backupFailedTx({
|
|
836
|
+
id: keccak256(req.request.data),
|
|
837
|
+
failureType: 'simulation',
|
|
838
|
+
request: {
|
|
839
|
+
to: req.request.to,
|
|
840
|
+
data: req.request.data
|
|
841
|
+
},
|
|
842
|
+
l1BlockNumber,
|
|
843
|
+
error: {
|
|
844
|
+
message: 'Bundle entry dropped: action reverted in sim'
|
|
845
|
+
},
|
|
846
|
+
context: {
|
|
847
|
+
actions: [
|
|
848
|
+
req.action
|
|
849
|
+
],
|
|
850
|
+
sender: this.getSenderAddress().toString(),
|
|
851
|
+
slot: targetSlot !== undefined ? Number(targetSlot) : undefined
|
|
852
|
+
},
|
|
853
|
+
timing
|
|
854
|
+
}, {
|
|
855
|
+
sharedFeeSummary
|
|
856
|
+
});
|
|
857
|
+
}
|
|
858
|
+
} catch (err) {
|
|
859
|
+
this.log.warn(`Failed to back up dropped-in-sim entries`, err);
|
|
860
|
+
}
|
|
861
|
+
}
|
|
703
862
|
/**
|
|
704
863
|
* Forwards transactions via Multicall3, rotating to the next available publisher if a send
|
|
705
864
|
* failure occurs (i.e. the tx never reached the chain).
|
|
706
865
|
* On-chain reverts and simulation errors are returned as-is without rotation.
|
|
707
|
-
*/ async forwardWithPublisherRotation(validRequests, txConfig, blobConfig) {
|
|
866
|
+
*/ async forwardWithPublisherRotation(validRequests, txConfig, blobConfig, targetSlot) {
|
|
867
|
+
if (!txConfig?.gasLimit) {
|
|
868
|
+
throw new Error('gasLimit is required for bundled transactions');
|
|
869
|
+
}
|
|
870
|
+
const txConfigWithGasLimit = txConfig;
|
|
708
871
|
const triedAddresses = [];
|
|
709
872
|
let currentPublisher = this.l1TxUtils;
|
|
710
873
|
while(true){
|
|
874
|
+
if (txConfig.txTimeoutAt && new Date() > txConfig.txTimeoutAt) {
|
|
875
|
+
this.log.warn(`Tx timeout (${txConfig.txTimeoutAt.toISOString()}) elapsed; stopping publisher rotation`, {
|
|
876
|
+
triedAddresses: triedAddresses.map((a)=>a.toString())
|
|
877
|
+
});
|
|
878
|
+
return undefined;
|
|
879
|
+
}
|
|
711
880
|
triedAddresses.push(currentPublisher.getSenderAddress());
|
|
712
881
|
try {
|
|
713
|
-
const result = await Multicall3.forward(validRequests.map((r)=>r.request), currentPublisher,
|
|
882
|
+
const result = await Multicall3.forward(validRequests.map((r)=>r.request), currentPublisher, txConfigWithGasLimit, blobConfig, {
|
|
883
|
+
gasLimitRequired: true
|
|
884
|
+
});
|
|
714
885
|
this.l1TxUtils = currentPublisher;
|
|
715
886
|
return result;
|
|
716
887
|
} catch (err) {
|
|
717
888
|
if (err instanceof TimeoutError) {
|
|
718
889
|
throw err;
|
|
719
890
|
}
|
|
891
|
+
if (err instanceof MulticallForwarderRevertedError) {
|
|
892
|
+
this.log.error('Forwarder transaction reverted on-chain; not rotating publisher', err, {
|
|
893
|
+
transactionHash: err.receipt.transactionHash
|
|
894
|
+
});
|
|
895
|
+
this.backupRevertFailure(validRequests, err, currentPublisher, targetSlot);
|
|
896
|
+
return undefined;
|
|
897
|
+
}
|
|
720
898
|
const viemError = formatViemError(err);
|
|
721
899
|
if (!this.getNextPublisher) {
|
|
722
900
|
this.log.error('Failed to publish bundled transactions', viemError);
|
|
901
|
+
this.backupSendFailure(validRequests, viemError, currentPublisher, targetSlot);
|
|
723
902
|
return undefined;
|
|
724
903
|
}
|
|
725
904
|
this.log.warn(`Publisher ${currentPublisher.getSenderAddress()} failed to send, rotating to next publisher`, viemError);
|
|
@@ -727,110 +906,205 @@ export class SequencerPublisher {
|
|
|
727
906
|
...triedAddresses
|
|
728
907
|
]);
|
|
729
908
|
if (!nextPublisher) {
|
|
730
|
-
this.log.error(
|
|
909
|
+
this.log.error(`All available publishers exhausted (tried ${triedAddresses.length}), failed to publish bundled transactions`, viemError, {
|
|
910
|
+
triedAddresses: triedAddresses.map((a)=>a.toString())
|
|
911
|
+
});
|
|
912
|
+
this.backupSendFailure(validRequests, viemError, currentPublisher, targetSlot);
|
|
731
913
|
return undefined;
|
|
732
914
|
}
|
|
733
915
|
currentPublisher = nextPublisher;
|
|
734
916
|
}
|
|
735
917
|
}
|
|
736
918
|
}
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
919
|
+
/** Backs up an on-chain revert failure to the failed tx store. */ backupRevertFailure(requests, err, publisher, targetSlot) {
|
|
920
|
+
this.backupFailedTx({
|
|
921
|
+
id: err.receipt.transactionHash,
|
|
922
|
+
failureType: 'revert',
|
|
923
|
+
request: {
|
|
924
|
+
to: MULTI_CALL_3_ADDRESS,
|
|
925
|
+
data: '0x'
|
|
926
|
+
},
|
|
927
|
+
l1BlockNumber: err.receipt.blockNumber,
|
|
928
|
+
receipt: {
|
|
929
|
+
transactionHash: err.receipt.transactionHash,
|
|
930
|
+
blockNumber: err.receipt.blockNumber,
|
|
931
|
+
gasUsed: err.receipt.gasUsed,
|
|
932
|
+
status: 'reverted'
|
|
933
|
+
},
|
|
934
|
+
error: {
|
|
935
|
+
message: err.message,
|
|
936
|
+
name: err.name
|
|
937
|
+
},
|
|
938
|
+
context: {
|
|
939
|
+
actions: requests.map((r)=>r.action),
|
|
940
|
+
requests: requests.filter((r)=>r.request.to !== null).map((r)=>({
|
|
941
|
+
action: r.action,
|
|
942
|
+
to: r.request.to,
|
|
943
|
+
data: r.request.data
|
|
944
|
+
})),
|
|
945
|
+
sender: publisher.getSenderAddress().toString(),
|
|
946
|
+
slot: targetSlot !== undefined ? Number(targetSlot) : undefined
|
|
947
|
+
},
|
|
948
|
+
gasInfo: err.txState ? {
|
|
949
|
+
sentGasPrice: err.txState.gasPrice,
|
|
950
|
+
gasLimit: err.txState.gasLimit,
|
|
951
|
+
nonce: err.txState.nonce
|
|
952
|
+
} : undefined,
|
|
953
|
+
timing: this.computeTimingInfo(targetSlot)
|
|
954
|
+
}, {
|
|
955
|
+
captureFeeSummary: true,
|
|
956
|
+
targetSlot
|
|
957
|
+
});
|
|
958
|
+
}
|
|
959
|
+
/** Backs up a send failure (tx never reached chain) to the failed tx store. */ backupSendFailure(requests, error, publisher, targetSlot) {
|
|
960
|
+
// If we can't get the block number, still back up without it.
|
|
961
|
+
void this.l1TxUtils.getBlockNumber().catch(()=>0n).then((l1BlockNumber)=>{
|
|
741
962
|
this.backupFailedTx({
|
|
742
|
-
id:
|
|
963
|
+
id: this.failureRecordId(requests.map((r)=>r.action), targetSlot),
|
|
743
964
|
failureType: 'send-error',
|
|
744
965
|
request: {
|
|
745
966
|
to: MULTI_CALL_3_ADDRESS,
|
|
746
|
-
data:
|
|
967
|
+
data: '0x'
|
|
747
968
|
},
|
|
748
|
-
|
|
749
|
-
l1BlockNumber: txContext.l1BlockNumber.toString(),
|
|
969
|
+
l1BlockNumber,
|
|
750
970
|
error: {
|
|
751
|
-
message:
|
|
752
|
-
name:
|
|
971
|
+
message: error.message,
|
|
972
|
+
name: 'name' in error ? error.name : undefined
|
|
753
973
|
},
|
|
754
974
|
context: {
|
|
755
975
|
actions: requests.map((r)=>r.action),
|
|
756
|
-
requests: requests.map((r)=>({
|
|
976
|
+
requests: requests.filter((r)=>r.request.to !== null).map((r)=>({
|
|
757
977
|
action: r.action,
|
|
758
978
|
to: r.request.to,
|
|
759
979
|
data: r.request.data
|
|
760
980
|
})),
|
|
761
|
-
sender:
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
this.log.verbose(`Published bundled transactions (${actionsListStr})`, {
|
|
769
|
-
result,
|
|
770
|
-
requests
|
|
981
|
+
sender: publisher.getSenderAddress().toString(),
|
|
982
|
+
slot: targetSlot !== undefined ? Number(targetSlot) : undefined
|
|
983
|
+
},
|
|
984
|
+
timing: this.computeTimingInfo(targetSlot)
|
|
985
|
+
}, {
|
|
986
|
+
captureFeeSummary: true,
|
|
987
|
+
targetSlot
|
|
771
988
|
});
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
989
|
+
});
|
|
990
|
+
}
|
|
991
|
+
/*
|
|
992
|
+
* Schedules sending all enqueued requests at (or after) the start of the given L2 slot.
|
|
993
|
+
*/ async sendRequestsAt(targetSlot) {
|
|
994
|
+
await this.waitForTargetSlot(targetSlot);
|
|
995
|
+
if (this.interrupted) {
|
|
996
|
+
return undefined;
|
|
997
|
+
}
|
|
998
|
+
return this.sendRequests(targetSlot);
|
|
999
|
+
}
|
|
1000
|
+
/**
|
|
1001
|
+
* Sleeps until one L1 slot before the L2 slot boundary, and then waits for that L1 block
|
|
1002
|
+
* to be mined, so we don't risk being included in it. If that block never gets mined after
|
|
1003
|
+
* a timeout, we assume it got skipped on L1, so we send the tx anyway.
|
|
1004
|
+
*/ async waitForTargetSlot(targetSlot) {
|
|
1005
|
+
const l1Constants = this.epochCache.getL1Constants();
|
|
1006
|
+
const nowInSeconds = this.dateProvider.nowInSeconds();
|
|
1007
|
+
const startOfTargetSlotTs = getTimestampForSlot(targetSlot, l1Constants);
|
|
1008
|
+
const previousL1BlockTs = startOfTargetSlotTs - this.ethereumSlotDuration;
|
|
1009
|
+
const waitDeadlineTs = previousL1BlockTs + BigInt(this.previousL1BlockWaitTimeoutMs / 1000);
|
|
1010
|
+
const logCtx = {
|
|
1011
|
+
targetSlot,
|
|
1012
|
+
startOfTargetSlotTs,
|
|
1013
|
+
nowInSeconds,
|
|
1014
|
+
previousL1BlockTs,
|
|
1015
|
+
waitDeadlineTs
|
|
1016
|
+
};
|
|
1017
|
+
// Check if we are already past time
|
|
1018
|
+
if (nowInSeconds >= startOfTargetSlotTs) {
|
|
1019
|
+
this.log.verbose(`Target slot ${targetSlot} already started, sending requests immediately`, logCtx);
|
|
1020
|
+
return;
|
|
1021
|
+
}
|
|
1022
|
+
// Otherwise we wait
|
|
1023
|
+
this.log.debug(`Waiting for slot ${targetSlot} before sending requests`, logCtx);
|
|
1024
|
+
// Wait until previous L1 block timestamp first
|
|
1025
|
+
const sleepMs = (Number(previousL1BlockTs) - nowInSeconds) * 1000;
|
|
1026
|
+
if (sleepMs > 0 && !this.interrupted) {
|
|
1027
|
+
this.log.trace(`Sleeping ${sleepMs}ms before waiting for previous L1 block`, logCtx);
|
|
1028
|
+
await this.interruptibleSleep.sleep(sleepMs);
|
|
1029
|
+
}
|
|
1030
|
+
// Then loop until we see the previous L1 block, so we know that we cannot be included in it.
|
|
1031
|
+
// We time out after a while, once we are sure that that block is skipped in L1.
|
|
1032
|
+
while(!this.interrupted){
|
|
1033
|
+
try {
|
|
1034
|
+
const nowInSeconds = this.dateProvider.nowInSeconds();
|
|
1035
|
+
logCtx.nowInSeconds = nowInSeconds;
|
|
1036
|
+
if (nowInSeconds >= waitDeadlineTs) {
|
|
1037
|
+
this.log.warn(`Timed out waiting for previous L1 block before sending requests, proceeding`, logCtx);
|
|
1038
|
+
return;
|
|
779
1039
|
}
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
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
|
-
}
|
|
1040
|
+
const latestBlockTs = await this.l1TxUtils.getBlock().then((b)=>b.timestamp);
|
|
1041
|
+
if (latestBlockTs >= previousL1BlockTs) {
|
|
1042
|
+
this.log.debug(`Previous L1 block mined, proceeding to send requests`, {
|
|
1043
|
+
...logCtx,
|
|
1044
|
+
latestBlockTs
|
|
1045
|
+
});
|
|
1046
|
+
return;
|
|
1047
|
+
}
|
|
1048
|
+
this.log.trace(`Previous L1 block not mined yet, continuing to wait`, {
|
|
1049
|
+
...logCtx,
|
|
1050
|
+
latestBlockTs
|
|
810
1051
|
});
|
|
1052
|
+
} catch (err) {
|
|
1053
|
+
this.log.error(`Error while waiting for previous L1 block before sending requests; retrying`, err, logCtx);
|
|
1054
|
+
} finally{
|
|
1055
|
+
await this.interruptibleSleep.sleep(this.previousL1BlockWaitPollIntervalMs);
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
callbackBundledTransactions(requests, result) {
|
|
1060
|
+
const actionsListStr = requests.map((r)=>r.action).join(', ');
|
|
1061
|
+
this.log.verbose(`Published bundled transactions (${actionsListStr})`, {
|
|
1062
|
+
result,
|
|
1063
|
+
requests: requests.map((r)=>({
|
|
1064
|
+
...r,
|
|
1065
|
+
// Avoid logging large blob data
|
|
1066
|
+
blobConfig: r.blobConfig ? {
|
|
1067
|
+
...r.blobConfig,
|
|
1068
|
+
blobs: r.blobConfig.blobs.map((b)=>({
|
|
1069
|
+
size: trimmedBytesLength(b)
|
|
1070
|
+
}))
|
|
1071
|
+
} : undefined
|
|
1072
|
+
}))
|
|
1073
|
+
});
|
|
1074
|
+
const successfulActions = [];
|
|
1075
|
+
const failedActions = [];
|
|
1076
|
+
for (const request of requests){
|
|
1077
|
+
if (request.checkSuccess(request.request, result)) {
|
|
1078
|
+
successfulActions.push(request.action);
|
|
1079
|
+
} else {
|
|
1080
|
+
failedActions.push(request.action);
|
|
811
1081
|
}
|
|
812
|
-
return {
|
|
813
|
-
successfulActions,
|
|
814
|
-
failedActions
|
|
815
|
-
};
|
|
816
1082
|
}
|
|
1083
|
+
return {
|
|
1084
|
+
successfulActions,
|
|
1085
|
+
failedActions
|
|
1086
|
+
};
|
|
817
1087
|
}
|
|
818
1088
|
/**
|
|
819
|
-
* @notice Will call `
|
|
1089
|
+
* @notice Will call `canProposeAt` to make sure that it is possible to propose
|
|
820
1090
|
* @param tipArchive - The archive to check
|
|
821
1091
|
* @returns The slot and block number if it is possible to propose, undefined otherwise
|
|
822
|
-
*/
|
|
1092
|
+
*/ async canProposeAt(tipArchive, msgSender, simulationOverridesPlan) {
|
|
823
1093
|
// TODO: #14291 - should loop through multiple keys to check if any of them can propose
|
|
824
|
-
|
|
1094
|
+
// These errors are expected when we cannot actually propose right now — usually because our
|
|
1095
|
+
// local view of the chain is ahead of L1 (proposed parent hasn't landed yet, or someone
|
|
1096
|
+
// else has just landed the slot, or the archive override doesn't match). We log a warn and
|
|
1097
|
+
// skip the proposal; we do NOT treat these as bugs.
|
|
1098
|
+
const expectedErrors = [
|
|
825
1099
|
'SlotAlreadyInChain',
|
|
826
1100
|
'InvalidProposer',
|
|
827
1101
|
'InvalidArchive'
|
|
828
1102
|
];
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
if (err instanceof FormattedViemError &&
|
|
833
|
-
this.log.warn(`Failed canProposeAtTime check with ${
|
|
1103
|
+
const slotOffset = this.aztecSlotDuration;
|
|
1104
|
+
const nextL1SlotTs = this.getNextL1SlotTimestamp() + slotOffset;
|
|
1105
|
+
return this.rollupContract.canProposeAt(tipArchive.toBuffer(), msgSender.toString(), nextL1SlotTs, await buildSimulationOverridesStateOverride(this.rollupContract, simulationOverridesPlan)).catch((err)=>{
|
|
1106
|
+
if (err instanceof FormattedViemError && expectedErrors.find((e)=>err.message.includes(e))) {
|
|
1107
|
+
this.log.warn(`Failed canProposeAtTime check with ${expectedErrors.find((e)=>err.message.includes(e))}`, {
|
|
834
1108
|
error: err.message
|
|
835
1109
|
});
|
|
836
1110
|
} else {
|
|
@@ -844,22 +1118,23 @@ export class SequencerPublisher {
|
|
|
844
1118
|
* @dev This is a convenience function that can be used by the sequencer to validate a "partial" header.
|
|
845
1119
|
* It will throw if the block header is invalid.
|
|
846
1120
|
* @param header - The block header to validate
|
|
847
|
-
*/ async validateBlockHeader(header,
|
|
1121
|
+
*/ async validateBlockHeader(header, simulationOverridesPlan) {
|
|
848
1122
|
const flags = {
|
|
849
1123
|
ignoreDA: true,
|
|
850
1124
|
ignoreSignatures: true
|
|
851
1125
|
};
|
|
852
1126
|
const args = [
|
|
853
1127
|
header.toViem(),
|
|
854
|
-
CommitteeAttestationsAndSigners.
|
|
1128
|
+
CommitteeAttestationsAndSigners.packAttestations([]),
|
|
855
1129
|
[],
|
|
856
1130
|
Signature.empty().toViemSignature(),
|
|
857
1131
|
`0x${'0'.repeat(64)}`,
|
|
858
1132
|
header.blobsHash.toString(),
|
|
859
1133
|
flags
|
|
860
1134
|
];
|
|
861
|
-
const
|
|
862
|
-
const
|
|
1135
|
+
const l1Constants = this.epochCache.getL1Constants();
|
|
1136
|
+
const ts = getLastL1SlotTimestampForL2Slot(header.slotNumber, l1Constants);
|
|
1137
|
+
const stateOverrides = await buildSimulationOverridesStateOverride(this.rollupContract, simulationOverridesPlan);
|
|
863
1138
|
let balance = 0n;
|
|
864
1139
|
if (this.config.fishermanMode) {
|
|
865
1140
|
// In fisherman mode, we can't know where the proposer is publishing from
|
|
@@ -881,7 +1156,7 @@ export class SequencerPublisher {
|
|
|
881
1156
|
}),
|
|
882
1157
|
from: MULTI_CALL_3_ADDRESS
|
|
883
1158
|
}, {
|
|
884
|
-
time: ts
|
|
1159
|
+
time: ts
|
|
885
1160
|
}, stateOverrides);
|
|
886
1161
|
this.log.debug(`Simulated validateHeader`);
|
|
887
1162
|
}
|
|
@@ -927,6 +1202,7 @@ export class SequencerPublisher {
|
|
|
927
1202
|
gasUsed,
|
|
928
1203
|
checkpointNumber,
|
|
929
1204
|
forcePendingCheckpointNumber: CheckpointNumber(checkpointNumber - 1),
|
|
1205
|
+
lastArchive: validationResult.checkpoint.lastArchive,
|
|
930
1206
|
reason
|
|
931
1207
|
};
|
|
932
1208
|
} catch (err) {
|
|
@@ -939,8 +1215,8 @@ export class SequencerPublisher {
|
|
|
939
1215
|
request,
|
|
940
1216
|
error: viemError.message
|
|
941
1217
|
});
|
|
942
|
-
const
|
|
943
|
-
if (
|
|
1218
|
+
const latestProposedCheckpointNumber = await this.rollupContract.getCheckpointNumber();
|
|
1219
|
+
if (latestProposedCheckpointNumber < checkpointNumber) {
|
|
944
1220
|
this.log.verbose(`Checkpoint ${checkpointNumber} has already been invalidated`, {
|
|
945
1221
|
...logData
|
|
946
1222
|
});
|
|
@@ -960,9 +1236,9 @@ export class SequencerPublisher {
|
|
|
960
1236
|
request: {
|
|
961
1237
|
to: request.to,
|
|
962
1238
|
data: request.data,
|
|
963
|
-
value: request.value
|
|
1239
|
+
value: request.value
|
|
964
1240
|
},
|
|
965
|
-
l1BlockNumber
|
|
1241
|
+
l1BlockNumber,
|
|
966
1242
|
error: {
|
|
967
1243
|
message: viemError.message,
|
|
968
1244
|
name: viemError.name
|
|
@@ -973,7 +1249,11 @@ export class SequencerPublisher {
|
|
|
973
1249
|
],
|
|
974
1250
|
checkpointNumber,
|
|
975
1251
|
sender: this.getSenderAddress().toString()
|
|
976
|
-
}
|
|
1252
|
+
},
|
|
1253
|
+
timing: this.computeTimingInfo(this.getCurrentL2Slot())
|
|
1254
|
+
}, {
|
|
1255
|
+
captureFeeSummary: true,
|
|
1256
|
+
targetSlot: this.getCurrentL2Slot()
|
|
977
1257
|
});
|
|
978
1258
|
throw new Error(`Failed to simulate invalidate checkpoint ${checkpointNumber}`, {
|
|
979
1259
|
cause: viemError
|
|
@@ -990,7 +1270,11 @@ export class SequencerPublisher {
|
|
|
990
1270
|
reason
|
|
991
1271
|
};
|
|
992
1272
|
this.log.debug(`Building invalidate checkpoint ${checkpoint.checkpointNumber} request`, logData);
|
|
993
|
-
|
|
1273
|
+
// Use the exact packed tuple posted to L1 verbatim. A repack via `packAttestations` is not a
|
|
1274
|
+
// byte-faithful inverse of `fromPacked` (a canonicalized yParity byte or an all-zero signature slot
|
|
1275
|
+
// round-trips differently), so it would diverge from the stored `attestationsHash` and revert the
|
|
1276
|
+
// invalidation.
|
|
1277
|
+
const attestationsAndSigners = validationResult.verbatimAttestations;
|
|
994
1278
|
if (reason === 'invalid-attestation') {
|
|
995
1279
|
return this.rollupContract.buildInvalidateBadAttestationRequest(checkpoint.checkpointNumber, attestationsAndSigners, committee, validationResult.invalidIndex);
|
|
996
1280
|
} else if (reason === 'insufficient-attestations') {
|
|
@@ -1000,28 +1284,7 @@ export class SequencerPublisher {
|
|
|
1000
1284
|
throw new Error(`Unknown reason for invalidation`);
|
|
1001
1285
|
}
|
|
1002
1286
|
}
|
|
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) {
|
|
1287
|
+
async enqueueCastSignalHelper(slotNumber, signalType, payload, base, signerAddress, signer) {
|
|
1025
1288
|
if (this.lastActions[signalType] && this.lastActions[signalType] === slotNumber) {
|
|
1026
1289
|
this.log.debug(`Skipping duplicate vote cast signal ${signalType} for slot ${slotNumber}`);
|
|
1027
1290
|
return false;
|
|
@@ -1041,30 +1304,26 @@ export class SequencerPublisher {
|
|
|
1041
1304
|
if (roundInfo.lastSignalSlot >= slotNumber) {
|
|
1042
1305
|
return false;
|
|
1043
1306
|
}
|
|
1044
|
-
if (await
|
|
1307
|
+
if (await base.isPayloadEmpty(payload)) {
|
|
1045
1308
|
this.log.warn(`Skipping vote cast for payload with empty code`);
|
|
1046
1309
|
return false;
|
|
1047
1310
|
}
|
|
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
|
-
}
|
|
1311
|
+
// Skip signaling if there is already a live (non-terminal) Governance proposal for this
|
|
1312
|
+
// payload. This is intentionally not cached: a previously-live proposal may transition to
|
|
1313
|
+
// a terminal state (Dropped/Rejected/Expired/Executed), at which point we may want to re-signal
|
|
1314
|
+
// the same payload in a future round.
|
|
1315
|
+
let proposed = false;
|
|
1316
|
+
try {
|
|
1317
|
+
proposed = await base.hasActiveProposalWithPayload(payload.toString());
|
|
1318
|
+
} catch (err) {
|
|
1319
|
+
// We deliberately swallow the error and proceed to signal. Failing closed (skipping the
|
|
1320
|
+
// signal) on transient RPC errors would let a flaky L1 endpoint silence governance
|
|
1321
|
+
// participation entirely; failing open at worst produces a duplicate signal that the
|
|
1322
|
+
// contract will simply count alongside others in the round.
|
|
1323
|
+
this.log.error(`Failed to check if payload ${payload} was already proposed (signalling anyway)`, err);
|
|
1065
1324
|
}
|
|
1066
|
-
if (
|
|
1067
|
-
this.log.info(`Payload ${payload}
|
|
1325
|
+
if (proposed) {
|
|
1326
|
+
this.log.info(`Payload ${payload} has a live governance proposal, stopping signals`);
|
|
1068
1327
|
return false;
|
|
1069
1328
|
}
|
|
1070
1329
|
const cachedLastVote = this.lastActions[signalType];
|
|
@@ -1077,53 +1336,17 @@ export class SequencerPublisher {
|
|
|
1077
1336
|
signer: this.l1TxUtils.client.account?.address,
|
|
1078
1337
|
lastValidL2Slot: slotNumber
|
|
1079
1338
|
});
|
|
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
1339
|
// TODO(palla/slash): All votes (governance and slashing) should txTimeoutAt at the end of the slot.
|
|
1118
1340
|
this.addRequest({
|
|
1119
|
-
gasConfig: {
|
|
1120
|
-
gasLimit: SequencerPublisher.VOTE_GAS_GUESS
|
|
1121
|
-
},
|
|
1122
1341
|
action,
|
|
1123
1342
|
request,
|
|
1124
1343
|
lastValidL2Slot: slotNumber,
|
|
1125
1344
|
checkSuccess: (_request, result)=>{
|
|
1126
|
-
const success = result &&
|
|
1345
|
+
const success = result && extractEventSuccess(result.receipt, {
|
|
1346
|
+
address: base.address.toString(),
|
|
1347
|
+
abi: EmpireBaseAbi,
|
|
1348
|
+
eventName: 'SignalCast'
|
|
1349
|
+
});
|
|
1127
1350
|
const logData = {
|
|
1128
1351
|
...result,
|
|
1129
1352
|
slotNumber,
|
|
@@ -1142,68 +1365,70 @@ export class SequencerPublisher {
|
|
|
1142
1365
|
});
|
|
1143
1366
|
return true;
|
|
1144
1367
|
}
|
|
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
1368
|
/**
|
|
1156
1369
|
* Enqueues a governance castSignal transaction to cast a signal for a given slot number.
|
|
1157
1370
|
* @param slotNumber - The slot number to cast a signal for.
|
|
1158
|
-
* @param timestamp - The timestamp of the slot to cast a signal for.
|
|
1159
1371
|
* @returns True if the signal was successfully enqueued, false otherwise.
|
|
1160
|
-
*/ enqueueGovernanceCastSignal(governancePayload, slotNumber,
|
|
1161
|
-
return this.enqueueCastSignalHelper(slotNumber,
|
|
1372
|
+
*/ enqueueGovernanceCastSignal(governancePayload, slotNumber, signerAddress, signer) {
|
|
1373
|
+
return this.enqueueCastSignalHelper(slotNumber, 'governance-signal', governancePayload, this.govProposerContract, signerAddress, signer);
|
|
1162
1374
|
}
|
|
1163
|
-
/**
|
|
1375
|
+
/**
|
|
1376
|
+
* Enqueues a `prune()` transaction if the rollup is prunable at the given slot's L1 timestamp.
|
|
1377
|
+
* `prune()` is permissionless and idempotent — if the chain is no longer prunable by send time the
|
|
1378
|
+
* bundle simulation usually drops the entry; on a node without `eth_simulateV1` the bundle is sent
|
|
1379
|
+
* as-is and the prune reverts `Rollup__NothingToPrune` inside `aggregate3(allowFailure: true)`
|
|
1380
|
+
* (a failed action, never a whole-tx revert). Used by the failed-sync fallback so a stuck pending
|
|
1381
|
+
* chain (e.g. bad data blocking sync) can be wound back to recover.
|
|
1382
|
+
* @returns true if a prune request was enqueued, false otherwise.
|
|
1383
|
+
*/ async enqueuePruneIfPrunable(slotNumber) {
|
|
1384
|
+
if (this.lastActions['prune'] === slotNumber) {
|
|
1385
|
+
this.log.debug(`Skipping duplicate prune for slot ${slotNumber}`, {
|
|
1386
|
+
slotNumber
|
|
1387
|
+
});
|
|
1388
|
+
return false;
|
|
1389
|
+
}
|
|
1390
|
+
// Use the SAME timestamp the bundle simulator overrides block.timestamp with at send time
|
|
1391
|
+
// (sequencer-bundle-simulator.ts) so this upfront check and the send-time sim agree. Slot-start
|
|
1392
|
+
// and last-L1-slot both fall within the same L2 slot (and epoch, which is what `canPruneAtTime`
|
|
1393
|
+
// derives), so they agree today; matching the simulator keeps it robust if the contract ever uses
|
|
1394
|
+
// the timestamp more granularly.
|
|
1395
|
+
const ts = getLastL1SlotTimestampForL2Slot(slotNumber, this.epochCache.getL1Constants());
|
|
1396
|
+
const canPrune = await this.rollupContract.canPruneAtTime(ts).catch((err)=>{
|
|
1397
|
+
this.log.error(`Failed to check canPruneAtTime for slot ${slotNumber}`, err, {
|
|
1398
|
+
slotNumber
|
|
1399
|
+
});
|
|
1400
|
+
return false;
|
|
1401
|
+
});
|
|
1402
|
+
if (!canPrune) {
|
|
1403
|
+
this.log.debug(`Rollup not prunable at slot ${slotNumber}`, {
|
|
1404
|
+
slotNumber
|
|
1405
|
+
});
|
|
1406
|
+
return false;
|
|
1407
|
+
}
|
|
1408
|
+
const request = {
|
|
1409
|
+
to: this.rollupContract.address,
|
|
1410
|
+
data: encodeFunctionData({
|
|
1411
|
+
abi: RollupAbi,
|
|
1412
|
+
functionName: 'prune',
|
|
1413
|
+
args: []
|
|
1414
|
+
})
|
|
1415
|
+
};
|
|
1416
|
+
this.log.info(`Enqueuing rollup prune for slot ${slotNumber}`, {
|
|
1417
|
+
slotNumber
|
|
1418
|
+
});
|
|
1419
|
+
return this.enqueueRequest('prune', request, {
|
|
1420
|
+
address: this.rollupContract.address,
|
|
1421
|
+
abi: RollupAbi,
|
|
1422
|
+
eventName: 'PrunedPending'
|
|
1423
|
+
}, slotNumber);
|
|
1424
|
+
}
|
|
1425
|
+
/** Enqueues all slashing actions as returned by the slasher client. */ async enqueueSlashingActions(actions, slotNumber, signerAddress, signer) {
|
|
1164
1426
|
if (actions.length === 0) {
|
|
1165
1427
|
this.log.debug(`No slashing actions to enqueue for slot ${slotNumber}`);
|
|
1166
1428
|
return false;
|
|
1167
1429
|
}
|
|
1168
1430
|
for (const action of actions){
|
|
1169
1431
|
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
1432
|
case 'vote-offenses':
|
|
1208
1433
|
{
|
|
1209
1434
|
this.log.debug(`Enqueuing slashing vote for ${action.votes.length} votes at slot ${slotNumber}`, {
|
|
@@ -1212,14 +1437,17 @@ export class SequencerPublisher {
|
|
|
1212
1437
|
votesCount: action.votes.length,
|
|
1213
1438
|
signerAddress
|
|
1214
1439
|
});
|
|
1215
|
-
if (this.slashingProposerContract
|
|
1216
|
-
this.log.error('
|
|
1440
|
+
if (!this.slashingProposerContract) {
|
|
1441
|
+
this.log.error('No slashing proposer contract available');
|
|
1217
1442
|
return false;
|
|
1218
1443
|
}
|
|
1219
|
-
const tallySlashingProposer = this.slashingProposerContract;
|
|
1220
1444
|
const votes = bufferToHex(encodeSlashConsensusVotes(action.votes));
|
|
1221
|
-
const request = await
|
|
1222
|
-
|
|
1445
|
+
const request = await this.slashingProposerContract.buildVoteRequestFromSigner(votes, slotNumber, signer);
|
|
1446
|
+
this.enqueueRequest('vote-offenses', request, {
|
|
1447
|
+
address: this.slashingProposerContract.address.toString(),
|
|
1448
|
+
abi: SlashingProposerAbi,
|
|
1449
|
+
eventName: 'VoteCast'
|
|
1450
|
+
}, slotNumber);
|
|
1223
1451
|
break;
|
|
1224
1452
|
}
|
|
1225
1453
|
case 'execute-slash':
|
|
@@ -1229,13 +1457,16 @@ export class SequencerPublisher {
|
|
|
1229
1457
|
round: action.round,
|
|
1230
1458
|
signerAddress
|
|
1231
1459
|
});
|
|
1232
|
-
if (this.slashingProposerContract
|
|
1233
|
-
this.log.error('
|
|
1460
|
+
if (!this.slashingProposerContract) {
|
|
1461
|
+
this.log.error('No slashing proposer contract available');
|
|
1234
1462
|
return false;
|
|
1235
1463
|
}
|
|
1236
|
-
const
|
|
1237
|
-
|
|
1238
|
-
|
|
1464
|
+
const executeRequest = this.slashingProposerContract.buildExecuteRoundRequest(action.round, action.committees);
|
|
1465
|
+
this.enqueueRequest('execute-slash', executeRequest, {
|
|
1466
|
+
address: this.slashingProposerContract.address.toString(),
|
|
1467
|
+
abi: SlashingProposerAbi,
|
|
1468
|
+
eventName: 'RoundExecuted'
|
|
1469
|
+
}, slotNumber);
|
|
1239
1470
|
break;
|
|
1240
1471
|
}
|
|
1241
1472
|
default:
|
|
@@ -1247,7 +1478,7 @@ export class SequencerPublisher {
|
|
|
1247
1478
|
}
|
|
1248
1479
|
return true;
|
|
1249
1480
|
}
|
|
1250
|
-
/**
|
|
1481
|
+
/** Enqueues a proposal for a checkpoint on L1 */ async enqueueProposeCheckpoint(checkpoint, attestationsAndSigners, attestationsAndSignersSignature, opts = {}) {
|
|
1251
1482
|
const checkpointHeader = checkpoint.header;
|
|
1252
1483
|
const blobFields = checkpoint.toBlobFields();
|
|
1253
1484
|
const blobs = await getBlobsPerL1Block(blobFields);
|
|
@@ -1259,52 +1490,38 @@ export class SequencerPublisher {
|
|
|
1259
1490
|
attestationsAndSignersSignature,
|
|
1260
1491
|
feeAssetPriceModifier: checkpoint.feeAssetPriceModifier
|
|
1261
1492
|
};
|
|
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
1493
|
this.log.verbose(`Enqueuing checkpoint propose transaction`, {
|
|
1279
1494
|
...checkpoint.toCheckpointInfo(),
|
|
1280
|
-
|
|
1495
|
+
txTimeoutAt: opts.txTimeoutAt
|
|
1496
|
+
});
|
|
1497
|
+
await this.addProposeTx(checkpoint, proposeTxArgs, {
|
|
1498
|
+
txTimeoutAt: opts.txTimeoutAt
|
|
1281
1499
|
});
|
|
1282
|
-
await this.addProposeTx(checkpoint, proposeTxArgs, opts, ts);
|
|
1283
1500
|
}
|
|
1284
1501
|
enqueueInvalidateCheckpoint(request, opts = {}) {
|
|
1285
1502
|
if (!request) {
|
|
1286
1503
|
return;
|
|
1287
1504
|
}
|
|
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
1505
|
const { gasUsed, checkpointNumber } = request;
|
|
1291
1506
|
const logData = {
|
|
1292
1507
|
gasUsed,
|
|
1293
1508
|
checkpointNumber,
|
|
1294
|
-
gasLimit,
|
|
1295
1509
|
opts
|
|
1296
1510
|
};
|
|
1297
1511
|
this.log.verbose(`Enqueuing invalidate checkpoint request`, logData);
|
|
1298
1512
|
this.addRequest({
|
|
1299
1513
|
action: `invalidate-by-${request.reason}`,
|
|
1300
1514
|
request: request.request,
|
|
1301
|
-
gasConfig: {
|
|
1302
|
-
gasLimit,
|
|
1515
|
+
gasConfig: opts.txTimeoutAt ? {
|
|
1303
1516
|
txTimeoutAt: opts.txTimeoutAt
|
|
1304
|
-
},
|
|
1517
|
+
} : undefined,
|
|
1305
1518
|
lastValidL2Slot: SlotNumber(this.getCurrentL2Slot() + 2),
|
|
1306
1519
|
checkSuccess: (_req, result)=>{
|
|
1307
|
-
const success = result &&
|
|
1520
|
+
const success = result && extractEventSuccess(result.receipt, {
|
|
1521
|
+
address: this.rollupContract.address,
|
|
1522
|
+
abi: RollupAbi,
|
|
1523
|
+
eventName: 'CheckpointInvalidated'
|
|
1524
|
+
});
|
|
1308
1525
|
if (!success) {
|
|
1309
1526
|
this.log.warn(`Invalidate checkpoint ${request.checkpointNumber} failed`, {
|
|
1310
1527
|
...result,
|
|
@@ -1320,89 +1537,36 @@ export class SequencerPublisher {
|
|
|
1320
1537
|
}
|
|
1321
1538
|
});
|
|
1322
1539
|
}
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
};
|
|
1540
|
+
/**
|
|
1541
|
+
* Dedup-checked enqueue helper for actions that are simulated at bundle-send time rather
|
|
1542
|
+
* than at enqueue time. Validates the (action, slot) dedup key, sets `lastActions`, and
|
|
1543
|
+
* enqueues without a gasLimit so the bundle simulate sets the only gasLimit that matters.
|
|
1544
|
+
*/ enqueueRequest(action, request, eventOpts, slotNumber) {
|
|
1329
1545
|
if (this.lastActions[action] && this.lastActions[action] === slotNumber) {
|
|
1330
1546
|
this.log.debug(`Skipping duplicate action ${action} for slot ${slotNumber}`);
|
|
1331
1547
|
return false;
|
|
1332
1548
|
}
|
|
1333
1549
|
const cachedLastActionSlot = this.lastActions[action];
|
|
1334
1550
|
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);
|
|
1551
|
+
this.log.debug(`Enqueuing ${action}`, {
|
|
1552
|
+
slotNumber
|
|
1553
|
+
});
|
|
1387
1554
|
this.addRequest({
|
|
1388
1555
|
action,
|
|
1389
|
-
request
|
|
1390
|
-
gasConfig: {
|
|
1391
|
-
gasLimit
|
|
1392
|
-
},
|
|
1556
|
+
request,
|
|
1393
1557
|
lastValidL2Slot: slotNumber,
|
|
1394
|
-
checkSuccess: (
|
|
1395
|
-
const success = result && result.receipt
|
|
1558
|
+
checkSuccess: (_request, result)=>{
|
|
1559
|
+
const success = result && extractEventSuccess(result.receipt, eventOpts);
|
|
1396
1560
|
if (!success) {
|
|
1397
1561
|
this.log.warn(`Action ${action} at ${slotNumber} failed`, {
|
|
1398
1562
|
...result,
|
|
1399
|
-
|
|
1563
|
+
slotNumber
|
|
1400
1564
|
});
|
|
1401
1565
|
this.lastActions[action] = cachedLastActionSlot;
|
|
1402
1566
|
} else {
|
|
1403
1567
|
this.log.info(`Action ${action} at ${slotNumber} succeeded`, {
|
|
1404
1568
|
...result,
|
|
1405
|
-
|
|
1569
|
+
slotNumber
|
|
1406
1570
|
});
|
|
1407
1571
|
}
|
|
1408
1572
|
return !!success;
|
|
@@ -1417,13 +1581,14 @@ export class SequencerPublisher {
|
|
|
1417
1581
|
* A call to `restart` is required before you can continue publishing.
|
|
1418
1582
|
*/ interrupt() {
|
|
1419
1583
|
this.interrupted = true;
|
|
1584
|
+
this.interruptibleSleep.interrupt();
|
|
1420
1585
|
this.l1TxUtils.interrupt();
|
|
1421
1586
|
}
|
|
1422
1587
|
/** Restarts the publisher after calling `interrupt`. */ restart() {
|
|
1423
1588
|
this.interrupted = false;
|
|
1424
1589
|
this.l1TxUtils.restart();
|
|
1425
1590
|
}
|
|
1426
|
-
async prepareProposeTx(encodedData
|
|
1591
|
+
async prepareProposeTx(encodedData) {
|
|
1427
1592
|
const kzg = Blob.getViemKzgInstance();
|
|
1428
1593
|
const blobInput = getPrefixedEthBlobCommitments(encodedData.blobs);
|
|
1429
1594
|
this.log.debug('Validating blob input', {
|
|
@@ -1437,7 +1602,11 @@ export class SequencerPublisher {
|
|
|
1437
1602
|
blobEvaluationGas = BigInt(encodedData.blobs.length) * 21_000n;
|
|
1438
1603
|
this.log.debug(`Using fixed blob evaluation gas estimate in fisherman mode: ${blobEvaluationGas}`);
|
|
1439
1604
|
} else {
|
|
1440
|
-
//
|
|
1605
|
+
// We call validateBlobs via estimateGas with real blob+kzg sidecars as a consistency check
|
|
1606
|
+
// that our locally-built blob commitments match the blob data. The bundle simulate at send
|
|
1607
|
+
// time uses eth_simulateV1, which cannot carry blob inputs, so the rollup's on-chain blob
|
|
1608
|
+
// check is forced off there — making this the only pre-flight detector of a commitment/data
|
|
1609
|
+
// mismatch. The returned gas estimate is stashed on the request for the bundle path to read.
|
|
1441
1610
|
blobEvaluationGas = await this.l1TxUtils.estimateGas(this.getSenderAddress().toString(), {
|
|
1442
1611
|
to: this.rollupContract.address,
|
|
1443
1612
|
data: encodeFunctionData({
|
|
@@ -1471,7 +1640,7 @@ export class SequencerPublisher {
|
|
|
1471
1640
|
data: validateBlobsData
|
|
1472
1641
|
},
|
|
1473
1642
|
blobData: encodedData.blobs.map((b)=>toHex(b.data)),
|
|
1474
|
-
l1BlockNumber
|
|
1643
|
+
l1BlockNumber,
|
|
1475
1644
|
error: {
|
|
1476
1645
|
message: viemError.message,
|
|
1477
1646
|
name: viemError.name
|
|
@@ -1481,7 +1650,11 @@ export class SequencerPublisher {
|
|
|
1481
1650
|
'validate-blobs'
|
|
1482
1651
|
],
|
|
1483
1652
|
sender: this.getSenderAddress().toString()
|
|
1484
|
-
}
|
|
1653
|
+
},
|
|
1654
|
+
timing: this.computeTimingInfo(this.getCurrentL2Slot())
|
|
1655
|
+
}, {
|
|
1656
|
+
captureFeeSummary: true,
|
|
1657
|
+
targetSlot: this.getCurrentL2Slot()
|
|
1485
1658
|
});
|
|
1486
1659
|
throw new Error('Failed to validate blobs');
|
|
1487
1660
|
});
|
|
@@ -1500,109 +1673,23 @@ export class SequencerPublisher {
|
|
|
1500
1673
|
encodedData.attestationsAndSignersSignature.toViemSignature(),
|
|
1501
1674
|
blobInput
|
|
1502
1675
|
];
|
|
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
1676
|
const rollupData = encodeFunctionData({
|
|
1518
1677
|
abi: RollupAbi,
|
|
1519
1678
|
functionName: 'propose',
|
|
1520
1679
|
args
|
|
1521
1680
|
});
|
|
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
1681
|
return {
|
|
1595
|
-
|
|
1596
|
-
|
|
1682
|
+
args,
|
|
1683
|
+
blobEvaluationGas,
|
|
1684
|
+
rollupData
|
|
1597
1685
|
};
|
|
1598
1686
|
}
|
|
1599
|
-
async addProposeTx(checkpoint, encodedData, opts = {}
|
|
1687
|
+
async addProposeTx(checkpoint, encodedData, opts = {}) {
|
|
1600
1688
|
const slot = checkpoint.header.slotNumber;
|
|
1601
1689
|
const timer = new Timer();
|
|
1602
1690
|
const kzg = Blob.getViemKzgInstance();
|
|
1603
|
-
const { rollupData,
|
|
1691
|
+
const { rollupData, blobEvaluationGas } = await this.prepareProposeTx(encodedData);
|
|
1604
1692
|
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
1693
|
// Send the blobs to the blob client preemptively. This helps in tests where the sequencer mistakingly thinks that the propose
|
|
1607
1694
|
// 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
1695
|
void Promise.resolve().then(()=>this.blobClient.sendBlobsToFilestore(encodedData.blobs).catch((_err)=>{
|
|
@@ -1616,9 +1703,10 @@ export class SequencerPublisher {
|
|
|
1616
1703
|
},
|
|
1617
1704
|
lastValidL2Slot: checkpoint.header.slotNumber,
|
|
1618
1705
|
gasConfig: {
|
|
1619
|
-
|
|
1620
|
-
gasLimit
|
|
1706
|
+
txTimeoutAt: opts.txTimeoutAt,
|
|
1707
|
+
gasLimit: undefined
|
|
1621
1708
|
},
|
|
1709
|
+
blobEvaluationGas,
|
|
1622
1710
|
blobConfig: {
|
|
1623
1711
|
blobs: encodedData.blobs.map((b)=>b.data),
|
|
1624
1712
|
kzg
|
|
@@ -1628,7 +1716,11 @@ export class SequencerPublisher {
|
|
|
1628
1716
|
return false;
|
|
1629
1717
|
}
|
|
1630
1718
|
const { receipt, stats, errorMsg } = result;
|
|
1631
|
-
const success =
|
|
1719
|
+
const success = extractEventSuccess(receipt, {
|
|
1720
|
+
address: this.rollupContract.address,
|
|
1721
|
+
abi: RollupAbi,
|
|
1722
|
+
eventName: 'CheckpointProposed'
|
|
1723
|
+
});
|
|
1632
1724
|
if (success) {
|
|
1633
1725
|
const endBlock = receipt.blockNumber;
|
|
1634
1726
|
const inclusionBlocks = Number(endBlock - startBlock);
|
|
@@ -1665,4 +1757,8 @@ export class SequencerPublisher {
|
|
|
1665
1757
|
}
|
|
1666
1758
|
});
|
|
1667
1759
|
}
|
|
1760
|
+
/** Returns the timestamp of the next L1 slot boundary after now. */ getNextL1SlotTimestamp() {
|
|
1761
|
+
const l1Constants = this.epochCache.getL1Constants();
|
|
1762
|
+
return getNextL1SlotTimestamp(this.dateProvider.nowInSeconds(), l1Constants);
|
|
1763
|
+
}
|
|
1668
1764
|
}
|