@aztec/sequencer-client 0.0.1-commit.993d240 → 0.0.1-commit.9a89641
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 +40 -41
- 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 +18 -14
- package/dest/config.d.ts +9 -4
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +29 -15
- 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 +39 -10
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +403 -75
- 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 +209 -19
- 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 +158 -117
- package/dest/sequencer/events.d.ts +16 -4
- 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/missing_committee.d.ts +72 -0
- package/dest/sequencer/missing_committee.d.ts.map +1 -0
- package/dest/sequencer/missing_committee.js +139 -0
- 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 +113 -28
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +352 -162
- 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 +29 -28
- package/src/client/sequencer-client.ts +20 -14
- package/src/config.ts +32 -16
- 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 +430 -86
- package/src/publisher/write_json.ts +78 -0
- package/src/sequencer/README.md +16 -6
- package/src/sequencer/automine/README.md +18 -4
- package/src/sequencer/automine/automine_factory.ts +8 -1
- package/src/sequencer/automine/automine_sequencer.ts +229 -21
- package/src/sequencer/automine/index.ts +6 -0
- package/src/sequencer/checkpoint_proposal_job.ts +177 -132
- package/src/sequencer/events.ts +16 -3
- package/src/sequencer/index.ts +0 -2
- package/src/sequencer/missing_committee.ts +192 -0
- package/src/sequencer/requests_tracker.ts +43 -0
- package/src/sequencer/sequencer.ts +382 -176
- 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 -101
- package/dest/sequencer/timetable.d.ts.map +0 -1
- package/dest/sequencer/timetable.js +0 -231
- package/src/sequencer/chain_state_overrides.ts +0 -162
- package/src/sequencer/timetable.ts +0 -295
|
@@ -379,22 +379,25 @@ 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';
|
|
387
|
+
import { buildProposerTimetable } from '@aztec/stdlib/timetable';
|
|
385
388
|
import { Attributes, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
386
389
|
import EventEmitter from 'node:events';
|
|
387
390
|
import { DefaultSequencerConfig } from '../config.js';
|
|
388
|
-
import { buildCheckpointSimulationOverridesPlan } from './chain_state_overrides.js';
|
|
389
391
|
import { CheckpointProposalJob } from './checkpoint_proposal_job.js';
|
|
390
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 { logMissingCommittee } from './missing_committee.js';
|
|
397
|
+
import { RequestsTracker } from './requests_tracker.js';
|
|
395
398
|
import { SequencerState } from './utils.js';
|
|
396
399
|
export { SequencerState };
|
|
397
|
-
_dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpointProposal'), _dec2 = trackSpan('
|
|
400
|
+
_dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpointProposal'), _dec2 = trackSpan('Sequencer.tryVoteAndPruneWhenCannotBuild', ({ slot })=>({
|
|
398
401
|
[Attributes.SLOT_NUMBER]: slot
|
|
399
402
|
})), _dec3 = trackSpan('Sequencer.tryVoteWhenEscapeHatchOpen', ({ slot })=>({
|
|
400
403
|
[Attributes.SLOT_NUMBER]: slot
|
|
@@ -437,7 +440,7 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
437
440
|
[
|
|
438
441
|
_dec2,
|
|
439
442
|
2,
|
|
440
|
-
"
|
|
443
|
+
"tryVoteAndPruneWhenCannotBuild"
|
|
441
444
|
],
|
|
442
445
|
[
|
|
443
446
|
_dec3,
|
|
@@ -449,22 +452,34 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
449
452
|
runningPromise;
|
|
450
453
|
state;
|
|
451
454
|
stateSlotNumber;
|
|
452
|
-
stateEnteredAtMs;
|
|
455
|
+
/** Wall-clock time (ms, via the date provider) at which the current state was entered. */ stateEnteredAtMs;
|
|
453
456
|
metrics;
|
|
454
457
|
checkpointProposalJobMetrics;
|
|
455
458
|
stateLog;
|
|
456
|
-
/** The last slot for which we attempted to perform our
|
|
457
|
-
/** The
|
|
459
|
+
/** The last slot for which we attempted to perform our fallback duties (votes and/or prune) with degraded block production */ lastSlotForFallbackAction;
|
|
460
|
+
/** The (checkpoint, slot) of the last invalidation request we successfully simulated, to prevent
|
|
461
|
+
* re-simulating and re-submitting the same invalidation across the many ticks within a single slot. */ lastInvalidationAttempt;
|
|
462
|
+
/** The last epoch for which we logged a "no committee" diagnostic, to avoid per-slot log spam. */ lastEpochForNoCommitteeLog;
|
|
458
463
|
/** The last slot for which we triggered a checkpoint proposal job, to prevent duplicate attempts. */ lastSlotForCheckpointProposalJob;
|
|
459
464
|
/** Last successful checkpoint proposed */ lastCheckpointProposed;
|
|
460
465
|
/** The last epoch for which we logged strategy comparison in fisherman mode. */ lastEpochForStrategyComparison;
|
|
461
466
|
/** The last checkpoint proposal job, tracked so we can await its pending L1 submission during shutdown. */ lastCheckpointProposalJob;
|
|
462
|
-
/**
|
|
467
|
+
/**
|
|
468
|
+
* In-flight fire-and-forget requests that {@link stop} interrupts and drains, and {@link pause} awaits
|
|
469
|
+
* untouched: the checkpoint proposal jobs' backgrounded L1 submissions (each job is handed this shared
|
|
470
|
+
* tracker) plus the sequencer's own fallback submissions (votes/prune when we cannot build, or
|
|
471
|
+
* escape-hatch votes). Each fallback send is gated by its wrapper publisher's interruptible target-slot
|
|
472
|
+
* sleep; the tracked interrupt wakes that sleep so the send short-circuits without publishing. A wrapper
|
|
473
|
+
* is created for a single send and is never restarted, so once interrupted its sleeper can never publish
|
|
474
|
+
* a stale-slot tx, even after the pooled publishers are restarted by a later {@link start}.
|
|
475
|
+
*/ pendingRequests;
|
|
476
|
+
/** Proposer schedule and block sub-slot timetable for the sequencer, rebuilt on every config update. */ timetable;
|
|
463
477
|
/** Config for the sequencer */ config;
|
|
464
478
|
signatureContext;
|
|
465
479
|
constructor(publisherFactory, validatorClient, globalsBuilder, p2pClient, worldState, slasherClient, l2BlockSource, l1ToL2MessageSource, checkpointsBuilder, l1Constants, dateProvider, epochCache, rollupContract, config, telemetry = getTelemetryClient(), log = createLogger('sequencer')){
|
|
466
|
-
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.
|
|
480
|
+
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;
|
|
467
481
|
this.stateLog = log.createChild('state');
|
|
482
|
+
this.stateEnteredAtMs = this.dateProvider.now();
|
|
468
483
|
// Add [FISHERMAN] prefix to logger if in fisherman mode
|
|
469
484
|
if (config.fishermanMode) {
|
|
470
485
|
this.log = log.createChild('[FISHERMAN]');
|
|
@@ -477,25 +492,120 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
477
492
|
this.checkpointProposalJobMetrics = new CheckpointProposalJobMetrics(telemetry);
|
|
478
493
|
this.updateConfig(config);
|
|
479
494
|
}
|
|
480
|
-
/**
|
|
495
|
+
/**
|
|
496
|
+
* Updates sequencer config by the defined values and rebuilds the timetable.
|
|
497
|
+
*
|
|
498
|
+
* The merged config is validated against a candidate before being committed: {@link buildTimetable} may
|
|
499
|
+
* reject the candidate (invalid timing geometry, or per-block allocation multipliers below the network
|
|
500
|
+
* minimums). On rejection we leave `this.config` and `this.timetable` untouched and rethrow, so a bad update
|
|
501
|
+
* never leaves the sequencer running with a rejected config and a stale timetable.
|
|
502
|
+
*/ updateConfig(config) {
|
|
481
503
|
const filteredConfig = pickFromSchema(config, SequencerConfigSchema);
|
|
504
|
+
const candidate = merge(this.config, filteredConfig);
|
|
505
|
+
let timetable;
|
|
506
|
+
try {
|
|
507
|
+
timetable = this.buildTimetable(candidate);
|
|
508
|
+
} catch (err) {
|
|
509
|
+
this.log.warn(`Rejecting sequencer config update: ${err.message}`, {
|
|
510
|
+
rejectedConfig: omit(filteredConfig, 'txPublicSetupAllowListExtend')
|
|
511
|
+
});
|
|
512
|
+
throw err;
|
|
513
|
+
}
|
|
514
|
+
this.config = candidate;
|
|
515
|
+
this.timetable = timetable;
|
|
482
516
|
this.log.info(`Updated sequencer config`, omit(filteredConfig, 'txPublicSetupAllowListExtend'));
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
517
|
+
}
|
|
518
|
+
/**
|
|
519
|
+
* Builds the proposer timetable from the given config and L1 constants via the shared
|
|
520
|
+
* {@link buildProposerTimetable} helper, so the sequencer derives the same blocks-per-checkpoint as the p2p
|
|
521
|
+
* layer and `getNodeInfo`. The fast local/e2e profile and budget clamping happen inside
|
|
522
|
+
* {@link ProposerTimetable}.
|
|
523
|
+
*
|
|
524
|
+
* Throws if the timing geometry is invalid or the per-block allocation multipliers are below the network
|
|
525
|
+
* minimums; callers must treat a throw as a rejected config and not commit it.
|
|
526
|
+
*/ buildTimetable(config) {
|
|
527
|
+
const timetable = buildProposerTimetable(config, this.l1Constants);
|
|
528
|
+
const maxNumberOfBlocks = timetable.getMaxBlocksPerCheckpoint();
|
|
529
|
+
this.log.info(`Sequencer timetable initialized with ${maxNumberOfBlocks} blocks per slot`, {
|
|
530
|
+
aztecSlotDuration: timetable.aztecSlotDuration,
|
|
531
|
+
ethereumSlotDuration: timetable.ethereumSlotDuration,
|
|
532
|
+
blockDuration: timetable.blockDuration,
|
|
533
|
+
minBlockDuration: timetable.minBlockDuration,
|
|
534
|
+
p2pPropagationTime: timetable.p2pPropagationTime,
|
|
535
|
+
checkpointProposalPrepareTime: timetable.checkpointProposalPrepareTime,
|
|
536
|
+
maxNumberOfBlocks
|
|
537
|
+
});
|
|
538
|
+
this.assertConfigMeetsNetworkTxLimits(config, maxNumberOfBlocks);
|
|
539
|
+
return timetable;
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* Checks this node's configured per-block allocation against the network admission limit. A node
|
|
543
|
+
* advertises and admits txs up to the limit derived from the network-minimum multipliers (see
|
|
544
|
+
* {@link computeNetworkTxGasLimits}).
|
|
545
|
+
*
|
|
546
|
+
* Fails startup (and runtime config updates) only when the configured per-block allocation *multipliers*
|
|
547
|
+
* (`perBlockAllocationMultiplier` / `perBlockDAAllocationMultiplier`) are below the network minimums: such
|
|
548
|
+
* a node would accept txs over RPC/gossip that its builder can never pack into a block regardless of block
|
|
549
|
+
* size. Operators may configure a higher (more generous) multiplier, but not a lower one.
|
|
550
|
+
*
|
|
551
|
+
* When the multipliers meet the floor but an absolute per-block gas cap (`maxDABlockGas` / `maxL2BlockGas`)
|
|
552
|
+
* shrinks the builder's effective grant below the network limit, this is legitimate operator
|
|
553
|
+
* restrictiveness — the node simply builds smaller blocks and such txs stay in the pool for other
|
|
554
|
+
* proposers — so we only log a warning rather than failing startup. Restrictive tx-count caps
|
|
555
|
+
* (`maxTxsPerBlock` / `maxTxsPerCheckpoint`) can likewise make the builder skip admitted txs; they are
|
|
556
|
+
* intentionally not modeled here for the same reason.
|
|
557
|
+
*/ assertConfigMeetsNetworkTxLimits(config, maxBlocksPerCheckpoint) {
|
|
558
|
+
// Mirror CheckpointBuilder.capLimitsByCheckpointBudgets: DA falls back to the general multiplier.
|
|
559
|
+
const l2Multiplier = config.perBlockAllocationMultiplier;
|
|
560
|
+
const daMultiplier = config.perBlockDAAllocationMultiplier ?? l2Multiplier;
|
|
561
|
+
// The allocation is monotonic in the multiplier, so a multiplier at or above the network minimum
|
|
562
|
+
// guarantees the builder grants at least the network admission limit. Checking the multipliers directly
|
|
563
|
+
// is sufficient (and strictly more conservative than modeling the resulting gas grant).
|
|
564
|
+
if (daMultiplier < MIN_PER_BLOCK_DA_ALLOCATION_MULTIPLIER) {
|
|
565
|
+
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.`);
|
|
566
|
+
}
|
|
567
|
+
if (l2Multiplier < MIN_PER_BLOCK_ALLOCATION_MULTIPLIER) {
|
|
568
|
+
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.`);
|
|
569
|
+
}
|
|
570
|
+
// Absolute per-block gas caps below the network admission limit are legitimate operator restrictiveness:
|
|
571
|
+
// the node simply builds smaller blocks and such txs stay in the pool for other proposers. Warn only.
|
|
572
|
+
const networkLimit = computeNetworkTxGasLimits({
|
|
573
|
+
maxBlocksPerCheckpoint,
|
|
574
|
+
manaCheckpointBudget: this.l1Constants.rollupManaLimit
|
|
575
|
+
});
|
|
576
|
+
if (config.maxDABlockGas !== undefined && config.maxDABlockGas < networkLimit.daGas) {
|
|
577
|
+
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.`, {
|
|
578
|
+
maxDABlockGas: config.maxDABlockGas,
|
|
579
|
+
networkDaGas: networkLimit.daGas,
|
|
580
|
+
maxBlocksPerCheckpoint
|
|
581
|
+
});
|
|
582
|
+
}
|
|
583
|
+
if (config.maxL2BlockGas !== undefined && config.maxL2BlockGas < networkLimit.l2Gas) {
|
|
584
|
+
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.`, {
|
|
585
|
+
maxL2BlockGas: config.maxL2BlockGas,
|
|
586
|
+
networkL2Gas: networkLimit.l2Gas,
|
|
587
|
+
maxBlocksPerCheckpoint
|
|
588
|
+
});
|
|
589
|
+
}
|
|
494
590
|
}
|
|
495
591
|
/** Initializes the sequencer (precomputes tables). Takes about 3s. */ init() {
|
|
496
592
|
getKzg();
|
|
497
593
|
}
|
|
498
|
-
/**
|
|
594
|
+
/**
|
|
595
|
+
* Starts (or restarts) the sequencer and moves it to the IDLE state. Idempotent: a start while already
|
|
596
|
+
* running is a no-op, so it never orphans the previous poll loop. A start while STOPPING throws, since the
|
|
597
|
+
* in-flight stop would mark the fresh loop's state STOPPED and orphan it — silently doing nothing would
|
|
598
|
+
* leave the caller believing the sequencer is running when it is on its way to STOPPED. Safe to call after
|
|
599
|
+
* a previous {@link stop} has resolved; the caller must also restart the publishers (see
|
|
600
|
+
* {@link SequencerClient.start}) so L1 publishing is re-enabled.
|
|
601
|
+
*/ start() {
|
|
602
|
+
if (this.state === SequencerState.STOPPING) {
|
|
603
|
+
throw new Error('Cannot start sequencer while it is stopping');
|
|
604
|
+
}
|
|
605
|
+
if (this.runningPromise?.isRunning()) {
|
|
606
|
+
this.log.warn('Attempted to start sequencer that is already running');
|
|
607
|
+
return;
|
|
608
|
+
}
|
|
499
609
|
this.runningPromise = new RunningPromise(this.safeWork.bind(this), this.log, this.config.sequencerPollingIntervalMS);
|
|
500
610
|
this.setState(SequencerState.IDLE, undefined, {
|
|
501
611
|
force: true
|
|
@@ -506,38 +616,64 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
506
616
|
/** Triggers an immediate run of the sequencer, bypassing the polling interval. */ trigger() {
|
|
507
617
|
return this.runningPromise?.trigger();
|
|
508
618
|
}
|
|
509
|
-
/**
|
|
619
|
+
/**
|
|
620
|
+
* Stops the sequencer from building blocks and moves it to STOPPED state, interrupting the in-flight
|
|
621
|
+
* work() iteration and its pending L1 submissions for a fast shutdown, then draining before returning.
|
|
622
|
+
* Idempotent: a second call while already stopped or stopping is a no-op. Lifecycle calls are expected
|
|
623
|
+
* to be serialized by the caller. For a restartable pause that lets in-flight work finish untouched
|
|
624
|
+
* (e.g. around a test clock warp), use {@link pause} instead.
|
|
625
|
+
*/ async stop() {
|
|
626
|
+
if (this.state === SequencerState.STOPPED || this.state === SequencerState.STOPPING) {
|
|
627
|
+
this.log.debug(`Sequencer already ${this.state.toLowerCase()}, ignoring stop`);
|
|
628
|
+
return;
|
|
629
|
+
}
|
|
510
630
|
this.log.info(`Stopping sequencer`);
|
|
511
631
|
this.setState(SequencerState.STOPPING, undefined, {
|
|
512
632
|
force: true
|
|
513
633
|
});
|
|
634
|
+
this.lastCheckpointProposalJob?.interrupt();
|
|
514
635
|
await this.publisherFactory.stopAll();
|
|
636
|
+
// Stop the poll loop and await the in-flight work() iteration. work() registers its fire-and-forget
|
|
637
|
+
// requests synchronously before returning, so once the loop has stopped, pendingRequests holds every
|
|
638
|
+
// request that will ever exist. Interrupting any earlier could miss a request registered by the last
|
|
639
|
+
// in-flight iteration.
|
|
515
640
|
await this.runningPromise?.stop();
|
|
516
|
-
|
|
641
|
+
this.pendingRequests.interruptRequests();
|
|
642
|
+
await this.pendingRequests.awaitRequests();
|
|
517
643
|
this.setState(SequencerState.STOPPED, undefined, {
|
|
518
644
|
force: true
|
|
519
645
|
});
|
|
520
646
|
this.log.info('Stopped sequencer');
|
|
521
647
|
}
|
|
648
|
+
/**
|
|
649
|
+
* Gracefully pauses block production so the sequencer can later be resumed with {@link start}: halts the
|
|
650
|
+
* poll loop and waits for the in-flight work() iteration and every pending L1 submission / fallback send
|
|
651
|
+
* to finish, without interrupting them. No interrupt lands mid-build, so no spurious checkpoint-error is
|
|
652
|
+
* emitted and no enqueued checkpoint is dropped. Deliberately does not stop inner services (validator/HA
|
|
653
|
+
* signer, publishers), so the slashing-protection store stays open and the sequencer stays restartable.
|
|
654
|
+
* Used by tests that pause sequencers around an L1 clock warp. Idempotent.
|
|
655
|
+
*/ async pause() {
|
|
656
|
+
if (!this.runningPromise?.isRunning()) {
|
|
657
|
+
this.log.debug('Sequencer not running, ignoring pause');
|
|
658
|
+
return;
|
|
659
|
+
}
|
|
660
|
+
this.log.info('Pausing sequencer');
|
|
661
|
+
// Halt the poll loop and let the in-flight iteration finish naturally — no interrupt, and no STOPPING
|
|
662
|
+
// state, since entering STOPPING would make the iteration's own setState calls throw and fail it.
|
|
663
|
+
// work() registers its fire-and-forget requests synchronously before returning, so once the loop has
|
|
664
|
+
// stopped pendingRequests holds every request that will ever exist; awaiting it lets them all finish.
|
|
665
|
+
await this.runningPromise.stop();
|
|
666
|
+
await this.pendingRequests.awaitRequests();
|
|
667
|
+
this.log.info('Paused sequencer');
|
|
668
|
+
}
|
|
522
669
|
/** Main sequencer loop with a try/catch */ async safeWork() {
|
|
523
670
|
try {
|
|
524
671
|
await this.work();
|
|
525
672
|
} 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
|
-
}
|
|
673
|
+
this.emit('checkpoint-error', {
|
|
674
|
+
error: err
|
|
675
|
+
});
|
|
676
|
+
throw err;
|
|
541
677
|
} finally{
|
|
542
678
|
this.setState(SequencerState.IDLE, undefined);
|
|
543
679
|
}
|
|
@@ -579,7 +715,7 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
579
715
|
}
|
|
580
716
|
/** Returns slot and target slot from a single clock snapshot. */ getSlotContextInNextL1Slot() {
|
|
581
717
|
const { slot, ts, nowSeconds, epoch } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
582
|
-
const targetSlot = SlotNumber(slot +
|
|
718
|
+
const targetSlot = SlotNumber(slot + PROPOSER_PIPELINING_SLOT_OFFSET);
|
|
583
719
|
return {
|
|
584
720
|
slot,
|
|
585
721
|
targetSlot,
|
|
@@ -594,10 +730,8 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
594
730
|
* This is the initial step in the main loop.
|
|
595
731
|
* @returns CheckpointProposalJob if successful, undefined if we are not yet synced or are not the proposer.
|
|
596
732
|
*/ 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) {
|
|
733
|
+
// Check we have not already processed this target slot (cheapest check).
|
|
734
|
+
if (this.lastSlotForCheckpointProposalJob && this.lastSlotForCheckpointProposalJob >= targetSlot) {
|
|
601
735
|
this.log.trace(`Target slot ${targetSlot} has already been processed`);
|
|
602
736
|
return undefined;
|
|
603
737
|
}
|
|
@@ -614,26 +748,16 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
614
748
|
});
|
|
615
749
|
return undefined;
|
|
616
750
|
}
|
|
617
|
-
//
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
if (!syncedTo) {
|
|
623
|
-
await this.tryVoteWhenSyncFails({
|
|
624
|
-
slot,
|
|
625
|
-
targetSlot,
|
|
626
|
-
ts
|
|
627
|
-
});
|
|
628
|
-
return undefined;
|
|
629
|
-
}
|
|
751
|
+
// Cheap proposer check first: most nodes are not the proposer for most slots, so gate the
|
|
752
|
+
// expensive multi-subsystem checkSync (and the rest of the build path) behind it. Computed once
|
|
753
|
+
// here and reused for the escape-hatch voting path below. No setState/timing gate on this path:
|
|
754
|
+
// the build-start deadline gate runs only on the proposer build path after a successful checkSync.
|
|
755
|
+
const [canPropose, proposer] = await this.checkCanPropose(targetSlot);
|
|
630
756
|
// If escape hatch is open for the target epoch, do not start checkpoint proposal work and do not attempt invalidations.
|
|
631
757
|
// Still perform governance/slashing voting (as proposer) once per slot.
|
|
632
758
|
// When pipelining, we check the target epoch (slot+1's epoch) since that's the epoch we're building for.
|
|
633
759
|
const isEscapeHatchOpen = await this.epochCache.isEscapeHatchOpen(targetEpoch);
|
|
634
760
|
if (isEscapeHatchOpen) {
|
|
635
|
-
this.setState(SequencerState.PROPOSER_CHECK, slot);
|
|
636
|
-
const [canPropose, proposer] = await this.checkCanPropose(targetSlot);
|
|
637
761
|
if (canPropose) {
|
|
638
762
|
await this.tryVoteWhenEscapeHatchOpen({
|
|
639
763
|
slot,
|
|
@@ -649,6 +773,57 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
649
773
|
}
|
|
650
774
|
return undefined;
|
|
651
775
|
}
|
|
776
|
+
// If we are not the proposer, check whether we should invalidate an invalid pending chain (a
|
|
777
|
+
// liveness backstop) and bail before any sync work or build-timing gate. This reads only the
|
|
778
|
+
// archiver's pending-chain validation status, which is authoritative on its own, instead of
|
|
779
|
+
// running the full sync check. Wrapped in try/catch because this leaner path skips the broader
|
|
780
|
+
// proposed-checkpoint/tip coherence screen that checkSync applied, so transient archiver
|
|
781
|
+
// incoherence surfaces as a quiet skip rather than a work-loop error.
|
|
782
|
+
if (!canPropose) {
|
|
783
|
+
try {
|
|
784
|
+
const pendingChainValidationStatus = await this.l2BlockSource.getPendingChainValidationStatus();
|
|
785
|
+
await this.considerInvalidatingCheckpoint(pendingChainValidationStatus, slot);
|
|
786
|
+
} catch (err) {
|
|
787
|
+
this.log.warn(`Failed to consider invalidating checkpoint`, {
|
|
788
|
+
err,
|
|
789
|
+
slot,
|
|
790
|
+
targetSlot
|
|
791
|
+
});
|
|
792
|
+
}
|
|
793
|
+
return undefined;
|
|
794
|
+
}
|
|
795
|
+
// Explicit build-loop entry gate: if we are past the latest useful block-building start for the
|
|
796
|
+
// target slot, abandon building for this slot. The proposer prioritizes the ideal L1-publish path
|
|
797
|
+
// and does not plan around the late consensus-handoff path. This is the proposer build path's
|
|
798
|
+
// timing gate; it runs only after we know we are the synced proposer, so non-proposer invalidation
|
|
799
|
+
// and escape-hatch voting (which returned above) are never gated by build timing. Vote-only paths
|
|
800
|
+
// still run when block building is abandoned.
|
|
801
|
+
const startDeadline = this.timetable.getBuildStartDeadline(targetSlot);
|
|
802
|
+
const nowForStartGate = this.dateProvider.now() / 1000;
|
|
803
|
+
if (nowForStartGate > startDeadline) {
|
|
804
|
+
this.log.debug(`Past start deadline for slot ${targetSlot}, abandoning block building`, {
|
|
805
|
+
targetSlot,
|
|
806
|
+
nowForStartGate,
|
|
807
|
+
startDeadline
|
|
808
|
+
});
|
|
809
|
+
// Mark the slot as attempted so a deadline abort is not retried within the same slot. Vote-only actions
|
|
810
|
+
// still need to run because sync can succeed even when it is too late to start building a checkpoint.
|
|
811
|
+
await this.tryVoteAndPruneWhenCannotBuild({
|
|
812
|
+
slot,
|
|
813
|
+
targetSlot
|
|
814
|
+
});
|
|
815
|
+
this.lastSlotForCheckpointProposalJob = targetSlot;
|
|
816
|
+
return undefined;
|
|
817
|
+
}
|
|
818
|
+
// We are the proposer, the escape hatch is closed, and we have time before the build start deadline.
|
|
819
|
+
// Now run the full sync check before building.
|
|
820
|
+
const syncedTo = await this.checkSync({
|
|
821
|
+
ts,
|
|
822
|
+
slot
|
|
823
|
+
});
|
|
824
|
+
if (!syncedTo) {
|
|
825
|
+
return undefined;
|
|
826
|
+
}
|
|
652
827
|
// Next checkpoint follows from the last synced one
|
|
653
828
|
const checkpointNumber = CheckpointNumber(syncedTo.checkpointNumber + 1);
|
|
654
829
|
const logCtx = {
|
|
@@ -660,14 +835,8 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
660
835
|
checkpointNumber,
|
|
661
836
|
isPendingChainValid: pick(syncedTo.pendingChainValidationStatus, 'valid', 'reason', 'invalidIndex')
|
|
662
837
|
};
|
|
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
|
-
}
|
|
838
|
+
// We are the synced proposer within the build window; enter the proposer-check state and build.
|
|
839
|
+
this.setState(SequencerState.PROPOSER_CHECK, targetSlot);
|
|
671
840
|
// Guard: don't exceed 1-deep pipeline. Without a proposed checkpoint, we can only build
|
|
672
841
|
// confirmed + 1. With a proposed checkpoint, we can build confirmed + 2.
|
|
673
842
|
const confirmedCkpt = syncedTo.checkpointedCheckpointNumber;
|
|
@@ -691,16 +860,15 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
691
860
|
const proposerForPublisher = this.config.fishermanMode ? undefined : proposer;
|
|
692
861
|
const { attestorAddress, publisher } = await this.publisherFactory.create(proposerForPublisher);
|
|
693
862
|
this.log.verbose(`Created publisher at address ${publisher.getSenderAddress()} for attestor ${attestorAddress}`);
|
|
694
|
-
const isPipelining = this.epochCache.isProposerPipeliningEnabled();
|
|
695
863
|
// Prepare invalidation request if the pending chain is invalid (returns undefined if no need).
|
|
696
864
|
// Only simulate invalidation when there's no proposed parent, since we assume the proposed parent
|
|
697
865
|
// will invalidate the currently invalid checkpoint on L1.
|
|
698
|
-
const invalidateCheckpoint =
|
|
866
|
+
const invalidateCheckpoint = syncedTo.hasProposedCheckpoint || syncedTo.pendingChainValidationStatus.valid ? undefined : await publisher.simulateInvalidateCheckpoint(syncedTo.pendingChainValidationStatus);
|
|
699
867
|
// Determine the correct archive and L1 state overrides for the canProposeAt check.
|
|
700
868
|
// The L1 contract reads archives[proposedCheckpointNumber] and compares it with the provided archive.
|
|
701
869
|
// When invalidating or pipelining, the local archive may differ from L1's, so we adjust accordingly.
|
|
702
870
|
let archiveForCheck = syncedTo.archive;
|
|
703
|
-
if (
|
|
871
|
+
if (syncedTo.hasProposedCheckpoint) {
|
|
704
872
|
this.metrics.recordPipelineDepth(syncedTo.checkpointNumber - syncedTo.checkpointedCheckpointNumber);
|
|
705
873
|
this.log.verbose(`Building on top of proposed checkpoint (pending=${syncedTo.proposedCheckpointData?.checkpointNumber}) for target slot ${targetSlot}`, {
|
|
706
874
|
targetSlot,
|
|
@@ -725,7 +893,7 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
725
893
|
// plus the parent checkpoint cell and fee header when pipelining.
|
|
726
894
|
const simulationOverridesPlan = await buildCheckpointSimulationOverridesPlan({
|
|
727
895
|
checkpointNumber,
|
|
728
|
-
proposedCheckpointData:
|
|
896
|
+
proposedCheckpointData: syncedTo.hasProposedCheckpoint ? syncedTo.proposedCheckpointData : undefined,
|
|
729
897
|
invalidateToPendingCheckpointNumber: invalidateCheckpoint?.forcePendingCheckpointNumber,
|
|
730
898
|
checkpointedCheckpointNumber: syncedTo.checkpointedCheckpointNumber,
|
|
731
899
|
rollup: this.rollupContract,
|
|
@@ -749,7 +917,7 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
749
917
|
this.emit('preparing-checkpoint', {
|
|
750
918
|
targetSlot,
|
|
751
919
|
checkpointNumber,
|
|
752
|
-
hadProposedParent:
|
|
920
|
+
hadProposedParent: syncedTo.hasProposedCheckpoint,
|
|
753
921
|
provenOverride,
|
|
754
922
|
simulatedPending: simulationOverridesPlan?.chainTipsOverride?.pending
|
|
755
923
|
});
|
|
@@ -810,14 +978,13 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
810
978
|
this.log.info(`Preparing checkpoint proposal ${checkpointNumber} for target slot ${targetSlot} during wall-clock slot ${slot}`, {
|
|
811
979
|
...logCtx,
|
|
812
980
|
...proposeContext,
|
|
813
|
-
proposer
|
|
814
|
-
pipeliningEnabled: this.epochCache.isProposerPipeliningEnabled()
|
|
981
|
+
proposer
|
|
815
982
|
});
|
|
816
983
|
// Create and return the checkpoint proposal job
|
|
817
|
-
return this.createCheckpointProposalJob(
|
|
984
|
+
return this.createCheckpointProposalJob(targetSlot, targetEpoch, checkpointNumber, syncedTo.blockNumber, syncedTo.checkpointedCheckpointNumber, proposer, publisher, attestorAddress, invalidateCheckpoint, syncedTo.proposedCheckpointData);
|
|
818
985
|
}
|
|
819
|
-
createCheckpointProposalJob(
|
|
820
|
-
return new CheckpointProposalJob(
|
|
986
|
+
createCheckpointProposalJob(targetSlot, targetEpoch, checkpointNumber, syncedToBlockNumber, checkpointedCheckpointNumber, proposer, publisher, attestorAddress, invalidateCheckpoint, proposedCheckpointData) {
|
|
987
|
+
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
988
|
}
|
|
822
989
|
/**
|
|
823
990
|
* Returns the current sequencer state.
|
|
@@ -825,9 +992,11 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
825
992
|
return this.state;
|
|
826
993
|
}
|
|
827
994
|
/**
|
|
828
|
-
* Internal helper for setting the sequencer state
|
|
995
|
+
* Internal helper for setting the sequencer state. Pure: sets the state, emits `state-changed`, and
|
|
996
|
+
* records metrics. Timing deadlines are queried explicitly at the relevant call sites, not gated here.
|
|
829
997
|
* @param proposedState - The new state to transition to.
|
|
830
|
-
* @param slotNumber - The
|
|
998
|
+
* @param slotNumber - The target slot being proposed for, emitted as `targetSlot` on the event payload
|
|
999
|
+
* and used to anchor `secondsIntoBuildFrame`. Undefined for lifecycle states with no associated slot.
|
|
831
1000
|
* @param force - Whether to force the transition even if the sequencer is stopped.
|
|
832
1001
|
*/ setState(proposedState, slotNumber, opts = {}) {
|
|
833
1002
|
if (this.state === SequencerState.STOPPING && proposedState !== SequencerState.STOPPED && !opts.force) {
|
|
@@ -838,15 +1007,13 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
838
1007
|
this.log.warn(`Cannot set sequencer from ${this.state} to ${proposedState} as it is stopped.`);
|
|
839
1008
|
return;
|
|
840
1009
|
}
|
|
841
|
-
|
|
842
|
-
if (slotNumber !== undefined) {
|
|
843
|
-
secondsIntoSlot = this.getSecondsIntoSlot(slotNumber);
|
|
844
|
-
this.timetable.assertTimeLeft(proposedState, secondsIntoSlot);
|
|
845
|
-
}
|
|
1010
|
+
const secondsIntoBuildFrame = slotNumber !== undefined ? this.getSecondsIntoBuildFrame(slotNumber) : undefined;
|
|
846
1011
|
const oldState = this.state;
|
|
847
1012
|
const oldStateSlotNumber = this.stateSlotNumber;
|
|
848
1013
|
const stateChanged = proposedState !== oldState;
|
|
849
|
-
|
|
1014
|
+
// Wall-clock time spent in the previous state: the delta between consecutive state-changing setState
|
|
1015
|
+
// calls, read from the date provider so it tracks simulated time under a test/manual clock.
|
|
1016
|
+
const transitionAtMs = this.dateProvider.now();
|
|
850
1017
|
const stateDurationMs = transitionAtMs - this.stateEnteredAtMs;
|
|
851
1018
|
const boringStates = [
|
|
852
1019
|
SequencerState.IDLE,
|
|
@@ -858,7 +1025,7 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
858
1025
|
newState: proposedState,
|
|
859
1026
|
slotNumber,
|
|
860
1027
|
stateSlotNumber: oldStateSlotNumber,
|
|
861
|
-
|
|
1028
|
+
secondsIntoBuildFrame,
|
|
862
1029
|
...stateChanged && {
|
|
863
1030
|
stateDurationMs: Math.ceil(stateDurationMs)
|
|
864
1031
|
}
|
|
@@ -866,8 +1033,8 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
866
1033
|
this.emit('state-changed', {
|
|
867
1034
|
oldState,
|
|
868
1035
|
newState: proposedState,
|
|
869
|
-
|
|
870
|
-
|
|
1036
|
+
secondsIntoBuildFrame,
|
|
1037
|
+
targetSlot: slotNumber
|
|
871
1038
|
});
|
|
872
1039
|
if (stateChanged) {
|
|
873
1040
|
this.metrics.recordStateDuration(stateDurationMs, oldState);
|
|
@@ -899,8 +1066,7 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
899
1066
|
})),
|
|
900
1067
|
this.l2BlockSource.getL2Tips().then((t)=>({
|
|
901
1068
|
proposed: t.proposed,
|
|
902
|
-
checkpointed: t.checkpointed
|
|
903
|
-
proposedCheckpoint: t.proposedCheckpoint
|
|
1069
|
+
checkpointed: t.checkpointed
|
|
904
1070
|
})),
|
|
905
1071
|
this.p2pClient.getStatus().then((p2p)=>p2p.syncedToL2Block),
|
|
906
1072
|
this.l1ToL2MessageSource.getL2Tips().then((t)=>({
|
|
@@ -940,35 +1106,23 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
940
1106
|
// matching proposed checkpoint (e.g. it crashed before assembling it). Building on this orphan block
|
|
941
1107
|
// would fork the chain off a tip no other node can follow. The archiver prunes these orphan blocks
|
|
942
1108
|
// once their build slot ends; this guard is the correctness barrier during the grace window before.
|
|
943
|
-
|
|
944
|
-
|
|
1109
|
+
// `getProposedCheckpointData()` returns the latest proposed checkpoint payload, which is always
|
|
1110
|
+
// the leading one (a proposed entry is only stored beyond the confirmed frontier and is deleted
|
|
1111
|
+
// on confirmation). It carries no tip, so there is no tip-vs-payload split read to reconcile.
|
|
1112
|
+
if (blockData.checkpointNumber > l2Tips.checkpointed.checkpoint.number && proposedCheckpointData?.checkpointNumber !== blockData.checkpointNumber) {
|
|
1113
|
+
const logCtx = {
|
|
945
1114
|
blockCheckpointNumber: blockData.checkpointNumber,
|
|
946
1115
|
checkpointedCheckpointNumber: l2Tips.checkpointed.checkpoint.number,
|
|
947
|
-
proposedCheckpointTipNumber:
|
|
948
|
-
proposedCheckpointDataNumber: proposedCheckpointData?.checkpointNumber,
|
|
1116
|
+
proposedCheckpointTipNumber: proposedCheckpointData?.checkpointNumber,
|
|
949
1117
|
blockNumber: blockData.header.getBlockNumber(),
|
|
950
1118
|
blockSlot: blockData.header.getSlot(),
|
|
951
1119
|
syncedL2Slot,
|
|
952
1120
|
...args
|
|
953
|
-
}
|
|
954
|
-
|
|
955
|
-
}
|
|
956
|
-
const hasProposedCheckpoint = l2Tips.proposedCheckpoint.checkpoint.number > l2Tips.checkpointed.checkpoint.number;
|
|
957
|
-
// The l2Tips and proposedCheckpointData reads above come from independent archiver snapshots
|
|
958
|
-
// (a JS-side tips cache vs. a direct store read on `#proposedCheckpoints`). A concurrent archiver
|
|
959
|
-
// write that mutates both can be observed split, leaving us with `hasProposedCheckpoint=true` but
|
|
960
|
-
// no proposedCheckpointData (or one whose number doesn't match the tip). Refuse to proceed in that
|
|
961
|
-
// window — the next checkSync tick will see a coherent snapshot.
|
|
962
|
-
if (hasProposedCheckpoint && (!proposedCheckpointData || proposedCheckpointData.checkpointNumber !== l2Tips.proposedCheckpoint.checkpoint.number)) {
|
|
963
|
-
this.log.warn(`Sequencer sync check failed: inconsistent proposed-checkpoint state`, {
|
|
964
|
-
proposedCheckpointTipNumber: l2Tips.proposedCheckpoint.checkpoint.number,
|
|
965
|
-
checkpointedTipNumber: l2Tips.checkpointed.checkpoint.number,
|
|
966
|
-
proposedCheckpointDataNumber: proposedCheckpointData?.checkpointNumber,
|
|
967
|
-
syncedL2Slot,
|
|
968
|
-
...args
|
|
969
|
-
});
|
|
1121
|
+
};
|
|
1122
|
+
this.log.debug(`Waiting for proposed checkpoint to catch up with reexecuted block`, logCtx);
|
|
970
1123
|
return undefined;
|
|
971
1124
|
}
|
|
1125
|
+
const hasProposedCheckpoint = proposedCheckpointData !== undefined;
|
|
972
1126
|
// Check that the proposed checkpoint is indeed the parent of the checkpoint we'll be building
|
|
973
1127
|
// The checkpoint number to build is derived as blockData.checkpointNumber + 1
|
|
974
1128
|
if (proposedCheckpointData && proposedCheckpointData.checkpointNumber !== blockData.checkpointNumber) {
|
|
@@ -1001,9 +1155,17 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
1001
1155
|
proposer = await this.epochCache.getProposerAttesterAddressInSlot(targetSlot);
|
|
1002
1156
|
} catch (e) {
|
|
1003
1157
|
if (e instanceof NoCommitteeError) {
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
this.
|
|
1158
|
+
const targetEpoch = getEpochAtSlot(targetSlot, this.l1Constants);
|
|
1159
|
+
if (this.lastEpochForNoCommitteeLog !== targetEpoch) {
|
|
1160
|
+
this.lastEpochForNoCommitteeLog = targetEpoch;
|
|
1161
|
+
await logMissingCommittee(targetSlot, targetEpoch, {
|
|
1162
|
+
epochCache: this.epochCache,
|
|
1163
|
+
rollupContract: this.rollupContract,
|
|
1164
|
+
l2BlockSource: this.l2BlockSource,
|
|
1165
|
+
l1Constants: this.l1Constants,
|
|
1166
|
+
dateProvider: this.dateProvider,
|
|
1167
|
+
logger: this.log
|
|
1168
|
+
});
|
|
1007
1169
|
}
|
|
1008
1170
|
return [
|
|
1009
1171
|
false,
|
|
@@ -1053,30 +1215,24 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
1053
1215
|
];
|
|
1054
1216
|
}
|
|
1055
1217
|
/**
|
|
1056
|
-
* Tries to vote on slashing actions and governance
|
|
1057
|
-
* This allows the sequencer to participate in governance/slashing votes even when it
|
|
1058
|
-
|
|
1218
|
+
* Tries to vote on slashing actions and governance and to prune when we cannot build and are past the
|
|
1219
|
+
* block-building window. This allows the sequencer to participate in governance/slashing votes even when it
|
|
1220
|
+
* cannot build blocks, and to prune the pending chain so it can recover from bad data that is blocking sync.
|
|
1221
|
+
*/ async tryVoteAndPruneWhenCannotBuild(args) {
|
|
1059
1222
|
const { slot, targetSlot } = args;
|
|
1060
1223
|
// Prevent duplicate attempts in the same slot
|
|
1061
|
-
if (this.
|
|
1062
|
-
this.log.trace(`Already attempted
|
|
1063
|
-
return;
|
|
1064
|
-
}
|
|
1065
|
-
// Check if we're past the max time for initializing a proposal
|
|
1066
|
-
const secondsIntoSlot = this.getSecondsIntoSlot(slot);
|
|
1067
|
-
const maxAllowedTime = this.timetable.getMaxAllowedTime(SequencerState.INITIALIZING_CHECKPOINT);
|
|
1068
|
-
// If we haven't exceeded the time limit for initializing a proposal, don't proceed with voting
|
|
1069
|
-
// We use INITIALIZING_PROPOSAL time limit because if we're past that, we can't build a block anyway
|
|
1070
|
-
if (maxAllowedTime === undefined || secondsIntoSlot <= maxAllowedTime) {
|
|
1071
|
-
this.log.trace(`Not attempting to vote since there is still time for block building`, {
|
|
1072
|
-
secondsIntoSlot,
|
|
1073
|
-
maxAllowedTime
|
|
1074
|
-
});
|
|
1224
|
+
if (this.lastSlotForFallbackAction === slot) {
|
|
1225
|
+
this.log.trace(`Already attempted fallback actions in slot ${slot} (skipping)`);
|
|
1075
1226
|
return;
|
|
1076
1227
|
}
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1228
|
+
// Vote-only actions do not give up the slot: if sync recovers, a later work-loop iteration can still build.
|
|
1229
|
+
// Under proposer pipelining the work loop reasons about the next L1 slot, so waiting for the target slot's
|
|
1230
|
+
// build-start deadline can miss the whole fallback window when the target advances with the clock.
|
|
1231
|
+
const nowSeconds = this.dateProvider.now() / 1000;
|
|
1232
|
+
const startDeadline = this.timetable.getBuildStartDeadline(targetSlot);
|
|
1233
|
+
this.log.trace(`Cannot build for slot ${slot}, checking for voting opportunities`, {
|
|
1234
|
+
nowSeconds,
|
|
1235
|
+
startDeadline
|
|
1080
1236
|
});
|
|
1081
1237
|
// Check if we're a proposer or proposal is open
|
|
1082
1238
|
const [canPropose, proposer] = await this.checkCanPropose(targetSlot);
|
|
@@ -1088,7 +1244,7 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
1088
1244
|
return;
|
|
1089
1245
|
}
|
|
1090
1246
|
// Mark this slot as attempted
|
|
1091
|
-
this.
|
|
1247
|
+
this.lastSlotForFallbackAction = slot;
|
|
1092
1248
|
// Get a publisher for voting
|
|
1093
1249
|
const { attestorAddress, publisher } = await this.publisherFactory.create(proposer);
|
|
1094
1250
|
this.log.debug(`Attempting to vote despite sync failure at slot ${slot}`, {
|
|
@@ -1099,22 +1255,41 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
1099
1255
|
const voter = new CheckpointVoter(targetSlot, publisher, attestorAddress, this.validatorClient, this.slasherClient, this.l1Constants, this.config, this.metrics, this.log);
|
|
1100
1256
|
const votesPromises = voter.enqueueVotes();
|
|
1101
1257
|
const votes = await Promise.all(votesPromises);
|
|
1102
|
-
if (
|
|
1103
|
-
|
|
1258
|
+
// Even if we cannot build, try to prune so a stuck pending chain (e.g. bad data blocking sync) can
|
|
1259
|
+
// recover. prune() is permissionless, so it rides the same fallback multicall as the votes.
|
|
1260
|
+
const pruneEnqueued = await this.tryEnqueuePruneIfPrunable(targetSlot, publisher);
|
|
1261
|
+
// Bail if nothing to do
|
|
1262
|
+
if (votes.every((p)=>!p) && !pruneEnqueued) {
|
|
1263
|
+
this.log.debug(`Nothing to enqueue for slot ${slot} (no votes, not prunable)`);
|
|
1104
1264
|
return;
|
|
1105
1265
|
}
|
|
1106
|
-
|
|
1107
|
-
|
|
1266
|
+
const [governanceVoteEnqueued, slashingVoteEnqueued] = votes;
|
|
1267
|
+
this.log.info(`Submitting fallback requests in slot ${slot} despite sync failure`, {
|
|
1268
|
+
slot,
|
|
1269
|
+
pruneEnqueued,
|
|
1270
|
+
governanceVoteEnqueued: !!governanceVoteEnqueued,
|
|
1271
|
+
slashingVoteEnqueued: !!slashingVoteEnqueued
|
|
1108
1272
|
});
|
|
1109
1273
|
// Votes are EIP-712-signed for `targetSlot` (the pipelined slot in which the multicall is
|
|
1110
1274
|
// expected to mine). Delay submission to the start of `targetSlot` so the tx mines in the
|
|
1111
1275
|
// slot the votes were signed for. We fire-and-forget so we don't block the sequencer's
|
|
1112
|
-
// work loop while waiting for the target slot to start.
|
|
1113
|
-
|
|
1114
|
-
this.log.error(`Failed to publish
|
|
1276
|
+
// work loop while waiting for the target slot to start, but track it so stop() can drain it.
|
|
1277
|
+
const send = publisher.sendRequestsAt(targetSlot).catch((err)=>{
|
|
1278
|
+
this.log.error(`Failed to publish fallback requests despite sync failure for slot ${slot}`, err, {
|
|
1115
1279
|
slot
|
|
1116
1280
|
});
|
|
1117
1281
|
});
|
|
1282
|
+
this.pendingRequests.trackRequest(send, ()=>publisher.interrupt());
|
|
1283
|
+
}
|
|
1284
|
+
async tryEnqueuePruneIfPrunable(targetSlot, publisher) {
|
|
1285
|
+
try {
|
|
1286
|
+
return await publisher.enqueuePruneIfPrunable(targetSlot);
|
|
1287
|
+
} catch (err) {
|
|
1288
|
+
this.log.error(`Failed to enqueue rollup prune for slot ${targetSlot}`, err, {
|
|
1289
|
+
targetSlot
|
|
1290
|
+
});
|
|
1291
|
+
return false;
|
|
1292
|
+
}
|
|
1118
1293
|
}
|
|
1119
1294
|
/**
|
|
1120
1295
|
* Tries to vote on slashing actions and governance proposals when escape hatch is open.
|
|
@@ -1122,12 +1297,12 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
1122
1297
|
*/ async tryVoteWhenEscapeHatchOpen(args) {
|
|
1123
1298
|
const { slot, targetSlot, proposer } = args;
|
|
1124
1299
|
// Prevent duplicate attempts in the same slot
|
|
1125
|
-
if (this.
|
|
1300
|
+
if (this.lastSlotForFallbackAction === slot) {
|
|
1126
1301
|
this.log.trace(`Already attempted to vote in slot ${slot} (escape hatch open, skipping)`);
|
|
1127
1302
|
return;
|
|
1128
1303
|
}
|
|
1129
1304
|
// Mark this slot as attempted
|
|
1130
|
-
this.
|
|
1305
|
+
this.lastSlotForFallbackAction = slot;
|
|
1131
1306
|
const { attestorAddress, publisher } = await this.publisherFactory.create(proposer);
|
|
1132
1307
|
this.log.debug(`Escape hatch open for slot ${slot}, attempting vote-only actions`, {
|
|
1133
1308
|
slot,
|
|
@@ -1137,8 +1312,7 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
1137
1312
|
// Under proposer pipelining, the multicall is expected to mine in `targetSlot` (slot + 1).
|
|
1138
1313
|
// Governance and slashing votes are EIP-712-signed against the slot they will mine in, and the
|
|
1139
1314
|
// L1 contract checks `msg.sender == getCurrentProposer()` using the mining slot. So we must
|
|
1140
|
-
// sign for `targetSlot` and delay submission to the start of `targetSlot`.
|
|
1141
|
-
// disabled `targetSlot == slot` and `sendRequestsAt` resolves with no extra sleep.
|
|
1315
|
+
// sign for `targetSlot` and delay submission to the start of `targetSlot`.
|
|
1142
1316
|
const voter = new CheckpointVoter(targetSlot, publisher, attestorAddress, this.validatorClient, this.slasherClient, this.l1Constants, this.config, this.metrics, this.log);
|
|
1143
1317
|
const votesPromises = voter.enqueueVotes();
|
|
1144
1318
|
const votes = await Promise.all(votesPromises);
|
|
@@ -1154,32 +1328,45 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
1154
1328
|
// the multicall mines in the slot the votes were signed for; otherwise the L1 contract reads
|
|
1155
1329
|
// `signaler = getCurrentProposer()` against the wrong slot and signature verification fails
|
|
1156
1330
|
// silently inside Multicall3. Fire-and-forget so we don't block the sequencer's work loop while
|
|
1157
|
-
// waiting for the target slot to start, mirroring
|
|
1158
|
-
|
|
1331
|
+
// waiting for the target slot to start, mirroring tryVoteAndPruneWhenCannotBuild, but tracked so
|
|
1332
|
+
// stop() can drain it.
|
|
1333
|
+
const send = publisher.sendRequestsAt(targetSlot).catch((err)=>{
|
|
1159
1334
|
this.log.error(`Failed to publish escape-hatch votes for slot ${slot}`, err, {
|
|
1160
1335
|
slot,
|
|
1161
1336
|
targetSlot
|
|
1162
1337
|
});
|
|
1163
1338
|
});
|
|
1339
|
+
this.pendingRequests.trackRequest(send, ()=>publisher.interrupt());
|
|
1164
1340
|
}
|
|
1165
1341
|
/**
|
|
1166
1342
|
* Considers invalidating a block if the pending chain is invalid. Depends on how long the invalid block
|
|
1167
1343
|
* has been there without being invalidated and whether the sequencer is in the committee or not. We always
|
|
1168
1344
|
* have the proposer try to invalidate, but if they fail, the sequencers in the committee are expected to try,
|
|
1169
1345
|
* and if they fail, any sequencer will try as well.
|
|
1170
|
-
|
|
1171
|
-
|
|
1346
|
+
* @param pendingChainValidationStatus - The archiver's pending-chain validation status, authoritative on its own.
|
|
1347
|
+
* @param currentSlot - The wall-clock slot, used for committee lookup, the per-(checkpoint, slot) dedup guard, and logging.
|
|
1348
|
+
*/ async considerInvalidatingCheckpoint(pendingChainValidationStatus, currentSlot) {
|
|
1172
1349
|
if (pendingChainValidationStatus.valid) {
|
|
1173
1350
|
return;
|
|
1174
1351
|
}
|
|
1175
1352
|
const invalidCheckpointNumber = pendingChainValidationStatus.checkpoint.checkpointNumber;
|
|
1353
|
+
// Avoid re-running the committee lookup, simulation, and submission on every tick within a slot.
|
|
1354
|
+
// The guard is keyed by (checkpoint, slot) — so a different invalid checkpoint surfacing later in
|
|
1355
|
+
// the same slot is not suppressed — and is set only after a request is successfully simulated below,
|
|
1356
|
+
// so a transient simulation failure (or thresholds not yet met) still retries on the next tick.
|
|
1357
|
+
if (this.lastInvalidationAttempt?.slot === currentSlot && this.lastInvalidationAttempt.checkpointNumber === invalidCheckpointNumber) {
|
|
1358
|
+
this.log.trace(`Already attempted to invalidate checkpoint ${invalidCheckpointNumber} in slot ${currentSlot}`, {
|
|
1359
|
+
currentSlot,
|
|
1360
|
+
invalidCheckpointNumber
|
|
1361
|
+
});
|
|
1362
|
+
return;
|
|
1363
|
+
}
|
|
1176
1364
|
const invalidCheckpointTimestamp = pendingChainValidationStatus.checkpoint.timestamp;
|
|
1177
1365
|
const timeSinceChainInvalid = this.dateProvider.nowInSeconds() - Number(invalidCheckpointTimestamp);
|
|
1178
1366
|
const ourValidatorAddresses = this.validatorClient.getValidatorAddresses();
|
|
1179
1367
|
const { secondsBeforeInvalidatingBlockAsCommitteeMember, secondsBeforeInvalidatingBlockAsNonCommitteeMember } = this.config;
|
|
1180
1368
|
const logData = {
|
|
1181
1369
|
invalidL1Timestamp: invalidCheckpointTimestamp,
|
|
1182
|
-
syncedL2Slot,
|
|
1183
1370
|
invalidCheckpoint: pendingChainValidationStatus.checkpoint,
|
|
1184
1371
|
secondsBeforeInvalidatingBlockAsCommitteeMember,
|
|
1185
1372
|
secondsBeforeInvalidatingBlockAsNonCommitteeMember,
|
|
@@ -1213,6 +1400,12 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
1213
1400
|
this.log.warn(`Failed to simulate invalidate checkpoint`, logData);
|
|
1214
1401
|
return;
|
|
1215
1402
|
}
|
|
1403
|
+
// We produced a valid invalidation request; record it so further ticks within this slot skip the
|
|
1404
|
+
// committee lookup, simulation, and submission above for this same invalid checkpoint.
|
|
1405
|
+
this.lastInvalidationAttempt = {
|
|
1406
|
+
slot: currentSlot,
|
|
1407
|
+
checkpointNumber: invalidCheckpointNumber
|
|
1408
|
+
};
|
|
1216
1409
|
this.log.info(invalidateAsCommitteeMember ? `Invalidating checkpoint ${invalidCheckpointNumber} as committee member` : `Invalidating checkpoint ${invalidCheckpointNumber} as non-committee member`, logData);
|
|
1217
1410
|
publisher.enqueueInvalidateCheckpoint(invalidateCheckpoint);
|
|
1218
1411
|
if (!this.config.fishermanMode) {
|
|
@@ -1248,12 +1441,12 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
1248
1441
|
}))
|
|
1249
1442
|
});
|
|
1250
1443
|
}
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
const
|
|
1256
|
-
return Number((this.dateProvider.now() / 1000 -
|
|
1444
|
+
/**
|
|
1445
|
+
* Wall-clock seconds elapsed since the build-frame start of the given target slot
|
|
1446
|
+
* (`now − getBuildFrameStart(targetSlot)`). May be negative if called before the build frame opens.
|
|
1447
|
+
*/ getSecondsIntoBuildFrame(targetSlot) {
|
|
1448
|
+
const buildFrameStart = this.timetable.getBuildFrameStart(targetSlot);
|
|
1449
|
+
return Number((this.dateProvider.now() / 1000 - buildFrameStart).toFixed(3));
|
|
1257
1450
|
}
|
|
1258
1451
|
get aztecSlotDuration() {
|
|
1259
1452
|
return this.l1Constants.slotDuration;
|
|
@@ -1276,7 +1469,4 @@ _dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpoi
|
|
|
1276
1469
|
getConfig() {
|
|
1277
1470
|
return this.config;
|
|
1278
1471
|
}
|
|
1279
|
-
get l1PublishingTime() {
|
|
1280
|
-
return this.config.l1PublishingTime ?? this.l1Constants.ethereumSlotDuration;
|
|
1281
|
-
}
|
|
1282
1472
|
}
|