@aztec/sequencer-client 0.0.1-commit.2ed92850 → 0.0.1-commit.2f68f620
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +281 -21
- package/dest/client/sequencer-client.d.ts +19 -9
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +65 -32
- package/dest/config.d.ts +28 -6
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +76 -37
- package/dest/global_variable_builder/fee_predictor.d.ts +37 -0
- package/dest/global_variable_builder/fee_predictor.d.ts.map +1 -0
- package/dest/global_variable_builder/fee_predictor.js +128 -0
- package/dest/global_variable_builder/fee_provider.d.ts +21 -0
- package/dest/global_variable_builder/fee_provider.d.ts.map +1 -0
- package/dest/global_variable_builder/fee_provider.js +58 -0
- package/dest/global_variable_builder/global_builder.d.ts +14 -16
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +16 -50
- package/dest/global_variable_builder/index.d.ts +4 -2
- package/dest/global_variable_builder/index.d.ts.map +1 -1
- package/dest/global_variable_builder/index.js +2 -0
- package/dest/index.d.ts +2 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -1
- package/dest/publisher/config.d.ts +47 -17
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +121 -42
- package/dest/publisher/index.d.ts +2 -1
- package/dest/publisher/index.d.ts.map +1 -1
- package/dest/publisher/l1_tx_failed_store/factory.d.ts +11 -0
- package/dest/publisher/l1_tx_failed_store/factory.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/factory.js +22 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +58 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.js +1 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts +15 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.js +34 -0
- package/dest/publisher/l1_tx_failed_store/index.d.ts +4 -0
- package/dest/publisher/l1_tx_failed_store/index.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/index.js +2 -0
- package/dest/publisher/sequencer-bundle-simulator.d.ts +96 -0
- package/dest/publisher/sequencer-bundle-simulator.d.ts.map +1 -0
- package/dest/publisher/sequencer-bundle-simulator.js +198 -0
- package/dest/publisher/sequencer-publisher-factory.d.ts +11 -5
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-factory.js +27 -3
- package/dest/publisher/sequencer-publisher-metrics.d.ts +1 -1
- package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-metrics.js +12 -4
- package/dest/publisher/sequencer-publisher.d.ts +94 -68
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +448 -363
- package/dest/sequencer/automine/automine_factory.d.ts +54 -0
- package/dest/sequencer/automine/automine_factory.d.ts.map +1 -0
- package/dest/sequencer/automine/automine_factory.js +84 -0
- package/dest/sequencer/automine/automine_sequencer.d.ts +151 -0
- package/dest/sequencer/automine/automine_sequencer.d.ts.map +1 -0
- package/dest/sequencer/automine/automine_sequencer.js +509 -0
- package/dest/sequencer/chain_state_overrides.d.ts +61 -0
- package/dest/sequencer/chain_state_overrides.d.ts.map +1 -0
- package/dest/sequencer/chain_state_overrides.js +98 -0
- package/dest/sequencer/checkpoint_proposal_job.d.ts +85 -14
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_proposal_job.js +882 -254
- package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts +34 -0
- package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_proposal_job_metrics.js +72 -0
- package/dest/sequencer/checkpoint_voter.d.ts +1 -2
- package/dest/sequencer/checkpoint_voter.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_voter.js +2 -5
- package/dest/sequencer/events.d.ts +48 -2
- package/dest/sequencer/events.d.ts.map +1 -1
- package/dest/sequencer/index.d.ts +3 -1
- package/dest/sequencer/index.d.ts.map +1 -1
- package/dest/sequencer/index.js +2 -0
- package/dest/sequencer/metrics.d.ts +23 -8
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +142 -36
- package/dest/sequencer/sequencer.d.ts +85 -22
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +380 -137
- package/dest/sequencer/timetable.d.ts +14 -6
- package/dest/sequencer/timetable.d.ts.map +1 -1
- package/dest/sequencer/timetable.js +47 -46
- package/dest/sequencer/types.d.ts +2 -2
- package/dest/sequencer/types.d.ts.map +1 -1
- package/dest/test/index.d.ts +3 -5
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.d.ts +12 -12
- package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.js +45 -36
- package/dest/test/utils.d.ts +3 -3
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +10 -8
- package/package.json +27 -28
- package/src/client/sequencer-client.ts +91 -35
- package/src/config.ts +98 -46
- package/src/global_variable_builder/README.md +44 -0
- package/src/global_variable_builder/fee_predictor.ts +172 -0
- package/src/global_variable_builder/fee_provider.ts +75 -0
- package/src/global_variable_builder/global_builder.ts +26 -63
- package/src/global_variable_builder/index.ts +3 -1
- package/src/index.ts +10 -1
- package/src/publisher/config.ts +157 -45
- package/src/publisher/index.ts +3 -0
- package/src/publisher/l1_tx_failed_store/factory.ts +32 -0
- package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +57 -0
- package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +46 -0
- package/src/publisher/l1_tx_failed_store/index.ts +3 -0
- package/src/publisher/sequencer-bundle-simulator.ts +254 -0
- package/src/publisher/sequencer-publisher-factory.ts +38 -9
- package/src/publisher/sequencer-publisher-metrics.ts +7 -3
- package/src/publisher/sequencer-publisher.ts +542 -460
- package/src/sequencer/README.md +162 -450
- package/src/sequencer/automine/README.md +46 -0
- package/src/sequencer/automine/automine_factory.ts +145 -0
- package/src/sequencer/automine/automine_sequencer.ts +595 -0
- package/src/sequencer/chain_state_overrides.ts +162 -0
- package/src/sequencer/checkpoint_proposal_job.ts +1078 -290
- package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
- package/src/sequencer/checkpoint_voter.ts +1 -12
- package/src/sequencer/events.ts +51 -2
- package/src/sequencer/index.ts +2 -0
- package/src/sequencer/metrics.ts +164 -39
- package/src/sequencer/sequencer.ts +471 -157
- package/src/sequencer/timetable.ts +62 -56
- package/src/sequencer/types.ts +1 -1
- package/src/test/index.ts +2 -4
- package/src/test/mock_checkpoint_builder.ts +65 -53
- package/src/test/utils.ts +31 -10
|
@@ -436,32 +436,36 @@ function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
|
|
|
436
436
|
return (_apply_decs_2203_r = applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
|
|
437
437
|
}
|
|
438
438
|
var _dec, _dec1, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _initProto;
|
|
439
|
-
import {
|
|
440
|
-
import { BLOBS_PER_CHECKPOINT, FIELDS_PER_BLOB } from '@aztec/constants';
|
|
441
|
-
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
439
|
+
import { BlockNumber, CheckpointNumber, IndexWithinCheckpoint } from '@aztec/foundation/branded-types';
|
|
442
440
|
import { randomInt } from '@aztec/foundation/crypto/random';
|
|
443
|
-
import {
|
|
441
|
+
import { flipSignature, generateRecoverableSignature, generateUnrecoverableSignature } from '@aztec/foundation/crypto/secp256k1-signer';
|
|
442
|
+
import { InterruptError, TimeoutError } from '@aztec/foundation/error';
|
|
444
443
|
import { filter } from '@aztec/foundation/iterator';
|
|
445
|
-
import {
|
|
444
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
445
|
+
import { InterruptibleSleep } from '@aztec/foundation/sleep';
|
|
446
446
|
import { Timer } from '@aztec/foundation/timer';
|
|
447
|
-
import { unfreeze } from '@aztec/foundation/types';
|
|
447
|
+
import { isErrorClass, unfreeze } from '@aztec/foundation/types';
|
|
448
448
|
import { CommitteeAttestationsAndSigners, MaliciousCommitteeAttestationsAndSigners } from '@aztec/stdlib/block';
|
|
449
|
-
import {
|
|
449
|
+
import { getPreviousCheckpointOutHashes, validateCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
450
|
+
import { computeQuorum, getSlotStartBuildTimestamp, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
450
451
|
import { Gas } from '@aztec/stdlib/gas';
|
|
452
|
+
import { InsufficientValidTxsError } from '@aztec/stdlib/interfaces/server';
|
|
451
453
|
import { computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
|
|
452
|
-
import { orderAttestations } from '@aztec/stdlib/p2p';
|
|
454
|
+
import { orderAttestations, trimAttestations } from '@aztec/stdlib/p2p';
|
|
453
455
|
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
454
456
|
import { Attributes, trackSpan } from '@aztec/telemetry-client';
|
|
455
457
|
import { DutyAlreadySignedError, SlashingProtectionError } from '@aztec/validator-ha-signer/errors';
|
|
458
|
+
import { buildCheckpointSimulationOverridesPlan } from './chain_state_overrides.js';
|
|
456
459
|
import { CheckpointVoter } from './checkpoint_voter.js';
|
|
457
460
|
import { SequencerInterruptedError } from './errors.js';
|
|
458
461
|
import { SequencerState } from './utils.js';
|
|
459
462
|
/** How much time to sleep while waiting for min transactions to accumulate for a block */ const TXS_POLLING_MS = 500;
|
|
463
|
+
const ARCHIVER_SYNC_POLLING_MS = 200;
|
|
460
464
|
_dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('CheckpointProposalJob.proposeCheckpoint', function() {
|
|
461
465
|
return {
|
|
462
466
|
// nullish operator needed for tests
|
|
463
467
|
[Attributes.COINBASE]: this.validatorClient.getCoinbaseForAttestor(this.attestorAddress)?.toString(),
|
|
464
|
-
[Attributes.SLOT_NUMBER]: this.
|
|
468
|
+
[Attributes.SLOT_NUMBER]: this.targetSlot
|
|
465
469
|
};
|
|
466
470
|
}), _dec2 = trackSpan('CheckpointProposalJob.buildBlocksForCheckpoint'), _dec3 = trackSpan('CheckpointProposalJob.waitUntilNextSubslot'), _dec4 = trackSpan('CheckpointProposalJob.buildSingleBlock'), _dec5 = trackSpan('CheckpointProposalJob.waitForMinTxs'), _dec6 = trackSpan('CheckpointProposalJob.waitForAttestations'), _dec7 = trackSpan('CheckpointProposalJob.waitUntilTimeInSlot');
|
|
467
471
|
/**
|
|
@@ -470,10 +474,12 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
470
474
|
* as well as enqueueing votes for slashing and governance proposals. This class is created from
|
|
471
475
|
* the Sequencer once the check for being the proposer for the slot has succeeded.
|
|
472
476
|
*/ export class CheckpointProposalJob {
|
|
473
|
-
|
|
474
|
-
|
|
477
|
+
slotNow;
|
|
478
|
+
targetSlot;
|
|
479
|
+
targetEpoch;
|
|
475
480
|
checkpointNumber;
|
|
476
481
|
syncedToBlockNumber;
|
|
482
|
+
checkpointedCheckpointNumber;
|
|
477
483
|
proposer;
|
|
478
484
|
publisher;
|
|
479
485
|
attestorAddress;
|
|
@@ -487,16 +493,18 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
487
493
|
checkpointsBuilder;
|
|
488
494
|
blockSink;
|
|
489
495
|
l1Constants;
|
|
496
|
+
signatureContext;
|
|
490
497
|
config;
|
|
491
498
|
timetable;
|
|
492
499
|
slasherClient;
|
|
493
500
|
epochCache;
|
|
494
501
|
dateProvider;
|
|
495
502
|
metrics;
|
|
503
|
+
checkpointMetrics;
|
|
496
504
|
eventEmitter;
|
|
497
505
|
setStateFn;
|
|
498
|
-
log;
|
|
499
506
|
tracer;
|
|
507
|
+
proposedCheckpointData;
|
|
500
508
|
static{
|
|
501
509
|
({ e: [_initProto] } = _apply_decs_2203_r(this, [
|
|
502
510
|
[
|
|
@@ -541,12 +549,28 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
541
549
|
]
|
|
542
550
|
], []));
|
|
543
551
|
}
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
552
|
+
log;
|
|
553
|
+
checkpointEventLog;
|
|
554
|
+
/** Tracks the fire-and-forget L1 submission promise so it can be awaited during shutdown. */ pendingL1Submission;
|
|
555
|
+
interruptibleSleep;
|
|
556
|
+
interrupted;
|
|
557
|
+
/**
|
|
558
|
+
* Chain state overrides built once per slot in proposeCheckpoint after the checkpoint is
|
|
559
|
+
* complete. Carries the pending parent override (archive + slot + fee header) for pipelining,
|
|
560
|
+
* or the invalidation pending override when rolling back. Consumed by
|
|
561
|
+
* publisher.validateBlockHeader before broadcast.
|
|
562
|
+
*/ checkpointSimulationOverridesPlan;
|
|
563
|
+
getSignatureContext() {
|
|
564
|
+
return this.signatureContext;
|
|
565
|
+
}
|
|
566
|
+
constructor(slotNow, targetSlot, targetEpoch, checkpointNumber, syncedToBlockNumber, checkpointedCheckpointNumber, // TODO(palla/mbps): Can we remove the proposer in favor of attestorAddress? Need to check fisherman-node flows.
|
|
567
|
+
proposer, publisher, attestorAddress, invalidateCheckpoint, validatorClient, globalsBuilder, p2pClient, worldState, l1ToL2MessageSource, l2BlockSource, checkpointsBuilder, blockSink, l1Constants, signatureContext, config, timetable, slasherClient, epochCache, dateProvider, metrics, checkpointMetrics, eventEmitter, setStateFn, tracer, bindings, proposedCheckpointData){
|
|
568
|
+
this.slotNow = slotNow;
|
|
569
|
+
this.targetSlot = targetSlot;
|
|
570
|
+
this.targetEpoch = targetEpoch;
|
|
548
571
|
this.checkpointNumber = checkpointNumber;
|
|
549
572
|
this.syncedToBlockNumber = syncedToBlockNumber;
|
|
573
|
+
this.checkpointedCheckpointNumber = checkpointedCheckpointNumber;
|
|
550
574
|
this.proposer = proposer;
|
|
551
575
|
this.publisher = publisher;
|
|
552
576
|
this.attestorAddress = attestorAddress;
|
|
@@ -560,55 +584,337 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
560
584
|
this.checkpointsBuilder = checkpointsBuilder;
|
|
561
585
|
this.blockSink = blockSink;
|
|
562
586
|
this.l1Constants = l1Constants;
|
|
587
|
+
this.signatureContext = signatureContext;
|
|
563
588
|
this.config = config;
|
|
564
589
|
this.timetable = timetable;
|
|
565
590
|
this.slasherClient = slasherClient;
|
|
566
591
|
this.epochCache = epochCache;
|
|
567
592
|
this.dateProvider = dateProvider;
|
|
568
593
|
this.metrics = metrics;
|
|
594
|
+
this.checkpointMetrics = checkpointMetrics;
|
|
569
595
|
this.eventEmitter = eventEmitter;
|
|
570
596
|
this.setStateFn = setStateFn;
|
|
571
|
-
this.log = log;
|
|
572
597
|
this.tracer = tracer;
|
|
573
|
-
|
|
598
|
+
this.proposedCheckpointData = proposedCheckpointData;
|
|
599
|
+
this.interruptibleSleep = (_initProto(this), new InterruptibleSleep());
|
|
600
|
+
this.interrupted = false;
|
|
601
|
+
this.log = createLogger('sequencer:checkpoint-proposal', {
|
|
602
|
+
...bindings,
|
|
603
|
+
instanceId: `slot-${this.slotNow}`
|
|
604
|
+
});
|
|
605
|
+
this.checkpointEventLog = createLogger('sequencer:checkpoint-events', {
|
|
606
|
+
...bindings,
|
|
607
|
+
instanceId: `slot-${this.slotNow}`
|
|
608
|
+
});
|
|
609
|
+
}
|
|
610
|
+
/** Awaits the pending L1 submission if one is in progress. Call during shutdown. */ async awaitPendingSubmission() {
|
|
611
|
+
this.log.info('Awaiting pending L1 payload submission');
|
|
612
|
+
await this.pendingL1Submission;
|
|
613
|
+
}
|
|
614
|
+
/** Interrupts job-owned waits, including the publisher's send-at-slot sleep, so shutdown can finish. */ interrupt() {
|
|
615
|
+
this.interrupted = true;
|
|
616
|
+
this.interruptibleSleep.interrupt(true);
|
|
617
|
+
this.publisher.interrupt();
|
|
618
|
+
}
|
|
619
|
+
async awaitInterruptibleSleep(ms) {
|
|
620
|
+
if (this.interrupted) {
|
|
621
|
+
throw new SequencerInterruptedError();
|
|
622
|
+
}
|
|
623
|
+
if (ms <= 0) {
|
|
624
|
+
return;
|
|
625
|
+
}
|
|
626
|
+
try {
|
|
627
|
+
await this.interruptibleSleep.sleep(ms);
|
|
628
|
+
} catch (err) {
|
|
629
|
+
if (err instanceof InterruptError) {
|
|
630
|
+
throw new SequencerInterruptedError();
|
|
631
|
+
}
|
|
632
|
+
throw err;
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
logCheckpointEvent(eventName, message, fields) {
|
|
636
|
+
this.checkpointEventLog.debug(message, {
|
|
637
|
+
eventName: `sequencer-checkpoint-${eventName}`,
|
|
638
|
+
...fields
|
|
639
|
+
});
|
|
574
640
|
}
|
|
575
641
|
/**
|
|
576
642
|
* Executes the checkpoint proposal job.
|
|
577
|
-
*
|
|
643
|
+
* Builds blocks, assembles checkpoint, and broadcasts the proposal (blocking).
|
|
644
|
+
* Attestation collection, signing, and L1 submission are backgrounded so the
|
|
645
|
+
* work loop can return to IDLE immediately for consecutive slot proposals.
|
|
646
|
+
* Returns the built checkpoint if successful, undefined otherwise.
|
|
578
647
|
*/ async execute() {
|
|
579
648
|
// Enqueue governance and slashing votes (returns promises that will be awaited later)
|
|
580
649
|
// In fisherman mode, we simulate slashing but don't actually publish to L1
|
|
581
650
|
// These are constant for the whole slot, so we only enqueue them once
|
|
582
|
-
const votesPromises = new CheckpointVoter(this.
|
|
583
|
-
// Build
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
651
|
+
const votesPromises = new CheckpointVoter(this.targetSlot, this.publisher, this.attestorAddress, this.validatorClient, this.slasherClient, this.l1Constants, this.config, this.metrics, this.log).enqueueVotes();
|
|
652
|
+
// Build blocks, assemble checkpoint, and broadcast proposal (BLOCKING).
|
|
653
|
+
// Returns after broadcast — attestation collection is deferred.
|
|
654
|
+
const broadcast = await this.proposeCheckpoint();
|
|
655
|
+
if (!broadcast) {
|
|
656
|
+
await Promise.all(votesPromises);
|
|
657
|
+
// Still submit votes even without a checkpoint.
|
|
658
|
+
// Under proposer pipelining, vote-offenses signatures are EIP-712-bound to `targetSlot`
|
|
659
|
+
// (the pipelined slot in which the multicall is expected to mine). Submitting at the
|
|
660
|
+
// wall-clock time would let the multicall mine in a different L2 slot, causing
|
|
661
|
+
// signature verification to fail silently inside Multicall3. Delay submission to the
|
|
662
|
+
// start of `targetSlot` so the tx mines in the slot the vote was signed for.
|
|
663
|
+
if (!this.config.fishermanMode) {
|
|
664
|
+
this.pendingL1Submission = this.publisher.sendRequestsAt(this.targetSlot).then(()=>{});
|
|
665
|
+
}
|
|
666
|
+
return undefined;
|
|
589
667
|
}
|
|
668
|
+
const { checkpoint } = broadcast;
|
|
669
|
+
this.metrics.recordCheckpointProposalSuccess();
|
|
590
670
|
// Do not post anything to L1 if we are fishermen, but do perform L1 fee analysis
|
|
591
671
|
if (this.config.fishermanMode) {
|
|
592
672
|
await this.handleCheckpointEndAsFisherman(checkpoint);
|
|
593
|
-
return;
|
|
673
|
+
return checkpoint;
|
|
594
674
|
}
|
|
595
|
-
//
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
675
|
+
// Background the attestation → signing → L1 pipeline so the work loop is unblocked
|
|
676
|
+
this.pendingL1Submission = this.waitForAttestationsAndEnqueueSubmissionAsync(broadcast, votesPromises);
|
|
677
|
+
// Return the built checkpoint immediately — the work loop is now unblocked
|
|
678
|
+
return checkpoint;
|
|
679
|
+
}
|
|
680
|
+
/**
|
|
681
|
+
* Background pipeline: collects attestations, signs them, enqueues the checkpoint, and submits to L1.
|
|
682
|
+
* Runs as a fire-and-forget task stored in `pendingL1Submission` so the work loop is unblocked.
|
|
683
|
+
*/ async waitForAttestationsAndEnqueueSubmissionAsync(broadcast, votesPromises) {
|
|
684
|
+
const { checkpoint } = broadcast;
|
|
685
|
+
try {
|
|
686
|
+
// Wait for all votes actions, enqueued at the beginning, to resolve
|
|
687
|
+
await Promise.all(votesPromises);
|
|
688
|
+
// Try to collect attestations from the committee
|
|
689
|
+
const signedAttestations = await this.getSignedCommitteeAttestations(broadcast);
|
|
690
|
+
// Wait for the previous checkpoint to land on L1 before submitting, so we can check it
|
|
691
|
+
// matches the proposed checkpoint we used as parent, and has valid attestations.
|
|
692
|
+
if (signedAttestations && await this.waitForValidParentCheckpointOnL1()) {
|
|
693
|
+
await this.enqueueCheckpointForSubmission({
|
|
694
|
+
checkpoint,
|
|
695
|
+
...signedAttestations
|
|
696
|
+
});
|
|
697
|
+
}
|
|
698
|
+
// If we failed to collect attestations, at least check if we need to issue an invalidation
|
|
699
|
+
if (!signedAttestations && await this.waitForSyncedL2SlotNumber(this.slotNow)) {
|
|
700
|
+
const validationStatus = await this.l2BlockSource.getPendingChainValidationStatus();
|
|
701
|
+
if (!validationStatus.valid) {
|
|
702
|
+
this.log.warn(`Checkpoint ${validationStatus.checkpoint.checkpointNumber} has invalid attestations, enqueuing invalidation in spite of attestation collection failure`, {
|
|
703
|
+
checkpoint: validationStatus.checkpoint,
|
|
704
|
+
reason: validationStatus.reason
|
|
705
|
+
});
|
|
706
|
+
await this.enqueueInvalidation(validationStatus);
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
// Send whatever was enqueued: votes + (propose | invalidation | nothing).
|
|
710
|
+
const l1Response = await this.publisher.sendRequestsAt(this.targetSlot);
|
|
711
|
+
const proposedAction = l1Response?.successfulActions.find((a)=>a === 'propose');
|
|
712
|
+
if (proposedAction) {
|
|
713
|
+
this.logCheckpointEvent('published', `Checkpoint published for slot ${this.targetSlot}`, {
|
|
714
|
+
slot: this.targetSlot,
|
|
715
|
+
checkpointNumber: this.checkpointNumber,
|
|
716
|
+
successfulActions: l1Response?.successfulActions,
|
|
717
|
+
sentActions: l1Response?.sentActions
|
|
718
|
+
});
|
|
719
|
+
this.eventEmitter.emit('checkpoint-published', {
|
|
720
|
+
checkpoint: this.checkpointNumber,
|
|
721
|
+
slot: this.targetSlot
|
|
722
|
+
});
|
|
723
|
+
const coinbase = checkpoint.header.coinbase;
|
|
724
|
+
await this.metrics.incFilledSlot(this.publisher.getSenderAddress().toString(), coinbase);
|
|
725
|
+
} else {
|
|
726
|
+
this.logCheckpointEvent('publish-failed', `Checkpoint publish failed for slot ${this.targetSlot}`, {
|
|
727
|
+
slot: this.targetSlot,
|
|
728
|
+
checkpointNumber: this.checkpointNumber,
|
|
729
|
+
successfulActions: l1Response?.successfulActions,
|
|
730
|
+
failedActions: l1Response?.failedActions,
|
|
731
|
+
sentActions: l1Response?.sentActions,
|
|
732
|
+
expiredActions: l1Response?.expiredActions,
|
|
733
|
+
reason: 'propose_action_not_successful'
|
|
734
|
+
});
|
|
735
|
+
this.log.warn(`Checkpoint publish failed for slot ${this.targetSlot}`, {
|
|
736
|
+
slot: this.targetSlot,
|
|
737
|
+
checkpointNumber: this.checkpointNumber,
|
|
738
|
+
successfulActions: l1Response?.successfulActions,
|
|
739
|
+
failedActions: l1Response?.failedActions,
|
|
740
|
+
sentActions: l1Response?.sentActions,
|
|
741
|
+
expiredActions: l1Response?.expiredActions,
|
|
742
|
+
reason: 'propose_action_not_successful'
|
|
743
|
+
});
|
|
744
|
+
this.eventEmitter.emit('checkpoint-publish-failed', {
|
|
745
|
+
...l1Response,
|
|
746
|
+
slot: this.targetSlot
|
|
747
|
+
});
|
|
748
|
+
this.metrics.recordPipelineDiscard();
|
|
749
|
+
}
|
|
750
|
+
} catch (err) {
|
|
751
|
+
if (err instanceof SequencerInterruptedError) {
|
|
752
|
+
return;
|
|
753
|
+
}
|
|
754
|
+
this.logCheckpointEvent('publish-failed', `Checkpoint publish failed for slot ${this.targetSlot}`, {
|
|
755
|
+
slot: this.targetSlot,
|
|
756
|
+
checkpointNumber: this.checkpointNumber,
|
|
757
|
+
reason: err instanceof Error ? err.message : String(err)
|
|
758
|
+
});
|
|
759
|
+
this.log.error(`Background attestation/L1 pipeline failed for slot ${this.targetSlot}`, err, {
|
|
760
|
+
slot: this.targetSlot,
|
|
761
|
+
checkpointNumber: this.checkpointNumber,
|
|
762
|
+
reason: err instanceof Error ? err.message : String(err)
|
|
602
763
|
});
|
|
603
|
-
const coinbase = checkpoint?.header.coinbase;
|
|
604
|
-
await this.metrics.incFilledSlot(this.publisher.getSenderAddress().toString(), coinbase);
|
|
605
|
-
return checkpoint;
|
|
606
|
-
} else if (checkpoint) {
|
|
607
764
|
this.eventEmitter.emit('checkpoint-publish-failed', {
|
|
608
|
-
|
|
609
|
-
|
|
765
|
+
slot: this.targetSlot
|
|
766
|
+
});
|
|
767
|
+
this.metrics.recordPipelineDiscard();
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
/** Enqueues the checkpoint for L1 submission. Called after pipeline sleep in execute(). */ async enqueueCheckpointForSubmission(result) {
|
|
771
|
+
const { checkpoint, attestations, attestationsSignature } = result;
|
|
772
|
+
// Build-frame deadlines are measured against `slotNow`; observers still see `targetSlot`.
|
|
773
|
+
this.setStateFn(SequencerState.PUBLISHING_CHECKPOINT, this.targetSlot, this.slotNow);
|
|
774
|
+
const aztecSlotDuration = this.l1Constants.slotDuration;
|
|
775
|
+
const submissionSlotStart = Number(getTimestampForSlot(this.targetSlot, this.l1Constants));
|
|
776
|
+
const txTimeoutAt = new Date((submissionSlotStart + aztecSlotDuration) * 1000);
|
|
777
|
+
// If we have been configured to potentially skip publishing checkpoint then roll the dice here
|
|
778
|
+
if (this.config.skipPublishingCheckpointsPercent !== undefined && this.config.skipPublishingCheckpointsPercent > 0) {
|
|
779
|
+
const roll = Math.max(0, randomInt(100));
|
|
780
|
+
if (roll < this.config.skipPublishingCheckpointsPercent) {
|
|
781
|
+
this.log.warn(`Skipping publishing proposal for checkpoint ${checkpoint.number}. Configured percentage: ${this.config.skipPublishingCheckpointsPercent}, generated value: ${roll}`);
|
|
782
|
+
return;
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
await this.publisher.enqueueProposeCheckpoint(checkpoint, attestations, attestationsSignature, {
|
|
786
|
+
txTimeoutAt
|
|
787
|
+
});
|
|
788
|
+
}
|
|
789
|
+
/**
|
|
790
|
+
* Wait until the archiver syncs past the given L2 slot number.
|
|
791
|
+
* The deadline is the end of `this.targetSlot`, beyond which any pipelined work would miss its
|
|
792
|
+
* L1 submission window and is no longer useful.
|
|
793
|
+
*/ async waitForSyncedL2SlotNumber(waitForSlot) {
|
|
794
|
+
const targetSlotStart = Number(getTimestampForSlot(this.targetSlot, this.l1Constants));
|
|
795
|
+
const targetSlotEndMs = (targetSlotStart + this.l1Constants.slotDuration) * 1000;
|
|
796
|
+
const syncDelayTolerance = this.l1Constants.ethereumSlotDuration * 2 * 1000;
|
|
797
|
+
const timeoutSeconds = Math.max(0.1, (targetSlotEndMs + syncDelayTolerance - this.dateProvider.now()) / 1000);
|
|
798
|
+
try {
|
|
799
|
+
const timer = new Timer();
|
|
800
|
+
while(true){
|
|
801
|
+
const syncedSlot = await this.l2BlockSource.getSyncedL2SlotNumber();
|
|
802
|
+
if (syncedSlot !== undefined && syncedSlot >= waitForSlot) {
|
|
803
|
+
return true;
|
|
804
|
+
}
|
|
805
|
+
if (timeoutSeconds && timer.s() > timeoutSeconds) {
|
|
806
|
+
throw new TimeoutError(`Timeout awaiting archiver sync past slot ${waitForSlot}`);
|
|
807
|
+
}
|
|
808
|
+
await this.awaitInterruptibleSleep(ARCHIVER_SYNC_POLLING_MS);
|
|
809
|
+
}
|
|
810
|
+
} catch (err) {
|
|
811
|
+
if (err instanceof SequencerInterruptedError) {
|
|
812
|
+
throw err;
|
|
813
|
+
}
|
|
814
|
+
this.log.warn(`Archiver did not sync L1 past slot ${waitForSlot} before slot ${this.targetSlot} expired, discarding pipelined work`, {
|
|
815
|
+
checkpointNumber: this.checkpointNumber
|
|
816
|
+
});
|
|
817
|
+
this.emitPipelinedCheckpointDiscarded('archiver-sync-timeout');
|
|
818
|
+
return false;
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
/**
|
|
822
|
+
* Waits for the parent checkpoint to land on L1 before submitting a pipelined checkpoint.
|
|
823
|
+
* Polls until the archiver has synced L1 past the parent's slot, then verifies:
|
|
824
|
+
* - If we built on a proposed parent: it must have landed on L1 with matching hash and valid attestations.
|
|
825
|
+
* - If we built without a proposed parent: no new checkpoint must have appeared for that slot.
|
|
826
|
+
* If the parent has invalid attestations, enqueues an invalidation. Returns whether to proceed with the proposal.
|
|
827
|
+
*/ async waitForValidParentCheckpointOnL1() {
|
|
828
|
+
if (this.config.skipWaitForValidParentCheckpointOnL1) {
|
|
829
|
+
this.log.warn(`Skipping waitForValidParentCheckpointOnL1 due to test configuration`, {
|
|
830
|
+
checkpointNumber: this.checkpointNumber
|
|
831
|
+
});
|
|
832
|
+
return true;
|
|
833
|
+
}
|
|
834
|
+
const parentCheckpointNumber = CheckpointNumber(this.checkpointNumber - 1);
|
|
835
|
+
// Wait until archiver has synced L1 past the parent's slot (slotNow)
|
|
836
|
+
if (!await this.waitForSyncedL2SlotNumber(this.slotNow)) {
|
|
837
|
+
return false;
|
|
838
|
+
}
|
|
839
|
+
const tips = await this.l2BlockSource.getL2Tips();
|
|
840
|
+
const checkpointedNumber = tips.checkpointed.checkpoint.number;
|
|
841
|
+
// We built on top of a proposed checkpoint. Verify it landed on L1 as expected.
|
|
842
|
+
if (this.proposedCheckpointData) {
|
|
843
|
+
// After syncing from L1 we see the chain tip has invalid attestations. This means the parent checkpoint was posted
|
|
844
|
+
// with invalid attestations, or it built on top of something with invalid attestations and didnt invalidate them.
|
|
845
|
+
// Either way, we thought our parent would be valid, so we have to throw away our work. But at least we'll try and
|
|
846
|
+
// invalidate on L1 so we clean up the chain for the next proposer. And we'll slash them, but that's handled elsewhere.
|
|
847
|
+
const validationStatus = await this.l2BlockSource.getPendingChainValidationStatus();
|
|
848
|
+
if (!validationStatus.valid) {
|
|
849
|
+
this.log.warn(`Parent checkpoint ${parentCheckpointNumber} has invalid attestations, discarding pipelined work`, {
|
|
850
|
+
checkpointNumber: this.checkpointNumber,
|
|
851
|
+
reason: validationStatus.reason
|
|
852
|
+
});
|
|
853
|
+
this.emitPipelinedCheckpointDiscarded('parent-invalid-attestations');
|
|
854
|
+
await this.enqueueInvalidation(validationStatus);
|
|
855
|
+
return false;
|
|
856
|
+
}
|
|
857
|
+
// The pending chain is valid. But did the parent checkpoint land on L1 at all?
|
|
858
|
+
if (checkpointedNumber < parentCheckpointNumber) {
|
|
859
|
+
this.log.warn(`Parent checkpoint ${parentCheckpointNumber} did not land on L1, discarding pipelined work`, {
|
|
860
|
+
checkpointNumber: this.checkpointNumber,
|
|
861
|
+
checkpointedNumber
|
|
862
|
+
});
|
|
863
|
+
this.emitPipelinedCheckpointDiscarded('parent-not-on-l1');
|
|
864
|
+
return false;
|
|
865
|
+
}
|
|
866
|
+
// It landed. But is it the one we were expecting?
|
|
867
|
+
const expectedHash = this.proposedCheckpointData.header.hash().toString();
|
|
868
|
+
if (tips.checkpointed.checkpoint.hash !== expectedHash) {
|
|
869
|
+
this.log.warn(`Parent checkpoint ${parentCheckpointNumber} hash mismatch on L1, discarding pipelined work`, {
|
|
870
|
+
checkpointNumber: this.checkpointNumber,
|
|
871
|
+
expectedHash,
|
|
872
|
+
actualHash: tips.checkpointed.checkpoint.hash
|
|
873
|
+
});
|
|
874
|
+
this.emitPipelinedCheckpointDiscarded('parent-hash-mismatch');
|
|
875
|
+
return false;
|
|
876
|
+
}
|
|
877
|
+
return true;
|
|
878
|
+
} else {
|
|
879
|
+
// We didn't see a proposed checkpoint at build time, so we built on checkpointed parent from two slots ago.
|
|
880
|
+
// But if a new checkpoint for the previous slot appeared on L1 in the meantime, our checkpoint assumed the wrong parent,
|
|
881
|
+
// so we have to discard our work. This can happen if we're somehow cut off from p2p and fail to see the checkpoint
|
|
882
|
+
// proposal for the previous slot.
|
|
883
|
+
if (checkpointedNumber > parentCheckpointNumber) {
|
|
884
|
+
this.log.warn(`Unexpected checkpoint ${checkpointedNumber} landed on L1 after we built on top of parent ${parentCheckpointNumber}, discarding pipelined work`, {
|
|
885
|
+
checkpointNumber: this.checkpointNumber,
|
|
886
|
+
checkpointedNumber
|
|
887
|
+
});
|
|
888
|
+
this.emitPipelinedCheckpointDiscarded('unexpected-parent-appeared');
|
|
889
|
+
return false;
|
|
890
|
+
}
|
|
891
|
+
return true;
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
/** Emits the pipelined-checkpoint-discarded event and records the metric. */ emitPipelinedCheckpointDiscarded(reason) {
|
|
895
|
+
this.metrics.recordPipelineParentCheckpointMismatch(reason);
|
|
896
|
+
this.eventEmitter.emit('pipelined-checkpoint-discarded', {
|
|
897
|
+
slot: this.targetSlot,
|
|
898
|
+
checkpointNumber: this.checkpointNumber,
|
|
899
|
+
reason
|
|
900
|
+
});
|
|
901
|
+
}
|
|
902
|
+
/** Simulates and enqueues an invalidation request for the invalid parent checkpoint. */ async enqueueInvalidation(validationStatus) {
|
|
903
|
+
if (this.config.skipInvalidateBlockAsProposer) {
|
|
904
|
+
this.log.warn(`Skipping checkpoint invalidation as proposer due to test configuration`);
|
|
905
|
+
return;
|
|
906
|
+
}
|
|
907
|
+
const invalidateRequest = await this.publisher.simulateInvalidateCheckpoint(validationStatus);
|
|
908
|
+
if (invalidateRequest) {
|
|
909
|
+
const submissionSlotStart = Number(getTimestampForSlot(this.targetSlot, this.l1Constants));
|
|
910
|
+
const txTimeoutAt = new Date((submissionSlotStart + this.l1Constants.slotDuration) * 1000);
|
|
911
|
+
this.publisher.enqueueInvalidateCheckpoint(invalidateRequest, {
|
|
912
|
+
txTimeoutAt
|
|
913
|
+
});
|
|
914
|
+
} else {
|
|
915
|
+
this.log.info(`Invalidation simulation returned undefined, checkpoint may have been removed already`, {
|
|
916
|
+
checkpointNumber: this.checkpointNumber
|
|
610
917
|
});
|
|
611
|
-
return undefined;
|
|
612
918
|
}
|
|
613
919
|
}
|
|
614
920
|
async proposeCheckpoint() {
|
|
@@ -619,29 +925,75 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
619
925
|
hasError: false
|
|
620
926
|
};
|
|
621
927
|
try {
|
|
928
|
+
const now = this.dateProvider.now();
|
|
929
|
+
if (this.proposedCheckpointData) {
|
|
930
|
+
// Measure against the wall-clock slot whose build window we are currently using.
|
|
931
|
+
// In pipelining mode `targetSlot` is intentionally one slot ahead, which makes the
|
|
932
|
+
// target-slot boundary a full slot away from the actual build start time.
|
|
933
|
+
const slotBoundaryMs = Number(getTimestampForSlot(this.slotNow, this.l1Constants)) * 1000;
|
|
934
|
+
this.checkpointMetrics.recordPipelinedCheckpointBuildStartOffsetFromSlotBoundary(now - slotBoundaryMs);
|
|
935
|
+
}
|
|
936
|
+
this.checkpointMetrics.startCheckpointTiming(now);
|
|
622
937
|
// Get operator configured coinbase and fee recipient for this attestor
|
|
623
938
|
const coinbase = this.validatorClient.getCoinbaseForAttestor(this.attestorAddress);
|
|
624
939
|
const feeRecipient = this.validatorClient.getFeeRecipientForAttestor(this.attestorAddress);
|
|
625
940
|
// Start the checkpoint
|
|
626
|
-
this.setStateFn(SequencerState.INITIALIZING_CHECKPOINT, this.
|
|
627
|
-
this.
|
|
941
|
+
this.setStateFn(SequencerState.INITIALIZING_CHECKPOINT, this.targetSlot, this.slotNow);
|
|
942
|
+
this.logCheckpointEvent('slot-started', `Starting checkpoint proposal for slot ${this.targetSlot}`, {
|
|
943
|
+
buildSlot: this.slotNow,
|
|
944
|
+
submissionSlot: this.targetSlot,
|
|
945
|
+
slot: this.targetSlot,
|
|
946
|
+
checkpointNumber: this.checkpointNumber,
|
|
947
|
+
proposer: this.proposer?.toString(),
|
|
948
|
+
attestorAddress: this.attestorAddress.toString(),
|
|
949
|
+
publisherAddress: this.publisher.getSenderAddress().toString(),
|
|
950
|
+
coinbase: coinbase.toString()
|
|
951
|
+
});
|
|
952
|
+
this.metrics.incOpenSlot(this.targetSlot, this.proposer?.toString() ?? 'unknown');
|
|
628
953
|
// Enqueues checkpoint invalidation (constant for the whole slot)
|
|
629
954
|
if (this.invalidateCheckpoint && !this.config.skipInvalidateBlockAsProposer) {
|
|
630
955
|
this.publisher.enqueueInvalidateCheckpoint(this.invalidateCheckpoint);
|
|
631
956
|
}
|
|
632
|
-
//
|
|
633
|
-
|
|
957
|
+
// Build the simulation plan for this slot. When pipelining, this overrides L1's view of
|
|
958
|
+
// pending/archive/fee-header to "as if the proposed parent had landed", so both the
|
|
959
|
+
// mana-min-fee simulation (in the globals builder) and the pre-broadcast
|
|
960
|
+
// validateBlockHeader see the chain tip the eventual L1 send will see.
|
|
961
|
+
this.checkpointSimulationOverridesPlan = await buildCheckpointSimulationOverridesPlan({
|
|
962
|
+
checkpointNumber: this.checkpointNumber,
|
|
963
|
+
proposedCheckpointData: this.proposedCheckpointData,
|
|
964
|
+
invalidateToPendingCheckpointNumber: this.invalidateCheckpoint?.forcePendingCheckpointNumber,
|
|
965
|
+
checkpointedCheckpointNumber: this.checkpointedCheckpointNumber,
|
|
966
|
+
rollup: this.publisher.rollupContract,
|
|
967
|
+
signatureContext: this.signatureContext,
|
|
968
|
+
log: this.log
|
|
969
|
+
});
|
|
970
|
+
const checkpointGlobalVariables = await this.globalsBuilder.buildCheckpointGlobalVariables(coinbase, feeRecipient, this.targetSlot, this.checkpointSimulationOverridesPlan);
|
|
634
971
|
// Collect L1 to L2 messages for the checkpoint and compute their hash
|
|
635
972
|
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(this.checkpointNumber);
|
|
636
973
|
const inHash = computeInHashFromL1ToL2Messages(l1ToL2Messages);
|
|
637
|
-
// Collect the out hashes of all the checkpoints before this one in the same epoch
|
|
638
|
-
|
|
639
|
-
|
|
974
|
+
// Collect the out hashes of all the checkpoints before this one in the same epoch.
|
|
975
|
+
// Under pipelining the parent checkpoint may not be on L1 yet at build time, so the helper
|
|
976
|
+
// splices in the parent's checkpointOutHash from the locally-known proposed checkpoint so
|
|
977
|
+
// the resulting `epochOutHash` matches what validators (and L1) compute once the parent
|
|
978
|
+
// lands on L1.
|
|
979
|
+
const previousCheckpointOutHashes = await getPreviousCheckpointOutHashes({
|
|
980
|
+
blockSource: this.l2BlockSource,
|
|
981
|
+
epoch: this.targetEpoch,
|
|
982
|
+
checkpointNumber: this.checkpointNumber,
|
|
983
|
+
l1Constants: this.epochCache.getL1Constants(),
|
|
984
|
+
pipeliningEnabled: true,
|
|
985
|
+
proposedCheckpointData: this.proposedCheckpointData,
|
|
986
|
+
log: this.log
|
|
987
|
+
});
|
|
988
|
+
// Anchor the modifier to the predicted parent fee header: L1 will apply it against
|
|
989
|
+
// that, not against the latest published checkpoint (which lags by one under pipelining).
|
|
990
|
+
const predictedParentEthPerFeeAssetE12 = this.checkpointSimulationOverridesPlan?.pendingCheckpointState?.feeHeader?.ethPerFeeAsset;
|
|
991
|
+
const feeAssetPriceModifier = await this.publisher.getFeeAssetPriceModifier(predictedParentEthPerFeeAssetE12);
|
|
640
992
|
const fork = _ts_add_disposable_resource(env, await this.worldState.fork(this.syncedToBlockNumber, {
|
|
641
993
|
closeDelayMs: 12_000
|
|
642
|
-
}),
|
|
994
|
+
}), true);
|
|
643
995
|
// Create checkpoint builder for the entire slot
|
|
644
|
-
const checkpointBuilder = await this.checkpointsBuilder.startCheckpoint(this.checkpointNumber, checkpointGlobalVariables, l1ToL2Messages, previousCheckpointOutHashes, fork);
|
|
996
|
+
const checkpointBuilder = await this.checkpointsBuilder.startCheckpoint(this.checkpointNumber, checkpointGlobalVariables, feeAssetPriceModifier, l1ToL2Messages, previousCheckpointOutHashes, fork, this.log.getBindings());
|
|
645
997
|
// Options for the validator client when creating block and checkpoint proposals
|
|
646
998
|
const blockProposalOptions = {
|
|
647
999
|
publishFullTxs: !!this.config.publishTxsWithProposals,
|
|
@@ -649,10 +1001,11 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
649
1001
|
};
|
|
650
1002
|
const checkpointProposalOptions = {
|
|
651
1003
|
publishFullTxs: !!this.config.publishTxsWithProposals,
|
|
652
|
-
broadcastInvalidCheckpointProposal: this.config.broadcastInvalidBlockProposal
|
|
1004
|
+
broadcastInvalidCheckpointProposal: this.config.broadcastInvalidCheckpointProposalOnly || this.config.broadcastInvalidBlockProposal
|
|
653
1005
|
};
|
|
654
1006
|
let blocksInCheckpoint = [];
|
|
655
1007
|
let blockPendingBroadcast = undefined;
|
|
1008
|
+
const checkpointBuildTimer = new Timer();
|
|
656
1009
|
try {
|
|
657
1010
|
// Main loop: build blocks for the checkpoint
|
|
658
1011
|
const result = await this.buildBlocksForCheckpoint(checkpointBuilder, checkpointGlobalVariables.timestamp, inHash, blockProposalOptions);
|
|
@@ -662,107 +1015,162 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
662
1015
|
// These errors are expected in HA mode, so we yield and let another HA node handle the slot
|
|
663
1016
|
// The only distinction between the 2 errors is SlashingProtectionError throws when the payload is different,
|
|
664
1017
|
// which is normal for block building (may have picked different txs)
|
|
665
|
-
if (err
|
|
666
|
-
this.log.info(`Checkpoint proposal for slot ${this.slot} already signed by another HA node, yielding`, {
|
|
667
|
-
slot: this.slot,
|
|
668
|
-
signedByNode: err.signedByNode
|
|
669
|
-
});
|
|
670
|
-
return undefined;
|
|
671
|
-
}
|
|
672
|
-
if (err instanceof SlashingProtectionError) {
|
|
673
|
-
this.log.info(`Checkpoint proposal for slot ${this.slot} blocked by slashing protection, yielding`, {
|
|
674
|
-
slot: this.slot,
|
|
675
|
-
existingMessageHash: err.existingMessageHash,
|
|
676
|
-
attemptedMessageHash: err.attemptedMessageHash
|
|
677
|
-
});
|
|
1018
|
+
if (this.handleHASigningError(err, 'Block proposal')) {
|
|
678
1019
|
return undefined;
|
|
679
1020
|
}
|
|
680
1021
|
throw err;
|
|
681
1022
|
}
|
|
682
1023
|
if (blocksInCheckpoint.length === 0) {
|
|
683
|
-
this.
|
|
684
|
-
slot: this.
|
|
1024
|
+
this.logCheckpointEvent('build-failed', `Checkpoint build failed for slot ${this.targetSlot}`, {
|
|
1025
|
+
slot: this.targetSlot,
|
|
1026
|
+
checkpointNumber: this.checkpointNumber,
|
|
1027
|
+
reason: 'no_blocks_built'
|
|
1028
|
+
});
|
|
1029
|
+
this.log.warn(`No blocks were built for slot ${this.targetSlot}`, {
|
|
1030
|
+
slot: this.targetSlot,
|
|
1031
|
+
checkpointNumber: this.checkpointNumber,
|
|
1032
|
+
reason: 'no_blocks_built'
|
|
685
1033
|
});
|
|
686
1034
|
this.eventEmitter.emit('checkpoint-empty', {
|
|
687
|
-
slot: this.
|
|
1035
|
+
slot: this.targetSlot
|
|
1036
|
+
});
|
|
1037
|
+
return undefined;
|
|
1038
|
+
}
|
|
1039
|
+
const minBlocksForCheckpoint = this.config.minBlocksForCheckpoint;
|
|
1040
|
+
if (minBlocksForCheckpoint !== undefined && blocksInCheckpoint.length < minBlocksForCheckpoint) {
|
|
1041
|
+
this.logCheckpointEvent('build-failed', `Checkpoint build failed for slot ${this.targetSlot}`, {
|
|
1042
|
+
slot: this.targetSlot,
|
|
1043
|
+
checkpointNumber: this.checkpointNumber,
|
|
1044
|
+
blocksBuilt: blocksInCheckpoint.length,
|
|
1045
|
+
minBlocksForCheckpoint,
|
|
1046
|
+
reason: 'min_blocks_not_met'
|
|
1047
|
+
});
|
|
1048
|
+
this.log.warn(`Checkpoint has fewer blocks than minimum (${blocksInCheckpoint.length} < ${minBlocksForCheckpoint}), skipping proposal`, {
|
|
1049
|
+
slot: this.targetSlot,
|
|
1050
|
+
checkpointNumber: this.checkpointNumber,
|
|
1051
|
+
blocksBuilt: blocksInCheckpoint.length,
|
|
1052
|
+
minBlocksForCheckpoint,
|
|
1053
|
+
reason: 'min_blocks_not_met'
|
|
688
1054
|
});
|
|
689
1055
|
return undefined;
|
|
690
1056
|
}
|
|
691
1057
|
// Assemble and broadcast the checkpoint proposal, including the last block that was not
|
|
692
1058
|
// broadcasted yet, and wait to collect the committee attestations.
|
|
693
|
-
this.setStateFn(SequencerState.ASSEMBLING_CHECKPOINT, this.
|
|
1059
|
+
this.setStateFn(SequencerState.ASSEMBLING_CHECKPOINT, this.targetSlot, this.slotNow);
|
|
694
1060
|
const checkpoint = await checkpointBuilder.completeCheckpoint();
|
|
695
|
-
//
|
|
1061
|
+
// Final validation: per-block limits are only checked if the operator set them explicitly.
|
|
1062
|
+
// Otherwise, checkpoint-level budgets were already enforced by the redistribution logic.
|
|
1063
|
+
try {
|
|
1064
|
+
validateCheckpoint(checkpoint, {
|
|
1065
|
+
rollupManaLimit: this.l1Constants.rollupManaLimit,
|
|
1066
|
+
maxL2BlockGas: this.config.maxL2BlockGas,
|
|
1067
|
+
maxDABlockGas: this.config.maxDABlockGas,
|
|
1068
|
+
maxTxsPerBlock: this.config.maxTxsPerBlock,
|
|
1069
|
+
maxTxsPerCheckpoint: this.config.maxTxsPerCheckpoint
|
|
1070
|
+
});
|
|
1071
|
+
} catch (err) {
|
|
1072
|
+
this.logCheckpointEvent('build-failed', `Checkpoint build failed for slot ${this.targetSlot}`, {
|
|
1073
|
+
slot: this.targetSlot,
|
|
1074
|
+
checkpointNumber: this.checkpointNumber,
|
|
1075
|
+
blocksBuilt: blocksInCheckpoint.length,
|
|
1076
|
+
reason: 'invalid_checkpoint',
|
|
1077
|
+
checkpoint: checkpoint.header.toInspect()
|
|
1078
|
+
});
|
|
1079
|
+
this.log.error(`Built an invalid checkpoint at slot ${this.slotNow} (skipping proposal)`, err, {
|
|
1080
|
+
slot: this.targetSlot,
|
|
1081
|
+
checkpointNumber: this.checkpointNumber,
|
|
1082
|
+
blocksBuilt: blocksInCheckpoint.length,
|
|
1083
|
+
reason: 'invalid_checkpoint',
|
|
1084
|
+
checkpoint: checkpoint.header.toInspect()
|
|
1085
|
+
});
|
|
1086
|
+
return undefined;
|
|
1087
|
+
}
|
|
1088
|
+
// Record checkpoint-level build metrics
|
|
1089
|
+
this.checkpointMetrics.recordCheckpointBuild(checkpointBuildTimer.ms(), blocksInCheckpoint.length, checkpoint.getStats().txCount, Number(checkpoint.header.totalManaUsed.toBigInt()));
|
|
1090
|
+
this.logCheckpointEvent('built', `Checkpoint built for slot ${this.targetSlot}`, {
|
|
1091
|
+
slot: this.targetSlot,
|
|
1092
|
+
buildSlot: this.slotNow,
|
|
1093
|
+
checkpointNumber: this.checkpointNumber,
|
|
1094
|
+
proposer: this.proposer?.toString(),
|
|
1095
|
+
attestorAddress: this.attestorAddress.toString(),
|
|
1096
|
+
publisherAddress: this.publisher.getSenderAddress().toString(),
|
|
1097
|
+
blocksBuilt: blocksInCheckpoint.length,
|
|
1098
|
+
txCount: checkpoint.getStats().txCount,
|
|
1099
|
+
totalMana: Number(checkpoint.header.totalManaUsed.toBigInt())
|
|
1100
|
+
});
|
|
1101
|
+
// In fisherman mode, return the checkpoint without broadcasting or collecting attestations
|
|
696
1102
|
if (this.config.fishermanMode) {
|
|
697
|
-
this.log.info(`Built checkpoint for slot ${this.
|
|
698
|
-
slot: this.
|
|
1103
|
+
this.log.info(`Built checkpoint for slot ${this.targetSlot} with ${blocksInCheckpoint.length} blocks. ` + `Skipping proposal in fisherman mode.`, {
|
|
1104
|
+
slot: this.targetSlot,
|
|
699
1105
|
checkpoint: checkpoint.header.toInspect(),
|
|
700
1106
|
blocksBuilt: blocksInCheckpoint.length
|
|
701
1107
|
});
|
|
702
1108
|
this.metrics.recordCheckpointSuccess();
|
|
703
|
-
|
|
1109
|
+
// Return a broadcast result with a dummy proposal — fisherman mode skips attestation collection
|
|
1110
|
+
return {
|
|
1111
|
+
checkpoint,
|
|
1112
|
+
proposal: undefined,
|
|
1113
|
+
blockProposedAt: this.dateProvider.now()
|
|
1114
|
+
};
|
|
704
1115
|
}
|
|
705
|
-
//
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
indexWithinCheckpoint: blockPendingBroadcast.block.indexWithinCheckpoint,
|
|
709
|
-
txs: blockPendingBroadcast.txs
|
|
710
|
-
};
|
|
711
|
-
// Create the checkpoint proposal and broadcast it
|
|
712
|
-
const proposal = await this.validatorClient.createCheckpointProposal(checkpoint.header, checkpoint.archive.root, lastBlock, this.proposer, checkpointProposalOptions);
|
|
713
|
-
const blockProposedAt = this.dateProvider.now();
|
|
714
|
-
await this.p2pClient.broadcastCheckpointProposal(proposal);
|
|
715
|
-
this.setStateFn(SequencerState.COLLECTING_ATTESTATIONS, this.slot);
|
|
716
|
-
const attestations = await this.waitForAttestations(proposal);
|
|
717
|
-
const blockAttestedAt = this.dateProvider.now();
|
|
718
|
-
this.metrics.recordCheckpointAttestationDelay(blockAttestedAt - blockProposedAt);
|
|
719
|
-
// Proposer must sign over the attestations before pushing them to L1
|
|
720
|
-
const signer = this.proposer ?? this.publisher.getSenderAddress();
|
|
721
|
-
let attestationsSignature;
|
|
1116
|
+
// Validate the header against L1 state before broadcasting.
|
|
1117
|
+
// If this fails the slot is aborted before any gossip work; state drift between here
|
|
1118
|
+
// and the eventual L1 send is caught by the bundle simulate at send time.
|
|
722
1119
|
try {
|
|
723
|
-
|
|
1120
|
+
await this.publisher.validateBlockHeader(checkpoint.header, this.checkpointSimulationOverridesPlan);
|
|
724
1121
|
} catch (err) {
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
1122
|
+
this.log.error(`Pre-broadcast header validation failed for slot ${this.targetSlot}; aborting`, err, {
|
|
1123
|
+
slot: this.targetSlot,
|
|
1124
|
+
checkpointNumber: this.checkpointNumber
|
|
1125
|
+
});
|
|
1126
|
+
this.metrics.recordCheckpointProposalFailed('header_validation_failed');
|
|
1127
|
+
this.eventEmitter.emit('header-validation-failed', {
|
|
1128
|
+
slot: this.targetSlot,
|
|
1129
|
+
checkpointNumber: this.checkpointNumber,
|
|
1130
|
+
reason: err instanceof Error ? err.message : String(err)
|
|
1131
|
+
});
|
|
1132
|
+
return undefined;
|
|
1133
|
+
}
|
|
1134
|
+
// Create the checkpoint proposal and broadcast it
|
|
1135
|
+
const proposal = await this.validatorClient.createCheckpointProposal(checkpoint.header, checkpoint.archive.root, this.checkpointNumber, feeAssetPriceModifier, blockPendingBroadcast, this.proposer, checkpointProposalOptions);
|
|
1136
|
+
// Advance our own optimistic proposed-checkpoint tip locally before gossiping. Gossipsub
|
|
1137
|
+
// doesn't echo our own messages back, so this is how the proposer makes its own proposed
|
|
1138
|
+
// checkpoint visible for pipelining the next slot. Built from local checkpoint data — never
|
|
1139
|
+
// from the broadcast proposal archive, which may be deliberately corrupted under test flags.
|
|
1140
|
+
// Fail closed: if this throws, the outer catch aborts the slot before gossiping.
|
|
1141
|
+
await this.syncProposedCheckpointToArchiver(checkpoint, blocksInCheckpoint.length, feeAssetPriceModifier);
|
|
1142
|
+
const blockProposedAt = this.dateProvider.now();
|
|
1143
|
+
if (this.config.skipBroadcastCheckpointProposal) {
|
|
1144
|
+
// Test-only: suppress the CheckpointProposal so peers never see a proposed checkpoint for
|
|
1145
|
+
// this slot, but still broadcast the held last block standalone so peers' archivers ingest
|
|
1146
|
+
// it as a proposed-but-uncheckpointed tip — the exact orphan-block state that
|
|
1147
|
+
// pruneOrphanProposedBlocks / checkSync must handle.
|
|
1148
|
+
if (blockPendingBroadcast && !this.config.skipBroadcastProposals) {
|
|
1149
|
+
await this.p2pClient.broadcastProposal(blockPendingBroadcast);
|
|
741
1150
|
}
|
|
742
|
-
|
|
1151
|
+
} else if (!this.config.skipBroadcastProposals) {
|
|
1152
|
+
await this.p2pClient.broadcastCheckpointProposal(proposal);
|
|
1153
|
+
this.checkpointMetrics.noteCheckpointBroadcast(this.dateProvider.now());
|
|
743
1154
|
}
|
|
744
|
-
//
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
txTimeoutAt,
|
|
751
|
-
forcePendingCheckpointNumber: this.invalidateCheckpoint?.forcePendingCheckpointNumber
|
|
752
|
-
});
|
|
753
|
-
return checkpoint;
|
|
1155
|
+
// Return immediately after broadcast — attestation collection happens in the background
|
|
1156
|
+
return {
|
|
1157
|
+
checkpoint,
|
|
1158
|
+
proposal,
|
|
1159
|
+
blockProposedAt
|
|
1160
|
+
};
|
|
754
1161
|
} catch (e) {
|
|
755
1162
|
env.error = e;
|
|
756
1163
|
env.hasError = true;
|
|
757
1164
|
} finally{
|
|
758
|
-
_ts_dispose_resources(env);
|
|
1165
|
+
const result = _ts_dispose_resources(env);
|
|
1166
|
+
if (result) await result;
|
|
759
1167
|
}
|
|
760
1168
|
} catch (err) {
|
|
761
1169
|
if (err && (err instanceof DutyAlreadySignedError || err instanceof SlashingProtectionError)) {
|
|
762
1170
|
// swallow this error. It's already been logged by a function deeper in the stack
|
|
763
1171
|
return undefined;
|
|
764
1172
|
}
|
|
765
|
-
this.log.error(`Error building checkpoint at slot ${this.
|
|
1173
|
+
this.log.error(`Error building checkpoint at slot ${this.targetSlot}`, err);
|
|
766
1174
|
return undefined;
|
|
767
1175
|
}
|
|
768
1176
|
}
|
|
@@ -772,19 +1180,25 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
772
1180
|
const blocksInCheckpoint = [];
|
|
773
1181
|
const txHashesAlreadyIncluded = new Set();
|
|
774
1182
|
const initialBlockNumber = BlockNumber(this.syncedToBlockNumber + 1);
|
|
775
|
-
// Remaining blob fields available for blocks (checkpoint end marker already subtracted)
|
|
776
|
-
let remainingBlobFields = BLOBS_PER_CHECKPOINT * FIELDS_PER_BLOB - NUM_CHECKPOINT_END_MARKER_FIELDS;
|
|
777
1183
|
// Last block in the checkpoint will usually be flagged as pending broadcast, so we send it along with the checkpoint proposal
|
|
778
1184
|
let blockPendingBroadcast = undefined;
|
|
779
1185
|
while(true){
|
|
780
1186
|
const blocksBuilt = blocksInCheckpoint.length;
|
|
781
|
-
const indexWithinCheckpoint = blocksBuilt;
|
|
1187
|
+
const indexWithinCheckpoint = IndexWithinCheckpoint(blocksBuilt);
|
|
782
1188
|
const blockNumber = BlockNumber(initialBlockNumber + blocksBuilt);
|
|
1189
|
+
if (blocksBuilt >= this.config.maxBlocksPerCheckpoint) {
|
|
1190
|
+
this.log.debug(`Reached max blocks per checkpoint`, {
|
|
1191
|
+
slot: this.targetSlot,
|
|
1192
|
+
blocksBuilt,
|
|
1193
|
+
maxBlocksPerCheckpoint: this.config.maxBlocksPerCheckpoint
|
|
1194
|
+
});
|
|
1195
|
+
break;
|
|
1196
|
+
}
|
|
783
1197
|
const secondsIntoSlot = this.getSecondsIntoSlot();
|
|
784
1198
|
const timingInfo = this.timetable.canStartNextBlock(secondsIntoSlot);
|
|
785
1199
|
if (!timingInfo.canStart) {
|
|
786
1200
|
this.log.debug(`Not enough time left in slot to start another block`, {
|
|
787
|
-
slot: this.
|
|
1201
|
+
slot: this.targetSlot,
|
|
788
1202
|
blocksBuilt,
|
|
789
1203
|
secondsIntoSlot
|
|
790
1204
|
});
|
|
@@ -799,67 +1213,66 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
799
1213
|
buildDeadline: timingInfo.deadline ? new Date((this.getSlotStartBuildTimestamp() + timingInfo.deadline) * 1000) : undefined,
|
|
800
1214
|
blockNumber,
|
|
801
1215
|
indexWithinCheckpoint,
|
|
802
|
-
txHashesAlreadyIncluded
|
|
803
|
-
remainingBlobFields
|
|
1216
|
+
txHashesAlreadyIncluded
|
|
804
1217
|
});
|
|
805
|
-
if
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
1218
|
+
// If we failed to build the block due to insufficient txs, we try again if there is still time left in the slot
|
|
1219
|
+
if ('failure' in buildResult) {
|
|
1220
|
+
// If this was the last subslot, or we're running with a single block per slot, we're done
|
|
1221
|
+
if (timingInfo.isLastBlock || timingInfo.deadline === undefined) {
|
|
1222
|
+
break;
|
|
1223
|
+
}
|
|
1224
|
+
// Otherwise, if there is still time for more blocks, we wait until the next subslot and try again
|
|
809
1225
|
await this.waitUntilNextSubslot(timingInfo.deadline);
|
|
810
1226
|
continue;
|
|
811
|
-
}
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
1227
|
+
}
|
|
1228
|
+
// If there was an error building the block, we just exit the loop and give up the rest of the slot.
|
|
1229
|
+
// We don't want to risk building more blocks if something went wrong.
|
|
1230
|
+
if ('error' in buildResult) {
|
|
815
1231
|
if (!(buildResult.error instanceof SequencerInterruptedError)) {
|
|
816
|
-
this.log.warn(`Halting block building for slot ${this.
|
|
817
|
-
slot: this.
|
|
1232
|
+
this.log.warn(`Halting block building for slot ${this.targetSlot}`, {
|
|
1233
|
+
slot: this.targetSlot,
|
|
818
1234
|
blocksBuilt,
|
|
819
1235
|
error: buildResult.error
|
|
820
1236
|
});
|
|
821
1237
|
}
|
|
822
1238
|
break;
|
|
823
1239
|
}
|
|
824
|
-
const { block, usedTxs
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
// Sync the proposed block to the archiver to make it available
|
|
829
|
-
// Note that the checkpoint builder uses its own fork so it should not need to wait for this syncing
|
|
830
|
-
// Eventually we should refactor the checkpoint builder to not need a separate long-lived fork
|
|
831
|
-
// Fire and forget - don't block the critical path, but log errors
|
|
832
|
-
this.syncProposedBlockToArchiver(block).catch((err)=>{
|
|
833
|
-
this.log.error(`Failed to sync proposed block ${block.number} to archiver`, {
|
|
834
|
-
blockNumber: block.number,
|
|
835
|
-
err
|
|
836
|
-
});
|
|
1240
|
+
const { block, usedTxs } = buildResult;
|
|
1241
|
+
this.checkpointMetrics.noteCheckpointBlockBuilt(this.dateProvider.now(), {
|
|
1242
|
+
isFirstBlock: blocksBuilt === 0,
|
|
1243
|
+
isLastBlock: timingInfo.isLastBlock
|
|
837
1244
|
});
|
|
1245
|
+
blocksInCheckpoint.push(block);
|
|
838
1246
|
usedTxs.forEach((tx)=>txHashesAlreadyIncluded.add(tx.txHash.toString()));
|
|
839
|
-
//
|
|
1247
|
+
// Sign the block proposal. This will throw if HA signing fails.
|
|
1248
|
+
const proposal = await this.createBlockProposal(block, inHash, usedTxs, {
|
|
1249
|
+
...blockProposalOptions,
|
|
1250
|
+
broadcastInvalidBlockProposal: blockProposalOptions.broadcastInvalidBlockProposal || block.indexWithinCheckpoint === this.config.invalidBlockProposalIndexWithinCheckpoint
|
|
1251
|
+
});
|
|
1252
|
+
// Sync the proposed block to the archiver to make it available, only after we've managed to sign the proposal,
|
|
1253
|
+
// so we avoid polluting our archive with a block that would fail.
|
|
1254
|
+
// We wait for the sync to succeed, as this helps catch consistency errors, even if it means we lose some time for block-building.
|
|
1255
|
+
// If this throws, we abort the entire checkpoint.
|
|
1256
|
+
await this.syncProposedBlockToArchiver(block);
|
|
1257
|
+
// If this is the last block, do not broadcast it, since it will be included in the checkpoint proposal.
|
|
840
1258
|
if (timingInfo.isLastBlock) {
|
|
841
|
-
this.log.verbose(`Completed final block ${blockNumber} for slot ${this.
|
|
842
|
-
slot: this.
|
|
1259
|
+
this.log.verbose(`Completed final block ${blockNumber} for slot ${this.targetSlot}`, {
|
|
1260
|
+
slot: this.targetSlot,
|
|
843
1261
|
blockNumber,
|
|
844
1262
|
blocksBuilt
|
|
845
1263
|
});
|
|
846
|
-
blockPendingBroadcast =
|
|
847
|
-
block,
|
|
848
|
-
txs: usedTxs
|
|
849
|
-
};
|
|
1264
|
+
blockPendingBroadcast = proposal;
|
|
850
1265
|
break;
|
|
851
1266
|
}
|
|
852
|
-
//
|
|
853
|
-
|
|
854
|
-
if (!this.config.fishermanMode) {
|
|
855
|
-
const proposal = await this.validatorClient.createBlockProposal(block.header, block.indexWithinCheckpoint, inHash, block.archive.root, usedTxs, this.proposer, blockProposalOptions);
|
|
1267
|
+
// Once we have a signed proposal and the archiver agreed with our proposed block, then we broadcast it.
|
|
1268
|
+
if (proposal && !this.config.skipBroadcastProposals) {
|
|
856
1269
|
await this.p2pClient.broadcastProposal(proposal);
|
|
857
1270
|
}
|
|
858
1271
|
// Wait until the next block's start time
|
|
859
1272
|
await this.waitUntilNextSubslot(timingInfo.deadline);
|
|
860
1273
|
}
|
|
861
|
-
this.log.verbose(`Block building loop completed for slot ${this.
|
|
862
|
-
slot: this.
|
|
1274
|
+
this.log.verbose(`Block building loop completed for slot ${this.targetSlot}`, {
|
|
1275
|
+
slot: this.targetSlot,
|
|
863
1276
|
blocksBuilt: blocksInCheckpoint.length
|
|
864
1277
|
});
|
|
865
1278
|
return {
|
|
@@ -867,115 +1280,162 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
867
1280
|
blockPendingBroadcast
|
|
868
1281
|
};
|
|
869
1282
|
}
|
|
1283
|
+
/** Creates a block proposal for a given block via the validator client (unless in fisherman mode) */ createBlockProposal(block, inHash, usedTxs, blockProposalOptions) {
|
|
1284
|
+
if (this.config.fishermanMode) {
|
|
1285
|
+
this.log.info(`Skipping block proposal for block ${block.number} in fisherman mode`);
|
|
1286
|
+
return Promise.resolve(undefined);
|
|
1287
|
+
}
|
|
1288
|
+
return this.validatorClient.createBlockProposal(block.header, this.checkpointNumber, block.indexWithinCheckpoint, inHash, block.archive.root, usedTxs, this.proposer, blockProposalOptions);
|
|
1289
|
+
}
|
|
870
1290
|
/** Sleeps until it is time to produce the next block in the slot */ async waitUntilNextSubslot(nextSubslotStart) {
|
|
871
|
-
this.setStateFn(SequencerState.WAITING_UNTIL_NEXT_BLOCK, this.
|
|
1291
|
+
this.setStateFn(SequencerState.WAITING_UNTIL_NEXT_BLOCK, this.targetSlot, this.slotNow);
|
|
872
1292
|
this.log.verbose(`Waiting until time for the next block at ${nextSubslotStart}s into slot`, {
|
|
873
|
-
slot: this.
|
|
1293
|
+
slot: this.targetSlot
|
|
874
1294
|
});
|
|
875
1295
|
await this.waitUntilTimeInSlot(nextSubslotStart);
|
|
876
1296
|
}
|
|
877
1297
|
/** Builds a single block. Called from the main block building loop. */ async buildSingleBlock(checkpointBuilder, opts) {
|
|
878
|
-
const { blockTimestamp, forceCreate, blockNumber, indexWithinCheckpoint, buildDeadline, txHashesAlreadyIncluded
|
|
879
|
-
this.log.verbose(`Preparing block ${blockNumber} index ${indexWithinCheckpoint} at checkpoint ${this.checkpointNumber} for slot ${this.
|
|
1298
|
+
const { blockTimestamp, forceCreate, blockNumber, indexWithinCheckpoint, buildDeadline, txHashesAlreadyIncluded } = opts;
|
|
1299
|
+
this.log.verbose(`Preparing block ${blockNumber} index ${indexWithinCheckpoint} at checkpoint ${this.checkpointNumber} for slot ${this.targetSlot}`, {
|
|
880
1300
|
...checkpointBuilder.getConstantData(),
|
|
881
1301
|
...opts
|
|
882
1302
|
});
|
|
883
1303
|
try {
|
|
884
1304
|
// Wait until we have enough txs to build the block
|
|
885
|
-
const minTxs = this.
|
|
886
|
-
const { availableTxs, canStartBuilding } = await this.waitForMinTxs(opts);
|
|
1305
|
+
const { availableTxs, canStartBuilding, minTxs } = await this.waitForMinTxs(opts);
|
|
887
1306
|
if (!canStartBuilding) {
|
|
888
|
-
this.
|
|
1307
|
+
this.logCheckpointEvent('block-build-failed', `Block build failed for slot ${this.targetSlot}`, {
|
|
1308
|
+
reason: 'insufficient_txs',
|
|
889
1309
|
blockNumber,
|
|
890
|
-
slot: this.
|
|
891
|
-
|
|
1310
|
+
slot: this.targetSlot,
|
|
1311
|
+
checkpointNumber: this.checkpointNumber,
|
|
1312
|
+
indexWithinCheckpoint,
|
|
1313
|
+
availableTxs,
|
|
1314
|
+
minTxs
|
|
1315
|
+
});
|
|
1316
|
+
this.log.warn(`Not enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.targetSlot} (got ${availableTxs} txs but needs ${minTxs})`, {
|
|
1317
|
+
reason: 'insufficient_txs',
|
|
1318
|
+
blockNumber,
|
|
1319
|
+
slot: this.targetSlot,
|
|
1320
|
+
checkpointNumber: this.checkpointNumber,
|
|
1321
|
+
indexWithinCheckpoint,
|
|
1322
|
+
availableTxs,
|
|
1323
|
+
minTxs
|
|
892
1324
|
});
|
|
893
1325
|
this.eventEmitter.emit('block-tx-count-check-failed', {
|
|
894
1326
|
minTxs,
|
|
895
1327
|
availableTxs,
|
|
896
|
-
slot: this.
|
|
1328
|
+
slot: this.targetSlot
|
|
897
1329
|
});
|
|
898
1330
|
this.metrics.recordBlockProposalFailed('insufficient_txs');
|
|
899
|
-
return
|
|
1331
|
+
return {
|
|
1332
|
+
failure: 'insufficient-txs'
|
|
1333
|
+
};
|
|
900
1334
|
}
|
|
901
1335
|
// Create iterator to pending txs. We filter out txs already included in previous blocks in the checkpoint
|
|
902
1336
|
// just in case p2p failed to sync the provisional block and didn't get to remove those txs from the mempool yet.
|
|
903
|
-
const pendingTxs = filter(this.p2pClient.
|
|
904
|
-
this.log.debug(`Building block ${blockNumber} at index ${indexWithinCheckpoint} for slot ${this.
|
|
905
|
-
slot: this.
|
|
1337
|
+
const pendingTxs = filter(this.p2pClient.iterateEligiblePendingTxs(), (tx)=>!txHashesAlreadyIncluded.has(tx.txHash.toString()));
|
|
1338
|
+
this.log.debug(`Building block ${blockNumber} at index ${indexWithinCheckpoint} for slot ${this.targetSlot} with ${availableTxs} available txs`, {
|
|
1339
|
+
slot: this.targetSlot,
|
|
906
1340
|
blockNumber,
|
|
907
1341
|
indexWithinCheckpoint
|
|
908
1342
|
});
|
|
909
|
-
this.setStateFn(SequencerState.CREATING_BLOCK, this.
|
|
910
|
-
//
|
|
911
|
-
|
|
912
|
-
|
|
1343
|
+
this.setStateFn(SequencerState.CREATING_BLOCK, this.targetSlot, this.slotNow);
|
|
1344
|
+
// Per-block limits are operator overrides (from SEQ_MAX_L2_BLOCK_GAS etc.) further capped
|
|
1345
|
+
// by remaining checkpoint-level budgets inside CheckpointBuilder before each block is built.
|
|
1346
|
+
// minValidTxs is passed into the builder so it can reject the block *before* updating state.
|
|
1347
|
+
const minValidTxs = forceCreate ? 0 : this.config.minValidTxsPerBlock ?? minTxs;
|
|
913
1348
|
const blockBuilderOptions = {
|
|
914
1349
|
maxTransactions: this.config.maxTxsPerBlock,
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
1350
|
+
maxBlockGas: this.config.maxL2BlockGas !== undefined || this.config.maxDABlockGas !== undefined ? new Gas(this.config.maxDABlockGas ?? Infinity, this.config.maxL2BlockGas ?? Infinity) : undefined,
|
|
1351
|
+
deadline: buildDeadline,
|
|
1352
|
+
isBuildingProposal: true,
|
|
1353
|
+
minValidTxs,
|
|
1354
|
+
maxBlocksPerCheckpoint: this.timetable.maxNumberOfBlocks,
|
|
1355
|
+
perBlockAllocationMultiplier: this.config.perBlockAllocationMultiplier
|
|
919
1356
|
};
|
|
920
|
-
// Actually build the block by executing txs
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
const
|
|
1357
|
+
// Actually build the block by executing txs. The builder throws InsufficientValidTxsError
|
|
1358
|
+
// if the number of successfully processed txs is below minValidTxs, ensuring state is not
|
|
1359
|
+
// updated for blocks that will be discarded.
|
|
1360
|
+
const buildResult = await this.buildSingleBlockWithCheckpointBuilder(checkpointBuilder, pendingTxs, blockNumber, blockTimestamp, blockBuilderOptions);
|
|
924
1361
|
// If any txs failed during execution, drop them from the mempool so we don't pick them up again
|
|
925
|
-
await this.dropFailedTxsFromP2P(failedTxs);
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
slot: this.slot,
|
|
1362
|
+
await this.dropFailedTxsFromP2P(buildResult.failedTxs);
|
|
1363
|
+
if (buildResult.status === 'insufficient-valid-txs') {
|
|
1364
|
+
this.logCheckpointEvent('block-build-failed', `Block build failed for slot ${this.targetSlot}`, {
|
|
1365
|
+
reason: 'insufficient_valid_txs',
|
|
1366
|
+
slot: this.targetSlot,
|
|
1367
|
+
checkpointNumber: this.checkpointNumber,
|
|
932
1368
|
blockNumber,
|
|
933
|
-
numTxs,
|
|
934
|
-
indexWithinCheckpoint
|
|
1369
|
+
numTxs: buildResult.processedCount,
|
|
1370
|
+
indexWithinCheckpoint,
|
|
1371
|
+
minValidTxs
|
|
935
1372
|
});
|
|
936
|
-
this.
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
1373
|
+
this.log.warn(`Block ${blockNumber} at index ${indexWithinCheckpoint} on slot ${this.targetSlot} has too few valid txs to be proposed`, {
|
|
1374
|
+
reason: 'insufficient_valid_txs',
|
|
1375
|
+
slot: this.targetSlot,
|
|
1376
|
+
checkpointNumber: this.checkpointNumber,
|
|
1377
|
+
blockNumber,
|
|
1378
|
+
numTxs: buildResult.processedCount,
|
|
1379
|
+
indexWithinCheckpoint,
|
|
1380
|
+
minValidTxs
|
|
1381
|
+
});
|
|
1382
|
+
this.eventEmitter.emit('block-build-failed', {
|
|
1383
|
+
reason: `Insufficient valid txs`,
|
|
1384
|
+
slot: this.targetSlot
|
|
940
1385
|
});
|
|
941
1386
|
this.metrics.recordBlockProposalFailed('insufficient_valid_txs');
|
|
942
|
-
return
|
|
1387
|
+
return {
|
|
1388
|
+
failure: 'insufficient-valid-txs'
|
|
1389
|
+
};
|
|
943
1390
|
}
|
|
944
1391
|
// Block creation succeeded, emit stats and metrics
|
|
1392
|
+
const { block, publicProcessorDuration, usedTxs, blockBuildDuration, numTxs } = buildResult;
|
|
945
1393
|
const blockStats = {
|
|
946
1394
|
eventName: 'l2-block-built',
|
|
947
1395
|
duration: blockBuildDuration,
|
|
948
1396
|
publicProcessDuration: publicProcessorDuration,
|
|
949
|
-
rollupCircuitsDuration: blockBuildingTimer.ms(),
|
|
950
1397
|
...block.getStats()
|
|
951
1398
|
};
|
|
952
1399
|
const blockHash = await block.hash();
|
|
953
1400
|
const txHashes = block.body.txEffects.map((tx)=>tx.txHash);
|
|
954
|
-
const manaPerSec =
|
|
955
|
-
this.log.info(`Built block ${block.number} at checkpoint ${this.checkpointNumber} for slot ${this.
|
|
1401
|
+
const manaPerSec = block.header.totalManaUsed.toNumberUnsafe() / (blockBuildDuration / 1000);
|
|
1402
|
+
this.log.info(`Built block ${block.number} at checkpoint ${this.checkpointNumber} for slot ${this.targetSlot} with ${numTxs} txs`, {
|
|
956
1403
|
blockHash,
|
|
957
1404
|
txHashes,
|
|
958
1405
|
manaPerSec,
|
|
959
1406
|
...blockStats
|
|
960
1407
|
});
|
|
1408
|
+
// `slot` is the target/submission slot (may be one ahead when pipelining),
|
|
1409
|
+
// `buildSlot` is the wall-clock slot during which the block was actually built.
|
|
961
1410
|
this.eventEmitter.emit('block-proposed', {
|
|
962
1411
|
blockNumber: block.number,
|
|
963
|
-
|
|
1412
|
+
blockHash,
|
|
1413
|
+
checkpointNumber: this.checkpointNumber,
|
|
1414
|
+
indexWithinCheckpoint: block.indexWithinCheckpoint,
|
|
1415
|
+
slot: this.targetSlot,
|
|
1416
|
+
buildSlot: this.slotNow
|
|
964
1417
|
});
|
|
965
|
-
this.metrics.recordBuiltBlock(blockBuildDuration,
|
|
1418
|
+
this.metrics.recordBuiltBlock(blockBuildDuration, block.header.totalManaUsed.toNumberUnsafe(), this.targetSlot);
|
|
966
1419
|
return {
|
|
967
1420
|
block,
|
|
968
|
-
usedTxs
|
|
969
|
-
remainingBlobFields: maxBlobFieldsForTxs - usedTxBlobFields
|
|
1421
|
+
usedTxs
|
|
970
1422
|
};
|
|
971
1423
|
} catch (err) {
|
|
972
1424
|
this.eventEmitter.emit('block-build-failed', {
|
|
973
1425
|
reason: err.message,
|
|
974
|
-
slot: this.
|
|
1426
|
+
slot: this.targetSlot
|
|
1427
|
+
});
|
|
1428
|
+
this.logCheckpointEvent('block-build-failed', `Block build failed for slot ${this.targetSlot}`, {
|
|
1429
|
+
reason: err instanceof Error ? err.message : String(err),
|
|
1430
|
+
slot: this.targetSlot,
|
|
1431
|
+
checkpointNumber: this.checkpointNumber,
|
|
1432
|
+
blockNumber
|
|
975
1433
|
});
|
|
976
1434
|
this.log.error(`Error building block`, err, {
|
|
977
|
-
|
|
978
|
-
slot: this.
|
|
1435
|
+
reason: err instanceof Error ? err.message : String(err),
|
|
1436
|
+
slot: this.targetSlot,
|
|
1437
|
+
checkpointNumber: this.checkpointNumber,
|
|
1438
|
+
blockNumber
|
|
979
1439
|
});
|
|
980
1440
|
this.metrics.recordBlockProposalFailed(err.name || 'unknown_error');
|
|
981
1441
|
this.metrics.recordFailedBlock();
|
|
@@ -984,9 +1444,31 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
984
1444
|
};
|
|
985
1445
|
}
|
|
986
1446
|
}
|
|
1447
|
+
/** Uses the checkpoint builder to build a block, catching InsufficientValidTxsError. */ async buildSingleBlockWithCheckpointBuilder(checkpointBuilder, pendingTxs, blockNumber, blockTimestamp, blockBuilderOptions) {
|
|
1448
|
+
try {
|
|
1449
|
+
const workTimer = new Timer();
|
|
1450
|
+
const result = await checkpointBuilder.buildBlock(pendingTxs, blockNumber, blockTimestamp, blockBuilderOptions);
|
|
1451
|
+
const blockBuildDuration = workTimer.ms();
|
|
1452
|
+
return {
|
|
1453
|
+
...result,
|
|
1454
|
+
blockBuildDuration,
|
|
1455
|
+
status: 'success'
|
|
1456
|
+
};
|
|
1457
|
+
} catch (err) {
|
|
1458
|
+
if (isErrorClass(err, InsufficientValidTxsError)) {
|
|
1459
|
+
return {
|
|
1460
|
+
failedTxs: err.failedTxs,
|
|
1461
|
+
processedCount: err.processedCount,
|
|
1462
|
+
status: 'insufficient-valid-txs'
|
|
1463
|
+
};
|
|
1464
|
+
}
|
|
1465
|
+
throw err;
|
|
1466
|
+
}
|
|
1467
|
+
}
|
|
987
1468
|
/** Waits until minTxs are available on the pool for building a block. */ async waitForMinTxs(opts) {
|
|
988
|
-
const minTxs = this.config.minTxsPerBlock;
|
|
989
1469
|
const { indexWithinCheckpoint, blockNumber, buildDeadline, forceCreate } = opts;
|
|
1470
|
+
// We only allow a block with 0 txs in the first block of the checkpoint
|
|
1471
|
+
const minTxs = indexWithinCheckpoint > 0 && this.config.minTxsPerBlock === 0 ? 1 : this.config.minTxsPerBlock;
|
|
990
1472
|
// Deadline is undefined if we are not enforcing the timetable, meaning we'll exit immediately when out of time
|
|
991
1473
|
const startBuildingDeadline = buildDeadline ? new Date(buildDeadline.getTime() - this.timetable.minExecutionTime * 1000) : undefined;
|
|
992
1474
|
let availableTxs = await this.p2pClient.getPendingTxCount();
|
|
@@ -996,31 +1478,57 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
996
1478
|
if (startBuildingDeadline === undefined || now >= startBuildingDeadline) {
|
|
997
1479
|
return {
|
|
998
1480
|
canStartBuilding: false,
|
|
999
|
-
availableTxs
|
|
1481
|
+
availableTxs,
|
|
1482
|
+
minTxs
|
|
1000
1483
|
};
|
|
1001
1484
|
}
|
|
1002
1485
|
// Wait a bit before checking again
|
|
1003
|
-
this.setStateFn(SequencerState.WAITING_FOR_TXS, this.
|
|
1004
|
-
this.log.verbose(`Waiting for enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.
|
|
1486
|
+
this.setStateFn(SequencerState.WAITING_FOR_TXS, this.targetSlot, this.slotNow);
|
|
1487
|
+
this.log.verbose(`Waiting for enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.targetSlot} (have ${availableTxs} but need ${minTxs})`, {
|
|
1005
1488
|
blockNumber,
|
|
1006
|
-
slot: this.
|
|
1489
|
+
slot: this.targetSlot,
|
|
1007
1490
|
indexWithinCheckpoint
|
|
1008
1491
|
});
|
|
1009
|
-
await
|
|
1492
|
+
await this.waitForTxsPollingInterval();
|
|
1010
1493
|
availableTxs = await this.p2pClient.getPendingTxCount();
|
|
1011
1494
|
}
|
|
1012
1495
|
return {
|
|
1013
1496
|
canStartBuilding: true,
|
|
1014
|
-
availableTxs
|
|
1497
|
+
availableTxs,
|
|
1498
|
+
minTxs
|
|
1015
1499
|
};
|
|
1016
1500
|
}
|
|
1501
|
+
async getSignedCommitteeAttestations(broadcast) {
|
|
1502
|
+
const { proposal, blockProposedAt } = broadcast;
|
|
1503
|
+
this.setStateFn(SequencerState.COLLECTING_ATTESTATIONS, this.targetSlot, this.slotNow);
|
|
1504
|
+
const attestations = await this.waitForAttestations(proposal);
|
|
1505
|
+
if (!attestations) {
|
|
1506
|
+
return undefined;
|
|
1507
|
+
}
|
|
1508
|
+
this.checkpointMetrics.recordCheckpointAttestationDelay(this.dateProvider.now() - blockProposedAt);
|
|
1509
|
+
// Proposer must sign over the attestations before pushing them to L1
|
|
1510
|
+
const signer = this.proposer ?? this.publisher.getSenderAddress();
|
|
1511
|
+
try {
|
|
1512
|
+
const attestationsSignature = await this.validatorClient.signAttestationsAndSigners(attestations, signer, this.targetSlot, this.checkpointNumber);
|
|
1513
|
+
return {
|
|
1514
|
+
attestations,
|
|
1515
|
+
attestationsSignature
|
|
1516
|
+
};
|
|
1517
|
+
} catch (err) {
|
|
1518
|
+
if (this.handleHASigningError(err, 'Attestations signature')) {
|
|
1519
|
+
return;
|
|
1520
|
+
}
|
|
1521
|
+
this.log.error(`Error signing attestations for checkpoint proposal at slot ${proposal.slotNumber}`, err);
|
|
1522
|
+
return undefined;
|
|
1523
|
+
}
|
|
1524
|
+
}
|
|
1017
1525
|
/**
|
|
1018
1526
|
* Waits for enough attestations to be collected via p2p.
|
|
1019
1527
|
* This is run after all blocks for the checkpoint have been built.
|
|
1020
1528
|
*/ async waitForAttestations(proposal) {
|
|
1021
1529
|
if (this.config.fishermanMode) {
|
|
1022
1530
|
this.log.debug('Skipping attestation collection in fisherman mode');
|
|
1023
|
-
return CommitteeAttestationsAndSigners.empty();
|
|
1531
|
+
return CommitteeAttestationsAndSigners.empty(this.getSignatureContext());
|
|
1024
1532
|
}
|
|
1025
1533
|
const slotNumber = proposal.slotNumber;
|
|
1026
1534
|
const { committee, seed, epoch } = await this.epochCache.getCommittee(slotNumber);
|
|
@@ -1028,47 +1536,91 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
1028
1536
|
throw new Error('No committee when collecting attestations');
|
|
1029
1537
|
} else if (committee.length === 0) {
|
|
1030
1538
|
this.log.verbose(`Attesting committee is empty`);
|
|
1031
|
-
return CommitteeAttestationsAndSigners.empty();
|
|
1539
|
+
return CommitteeAttestationsAndSigners.empty(this.getSignatureContext());
|
|
1032
1540
|
} else {
|
|
1033
1541
|
this.log.debug(`Attesting committee length is ${committee.length}`, {
|
|
1034
1542
|
committee
|
|
1035
1543
|
});
|
|
1036
1544
|
}
|
|
1037
|
-
const numberOfRequiredAttestations =
|
|
1545
|
+
const numberOfRequiredAttestations = computeQuorum(committee.length);
|
|
1038
1546
|
if (this.config.skipCollectingAttestations) {
|
|
1039
1547
|
this.log.warn('Skipping attestation collection as per config (attesting with own keys only)');
|
|
1040
|
-
const attestations = await this.validatorClient?.collectOwnAttestations(proposal);
|
|
1041
|
-
|
|
1548
|
+
const attestations = await this.validatorClient?.collectOwnAttestations(proposal, this.checkpointNumber);
|
|
1549
|
+
this.logCheckpointAttestations('collected', committee, attestations ?? [], numberOfRequiredAttestations, {
|
|
1550
|
+
reason: 'collect_own_only'
|
|
1551
|
+
});
|
|
1552
|
+
return new CommitteeAttestationsAndSigners(orderAttestations(attestations ?? [], committee), this.getSignatureContext());
|
|
1042
1553
|
}
|
|
1043
|
-
const attestationTimeAllowed = this.config.enforceTimeTable ? this.timetable.
|
|
1044
|
-
const attestationDeadline = new Date(this.
|
|
1554
|
+
const attestationTimeAllowed = this.config.enforceTimeTable ? this.timetable.getCheckpointAttestationDeadline() : this.l1Constants.slotDuration;
|
|
1555
|
+
const attestationDeadline = new Date((this.getSlotStartBuildTimestamp() + attestationTimeAllowed) * 1000);
|
|
1045
1556
|
this.metrics.recordRequiredAttestations(numberOfRequiredAttestations, attestationTimeAllowed);
|
|
1046
1557
|
const collectAttestationsTimer = new Timer();
|
|
1047
1558
|
let collectedAttestationsCount = 0;
|
|
1048
1559
|
try {
|
|
1049
|
-
const attestations = await this.validatorClient.collectAttestations(proposal, numberOfRequiredAttestations, attestationDeadline);
|
|
1560
|
+
const attestations = await this.validatorClient.collectAttestations(proposal, numberOfRequiredAttestations, attestationDeadline, this.checkpointNumber);
|
|
1050
1561
|
collectedAttestationsCount = attestations.length;
|
|
1562
|
+
// Trim attestations to minimum required to save L1 calldata gas
|
|
1563
|
+
const localAddresses = this.validatorClient.getValidatorAddresses();
|
|
1564
|
+
const trimmed = trimAttestations(attestations, numberOfRequiredAttestations, this.attestorAddress, localAddresses);
|
|
1565
|
+
if (trimmed.length < attestations.length) {
|
|
1566
|
+
this.log.debug(`Trimmed attestations from ${attestations.length} to ${trimmed.length} for L1 submission`);
|
|
1567
|
+
}
|
|
1051
1568
|
// Rollup contract requires that the signatures are provided in the order of the committee
|
|
1052
|
-
const sorted = orderAttestations(
|
|
1569
|
+
const sorted = orderAttestations(trimmed, committee);
|
|
1570
|
+
this.logCheckpointAttestations('collected', committee, attestations, numberOfRequiredAttestations, {
|
|
1571
|
+
submittedCount: trimmed.length
|
|
1572
|
+
});
|
|
1053
1573
|
// Manipulate the attestations if we've been configured to do so
|
|
1054
|
-
if (this.config.injectFakeAttestation || this.config.shuffleAttestationOrdering) {
|
|
1574
|
+
if (this.config.injectFakeAttestation || this.config.injectHighSValueAttestation || this.config.injectUnrecoverableSignatureAttestation || this.config.shuffleAttestationOrdering) {
|
|
1055
1575
|
return this.manipulateAttestations(proposal.slotNumber, epoch, seed, committee, sorted);
|
|
1056
1576
|
}
|
|
1057
|
-
return new CommitteeAttestationsAndSigners(sorted);
|
|
1577
|
+
return new CommitteeAttestationsAndSigners(sorted, this.getSignatureContext());
|
|
1058
1578
|
} catch (err) {
|
|
1059
1579
|
if (err && err instanceof AttestationTimeoutError) {
|
|
1060
1580
|
collectedAttestationsCount = err.collectedCount;
|
|
1581
|
+
this.logCheckpointAttestations('failed', committee, undefined, numberOfRequiredAttestations, {
|
|
1582
|
+
collectedCount: collectedAttestationsCount,
|
|
1583
|
+
reason: 'timeout'
|
|
1584
|
+
});
|
|
1585
|
+
this.log.error(`Timeout while waiting for attestations for checkpoint proposal at slot ${proposal.slotNumber} (collected ${collectedAttestationsCount}/${numberOfRequiredAttestations})`, err);
|
|
1586
|
+
} else {
|
|
1587
|
+
this.logCheckpointAttestations('failed', committee, undefined, numberOfRequiredAttestations, {
|
|
1588
|
+
collectedCount: collectedAttestationsCount,
|
|
1589
|
+
reason: err instanceof Error ? err.message : String(err)
|
|
1590
|
+
});
|
|
1591
|
+
this.log.error(`Error collecting attestations for checkpoint proposal at slot ${proposal.slotNumber}`, err);
|
|
1061
1592
|
}
|
|
1062
|
-
|
|
1593
|
+
return undefined;
|
|
1063
1594
|
} finally{
|
|
1064
1595
|
this.metrics.recordCollectedAttestations(collectedAttestationsCount, collectAttestationsTimer.ms());
|
|
1065
1596
|
}
|
|
1066
1597
|
}
|
|
1598
|
+
logCheckpointAttestations(status, committee, attestations, requiredAttestations, opts = {}) {
|
|
1599
|
+
const signedValidators = attestations?.map((attestation)=>attestation.getSender()?.toString()).filter((address)=>address !== undefined) ?? [];
|
|
1600
|
+
const collectedCount = opts.collectedCount ?? new Set(signedValidators).size;
|
|
1601
|
+
const missingValidatorCount = status === 'failed' ? Math.max(0, requiredAttestations - collectedCount) : undefined;
|
|
1602
|
+
this.logCheckpointEvent(`attestations-${status}`, `Checkpoint attestations ${status} for slot ${this.targetSlot}`, {
|
|
1603
|
+
slot: this.targetSlot,
|
|
1604
|
+
checkpointNumber: this.checkpointNumber,
|
|
1605
|
+
committeeSize: committee.length,
|
|
1606
|
+
requiredAttestations,
|
|
1607
|
+
collectedAttestations: collectedCount,
|
|
1608
|
+
...opts.submittedCount !== undefined && {
|
|
1609
|
+
submittedAttestations: opts.submittedCount
|
|
1610
|
+
},
|
|
1611
|
+
...missingValidatorCount !== undefined && {
|
|
1612
|
+
missingValidatorCount
|
|
1613
|
+
},
|
|
1614
|
+
...opts.reason !== undefined && {
|
|
1615
|
+
reason: opts.reason
|
|
1616
|
+
}
|
|
1617
|
+
});
|
|
1618
|
+
}
|
|
1067
1619
|
/** Breaks the attestations before publishing based on attack configs */ manipulateAttestations(slotNumber, epoch, seed, committee, attestations) {
|
|
1068
1620
|
// Compute the proposer index in the committee, since we dont want to tweak it.
|
|
1069
1621
|
// Otherwise, the L1 rollup contract will reject the block outright.
|
|
1070
1622
|
const proposerIndex = Number(this.epochCache.computeProposerIndex(slotNumber, epoch, seed, BigInt(committee.length)));
|
|
1071
|
-
if (this.config.injectFakeAttestation) {
|
|
1623
|
+
if (this.config.injectFakeAttestation || this.config.injectHighSValueAttestation || this.config.injectUnrecoverableSignatureAttestation) {
|
|
1072
1624
|
// Find non-empty attestations that are not from the proposer
|
|
1073
1625
|
const nonProposerIndices = [];
|
|
1074
1626
|
for(let i = 0; i < attestations.length; i++){
|
|
@@ -1078,28 +1630,47 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
1078
1630
|
}
|
|
1079
1631
|
if (nonProposerIndices.length > 0) {
|
|
1080
1632
|
const targetIndex = nonProposerIndices[randomInt(nonProposerIndices.length)];
|
|
1081
|
-
this.
|
|
1082
|
-
|
|
1633
|
+
if (this.config.injectHighSValueAttestation) {
|
|
1634
|
+
this.log.warn(`Injecting high-s value attestation in checkpoint for slot ${slotNumber} at index ${targetIndex}`);
|
|
1635
|
+
unfreeze(attestations[targetIndex]).signature = flipSignature(attestations[targetIndex].signature);
|
|
1636
|
+
} else if (this.config.injectUnrecoverableSignatureAttestation) {
|
|
1637
|
+
this.log.warn(`Injecting unrecoverable signature attestation in checkpoint for slot ${slotNumber} at index ${targetIndex}`);
|
|
1638
|
+
unfreeze(attestations[targetIndex]).signature = generateUnrecoverableSignature();
|
|
1639
|
+
} else {
|
|
1640
|
+
this.log.warn(`Injecting fake attestation in checkpoint for slot ${slotNumber} at index ${targetIndex}`);
|
|
1641
|
+
unfreeze(attestations[targetIndex]).signature = generateRecoverableSignature();
|
|
1642
|
+
}
|
|
1083
1643
|
}
|
|
1084
|
-
return new CommitteeAttestationsAndSigners(attestations);
|
|
1644
|
+
return new CommitteeAttestationsAndSigners(attestations, this.getSignatureContext());
|
|
1085
1645
|
}
|
|
1086
1646
|
if (this.config.shuffleAttestationOrdering) {
|
|
1087
1647
|
this.log.warn(`Shuffling attestation ordering in checkpoint for slot ${slotNumber} (proposer #${proposerIndex})`);
|
|
1088
1648
|
const shuffled = [
|
|
1089
1649
|
...attestations
|
|
1090
1650
|
];
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
];
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1651
|
+
// Find two non-proposer positions that both have non-empty signatures to swap.
|
|
1652
|
+
// This ensures the bitmap doesn't change, so the MaliciousCommitteeAttestationsAndSigners
|
|
1653
|
+
// signers array stays correctly aligned with L1's committee reconstruction.
|
|
1654
|
+
const swappable = [];
|
|
1655
|
+
for(let k = 0; k < shuffled.length; k++){
|
|
1656
|
+
if (!shuffled[k].signature.isEmpty() && k !== proposerIndex) {
|
|
1657
|
+
swappable.push(k);
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1660
|
+
if (swappable.length >= 2) {
|
|
1661
|
+
const [i, j] = [
|
|
1662
|
+
swappable[0],
|
|
1663
|
+
swappable[1]
|
|
1664
|
+
];
|
|
1665
|
+
[shuffled[i], shuffled[j]] = [
|
|
1666
|
+
shuffled[j],
|
|
1667
|
+
shuffled[i]
|
|
1668
|
+
];
|
|
1669
|
+
}
|
|
1670
|
+
const signers = new CommitteeAttestationsAndSigners(attestations, this.getSignatureContext()).getSigners();
|
|
1671
|
+
return new MaliciousCommitteeAttestationsAndSigners(shuffled, signers, this.getSignatureContext());
|
|
1101
1672
|
}
|
|
1102
|
-
return new CommitteeAttestationsAndSigners(attestations);
|
|
1673
|
+
return new CommitteeAttestationsAndSigners(attestations, this.getSignatureContext());
|
|
1103
1674
|
}
|
|
1104
1675
|
async dropFailedTxsFromP2P(failedTxs) {
|
|
1105
1676
|
if (failedTxs.length === 0) {
|
|
@@ -1108,14 +1679,18 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
1108
1679
|
const failedTxData = failedTxs.map((fail)=>fail.tx);
|
|
1109
1680
|
const failedTxHashes = failedTxData.map((tx)=>tx.getTxHash());
|
|
1110
1681
|
this.log.verbose(`Dropping failed txs ${failedTxHashes.join(', ')}`);
|
|
1111
|
-
await this.p2pClient.
|
|
1682
|
+
await this.p2pClient.handleFailedExecution(failedTxHashes);
|
|
1112
1683
|
}
|
|
1113
1684
|
/**
|
|
1114
1685
|
* Adds the proposed block to the archiver so it's available via P2P.
|
|
1115
1686
|
* Gossip doesn't echo messages back to the sender, so the proposer's archiver/world-state
|
|
1116
1687
|
* would never receive its own block without this explicit sync.
|
|
1688
|
+
*
|
|
1689
|
+
* In fisherman mode we skip this push: the fisherman builds blocks locally for validation
|
|
1690
|
+
* and fee analysis only, and pushing them to the archiver causes spurious reorg cascades
|
|
1691
|
+
* whenever the real proposer's block arrives from L1.
|
|
1117
1692
|
*/ async syncProposedBlockToArchiver(block) {
|
|
1118
|
-
if (this.config.skipPushProposedBlocksToArchiver
|
|
1693
|
+
if (this.config.skipPushProposedBlocksToArchiver || this.config.fishermanMode) {
|
|
1119
1694
|
this.log.warn(`Skipping push of proposed block ${block.number} to archiver`, {
|
|
1120
1695
|
blockNumber: block.number,
|
|
1121
1696
|
slot: block.header.globalVariables.slotNumber
|
|
@@ -1128,32 +1703,85 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
1128
1703
|
});
|
|
1129
1704
|
await this.blockSink.addBlock(block);
|
|
1130
1705
|
}
|
|
1706
|
+
/**
|
|
1707
|
+
* Adds the proposed checkpoint to the archiver so the proposer's optimistic proposed-checkpoint
|
|
1708
|
+
* tip advances locally. Gossip doesn't echo our own messages back, so without this the proposer
|
|
1709
|
+
* would never see its own proposed checkpoint and couldn't pipeline the next slot.
|
|
1710
|
+
*
|
|
1711
|
+
* Skipped whenever proposed blocks aren't pushed (`skipPushProposedBlocksToArchiver`, fisherman
|
|
1712
|
+
* mode): the archiver derives the checkpoint archive from its stored blocks, so without them the
|
|
1713
|
+
* push would fail. All blocks were already added (and awaited) during block building, so this
|
|
1714
|
+
* needs no retry — they are guaranteed present by the time we get here.
|
|
1715
|
+
*/ async syncProposedCheckpointToArchiver(checkpoint, blockCount, feeAssetPriceModifier) {
|
|
1716
|
+
if (this.config.skipPushProposedBlocksToArchiver || this.config.fishermanMode) {
|
|
1717
|
+
return;
|
|
1718
|
+
}
|
|
1719
|
+
const startBlock = BlockNumber(this.syncedToBlockNumber + 1);
|
|
1720
|
+
this.log.debug(`Syncing proposed checkpoint ${this.checkpointNumber} to archiver`, {
|
|
1721
|
+
checkpointNumber: this.checkpointNumber,
|
|
1722
|
+
slot: this.targetSlot,
|
|
1723
|
+
startBlock,
|
|
1724
|
+
blockCount
|
|
1725
|
+
});
|
|
1726
|
+
await this.blockSink.addProposedCheckpoint({
|
|
1727
|
+
header: checkpoint.header,
|
|
1728
|
+
checkpointNumber: this.checkpointNumber,
|
|
1729
|
+
startBlock,
|
|
1730
|
+
blockCount,
|
|
1731
|
+
totalManaUsed: checkpoint.header.totalManaUsed.toBigInt(),
|
|
1732
|
+
feeAssetPriceModifier
|
|
1733
|
+
});
|
|
1734
|
+
}
|
|
1131
1735
|
/** Runs fee analysis and logs checkpoint outcome as fisherman */ async handleCheckpointEndAsFisherman(checkpoint) {
|
|
1132
1736
|
// Perform L1 fee analysis before clearing requests
|
|
1133
1737
|
// The callback is invoked asynchronously after the next block is mined
|
|
1134
|
-
const feeAnalysis = await this.publisher.analyzeL1Fees(this.
|
|
1738
|
+
const feeAnalysis = await this.publisher.analyzeL1Fees(this.targetSlot, (analysis)=>this.metrics.recordFishermanFeeAnalysis(analysis));
|
|
1135
1739
|
if (checkpoint) {
|
|
1136
|
-
this.log.info(`Validation checkpoint building SUCCEEDED for slot ${this.
|
|
1740
|
+
this.log.info(`Validation checkpoint building SUCCEEDED for slot ${this.targetSlot}`, {
|
|
1137
1741
|
...checkpoint.toCheckpointInfo(),
|
|
1138
1742
|
...checkpoint.getStats(),
|
|
1139
1743
|
feeAnalysisId: feeAnalysis?.id
|
|
1140
1744
|
});
|
|
1141
1745
|
} else {
|
|
1142
|
-
this.log.warn(`Validation block building FAILED for slot ${this.
|
|
1143
|
-
slot: this.
|
|
1746
|
+
this.log.warn(`Validation block building FAILED for slot ${this.targetSlot}`, {
|
|
1747
|
+
slot: this.targetSlot,
|
|
1144
1748
|
feeAnalysisId: feeAnalysis?.id
|
|
1145
1749
|
});
|
|
1146
|
-
this.metrics.
|
|
1750
|
+
this.metrics.recordCheckpointProposalFailed('block_build_failed');
|
|
1147
1751
|
}
|
|
1148
1752
|
this.publisher.clearPendingRequests();
|
|
1149
1753
|
}
|
|
1754
|
+
/**
|
|
1755
|
+
* Helper to handle HA double-signing errors. Returns true if the error was handled (caller should yield).
|
|
1756
|
+
*/ handleHASigningError(err, errorContext) {
|
|
1757
|
+
if (err instanceof DutyAlreadySignedError) {
|
|
1758
|
+
this.log.info(`${errorContext} for slot ${this.targetSlot} already signed by another HA node, yielding`, {
|
|
1759
|
+
slot: this.targetSlot,
|
|
1760
|
+
signedByNode: err.signedByNode
|
|
1761
|
+
});
|
|
1762
|
+
return true;
|
|
1763
|
+
}
|
|
1764
|
+
if (err instanceof SlashingProtectionError) {
|
|
1765
|
+
this.log.info(`${errorContext} for slot ${this.targetSlot} blocked by slashing protection, yielding`, {
|
|
1766
|
+
slot: this.targetSlot,
|
|
1767
|
+
existingMessageHash: err.existingMessageHash,
|
|
1768
|
+
attemptedMessageHash: err.attemptedMessageHash
|
|
1769
|
+
});
|
|
1770
|
+
return true;
|
|
1771
|
+
}
|
|
1772
|
+
return false;
|
|
1773
|
+
}
|
|
1150
1774
|
/** Waits until a specific time within the current slot */ async waitUntilTimeInSlot(targetSecondsIntoSlot) {
|
|
1151
1775
|
const slotStartTimestamp = this.getSlotStartBuildTimestamp();
|
|
1152
1776
|
const targetTimestamp = slotStartTimestamp + targetSecondsIntoSlot;
|
|
1153
|
-
|
|
1777
|
+
const delayMs = targetTimestamp * 1000 - this.dateProvider.nowAsDate().getTime();
|
|
1778
|
+
await this.awaitInterruptibleSleep(delayMs);
|
|
1779
|
+
}
|
|
1780
|
+
/** Pause between mempool polls in waitForMinTxs. Extracted for test overriding. */ async waitForTxsPollingInterval() {
|
|
1781
|
+
await this.awaitInterruptibleSleep(TXS_POLLING_MS);
|
|
1154
1782
|
}
|
|
1155
1783
|
getSlotStartBuildTimestamp() {
|
|
1156
|
-
return getSlotStartBuildTimestamp(this.
|
|
1784
|
+
return getSlotStartBuildTimestamp(this.slotNow, this.l1Constants);
|
|
1157
1785
|
}
|
|
1158
1786
|
getSecondsIntoSlot() {
|
|
1159
1787
|
const slotStartTimestamp = this.getSlotStartBuildTimestamp();
|