@aztec/sequencer-client 6.0.0-nightly.20260604 → 6.0.0-nightly.20260721
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 +27 -27
- package/dest/client/sequencer-client.d.ts +16 -3
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +17 -12
- package/dest/config.d.ts +6 -2
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +23 -14
- package/dest/global_variable_builder/fee_predictor.d.ts +1 -1
- package/dest/global_variable_builder/fee_predictor.d.ts.map +1 -1
- package/dest/global_variable_builder/fee_predictor.js +11 -1
- package/dest/global_variable_builder/fee_provider.d.ts +1 -1
- package/dest/global_variable_builder/fee_provider.d.ts.map +1 -1
- package/dest/global_variable_builder/fee_provider.js +27 -5
- package/dest/global_variable_builder/global_builder.d.ts +3 -16
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +2 -25
- 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 +5 -1
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +11 -1
- 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 +48 -8
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -1
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.js +68 -1
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts +2 -2
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts.map +1 -1
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.js +4 -2
- package/dest/publisher/l1_tx_failed_store/index.d.ts +2 -2
- package/dest/publisher/l1_tx_failed_store/index.d.ts.map +1 -1
- package/dest/publisher/l1_tx_failed_store/index.js +1 -0
- package/dest/publisher/sequencer-publisher.d.ts +34 -6
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +364 -60
- 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 +5 -3
- package/dest/sequencer/automine/automine_factory.d.ts.map +1 -1
- package/dest/sequencer/automine/automine_factory.js +2 -1
- package/dest/sequencer/automine/automine_sequencer.d.ts +43 -5
- package/dest/sequencer/automine/automine_sequencer.d.ts.map +1 -1
- package/dest/sequencer/automine/automine_sequencer.js +199 -18
- 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 +28 -15
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_proposal_job.js +140 -96
- package/dest/sequencer/events.d.ts +16 -5
- package/dest/sequencer/events.d.ts.map +1 -1
- package/dest/sequencer/index.d.ts +1 -3
- package/dest/sequencer/index.d.ts.map +1 -1
- package/dest/sequencer/index.js +0 -2
- 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 +110 -36
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +330 -174
- 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 +18 -1
- package/package.json +30 -28
- package/src/client/sequencer-client.ts +20 -13
- package/src/config.ts +25 -12
- package/src/global_variable_builder/fee_predictor.ts +11 -1
- package/src/global_variable_builder/fee_provider.ts +27 -5
- package/src/global_variable_builder/global_builder.ts +2 -34
- package/src/index.ts +1 -10
- package/src/publisher/config.ts +22 -1
- package/src/publisher/l1_to_l2_messaging.ts +85 -0
- package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +114 -7
- package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +4 -3
- package/src/publisher/l1_tx_failed_store/index.ts +1 -1
- package/src/publisher/sequencer-publisher.ts +385 -71
- package/src/publisher/write_json.ts +78 -0
- package/src/sequencer/automine/README.md +18 -4
- package/src/sequencer/automine/automine_factory.ts +8 -1
- package/src/sequencer/automine/automine_sequencer.ts +221 -20
- package/src/sequencer/automine/index.ts +6 -0
- package/src/sequencer/checkpoint_proposal_job.ts +163 -111
- package/src/sequencer/events.ts +16 -4
- package/src/sequencer/index.ts +0 -2
- package/src/sequencer/requests_tracker.ts +43 -0
- package/src/sequencer/sequencer.ts +361 -187
- package/src/test/index.ts +2 -2
- package/src/test/utils.ts +33 -0
- package/dest/sequencer/chain_state_overrides.d.ts +0 -61
- package/dest/sequencer/chain_state_overrides.d.ts.map +0 -1
- package/dest/sequencer/chain_state_overrides.js +0 -98
- package/dest/sequencer/timetable.d.ts +0 -98
- package/dest/sequencer/timetable.d.ts.map +0 -1
- package/dest/sequencer/timetable.js +0 -227
- package/src/sequencer/chain_state_overrides.ts +0 -162
- package/src/sequencer/timetable.ts +0 -288
|
@@ -379,23 +379,24 @@ import { merge, omit, pick } from '@aztec/foundation/collection';
|
|
|
379
379
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
380
380
|
import { createLogger } from '@aztec/foundation/log';
|
|
381
381
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
382
|
-
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';
|
|
383
385
|
import { SequencerConfigSchema } from '@aztec/stdlib/interfaces/server';
|
|
384
386
|
import { pickFromSchema } from '@aztec/stdlib/schemas';
|
|
385
|
-
import {
|
|
387
|
+
import { buildProposerTimetable } from '@aztec/stdlib/timetable';
|
|
386
388
|
import { Attributes, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
387
389
|
import EventEmitter from 'node:events';
|
|
388
390
|
import { DefaultSequencerConfig } from '../config.js';
|
|
389
|
-
import { buildCheckpointSimulationOverridesPlan } from './chain_state_overrides.js';
|
|
390
391
|
import { CheckpointProposalJob } from './checkpoint_proposal_job.js';
|
|
391
392
|
import { CheckpointProposalJobMetrics } from './checkpoint_proposal_job_metrics.js';
|
|
392
393
|
import { CheckpointVoter } from './checkpoint_voter.js';
|
|
393
|
-
import { SequencerInterruptedError
|
|
394
|
+
import { SequencerInterruptedError } from './errors.js';
|
|
394
395
|
import { SequencerMetrics } from './metrics.js';
|
|
395
|
-
import {
|
|
396
|
+
import { RequestsTracker } from './requests_tracker.js';
|
|
396
397
|
import { SequencerState } from './utils.js';
|
|
397
398
|
export { SequencerState };
|
|
398
|
-
_dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpointProposal'), _dec2 = trackSpan('
|
|
399
|
+
_dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpointProposal'), _dec2 = trackSpan('Sequencer.tryVoteAndPruneWhenCannotBuild', ({ slot })=>({
|
|
399
400
|
[Attributes.SLOT_NUMBER]: slot
|
|
400
401
|
})), _dec3 = trackSpan('Sequencer.tryVoteWhenEscapeHatchOpen', ({ slot })=>({
|
|
401
402
|
[Attributes.SLOT_NUMBER]: slot
|
|
@@ -438,7 +439,7 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
438
439
|
[
|
|
439
440
|
_dec2,
|
|
440
441
|
2,
|
|
441
|
-
"
|
|
442
|
+
"tryVoteAndPruneWhenCannotBuild"
|
|
442
443
|
],
|
|
443
444
|
[
|
|
444
445
|
_dec3,
|
|
@@ -450,22 +451,34 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
450
451
|
runningPromise;
|
|
451
452
|
state;
|
|
452
453
|
stateSlotNumber;
|
|
453
|
-
stateEnteredAtMs;
|
|
454
|
+
/** Wall-clock time (ms, via the date provider) at which the current state was entered. */ stateEnteredAtMs;
|
|
454
455
|
metrics;
|
|
455
456
|
checkpointProposalJobMetrics;
|
|
456
457
|
stateLog;
|
|
457
|
-
/** The last slot for which we attempted to perform our
|
|
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;
|
|
458
461
|
/** The last slot for which we logged "no committee" warning, to avoid spam */ lastSlotForNoCommitteeWarning;
|
|
459
462
|
/** The last slot for which we triggered a checkpoint proposal job, to prevent duplicate attempts. */ lastSlotForCheckpointProposalJob;
|
|
460
463
|
/** Last successful checkpoint proposed */ lastCheckpointProposed;
|
|
461
464
|
/** The last epoch for which we logged strategy comparison in fisherman mode. */ lastEpochForStrategyComparison;
|
|
462
465
|
/** The last checkpoint proposal job, tracked so we can await its pending L1 submission during shutdown. */ lastCheckpointProposalJob;
|
|
463
|
-
/**
|
|
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;
|
|
464
476
|
/** Config for the sequencer */ config;
|
|
465
477
|
signatureContext;
|
|
466
478
|
constructor(publisherFactory, validatorClient, globalsBuilder, p2pClient, worldState, slasherClient, l2BlockSource, l1ToL2MessageSource, checkpointsBuilder, l1Constants, dateProvider, epochCache, rollupContract, config, telemetry = getTelemetryClient(), log = createLogger('sequencer')){
|
|
467
|
-
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.
|
|
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;
|
|
468
480
|
this.stateLog = log.createChild('state');
|
|
481
|
+
this.stateEnteredAtMs = this.dateProvider.now();
|
|
469
482
|
// Add [FISHERMAN] prefix to logger if in fisherman mode
|
|
470
483
|
if (config.fishermanMode) {
|
|
471
484
|
this.log = log.createChild('[FISHERMAN]');
|
|
@@ -478,24 +491,120 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
478
491
|
this.checkpointProposalJobMetrics = new CheckpointProposalJobMetrics(telemetry);
|
|
479
492
|
this.updateConfig(config);
|
|
480
493
|
}
|
|
481
|
-
/**
|
|
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) {
|
|
482
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;
|
|
483
515
|
this.log.info(`Updated sequencer config`, omit(filteredConfig, 'txPublicSetupAllowListExtend'));
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
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
|
+
}
|
|
494
589
|
}
|
|
495
590
|
/** Initializes the sequencer (precomputes tables). Takes about 3s. */ init() {
|
|
496
591
|
getKzg();
|
|
497
592
|
}
|
|
498
|
-
/**
|
|
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
|
+
}
|
|
499
608
|
this.runningPromise = new RunningPromise(this.safeWork.bind(this), this.log, this.config.sequencerPollingIntervalMS);
|
|
500
609
|
this.setState(SequencerState.IDLE, undefined, {
|
|
501
610
|
force: true
|
|
@@ -506,38 +615,64 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
506
615
|
/** Triggers an immediate run of the sequencer, bypassing the polling interval. */ trigger() {
|
|
507
616
|
return this.runningPromise?.trigger();
|
|
508
617
|
}
|
|
509
|
-
/**
|
|
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
|
+
}
|
|
510
629
|
this.log.info(`Stopping sequencer`);
|
|
511
630
|
this.setState(SequencerState.STOPPING, undefined, {
|
|
512
631
|
force: true
|
|
513
632
|
});
|
|
633
|
+
this.lastCheckpointProposalJob?.interrupt();
|
|
514
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.
|
|
515
639
|
await this.runningPromise?.stop();
|
|
516
|
-
|
|
640
|
+
this.pendingRequests.interruptRequests();
|
|
641
|
+
await this.pendingRequests.awaitRequests();
|
|
517
642
|
this.setState(SequencerState.STOPPED, undefined, {
|
|
518
643
|
force: true
|
|
519
644
|
});
|
|
520
645
|
this.log.info('Stopped sequencer');
|
|
521
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
|
+
}
|
|
522
668
|
/** Main sequencer loop with a try/catch */ async safeWork() {
|
|
523
669
|
try {
|
|
524
670
|
await this.work();
|
|
525
671
|
} catch (err) {
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
// No need to alert if we just didn't get to start in time
|
|
531
|
-
this.log.debug(err.message, {
|
|
532
|
-
now: this.dateProvider.nowInSeconds()
|
|
533
|
-
});
|
|
534
|
-
} else {
|
|
535
|
-
// Re-throw other errors
|
|
536
|
-
this.emit('checkpoint-error', {
|
|
537
|
-
error: err
|
|
538
|
-
});
|
|
539
|
-
throw err;
|
|
540
|
-
}
|
|
672
|
+
this.emit('checkpoint-error', {
|
|
673
|
+
error: err
|
|
674
|
+
});
|
|
675
|
+
throw err;
|
|
541
676
|
} finally{
|
|
542
677
|
this.setState(SequencerState.IDLE, undefined);
|
|
543
678
|
}
|
|
@@ -594,10 +729,8 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
594
729
|
* This is the initial step in the main loop.
|
|
595
730
|
* @returns CheckpointProposalJob if successful, undefined if we are not yet synced or are not the proposer.
|
|
596
731
|
*/ async prepareCheckpointProposal(slot, targetSlot, epoch, targetEpoch, ts, nowSeconds) {
|
|
597
|
-
// Check we have not already processed this target slot (cheapest check)
|
|
598
|
-
|
|
599
|
-
// running against actual time (eg when we use sandbox-style automining)
|
|
600
|
-
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) {
|
|
601
734
|
this.log.trace(`Target slot ${targetSlot} has already been processed`);
|
|
602
735
|
return undefined;
|
|
603
736
|
}
|
|
@@ -614,26 +747,16 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
614
747
|
});
|
|
615
748
|
return undefined;
|
|
616
749
|
}
|
|
617
|
-
//
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
if (!syncedTo) {
|
|
623
|
-
await this.tryVoteWhenSyncFails({
|
|
624
|
-
slot,
|
|
625
|
-
targetSlot,
|
|
626
|
-
ts
|
|
627
|
-
});
|
|
628
|
-
return undefined;
|
|
629
|
-
}
|
|
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);
|
|
630
755
|
// If escape hatch is open for the target epoch, do not start checkpoint proposal work and do not attempt invalidations.
|
|
631
756
|
// Still perform governance/slashing voting (as proposer) once per slot.
|
|
632
757
|
// When pipelining, we check the target epoch (slot+1's epoch) since that's the epoch we're building for.
|
|
633
758
|
const isEscapeHatchOpen = await this.epochCache.isEscapeHatchOpen(targetEpoch);
|
|
634
759
|
if (isEscapeHatchOpen) {
|
|
635
|
-
this.setState(SequencerState.PROPOSER_CHECK, slot);
|
|
636
|
-
const [canPropose, proposer] = await this.checkCanPropose(targetSlot);
|
|
637
760
|
if (canPropose) {
|
|
638
761
|
await this.tryVoteWhenEscapeHatchOpen({
|
|
639
762
|
slot,
|
|
@@ -649,6 +772,57 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
649
772
|
}
|
|
650
773
|
return undefined;
|
|
651
774
|
}
|
|
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
|
+
// We are the proposer, the escape hatch is closed, and we have time before the build start deadline.
|
|
818
|
+
// Now run the full sync check before building.
|
|
819
|
+
const syncedTo = await this.checkSync({
|
|
820
|
+
ts,
|
|
821
|
+
slot
|
|
822
|
+
});
|
|
823
|
+
if (!syncedTo) {
|
|
824
|
+
return undefined;
|
|
825
|
+
}
|
|
652
826
|
// Next checkpoint follows from the last synced one
|
|
653
827
|
const checkpointNumber = CheckpointNumber(syncedTo.checkpointNumber + 1);
|
|
654
828
|
const logCtx = {
|
|
@@ -660,14 +834,8 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
660
834
|
checkpointNumber,
|
|
661
835
|
isPendingChainValid: pick(syncedTo.pendingChainValidationStatus, 'valid', 'reason', 'invalidIndex')
|
|
662
836
|
};
|
|
663
|
-
//
|
|
664
|
-
this.setState(SequencerState.PROPOSER_CHECK,
|
|
665
|
-
const [canPropose, proposer] = await this.checkCanPropose(targetSlot);
|
|
666
|
-
// If we are not a proposer check if we should invalidate an invalid checkpoint, and bail
|
|
667
|
-
if (!canPropose) {
|
|
668
|
-
await this.considerInvalidatingCheckpoint(syncedTo, slot);
|
|
669
|
-
return undefined;
|
|
670
|
-
}
|
|
837
|
+
// We are the synced proposer within the build window; enter the proposer-check state and build.
|
|
838
|
+
this.setState(SequencerState.PROPOSER_CHECK, targetSlot);
|
|
671
839
|
// Guard: don't exceed 1-deep pipeline. Without a proposed checkpoint, we can only build
|
|
672
840
|
// confirmed + 1. With a proposed checkpoint, we can build confirmed + 2.
|
|
673
841
|
const confirmedCkpt = syncedTo.checkpointedCheckpointNumber;
|
|
@@ -812,12 +980,10 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
812
980
|
proposer
|
|
813
981
|
});
|
|
814
982
|
// Create and return the checkpoint proposal job
|
|
815
|
-
return this.createCheckpointProposalJob(
|
|
983
|
+
return this.createCheckpointProposalJob(targetSlot, targetEpoch, checkpointNumber, syncedTo.blockNumber, syncedTo.checkpointedCheckpointNumber, proposer, publisher, attestorAddress, invalidateCheckpoint, syncedTo.proposedCheckpointData);
|
|
816
984
|
}
|
|
817
|
-
createCheckpointProposalJob(
|
|
818
|
-
return new CheckpointProposalJob(
|
|
819
|
-
timeReferenceSlot
|
|
820
|
-
}), this.tracer, this.log.getBindings(), proposedCheckpointData);
|
|
985
|
+
createCheckpointProposalJob(targetSlot, targetEpoch, checkpointNumber, syncedToBlockNumber, checkpointedCheckpointNumber, proposer, publisher, attestorAddress, invalidateCheckpoint, proposedCheckpointData) {
|
|
986
|
+
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);
|
|
821
987
|
}
|
|
822
988
|
/**
|
|
823
989
|
* Returns the current sequencer state.
|
|
@@ -825,11 +991,12 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
825
991
|
return this.state;
|
|
826
992
|
}
|
|
827
993
|
/**
|
|
828
|
-
* Internal helper for setting the sequencer state
|
|
994
|
+
* Internal helper for setting the sequencer state. Pure: sets the state, emits `state-changed`, and
|
|
995
|
+
* records metrics. Timing deadlines are queried explicitly at the relevant call sites, not gated here.
|
|
829
996
|
* @param proposedState - The new state to transition to.
|
|
830
|
-
* @param slotNumber - The
|
|
997
|
+
* @param slotNumber - The target slot being proposed for, emitted as `targetSlot` on the event payload
|
|
998
|
+
* and used to anchor `secondsIntoBuildFrame`. Undefined for lifecycle states with no associated slot.
|
|
831
999
|
* @param force - Whether to force the transition even if the sequencer is stopped.
|
|
832
|
-
* @param timeReferenceSlot - The slot to use for deadline checks when it differs from the logical slot.
|
|
833
1000
|
*/ setState(proposedState, slotNumber, opts = {}) {
|
|
834
1001
|
if (this.state === SequencerState.STOPPING && proposedState !== SequencerState.STOPPED && !opts.force) {
|
|
835
1002
|
this.log.warn(`Cannot set sequencer to ${proposedState} as it is stopping.`);
|
|
@@ -839,16 +1006,13 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
839
1006
|
this.log.warn(`Cannot set sequencer from ${this.state} to ${proposedState} as it is stopped.`);
|
|
840
1007
|
return;
|
|
841
1008
|
}
|
|
842
|
-
|
|
843
|
-
const timeReferenceSlot = opts.timeReferenceSlot ?? slotNumber;
|
|
844
|
-
if (timeReferenceSlot !== undefined) {
|
|
845
|
-
secondsIntoSlot = this.getSecondsIntoSlot(timeReferenceSlot);
|
|
846
|
-
this.timetable.assertTimeLeft(proposedState, secondsIntoSlot);
|
|
847
|
-
}
|
|
1009
|
+
const secondsIntoBuildFrame = slotNumber !== undefined ? this.getSecondsIntoBuildFrame(slotNumber) : undefined;
|
|
848
1010
|
const oldState = this.state;
|
|
849
1011
|
const oldStateSlotNumber = this.stateSlotNumber;
|
|
850
1012
|
const stateChanged = proposedState !== oldState;
|
|
851
|
-
|
|
1013
|
+
// Wall-clock time spent in the previous state: the delta between consecutive state-changing setState
|
|
1014
|
+
// calls, read from the date provider so it tracks simulated time under a test/manual clock.
|
|
1015
|
+
const transitionAtMs = this.dateProvider.now();
|
|
852
1016
|
const stateDurationMs = transitionAtMs - this.stateEnteredAtMs;
|
|
853
1017
|
const boringStates = [
|
|
854
1018
|
SequencerState.IDLE,
|
|
@@ -859,9 +1023,8 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
859
1023
|
oldState,
|
|
860
1024
|
newState: proposedState,
|
|
861
1025
|
slotNumber,
|
|
862
|
-
timeReferenceSlot,
|
|
863
1026
|
stateSlotNumber: oldStateSlotNumber,
|
|
864
|
-
|
|
1027
|
+
secondsIntoBuildFrame,
|
|
865
1028
|
...stateChanged && {
|
|
866
1029
|
stateDurationMs: Math.ceil(stateDurationMs)
|
|
867
1030
|
}
|
|
@@ -869,9 +1032,8 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
869
1032
|
this.emit('state-changed', {
|
|
870
1033
|
oldState,
|
|
871
1034
|
newState: proposedState,
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
timeReferenceSlot
|
|
1035
|
+
secondsIntoBuildFrame,
|
|
1036
|
+
targetSlot: slotNumber
|
|
875
1037
|
});
|
|
876
1038
|
if (stateChanged) {
|
|
877
1039
|
this.metrics.recordStateDuration(stateDurationMs, oldState);
|
|
@@ -903,8 +1065,7 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
903
1065
|
})),
|
|
904
1066
|
this.l2BlockSource.getL2Tips().then((t)=>({
|
|
905
1067
|
proposed: t.proposed,
|
|
906
|
-
checkpointed: t.checkpointed
|
|
907
|
-
proposedCheckpoint: t.proposedCheckpoint
|
|
1068
|
+
checkpointed: t.checkpointed
|
|
908
1069
|
})),
|
|
909
1070
|
this.p2pClient.getStatus().then((p2p)=>p2p.syncedToL2Block),
|
|
910
1071
|
this.l1ToL2MessageSource.getL2Tips().then((t)=>({
|
|
@@ -944,45 +1105,23 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
944
1105
|
// matching proposed checkpoint (e.g. it crashed before assembling it). Building on this orphan block
|
|
945
1106
|
// would fork the chain off a tip no other node can follow. The archiver prunes these orphan blocks
|
|
946
1107
|
// once their build slot ends; this guard is the correctness barrier during the grace window before.
|
|
947
|
-
|
|
1108
|
+
// `getProposedCheckpointData()` returns the latest proposed checkpoint payload, which is always
|
|
1109
|
+
// the leading one (a proposed entry is only stored beyond the confirmed frontier and is deleted
|
|
1110
|
+
// on confirmation). It carries no tip, so there is no tip-vs-payload split read to reconcile.
|
|
1111
|
+
if (blockData.checkpointNumber > l2Tips.checkpointed.checkpoint.number && proposedCheckpointData?.checkpointNumber !== blockData.checkpointNumber) {
|
|
948
1112
|
const logCtx = {
|
|
949
1113
|
blockCheckpointNumber: blockData.checkpointNumber,
|
|
950
1114
|
checkpointedCheckpointNumber: l2Tips.checkpointed.checkpoint.number,
|
|
951
|
-
proposedCheckpointTipNumber:
|
|
952
|
-
proposedCheckpointDataNumber: proposedCheckpointData?.checkpointNumber,
|
|
1115
|
+
proposedCheckpointTipNumber: proposedCheckpointData?.checkpointNumber,
|
|
953
1116
|
blockNumber: blockData.header.getBlockNumber(),
|
|
954
1117
|
blockSlot: blockData.header.getSlot(),
|
|
955
1118
|
syncedL2Slot,
|
|
956
1119
|
...args
|
|
957
1120
|
};
|
|
958
|
-
|
|
959
|
-
// slot, so a world-state tip sitting in an as-yet-unproposed checkpoint is the expected steady state
|
|
960
|
-
// until that checkpoint is due. Only treat it as abnormal — and warn — once the checkpoint is overdue
|
|
961
|
-
// by the same deadline the archiver uses to prune the orphan block (see pruneOrphanProposedBlocks).
|
|
962
|
-
// Before then this is normal pipelining and we wait it out quietly.
|
|
963
|
-
if (this.isProposedCheckpointOverdue(blockData.header.getSlot())) {
|
|
964
|
-
this.log.warn(`Sequencer sync check failed: proposed block has no matching proposed checkpoint`, logCtx);
|
|
965
|
-
} else {
|
|
966
|
-
this.log.debug(`Waiting for proposed checkpoint to catch up with reexecuted block`, logCtx);
|
|
967
|
-
}
|
|
968
|
-
return undefined;
|
|
969
|
-
}
|
|
970
|
-
const hasProposedCheckpoint = l2Tips.proposedCheckpoint.checkpoint.number > l2Tips.checkpointed.checkpoint.number;
|
|
971
|
-
// The l2Tips and proposedCheckpointData reads above come from independent archiver snapshots
|
|
972
|
-
// (a JS-side tips cache vs. a direct store read on `#proposedCheckpoints`). A concurrent archiver
|
|
973
|
-
// write that mutates both can be observed split, leaving us with `hasProposedCheckpoint=true` but
|
|
974
|
-
// no proposedCheckpointData (or one whose number doesn't match the tip). Refuse to proceed in that
|
|
975
|
-
// window — the next checkSync tick will see a coherent snapshot.
|
|
976
|
-
if (hasProposedCheckpoint && (!proposedCheckpointData || proposedCheckpointData.checkpointNumber !== l2Tips.proposedCheckpoint.checkpoint.number)) {
|
|
977
|
-
this.log.warn(`Sequencer sync check failed: inconsistent proposed-checkpoint state`, {
|
|
978
|
-
proposedCheckpointTipNumber: l2Tips.proposedCheckpoint.checkpoint.number,
|
|
979
|
-
checkpointedTipNumber: l2Tips.checkpointed.checkpoint.number,
|
|
980
|
-
proposedCheckpointDataNumber: proposedCheckpointData?.checkpointNumber,
|
|
981
|
-
syncedL2Slot,
|
|
982
|
-
...args
|
|
983
|
-
});
|
|
1121
|
+
this.log.debug(`Waiting for proposed checkpoint to catch up with reexecuted block`, logCtx);
|
|
984
1122
|
return undefined;
|
|
985
1123
|
}
|
|
1124
|
+
const hasProposedCheckpoint = proposedCheckpointData !== undefined;
|
|
986
1125
|
// Check that the proposed checkpoint is indeed the parent of the checkpoint we'll be building
|
|
987
1126
|
// The checkpoint number to build is derived as blockData.checkpointNumber + 1
|
|
988
1127
|
if (proposedCheckpointData && proposedCheckpointData.checkpointNumber !== blockData.checkpointNumber) {
|
|
@@ -1007,18 +1146,6 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
1007
1146
|
};
|
|
1008
1147
|
}
|
|
1009
1148
|
/**
|
|
1010
|
-
* Whether the enclosing checkpoint of a reexecuted block is overdue: past the deadline by which a
|
|
1011
|
-
* well-behaved proposer should have published it. Mirrors the archiver's orphan-prune deadline (the
|
|
1012
|
-
* start of the slot after the block's build slot, plus a grace period) so the sequencer only warns
|
|
1013
|
-
* about a missing proposed checkpoint once the archiver itself would prune the orphan block. The grace
|
|
1014
|
-
* is derived from the block build duration the same way the archiver defaults it at node wiring.
|
|
1015
|
-
*/ isProposedCheckpointOverdue(blockSlot) {
|
|
1016
|
-
const expectedBySlot = SlotNumber(Number(blockSlot) - PROPOSER_PIPELINING_SLOT_OFFSET + 1);
|
|
1017
|
-
const graceSeconds = this.config.blockDurationMs !== undefined ? Math.ceil(this.config.blockDurationMs / 1000) : MIN_EXECUTION_TIME;
|
|
1018
|
-
const expectedByTime = getTimestampForSlot(expectedBySlot, this.l1Constants) + BigInt(graceSeconds);
|
|
1019
|
-
return BigInt(this.dateProvider.nowInSeconds()) >= expectedByTime;
|
|
1020
|
-
}
|
|
1021
|
-
/**
|
|
1022
1149
|
* Checks if we are the proposer for the next slot.
|
|
1023
1150
|
* @returns True if we can propose, and the proposer address (undefined if anyone can propose)
|
|
1024
1151
|
*/ async checkCanPropose(targetSlot) {
|
|
@@ -1079,30 +1206,24 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
1079
1206
|
];
|
|
1080
1207
|
}
|
|
1081
1208
|
/**
|
|
1082
|
-
* Tries to vote on slashing actions and governance
|
|
1083
|
-
* This allows the sequencer to participate in governance/slashing votes even when it
|
|
1084
|
-
|
|
1209
|
+
* Tries to vote on slashing actions and governance and to prune when we cannot build and are past the
|
|
1210
|
+
* block-building window. This allows the sequencer to participate in governance/slashing votes even when it
|
|
1211
|
+
* cannot build blocks, and to prune the pending chain so it can recover from bad data that is blocking sync.
|
|
1212
|
+
*/ async tryVoteAndPruneWhenCannotBuild(args) {
|
|
1085
1213
|
const { slot, targetSlot } = args;
|
|
1086
1214
|
// Prevent duplicate attempts in the same slot
|
|
1087
|
-
if (this.
|
|
1088
|
-
this.log.trace(`Already attempted
|
|
1089
|
-
return;
|
|
1090
|
-
}
|
|
1091
|
-
// Check if we're past the max time for initializing a proposal
|
|
1092
|
-
const secondsIntoSlot = this.getSecondsIntoSlot(slot);
|
|
1093
|
-
const maxAllowedTime = this.timetable.getMaxAllowedTime(SequencerState.INITIALIZING_CHECKPOINT);
|
|
1094
|
-
// If we haven't exceeded the time limit for initializing a proposal, don't proceed with voting
|
|
1095
|
-
// We use INITIALIZING_PROPOSAL time limit because if we're past that, we can't build a block anyway
|
|
1096
|
-
if (maxAllowedTime === undefined || secondsIntoSlot <= maxAllowedTime) {
|
|
1097
|
-
this.log.trace(`Not attempting to vote since there is still time for block building`, {
|
|
1098
|
-
secondsIntoSlot,
|
|
1099
|
-
maxAllowedTime
|
|
1100
|
-
});
|
|
1215
|
+
if (this.lastSlotForFallbackAction === slot) {
|
|
1216
|
+
this.log.trace(`Already attempted fallback actions in slot ${slot} (skipping)`);
|
|
1101
1217
|
return;
|
|
1102
1218
|
}
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1219
|
+
// Vote-only actions do not give up the slot: if sync recovers, a later work-loop iteration can still build.
|
|
1220
|
+
// Under proposer pipelining the work loop reasons about the next L1 slot, so waiting for the target slot's
|
|
1221
|
+
// build-start deadline can miss the whole fallback window when the target advances with the clock.
|
|
1222
|
+
const nowSeconds = this.dateProvider.now() / 1000;
|
|
1223
|
+
const startDeadline = this.timetable.getBuildStartDeadline(targetSlot);
|
|
1224
|
+
this.log.trace(`Cannot build for slot ${slot}, checking for voting opportunities`, {
|
|
1225
|
+
nowSeconds,
|
|
1226
|
+
startDeadline
|
|
1106
1227
|
});
|
|
1107
1228
|
// Check if we're a proposer or proposal is open
|
|
1108
1229
|
const [canPropose, proposer] = await this.checkCanPropose(targetSlot);
|
|
@@ -1114,7 +1235,7 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
1114
1235
|
return;
|
|
1115
1236
|
}
|
|
1116
1237
|
// Mark this slot as attempted
|
|
1117
|
-
this.
|
|
1238
|
+
this.lastSlotForFallbackAction = slot;
|
|
1118
1239
|
// Get a publisher for voting
|
|
1119
1240
|
const { attestorAddress, publisher } = await this.publisherFactory.create(proposer);
|
|
1120
1241
|
this.log.debug(`Attempting to vote despite sync failure at slot ${slot}`, {
|
|
@@ -1125,22 +1246,41 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
1125
1246
|
const voter = new CheckpointVoter(targetSlot, publisher, attestorAddress, this.validatorClient, this.slasherClient, this.l1Constants, this.config, this.metrics, this.log);
|
|
1126
1247
|
const votesPromises = voter.enqueueVotes();
|
|
1127
1248
|
const votes = await Promise.all(votesPromises);
|
|
1128
|
-
if (
|
|
1129
|
-
|
|
1249
|
+
// Even if we cannot build, try to prune so a stuck pending chain (e.g. bad data blocking sync) can
|
|
1250
|
+
// recover. prune() is permissionless, so it rides the same fallback multicall as the votes.
|
|
1251
|
+
const pruneEnqueued = await this.tryEnqueuePruneIfPrunable(targetSlot, publisher);
|
|
1252
|
+
// Bail if nothing to do
|
|
1253
|
+
if (votes.every((p)=>!p) && !pruneEnqueued) {
|
|
1254
|
+
this.log.debug(`Nothing to enqueue for slot ${slot} (no votes, not prunable)`);
|
|
1130
1255
|
return;
|
|
1131
1256
|
}
|
|
1132
|
-
|
|
1133
|
-
|
|
1257
|
+
const [governanceVoteEnqueued, slashingVoteEnqueued] = votes;
|
|
1258
|
+
this.log.info(`Submitting fallback requests in slot ${slot} despite sync failure`, {
|
|
1259
|
+
slot,
|
|
1260
|
+
pruneEnqueued,
|
|
1261
|
+
governanceVoteEnqueued: !!governanceVoteEnqueued,
|
|
1262
|
+
slashingVoteEnqueued: !!slashingVoteEnqueued
|
|
1134
1263
|
});
|
|
1135
1264
|
// Votes are EIP-712-signed for `targetSlot` (the pipelined slot in which the multicall is
|
|
1136
1265
|
// expected to mine). Delay submission to the start of `targetSlot` so the tx mines in the
|
|
1137
1266
|
// slot the votes were signed for. We fire-and-forget so we don't block the sequencer's
|
|
1138
|
-
// work loop while waiting for the target slot to start.
|
|
1139
|
-
|
|
1140
|
-
this.log.error(`Failed to publish
|
|
1267
|
+
// work loop while waiting for the target slot to start, but track it so stop() can drain it.
|
|
1268
|
+
const send = publisher.sendRequestsAt(targetSlot).catch((err)=>{
|
|
1269
|
+
this.log.error(`Failed to publish fallback requests despite sync failure for slot ${slot}`, err, {
|
|
1141
1270
|
slot
|
|
1142
1271
|
});
|
|
1143
1272
|
});
|
|
1273
|
+
this.pendingRequests.trackRequest(send, ()=>publisher.interrupt());
|
|
1274
|
+
}
|
|
1275
|
+
async tryEnqueuePruneIfPrunable(targetSlot, publisher) {
|
|
1276
|
+
try {
|
|
1277
|
+
return await publisher.enqueuePruneIfPrunable(targetSlot);
|
|
1278
|
+
} catch (err) {
|
|
1279
|
+
this.log.error(`Failed to enqueue rollup prune for slot ${targetSlot}`, err, {
|
|
1280
|
+
targetSlot
|
|
1281
|
+
});
|
|
1282
|
+
return false;
|
|
1283
|
+
}
|
|
1144
1284
|
}
|
|
1145
1285
|
/**
|
|
1146
1286
|
* Tries to vote on slashing actions and governance proposals when escape hatch is open.
|
|
@@ -1148,12 +1288,12 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
1148
1288
|
*/ async tryVoteWhenEscapeHatchOpen(args) {
|
|
1149
1289
|
const { slot, targetSlot, proposer } = args;
|
|
1150
1290
|
// Prevent duplicate attempts in the same slot
|
|
1151
|
-
if (this.
|
|
1291
|
+
if (this.lastSlotForFallbackAction === slot) {
|
|
1152
1292
|
this.log.trace(`Already attempted to vote in slot ${slot} (escape hatch open, skipping)`);
|
|
1153
1293
|
return;
|
|
1154
1294
|
}
|
|
1155
1295
|
// Mark this slot as attempted
|
|
1156
|
-
this.
|
|
1296
|
+
this.lastSlotForFallbackAction = slot;
|
|
1157
1297
|
const { attestorAddress, publisher } = await this.publisherFactory.create(proposer);
|
|
1158
1298
|
this.log.debug(`Escape hatch open for slot ${slot}, attempting vote-only actions`, {
|
|
1159
1299
|
slot,
|
|
@@ -1179,32 +1319,45 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
1179
1319
|
// the multicall mines in the slot the votes were signed for; otherwise the L1 contract reads
|
|
1180
1320
|
// `signaler = getCurrentProposer()` against the wrong slot and signature verification fails
|
|
1181
1321
|
// silently inside Multicall3. Fire-and-forget so we don't block the sequencer's work loop while
|
|
1182
|
-
// waiting for the target slot to start, mirroring
|
|
1183
|
-
|
|
1322
|
+
// waiting for the target slot to start, mirroring tryVoteAndPruneWhenCannotBuild, but tracked so
|
|
1323
|
+
// stop() can drain it.
|
|
1324
|
+
const send = publisher.sendRequestsAt(targetSlot).catch((err)=>{
|
|
1184
1325
|
this.log.error(`Failed to publish escape-hatch votes for slot ${slot}`, err, {
|
|
1185
1326
|
slot,
|
|
1186
1327
|
targetSlot
|
|
1187
1328
|
});
|
|
1188
1329
|
});
|
|
1330
|
+
this.pendingRequests.trackRequest(send, ()=>publisher.interrupt());
|
|
1189
1331
|
}
|
|
1190
1332
|
/**
|
|
1191
1333
|
* Considers invalidating a block if the pending chain is invalid. Depends on how long the invalid block
|
|
1192
1334
|
* has been there without being invalidated and whether the sequencer is in the committee or not. We always
|
|
1193
1335
|
* have the proposer try to invalidate, but if they fail, the sequencers in the committee are expected to try,
|
|
1194
1336
|
* and if they fail, any sequencer will try as well.
|
|
1195
|
-
|
|
1196
|
-
|
|
1337
|
+
* @param pendingChainValidationStatus - The archiver's pending-chain validation status, authoritative on its own.
|
|
1338
|
+
* @param currentSlot - The wall-clock slot, used for committee lookup, the per-(checkpoint, slot) dedup guard, and logging.
|
|
1339
|
+
*/ async considerInvalidatingCheckpoint(pendingChainValidationStatus, currentSlot) {
|
|
1197
1340
|
if (pendingChainValidationStatus.valid) {
|
|
1198
1341
|
return;
|
|
1199
1342
|
}
|
|
1200
1343
|
const invalidCheckpointNumber = pendingChainValidationStatus.checkpoint.checkpointNumber;
|
|
1344
|
+
// Avoid re-running the committee lookup, simulation, and submission on every tick within a slot.
|
|
1345
|
+
// The guard is keyed by (checkpoint, slot) — so a different invalid checkpoint surfacing later in
|
|
1346
|
+
// the same slot is not suppressed — and is set only after a request is successfully simulated below,
|
|
1347
|
+
// so a transient simulation failure (or thresholds not yet met) still retries on the next tick.
|
|
1348
|
+
if (this.lastInvalidationAttempt?.slot === currentSlot && this.lastInvalidationAttempt.checkpointNumber === invalidCheckpointNumber) {
|
|
1349
|
+
this.log.trace(`Already attempted to invalidate checkpoint ${invalidCheckpointNumber} in slot ${currentSlot}`, {
|
|
1350
|
+
currentSlot,
|
|
1351
|
+
invalidCheckpointNumber
|
|
1352
|
+
});
|
|
1353
|
+
return;
|
|
1354
|
+
}
|
|
1201
1355
|
const invalidCheckpointTimestamp = pendingChainValidationStatus.checkpoint.timestamp;
|
|
1202
1356
|
const timeSinceChainInvalid = this.dateProvider.nowInSeconds() - Number(invalidCheckpointTimestamp);
|
|
1203
1357
|
const ourValidatorAddresses = this.validatorClient.getValidatorAddresses();
|
|
1204
1358
|
const { secondsBeforeInvalidatingBlockAsCommitteeMember, secondsBeforeInvalidatingBlockAsNonCommitteeMember } = this.config;
|
|
1205
1359
|
const logData = {
|
|
1206
1360
|
invalidL1Timestamp: invalidCheckpointTimestamp,
|
|
1207
|
-
syncedL2Slot,
|
|
1208
1361
|
invalidCheckpoint: pendingChainValidationStatus.checkpoint,
|
|
1209
1362
|
secondsBeforeInvalidatingBlockAsCommitteeMember,
|
|
1210
1363
|
secondsBeforeInvalidatingBlockAsNonCommitteeMember,
|
|
@@ -1238,6 +1391,12 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
1238
1391
|
this.log.warn(`Failed to simulate invalidate checkpoint`, logData);
|
|
1239
1392
|
return;
|
|
1240
1393
|
}
|
|
1394
|
+
// We produced a valid invalidation request; record it so further ticks within this slot skip the
|
|
1395
|
+
// committee lookup, simulation, and submission above for this same invalid checkpoint.
|
|
1396
|
+
this.lastInvalidationAttempt = {
|
|
1397
|
+
slot: currentSlot,
|
|
1398
|
+
checkpointNumber: invalidCheckpointNumber
|
|
1399
|
+
};
|
|
1241
1400
|
this.log.info(invalidateAsCommitteeMember ? `Invalidating checkpoint ${invalidCheckpointNumber} as committee member` : `Invalidating checkpoint ${invalidCheckpointNumber} as non-committee member`, logData);
|
|
1242
1401
|
publisher.enqueueInvalidateCheckpoint(invalidateCheckpoint);
|
|
1243
1402
|
if (!this.config.fishermanMode) {
|
|
@@ -1273,12 +1432,12 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
1273
1432
|
}))
|
|
1274
1433
|
});
|
|
1275
1434
|
}
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
const
|
|
1281
|
-
return Number((this.dateProvider.now() / 1000 -
|
|
1435
|
+
/**
|
|
1436
|
+
* Wall-clock seconds elapsed since the build-frame start of the given target slot
|
|
1437
|
+
* (`now − getBuildFrameStart(targetSlot)`). May be negative if called before the build frame opens.
|
|
1438
|
+
*/ getSecondsIntoBuildFrame(targetSlot) {
|
|
1439
|
+
const buildFrameStart = this.timetable.getBuildFrameStart(targetSlot);
|
|
1440
|
+
return Number((this.dateProvider.now() / 1000 - buildFrameStart).toFixed(3));
|
|
1282
1441
|
}
|
|
1283
1442
|
get aztecSlotDuration() {
|
|
1284
1443
|
return this.l1Constants.slotDuration;
|
|
@@ -1301,7 +1460,4 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
1301
1460
|
getConfig() {
|
|
1302
1461
|
return this.config;
|
|
1303
1462
|
}
|
|
1304
|
-
get l1PublishingTime() {
|
|
1305
|
-
return this.config.l1PublishingTime ?? this.l1Constants.ethereumSlotDuration;
|
|
1306
|
-
}
|
|
1307
1463
|
}
|