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