@aztec/sequencer-client 0.0.1-commit.85d7d01 → 0.0.1-commit.8655d4a
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 +282 -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 +53 -30
- package/dest/config.d.ts +28 -5
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +62 -27
- 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 +16 -3
- package/dest/publisher/sequencer-publisher.d.ts +77 -65
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +345 -512
- 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 +506 -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 +54 -11
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_proposal_job.js +776 -227
- 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 +47 -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 +59 -16
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +333 -119
- package/dest/sequencer/timetable.d.ts +17 -3
- package/dest/sequencer/timetable.d.ts.map +1 -1
- package/dest/sequencer/timetable.js +51 -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 +72 -33
- package/src/config.ts +76 -27
- 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 +18 -6
- package/src/publisher/sequencer-publisher.ts +426 -567
- package/src/sequencer/README.md +152 -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 +592 -0
- package/src/sequencer/chain_state_overrides.ts +162 -0
- package/src/sequencer/checkpoint_proposal_job.ts +941 -256
- package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
- package/src/sequencer/checkpoint_voter.ts +1 -12
- package/src/sequencer/events.ts +50 -2
- package/src/sequencer/index.ts +2 -0
- package/src/sequencer/metrics.ts +57 -24
- package/src/sequencer/sequencer.ts +414 -132
- package/src/sequencer/timetable.ts +64 -52
- package/src/sequencer/types.ts +1 -1
- package/src/test/mock_checkpoint_builder.ts +51 -48
- package/src/test/utils.ts +28 -10
|
@@ -370,43 +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';
|
|
382
|
+
import { TimeoutError } from '@aztec/foundation/error';
|
|
383
383
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
384
384
|
import { Signature } from '@aztec/foundation/eth-signature';
|
|
385
385
|
import { createLogger } from '@aztec/foundation/log';
|
|
386
|
-
import {
|
|
386
|
+
import { InterruptibleSleep } from '@aztec/foundation/sleep';
|
|
387
387
|
import { bufferToHex } from '@aztec/foundation/string';
|
|
388
388
|
import { Timer } from '@aztec/foundation/timer';
|
|
389
|
-
import { EmpireBaseAbi, ErrorsAbi, RollupAbi } from '@aztec/l1-artifacts';
|
|
389
|
+
import { EmpireBaseAbi, ErrorsAbi, RollupAbi, SlashingProposerAbi } from '@aztec/l1-artifacts';
|
|
390
390
|
import { encodeSlashConsensusVotes } from '@aztec/slasher';
|
|
391
391
|
import { CommitteeAttestationsAndSigners } from '@aztec/stdlib/block';
|
|
392
|
+
import { getLastL1SlotTimestampForL2Slot, getNextL1SlotTimestamp, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
392
393
|
import { getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
393
|
-
import { encodeFunctionData, keccak256,
|
|
394
|
+
import { encodeFunctionData, keccak256, toHex } from 'viem';
|
|
394
395
|
import { createL1TxFailedStore } from './l1_tx_failed_store/index.js';
|
|
396
|
+
import { SequencerBundleSimulator } from './sequencer-bundle-simulator.js';
|
|
395
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
|
+
}
|
|
396
408
|
export const Actions = [
|
|
397
409
|
'invalidate-by-invalid-attestation',
|
|
398
410
|
'invalidate-by-insufficient-attestations',
|
|
399
411
|
'propose',
|
|
400
412
|
'governance-signal',
|
|
401
|
-
'empire-slashing-signal',
|
|
402
|
-
'create-empire-payload',
|
|
403
|
-
'execute-empire-payload',
|
|
404
413
|
'vote-offenses',
|
|
405
414
|
'execute-slash'
|
|
406
415
|
];
|
|
407
416
|
// Sorting for actions such that invalidations go before proposals, and proposals go before votes
|
|
408
417
|
export const compareActions = (a, b)=>Actions.indexOf(a) - Actions.indexOf(b);
|
|
409
|
-
_dec = trackSpan('SequencerPublisher.sendRequests'), _dec1 = trackSpan('SequencerPublisher.validateBlockHeader')
|
|
418
|
+
_dec = trackSpan('SequencerPublisher.sendRequests'), _dec1 = trackSpan('SequencerPublisher.validateBlockHeader');
|
|
410
419
|
export class SequencerPublisher {
|
|
411
420
|
config;
|
|
412
421
|
static{
|
|
@@ -420,58 +429,60 @@ export class SequencerPublisher {
|
|
|
420
429
|
_dec1,
|
|
421
430
|
2,
|
|
422
431
|
"validateBlockHeader"
|
|
423
|
-
],
|
|
424
|
-
[
|
|
425
|
-
_dec2,
|
|
426
|
-
2,
|
|
427
|
-
"validateCheckpointForSubmission"
|
|
428
432
|
]
|
|
429
433
|
], []));
|
|
430
434
|
}
|
|
431
435
|
interrupted;
|
|
432
436
|
metrics;
|
|
437
|
+
bundleSimulator;
|
|
433
438
|
epochCache;
|
|
434
439
|
failedTxStore;
|
|
435
|
-
|
|
436
|
-
|
|
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;
|
|
437
445
|
lastActions;
|
|
438
|
-
isPayloadEmptyCache;
|
|
439
|
-
payloadProposedCache;
|
|
440
446
|
log;
|
|
441
447
|
ethereumSlotDuration;
|
|
448
|
+
aztecSlotDuration;
|
|
449
|
+
/** Date provider for wall-clock time. */ dateProvider;
|
|
442
450
|
blobClient;
|
|
443
|
-
/**
|
|
451
|
+
/** Optional callback to obtain a replacement publisher when the current one fails to send. */ getNextPublisher;
|
|
444
452
|
/** L1 fee analyzer for fisherman mode */ l1FeeAnalyzer;
|
|
445
453
|
/** Fee asset price oracle for computing price modifiers from Uniswap V4 */ feeAssetPriceOracle;
|
|
446
|
-
|
|
447
|
-
static MULTICALL_OVERHEAD_GAS_GUESS = 5000n;
|
|
448
|
-
// Gas report for VotingWithSigTest shows a max gas of 100k, but we've seen it cost 700k+ in testnet
|
|
449
|
-
static VOTE_GAS_GUESS = 800_000n;
|
|
454
|
+
/** Interruptible sleep used by sendRequestsAt to wait until a target timestamp. */ interruptibleSleep;
|
|
450
455
|
l1TxUtils;
|
|
451
456
|
rollupContract;
|
|
452
457
|
govProposerContract;
|
|
453
458
|
slashingProposerContract;
|
|
454
|
-
slashFactoryContract;
|
|
455
459
|
tracer;
|
|
456
460
|
requests;
|
|
457
461
|
constructor(config, deps){
|
|
458
462
|
this.config = config;
|
|
459
463
|
this.interrupted = (_initProto(this), false);
|
|
460
|
-
this.
|
|
461
|
-
|
|
464
|
+
this.revertDecoderAbi = mergeAbis([
|
|
465
|
+
RollupAbi,
|
|
466
|
+
SlashingProposerAbi,
|
|
467
|
+
EmpireBaseAbi,
|
|
468
|
+
ErrorsAbi
|
|
469
|
+
]);
|
|
462
470
|
this.lastActions = {};
|
|
463
|
-
this.
|
|
464
|
-
this.payloadProposedCache = new Set();
|
|
471
|
+
this.interruptibleSleep = new InterruptibleSleep();
|
|
465
472
|
this.requests = [];
|
|
466
473
|
this.log = deps.log ?? createLogger('sequencer:publisher');
|
|
467
474
|
this.ethereumSlotDuration = BigInt(config.ethereumSlotDuration);
|
|
475
|
+
this.aztecSlotDuration = BigInt(config.aztecSlotDuration);
|
|
476
|
+
this.dateProvider = deps.dateProvider;
|
|
468
477
|
this.epochCache = deps.epochCache;
|
|
469
478
|
this.lastActions = deps.lastActions;
|
|
470
479
|
this.blobClient = deps.blobClient;
|
|
480
|
+
this.dateProvider = deps.dateProvider;
|
|
471
481
|
const telemetry = deps.telemetry ?? getTelemetryClient();
|
|
472
482
|
this.metrics = deps.metrics ?? new SequencerPublisherMetrics(telemetry, 'SequencerPublisher');
|
|
473
483
|
this.tracer = telemetry.getTracer('SequencerPublisher');
|
|
474
484
|
this.l1TxUtils = deps.l1TxUtils;
|
|
485
|
+
this.getNextPublisher = deps.getNextPublisher;
|
|
475
486
|
this.rollupContract = deps.rollupContract;
|
|
476
487
|
this.govProposerContract = deps.governanceProposerContract;
|
|
477
488
|
this.slashingProposerContract = deps.slashingProposerContract;
|
|
@@ -480,15 +491,20 @@ export class SequencerPublisher {
|
|
|
480
491
|
const newSlashingProposer = await this.rollupContract.getSlashingProposer();
|
|
481
492
|
this.slashingProposerContract = newSlashingProposer;
|
|
482
493
|
});
|
|
483
|
-
this.slashFactoryContract = deps.slashFactoryContract;
|
|
484
494
|
// Initialize L1 fee analyzer for fisherman mode
|
|
485
495
|
if (config.fishermanMode) {
|
|
486
|
-
this.l1FeeAnalyzer = new L1FeeAnalyzer(this.l1TxUtils.client, deps.dateProvider,
|
|
496
|
+
this.l1FeeAnalyzer = new L1FeeAnalyzer(this.l1TxUtils.client, deps.dateProvider, this.log.createChild('fee-analyzer'));
|
|
487
497
|
}
|
|
488
498
|
// Initialize fee asset price oracle
|
|
489
|
-
this.feeAssetPriceOracle = new FeeAssetPriceOracle(this.l1TxUtils.client, this.rollupContract,
|
|
499
|
+
this.feeAssetPriceOracle = new FeeAssetPriceOracle(this.l1TxUtils.client, this.rollupContract, this.log.createChild('price-oracle'));
|
|
490
500
|
// Initialize failed L1 tx store (optional, for test networks)
|
|
491
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
|
+
});
|
|
492
508
|
}
|
|
493
509
|
/**
|
|
494
510
|
* Backs up a failed L1 transaction to the configured store for debugging.
|
|
@@ -511,9 +527,13 @@ export class SequencerPublisher {
|
|
|
511
527
|
}
|
|
512
528
|
/**
|
|
513
529
|
* Gets the fee asset price modifier from the oracle.
|
|
514
|
-
*
|
|
515
|
-
|
|
516
|
-
|
|
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);
|
|
517
537
|
}
|
|
518
538
|
getSenderAddress() {
|
|
519
539
|
return this.l1TxUtils.getSenderAddress();
|
|
@@ -523,17 +543,11 @@ export class SequencerPublisher {
|
|
|
523
543
|
*/ getL1FeeAnalyzer() {
|
|
524
544
|
return this.l1FeeAnalyzer;
|
|
525
545
|
}
|
|
526
|
-
/**
|
|
527
|
-
* Sets the proposer address to use for simulations in fisherman mode.
|
|
528
|
-
* @param proposerAddress - The actual proposer's address to use for balance lookups in simulations
|
|
529
|
-
*/ setProposerAddressForSimulation(proposerAddress) {
|
|
530
|
-
this.proposerAddressForSimulation = proposerAddress;
|
|
531
|
-
}
|
|
532
546
|
addRequest(request) {
|
|
533
547
|
this.requests.push(request);
|
|
534
548
|
}
|
|
535
549
|
getCurrentL2Slot() {
|
|
536
|
-
return this.epochCache.
|
|
550
|
+
return this.epochCache.getSlotNow();
|
|
537
551
|
}
|
|
538
552
|
/**
|
|
539
553
|
* Clears all pending requests without sending them.
|
|
@@ -586,11 +600,15 @@ export class SequencerPublisher {
|
|
|
586
600
|
}
|
|
587
601
|
/**
|
|
588
602
|
* Sends all requests that are still valid.
|
|
603
|
+
* @param targetSlot - The target L2 slot for this send. When provided (pipelined path via
|
|
604
|
+
* sendRequestsAt), it is threaded into bundleSimulate so the block.timestamp override
|
|
605
|
+
* matches the slot the propose is built for. When omitted, falls back to
|
|
606
|
+
* getCurrentL2Slot() for the non-pipelined callers in Sequencer.doWork.
|
|
589
607
|
* @returns one of:
|
|
590
608
|
* - A receipt and stats if the tx succeeded
|
|
591
609
|
* - a receipt and errorMsg if it failed on L1
|
|
592
610
|
* - undefined if no valid requests are found OR the tx failed to send.
|
|
593
|
-
*/ async sendRequests() {
|
|
611
|
+
*/ async sendRequests(targetSlot) {
|
|
594
612
|
const requestsToProcess = [
|
|
595
613
|
...this.requests
|
|
596
614
|
];
|
|
@@ -598,10 +616,9 @@ export class SequencerPublisher {
|
|
|
598
616
|
if (this.interrupted || requestsToProcess.length === 0) {
|
|
599
617
|
return undefined;
|
|
600
618
|
}
|
|
601
|
-
const currentL2Slot = this.getCurrentL2Slot();
|
|
619
|
+
const currentL2Slot = targetSlot ?? this.getCurrentL2Slot();
|
|
602
620
|
this.log.debug(`Sending requests on L2 slot ${currentL2Slot}`);
|
|
603
621
|
const validRequests = requestsToProcess.filter((request)=>request.lastValidL2Slot >= currentL2Slot);
|
|
604
|
-
const validActions = validRequests.map((x)=>x.action);
|
|
605
622
|
const expiredActions = requestsToProcess.filter((request)=>request.lastValidL2Slot < currentL2Slot).map((x)=>x.action);
|
|
606
623
|
if (validRequests.length !== requestsToProcess.length) {
|
|
607
624
|
this.log.warn(`Some requests were expired for slot ${currentL2Slot}`, {
|
|
@@ -619,68 +636,53 @@ export class SequencerPublisher {
|
|
|
619
636
|
this.log.debug(`No valid requests to send`);
|
|
620
637
|
return undefined;
|
|
621
638
|
}
|
|
622
|
-
//
|
|
623
|
-
|
|
624
|
-
// See https://github.com/AztecProtocol/aztec-packages/issues/11513
|
|
625
|
-
const gasConfigs = requestsToProcess.filter((request)=>request.gasConfig).map((request)=>request.gasConfig);
|
|
626
|
-
const blobConfigs = requestsToProcess.filter((request)=>request.blobConfig).map((request)=>request.blobConfig);
|
|
627
|
-
if (blobConfigs.length > 1) {
|
|
628
|
-
throw new Error('Multiple blob configs found');
|
|
629
|
-
}
|
|
630
|
-
const blobConfig = blobConfigs[0];
|
|
631
|
-
// Merge gasConfigs. Yields the sum of gasLimits, and the earliest txTimeoutAt, or undefined if no gasConfig sets them.
|
|
632
|
-
const gasLimits = gasConfigs.map((g)=>g?.gasLimit).filter((g)=>g !== undefined);
|
|
633
|
-
let gasLimit = gasLimits.length > 0 ? sumBigint(gasLimits) : undefined; // sum
|
|
634
|
-
// Cap at L1 block gas limit so the node accepts the tx ("gas limit too high" otherwise).
|
|
635
|
-
const maxGas = MAX_L1_TX_LIMIT;
|
|
636
|
-
if (gasLimit !== undefined && gasLimit > maxGas) {
|
|
637
|
-
this.log.debug('Capping bundled tx gas limit to L1 max', {
|
|
638
|
-
requested: gasLimit,
|
|
639
|
-
capped: maxGas
|
|
640
|
-
});
|
|
641
|
-
gasLimit = maxGas;
|
|
642
|
-
}
|
|
639
|
+
// Collect earliest txTimeoutAt across all requests.
|
|
640
|
+
const gasConfigs = validRequests.filter((request)=>request.gasConfig).map((request)=>request.gasConfig);
|
|
643
641
|
const txTimeoutAts = gasConfigs.map((g)=>g?.txTimeoutAt).filter((g)=>g !== undefined);
|
|
644
|
-
const txTimeoutAt = txTimeoutAts.length > 0 ? new Date(Math.min(...txTimeoutAts.map((g)=>g.getTime()))) : undefined;
|
|
645
|
-
const txConfig = {
|
|
646
|
-
gasLimit,
|
|
647
|
-
txTimeoutAt
|
|
648
|
-
};
|
|
642
|
+
const txTimeoutAt = txTimeoutAts.length > 0 ? new Date(Math.min(...txTimeoutAts.map((g)=>g.getTime()))) : undefined;
|
|
649
643
|
// Sort the requests so that proposals always go first
|
|
650
644
|
// This ensures the committee gets precomputed correctly
|
|
651
645
|
validRequests.sort((a, b)=>compareActions(a.action, b.action));
|
|
652
646
|
try {
|
|
653
|
-
//
|
|
654
|
-
const
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
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
|
|
666
|
+
};
|
|
667
667
|
this.log.debug('Forwarding transactions', {
|
|
668
|
-
|
|
668
|
+
requests: requests.map((request)=>request.action),
|
|
669
669
|
txConfig
|
|
670
670
|
});
|
|
671
|
-
const result = await
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
671
|
+
const result = await this.forwardWithPublisherRotation(requests, txConfig, blobConfig);
|
|
672
|
+
if (result === undefined) {
|
|
673
|
+
return undefined;
|
|
674
|
+
}
|
|
675
|
+
const { successfulActions = [], failedActions = [] } = this.callbackBundledTransactions(requests, result);
|
|
676
|
+
const allFailedActions = [
|
|
677
|
+
...failedActions,
|
|
678
|
+
...droppedRequests.map((d)=>d.request.action)
|
|
679
|
+
];
|
|
678
680
|
return {
|
|
679
681
|
result,
|
|
680
682
|
expiredActions,
|
|
681
|
-
sentActions:
|
|
683
|
+
sentActions: requests.map((x)=>x.action),
|
|
682
684
|
successfulActions,
|
|
683
|
-
failedActions
|
|
685
|
+
failedActions: allFailedActions
|
|
684
686
|
};
|
|
685
687
|
} catch (err) {
|
|
686
688
|
const viemError = formatViemError(err);
|
|
@@ -694,103 +696,174 @@ export class SequencerPublisher {
|
|
|
694
696
|
}
|
|
695
697
|
}
|
|
696
698
|
}
|
|
697
|
-
|
|
698
|
-
const
|
|
699
|
-
|
|
700
|
-
this.log.
|
|
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){
|
|
701
716
|
this.backupFailedTx({
|
|
702
|
-
id: keccak256(
|
|
703
|
-
failureType: '
|
|
717
|
+
id: keccak256(req.request.data),
|
|
718
|
+
failureType: 'simulation',
|
|
704
719
|
request: {
|
|
705
|
-
to:
|
|
706
|
-
data:
|
|
720
|
+
to: req.request.to,
|
|
721
|
+
data: req.request.data
|
|
707
722
|
},
|
|
708
|
-
|
|
709
|
-
l1BlockNumber: txContext.l1BlockNumber.toString(),
|
|
723
|
+
l1BlockNumber: l1BlockNumber.toString(),
|
|
710
724
|
error: {
|
|
711
|
-
message:
|
|
712
|
-
name: result.name
|
|
725
|
+
message: 'Bundle entry dropped: action reverted in sim'
|
|
713
726
|
},
|
|
714
727
|
context: {
|
|
715
|
-
actions:
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
to: r.request.to,
|
|
719
|
-
data: r.request.data
|
|
720
|
-
})),
|
|
728
|
+
actions: [
|
|
729
|
+
req.action
|
|
730
|
+
],
|
|
721
731
|
sender: this.getSenderAddress().toString()
|
|
722
732
|
}
|
|
723
733
|
});
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
}
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
/**
|
|
737
|
+
* Forwards transactions via Multicall3, rotating to the next available publisher if a send
|
|
738
|
+
* failure occurs (i.e. the tx never reached the chain).
|
|
739
|
+
* On-chain reverts and simulation errors are returned as-is without rotation.
|
|
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;
|
|
745
|
+
const triedAddresses = [];
|
|
746
|
+
let currentPublisher = this.l1TxUtils;
|
|
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;
|
|
740
753
|
}
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
failureType: 'revert',
|
|
746
|
-
request: {
|
|
747
|
-
to: MULTI_CALL_3_ADDRESS,
|
|
748
|
-
data: txContext.multicallData
|
|
749
|
-
},
|
|
750
|
-
blobData: txContext.blobData,
|
|
751
|
-
l1BlockNumber: result.receipt.blockNumber.toString(),
|
|
752
|
-
receipt: {
|
|
753
|
-
transactionHash: result.receipt.transactionHash,
|
|
754
|
-
blockNumber: result.receipt.blockNumber.toString(),
|
|
755
|
-
gasUsed: (result.receipt.gasUsed ?? 0n).toString(),
|
|
756
|
-
status: 'reverted'
|
|
757
|
-
},
|
|
758
|
-
error: {
|
|
759
|
-
message: result.errorMsg ?? 'Transaction reverted'
|
|
760
|
-
},
|
|
761
|
-
context: {
|
|
762
|
-
actions: failedActions,
|
|
763
|
-
requests: requests.filter((r)=>failedActions.includes(r.action)).map((r)=>({
|
|
764
|
-
action: r.action,
|
|
765
|
-
to: r.request.to,
|
|
766
|
-
data: r.request.data
|
|
767
|
-
})),
|
|
768
|
-
sender: this.getSenderAddress().toString()
|
|
769
|
-
}
|
|
754
|
+
triedAddresses.push(currentPublisher.getSenderAddress());
|
|
755
|
+
try {
|
|
756
|
+
const result = await Multicall3.forward(validRequests.map((r)=>r.request), currentPublisher, txConfigWithGasLimit, blobConfig, {
|
|
757
|
+
gasLimitRequired: true
|
|
770
758
|
});
|
|
759
|
+
this.l1TxUtils = currentPublisher;
|
|
760
|
+
return result;
|
|
761
|
+
} catch (err) {
|
|
762
|
+
if (err instanceof TimeoutError) {
|
|
763
|
+
throw err;
|
|
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
|
+
}
|
|
771
|
+
const viemError = formatViemError(err);
|
|
772
|
+
if (!this.getNextPublisher) {
|
|
773
|
+
this.log.error('Failed to publish bundled transactions', viemError);
|
|
774
|
+
return undefined;
|
|
775
|
+
}
|
|
776
|
+
this.log.warn(`Publisher ${currentPublisher.getSenderAddress()} failed to send, rotating to next publisher`, viemError);
|
|
777
|
+
const nextPublisher = await this.getNextPublisher([
|
|
778
|
+
...triedAddresses
|
|
779
|
+
]);
|
|
780
|
+
if (!nextPublisher) {
|
|
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
|
+
});
|
|
784
|
+
return undefined;
|
|
785
|
+
}
|
|
786
|
+
currentPublisher = nextPublisher;
|
|
771
787
|
}
|
|
772
|
-
return {
|
|
773
|
-
successfulActions,
|
|
774
|
-
failedActions
|
|
775
|
-
};
|
|
776
788
|
}
|
|
777
789
|
}
|
|
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
|
+
const sleepMs = submitAfterMs - this.dateProvider.now();
|
|
805
|
+
if (sleepMs > 0) {
|
|
806
|
+
this.log.debug(`Sleeping ${sleepMs}ms before sending requests`, {
|
|
807
|
+
targetSlot,
|
|
808
|
+
submitAfterMs
|
|
809
|
+
});
|
|
810
|
+
await this.interruptibleSleep.sleep(sleepMs);
|
|
811
|
+
}
|
|
812
|
+
if (this.interrupted) {
|
|
813
|
+
return undefined;
|
|
814
|
+
}
|
|
815
|
+
return this.sendRequests(targetSlot);
|
|
816
|
+
}
|
|
817
|
+
callbackBundledTransactions(requests, result) {
|
|
818
|
+
const actionsListStr = requests.map((r)=>r.action).join(', ');
|
|
819
|
+
this.log.verbose(`Published bundled transactions (${actionsListStr})`, {
|
|
820
|
+
result,
|
|
821
|
+
requests: requests.map((r)=>({
|
|
822
|
+
...r,
|
|
823
|
+
// Avoid logging large blob data
|
|
824
|
+
blobConfig: r.blobConfig ? {
|
|
825
|
+
...r.blobConfig,
|
|
826
|
+
blobs: r.blobConfig.blobs.map((b)=>({
|
|
827
|
+
size: trimmedBytesLength(b)
|
|
828
|
+
}))
|
|
829
|
+
} : undefined
|
|
830
|
+
}))
|
|
831
|
+
});
|
|
832
|
+
const successfulActions = [];
|
|
833
|
+
const failedActions = [];
|
|
834
|
+
for (const request of requests){
|
|
835
|
+
if (request.checkSuccess(request.request, result)) {
|
|
836
|
+
successfulActions.push(request.action);
|
|
837
|
+
} else {
|
|
838
|
+
failedActions.push(request.action);
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
return {
|
|
842
|
+
successfulActions,
|
|
843
|
+
failedActions
|
|
844
|
+
};
|
|
845
|
+
}
|
|
778
846
|
/**
|
|
779
|
-
* @notice Will call `
|
|
847
|
+
* @notice Will call `canProposeAt` to make sure that it is possible to propose
|
|
780
848
|
* @param tipArchive - The archive to check
|
|
781
849
|
* @returns The slot and block number if it is possible to propose, undefined otherwise
|
|
782
|
-
*/
|
|
850
|
+
*/ async canProposeAt(tipArchive, msgSender, simulationOverridesPlan) {
|
|
783
851
|
// TODO: #14291 - should loop through multiple keys to check if any of them can propose
|
|
784
|
-
|
|
852
|
+
// These errors are expected when we cannot actually propose right now — usually because our
|
|
853
|
+
// local view of the chain is ahead of L1 (proposed parent hasn't landed yet, or someone
|
|
854
|
+
// else has just landed the slot, or the archive override doesn't match). We log a warn and
|
|
855
|
+
// skip the proposal; we do NOT treat these as bugs.
|
|
856
|
+
const expectedErrors = [
|
|
785
857
|
'SlotAlreadyInChain',
|
|
786
858
|
'InvalidProposer',
|
|
787
859
|
'InvalidArchive'
|
|
788
860
|
];
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
861
|
+
const pipelined = this.epochCache.isProposerPipeliningEnabled();
|
|
862
|
+
const slotOffset = pipelined ? this.aztecSlotDuration : 0n;
|
|
863
|
+
const nextL1SlotTs = this.getNextL1SlotTimestamp() + slotOffset;
|
|
864
|
+
return this.rollupContract.canProposeAt(tipArchive.toBuffer(), msgSender.toString(), nextL1SlotTs, await buildSimulationOverridesStateOverride(this.rollupContract, simulationOverridesPlan)).catch((err)=>{
|
|
865
|
+
if (err instanceof FormattedViemError && expectedErrors.find((e)=>err.message.includes(e))) {
|
|
866
|
+
this.log.warn(`Failed canProposeAtTime check with ${expectedErrors.find((e)=>err.message.includes(e))}`, {
|
|
794
867
|
error: err.message
|
|
795
868
|
});
|
|
796
869
|
} else {
|
|
@@ -804,22 +877,23 @@ export class SequencerPublisher {
|
|
|
804
877
|
* @dev This is a convenience function that can be used by the sequencer to validate a "partial" header.
|
|
805
878
|
* It will throw if the block header is invalid.
|
|
806
879
|
* @param header - The block header to validate
|
|
807
|
-
*/ async validateBlockHeader(header,
|
|
880
|
+
*/ async validateBlockHeader(header, simulationOverridesPlan) {
|
|
808
881
|
const flags = {
|
|
809
882
|
ignoreDA: true,
|
|
810
883
|
ignoreSignatures: true
|
|
811
884
|
};
|
|
812
885
|
const args = [
|
|
813
886
|
header.toViem(),
|
|
814
|
-
CommitteeAttestationsAndSigners.
|
|
887
|
+
CommitteeAttestationsAndSigners.packAttestations([]),
|
|
815
888
|
[],
|
|
816
889
|
Signature.empty().toViemSignature(),
|
|
817
890
|
`0x${'0'.repeat(64)}`,
|
|
818
891
|
header.blobsHash.toString(),
|
|
819
892
|
flags
|
|
820
893
|
];
|
|
821
|
-
const
|
|
822
|
-
const
|
|
894
|
+
const l1Constants = this.epochCache.getL1Constants();
|
|
895
|
+
const ts = getLastL1SlotTimestampForL2Slot(header.slotNumber, l1Constants);
|
|
896
|
+
const stateOverrides = await buildSimulationOverridesStateOverride(this.rollupContract, simulationOverridesPlan);
|
|
823
897
|
let balance = 0n;
|
|
824
898
|
if (this.config.fishermanMode) {
|
|
825
899
|
// In fisherman mode, we can't know where the proposer is publishing from
|
|
@@ -841,7 +915,7 @@ export class SequencerPublisher {
|
|
|
841
915
|
}),
|
|
842
916
|
from: MULTI_CALL_3_ADDRESS
|
|
843
917
|
}, {
|
|
844
|
-
time: ts
|
|
918
|
+
time: ts
|
|
845
919
|
}, stateOverrides);
|
|
846
920
|
this.log.debug(`Simulated validateHeader`);
|
|
847
921
|
}
|
|
@@ -887,6 +961,7 @@ export class SequencerPublisher {
|
|
|
887
961
|
gasUsed,
|
|
888
962
|
checkpointNumber,
|
|
889
963
|
forcePendingCheckpointNumber: CheckpointNumber(checkpointNumber - 1),
|
|
964
|
+
lastArchive: validationResult.checkpoint.lastArchive,
|
|
890
965
|
reason
|
|
891
966
|
};
|
|
892
967
|
} catch (err) {
|
|
@@ -899,8 +974,8 @@ export class SequencerPublisher {
|
|
|
899
974
|
request,
|
|
900
975
|
error: viemError.message
|
|
901
976
|
});
|
|
902
|
-
const
|
|
903
|
-
if (
|
|
977
|
+
const latestProposedCheckpointNumber = await this.rollupContract.getCheckpointNumber();
|
|
978
|
+
if (latestProposedCheckpointNumber < checkpointNumber) {
|
|
904
979
|
this.log.verbose(`Checkpoint ${checkpointNumber} has already been invalidated`, {
|
|
905
980
|
...logData
|
|
906
981
|
});
|
|
@@ -950,7 +1025,7 @@ export class SequencerPublisher {
|
|
|
950
1025
|
reason
|
|
951
1026
|
};
|
|
952
1027
|
this.log.debug(`Building invalidate checkpoint ${checkpoint.checkpointNumber} request`, logData);
|
|
953
|
-
const attestationsAndSigners =
|
|
1028
|
+
const attestationsAndSigners = CommitteeAttestationsAndSigners.packAttestations(validationResult.attestations);
|
|
954
1029
|
if (reason === 'invalid-attestation') {
|
|
955
1030
|
return this.rollupContract.buildInvalidateBadAttestationRequest(checkpoint.checkpointNumber, attestationsAndSigners, committee, validationResult.invalidIndex);
|
|
956
1031
|
} else if (reason === 'insufficient-attestations') {
|
|
@@ -960,28 +1035,7 @@ export class SequencerPublisher {
|
|
|
960
1035
|
throw new Error(`Unknown reason for invalidation`);
|
|
961
1036
|
}
|
|
962
1037
|
}
|
|
963
|
-
|
|
964
|
-
const ts = BigInt((await this.l1TxUtils.getBlock()).timestamp + this.ethereumSlotDuration);
|
|
965
|
-
const blobFields = checkpoint.toBlobFields();
|
|
966
|
-
const blobs = await getBlobsPerL1Block(blobFields);
|
|
967
|
-
const blobInput = getPrefixedEthBlobCommitments(blobs);
|
|
968
|
-
const args = [
|
|
969
|
-
{
|
|
970
|
-
header: checkpoint.header.toViem(),
|
|
971
|
-
archive: toHex(checkpoint.archive.root.toBuffer()),
|
|
972
|
-
oracleInput: {
|
|
973
|
-
feeAssetPriceModifier: checkpoint.feeAssetPriceModifier
|
|
974
|
-
}
|
|
975
|
-
},
|
|
976
|
-
attestationsAndSigners.getPackedAttestations(),
|
|
977
|
-
attestationsAndSigners.getSigners().map((signer)=>signer.toString()),
|
|
978
|
-
attestationsAndSignersSignature.toViemSignature(),
|
|
979
|
-
blobInput
|
|
980
|
-
];
|
|
981
|
-
await this.simulateProposeTx(args, ts, options);
|
|
982
|
-
return ts;
|
|
983
|
-
}
|
|
984
|
-
async enqueueCastSignalHelper(slotNumber, timestamp, signalType, payload, base, signerAddress, signer) {
|
|
1038
|
+
async enqueueCastSignalHelper(slotNumber, signalType, payload, base, signerAddress, signer) {
|
|
985
1039
|
if (this.lastActions[signalType] && this.lastActions[signalType] === slotNumber) {
|
|
986
1040
|
this.log.debug(`Skipping duplicate vote cast signal ${signalType} for slot ${slotNumber}`);
|
|
987
1041
|
return false;
|
|
@@ -1001,30 +1055,26 @@ export class SequencerPublisher {
|
|
|
1001
1055
|
if (roundInfo.lastSignalSlot >= slotNumber) {
|
|
1002
1056
|
return false;
|
|
1003
1057
|
}
|
|
1004
|
-
if (await
|
|
1058
|
+
if (await base.isPayloadEmpty(payload)) {
|
|
1005
1059
|
this.log.warn(`Skipping vote cast for payload with empty code`);
|
|
1006
1060
|
return false;
|
|
1007
1061
|
}
|
|
1008
|
-
//
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
} catch (err) {
|
|
1022
|
-
this.log.warn(`Failed to check if payload ${payload} was proposed after retries, skipping signal`, err);
|
|
1023
|
-
return false;
|
|
1024
|
-
}
|
|
1062
|
+
// Skip signaling if there is already a live (non-terminal) Governance proposal for this
|
|
1063
|
+
// payload. This is intentionally not cached: a previously-live proposal may transition to
|
|
1064
|
+
// a terminal state (Dropped/Rejected/Expired/Executed), at which point we may want to re-signal
|
|
1065
|
+
// the same payload in a future round.
|
|
1066
|
+
let proposed = false;
|
|
1067
|
+
try {
|
|
1068
|
+
proposed = await base.hasActiveProposalWithPayload(payload.toString());
|
|
1069
|
+
} catch (err) {
|
|
1070
|
+
// We deliberately swallow the error and proceed to signal. Failing closed (skipping the
|
|
1071
|
+
// signal) on transient RPC errors would let a flaky L1 endpoint silence governance
|
|
1072
|
+
// participation entirely; failing open at worst produces a duplicate signal that the
|
|
1073
|
+
// contract will simply count alongside others in the round.
|
|
1074
|
+
this.log.error(`Failed to check if payload ${payload} was already proposed (signalling anyway)`, err);
|
|
1025
1075
|
}
|
|
1026
|
-
if (
|
|
1027
|
-
this.log.info(`Payload ${payload}
|
|
1076
|
+
if (proposed) {
|
|
1077
|
+
this.log.info(`Payload ${payload} has a live governance proposal, stopping signals`);
|
|
1028
1078
|
return false;
|
|
1029
1079
|
}
|
|
1030
1080
|
const cachedLastVote = this.lastActions[signalType];
|
|
@@ -1037,53 +1087,17 @@ export class SequencerPublisher {
|
|
|
1037
1087
|
signer: this.l1TxUtils.client.account?.address,
|
|
1038
1088
|
lastValidL2Slot: slotNumber
|
|
1039
1089
|
});
|
|
1040
|
-
const l1BlockNumber = await this.l1TxUtils.getBlockNumber();
|
|
1041
|
-
try {
|
|
1042
|
-
await this.l1TxUtils.simulate(request, {
|
|
1043
|
-
time: timestamp
|
|
1044
|
-
}, [], mergeAbis([
|
|
1045
|
-
request.abi ?? [],
|
|
1046
|
-
ErrorsAbi
|
|
1047
|
-
]));
|
|
1048
|
-
this.log.debug(`Simulation for ${action} at slot ${slotNumber} succeeded`, {
|
|
1049
|
-
request
|
|
1050
|
-
});
|
|
1051
|
-
} catch (err) {
|
|
1052
|
-
const viemError = formatViemError(err);
|
|
1053
|
-
this.log.error(`Failed simulation for ${action} at slot ${slotNumber} (enqueuing the action anyway)`, viemError);
|
|
1054
|
-
this.backupFailedTx({
|
|
1055
|
-
id: keccak256(request.data),
|
|
1056
|
-
failureType: 'simulation',
|
|
1057
|
-
request: {
|
|
1058
|
-
to: request.to,
|
|
1059
|
-
data: request.data,
|
|
1060
|
-
value: request.value?.toString()
|
|
1061
|
-
},
|
|
1062
|
-
l1BlockNumber: l1BlockNumber.toString(),
|
|
1063
|
-
error: {
|
|
1064
|
-
message: viemError.message,
|
|
1065
|
-
name: viemError.name
|
|
1066
|
-
},
|
|
1067
|
-
context: {
|
|
1068
|
-
actions: [
|
|
1069
|
-
action
|
|
1070
|
-
],
|
|
1071
|
-
slot: slotNumber,
|
|
1072
|
-
sender: this.getSenderAddress().toString()
|
|
1073
|
-
}
|
|
1074
|
-
});
|
|
1075
|
-
// Yes, we enqueue the request anyway, in case there was a bug with the simulation itself
|
|
1076
|
-
}
|
|
1077
1090
|
// TODO(palla/slash): All votes (governance and slashing) should txTimeoutAt at the end of the slot.
|
|
1078
1091
|
this.addRequest({
|
|
1079
|
-
gasConfig: {
|
|
1080
|
-
gasLimit: SequencerPublisher.VOTE_GAS_GUESS
|
|
1081
|
-
},
|
|
1082
1092
|
action,
|
|
1083
1093
|
request,
|
|
1084
1094
|
lastValidL2Slot: slotNumber,
|
|
1085
1095
|
checkSuccess: (_request, result)=>{
|
|
1086
|
-
const success = result &&
|
|
1096
|
+
const success = result && extractEventSuccess(result.receipt, {
|
|
1097
|
+
address: base.address.toString(),
|
|
1098
|
+
abi: EmpireBaseAbi,
|
|
1099
|
+
eventName: 'SignalCast'
|
|
1100
|
+
});
|
|
1087
1101
|
const logData = {
|
|
1088
1102
|
...result,
|
|
1089
1103
|
slotNumber,
|
|
@@ -1102,68 +1116,20 @@ export class SequencerPublisher {
|
|
|
1102
1116
|
});
|
|
1103
1117
|
return true;
|
|
1104
1118
|
}
|
|
1105
|
-
async isPayloadEmpty(payload) {
|
|
1106
|
-
const key = payload.toString();
|
|
1107
|
-
const cached = this.isPayloadEmptyCache.get(key);
|
|
1108
|
-
if (cached) {
|
|
1109
|
-
return cached;
|
|
1110
|
-
}
|
|
1111
|
-
const isEmpty = !await this.l1TxUtils.getCode(payload);
|
|
1112
|
-
this.isPayloadEmptyCache.set(key, isEmpty);
|
|
1113
|
-
return isEmpty;
|
|
1114
|
-
}
|
|
1115
1119
|
/**
|
|
1116
1120
|
* Enqueues a governance castSignal transaction to cast a signal for a given slot number.
|
|
1117
1121
|
* @param slotNumber - The slot number to cast a signal for.
|
|
1118
|
-
* @param timestamp - The timestamp of the slot to cast a signal for.
|
|
1119
1122
|
* @returns True if the signal was successfully enqueued, false otherwise.
|
|
1120
|
-
*/ enqueueGovernanceCastSignal(governancePayload, slotNumber,
|
|
1121
|
-
return this.enqueueCastSignalHelper(slotNumber,
|
|
1123
|
+
*/ enqueueGovernanceCastSignal(governancePayload, slotNumber, signerAddress, signer) {
|
|
1124
|
+
return this.enqueueCastSignalHelper(slotNumber, 'governance-signal', governancePayload, this.govProposerContract, signerAddress, signer);
|
|
1122
1125
|
}
|
|
1123
|
-
/** Enqueues all slashing actions as returned by the slasher client. */ async enqueueSlashingActions(actions, slotNumber,
|
|
1126
|
+
/** Enqueues all slashing actions as returned by the slasher client. */ async enqueueSlashingActions(actions, slotNumber, signerAddress, signer) {
|
|
1124
1127
|
if (actions.length === 0) {
|
|
1125
1128
|
this.log.debug(`No slashing actions to enqueue for slot ${slotNumber}`);
|
|
1126
1129
|
return false;
|
|
1127
1130
|
}
|
|
1128
1131
|
for (const action of actions){
|
|
1129
1132
|
switch(action.type){
|
|
1130
|
-
case 'vote-empire-payload':
|
|
1131
|
-
{
|
|
1132
|
-
if (this.slashingProposerContract?.type !== 'empire') {
|
|
1133
|
-
this.log.error('Cannot vote for empire payload on non-empire slashing contract');
|
|
1134
|
-
break;
|
|
1135
|
-
}
|
|
1136
|
-
this.log.debug(`Enqueuing slashing vote for payload ${action.payload} at slot ${slotNumber}`, {
|
|
1137
|
-
signerAddress
|
|
1138
|
-
});
|
|
1139
|
-
await this.enqueueCastSignalHelper(slotNumber, timestamp, 'empire-slashing-signal', action.payload, this.slashingProposerContract, signerAddress, signer);
|
|
1140
|
-
break;
|
|
1141
|
-
}
|
|
1142
|
-
case 'create-empire-payload':
|
|
1143
|
-
{
|
|
1144
|
-
this.log.debug(`Enqueuing slashing create payload at slot ${slotNumber}`, {
|
|
1145
|
-
slotNumber,
|
|
1146
|
-
signerAddress
|
|
1147
|
-
});
|
|
1148
|
-
const request = this.slashFactoryContract.buildCreatePayloadRequest(action.data);
|
|
1149
|
-
await this.simulateAndEnqueueRequest('create-empire-payload', request, (receipt)=>!!this.slashFactoryContract.tryExtractSlashPayloadCreatedEvent(receipt.logs), slotNumber, timestamp);
|
|
1150
|
-
break;
|
|
1151
|
-
}
|
|
1152
|
-
case 'execute-empire-payload':
|
|
1153
|
-
{
|
|
1154
|
-
this.log.debug(`Enqueuing slashing execute payload at slot ${slotNumber}`, {
|
|
1155
|
-
slotNumber,
|
|
1156
|
-
signerAddress
|
|
1157
|
-
});
|
|
1158
|
-
if (this.slashingProposerContract?.type !== 'empire') {
|
|
1159
|
-
this.log.error('Cannot execute slashing payload on non-empire slashing contract');
|
|
1160
|
-
return false;
|
|
1161
|
-
}
|
|
1162
|
-
const empireSlashingProposer = this.slashingProposerContract;
|
|
1163
|
-
const request = empireSlashingProposer.buildExecuteRoundRequest(action.round);
|
|
1164
|
-
await this.simulateAndEnqueueRequest('execute-empire-payload', request, (receipt)=>!!empireSlashingProposer.tryExtractPayloadSubmittedEvent(receipt.logs), slotNumber, timestamp);
|
|
1165
|
-
break;
|
|
1166
|
-
}
|
|
1167
1133
|
case 'vote-offenses':
|
|
1168
1134
|
{
|
|
1169
1135
|
this.log.debug(`Enqueuing slashing vote for ${action.votes.length} votes at slot ${slotNumber}`, {
|
|
@@ -1172,14 +1138,17 @@ export class SequencerPublisher {
|
|
|
1172
1138
|
votesCount: action.votes.length,
|
|
1173
1139
|
signerAddress
|
|
1174
1140
|
});
|
|
1175
|
-
if (this.slashingProposerContract
|
|
1176
|
-
this.log.error('
|
|
1141
|
+
if (!this.slashingProposerContract) {
|
|
1142
|
+
this.log.error('No slashing proposer contract available');
|
|
1177
1143
|
return false;
|
|
1178
1144
|
}
|
|
1179
|
-
const tallySlashingProposer = this.slashingProposerContract;
|
|
1180
1145
|
const votes = bufferToHex(encodeSlashConsensusVotes(action.votes));
|
|
1181
|
-
const request = await
|
|
1182
|
-
|
|
1146
|
+
const request = await this.slashingProposerContract.buildVoteRequestFromSigner(votes, slotNumber, signer);
|
|
1147
|
+
this.enqueueRequest('vote-offenses', request, {
|
|
1148
|
+
address: this.slashingProposerContract.address.toString(),
|
|
1149
|
+
abi: SlashingProposerAbi,
|
|
1150
|
+
eventName: 'VoteCast'
|
|
1151
|
+
}, slotNumber);
|
|
1183
1152
|
break;
|
|
1184
1153
|
}
|
|
1185
1154
|
case 'execute-slash':
|
|
@@ -1189,13 +1158,16 @@ export class SequencerPublisher {
|
|
|
1189
1158
|
round: action.round,
|
|
1190
1159
|
signerAddress
|
|
1191
1160
|
});
|
|
1192
|
-
if (this.slashingProposerContract
|
|
1193
|
-
this.log.error('
|
|
1161
|
+
if (!this.slashingProposerContract) {
|
|
1162
|
+
this.log.error('No slashing proposer contract available');
|
|
1194
1163
|
return false;
|
|
1195
1164
|
}
|
|
1196
|
-
const
|
|
1197
|
-
|
|
1198
|
-
|
|
1165
|
+
const executeRequest = this.slashingProposerContract.buildExecuteRoundRequest(action.round, action.committees);
|
|
1166
|
+
this.enqueueRequest('execute-slash', executeRequest, {
|
|
1167
|
+
address: this.slashingProposerContract.address.toString(),
|
|
1168
|
+
abi: SlashingProposerAbi,
|
|
1169
|
+
eventName: 'RoundExecuted'
|
|
1170
|
+
}, slotNumber);
|
|
1199
1171
|
break;
|
|
1200
1172
|
}
|
|
1201
1173
|
default:
|
|
@@ -1207,7 +1179,7 @@ export class SequencerPublisher {
|
|
|
1207
1179
|
}
|
|
1208
1180
|
return true;
|
|
1209
1181
|
}
|
|
1210
|
-
/**
|
|
1182
|
+
/** Enqueues a proposal for a checkpoint on L1 */ async enqueueProposeCheckpoint(checkpoint, attestationsAndSigners, attestationsAndSignersSignature, opts = {}) {
|
|
1211
1183
|
const checkpointHeader = checkpoint.header;
|
|
1212
1184
|
const blobFields = checkpoint.toBlobFields();
|
|
1213
1185
|
const blobs = await getBlobsPerL1Block(blobFields);
|
|
@@ -1219,52 +1191,38 @@ export class SequencerPublisher {
|
|
|
1219
1191
|
attestationsAndSignersSignature,
|
|
1220
1192
|
feeAssetPriceModifier: checkpoint.feeAssetPriceModifier
|
|
1221
1193
|
};
|
|
1222
|
-
let ts;
|
|
1223
|
-
try {
|
|
1224
|
-
// @note This will make sure that we are passing the checks for our header ASSUMING that the data is also made available
|
|
1225
|
-
// This means that we can avoid the simulation issues in later checks.
|
|
1226
|
-
// By simulation issue, I mean the fact that the block.timestamp is equal to the last block, not the next, which
|
|
1227
|
-
// make time consistency checks break.
|
|
1228
|
-
// TODO(palla): Check whether we're validating twice, once here and once within addProposeTx, since we call simulateProposeTx in both places.
|
|
1229
|
-
ts = await this.validateCheckpointForSubmission(checkpoint, attestationsAndSigners, attestationsAndSignersSignature, opts);
|
|
1230
|
-
} catch (err) {
|
|
1231
|
-
this.log.error(`Checkpoint validation failed. ${err instanceof Error ? err.message : 'No error message'}`, err, {
|
|
1232
|
-
...checkpoint.getStats(),
|
|
1233
|
-
slotNumber: checkpoint.header.slotNumber,
|
|
1234
|
-
forcePendingCheckpointNumber: opts.forcePendingCheckpointNumber
|
|
1235
|
-
});
|
|
1236
|
-
throw err;
|
|
1237
|
-
}
|
|
1238
1194
|
this.log.verbose(`Enqueuing checkpoint propose transaction`, {
|
|
1239
1195
|
...checkpoint.toCheckpointInfo(),
|
|
1240
|
-
|
|
1196
|
+
txTimeoutAt: opts.txTimeoutAt
|
|
1197
|
+
});
|
|
1198
|
+
await this.addProposeTx(checkpoint, proposeTxArgs, {
|
|
1199
|
+
txTimeoutAt: opts.txTimeoutAt
|
|
1241
1200
|
});
|
|
1242
|
-
await this.addProposeTx(checkpoint, proposeTxArgs, opts, ts);
|
|
1243
1201
|
}
|
|
1244
1202
|
enqueueInvalidateCheckpoint(request, opts = {}) {
|
|
1245
1203
|
if (!request) {
|
|
1246
1204
|
return;
|
|
1247
1205
|
}
|
|
1248
|
-
// We issued the simulation against the rollup contract, so we need to account for the overhead of the multicall3
|
|
1249
|
-
const gasLimit = this.l1TxUtils.bumpGasLimit(BigInt(Math.ceil(Number(request.gasUsed) * 64 / 63)));
|
|
1250
1206
|
const { gasUsed, checkpointNumber } = request;
|
|
1251
1207
|
const logData = {
|
|
1252
1208
|
gasUsed,
|
|
1253
1209
|
checkpointNumber,
|
|
1254
|
-
gasLimit,
|
|
1255
1210
|
opts
|
|
1256
1211
|
};
|
|
1257
1212
|
this.log.verbose(`Enqueuing invalidate checkpoint request`, logData);
|
|
1258
1213
|
this.addRequest({
|
|
1259
1214
|
action: `invalidate-by-${request.reason}`,
|
|
1260
1215
|
request: request.request,
|
|
1261
|
-
gasConfig: {
|
|
1262
|
-
gasLimit,
|
|
1216
|
+
gasConfig: opts.txTimeoutAt ? {
|
|
1263
1217
|
txTimeoutAt: opts.txTimeoutAt
|
|
1264
|
-
},
|
|
1218
|
+
} : undefined,
|
|
1265
1219
|
lastValidL2Slot: SlotNumber(this.getCurrentL2Slot() + 2),
|
|
1266
1220
|
checkSuccess: (_req, result)=>{
|
|
1267
|
-
const success = result &&
|
|
1221
|
+
const success = result && extractEventSuccess(result.receipt, {
|
|
1222
|
+
address: this.rollupContract.address,
|
|
1223
|
+
abi: RollupAbi,
|
|
1224
|
+
eventName: 'CheckpointInvalidated'
|
|
1225
|
+
});
|
|
1268
1226
|
if (!success) {
|
|
1269
1227
|
this.log.warn(`Invalidate checkpoint ${request.checkpointNumber} failed`, {
|
|
1270
1228
|
...result,
|
|
@@ -1280,89 +1238,36 @@ export class SequencerPublisher {
|
|
|
1280
1238
|
}
|
|
1281
1239
|
});
|
|
1282
1240
|
}
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
};
|
|
1241
|
+
/**
|
|
1242
|
+
* Dedup-checked enqueue helper for actions that are simulated at bundle-send time rather
|
|
1243
|
+
* than at enqueue time. Validates the (action, slot) dedup key, sets `lastActions`, and
|
|
1244
|
+
* enqueues without a gasLimit so the bundle simulate sets the only gasLimit that matters.
|
|
1245
|
+
*/ enqueueRequest(action, request, eventOpts, slotNumber) {
|
|
1289
1246
|
if (this.lastActions[action] && this.lastActions[action] === slotNumber) {
|
|
1290
1247
|
this.log.debug(`Skipping duplicate action ${action} for slot ${slotNumber}`);
|
|
1291
1248
|
return false;
|
|
1292
1249
|
}
|
|
1293
1250
|
const cachedLastActionSlot = this.lastActions[action];
|
|
1294
1251
|
this.lastActions[action] = slotNumber;
|
|
1295
|
-
this.log.debug(`
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
const simulateAbi = mergeAbis([
|
|
1299
|
-
request.abi ?? [],
|
|
1300
|
-
ErrorsAbi
|
|
1301
|
-
]);
|
|
1302
|
-
try {
|
|
1303
|
-
({ gasUsed } = await this.l1TxUtils.simulate(request, {
|
|
1304
|
-
time: timestamp
|
|
1305
|
-
}, [], simulateAbi)); // TODO(palla/slash): Check the timestamp logic
|
|
1306
|
-
this.log.verbose(`Simulation for ${action} succeeded`, {
|
|
1307
|
-
...logData,
|
|
1308
|
-
request,
|
|
1309
|
-
gasUsed
|
|
1310
|
-
});
|
|
1311
|
-
} catch (err) {
|
|
1312
|
-
const viemError = formatViemError(err, simulateAbi);
|
|
1313
|
-
this.log.error(`Simulation for ${action} at ${slotNumber} failed`, viemError, logData);
|
|
1314
|
-
this.backupFailedTx({
|
|
1315
|
-
id: keccak256(request.data),
|
|
1316
|
-
failureType: 'simulation',
|
|
1317
|
-
request: {
|
|
1318
|
-
to: request.to,
|
|
1319
|
-
data: request.data,
|
|
1320
|
-
value: request.value?.toString()
|
|
1321
|
-
},
|
|
1322
|
-
l1BlockNumber: l1BlockNumber.toString(),
|
|
1323
|
-
error: {
|
|
1324
|
-
message: viemError.message,
|
|
1325
|
-
name: viemError.name
|
|
1326
|
-
},
|
|
1327
|
-
context: {
|
|
1328
|
-
actions: [
|
|
1329
|
-
action
|
|
1330
|
-
],
|
|
1331
|
-
slot: slotNumber,
|
|
1332
|
-
sender: this.getSenderAddress().toString()
|
|
1333
|
-
}
|
|
1334
|
-
});
|
|
1335
|
-
return false;
|
|
1336
|
-
}
|
|
1337
|
-
// We issued the simulation against the rollup contract, so we need to account for the overhead of the multicall3
|
|
1338
|
-
const gasLimit = this.l1TxUtils.bumpGasLimit(BigInt(Math.ceil(Number(gasUsed) * 64 / 63)));
|
|
1339
|
-
logData.gasLimit = gasLimit;
|
|
1340
|
-
// Store the ABI used for simulation on the request so Multicall3.forward can decode errors
|
|
1341
|
-
// when the tx is sent and a revert is diagnosed via simulation.
|
|
1342
|
-
const requestWithAbi = {
|
|
1343
|
-
...request,
|
|
1344
|
-
abi: simulateAbi
|
|
1345
|
-
};
|
|
1346
|
-
this.log.debug(`Enqueuing ${action}`, logData);
|
|
1252
|
+
this.log.debug(`Enqueuing ${action}`, {
|
|
1253
|
+
slotNumber
|
|
1254
|
+
});
|
|
1347
1255
|
this.addRequest({
|
|
1348
1256
|
action,
|
|
1349
|
-
request
|
|
1350
|
-
gasConfig: {
|
|
1351
|
-
gasLimit
|
|
1352
|
-
},
|
|
1257
|
+
request,
|
|
1353
1258
|
lastValidL2Slot: slotNumber,
|
|
1354
|
-
checkSuccess: (
|
|
1355
|
-
const success = result && result.receipt
|
|
1259
|
+
checkSuccess: (_request, result)=>{
|
|
1260
|
+
const success = result && extractEventSuccess(result.receipt, eventOpts);
|
|
1356
1261
|
if (!success) {
|
|
1357
1262
|
this.log.warn(`Action ${action} at ${slotNumber} failed`, {
|
|
1358
1263
|
...result,
|
|
1359
|
-
|
|
1264
|
+
slotNumber
|
|
1360
1265
|
});
|
|
1361
1266
|
this.lastActions[action] = cachedLastActionSlot;
|
|
1362
1267
|
} else {
|
|
1363
1268
|
this.log.info(`Action ${action} at ${slotNumber} succeeded`, {
|
|
1364
1269
|
...result,
|
|
1365
|
-
|
|
1270
|
+
slotNumber
|
|
1366
1271
|
});
|
|
1367
1272
|
}
|
|
1368
1273
|
return !!success;
|
|
@@ -1377,13 +1282,14 @@ export class SequencerPublisher {
|
|
|
1377
1282
|
* A call to `restart` is required before you can continue publishing.
|
|
1378
1283
|
*/ interrupt() {
|
|
1379
1284
|
this.interrupted = true;
|
|
1285
|
+
this.interruptibleSleep.interrupt();
|
|
1380
1286
|
this.l1TxUtils.interrupt();
|
|
1381
1287
|
}
|
|
1382
1288
|
/** Restarts the publisher after calling `interrupt`. */ restart() {
|
|
1383
1289
|
this.interrupted = false;
|
|
1384
1290
|
this.l1TxUtils.restart();
|
|
1385
1291
|
}
|
|
1386
|
-
async prepareProposeTx(encodedData
|
|
1292
|
+
async prepareProposeTx(encodedData) {
|
|
1387
1293
|
const kzg = Blob.getViemKzgInstance();
|
|
1388
1294
|
const blobInput = getPrefixedEthBlobCommitments(encodedData.blobs);
|
|
1389
1295
|
this.log.debug('Validating blob input', {
|
|
@@ -1397,7 +1303,11 @@ export class SequencerPublisher {
|
|
|
1397
1303
|
blobEvaluationGas = BigInt(encodedData.blobs.length) * 21_000n;
|
|
1398
1304
|
this.log.debug(`Using fixed blob evaluation gas estimate in fisherman mode: ${blobEvaluationGas}`);
|
|
1399
1305
|
} else {
|
|
1400
|
-
//
|
|
1306
|
+
// We call validateBlobs via estimateGas with real blob+kzg sidecars as a consistency check
|
|
1307
|
+
// that our locally-built blob commitments match the blob data. The bundle simulate at send
|
|
1308
|
+
// time uses eth_simulateV1, which cannot carry blob inputs, so the rollup's on-chain blob
|
|
1309
|
+
// check is forced off there — making this the only pre-flight detector of a commitment/data
|
|
1310
|
+
// mismatch. The returned gas estimate is stashed on the request for the bundle path to read.
|
|
1401
1311
|
blobEvaluationGas = await this.l1TxUtils.estimateGas(this.getSenderAddress().toString(), {
|
|
1402
1312
|
to: this.rollupContract.address,
|
|
1403
1313
|
data: encodeFunctionData({
|
|
@@ -1460,109 +1370,23 @@ export class SequencerPublisher {
|
|
|
1460
1370
|
encodedData.attestationsAndSignersSignature.toViemSignature(),
|
|
1461
1371
|
blobInput
|
|
1462
1372
|
];
|
|
1463
|
-
const { rollupData, simulationResult } = await this.simulateProposeTx(args, timestamp, options);
|
|
1464
|
-
return {
|
|
1465
|
-
args,
|
|
1466
|
-
blobEvaluationGas,
|
|
1467
|
-
rollupData,
|
|
1468
|
-
simulationResult
|
|
1469
|
-
};
|
|
1470
|
-
}
|
|
1471
|
-
/**
|
|
1472
|
-
* Simulates the propose tx with eth_simulateV1
|
|
1473
|
-
* @param args - The propose tx args
|
|
1474
|
-
* @param timestamp - The timestamp to simulate proposal at
|
|
1475
|
-
* @returns The simulation result
|
|
1476
|
-
*/ async simulateProposeTx(args, timestamp, options) {
|
|
1477
1373
|
const rollupData = encodeFunctionData({
|
|
1478
1374
|
abi: RollupAbi,
|
|
1479
1375
|
functionName: 'propose',
|
|
1480
1376
|
args
|
|
1481
1377
|
});
|
|
1482
|
-
// override the pending checkpoint number if requested
|
|
1483
|
-
const forcePendingCheckpointNumberStateDiff = (options.forcePendingCheckpointNumber !== undefined ? await this.rollupContract.makePendingCheckpointNumberOverride(options.forcePendingCheckpointNumber) : []).flatMap((override)=>override.stateDiff ?? []);
|
|
1484
|
-
const stateOverrides = [
|
|
1485
|
-
{
|
|
1486
|
-
address: this.rollupContract.address,
|
|
1487
|
-
// @note we override checkBlob to false since blobs are not part simulate()
|
|
1488
|
-
stateDiff: [
|
|
1489
|
-
{
|
|
1490
|
-
slot: toPaddedHex(RollupContract.checkBlobStorageSlot, true),
|
|
1491
|
-
value: toPaddedHex(0n, true)
|
|
1492
|
-
},
|
|
1493
|
-
...forcePendingCheckpointNumberStateDiff
|
|
1494
|
-
]
|
|
1495
|
-
}
|
|
1496
|
-
];
|
|
1497
|
-
// In fisherman mode, simulate as the proposer but with sufficient balance
|
|
1498
|
-
if (this.proposerAddressForSimulation) {
|
|
1499
|
-
stateOverrides.push({
|
|
1500
|
-
address: this.proposerAddressForSimulation.toString(),
|
|
1501
|
-
balance: 10n * WEI_CONST * WEI_CONST
|
|
1502
|
-
});
|
|
1503
|
-
}
|
|
1504
|
-
const l1BlockNumber = await this.l1TxUtils.getBlockNumber();
|
|
1505
|
-
const simulationResult = await this.l1TxUtils.simulate({
|
|
1506
|
-
to: this.rollupContract.address,
|
|
1507
|
-
data: rollupData,
|
|
1508
|
-
gas: MAX_L1_TX_LIMIT,
|
|
1509
|
-
...this.proposerAddressForSimulation && {
|
|
1510
|
-
from: this.proposerAddressForSimulation.toString()
|
|
1511
|
-
}
|
|
1512
|
-
}, {
|
|
1513
|
-
// @note we add 1n to the timestamp because geth implementation doesn't like simulation timestamp to be equal to the current block timestamp
|
|
1514
|
-
time: timestamp + 1n,
|
|
1515
|
-
// @note reth should have a 30m gas limit per block but throws errors that this tx is beyond limit so we increase here
|
|
1516
|
-
gasLimit: MAX_L1_TX_LIMIT * 2n
|
|
1517
|
-
}, stateOverrides, RollupAbi, {
|
|
1518
|
-
// @note fallback gas estimate to use if the node doesn't support simulation API
|
|
1519
|
-
fallbackGasEstimate: MAX_L1_TX_LIMIT
|
|
1520
|
-
}).catch((err)=>{
|
|
1521
|
-
// In fisherman mode, we expect ValidatorSelection__MissingProposerSignature since fisherman doesn't have proposer signature
|
|
1522
|
-
const viemError = formatViemError(err);
|
|
1523
|
-
if (this.config.fishermanMode && viemError.message?.includes('ValidatorSelection__MissingProposerSignature')) {
|
|
1524
|
-
this.log.debug(`Ignoring expected ValidatorSelection__MissingProposerSignature error in fisherman mode`);
|
|
1525
|
-
// Return a minimal simulation result with the fallback gas estimate
|
|
1526
|
-
return {
|
|
1527
|
-
gasUsed: MAX_L1_TX_LIMIT,
|
|
1528
|
-
logs: []
|
|
1529
|
-
};
|
|
1530
|
-
}
|
|
1531
|
-
this.log.error(`Failed to simulate propose tx`, viemError);
|
|
1532
|
-
this.backupFailedTx({
|
|
1533
|
-
id: keccak256(rollupData),
|
|
1534
|
-
failureType: 'simulation',
|
|
1535
|
-
request: {
|
|
1536
|
-
to: this.rollupContract.address,
|
|
1537
|
-
data: rollupData
|
|
1538
|
-
},
|
|
1539
|
-
l1BlockNumber: l1BlockNumber.toString(),
|
|
1540
|
-
error: {
|
|
1541
|
-
message: viemError.message,
|
|
1542
|
-
name: viemError.name
|
|
1543
|
-
},
|
|
1544
|
-
context: {
|
|
1545
|
-
actions: [
|
|
1546
|
-
'propose'
|
|
1547
|
-
],
|
|
1548
|
-
slot: Number(args[0].header.slotNumber),
|
|
1549
|
-
sender: this.getSenderAddress().toString()
|
|
1550
|
-
}
|
|
1551
|
-
});
|
|
1552
|
-
throw err;
|
|
1553
|
-
});
|
|
1554
1378
|
return {
|
|
1555
|
-
|
|
1556
|
-
|
|
1379
|
+
args,
|
|
1380
|
+
blobEvaluationGas,
|
|
1381
|
+
rollupData
|
|
1557
1382
|
};
|
|
1558
1383
|
}
|
|
1559
|
-
async addProposeTx(checkpoint, encodedData, opts = {}
|
|
1384
|
+
async addProposeTx(checkpoint, encodedData, opts = {}) {
|
|
1560
1385
|
const slot = checkpoint.header.slotNumber;
|
|
1561
1386
|
const timer = new Timer();
|
|
1562
1387
|
const kzg = Blob.getViemKzgInstance();
|
|
1563
|
-
const { rollupData,
|
|
1388
|
+
const { rollupData, blobEvaluationGas } = await this.prepareProposeTx(encodedData);
|
|
1564
1389
|
const startBlock = await this.l1TxUtils.getBlockNumber();
|
|
1565
|
-
const gasLimit = this.l1TxUtils.bumpGasLimit(BigInt(Math.ceil(Number(simulationResult.gasUsed) * 64 / 63)) + blobEvaluationGas + SequencerPublisher.MULTICALL_OVERHEAD_GAS_GUESS);
|
|
1566
1390
|
// Send the blobs to the blob client preemptively. This helps in tests where the sequencer mistakingly thinks that the propose
|
|
1567
1391
|
// tx fails but it does get mined. We make sure that the blobs are sent to the blob client regardless of the tx outcome.
|
|
1568
1392
|
void Promise.resolve().then(()=>this.blobClient.sendBlobsToFilestore(encodedData.blobs).catch((_err)=>{
|
|
@@ -1576,9 +1400,10 @@ export class SequencerPublisher {
|
|
|
1576
1400
|
},
|
|
1577
1401
|
lastValidL2Slot: checkpoint.header.slotNumber,
|
|
1578
1402
|
gasConfig: {
|
|
1579
|
-
|
|
1580
|
-
gasLimit
|
|
1403
|
+
txTimeoutAt: opts.txTimeoutAt,
|
|
1404
|
+
gasLimit: undefined
|
|
1581
1405
|
},
|
|
1406
|
+
blobEvaluationGas,
|
|
1582
1407
|
blobConfig: {
|
|
1583
1408
|
blobs: encodedData.blobs.map((b)=>b.data),
|
|
1584
1409
|
kzg
|
|
@@ -1588,7 +1413,11 @@ export class SequencerPublisher {
|
|
|
1588
1413
|
return false;
|
|
1589
1414
|
}
|
|
1590
1415
|
const { receipt, stats, errorMsg } = result;
|
|
1591
|
-
const success =
|
|
1416
|
+
const success = extractEventSuccess(receipt, {
|
|
1417
|
+
address: this.rollupContract.address,
|
|
1418
|
+
abi: RollupAbi,
|
|
1419
|
+
eventName: 'CheckpointProposed'
|
|
1420
|
+
});
|
|
1592
1421
|
if (success) {
|
|
1593
1422
|
const endBlock = receipt.blockNumber;
|
|
1594
1423
|
const inclusionBlocks = Number(endBlock - startBlock);
|
|
@@ -1625,4 +1454,8 @@ export class SequencerPublisher {
|
|
|
1625
1454
|
}
|
|
1626
1455
|
});
|
|
1627
1456
|
}
|
|
1457
|
+
/** Returns the timestamp of the next L1 slot boundary after now. */ getNextL1SlotTimestamp() {
|
|
1458
|
+
const l1Constants = this.epochCache.getL1Constants();
|
|
1459
|
+
return getNextL1SlotTimestamp(this.dateProvider.nowInSeconds(), l1Constants);
|
|
1460
|
+
}
|
|
1628
1461
|
}
|