@aztec/sequencer-client 0.0.1-commit.42ee6df9b → 0.0.1-commit.431c48d
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +283 -21
- package/dest/client/sequencer-client.d.ts +20 -5
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +26 -22
- package/dest/config.d.ts +13 -4
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +67 -26
- 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 +7 -26
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +6 -67
- package/dest/global_variable_builder/index.d.ts +3 -1
- 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 +7 -3
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +13 -3
- package/dest/publisher/l1_to_l2_messaging.d.ts +21 -0
- package/dest/publisher/l1_to_l2_messaging.d.ts.map +1 -0
- package/dest/publisher/l1_to_l2_messaging.js +70 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +3 -4
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -1
- package/dest/publisher/sequencer-bundle-simulator.d.ts +96 -0
- package/dest/publisher/sequencer-bundle-simulator.d.ts.map +1 -0
- package/dest/publisher/sequencer-bundle-simulator.js +198 -0
- package/dest/publisher/sequencer-publisher-factory.d.ts +1 -3
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-factory.js +0 -1
- package/dest/publisher/sequencer-publisher.d.ts +65 -70
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +413 -559
- package/dest/publisher/write_json.d.ts +11 -0
- package/dest/publisher/write_json.d.ts.map +1 -0
- package/dest/publisher/write_json.js +57 -0
- package/dest/sequencer/automine/automine_factory.d.ts +56 -0
- package/dest/sequencer/automine/automine_factory.d.ts.map +1 -0
- package/dest/sequencer/automine/automine_factory.js +85 -0
- package/dest/sequencer/automine/automine_sequencer.d.ts +189 -0
- package/dest/sequencer/automine/automine_sequencer.d.ts.map +1 -0
- package/dest/sequencer/automine/automine_sequencer.js +696 -0
- package/dest/sequencer/automine/index.d.ts +3 -0
- package/dest/sequencer/automine/index.d.ts.map +1 -0
- package/dest/sequencer/automine/index.js +2 -0
- package/dest/sequencer/checkpoint_proposal_job.d.ts +67 -36
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_proposal_job.js +705 -256
- package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts +34 -0
- package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_proposal_job_metrics.js +72 -0
- package/dest/sequencer/errors.d.ts +1 -8
- package/dest/sequencer/errors.d.ts.map +1 -1
- package/dest/sequencer/errors.js +0 -9
- package/dest/sequencer/events.d.ts +61 -5
- package/dest/sequencer/events.d.ts.map +1 -1
- package/dest/sequencer/metrics.d.ts +10 -11
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +34 -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 +147 -33
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +543 -180
- 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/utils.d.ts +15 -1
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +25 -7
- package/package.json +28 -27
- package/src/client/sequencer-client.ts +37 -27
- package/src/config.ts +79 -26
- 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 +11 -91
- package/src/global_variable_builder/index.ts +2 -0
- package/src/publisher/config.ts +30 -7
- package/src/publisher/l1_to_l2_messaging.ts +85 -0
- package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +3 -1
- package/src/publisher/sequencer-bundle-simulator.ts +254 -0
- package/src/publisher/sequencer-publisher-factory.ts +0 -3
- package/src/publisher/sequencer-publisher.ts +458 -622
- package/src/publisher/write_json.ts +78 -0
- package/src/sequencer/automine/README.md +60 -0
- package/src/sequencer/automine/automine_factory.ts +152 -0
- package/src/sequencer/automine/automine_sequencer.ts +800 -0
- package/src/sequencer/automine/index.ts +6 -0
- package/src/sequencer/checkpoint_proposal_job.ts +823 -316
- package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
- package/src/sequencer/errors.ts +0 -15
- package/src/sequencer/events.ts +66 -5
- package/src/sequencer/metrics.ts +49 -25
- package/src/sequencer/requests_tracker.ts +43 -0
- package/src/sequencer/sequencer.ts +607 -206
- package/src/sequencer/types.ts +1 -1
- package/src/test/index.ts +2 -2
- 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/README.md +0 -531
- package/src/sequencer/timetable.ts +0 -283
|
@@ -372,29 +372,31 @@ function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
|
|
|
372
372
|
}
|
|
373
373
|
var _dec, _dec1, _dec2, _dec3, _initProto;
|
|
374
374
|
import { getKzg } from '@aztec/blob-lib';
|
|
375
|
-
import {
|
|
375
|
+
import { PROPOSER_PIPELINING_SLOT_OFFSET } from '@aztec/epoch-cache';
|
|
376
376
|
import { NoCommitteeError } from '@aztec/ethereum/contracts';
|
|
377
|
-
import {
|
|
377
|
+
import { CheckpointNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
378
378
|
import { merge, omit, pick } from '@aztec/foundation/collection';
|
|
379
|
-
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
380
379
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
381
380
|
import { createLogger } from '@aztec/foundation/log';
|
|
382
381
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
383
|
-
import {
|
|
382
|
+
import { buildCheckpointSimulationOverridesPlan } from '@aztec/stdlib/checkpoint';
|
|
383
|
+
import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
|
|
384
|
+
import { MIN_PER_BLOCK_ALLOCATION_MULTIPLIER, MIN_PER_BLOCK_DA_ALLOCATION_MULTIPLIER, computeNetworkTxGasLimits } from '@aztec/stdlib/gas';
|
|
384
385
|
import { SequencerConfigSchema } from '@aztec/stdlib/interfaces/server';
|
|
385
386
|
import { pickFromSchema } from '@aztec/stdlib/schemas';
|
|
386
|
-
import {
|
|
387
|
+
import { buildProposerTimetable } from '@aztec/stdlib/timetable';
|
|
387
388
|
import { Attributes, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
388
389
|
import EventEmitter from 'node:events';
|
|
389
390
|
import { DefaultSequencerConfig } from '../config.js';
|
|
390
391
|
import { CheckpointProposalJob } from './checkpoint_proposal_job.js';
|
|
392
|
+
import { CheckpointProposalJobMetrics } from './checkpoint_proposal_job_metrics.js';
|
|
391
393
|
import { CheckpointVoter } from './checkpoint_voter.js';
|
|
392
|
-
import { SequencerInterruptedError
|
|
394
|
+
import { SequencerInterruptedError } from './errors.js';
|
|
393
395
|
import { SequencerMetrics } from './metrics.js';
|
|
394
|
-
import {
|
|
396
|
+
import { RequestsTracker } from './requests_tracker.js';
|
|
395
397
|
import { SequencerState } from './utils.js';
|
|
396
398
|
export { SequencerState };
|
|
397
|
-
_dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpointProposal'), _dec2 = trackSpan('
|
|
399
|
+
_dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpointProposal'), _dec2 = trackSpan('Sequencer.tryVoteAndPruneWhenCannotBuild', ({ slot })=>({
|
|
398
400
|
[Attributes.SLOT_NUMBER]: slot
|
|
399
401
|
})), _dec3 = trackSpan('Sequencer.tryVoteWhenEscapeHatchOpen', ({ slot })=>({
|
|
400
402
|
[Attributes.SLOT_NUMBER]: slot
|
|
@@ -437,7 +439,7 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
437
439
|
[
|
|
438
440
|
_dec2,
|
|
439
441
|
2,
|
|
440
|
-
"
|
|
442
|
+
"tryVoteAndPruneWhenCannotBuild"
|
|
441
443
|
],
|
|
442
444
|
[
|
|
443
445
|
_dec3,
|
|
@@ -448,41 +450,161 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
448
450
|
}
|
|
449
451
|
runningPromise;
|
|
450
452
|
state;
|
|
453
|
+
stateSlotNumber;
|
|
454
|
+
/** Wall-clock time (ms, via the date provider) at which the current state was entered. */ stateEnteredAtMs;
|
|
451
455
|
metrics;
|
|
452
|
-
|
|
456
|
+
checkpointProposalJobMetrics;
|
|
457
|
+
stateLog;
|
|
458
|
+
/** The last slot for which we attempted to perform our fallback duties (votes and/or prune) with degraded block production */ lastSlotForFallbackAction;
|
|
459
|
+
/** The (checkpoint, slot) of the last invalidation request we successfully simulated, to prevent
|
|
460
|
+
* re-simulating and re-submitting the same invalidation across the many ticks within a single slot. */ lastInvalidationAttempt;
|
|
453
461
|
/** The last slot for which we logged "no committee" warning, to avoid spam */ lastSlotForNoCommitteeWarning;
|
|
454
462
|
/** The last slot for which we triggered a checkpoint proposal job, to prevent duplicate attempts. */ lastSlotForCheckpointProposalJob;
|
|
455
463
|
/** Last successful checkpoint proposed */ lastCheckpointProposed;
|
|
456
464
|
/** The last epoch for which we logged strategy comparison in fisherman mode. */ lastEpochForStrategyComparison;
|
|
457
465
|
/** The last checkpoint proposal job, tracked so we can await its pending L1 submission during shutdown. */ lastCheckpointProposalJob;
|
|
458
|
-
/**
|
|
466
|
+
/**
|
|
467
|
+
* In-flight fire-and-forget requests that {@link stop} interrupts and drains, and {@link pause} awaits
|
|
468
|
+
* untouched: the checkpoint proposal jobs' backgrounded L1 submissions (each job is handed this shared
|
|
469
|
+
* tracker) plus the sequencer's own fallback submissions (votes/prune when we cannot build, or
|
|
470
|
+
* escape-hatch votes). Each fallback send is gated by its wrapper publisher's interruptible target-slot
|
|
471
|
+
* sleep; the tracked interrupt wakes that sleep so the send short-circuits without publishing. A wrapper
|
|
472
|
+
* is created for a single send and is never restarted, so once interrupted its sleeper can never publish
|
|
473
|
+
* a stale-slot tx, even after the pooled publishers are restarted by a later {@link start}.
|
|
474
|
+
*/ pendingRequests;
|
|
475
|
+
/** Proposer schedule and block sub-slot timetable for the sequencer, rebuilt on every config update. */ timetable;
|
|
459
476
|
/** Config for the sequencer */ config;
|
|
477
|
+
signatureContext;
|
|
460
478
|
constructor(publisherFactory, validatorClient, globalsBuilder, p2pClient, worldState, slasherClient, l2BlockSource, l1ToL2MessageSource, checkpointsBuilder, l1Constants, dateProvider, epochCache, rollupContract, config, telemetry = getTelemetryClient(), log = createLogger('sequencer')){
|
|
461
|
-
super(), this.publisherFactory = publisherFactory, this.validatorClient = validatorClient, this.globalsBuilder = globalsBuilder, this.p2pClient = p2pClient, this.worldState = worldState, this.slasherClient = slasherClient, this.l2BlockSource = l2BlockSource, this.l1ToL2MessageSource = l1ToL2MessageSource, this.checkpointsBuilder = checkpointsBuilder, this.l1Constants = l1Constants, this.dateProvider = dateProvider, this.epochCache = epochCache, this.rollupContract = rollupContract, this.telemetry = telemetry, this.log = log, this.state = (_initProto(this), SequencerState.STOPPED), this.config = DefaultSequencerConfig;
|
|
479
|
+
super(), this.publisherFactory = publisherFactory, this.validatorClient = validatorClient, this.globalsBuilder = globalsBuilder, this.p2pClient = p2pClient, this.worldState = worldState, this.slasherClient = slasherClient, this.l2BlockSource = l2BlockSource, this.l1ToL2MessageSource = l1ToL2MessageSource, this.checkpointsBuilder = checkpointsBuilder, this.l1Constants = l1Constants, this.dateProvider = dateProvider, this.epochCache = epochCache, this.rollupContract = rollupContract, this.telemetry = telemetry, this.log = log, this.state = (_initProto(this), SequencerState.STOPPED), this.pendingRequests = new RequestsTracker(), this.config = DefaultSequencerConfig;
|
|
480
|
+
this.stateLog = log.createChild('state');
|
|
481
|
+
this.stateEnteredAtMs = this.dateProvider.now();
|
|
462
482
|
// Add [FISHERMAN] prefix to logger if in fisherman mode
|
|
463
483
|
if (config.fishermanMode) {
|
|
464
484
|
this.log = log.createChild('[FISHERMAN]');
|
|
465
485
|
}
|
|
486
|
+
this.signatureContext = {
|
|
487
|
+
chainId: config.l1ChainId,
|
|
488
|
+
rollupAddress: config.rollupAddress
|
|
489
|
+
};
|
|
466
490
|
this.metrics = new SequencerMetrics(telemetry, this.rollupContract, 'Sequencer');
|
|
491
|
+
this.checkpointProposalJobMetrics = new CheckpointProposalJobMetrics(telemetry);
|
|
467
492
|
this.updateConfig(config);
|
|
468
493
|
}
|
|
469
|
-
/**
|
|
494
|
+
/**
|
|
495
|
+
* Updates sequencer config by the defined values and rebuilds the timetable.
|
|
496
|
+
*
|
|
497
|
+
* The merged config is validated against a candidate before being committed: {@link buildTimetable} may
|
|
498
|
+
* reject the candidate (invalid timing geometry, or per-block allocation multipliers below the network
|
|
499
|
+
* minimums). On rejection we leave `this.config` and `this.timetable` untouched and rethrow, so a bad update
|
|
500
|
+
* never leaves the sequencer running with a rejected config and a stale timetable.
|
|
501
|
+
*/ updateConfig(config) {
|
|
470
502
|
const filteredConfig = pickFromSchema(config, SequencerConfigSchema);
|
|
503
|
+
const candidate = merge(this.config, filteredConfig);
|
|
504
|
+
let timetable;
|
|
505
|
+
try {
|
|
506
|
+
timetable = this.buildTimetable(candidate);
|
|
507
|
+
} catch (err) {
|
|
508
|
+
this.log.warn(`Rejecting sequencer config update: ${err.message}`, {
|
|
509
|
+
rejectedConfig: omit(filteredConfig, 'txPublicSetupAllowListExtend')
|
|
510
|
+
});
|
|
511
|
+
throw err;
|
|
512
|
+
}
|
|
513
|
+
this.config = candidate;
|
|
514
|
+
this.timetable = timetable;
|
|
471
515
|
this.log.info(`Updated sequencer config`, omit(filteredConfig, 'txPublicSetupAllowListExtend'));
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* Builds the proposer timetable from the given config and L1 constants via the shared
|
|
519
|
+
* {@link buildProposerTimetable} helper, so the sequencer derives the same blocks-per-checkpoint as the p2p
|
|
520
|
+
* layer and `getNodeInfo`. The fast local/e2e profile and budget clamping happen inside
|
|
521
|
+
* {@link ProposerTimetable}.
|
|
522
|
+
*
|
|
523
|
+
* Throws if the timing geometry is invalid or the per-block allocation multipliers are below the network
|
|
524
|
+
* minimums; callers must treat a throw as a rejected config and not commit it.
|
|
525
|
+
*/ buildTimetable(config) {
|
|
526
|
+
const timetable = buildProposerTimetable(config, this.l1Constants);
|
|
527
|
+
const maxNumberOfBlocks = timetable.getMaxBlocksPerCheckpoint();
|
|
528
|
+
this.log.info(`Sequencer timetable initialized with ${maxNumberOfBlocks} blocks per slot`, {
|
|
529
|
+
aztecSlotDuration: timetable.aztecSlotDuration,
|
|
530
|
+
ethereumSlotDuration: timetable.ethereumSlotDuration,
|
|
531
|
+
blockDuration: timetable.blockDuration,
|
|
532
|
+
minBlockDuration: timetable.minBlockDuration,
|
|
533
|
+
p2pPropagationTime: timetable.p2pPropagationTime,
|
|
534
|
+
checkpointProposalPrepareTime: timetable.checkpointProposalPrepareTime,
|
|
535
|
+
maxNumberOfBlocks
|
|
536
|
+
});
|
|
537
|
+
this.assertConfigMeetsNetworkTxLimits(config, maxNumberOfBlocks);
|
|
538
|
+
return timetable;
|
|
539
|
+
}
|
|
540
|
+
/**
|
|
541
|
+
* Checks this node's configured per-block allocation against the network admission limit. A node
|
|
542
|
+
* advertises and admits txs up to the limit derived from the network-minimum multipliers (see
|
|
543
|
+
* {@link computeNetworkTxGasLimits}).
|
|
544
|
+
*
|
|
545
|
+
* Fails startup (and runtime config updates) only when the configured per-block allocation *multipliers*
|
|
546
|
+
* (`perBlockAllocationMultiplier` / `perBlockDAAllocationMultiplier`) are below the network minimums: such
|
|
547
|
+
* a node would accept txs over RPC/gossip that its builder can never pack into a block regardless of block
|
|
548
|
+
* size. Operators may configure a higher (more generous) multiplier, but not a lower one.
|
|
549
|
+
*
|
|
550
|
+
* When the multipliers meet the floor but an absolute per-block gas cap (`maxDABlockGas` / `maxL2BlockGas`)
|
|
551
|
+
* shrinks the builder's effective grant below the network limit, this is legitimate operator
|
|
552
|
+
* restrictiveness — the node simply builds smaller blocks and such txs stay in the pool for other
|
|
553
|
+
* proposers — so we only log a warning rather than failing startup. Restrictive tx-count caps
|
|
554
|
+
* (`maxTxsPerBlock` / `maxTxsPerCheckpoint`) can likewise make the builder skip admitted txs; they are
|
|
555
|
+
* intentionally not modeled here for the same reason.
|
|
556
|
+
*/ assertConfigMeetsNetworkTxLimits(config, maxBlocksPerCheckpoint) {
|
|
557
|
+
// Mirror CheckpointBuilder.capLimitsByCheckpointBudgets: DA falls back to the general multiplier.
|
|
558
|
+
const l2Multiplier = config.perBlockAllocationMultiplier;
|
|
559
|
+
const daMultiplier = config.perBlockDAAllocationMultiplier ?? l2Multiplier;
|
|
560
|
+
// The allocation is monotonic in the multiplier, so a multiplier at or above the network minimum
|
|
561
|
+
// guarantees the builder grants at least the network admission limit. Checking the multipliers directly
|
|
562
|
+
// is sufficient (and strictly more conservative than modeling the resulting gas grant).
|
|
563
|
+
if (daMultiplier < MIN_PER_BLOCK_DA_ALLOCATION_MULTIPLIER) {
|
|
564
|
+
throw new Error(`perBlockDAAllocationMultiplier (${daMultiplier}) is below the network minimum ` + `${MIN_PER_BLOCK_DA_ALLOCATION_MULTIPLIER}; the node would admit txs its own builder can never include.`);
|
|
565
|
+
}
|
|
566
|
+
if (l2Multiplier < MIN_PER_BLOCK_ALLOCATION_MULTIPLIER) {
|
|
567
|
+
throw new Error(`perBlockAllocationMultiplier (${l2Multiplier}) is below the network minimum ` + `${MIN_PER_BLOCK_ALLOCATION_MULTIPLIER}; the node would admit txs its own builder can never include.`);
|
|
568
|
+
}
|
|
569
|
+
// Absolute per-block gas caps below the network admission limit are legitimate operator restrictiveness:
|
|
570
|
+
// the node simply builds smaller blocks and such txs stay in the pool for other proposers. Warn only.
|
|
571
|
+
const networkLimit = computeNetworkTxGasLimits({
|
|
572
|
+
maxBlocksPerCheckpoint,
|
|
573
|
+
manaCheckpointBudget: this.l1Constants.rollupManaLimit
|
|
574
|
+
});
|
|
575
|
+
if (config.maxDABlockGas !== undefined && config.maxDABlockGas < networkLimit.daGas) {
|
|
576
|
+
this.log.warn(`Sequencer maxDABlockGas (${config.maxDABlockGas}) is below the network DA admission limit ` + `(${networkLimit.daGas}): txs declaring more DA gas are admitted over RPC/gossip but will be skipped ` + `by this proposer's own blocks and left in the pool for other proposers.`, {
|
|
577
|
+
maxDABlockGas: config.maxDABlockGas,
|
|
578
|
+
networkDaGas: networkLimit.daGas,
|
|
579
|
+
maxBlocksPerCheckpoint
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
if (config.maxL2BlockGas !== undefined && config.maxL2BlockGas < networkLimit.l2Gas) {
|
|
583
|
+
this.log.warn(`Sequencer maxL2BlockGas (${config.maxL2BlockGas}) is below the network L2 admission limit ` + `(${networkLimit.l2Gas}): txs declaring more L2 gas are admitted over RPC/gossip but will be skipped ` + `by this proposer's own blocks and left in the pool for other proposers.`, {
|
|
584
|
+
maxL2BlockGas: config.maxL2BlockGas,
|
|
585
|
+
networkL2Gas: networkLimit.l2Gas,
|
|
586
|
+
maxBlocksPerCheckpoint
|
|
587
|
+
});
|
|
588
|
+
}
|
|
481
589
|
}
|
|
482
590
|
/** Initializes the sequencer (precomputes tables). Takes about 3s. */ init() {
|
|
483
591
|
getKzg();
|
|
484
592
|
}
|
|
485
|
-
/**
|
|
593
|
+
/**
|
|
594
|
+
* Starts (or restarts) the sequencer and moves it to the IDLE state. Idempotent: a start while already
|
|
595
|
+
* running is a no-op, so it never orphans the previous poll loop. A start while STOPPING throws, since the
|
|
596
|
+
* in-flight stop would mark the fresh loop's state STOPPED and orphan it — silently doing nothing would
|
|
597
|
+
* leave the caller believing the sequencer is running when it is on its way to STOPPED. Safe to call after
|
|
598
|
+
* a previous {@link stop} has resolved; the caller must also restart the publishers (see
|
|
599
|
+
* {@link SequencerClient.start}) so L1 publishing is re-enabled.
|
|
600
|
+
*/ start() {
|
|
601
|
+
if (this.state === SequencerState.STOPPING) {
|
|
602
|
+
throw new Error('Cannot start sequencer while it is stopping');
|
|
603
|
+
}
|
|
604
|
+
if (this.runningPromise?.isRunning()) {
|
|
605
|
+
this.log.warn('Attempted to start sequencer that is already running');
|
|
606
|
+
return;
|
|
607
|
+
}
|
|
486
608
|
this.runningPromise = new RunningPromise(this.safeWork.bind(this), this.log, this.config.sequencerPollingIntervalMS);
|
|
487
609
|
this.setState(SequencerState.IDLE, undefined, {
|
|
488
610
|
force: true
|
|
@@ -490,19 +612,59 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
490
612
|
this.runningPromise.start();
|
|
491
613
|
this.log.info('Started sequencer');
|
|
492
614
|
}
|
|
493
|
-
/**
|
|
615
|
+
/** Triggers an immediate run of the sequencer, bypassing the polling interval. */ trigger() {
|
|
616
|
+
return this.runningPromise?.trigger();
|
|
617
|
+
}
|
|
618
|
+
/**
|
|
619
|
+
* Stops the sequencer from building blocks and moves it to STOPPED state, interrupting the in-flight
|
|
620
|
+
* work() iteration and its pending L1 submissions for a fast shutdown, then draining before returning.
|
|
621
|
+
* Idempotent: a second call while already stopped or stopping is a no-op. Lifecycle calls are expected
|
|
622
|
+
* to be serialized by the caller. For a restartable pause that lets in-flight work finish untouched
|
|
623
|
+
* (e.g. around a test clock warp), use {@link pause} instead.
|
|
624
|
+
*/ async stop() {
|
|
625
|
+
if (this.state === SequencerState.STOPPED || this.state === SequencerState.STOPPING) {
|
|
626
|
+
this.log.debug(`Sequencer already ${this.state.toLowerCase()}, ignoring stop`);
|
|
627
|
+
return;
|
|
628
|
+
}
|
|
494
629
|
this.log.info(`Stopping sequencer`);
|
|
495
630
|
this.setState(SequencerState.STOPPING, undefined, {
|
|
496
631
|
force: true
|
|
497
632
|
});
|
|
633
|
+
this.lastCheckpointProposalJob?.interrupt();
|
|
498
634
|
await this.publisherFactory.stopAll();
|
|
635
|
+
// Stop the poll loop and await the in-flight work() iteration. work() registers its fire-and-forget
|
|
636
|
+
// requests synchronously before returning, so once the loop has stopped, pendingRequests holds every
|
|
637
|
+
// request that will ever exist. Interrupting any earlier could miss a request registered by the last
|
|
638
|
+
// in-flight iteration.
|
|
499
639
|
await this.runningPromise?.stop();
|
|
500
|
-
|
|
640
|
+
this.pendingRequests.interruptRequests();
|
|
641
|
+
await this.pendingRequests.awaitRequests();
|
|
501
642
|
this.setState(SequencerState.STOPPED, undefined, {
|
|
502
643
|
force: true
|
|
503
644
|
});
|
|
504
645
|
this.log.info('Stopped sequencer');
|
|
505
646
|
}
|
|
647
|
+
/**
|
|
648
|
+
* Gracefully pauses block production so the sequencer can later be resumed with {@link start}: halts the
|
|
649
|
+
* poll loop and waits for the in-flight work() iteration and every pending L1 submission / fallback send
|
|
650
|
+
* to finish, without interrupting them. No interrupt lands mid-build, so no spurious checkpoint-error is
|
|
651
|
+
* emitted and no enqueued checkpoint is dropped. Deliberately does not stop inner services (validator/HA
|
|
652
|
+
* signer, publishers), so the slashing-protection store stays open and the sequencer stays restartable.
|
|
653
|
+
* Used by tests that pause sequencers around an L1 clock warp. Idempotent.
|
|
654
|
+
*/ async pause() {
|
|
655
|
+
if (!this.runningPromise?.isRunning()) {
|
|
656
|
+
this.log.debug('Sequencer not running, ignoring pause');
|
|
657
|
+
return;
|
|
658
|
+
}
|
|
659
|
+
this.log.info('Pausing sequencer');
|
|
660
|
+
// Halt the poll loop and let the in-flight iteration finish naturally — no interrupt, and no STOPPING
|
|
661
|
+
// state, since entering STOPPING would make the iteration's own setState calls throw and fail it.
|
|
662
|
+
// work() registers its fire-and-forget requests synchronously before returning, so once the loop has
|
|
663
|
+
// stopped pendingRequests holds every request that will ever exist; awaiting it lets them all finish.
|
|
664
|
+
await this.runningPromise.stop();
|
|
665
|
+
await this.pendingRequests.awaitRequests();
|
|
666
|
+
this.log.info('Paused sequencer');
|
|
667
|
+
}
|
|
506
668
|
/** Main sequencer loop with a try/catch */ async safeWork() {
|
|
507
669
|
try {
|
|
508
670
|
await this.work();
|
|
@@ -510,19 +672,7 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
510
672
|
this.emit('checkpoint-error', {
|
|
511
673
|
error: err
|
|
512
674
|
});
|
|
513
|
-
|
|
514
|
-
// Log as warn only if we had to abort halfway through the block proposal
|
|
515
|
-
const logLvl = [
|
|
516
|
-
SequencerState.INITIALIZING_CHECKPOINT,
|
|
517
|
-
SequencerState.PROPOSER_CHECK
|
|
518
|
-
].includes(err.proposedState) ? 'debug' : 'warn';
|
|
519
|
-
this.log[logLvl](err.message, {
|
|
520
|
-
now: this.dateProvider.nowInSeconds()
|
|
521
|
-
});
|
|
522
|
-
} else {
|
|
523
|
-
// Re-throw other errors
|
|
524
|
-
throw err;
|
|
525
|
-
}
|
|
675
|
+
throw err;
|
|
526
676
|
} finally{
|
|
527
677
|
this.setState(SequencerState.IDLE, undefined);
|
|
528
678
|
}
|
|
@@ -541,8 +691,7 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
541
691
|
* - Submit checkpoint
|
|
542
692
|
*/ async work() {
|
|
543
693
|
this.setState(SequencerState.SYNCHRONIZING, undefined);
|
|
544
|
-
const { slot, ts, nowSeconds
|
|
545
|
-
const { slot: targetSlot, epoch: targetEpoch } = this.epochCache.getTargetEpochAndSlotInNextL1Slot();
|
|
694
|
+
const { slot, targetSlot, epoch, targetEpoch, ts, nowSeconds } = this.getSlotContextInNextL1Slot();
|
|
546
695
|
// Check if we are synced and it's our slot, grab a publisher, check previous block invalidation, etc
|
|
547
696
|
const checkpointProposalJob = await this.prepareCheckpointProposal(slot, targetSlot, epoch, targetEpoch, ts, nowSeconds);
|
|
548
697
|
if (!checkpointProposalJob) {
|
|
@@ -563,15 +712,25 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
563
712
|
}
|
|
564
713
|
return checkpoint;
|
|
565
714
|
}
|
|
715
|
+
/** Returns slot and target slot from a single clock snapshot. */ getSlotContextInNextL1Slot() {
|
|
716
|
+
const { slot, ts, nowSeconds, epoch } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
717
|
+
const targetSlot = SlotNumber(slot + PROPOSER_PIPELINING_SLOT_OFFSET);
|
|
718
|
+
return {
|
|
719
|
+
slot,
|
|
720
|
+
targetSlot,
|
|
721
|
+
epoch,
|
|
722
|
+
targetEpoch: getEpochAtSlot(targetSlot, this.l1Constants),
|
|
723
|
+
ts,
|
|
724
|
+
nowSeconds
|
|
725
|
+
};
|
|
726
|
+
}
|
|
566
727
|
/**
|
|
567
728
|
* Prepares the checkpoint proposal by performing all necessary checks and setup.
|
|
568
729
|
* This is the initial step in the main loop.
|
|
569
730
|
* @returns CheckpointProposalJob if successful, undefined if we are not yet synced or are not the proposer.
|
|
570
731
|
*/ async prepareCheckpointProposal(slot, targetSlot, epoch, targetEpoch, ts, nowSeconds) {
|
|
571
|
-
// Check we have not already processed this target slot (cheapest check)
|
|
572
|
-
|
|
573
|
-
// running against actual time (eg when we use sandbox-style automining)
|
|
574
|
-
if (this.lastSlotForCheckpointProposalJob && this.lastSlotForCheckpointProposalJob >= targetSlot && this.config.enforceTimeTable) {
|
|
732
|
+
// Check we have not already processed this target slot (cheapest check).
|
|
733
|
+
if (this.lastSlotForCheckpointProposalJob && this.lastSlotForCheckpointProposalJob >= targetSlot) {
|
|
575
734
|
this.log.trace(`Target slot ${targetSlot} has already been processed`);
|
|
576
735
|
return undefined;
|
|
577
736
|
}
|
|
@@ -580,29 +739,28 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
580
739
|
this.log.trace(`Slot ${targetSlot} has already been published as checkpoint ${this.lastCheckpointProposed.number}`);
|
|
581
740
|
return undefined;
|
|
582
741
|
}
|
|
583
|
-
//
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
slot
|
|
587
|
-
|
|
588
|
-
if (!syncedTo) {
|
|
589
|
-
await this.tryVoteWhenSyncFails({
|
|
590
|
-
slot,
|
|
591
|
-
targetSlot,
|
|
592
|
-
ts
|
|
742
|
+
// Test-only: skip proposing for explicitly paused slots. Attestation paths run in the validator
|
|
743
|
+
// client and are not gated by this hook, so paused proposers still attest to others' proposals.
|
|
744
|
+
if (this.config.pauseProposingForSlots?.some((s)=>s === targetSlot)) {
|
|
745
|
+
this.log.warn(`Skipping proposal for paused slot ${targetSlot} (test-only pauseProposingForSlots hook)`, {
|
|
746
|
+
targetSlot
|
|
593
747
|
});
|
|
594
748
|
return undefined;
|
|
595
749
|
}
|
|
750
|
+
// Cheap proposer check first: most nodes are not the proposer for most slots, so gate the
|
|
751
|
+
// expensive multi-subsystem checkSync (and the rest of the build path) behind it. Computed once
|
|
752
|
+
// here and reused for the escape-hatch voting path below. No setState/timing gate on this path:
|
|
753
|
+
// the build-start deadline gate runs only on the proposer build path after a successful checkSync.
|
|
754
|
+
const [canPropose, proposer] = await this.checkCanPropose(targetSlot);
|
|
596
755
|
// If escape hatch is open for the target epoch, do not start checkpoint proposal work and do not attempt invalidations.
|
|
597
756
|
// Still perform governance/slashing voting (as proposer) once per slot.
|
|
598
757
|
// When pipelining, we check the target epoch (slot+1's epoch) since that's the epoch we're building for.
|
|
599
758
|
const isEscapeHatchOpen = await this.epochCache.isEscapeHatchOpen(targetEpoch);
|
|
600
759
|
if (isEscapeHatchOpen) {
|
|
601
|
-
this.setState(SequencerState.PROPOSER_CHECK, slot);
|
|
602
|
-
const [canPropose, proposer] = await this.checkCanPropose(targetSlot);
|
|
603
760
|
if (canPropose) {
|
|
604
761
|
await this.tryVoteWhenEscapeHatchOpen({
|
|
605
762
|
slot,
|
|
763
|
+
targetSlot,
|
|
606
764
|
proposer
|
|
607
765
|
});
|
|
608
766
|
} else {
|
|
@@ -614,15 +772,82 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
614
772
|
}
|
|
615
773
|
return undefined;
|
|
616
774
|
}
|
|
617
|
-
//
|
|
618
|
-
|
|
619
|
-
//
|
|
620
|
-
//
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
775
|
+
// If we are not the proposer, check whether we should invalidate an invalid pending chain (a
|
|
776
|
+
// liveness backstop) and bail before any sync work or build-timing gate. This reads only the
|
|
777
|
+
// archiver's pending-chain validation status, which is authoritative on its own, instead of
|
|
778
|
+
// running the full sync check. Wrapped in try/catch because this leaner path skips the broader
|
|
779
|
+
// proposed-checkpoint/tip coherence screen that checkSync applied, so transient archiver
|
|
780
|
+
// incoherence surfaces as a quiet skip rather than a work-loop error.
|
|
781
|
+
if (!canPropose) {
|
|
782
|
+
try {
|
|
783
|
+
const pendingChainValidationStatus = await this.l2BlockSource.getPendingChainValidationStatus();
|
|
784
|
+
await this.considerInvalidatingCheckpoint(pendingChainValidationStatus, slot);
|
|
785
|
+
} catch (err) {
|
|
786
|
+
this.log.warn(`Failed to consider invalidating checkpoint`, {
|
|
787
|
+
err,
|
|
788
|
+
slot,
|
|
789
|
+
targetSlot
|
|
790
|
+
});
|
|
791
|
+
}
|
|
792
|
+
return undefined;
|
|
793
|
+
}
|
|
794
|
+
// Explicit build-loop entry gate: if we are past the latest useful block-building start for the
|
|
795
|
+
// target slot, abandon building for this slot. The proposer prioritizes the ideal L1-publish path
|
|
796
|
+
// and does not plan around the late consensus-handoff path. This is the proposer build path's
|
|
797
|
+
// timing gate; it runs only after we know we are the synced proposer, so non-proposer invalidation
|
|
798
|
+
// and escape-hatch voting (which returned above) are never gated by build timing. Vote-only paths
|
|
799
|
+
// still run when block building is abandoned.
|
|
800
|
+
const startDeadline = this.timetable.getBuildStartDeadline(targetSlot);
|
|
801
|
+
const nowForStartGate = this.dateProvider.now() / 1000;
|
|
802
|
+
if (nowForStartGate > startDeadline) {
|
|
803
|
+
this.log.debug(`Past start deadline for slot ${targetSlot}, abandoning block building`, {
|
|
804
|
+
targetSlot,
|
|
805
|
+
nowForStartGate,
|
|
806
|
+
startDeadline
|
|
807
|
+
});
|
|
808
|
+
// Mark the slot as attempted so a deadline abort is not retried within the same slot. Vote-only actions
|
|
809
|
+
// still need to run because sync can succeed even when it is too late to start building a checkpoint.
|
|
810
|
+
await this.tryVoteAndPruneWhenCannotBuild({
|
|
811
|
+
slot,
|
|
812
|
+
targetSlot
|
|
813
|
+
});
|
|
814
|
+
this.lastSlotForCheckpointProposalJob = targetSlot;
|
|
815
|
+
return undefined;
|
|
816
|
+
}
|
|
817
|
+
// A proposal that cannot reach the committee is worse than not proposing: the slot is burned, and a
|
|
818
|
+
// node holding enough committee seats to reach quorum on its own would publish a checkpoint whose tx
|
|
819
|
+
// data was never gossiped to anyone, which is indistinguishable from data withholding. Skip building
|
|
820
|
+
// while peerless, but keep the vote/prune duties below. Only applies when p2p is enabled: setups that
|
|
821
|
+
// disable it (sandbox, single node, automine) legitimately propose with no peers.
|
|
822
|
+
const connectivity = await this.p2pClient.getP2PConnectivity();
|
|
823
|
+
const minPeersToPropose = this.config.minPeersToPropose;
|
|
824
|
+
if (connectivity.enabled && connectivity.connectedPeers < minPeersToPropose) {
|
|
825
|
+
this.log.warn(`Skipping checkpoint proposal for slot ${targetSlot} since we have too few connected peers`, {
|
|
826
|
+
targetSlot,
|
|
827
|
+
connectedPeers: connectivity.connectedPeers,
|
|
828
|
+
minPeersToPropose
|
|
829
|
+
});
|
|
830
|
+
this.metrics.recordCheckpointPrecheckFailed('no_peers');
|
|
831
|
+
// Mark the slot as attempted so the gate is not re-evaluated on every tick within the slot. Vote-only
|
|
832
|
+
// actions still run: L1 duties (governance/slashing votes, prune) do not depend on gossip.
|
|
833
|
+
await this.tryVoteAndPruneWhenCannotBuild({
|
|
834
|
+
slot,
|
|
835
|
+
targetSlot
|
|
836
|
+
});
|
|
837
|
+
this.lastSlotForCheckpointProposalJob = targetSlot;
|
|
838
|
+
return undefined;
|
|
839
|
+
}
|
|
840
|
+
// We are the proposer, the escape hatch is closed, and we have time before the build start deadline.
|
|
841
|
+
// Now run the full sync check before building.
|
|
842
|
+
const syncedTo = await this.checkSync({
|
|
843
|
+
ts,
|
|
844
|
+
slot
|
|
845
|
+
});
|
|
846
|
+
if (!syncedTo) {
|
|
624
847
|
return undefined;
|
|
625
848
|
}
|
|
849
|
+
// Next checkpoint follows from the last synced one
|
|
850
|
+
const checkpointNumber = CheckpointNumber(syncedTo.checkpointNumber + 1);
|
|
626
851
|
const logCtx = {
|
|
627
852
|
nowSeconds,
|
|
628
853
|
syncedToL2Slot: syncedTo.syncedL2Slot,
|
|
@@ -632,12 +857,13 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
632
857
|
checkpointNumber,
|
|
633
858
|
isPendingChainValid: pick(syncedTo.pendingChainValidationStatus, 'valid', 'reason', 'invalidIndex')
|
|
634
859
|
};
|
|
635
|
-
//
|
|
636
|
-
this.setState(SequencerState.PROPOSER_CHECK,
|
|
637
|
-
|
|
638
|
-
//
|
|
639
|
-
|
|
640
|
-
|
|
860
|
+
// We are the synced proposer within the build window; enter the proposer-check state and build.
|
|
861
|
+
this.setState(SequencerState.PROPOSER_CHECK, targetSlot);
|
|
862
|
+
// Guard: don't exceed 1-deep pipeline. Without a proposed checkpoint, we can only build
|
|
863
|
+
// confirmed + 1. With a proposed checkpoint, we can build confirmed + 2.
|
|
864
|
+
const confirmedCkpt = syncedTo.checkpointedCheckpointNumber;
|
|
865
|
+
if (checkpointNumber > confirmedCkpt + 2) {
|
|
866
|
+
this.log.verbose(`Skipping slot ${targetSlot}: checkpoint ${checkpointNumber} exceeds max pipeline depth (confirmed=${confirmedCkpt})`);
|
|
641
867
|
return undefined;
|
|
642
868
|
}
|
|
643
869
|
// Check that the target slot is not taken by a block already (should never happen, since only us can propose for this slot)
|
|
@@ -656,43 +882,84 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
656
882
|
const proposerForPublisher = this.config.fishermanMode ? undefined : proposer;
|
|
657
883
|
const { attestorAddress, publisher } = await this.publisherFactory.create(proposerForPublisher);
|
|
658
884
|
this.log.verbose(`Created publisher at address ${publisher.getSenderAddress()} for attestor ${attestorAddress}`);
|
|
659
|
-
//
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
}
|
|
664
|
-
// Prepare invalidation request if the pending chain is invalid (returns undefined if no need)
|
|
665
|
-
let invalidateCheckpoint = await publisher.simulateInvalidateCheckpoint(syncedTo.pendingChainValidationStatus);
|
|
885
|
+
// Prepare invalidation request if the pending chain is invalid (returns undefined if no need).
|
|
886
|
+
// Only simulate invalidation when there's no proposed parent, since we assume the proposed parent
|
|
887
|
+
// will invalidate the currently invalid checkpoint on L1.
|
|
888
|
+
const invalidateCheckpoint = syncedTo.hasProposedCheckpoint || syncedTo.pendingChainValidationStatus.valid ? undefined : await publisher.simulateInvalidateCheckpoint(syncedTo.pendingChainValidationStatus);
|
|
666
889
|
// Determine the correct archive and L1 state overrides for the canProposeAt check.
|
|
667
890
|
// The L1 contract reads archives[proposedCheckpointNumber] and compares it with the provided archive.
|
|
668
891
|
// When invalidating or pipelining, the local archive may differ from L1's, so we adjust accordingly.
|
|
669
892
|
let archiveForCheck = syncedTo.archive;
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
// Clear the invalidation - the proposed checkpoint should handle it.
|
|
683
|
-
invalidateCheckpoint = undefined;
|
|
893
|
+
if (syncedTo.hasProposedCheckpoint) {
|
|
894
|
+
this.metrics.recordPipelineDepth(syncedTo.checkpointNumber - syncedTo.checkpointedCheckpointNumber);
|
|
895
|
+
this.log.verbose(`Building on top of proposed checkpoint (pending=${syncedTo.proposedCheckpointData?.checkpointNumber}) for target slot ${targetSlot}`, {
|
|
896
|
+
targetSlot,
|
|
897
|
+
parentCheckpointNumber: CheckpointNumber(checkpointNumber - 1)
|
|
898
|
+
});
|
|
899
|
+
// Match what L1 will see at archives[pending] once the proposed parent lands: the parent's
|
|
900
|
+
// own archive root from the gossiped proposal. `syncedTo.archive` is the world-state-local
|
|
901
|
+
// view and can transiently diverge from the proposed parent (e.g. before the proposed
|
|
902
|
+
// parent's blocks have been applied locally); diverging here would cause the canProposeAt
|
|
903
|
+
// override to set archives[pending] to one value while we present another for comparison.
|
|
904
|
+
archiveForCheck = syncedTo.proposedCheckpointData.archive.root;
|
|
684
905
|
} else if (invalidateCheckpoint) {
|
|
685
906
|
// After invalidation, L1 will roll back to checkpoint N-1. The archive at N-1 already
|
|
686
907
|
// exists on L1, so we just pass the matching archive (the lastArchive of the invalid checkpoint).
|
|
687
908
|
archiveForCheck = invalidateCheckpoint.lastArchive;
|
|
688
|
-
l1Overrides.forcePendingCheckpointNumber = invalidateCheckpoint.forcePendingCheckpointNumber;
|
|
689
909
|
this.metrics.recordPipelineDepth(0);
|
|
690
910
|
} else {
|
|
691
911
|
this.metrics.recordPipelineDepth(0);
|
|
692
912
|
}
|
|
693
|
-
|
|
913
|
+
// Build the simulation plan: pending/proven override from pipelining or invalidation (or the
|
|
914
|
+
// current snapshot when neither applies, to short-circuit any pending prune in simulation),
|
|
915
|
+
// plus the parent checkpoint cell and fee header when pipelining.
|
|
916
|
+
const simulationOverridesPlan = await buildCheckpointSimulationOverridesPlan({
|
|
917
|
+
checkpointNumber,
|
|
918
|
+
proposedCheckpointData: syncedTo.hasProposedCheckpoint ? syncedTo.proposedCheckpointData : undefined,
|
|
919
|
+
invalidateToPendingCheckpointNumber: invalidateCheckpoint?.forcePendingCheckpointNumber,
|
|
920
|
+
checkpointedCheckpointNumber: syncedTo.checkpointedCheckpointNumber,
|
|
921
|
+
rollup: this.rollupContract,
|
|
922
|
+
signatureContext: this.signatureContext,
|
|
923
|
+
log: this.log
|
|
924
|
+
});
|
|
925
|
+
// The plan always pins both pending/proven (to short-circuit `canPruneAtTime` in simulation),
|
|
926
|
+
// so `provenOverride` always reflects the assumed proven checkpoint we are pinning the
|
|
927
|
+
// simulation to. We additionally warn when the pin is load-bearing — i.e. when a prune would
|
|
928
|
+
// actually fire at the target slot without it — so observers can spot "we are building
|
|
929
|
+
// optimistically across a pruning boundary" in the logs.
|
|
930
|
+
const provenOverride = simulationOverridesPlan?.chainTipsOverride?.proven;
|
|
931
|
+
if (provenOverride !== undefined && await this.l2BlockSource.isPruneDueAtSlot(targetSlot)) {
|
|
932
|
+
this.log.warn(`Assuming proof for epoch ending at checkpoint ${provenOverride} lands by target slot ${targetSlot}`, {
|
|
933
|
+
checkpointNumber,
|
|
934
|
+
slot,
|
|
935
|
+
targetSlot,
|
|
936
|
+
provenOverride
|
|
937
|
+
});
|
|
938
|
+
}
|
|
939
|
+
this.emit('preparing-checkpoint', {
|
|
940
|
+
targetSlot,
|
|
941
|
+
checkpointNumber,
|
|
942
|
+
hadProposedParent: syncedTo.hasProposedCheckpoint,
|
|
943
|
+
provenOverride,
|
|
944
|
+
simulatedPending: simulationOverridesPlan?.chainTipsOverride?.pending
|
|
945
|
+
});
|
|
946
|
+
const canProposeCheck = await publisher.canProposeAt(archiveForCheck, proposer ?? EthAddress.ZERO, simulationOverridesPlan);
|
|
947
|
+
const proposeContext = {
|
|
948
|
+
hasProposedCheckpoint: syncedTo.hasProposedCheckpoint,
|
|
949
|
+
proposedCheckpointNumber: syncedTo.proposedCheckpointData?.checkpointNumber,
|
|
950
|
+
checkpointedCheckpointNumber: syncedTo.checkpointedCheckpointNumber,
|
|
951
|
+
isInvalidating: !!invalidateCheckpoint,
|
|
952
|
+
invalidatingCheckpointNumber: invalidateCheckpoint?.checkpointNumber,
|
|
953
|
+
archiveForCheck: archiveForCheck.toString(),
|
|
954
|
+
overridePendingCheckpointNumber: simulationOverridesPlan?.chainTipsOverride?.pending,
|
|
955
|
+
overrideArchive: simulationOverridesPlan?.pendingCheckpointState?.archive,
|
|
956
|
+
overrideFeeHeader: simulationOverridesPlan?.pendingCheckpointState?.feeHeader
|
|
957
|
+
};
|
|
694
958
|
if (canProposeCheck === undefined) {
|
|
695
|
-
this.log.warn(`Cannot propose checkpoint ${checkpointNumber} at slot ${slot} due to failed rollup contract check`,
|
|
959
|
+
this.log.warn(`Cannot propose checkpoint ${checkpointNumber} at slot ${slot} due to failed rollup contract check`, {
|
|
960
|
+
...logCtx,
|
|
961
|
+
...proposeContext
|
|
962
|
+
});
|
|
696
963
|
this.emit('proposer-rollup-check-failed', {
|
|
697
964
|
reason: 'Rollup contract check failed',
|
|
698
965
|
slot
|
|
@@ -703,6 +970,7 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
703
970
|
if (canProposeCheck.slot !== targetSlot) {
|
|
704
971
|
this.log.warn(`Cannot propose block due to slot mismatch with rollup contract (this can be caused by a clock out of sync). Expected slot ${targetSlot} but got ${canProposeCheck.slot}.`, {
|
|
705
972
|
...logCtx,
|
|
973
|
+
...proposeContext,
|
|
706
974
|
rollup: canProposeCheck,
|
|
707
975
|
expectedSlot: targetSlot
|
|
708
976
|
});
|
|
@@ -716,6 +984,7 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
716
984
|
if (canProposeCheck.checkpointNumber !== checkpointNumber) {
|
|
717
985
|
this.log.warn(`Cannot propose due to block mismatch with rollup contract (this can be caused by a pending archiver sync). Expected checkpoint ${checkpointNumber} but got ${canProposeCheck.checkpointNumber}.`, {
|
|
718
986
|
...logCtx,
|
|
987
|
+
...proposeContext,
|
|
719
988
|
rollup: canProposeCheck,
|
|
720
989
|
expectedSlot: slot
|
|
721
990
|
});
|
|
@@ -730,14 +999,14 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
730
999
|
await this.p2pClient.prepareForSlot(targetSlot);
|
|
731
1000
|
this.log.info(`Preparing checkpoint proposal ${checkpointNumber} for target slot ${targetSlot} during wall-clock slot ${slot}`, {
|
|
732
1001
|
...logCtx,
|
|
733
|
-
|
|
734
|
-
|
|
1002
|
+
...proposeContext,
|
|
1003
|
+
proposer
|
|
735
1004
|
});
|
|
736
1005
|
// Create and return the checkpoint proposal job
|
|
737
|
-
return this.createCheckpointProposalJob(
|
|
1006
|
+
return this.createCheckpointProposalJob(targetSlot, targetEpoch, checkpointNumber, syncedTo.blockNumber, syncedTo.checkpointedCheckpointNumber, proposer, publisher, attestorAddress, invalidateCheckpoint, syncedTo.proposedCheckpointData);
|
|
738
1007
|
}
|
|
739
|
-
createCheckpointProposalJob(
|
|
740
|
-
return new CheckpointProposalJob(
|
|
1008
|
+
createCheckpointProposalJob(targetSlot, targetEpoch, checkpointNumber, syncedToBlockNumber, checkpointedCheckpointNumber, proposer, publisher, attestorAddress, invalidateCheckpoint, proposedCheckpointData) {
|
|
1009
|
+
return new CheckpointProposalJob(targetSlot, targetEpoch, checkpointNumber, syncedToBlockNumber, checkpointedCheckpointNumber, proposer, publisher, attestorAddress, invalidateCheckpoint, this.validatorClient, this.globalsBuilder, this.p2pClient, this.worldState, this.l1ToL2MessageSource, this.l2BlockSource, this.checkpointsBuilder, this.l2BlockSource, this.l1Constants, this.signatureContext, this.config, this.timetable, this.slasherClient, this.epochCache, this.dateProvider, this.metrics, this.checkpointProposalJobMetrics.createRecorder(), this, this.pendingRequests, this.setState.bind(this), this.tracer, this.log.getBindings(), proposedCheckpointData);
|
|
741
1010
|
}
|
|
742
1011
|
/**
|
|
743
1012
|
* Returns the current sequencer state.
|
|
@@ -745,9 +1014,11 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
745
1014
|
return this.state;
|
|
746
1015
|
}
|
|
747
1016
|
/**
|
|
748
|
-
* Internal helper for setting the sequencer state
|
|
1017
|
+
* Internal helper for setting the sequencer state. Pure: sets the state, emits `state-changed`, and
|
|
1018
|
+
* records metrics. Timing deadlines are queried explicitly at the relevant call sites, not gated here.
|
|
749
1019
|
* @param proposedState - The new state to transition to.
|
|
750
|
-
* @param slotNumber - The
|
|
1020
|
+
* @param slotNumber - The target slot being proposed for, emitted as `targetSlot` on the event payload
|
|
1021
|
+
* and used to anchor `secondsIntoBuildFrame`. Undefined for lifecycle states with no associated slot.
|
|
751
1022
|
* @param force - Whether to force the transition even if the sequencer is stopped.
|
|
752
1023
|
*/ setState(proposedState, slotNumber, opts = {}) {
|
|
753
1024
|
if (this.state === SequencerState.STOPPING && proposedState !== SequencerState.STOPPED && !opts.force) {
|
|
@@ -758,26 +1029,40 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
758
1029
|
this.log.warn(`Cannot set sequencer from ${this.state} to ${proposedState} as it is stopped.`);
|
|
759
1030
|
return;
|
|
760
1031
|
}
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
1032
|
+
const secondsIntoBuildFrame = slotNumber !== undefined ? this.getSecondsIntoBuildFrame(slotNumber) : undefined;
|
|
1033
|
+
const oldState = this.state;
|
|
1034
|
+
const oldStateSlotNumber = this.stateSlotNumber;
|
|
1035
|
+
const stateChanged = proposedState !== oldState;
|
|
1036
|
+
// Wall-clock time spent in the previous state: the delta between consecutive state-changing setState
|
|
1037
|
+
// calls, read from the date provider so it tracks simulated time under a test/manual clock.
|
|
1038
|
+
const transitionAtMs = this.dateProvider.now();
|
|
1039
|
+
const stateDurationMs = transitionAtMs - this.stateEnteredAtMs;
|
|
766
1040
|
const boringStates = [
|
|
767
1041
|
SequencerState.IDLE,
|
|
768
1042
|
SequencerState.SYNCHRONIZING
|
|
769
1043
|
];
|
|
770
|
-
const logLevel = boringStates.includes(proposedState) && boringStates.includes(
|
|
771
|
-
this.
|
|
1044
|
+
const logLevel = boringStates.includes(proposedState) && boringStates.includes(oldState) ? 'trace' : 'debug';
|
|
1045
|
+
this.stateLog[logLevel](`Transitioning from ${oldState} to ${proposedState}`, {
|
|
1046
|
+
oldState,
|
|
1047
|
+
newState: proposedState,
|
|
772
1048
|
slotNumber,
|
|
773
|
-
|
|
1049
|
+
stateSlotNumber: oldStateSlotNumber,
|
|
1050
|
+
secondsIntoBuildFrame,
|
|
1051
|
+
...stateChanged && {
|
|
1052
|
+
stateDurationMs: Math.ceil(stateDurationMs)
|
|
1053
|
+
}
|
|
774
1054
|
});
|
|
775
1055
|
this.emit('state-changed', {
|
|
776
|
-
oldState
|
|
1056
|
+
oldState,
|
|
777
1057
|
newState: proposedState,
|
|
778
|
-
|
|
779
|
-
|
|
1058
|
+
secondsIntoBuildFrame,
|
|
1059
|
+
targetSlot: slotNumber
|
|
780
1060
|
});
|
|
1061
|
+
if (stateChanged) {
|
|
1062
|
+
this.metrics.recordStateDuration(stateDurationMs, oldState);
|
|
1063
|
+
this.stateEnteredAtMs = transitionAtMs;
|
|
1064
|
+
this.stateSlotNumber = slotNumber;
|
|
1065
|
+
}
|
|
781
1066
|
this.state = proposedState;
|
|
782
1067
|
}
|
|
783
1068
|
/**
|
|
@@ -803,49 +1088,74 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
803
1088
|
})),
|
|
804
1089
|
this.l2BlockSource.getL2Tips().then((t)=>({
|
|
805
1090
|
proposed: t.proposed,
|
|
806
|
-
checkpointed: t.checkpointed
|
|
807
|
-
proposedCheckpoint: t.proposedCheckpoint
|
|
1091
|
+
checkpointed: t.checkpointed
|
|
808
1092
|
})),
|
|
809
1093
|
this.p2pClient.getStatus().then((p2p)=>p2p.syncedToL2Block),
|
|
810
|
-
this.l1ToL2MessageSource.getL2Tips().then((t)=>
|
|
1094
|
+
this.l1ToL2MessageSource.getL2Tips().then((t)=>({
|
|
1095
|
+
proposed: t.proposed,
|
|
1096
|
+
checkpointed: t.checkpointed
|
|
1097
|
+
})),
|
|
811
1098
|
this.l2BlockSource.getPendingChainValidationStatus(),
|
|
812
|
-
this.l2BlockSource.
|
|
1099
|
+
this.l2BlockSource.getProposedCheckpointData()
|
|
813
1100
|
]);
|
|
814
|
-
const [worldState, l2Tips, p2p,
|
|
815
|
-
|
|
816
|
-
// as the world state can compute the new genesis block hash, but other components use the hardcoded constant.
|
|
817
|
-
// TODO(palla/mbps): Fix the above. All components should be able to handle dynamic genesis block hashes.
|
|
818
|
-
const result = l2Tips.proposed.number === 0 && worldState.number === 0 && p2p.number === 0 && l1ToL2MessageSource.number === 0 || worldState.hash === l2Tips.proposed.hash && p2p.hash === l2Tips.proposed.hash && l1ToL2MessageSource.hash === l2Tips.proposed.hash;
|
|
1101
|
+
const [worldState, l2Tips, p2p, l1ToL2MessageSourceTips, pendingChainValidationStatus, proposedCheckpointData] = syncedBlocks;
|
|
1102
|
+
const result = worldState.hash === l2Tips.proposed.hash && p2p.hash === l2Tips.proposed.hash && l1ToL2MessageSourceTips.proposed.hash === l2Tips.proposed.hash && l1ToL2MessageSourceTips.checkpointed.block.hash === l2Tips.checkpointed.block.hash && l1ToL2MessageSourceTips.checkpointed.checkpoint.hash === l2Tips.checkpointed.checkpoint.hash;
|
|
819
1103
|
if (!result) {
|
|
820
1104
|
this.log.debug(`Sequencer sync check failed`, {
|
|
821
1105
|
worldState,
|
|
822
1106
|
l2BlockSource: l2Tips.proposed,
|
|
823
1107
|
p2p,
|
|
824
|
-
|
|
1108
|
+
l1ToL2MessageSourceTips
|
|
825
1109
|
});
|
|
826
1110
|
return undefined;
|
|
827
1111
|
}
|
|
828
|
-
// Special case for genesis state
|
|
829
1112
|
const blockNumber = worldState.number;
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
blockNumber
|
|
836
|
-
|
|
837
|
-
hasProposedCheckpoint: false,
|
|
1113
|
+
const blockData = await this.l2BlockSource.getBlockData({
|
|
1114
|
+
number: blockNumber
|
|
1115
|
+
});
|
|
1116
|
+
if (!blockData) {
|
|
1117
|
+
this.log.warn(`Sequencer sync check failed: failed to get L2 block data ${blockNumber} from the archiver`, {
|
|
1118
|
+
blockNumber,
|
|
1119
|
+
l2Tips,
|
|
838
1120
|
syncedL2Slot,
|
|
839
|
-
|
|
1121
|
+
...args
|
|
1122
|
+
});
|
|
1123
|
+
return undefined;
|
|
1124
|
+
}
|
|
1125
|
+
// Refuse to build a checkpoint on top of a proposed block whose enclosing checkpoint was never
|
|
1126
|
+
// proposed. Under pipelining we may have received and reexecuted such a block locally — advancing
|
|
1127
|
+
// our world-state tip past the checkpointed tip — while the proposing node never published the
|
|
1128
|
+
// matching proposed checkpoint (e.g. it crashed before assembling it). Building on this orphan block
|
|
1129
|
+
// would fork the chain off a tip no other node can follow. The archiver prunes these orphan blocks
|
|
1130
|
+
// once their build slot ends; this guard is the correctness barrier during the grace window before.
|
|
1131
|
+
// `getProposedCheckpointData()` returns the latest proposed checkpoint payload, which is always
|
|
1132
|
+
// the leading one (a proposed entry is only stored beyond the confirmed frontier and is deleted
|
|
1133
|
+
// on confirmation). It carries no tip, so there is no tip-vs-payload split read to reconcile.
|
|
1134
|
+
if (blockData.checkpointNumber > l2Tips.checkpointed.checkpoint.number && proposedCheckpointData?.checkpointNumber !== blockData.checkpointNumber) {
|
|
1135
|
+
const logCtx = {
|
|
1136
|
+
blockCheckpointNumber: blockData.checkpointNumber,
|
|
1137
|
+
checkpointedCheckpointNumber: l2Tips.checkpointed.checkpoint.number,
|
|
1138
|
+
proposedCheckpointTipNumber: proposedCheckpointData?.checkpointNumber,
|
|
1139
|
+
blockNumber: blockData.header.getBlockNumber(),
|
|
1140
|
+
blockSlot: blockData.header.getSlot(),
|
|
1141
|
+
syncedL2Slot,
|
|
1142
|
+
...args
|
|
840
1143
|
};
|
|
1144
|
+
this.log.debug(`Waiting for proposed checkpoint to catch up with reexecuted block`, logCtx);
|
|
1145
|
+
return undefined;
|
|
841
1146
|
}
|
|
842
|
-
const
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
1147
|
+
const hasProposedCheckpoint = proposedCheckpointData !== undefined;
|
|
1148
|
+
// Check that the proposed checkpoint is indeed the parent of the checkpoint we'll be building
|
|
1149
|
+
// The checkpoint number to build is derived as blockData.checkpointNumber + 1
|
|
1150
|
+
if (proposedCheckpointData && proposedCheckpointData.checkpointNumber !== blockData.checkpointNumber) {
|
|
1151
|
+
this.log.warn(`Sequencer sync check failed: proposed checkpoint number mismatch`, {
|
|
1152
|
+
proposedCheckpointNumber: proposedCheckpointData.checkpointNumber,
|
|
1153
|
+
blockCheckpointNumber: blockData.checkpointNumber,
|
|
1154
|
+
syncedL2Slot,
|
|
1155
|
+
...args
|
|
1156
|
+
});
|
|
846
1157
|
return undefined;
|
|
847
1158
|
}
|
|
848
|
-
const hasProposedCheckpoint = l2Tips.proposedCheckpoint.checkpoint.number > l2Tips.checkpointed.checkpoint.number;
|
|
849
1159
|
return {
|
|
850
1160
|
blockData,
|
|
851
1161
|
blockNumber: blockData.header.getBlockNumber(),
|
|
@@ -919,30 +1229,24 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
919
1229
|
];
|
|
920
1230
|
}
|
|
921
1231
|
/**
|
|
922
|
-
* Tries to vote on slashing actions and governance
|
|
923
|
-
* This allows the sequencer to participate in governance/slashing votes even when it
|
|
924
|
-
|
|
1232
|
+
* Tries to vote on slashing actions and governance and to prune when we cannot build and are past the
|
|
1233
|
+
* block-building window. This allows the sequencer to participate in governance/slashing votes even when it
|
|
1234
|
+
* cannot build blocks, and to prune the pending chain so it can recover from bad data that is blocking sync.
|
|
1235
|
+
*/ async tryVoteAndPruneWhenCannotBuild(args) {
|
|
925
1236
|
const { slot, targetSlot } = args;
|
|
926
1237
|
// Prevent duplicate attempts in the same slot
|
|
927
|
-
if (this.
|
|
928
|
-
this.log.trace(`Already attempted
|
|
929
|
-
return;
|
|
930
|
-
}
|
|
931
|
-
// Check if we're past the max time for initializing a proposal
|
|
932
|
-
const secondsIntoSlot = this.getSecondsIntoSlot(slot);
|
|
933
|
-
const maxAllowedTime = this.timetable.getMaxAllowedTime(SequencerState.INITIALIZING_CHECKPOINT);
|
|
934
|
-
// If we haven't exceeded the time limit for initializing a proposal, don't proceed with voting
|
|
935
|
-
// We use INITIALIZING_PROPOSAL time limit because if we're past that, we can't build a block anyway
|
|
936
|
-
if (maxAllowedTime === undefined || secondsIntoSlot <= maxAllowedTime) {
|
|
937
|
-
this.log.trace(`Not attempting to vote since there is still time for block building`, {
|
|
938
|
-
secondsIntoSlot,
|
|
939
|
-
maxAllowedTime
|
|
940
|
-
});
|
|
1238
|
+
if (this.lastSlotForFallbackAction === slot) {
|
|
1239
|
+
this.log.trace(`Already attempted fallback actions in slot ${slot} (skipping)`);
|
|
941
1240
|
return;
|
|
942
1241
|
}
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
1242
|
+
// Vote-only actions do not give up the slot: if sync recovers, a later work-loop iteration can still build.
|
|
1243
|
+
// Under proposer pipelining the work loop reasons about the next L1 slot, so waiting for the target slot's
|
|
1244
|
+
// build-start deadline can miss the whole fallback window when the target advances with the clock.
|
|
1245
|
+
const nowSeconds = this.dateProvider.now() / 1000;
|
|
1246
|
+
const startDeadline = this.timetable.getBuildStartDeadline(targetSlot);
|
|
1247
|
+
this.log.trace(`Cannot build for slot ${slot}, checking for voting opportunities`, {
|
|
1248
|
+
nowSeconds,
|
|
1249
|
+
startDeadline
|
|
946
1250
|
});
|
|
947
1251
|
// Check if we're a proposer or proposal is open
|
|
948
1252
|
const [canPropose, proposer] = await this.checkCanPropose(targetSlot);
|
|
@@ -954,7 +1258,7 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
954
1258
|
return;
|
|
955
1259
|
}
|
|
956
1260
|
// Mark this slot as attempted
|
|
957
|
-
this.
|
|
1261
|
+
this.lastSlotForFallbackAction = slot;
|
|
958
1262
|
// Get a publisher for voting
|
|
959
1263
|
const { attestorAddress, publisher } = await this.publisherFactory.create(proposer);
|
|
960
1264
|
this.log.debug(`Attempting to vote despite sync failure at slot ${slot}`, {
|
|
@@ -965,33 +1269,65 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
965
1269
|
const voter = new CheckpointVoter(targetSlot, publisher, attestorAddress, this.validatorClient, this.slasherClient, this.l1Constants, this.config, this.metrics, this.log);
|
|
966
1270
|
const votesPromises = voter.enqueueVotes();
|
|
967
1271
|
const votes = await Promise.all(votesPromises);
|
|
968
|
-
if (
|
|
969
|
-
|
|
1272
|
+
// Even if we cannot build, try to prune so a stuck pending chain (e.g. bad data blocking sync) can
|
|
1273
|
+
// recover. prune() is permissionless, so it rides the same fallback multicall as the votes.
|
|
1274
|
+
const pruneEnqueued = await this.tryEnqueuePruneIfPrunable(targetSlot, publisher);
|
|
1275
|
+
// Bail if nothing to do
|
|
1276
|
+
if (votes.every((p)=>!p) && !pruneEnqueued) {
|
|
1277
|
+
this.log.debug(`Nothing to enqueue for slot ${slot} (no votes, not prunable)`);
|
|
970
1278
|
return;
|
|
971
1279
|
}
|
|
972
|
-
|
|
973
|
-
|
|
1280
|
+
const [governanceVoteEnqueued, slashingVoteEnqueued] = votes;
|
|
1281
|
+
this.log.info(`Submitting fallback requests in slot ${slot} despite sync failure`, {
|
|
1282
|
+
slot,
|
|
1283
|
+
pruneEnqueued,
|
|
1284
|
+
governanceVoteEnqueued: !!governanceVoteEnqueued,
|
|
1285
|
+
slashingVoteEnqueued: !!slashingVoteEnqueued
|
|
974
1286
|
});
|
|
975
|
-
|
|
1287
|
+
// Votes are EIP-712-signed for `targetSlot` (the pipelined slot in which the multicall is
|
|
1288
|
+
// expected to mine). Delay submission to the start of `targetSlot` so the tx mines in the
|
|
1289
|
+
// slot the votes were signed for. We fire-and-forget so we don't block the sequencer's
|
|
1290
|
+
// work loop while waiting for the target slot to start, but track it so stop() can drain it.
|
|
1291
|
+
const send = publisher.sendRequestsAt(targetSlot).catch((err)=>{
|
|
1292
|
+
this.log.error(`Failed to publish fallback requests despite sync failure for slot ${slot}`, err, {
|
|
1293
|
+
slot
|
|
1294
|
+
});
|
|
1295
|
+
});
|
|
1296
|
+
this.pendingRequests.trackRequest(send, ()=>publisher.interrupt());
|
|
1297
|
+
}
|
|
1298
|
+
async tryEnqueuePruneIfPrunable(targetSlot, publisher) {
|
|
1299
|
+
try {
|
|
1300
|
+
return await publisher.enqueuePruneIfPrunable(targetSlot);
|
|
1301
|
+
} catch (err) {
|
|
1302
|
+
this.log.error(`Failed to enqueue rollup prune for slot ${targetSlot}`, err, {
|
|
1303
|
+
targetSlot
|
|
1304
|
+
});
|
|
1305
|
+
return false;
|
|
1306
|
+
}
|
|
976
1307
|
}
|
|
977
1308
|
/**
|
|
978
1309
|
* Tries to vote on slashing actions and governance proposals when escape hatch is open.
|
|
979
1310
|
* This allows the sequencer to participate in voting without performing checkpoint proposal work.
|
|
980
1311
|
*/ async tryVoteWhenEscapeHatchOpen(args) {
|
|
981
|
-
const { slot, proposer } = args;
|
|
1312
|
+
const { slot, targetSlot, proposer } = args;
|
|
982
1313
|
// Prevent duplicate attempts in the same slot
|
|
983
|
-
if (this.
|
|
1314
|
+
if (this.lastSlotForFallbackAction === slot) {
|
|
984
1315
|
this.log.trace(`Already attempted to vote in slot ${slot} (escape hatch open, skipping)`);
|
|
985
1316
|
return;
|
|
986
1317
|
}
|
|
987
1318
|
// Mark this slot as attempted
|
|
988
|
-
this.
|
|
1319
|
+
this.lastSlotForFallbackAction = slot;
|
|
989
1320
|
const { attestorAddress, publisher } = await this.publisherFactory.create(proposer);
|
|
990
1321
|
this.log.debug(`Escape hatch open for slot ${slot}, attempting vote-only actions`, {
|
|
991
1322
|
slot,
|
|
1323
|
+
targetSlot,
|
|
992
1324
|
attestorAddress
|
|
993
1325
|
});
|
|
994
|
-
|
|
1326
|
+
// Under proposer pipelining, the multicall is expected to mine in `targetSlot` (slot + 1).
|
|
1327
|
+
// Governance and slashing votes are EIP-712-signed against the slot they will mine in, and the
|
|
1328
|
+
// L1 contract checks `msg.sender == getCurrentProposer()` using the mining slot. So we must
|
|
1329
|
+
// sign for `targetSlot` and delay submission to the start of `targetSlot`.
|
|
1330
|
+
const voter = new CheckpointVoter(targetSlot, publisher, attestorAddress, this.validatorClient, this.slasherClient, this.l1Constants, this.config, this.metrics, this.log);
|
|
995
1331
|
const votesPromises = voter.enqueueVotes();
|
|
996
1332
|
const votes = await Promise.all(votesPromises);
|
|
997
1333
|
if (votes.every((p)=>!p)) {
|
|
@@ -999,28 +1335,52 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
999
1335
|
return;
|
|
1000
1336
|
}
|
|
1001
1337
|
this.log.info(`Voting in slot ${slot} (escape hatch open)`, {
|
|
1002
|
-
slot
|
|
1338
|
+
slot,
|
|
1339
|
+
targetSlot
|
|
1340
|
+
});
|
|
1341
|
+
// Votes are EIP-712-signed for `targetSlot`. Delay submission to the start of `targetSlot` so
|
|
1342
|
+
// the multicall mines in the slot the votes were signed for; otherwise the L1 contract reads
|
|
1343
|
+
// `signaler = getCurrentProposer()` against the wrong slot and signature verification fails
|
|
1344
|
+
// silently inside Multicall3. Fire-and-forget so we don't block the sequencer's work loop while
|
|
1345
|
+
// waiting for the target slot to start, mirroring tryVoteAndPruneWhenCannotBuild, but tracked so
|
|
1346
|
+
// stop() can drain it.
|
|
1347
|
+
const send = publisher.sendRequestsAt(targetSlot).catch((err)=>{
|
|
1348
|
+
this.log.error(`Failed to publish escape-hatch votes for slot ${slot}`, err, {
|
|
1349
|
+
slot,
|
|
1350
|
+
targetSlot
|
|
1351
|
+
});
|
|
1003
1352
|
});
|
|
1004
|
-
|
|
1353
|
+
this.pendingRequests.trackRequest(send, ()=>publisher.interrupt());
|
|
1005
1354
|
}
|
|
1006
1355
|
/**
|
|
1007
1356
|
* Considers invalidating a block if the pending chain is invalid. Depends on how long the invalid block
|
|
1008
1357
|
* has been there without being invalidated and whether the sequencer is in the committee or not. We always
|
|
1009
1358
|
* have the proposer try to invalidate, but if they fail, the sequencers in the committee are expected to try,
|
|
1010
1359
|
* and if they fail, any sequencer will try as well.
|
|
1011
|
-
|
|
1012
|
-
|
|
1360
|
+
* @param pendingChainValidationStatus - The archiver's pending-chain validation status, authoritative on its own.
|
|
1361
|
+
* @param currentSlot - The wall-clock slot, used for committee lookup, the per-(checkpoint, slot) dedup guard, and logging.
|
|
1362
|
+
*/ async considerInvalidatingCheckpoint(pendingChainValidationStatus, currentSlot) {
|
|
1013
1363
|
if (pendingChainValidationStatus.valid) {
|
|
1014
1364
|
return;
|
|
1015
1365
|
}
|
|
1016
1366
|
const invalidCheckpointNumber = pendingChainValidationStatus.checkpoint.checkpointNumber;
|
|
1367
|
+
// Avoid re-running the committee lookup, simulation, and submission on every tick within a slot.
|
|
1368
|
+
// The guard is keyed by (checkpoint, slot) — so a different invalid checkpoint surfacing later in
|
|
1369
|
+
// the same slot is not suppressed — and is set only after a request is successfully simulated below,
|
|
1370
|
+
// so a transient simulation failure (or thresholds not yet met) still retries on the next tick.
|
|
1371
|
+
if (this.lastInvalidationAttempt?.slot === currentSlot && this.lastInvalidationAttempt.checkpointNumber === invalidCheckpointNumber) {
|
|
1372
|
+
this.log.trace(`Already attempted to invalidate checkpoint ${invalidCheckpointNumber} in slot ${currentSlot}`, {
|
|
1373
|
+
currentSlot,
|
|
1374
|
+
invalidCheckpointNumber
|
|
1375
|
+
});
|
|
1376
|
+
return;
|
|
1377
|
+
}
|
|
1017
1378
|
const invalidCheckpointTimestamp = pendingChainValidationStatus.checkpoint.timestamp;
|
|
1018
1379
|
const timeSinceChainInvalid = this.dateProvider.nowInSeconds() - Number(invalidCheckpointTimestamp);
|
|
1019
1380
|
const ourValidatorAddresses = this.validatorClient.getValidatorAddresses();
|
|
1020
1381
|
const { secondsBeforeInvalidatingBlockAsCommitteeMember, secondsBeforeInvalidatingBlockAsNonCommitteeMember } = this.config;
|
|
1021
1382
|
const logData = {
|
|
1022
1383
|
invalidL1Timestamp: invalidCheckpointTimestamp,
|
|
1023
|
-
syncedL2Slot,
|
|
1024
1384
|
invalidCheckpoint: pendingChainValidationStatus.checkpoint,
|
|
1025
1385
|
secondsBeforeInvalidatingBlockAsCommitteeMember,
|
|
1026
1386
|
secondsBeforeInvalidatingBlockAsNonCommitteeMember,
|
|
@@ -1054,6 +1414,12 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
1054
1414
|
this.log.warn(`Failed to simulate invalidate checkpoint`, logData);
|
|
1055
1415
|
return;
|
|
1056
1416
|
}
|
|
1417
|
+
// We produced a valid invalidation request; record it so further ticks within this slot skip the
|
|
1418
|
+
// committee lookup, simulation, and submission above for this same invalid checkpoint.
|
|
1419
|
+
this.lastInvalidationAttempt = {
|
|
1420
|
+
slot: currentSlot,
|
|
1421
|
+
checkpointNumber: invalidCheckpointNumber
|
|
1422
|
+
};
|
|
1057
1423
|
this.log.info(invalidateAsCommitteeMember ? `Invalidating checkpoint ${invalidCheckpointNumber} as committee member` : `Invalidating checkpoint ${invalidCheckpointNumber} as non-committee member`, logData);
|
|
1058
1424
|
publisher.enqueueInvalidateCheckpoint(invalidateCheckpoint);
|
|
1059
1425
|
if (!this.config.fishermanMode) {
|
|
@@ -1089,12 +1455,12 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
1089
1455
|
}))
|
|
1090
1456
|
});
|
|
1091
1457
|
}
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
const
|
|
1097
|
-
return Number((this.dateProvider.now() / 1000 -
|
|
1458
|
+
/**
|
|
1459
|
+
* Wall-clock seconds elapsed since the build-frame start of the given target slot
|
|
1460
|
+
* (`now − getBuildFrameStart(targetSlot)`). May be negative if called before the build frame opens.
|
|
1461
|
+
*/ getSecondsIntoBuildFrame(targetSlot) {
|
|
1462
|
+
const buildFrameStart = this.timetable.getBuildFrameStart(targetSlot);
|
|
1463
|
+
return Number((this.dateProvider.now() / 1000 - buildFrameStart).toFixed(3));
|
|
1098
1464
|
}
|
|
1099
1465
|
get aztecSlotDuration() {
|
|
1100
1466
|
return this.l1Constants.slotDuration;
|
|
@@ -1117,7 +1483,4 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
1117
1483
|
getConfig() {
|
|
1118
1484
|
return this.config;
|
|
1119
1485
|
}
|
|
1120
|
-
get l1PublishingTime() {
|
|
1121
|
-
return this.config.l1PublishingTime ?? this.l1Constants.ethereumSlotDuration;
|
|
1122
|
-
}
|
|
1123
1486
|
}
|