@aztec/sequencer-client 0.0.1-commit.d1f2d6c → 0.0.1-commit.d20b825a7
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/dest/client/sequencer-client.d.ts +17 -7
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +63 -30
- package/dest/config.d.ts +26 -7
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +52 -36
- package/dest/global_variable_builder/fee_predictor.d.ts +37 -0
- package/dest/global_variable_builder/fee_predictor.d.ts.map +1 -0
- package/dest/global_variable_builder/fee_predictor.js +128 -0
- package/dest/global_variable_builder/fee_provider.d.ts +21 -0
- package/dest/global_variable_builder/fee_provider.d.ts.map +1 -0
- package/dest/global_variable_builder/fee_provider.js +58 -0
- package/dest/global_variable_builder/global_builder.d.ts +15 -16
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +16 -50
- package/dest/global_variable_builder/index.d.ts +4 -2
- package/dest/global_variable_builder/index.d.ts.map +1 -1
- package/dest/global_variable_builder/index.js +2 -0
- package/dest/publisher/config.d.ts +47 -17
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +121 -42
- package/dest/publisher/index.d.ts +2 -1
- package/dest/publisher/index.d.ts.map +1 -1
- package/dest/publisher/l1_tx_failed_store/factory.d.ts +11 -0
- package/dest/publisher/l1_tx_failed_store/factory.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/factory.js +22 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +58 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.js +1 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts +15 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.js +34 -0
- package/dest/publisher/l1_tx_failed_store/index.d.ts +4 -0
- package/dest/publisher/l1_tx_failed_store/index.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/index.js +2 -0
- package/dest/publisher/sequencer-publisher-factory.d.ts +11 -5
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-factory.js +27 -3
- package/dest/publisher/sequencer-publisher-metrics.d.ts +1 -1
- package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-metrics.js +12 -4
- package/dest/publisher/sequencer-publisher.d.ts +75 -49
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +470 -156
- package/dest/sequencer/chain_state_overrides.d.ts +25 -0
- package/dest/sequencer/chain_state_overrides.d.ts.map +1 -0
- package/dest/sequencer/chain_state_overrides.js +39 -0
- package/dest/sequencer/checkpoint_proposal_job.d.ts +67 -14
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_proposal_job.js +581 -242
- package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts +34 -0
- package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_proposal_job_metrics.js +72 -0
- package/dest/sequencer/checkpoint_voter.d.ts +1 -2
- package/dest/sequencer/checkpoint_voter.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_voter.js +2 -5
- package/dest/sequencer/events.d.ts +7 -1
- package/dest/sequencer/events.d.ts.map +1 -1
- package/dest/sequencer/metrics.d.ts +21 -8
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +135 -36
- package/dest/sequencer/sequencer.d.ts +45 -17
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +160 -94
- package/dest/sequencer/timetable.d.ts +17 -6
- package/dest/sequencer/timetable.d.ts.map +1 -1
- package/dest/sequencer/timetable.js +51 -46
- package/dest/sequencer/types.d.ts +2 -2
- package/dest/sequencer/types.d.ts.map +1 -1
- package/dest/test/index.d.ts +3 -5
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.d.ts +14 -11
- package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.js +63 -40
- package/dest/test/utils.d.ts +3 -3
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +5 -4
- package/package.json +27 -28
- package/src/client/sequencer-client.ts +81 -30
- package/src/config.ts +70 -46
- package/src/global_variable_builder/README.md +44 -0
- package/src/global_variable_builder/fee_predictor.ts +172 -0
- package/src/global_variable_builder/fee_provider.ts +75 -0
- package/src/global_variable_builder/global_builder.ts +27 -63
- package/src/global_variable_builder/index.ts +3 -1
- package/src/publisher/config.ts +157 -45
- package/src/publisher/index.ts +3 -0
- package/src/publisher/l1_tx_failed_store/factory.ts +32 -0
- package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +57 -0
- package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +46 -0
- package/src/publisher/l1_tx_failed_store/index.ts +3 -0
- package/src/publisher/sequencer-publisher-factory.ts +38 -9
- package/src/publisher/sequencer-publisher-metrics.ts +7 -3
- package/src/publisher/sequencer-publisher.ts +531 -214
- package/src/sequencer/README.md +83 -13
- package/src/sequencer/chain_state_overrides.ts +87 -0
- package/src/sequencer/checkpoint_proposal_job.ts +748 -278
- package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
- package/src/sequencer/checkpoint_voter.ts +1 -12
- package/src/sequencer/events.ts +6 -1
- package/src/sequencer/metrics.ts +156 -40
- package/src/sequencer/sequencer.ts +232 -107
- package/src/sequencer/timetable.ts +70 -57
- package/src/sequencer/types.ts +1 -1
- package/src/test/index.ts +2 -4
- package/src/test/mock_checkpoint_builder.ts +84 -56
- package/src/test/utils.ts +5 -2
|
@@ -436,23 +436,26 @@ function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
|
|
|
436
436
|
return (_apply_decs_2203_r = applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
|
|
437
437
|
}
|
|
438
438
|
var _dec, _dec1, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _initProto;
|
|
439
|
-
import {
|
|
440
|
-
import { BLOBS_PER_CHECKPOINT, FIELDS_PER_BLOB } from '@aztec/constants';
|
|
441
|
-
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
439
|
+
import { BlockNumber, CheckpointNumber, IndexWithinCheckpoint } from '@aztec/foundation/branded-types';
|
|
442
440
|
import { randomInt } from '@aztec/foundation/crypto/random';
|
|
443
|
-
import {
|
|
441
|
+
import { flipSignature, generateRecoverableSignature, generateUnrecoverableSignature } from '@aztec/foundation/crypto/secp256k1-signer';
|
|
444
442
|
import { filter } from '@aztec/foundation/iterator';
|
|
443
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
444
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
445
445
|
import { sleep, sleepUntil } from '@aztec/foundation/sleep';
|
|
446
446
|
import { Timer } from '@aztec/foundation/timer';
|
|
447
|
-
import { unfreeze } from '@aztec/foundation/types';
|
|
447
|
+
import { isErrorClass, unfreeze } from '@aztec/foundation/types';
|
|
448
448
|
import { CommitteeAttestationsAndSigners, MaliciousCommitteeAttestationsAndSigners } from '@aztec/stdlib/block';
|
|
449
|
-
import {
|
|
449
|
+
import { validateCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
450
|
+
import { computeQuorum, getSlotStartBuildTimestamp, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
450
451
|
import { Gas } from '@aztec/stdlib/gas';
|
|
452
|
+
import { InsufficientValidTxsError } from '@aztec/stdlib/interfaces/server';
|
|
451
453
|
import { computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
|
|
452
|
-
import { orderAttestations } from '@aztec/stdlib/p2p';
|
|
454
|
+
import { orderAttestations, trimAttestations } from '@aztec/stdlib/p2p';
|
|
453
455
|
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
454
456
|
import { Attributes, trackSpan } from '@aztec/telemetry-client';
|
|
455
457
|
import { DutyAlreadySignedError, SlashingProtectionError } from '@aztec/validator-ha-signer/errors';
|
|
458
|
+
import { buildPipelinedParentSimulationOverridesPlan, buildSubmissionSimulationOverridesPlan } from './chain_state_overrides.js';
|
|
456
459
|
import { CheckpointVoter } from './checkpoint_voter.js';
|
|
457
460
|
import { SequencerInterruptedError } from './errors.js';
|
|
458
461
|
import { SequencerState } from './utils.js';
|
|
@@ -461,7 +464,7 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
461
464
|
return {
|
|
462
465
|
// nullish operator needed for tests
|
|
463
466
|
[Attributes.COINBASE]: this.validatorClient.getCoinbaseForAttestor(this.attestorAddress)?.toString(),
|
|
464
|
-
[Attributes.SLOT_NUMBER]: this.
|
|
467
|
+
[Attributes.SLOT_NUMBER]: this.targetSlot
|
|
465
468
|
};
|
|
466
469
|
}), _dec2 = trackSpan('CheckpointProposalJob.buildBlocksForCheckpoint'), _dec3 = trackSpan('CheckpointProposalJob.waitUntilNextSubslot'), _dec4 = trackSpan('CheckpointProposalJob.buildSingleBlock'), _dec5 = trackSpan('CheckpointProposalJob.waitForMinTxs'), _dec6 = trackSpan('CheckpointProposalJob.waitForAttestations'), _dec7 = trackSpan('CheckpointProposalJob.waitUntilTimeInSlot');
|
|
467
470
|
/**
|
|
@@ -470,8 +473,9 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
470
473
|
* as well as enqueueing votes for slashing and governance proposals. This class is created from
|
|
471
474
|
* the Sequencer once the check for being the proposer for the slot has succeeded.
|
|
472
475
|
*/ export class CheckpointProposalJob {
|
|
473
|
-
|
|
474
|
-
|
|
476
|
+
slotNow;
|
|
477
|
+
targetSlot;
|
|
478
|
+
targetEpoch;
|
|
475
479
|
checkpointNumber;
|
|
476
480
|
syncedToBlockNumber;
|
|
477
481
|
proposer;
|
|
@@ -493,10 +497,11 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
493
497
|
epochCache;
|
|
494
498
|
dateProvider;
|
|
495
499
|
metrics;
|
|
500
|
+
checkpointMetrics;
|
|
496
501
|
eventEmitter;
|
|
497
502
|
setStateFn;
|
|
498
|
-
log;
|
|
499
503
|
tracer;
|
|
504
|
+
proposedCheckpointData;
|
|
500
505
|
static{
|
|
501
506
|
({ e: [_initProto] } = _apply_decs_2203_r(this, [
|
|
502
507
|
[
|
|
@@ -541,10 +546,14 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
541
546
|
]
|
|
542
547
|
], []));
|
|
543
548
|
}
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
549
|
+
log;
|
|
550
|
+
/** Tracks the fire-and-forget L1 submission promise so it can be awaited during shutdown. */ pendingL1Submission;
|
|
551
|
+
/** Pipelined parent chain state used while building and later submitting this checkpoint. */ pipelinedParentSimulationOverridesPlan;
|
|
552
|
+
constructor(slotNow, targetSlot, targetEpoch, checkpointNumber, syncedToBlockNumber, // TODO(palla/mbps): Can we remove the proposer in favor of attestorAddress? Need to check fisherman-node flows.
|
|
553
|
+
proposer, publisher, attestorAddress, invalidateCheckpoint, validatorClient, globalsBuilder, p2pClient, worldState, l1ToL2MessageSource, l2BlockSource, checkpointsBuilder, blockSink, l1Constants, config, timetable, slasherClient, epochCache, dateProvider, metrics, checkpointMetrics, eventEmitter, setStateFn, tracer, bindings, proposedCheckpointData){
|
|
554
|
+
this.slotNow = slotNow;
|
|
555
|
+
this.targetSlot = targetSlot;
|
|
556
|
+
this.targetEpoch = targetEpoch;
|
|
548
557
|
this.checkpointNumber = checkpointNumber;
|
|
549
558
|
this.syncedToBlockNumber = syncedToBlockNumber;
|
|
550
559
|
this.proposer = proposer;
|
|
@@ -566,49 +575,261 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
566
575
|
this.epochCache = epochCache;
|
|
567
576
|
this.dateProvider = dateProvider;
|
|
568
577
|
this.metrics = metrics;
|
|
578
|
+
this.checkpointMetrics = checkpointMetrics;
|
|
569
579
|
this.eventEmitter = eventEmitter;
|
|
570
580
|
this.setStateFn = setStateFn;
|
|
571
|
-
this.log = log;
|
|
572
581
|
this.tracer = tracer;
|
|
582
|
+
this.proposedCheckpointData = proposedCheckpointData;
|
|
573
583
|
_initProto(this);
|
|
584
|
+
this.log = createLogger('sequencer:checkpoint-proposal', {
|
|
585
|
+
...bindings,
|
|
586
|
+
instanceId: `slot-${this.slotNow}`
|
|
587
|
+
});
|
|
588
|
+
}
|
|
589
|
+
/** Awaits the pending L1 submission if one is in progress. Call during shutdown. */ async awaitPendingSubmission() {
|
|
590
|
+
this.log.info('Awaiting pending L1 payload submission');
|
|
591
|
+
await this.pendingL1Submission;
|
|
574
592
|
}
|
|
575
593
|
/**
|
|
576
594
|
* Executes the checkpoint proposal job.
|
|
577
|
-
*
|
|
595
|
+
* Builds blocks, assembles checkpoint, and broadcasts the proposal (blocking).
|
|
596
|
+
* Attestation collection, signing, and L1 submission are backgrounded so the
|
|
597
|
+
* work loop can return to IDLE immediately for consecutive slot proposals.
|
|
598
|
+
* Returns the built checkpoint if successful, undefined otherwise.
|
|
578
599
|
*/ async execute() {
|
|
579
600
|
// Enqueue governance and slashing votes (returns promises that will be awaited later)
|
|
580
601
|
// In fisherman mode, we simulate slashing but don't actually publish to L1
|
|
581
602
|
// These are constant for the whole slot, so we only enqueue them once
|
|
582
|
-
const votesPromises = new CheckpointVoter(this.
|
|
583
|
-
// Build
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
603
|
+
const votesPromises = new CheckpointVoter(this.targetSlot, this.publisher, this.attestorAddress, this.validatorClient, this.slasherClient, this.l1Constants, this.config, this.metrics, this.log).enqueueVotes();
|
|
604
|
+
// Build blocks, assemble checkpoint, and broadcast proposal (BLOCKING).
|
|
605
|
+
// Returns after broadcast — attestation collection is deferred.
|
|
606
|
+
const broadcast = await this.proposeCheckpoint();
|
|
607
|
+
if (!broadcast) {
|
|
608
|
+
await Promise.all(votesPromises);
|
|
609
|
+
// Still submit votes even without a checkpoint
|
|
610
|
+
if (!this.config.fishermanMode) {
|
|
611
|
+
this.pendingL1Submission = this.publisher.sendRequestsAt(this.dateProvider.nowAsDate()).then(()=>{});
|
|
612
|
+
}
|
|
613
|
+
return undefined;
|
|
589
614
|
}
|
|
615
|
+
const { checkpoint } = broadcast;
|
|
616
|
+
this.metrics.recordCheckpointProposalSuccess();
|
|
590
617
|
// Do not post anything to L1 if we are fishermen, but do perform L1 fee analysis
|
|
591
618
|
if (this.config.fishermanMode) {
|
|
592
619
|
await this.handleCheckpointEndAsFisherman(checkpoint);
|
|
620
|
+
return checkpoint;
|
|
621
|
+
}
|
|
622
|
+
// Background the attestation → signing → L1 pipeline so the work loop is unblocked
|
|
623
|
+
this.pendingL1Submission = this.waitForAttestationsAndEnqueueSubmissionAsync(broadcast, votesPromises);
|
|
624
|
+
// Return the built checkpoint immediately — the work loop is now unblocked
|
|
625
|
+
return checkpoint;
|
|
626
|
+
}
|
|
627
|
+
/**
|
|
628
|
+
* Background pipeline: collects attestations, signs them, enqueues the checkpoint, and submits to L1.
|
|
629
|
+
* Runs as a fire-and-forget task stored in `pendingL1Submission` so the work loop is unblocked.
|
|
630
|
+
*/ async waitForAttestationsAndEnqueueSubmissionAsync(broadcast, votesPromises) {
|
|
631
|
+
const { checkpoint } = broadcast;
|
|
632
|
+
const isPipelining = this.epochCache.isProposerPipeliningEnabled();
|
|
633
|
+
try {
|
|
634
|
+
// Wait for all votes actions, enqueued at the beginning, to resolve
|
|
635
|
+
await Promise.all(votesPromises);
|
|
636
|
+
// Try to collect attestations from the committee
|
|
637
|
+
const signedAttestations = await this.getSignedCommitteeAttestations(broadcast);
|
|
638
|
+
// If pipelining, wait for the previous checkpoint to land on L1 before submitting,
|
|
639
|
+
// so we can check it matches the proposed checkpoint we used as parent, and has valid attestations.
|
|
640
|
+
if (signedAttestations && (!isPipelining || await this.waitForValidParentCheckpointOnL1())) {
|
|
641
|
+
await this.enqueueCheckpointForSubmission({
|
|
642
|
+
checkpoint,
|
|
643
|
+
...signedAttestations
|
|
644
|
+
});
|
|
645
|
+
}
|
|
646
|
+
// If we failed to collect attestations, at least check if we need to issue an invalidation
|
|
647
|
+
// Note that if we are not pipelining, we enqueued the invalidation at the beginning
|
|
648
|
+
if (!signedAttestations && isPipelining && await this.waitForSyncedL2SlotNumber(this.slotNow)) {
|
|
649
|
+
const validationStatus = await this.l2BlockSource.getPendingChainValidationStatus();
|
|
650
|
+
if (!validationStatus.valid) {
|
|
651
|
+
this.log.warn(`Checkpoint ${validationStatus.checkpoint.checkpointNumber} has invalid attestations, enqueuing invalidation in spite of attestation collection failure`, {
|
|
652
|
+
checkpoint: validationStatus.checkpoint,
|
|
653
|
+
reason: validationStatus.reason
|
|
654
|
+
});
|
|
655
|
+
await this.enqueueInvalidation(validationStatus);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
// Send whatever was enqueued: votes + (propose | invalidation | nothing).
|
|
659
|
+
// Compute the earliest time to submit: pipeline slot start when pipelining, now otherwise.
|
|
660
|
+
const submitAfter = isPipelining ? new Date(Number(getTimestampForSlot(this.targetSlot, this.l1Constants)) * 1000) : new Date(this.dateProvider.now());
|
|
661
|
+
const l1Response = await this.publisher.sendRequestsAt(submitAfter);
|
|
662
|
+
const proposedAction = l1Response?.successfulActions.find((a)=>a === 'propose');
|
|
663
|
+
if (proposedAction) {
|
|
664
|
+
this.eventEmitter.emit('checkpoint-published', {
|
|
665
|
+
checkpoint: this.checkpointNumber,
|
|
666
|
+
slot: this.targetSlot
|
|
667
|
+
});
|
|
668
|
+
const coinbase = checkpoint.header.coinbase;
|
|
669
|
+
await this.metrics.incFilledSlot(this.publisher.getSenderAddress().toString(), coinbase);
|
|
670
|
+
} else {
|
|
671
|
+
this.eventEmitter.emit('checkpoint-publish-failed', {
|
|
672
|
+
...l1Response,
|
|
673
|
+
slot: this.targetSlot
|
|
674
|
+
});
|
|
675
|
+
if (isPipelining) {
|
|
676
|
+
this.metrics.recordPipelineDiscard();
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
} catch (err) {
|
|
680
|
+
if (err instanceof SequencerInterruptedError) {
|
|
681
|
+
return;
|
|
682
|
+
}
|
|
683
|
+
this.log.error(`Background attestation/L1 pipeline failed for slot ${this.targetSlot}`, err);
|
|
684
|
+
this.eventEmitter.emit('checkpoint-publish-failed', {
|
|
685
|
+
slot: this.targetSlot
|
|
686
|
+
});
|
|
687
|
+
if (isPipelining) {
|
|
688
|
+
this.metrics.recordPipelineDiscard();
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
/** Enqueues the checkpoint for L1 submission. Called after pipeline sleep in execute(). */ async enqueueCheckpointForSubmission(result) {
|
|
693
|
+
const { checkpoint, attestations, attestationsSignature } = result;
|
|
694
|
+
this.setStateFn(SequencerState.PUBLISHING_CHECKPOINT, this.targetSlot);
|
|
695
|
+
const aztecSlotDuration = this.l1Constants.slotDuration;
|
|
696
|
+
const submissionSlotStart = Number(getTimestampForSlot(this.targetSlot, this.l1Constants));
|
|
697
|
+
const txTimeoutAt = new Date((submissionSlotStart + aztecSlotDuration) * 1000);
|
|
698
|
+
// If we have been configured to potentially skip publishing checkpoint then roll the dice here
|
|
699
|
+
if (this.config.skipPublishingCheckpointsPercent !== undefined && this.config.skipPublishingCheckpointsPercent > 0) {
|
|
700
|
+
const roll = Math.max(0, randomInt(100));
|
|
701
|
+
if (roll < this.config.skipPublishingCheckpointsPercent) {
|
|
702
|
+
this.log.warn(`Skipping publishing proposal for checkpoint ${checkpoint.number}. Configured percentage: ${this.config.skipPublishingCheckpointsPercent}, generated value: ${roll}`);
|
|
703
|
+
return;
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
const isPipelining = this.epochCache.isProposerPipeliningEnabled();
|
|
707
|
+
const submissionSimulationOverridesPlan = buildSubmissionSimulationOverridesPlan({
|
|
708
|
+
pipelinedParentPlan: this.pipelinedParentSimulationOverridesPlan,
|
|
709
|
+
invalidateToPendingCheckpointNumber: this.invalidateCheckpoint?.forcePendingCheckpointNumber,
|
|
710
|
+
lastArchiveRoot: checkpoint.header.lastArchiveRoot,
|
|
711
|
+
pipeliningEnabled: isPipelining
|
|
712
|
+
});
|
|
713
|
+
await this.publisher.enqueueProposeCheckpoint(checkpoint, attestations, attestationsSignature, {
|
|
714
|
+
txTimeoutAt,
|
|
715
|
+
...submissionSimulationOverridesPlan ? {
|
|
716
|
+
simulationOverridesPlan: submissionSimulationOverridesPlan
|
|
717
|
+
} : {}
|
|
718
|
+
});
|
|
719
|
+
}
|
|
720
|
+
/**
|
|
721
|
+
* Wait until the archiver syncs past the given L2 slot number.
|
|
722
|
+
* The deadline is the end of `this.targetSlot`, beyond which any pipelined work would miss its
|
|
723
|
+
* L1 submission window and is no longer useful.
|
|
724
|
+
*/ async waitForSyncedL2SlotNumber(waitForSlot) {
|
|
725
|
+
const targetSlotStart = Number(getTimestampForSlot(this.targetSlot, this.l1Constants));
|
|
726
|
+
const targetSlotEndMs = (targetSlotStart + this.l1Constants.slotDuration) * 1000;
|
|
727
|
+
const syncDelayTolerance = this.l1Constants.ethereumSlotDuration * 2 * 1000;
|
|
728
|
+
const timeoutSeconds = Math.max(0.1, (targetSlotEndMs + syncDelayTolerance - this.dateProvider.now()) / 1000);
|
|
729
|
+
try {
|
|
730
|
+
return await retryUntil(async ()=>{
|
|
731
|
+
const syncedSlot = await this.l2BlockSource.getSyncedL2SlotNumber();
|
|
732
|
+
return syncedSlot !== undefined && syncedSlot >= waitForSlot;
|
|
733
|
+
}, `archiver sync past slot ${waitForSlot}`, timeoutSeconds, 0.2);
|
|
734
|
+
} catch {
|
|
735
|
+
this.log.warn(`Archiver did not sync L1 past slot ${waitForSlot} before slot ${this.targetSlot} expired, discarding pipelined work`, {
|
|
736
|
+
checkpointNumber: this.checkpointNumber
|
|
737
|
+
});
|
|
738
|
+
this.emitPipelinedCheckpointDiscarded('archiver-sync-timeout');
|
|
739
|
+
return false;
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
/**
|
|
743
|
+
* Waits for the parent checkpoint to land on L1 before submitting a pipelined checkpoint.
|
|
744
|
+
* Polls until the archiver has synced L1 past the parent's slot, then verifies:
|
|
745
|
+
* - If we built on a proposed parent: it must have landed on L1 with matching hash and valid attestations.
|
|
746
|
+
* - If we built without a proposed parent: no new checkpoint must have appeared for that slot.
|
|
747
|
+
* If the parent has invalid attestations, enqueues an invalidation. Returns whether to proceed with the proposal.
|
|
748
|
+
*/ async waitForValidParentCheckpointOnL1() {
|
|
749
|
+
const parentCheckpointNumber = CheckpointNumber(this.checkpointNumber - 1);
|
|
750
|
+
// Wait until archiver has synced L1 past the parent's slot (slotNow)
|
|
751
|
+
if (!await this.waitForSyncedL2SlotNumber(this.slotNow)) {
|
|
752
|
+
return false;
|
|
753
|
+
}
|
|
754
|
+
const tips = await this.l2BlockSource.getL2Tips();
|
|
755
|
+
const checkpointedNumber = tips.checkpointed.checkpoint.number;
|
|
756
|
+
// We built on top of a proposed checkpoint. Verify it landed on L1 as expected.
|
|
757
|
+
if (this.proposedCheckpointData) {
|
|
758
|
+
// After syncing from L1 we see the chain tip has invalid attestations. This means the parent checkpoint was posted
|
|
759
|
+
// with invalid attestations, or it built on top of something with invalid attestations and didnt invalidate them.
|
|
760
|
+
// Either way, we thought our parent would be valid, so we have to throw away our work. But at least we'll try and
|
|
761
|
+
// invalidate on L1 so we clean up the chain for the next proposer. And we'll slash them, but that's handled elsewhere.
|
|
762
|
+
const validationStatus = await this.l2BlockSource.getPendingChainValidationStatus();
|
|
763
|
+
if (!validationStatus.valid) {
|
|
764
|
+
this.log.warn(`Parent checkpoint ${parentCheckpointNumber} has invalid attestations, discarding pipelined work`, {
|
|
765
|
+
checkpointNumber: this.checkpointNumber,
|
|
766
|
+
reason: validationStatus.reason
|
|
767
|
+
});
|
|
768
|
+
this.emitPipelinedCheckpointDiscarded('parent-invalid-attestations');
|
|
769
|
+
await this.enqueueInvalidation(validationStatus);
|
|
770
|
+
return false;
|
|
771
|
+
}
|
|
772
|
+
// The pending chain is valid. But did the parent checkpoint land on L1 at all?
|
|
773
|
+
if (checkpointedNumber < parentCheckpointNumber) {
|
|
774
|
+
this.log.warn(`Parent checkpoint ${parentCheckpointNumber} did not land on L1, discarding pipelined work`, {
|
|
775
|
+
checkpointNumber: this.checkpointNumber,
|
|
776
|
+
checkpointedNumber
|
|
777
|
+
});
|
|
778
|
+
this.emitPipelinedCheckpointDiscarded('parent-not-on-l1');
|
|
779
|
+
return false;
|
|
780
|
+
}
|
|
781
|
+
// It landed. But is it the one we were expecting?
|
|
782
|
+
const expectedHash = this.proposedCheckpointData.header.hash().toString();
|
|
783
|
+
if (tips.checkpointed.checkpoint.hash !== expectedHash) {
|
|
784
|
+
this.log.warn(`Parent checkpoint ${parentCheckpointNumber} hash mismatch on L1, discarding pipelined work`, {
|
|
785
|
+
checkpointNumber: this.checkpointNumber,
|
|
786
|
+
expectedHash,
|
|
787
|
+
actualHash: tips.checkpointed.checkpoint.hash
|
|
788
|
+
});
|
|
789
|
+
this.emitPipelinedCheckpointDiscarded('parent-hash-mismatch');
|
|
790
|
+
return false;
|
|
791
|
+
}
|
|
792
|
+
return true;
|
|
793
|
+
} else {
|
|
794
|
+
// We didn't see a proposed checkpoint at build time, so we built on checkpointed parent from two slots ago.
|
|
795
|
+
// But if a new checkpoint for the previous slot appeared on L1 in the meantime, our checkpoint assumed the wrong parent,
|
|
796
|
+
// so we have to discard our work. This can happen if we're somehow cut off from p2p and fail to see the checkpoint
|
|
797
|
+
// proposal for the previous slot.
|
|
798
|
+
if (checkpointedNumber > parentCheckpointNumber) {
|
|
799
|
+
this.log.warn(`Unexpected checkpoint ${checkpointedNumber} landed on L1 after we built on top of parent ${parentCheckpointNumber}, discarding pipelined work`, {
|
|
800
|
+
checkpointNumber: this.checkpointNumber,
|
|
801
|
+
checkpointedNumber
|
|
802
|
+
});
|
|
803
|
+
this.emitPipelinedCheckpointDiscarded('unexpected-parent-appeared');
|
|
804
|
+
return false;
|
|
805
|
+
}
|
|
806
|
+
return true;
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
/** Emits the pipelined-checkpoint-discarded event and records the metric. */ emitPipelinedCheckpointDiscarded(reason) {
|
|
810
|
+
this.metrics.recordPipelineParentCheckpointMismatch(reason);
|
|
811
|
+
this.eventEmitter.emit('pipelined-checkpoint-discarded', {
|
|
812
|
+
slot: this.targetSlot,
|
|
813
|
+
checkpointNumber: this.checkpointNumber,
|
|
814
|
+
reason
|
|
815
|
+
});
|
|
816
|
+
}
|
|
817
|
+
/** Simulates and enqueues an invalidation request for the invalid parent checkpoint. */ async enqueueInvalidation(validationStatus) {
|
|
818
|
+
if (this.config.skipInvalidateBlockAsProposer) {
|
|
819
|
+
this.log.warn(`Skipping checkpoint invalidation as proposer due to test configuration`);
|
|
593
820
|
return;
|
|
594
821
|
}
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
this.
|
|
600
|
-
|
|
601
|
-
slot: this.slot
|
|
822
|
+
const invalidateRequest = await this.publisher.simulateInvalidateCheckpoint(validationStatus);
|
|
823
|
+
if (invalidateRequest) {
|
|
824
|
+
const submissionSlotStart = Number(getTimestampForSlot(this.targetSlot, this.l1Constants));
|
|
825
|
+
const txTimeoutAt = new Date((submissionSlotStart + this.l1Constants.slotDuration) * 1000);
|
|
826
|
+
this.publisher.enqueueInvalidateCheckpoint(invalidateRequest, {
|
|
827
|
+
txTimeoutAt
|
|
602
828
|
});
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
} else if (checkpoint) {
|
|
607
|
-
this.eventEmitter.emit('checkpoint-publish-failed', {
|
|
608
|
-
...l1Response,
|
|
609
|
-
slot: this.slot
|
|
829
|
+
} else {
|
|
830
|
+
this.log.info(`Invalidation simulation returned undefined, checkpoint may have been removed already`, {
|
|
831
|
+
checkpointNumber: this.checkpointNumber
|
|
610
832
|
});
|
|
611
|
-
return undefined;
|
|
612
833
|
}
|
|
613
834
|
}
|
|
614
835
|
async proposeCheckpoint() {
|
|
@@ -619,29 +840,55 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
619
840
|
hasError: false
|
|
620
841
|
};
|
|
621
842
|
try {
|
|
843
|
+
const now = this.dateProvider.now();
|
|
844
|
+
if (this.epochCache.isProposerPipeliningEnabled() && this.proposedCheckpointData) {
|
|
845
|
+
// Measure against the wall-clock slot whose build window we are currently using.
|
|
846
|
+
// In pipelining mode `targetSlot` is intentionally one slot ahead, which makes the
|
|
847
|
+
// target-slot boundary a full slot away from the actual build start time.
|
|
848
|
+
const slotBoundaryMs = Number(getTimestampForSlot(this.slotNow, this.l1Constants)) * 1000;
|
|
849
|
+
this.checkpointMetrics.recordPipelinedCheckpointBuildStartOffsetFromSlotBoundary(now - slotBoundaryMs);
|
|
850
|
+
}
|
|
851
|
+
this.checkpointMetrics.startCheckpointTiming(now);
|
|
622
852
|
// Get operator configured coinbase and fee recipient for this attestor
|
|
623
853
|
const coinbase = this.validatorClient.getCoinbaseForAttestor(this.attestorAddress);
|
|
624
854
|
const feeRecipient = this.validatorClient.getFeeRecipientForAttestor(this.attestorAddress);
|
|
625
855
|
// Start the checkpoint
|
|
626
|
-
this.setStateFn(SequencerState.INITIALIZING_CHECKPOINT, this.
|
|
627
|
-
this.
|
|
856
|
+
this.setStateFn(SequencerState.INITIALIZING_CHECKPOINT, this.targetSlot);
|
|
857
|
+
this.log.info(`Starting checkpoint proposal`, {
|
|
858
|
+
buildSlot: this.slotNow,
|
|
859
|
+
submissionSlot: this.targetSlot,
|
|
860
|
+
pipelining: this.epochCache.isProposerPipeliningEnabled(),
|
|
861
|
+
proposer: this.proposer?.toString(),
|
|
862
|
+
coinbase: coinbase.toString()
|
|
863
|
+
});
|
|
864
|
+
this.metrics.incOpenSlot(this.targetSlot, this.proposer?.toString() ?? 'unknown');
|
|
628
865
|
// Enqueues checkpoint invalidation (constant for the whole slot)
|
|
629
866
|
if (this.invalidateCheckpoint && !this.config.skipInvalidateBlockAsProposer) {
|
|
630
867
|
this.publisher.enqueueInvalidateCheckpoint(this.invalidateCheckpoint);
|
|
631
868
|
}
|
|
632
|
-
// Create checkpoint builder for the slot
|
|
633
|
-
|
|
869
|
+
// Create checkpoint builder for the slot.
|
|
870
|
+
// When pipelining, force the proposed checkpoint number and fee header to our parent so the
|
|
871
|
+
// fee computation sees the same chain tip that L1 will see once the previous pipelined checkpoint lands.
|
|
872
|
+
const isPipelining = this.epochCache.isProposerPipeliningEnabled();
|
|
873
|
+
this.pipelinedParentSimulationOverridesPlan = isPipelining ? await buildPipelinedParentSimulationOverridesPlan({
|
|
874
|
+
checkpointNumber: this.checkpointNumber,
|
|
875
|
+
proposedCheckpointData: this.proposedCheckpointData,
|
|
876
|
+
rollup: this.publisher.rollupContract,
|
|
877
|
+
log: this.log
|
|
878
|
+
}) : undefined;
|
|
879
|
+
const checkpointGlobalVariables = await this.globalsBuilder.buildCheckpointGlobalVariables(coinbase, feeRecipient, this.targetSlot, this.pipelinedParentSimulationOverridesPlan);
|
|
634
880
|
// Collect L1 to L2 messages for the checkpoint and compute their hash
|
|
635
881
|
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(this.checkpointNumber);
|
|
636
882
|
const inHash = computeInHashFromL1ToL2Messages(l1ToL2Messages);
|
|
637
883
|
// Collect the out hashes of all the checkpoints before this one in the same epoch
|
|
638
|
-
const
|
|
639
|
-
|
|
884
|
+
const previousCheckpointOutHashes = (await this.l2BlockSource.getCheckpointsDataForEpoch(this.targetEpoch)).filter((c)=>c.checkpointNumber < this.checkpointNumber).map((c)=>c.checkpointOutHash);
|
|
885
|
+
// Get the fee asset price modifier from the oracle
|
|
886
|
+
const feeAssetPriceModifier = await this.publisher.getFeeAssetPriceModifier();
|
|
640
887
|
const fork = _ts_add_disposable_resource(env, await this.worldState.fork(this.syncedToBlockNumber, {
|
|
641
888
|
closeDelayMs: 12_000
|
|
642
|
-
}),
|
|
889
|
+
}), true);
|
|
643
890
|
// Create checkpoint builder for the entire slot
|
|
644
|
-
const checkpointBuilder = await this.checkpointsBuilder.startCheckpoint(this.checkpointNumber, checkpointGlobalVariables, l1ToL2Messages, previousCheckpointOutHashes, fork);
|
|
891
|
+
const checkpointBuilder = await this.checkpointsBuilder.startCheckpoint(this.checkpointNumber, checkpointGlobalVariables, feeAssetPriceModifier, l1ToL2Messages, previousCheckpointOutHashes, fork, this.log.getBindings());
|
|
645
892
|
// Options for the validator client when creating block and checkpoint proposals
|
|
646
893
|
const blockProposalOptions = {
|
|
647
894
|
publishFullTxs: !!this.config.publishTxsWithProposals,
|
|
@@ -653,6 +900,7 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
653
900
|
};
|
|
654
901
|
let blocksInCheckpoint = [];
|
|
655
902
|
let blockPendingBroadcast = undefined;
|
|
903
|
+
const checkpointBuildTimer = new Timer();
|
|
656
904
|
try {
|
|
657
905
|
// Main loop: build blocks for the checkpoint
|
|
658
906
|
const result = await this.buildBlocksForCheckpoint(checkpointBuilder, checkpointGlobalVariables.timestamp, inHash, blockProposalOptions);
|
|
@@ -662,107 +910,90 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
662
910
|
// These errors are expected in HA mode, so we yield and let another HA node handle the slot
|
|
663
911
|
// The only distinction between the 2 errors is SlashingProtectionError throws when the payload is different,
|
|
664
912
|
// which is normal for block building (may have picked different txs)
|
|
665
|
-
if (err
|
|
666
|
-
this.log.info(`Checkpoint proposal for slot ${this.slot} already signed by another HA node, yielding`, {
|
|
667
|
-
slot: this.slot,
|
|
668
|
-
signedByNode: err.signedByNode
|
|
669
|
-
});
|
|
670
|
-
return undefined;
|
|
671
|
-
}
|
|
672
|
-
if (err instanceof SlashingProtectionError) {
|
|
673
|
-
this.log.info(`Checkpoint proposal for slot ${this.slot} blocked by slashing protection, yielding`, {
|
|
674
|
-
slot: this.slot,
|
|
675
|
-
existingMessageHash: err.existingMessageHash,
|
|
676
|
-
attemptedMessageHash: err.attemptedMessageHash
|
|
677
|
-
});
|
|
913
|
+
if (this.handleHASigningError(err, 'Block proposal')) {
|
|
678
914
|
return undefined;
|
|
679
915
|
}
|
|
680
916
|
throw err;
|
|
681
917
|
}
|
|
682
918
|
if (blocksInCheckpoint.length === 0) {
|
|
683
|
-
this.log.warn(`No blocks were built for slot ${this.
|
|
684
|
-
slot: this.
|
|
919
|
+
this.log.warn(`No blocks were built for slot ${this.targetSlot}`, {
|
|
920
|
+
slot: this.targetSlot
|
|
685
921
|
});
|
|
686
922
|
this.eventEmitter.emit('checkpoint-empty', {
|
|
687
|
-
slot: this.
|
|
923
|
+
slot: this.targetSlot
|
|
924
|
+
});
|
|
925
|
+
return undefined;
|
|
926
|
+
}
|
|
927
|
+
const minBlocksForCheckpoint = this.config.minBlocksForCheckpoint;
|
|
928
|
+
if (minBlocksForCheckpoint !== undefined && blocksInCheckpoint.length < minBlocksForCheckpoint) {
|
|
929
|
+
this.log.warn(`Checkpoint has fewer blocks than minimum (${blocksInCheckpoint.length} < ${minBlocksForCheckpoint}), skipping proposal`, {
|
|
930
|
+
slot: this.targetSlot,
|
|
931
|
+
blocksBuilt: blocksInCheckpoint.length,
|
|
932
|
+
minBlocksForCheckpoint
|
|
688
933
|
});
|
|
689
934
|
return undefined;
|
|
690
935
|
}
|
|
691
936
|
// Assemble and broadcast the checkpoint proposal, including the last block that was not
|
|
692
937
|
// broadcasted yet, and wait to collect the committee attestations.
|
|
693
|
-
this.setStateFn(SequencerState.ASSEMBLING_CHECKPOINT, this.
|
|
938
|
+
this.setStateFn(SequencerState.ASSEMBLING_CHECKPOINT, this.targetSlot);
|
|
694
939
|
const checkpoint = await checkpointBuilder.completeCheckpoint();
|
|
695
|
-
//
|
|
940
|
+
// Final validation: per-block limits are only checked if the operator set them explicitly.
|
|
941
|
+
// Otherwise, checkpoint-level budgets were already enforced by the redistribution logic.
|
|
942
|
+
try {
|
|
943
|
+
validateCheckpoint(checkpoint, {
|
|
944
|
+
rollupManaLimit: this.l1Constants.rollupManaLimit,
|
|
945
|
+
maxL2BlockGas: this.config.maxL2BlockGas,
|
|
946
|
+
maxDABlockGas: this.config.maxDABlockGas,
|
|
947
|
+
maxTxsPerBlock: this.config.maxTxsPerBlock,
|
|
948
|
+
maxTxsPerCheckpoint: this.config.maxTxsPerCheckpoint
|
|
949
|
+
});
|
|
950
|
+
} catch (err) {
|
|
951
|
+
this.log.error(`Built an invalid checkpoint at slot ${this.slotNow} (skipping proposal)`, err, {
|
|
952
|
+
checkpoint: checkpoint.header.toInspect()
|
|
953
|
+
});
|
|
954
|
+
return undefined;
|
|
955
|
+
}
|
|
956
|
+
// Record checkpoint-level build metrics
|
|
957
|
+
this.checkpointMetrics.recordCheckpointBuild(checkpointBuildTimer.ms(), blocksInCheckpoint.length, checkpoint.getStats().txCount, Number(checkpoint.header.totalManaUsed.toBigInt()));
|
|
958
|
+
// In fisherman mode, return the checkpoint without broadcasting or collecting attestations
|
|
696
959
|
if (this.config.fishermanMode) {
|
|
697
|
-
this.log.info(`Built checkpoint for slot ${this.
|
|
698
|
-
slot: this.
|
|
960
|
+
this.log.info(`Built checkpoint for slot ${this.targetSlot} with ${blocksInCheckpoint.length} blocks. ` + `Skipping proposal in fisherman mode.`, {
|
|
961
|
+
slot: this.targetSlot,
|
|
699
962
|
checkpoint: checkpoint.header.toInspect(),
|
|
700
963
|
blocksBuilt: blocksInCheckpoint.length
|
|
701
964
|
});
|
|
702
965
|
this.metrics.recordCheckpointSuccess();
|
|
703
|
-
|
|
966
|
+
// Return a broadcast result with a dummy proposal — fisherman mode skips attestation collection
|
|
967
|
+
return {
|
|
968
|
+
checkpoint,
|
|
969
|
+
proposal: undefined,
|
|
970
|
+
blockProposedAt: this.dateProvider.now()
|
|
971
|
+
};
|
|
704
972
|
}
|
|
705
|
-
// Include the block pending broadcast in the checkpoint proposal if any
|
|
706
|
-
const lastBlock = blockPendingBroadcast && {
|
|
707
|
-
blockHeader: blockPendingBroadcast.block.header,
|
|
708
|
-
indexWithinCheckpoint: blockPendingBroadcast.block.indexWithinCheckpoint,
|
|
709
|
-
txs: blockPendingBroadcast.txs
|
|
710
|
-
};
|
|
711
973
|
// Create the checkpoint proposal and broadcast it
|
|
712
|
-
const proposal = await this.validatorClient.createCheckpointProposal(checkpoint.header, checkpoint.archive.root,
|
|
974
|
+
const proposal = await this.validatorClient.createCheckpointProposal(checkpoint.header, checkpoint.archive.root, this.checkpointNumber, feeAssetPriceModifier, blockPendingBroadcast, this.proposer, checkpointProposalOptions);
|
|
713
975
|
const blockProposedAt = this.dateProvider.now();
|
|
714
976
|
await this.p2pClient.broadcastCheckpointProposal(proposal);
|
|
715
|
-
this.
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
try {
|
|
723
|
-
attestationsSignature = await this.validatorClient.signAttestationsAndSigners(attestations, signer, this.slot, this.checkpointNumber);
|
|
724
|
-
} catch (err) {
|
|
725
|
-
// We shouldn't really get here since we yield to another HA node
|
|
726
|
-
// as soon as we see these errors when creating block proposals.
|
|
727
|
-
if (err instanceof DutyAlreadySignedError) {
|
|
728
|
-
this.log.info(`Attestations signature for slot ${this.slot} already signed by another HA node, yielding`, {
|
|
729
|
-
slot: this.slot,
|
|
730
|
-
signedByNode: err.signedByNode
|
|
731
|
-
});
|
|
732
|
-
return undefined;
|
|
733
|
-
}
|
|
734
|
-
if (err instanceof SlashingProtectionError) {
|
|
735
|
-
this.log.info(`Attestations signature for slot ${this.slot} blocked by slashing protection, yielding`, {
|
|
736
|
-
slot: this.slot,
|
|
737
|
-
existingMessageHash: err.existingMessageHash,
|
|
738
|
-
attemptedMessageHash: err.attemptedMessageHash
|
|
739
|
-
});
|
|
740
|
-
return undefined;
|
|
741
|
-
}
|
|
742
|
-
throw err;
|
|
743
|
-
}
|
|
744
|
-
// Enqueue publishing the checkpoint to L1
|
|
745
|
-
this.setStateFn(SequencerState.PUBLISHING_CHECKPOINT, this.slot);
|
|
746
|
-
const aztecSlotDuration = this.l1Constants.slotDuration;
|
|
747
|
-
const slotStartBuildTimestamp = this.getSlotStartBuildTimestamp();
|
|
748
|
-
const txTimeoutAt = new Date((slotStartBuildTimestamp + aztecSlotDuration) * 1000);
|
|
749
|
-
await this.publisher.enqueueProposeCheckpoint(checkpoint, attestations, attestationsSignature, {
|
|
750
|
-
txTimeoutAt,
|
|
751
|
-
forcePendingCheckpointNumber: this.invalidateCheckpoint?.forcePendingCheckpointNumber
|
|
752
|
-
});
|
|
753
|
-
return checkpoint;
|
|
977
|
+
this.checkpointMetrics.noteCheckpointBroadcast(this.dateProvider.now());
|
|
978
|
+
// Return immediately after broadcast — attestation collection happens in the background
|
|
979
|
+
return {
|
|
980
|
+
checkpoint,
|
|
981
|
+
proposal,
|
|
982
|
+
blockProposedAt
|
|
983
|
+
};
|
|
754
984
|
} catch (e) {
|
|
755
985
|
env.error = e;
|
|
756
986
|
env.hasError = true;
|
|
757
987
|
} finally{
|
|
758
|
-
_ts_dispose_resources(env);
|
|
988
|
+
const result = _ts_dispose_resources(env);
|
|
989
|
+
if (result) await result;
|
|
759
990
|
}
|
|
760
991
|
} catch (err) {
|
|
761
992
|
if (err && (err instanceof DutyAlreadySignedError || err instanceof SlashingProtectionError)) {
|
|
762
993
|
// swallow this error. It's already been logged by a function deeper in the stack
|
|
763
994
|
return undefined;
|
|
764
995
|
}
|
|
765
|
-
this.log.error(`Error building checkpoint at slot ${this.
|
|
996
|
+
this.log.error(`Error building checkpoint at slot ${this.targetSlot}`, err);
|
|
766
997
|
return undefined;
|
|
767
998
|
}
|
|
768
999
|
}
|
|
@@ -772,19 +1003,17 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
772
1003
|
const blocksInCheckpoint = [];
|
|
773
1004
|
const txHashesAlreadyIncluded = new Set();
|
|
774
1005
|
const initialBlockNumber = BlockNumber(this.syncedToBlockNumber + 1);
|
|
775
|
-
// Remaining blob fields available for blocks (checkpoint end marker already subtracted)
|
|
776
|
-
let remainingBlobFields = BLOBS_PER_CHECKPOINT * FIELDS_PER_BLOB - NUM_CHECKPOINT_END_MARKER_FIELDS;
|
|
777
1006
|
// Last block in the checkpoint will usually be flagged as pending broadcast, so we send it along with the checkpoint proposal
|
|
778
1007
|
let blockPendingBroadcast = undefined;
|
|
779
1008
|
while(true){
|
|
780
1009
|
const blocksBuilt = blocksInCheckpoint.length;
|
|
781
|
-
const indexWithinCheckpoint = blocksBuilt;
|
|
1010
|
+
const indexWithinCheckpoint = IndexWithinCheckpoint(blocksBuilt);
|
|
782
1011
|
const blockNumber = BlockNumber(initialBlockNumber + blocksBuilt);
|
|
783
1012
|
const secondsIntoSlot = this.getSecondsIntoSlot();
|
|
784
1013
|
const timingInfo = this.timetable.canStartNextBlock(secondsIntoSlot);
|
|
785
1014
|
if (!timingInfo.canStart) {
|
|
786
1015
|
this.log.debug(`Not enough time left in slot to start another block`, {
|
|
787
|
-
slot: this.
|
|
1016
|
+
slot: this.targetSlot,
|
|
788
1017
|
blocksBuilt,
|
|
789
1018
|
secondsIntoSlot
|
|
790
1019
|
});
|
|
@@ -799,66 +1028,61 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
799
1028
|
buildDeadline: timingInfo.deadline ? new Date((this.getSlotStartBuildTimestamp() + timingInfo.deadline) * 1000) : undefined,
|
|
800
1029
|
blockNumber,
|
|
801
1030
|
indexWithinCheckpoint,
|
|
802
|
-
txHashesAlreadyIncluded
|
|
803
|
-
remainingBlobFields
|
|
1031
|
+
txHashesAlreadyIncluded
|
|
804
1032
|
});
|
|
805
|
-
if
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
1033
|
+
// If we failed to build the block due to insufficient txs, we try again if there is still time left in the slot
|
|
1034
|
+
if ('failure' in buildResult) {
|
|
1035
|
+
// If this was the last subslot, or we're running with a single block per slot, we're done
|
|
1036
|
+
if (timingInfo.isLastBlock || timingInfo.deadline === undefined) {
|
|
1037
|
+
break;
|
|
1038
|
+
}
|
|
1039
|
+
// Otherwise, if there is still time for more blocks, we wait until the next subslot and try again
|
|
809
1040
|
await this.waitUntilNextSubslot(timingInfo.deadline);
|
|
810
1041
|
continue;
|
|
811
|
-
}
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
1042
|
+
}
|
|
1043
|
+
// If there was an error building the block, we just exit the loop and give up the rest of the slot.
|
|
1044
|
+
// We don't want to risk building more blocks if something went wrong.
|
|
1045
|
+
if ('error' in buildResult) {
|
|
815
1046
|
if (!(buildResult.error instanceof SequencerInterruptedError)) {
|
|
816
|
-
this.log.warn(`Halting block building for slot ${this.
|
|
817
|
-
slot: this.
|
|
1047
|
+
this.log.warn(`Halting block building for slot ${this.targetSlot}`, {
|
|
1048
|
+
slot: this.targetSlot,
|
|
818
1049
|
blocksBuilt,
|
|
819
1050
|
error: buildResult.error
|
|
820
1051
|
});
|
|
821
1052
|
}
|
|
822
1053
|
break;
|
|
823
1054
|
}
|
|
824
|
-
const { block, usedTxs
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
// Sync the proposed block to the archiver to make it available
|
|
829
|
-
// Note that the checkpoint builder uses its own fork so it should not need to wait for this syncing
|
|
830
|
-
// Eventually we should refactor the checkpoint builder to not need a separate long-lived fork
|
|
831
|
-
// Fire and forget - don't block the critical path, but log errors
|
|
832
|
-
this.syncProposedBlockToArchiver(block).catch((err)=>{
|
|
833
|
-
this.log.error(`Failed to sync proposed block ${block.number} to archiver`, {
|
|
834
|
-
blockNumber: block.number,
|
|
835
|
-
err
|
|
836
|
-
});
|
|
1055
|
+
const { block, usedTxs } = buildResult;
|
|
1056
|
+
this.checkpointMetrics.noteCheckpointBlockBuilt(this.dateProvider.now(), {
|
|
1057
|
+
isFirstBlock: blocksBuilt === 0,
|
|
1058
|
+
isLastBlock: timingInfo.isLastBlock
|
|
837
1059
|
});
|
|
838
|
-
|
|
1060
|
+
blocksInCheckpoint.push(block);
|
|
1061
|
+
usedTxs.forEach((tx)=>txHashesAlreadyIncluded.add(tx.txHash.toString()));
|
|
1062
|
+
// Sign the block proposal. This will throw if HA signing fails.
|
|
1063
|
+
const proposal = await this.createBlockProposal(block, inHash, usedTxs, blockProposalOptions);
|
|
1064
|
+
// Sync the proposed block to the archiver to make it available, only after we've managed to sign the proposal,
|
|
1065
|
+
// so we avoid polluting our archive with a block that would fail.
|
|
1066
|
+
// We wait for the sync to succeed, as this helps catch consistency errors, even if it means we lose some time for block-building.
|
|
1067
|
+
// If this throws, we abort the entire checkpoint.
|
|
1068
|
+
await this.syncProposedBlockToArchiver(block);
|
|
1069
|
+
// If this is the last block, do not broadcast it, since it will be included in the checkpoint proposal.
|
|
839
1070
|
if (timingInfo.isLastBlock) {
|
|
840
|
-
this.log.verbose(`Completed final block ${blockNumber} for slot ${this.
|
|
841
|
-
slot: this.
|
|
1071
|
+
this.log.verbose(`Completed final block ${blockNumber} for slot ${this.targetSlot}`, {
|
|
1072
|
+
slot: this.targetSlot,
|
|
842
1073
|
blockNumber,
|
|
843
1074
|
blocksBuilt
|
|
844
1075
|
});
|
|
845
|
-
blockPendingBroadcast =
|
|
846
|
-
block,
|
|
847
|
-
txs: usedTxs
|
|
848
|
-
};
|
|
1076
|
+
blockPendingBroadcast = proposal;
|
|
849
1077
|
break;
|
|
850
1078
|
}
|
|
851
|
-
//
|
|
852
|
-
|
|
853
|
-
if (!this.config.fishermanMode) {
|
|
854
|
-
const proposal = await this.validatorClient.createBlockProposal(block.header, block.indexWithinCheckpoint, inHash, block.archive.root, usedTxs, this.proposer, blockProposalOptions);
|
|
855
|
-
await this.p2pClient.broadcastProposal(proposal);
|
|
856
|
-
}
|
|
1079
|
+
// Once we have a signed proposal and the archiver agreed with our proposed block, then we broadcast it.
|
|
1080
|
+
proposal && await this.p2pClient.broadcastProposal(proposal);
|
|
857
1081
|
// Wait until the next block's start time
|
|
858
1082
|
await this.waitUntilNextSubslot(timingInfo.deadline);
|
|
859
1083
|
}
|
|
860
|
-
this.log.verbose(`Block building loop completed for slot ${this.
|
|
861
|
-
slot: this.
|
|
1084
|
+
this.log.verbose(`Block building loop completed for slot ${this.targetSlot}`, {
|
|
1085
|
+
slot: this.targetSlot,
|
|
862
1086
|
blocksBuilt: blocksInCheckpoint.length
|
|
863
1087
|
});
|
|
864
1088
|
return {
|
|
@@ -866,115 +1090,127 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
866
1090
|
blockPendingBroadcast
|
|
867
1091
|
};
|
|
868
1092
|
}
|
|
1093
|
+
/** Creates a block proposal for a given block via the validator client (unless in fisherman mode) */ createBlockProposal(block, inHash, usedTxs, blockProposalOptions) {
|
|
1094
|
+
if (this.config.fishermanMode) {
|
|
1095
|
+
this.log.info(`Skipping block proposal for block ${block.number} in fisherman mode`);
|
|
1096
|
+
return Promise.resolve(undefined);
|
|
1097
|
+
}
|
|
1098
|
+
return this.validatorClient.createBlockProposal(block.header, this.checkpointNumber, block.indexWithinCheckpoint, inHash, block.archive.root, usedTxs, this.proposer, blockProposalOptions);
|
|
1099
|
+
}
|
|
869
1100
|
/** Sleeps until it is time to produce the next block in the slot */ async waitUntilNextSubslot(nextSubslotStart) {
|
|
870
|
-
this.setStateFn(SequencerState.WAITING_UNTIL_NEXT_BLOCK, this.
|
|
1101
|
+
this.setStateFn(SequencerState.WAITING_UNTIL_NEXT_BLOCK, this.targetSlot);
|
|
871
1102
|
this.log.verbose(`Waiting until time for the next block at ${nextSubslotStart}s into slot`, {
|
|
872
|
-
slot: this.
|
|
1103
|
+
slot: this.targetSlot
|
|
873
1104
|
});
|
|
874
1105
|
await this.waitUntilTimeInSlot(nextSubslotStart);
|
|
875
1106
|
}
|
|
876
1107
|
/** Builds a single block. Called from the main block building loop. */ async buildSingleBlock(checkpointBuilder, opts) {
|
|
877
|
-
const { blockTimestamp, forceCreate, blockNumber, indexWithinCheckpoint, buildDeadline, txHashesAlreadyIncluded
|
|
878
|
-
this.log.verbose(`Preparing block ${blockNumber} index ${indexWithinCheckpoint} at checkpoint ${this.checkpointNumber} for slot ${this.
|
|
1108
|
+
const { blockTimestamp, forceCreate, blockNumber, indexWithinCheckpoint, buildDeadline, txHashesAlreadyIncluded } = opts;
|
|
1109
|
+
this.log.verbose(`Preparing block ${blockNumber} index ${indexWithinCheckpoint} at checkpoint ${this.checkpointNumber} for slot ${this.targetSlot}`, {
|
|
879
1110
|
...checkpointBuilder.getConstantData(),
|
|
880
1111
|
...opts
|
|
881
1112
|
});
|
|
882
1113
|
try {
|
|
883
1114
|
// Wait until we have enough txs to build the block
|
|
884
|
-
const minTxs = this.
|
|
885
|
-
const { availableTxs, canStartBuilding } = await this.waitForMinTxs(opts);
|
|
1115
|
+
const { availableTxs, canStartBuilding, minTxs } = await this.waitForMinTxs(opts);
|
|
886
1116
|
if (!canStartBuilding) {
|
|
887
|
-
this.log.warn(`Not enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.
|
|
1117
|
+
this.log.warn(`Not enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.targetSlot} (got ${availableTxs} txs but needs ${minTxs})`, {
|
|
888
1118
|
blockNumber,
|
|
889
|
-
slot: this.
|
|
1119
|
+
slot: this.targetSlot,
|
|
890
1120
|
indexWithinCheckpoint
|
|
891
1121
|
});
|
|
892
1122
|
this.eventEmitter.emit('block-tx-count-check-failed', {
|
|
893
1123
|
minTxs,
|
|
894
1124
|
availableTxs,
|
|
895
|
-
slot: this.
|
|
1125
|
+
slot: this.targetSlot
|
|
896
1126
|
});
|
|
897
1127
|
this.metrics.recordBlockProposalFailed('insufficient_txs');
|
|
898
|
-
return
|
|
1128
|
+
return {
|
|
1129
|
+
failure: 'insufficient-txs'
|
|
1130
|
+
};
|
|
899
1131
|
}
|
|
900
1132
|
// Create iterator to pending txs. We filter out txs already included in previous blocks in the checkpoint
|
|
901
1133
|
// just in case p2p failed to sync the provisional block and didn't get to remove those txs from the mempool yet.
|
|
902
|
-
const pendingTxs = filter(this.p2pClient.
|
|
903
|
-
this.log.debug(`Building block ${blockNumber} at index ${indexWithinCheckpoint} for slot ${this.
|
|
904
|
-
slot: this.
|
|
1134
|
+
const pendingTxs = filter(this.p2pClient.iterateEligiblePendingTxs(), (tx)=>!txHashesAlreadyIncluded.has(tx.txHash.toString()));
|
|
1135
|
+
this.log.debug(`Building block ${blockNumber} at index ${indexWithinCheckpoint} for slot ${this.targetSlot} with ${availableTxs} available txs`, {
|
|
1136
|
+
slot: this.targetSlot,
|
|
905
1137
|
blockNumber,
|
|
906
1138
|
indexWithinCheckpoint
|
|
907
1139
|
});
|
|
908
|
-
this.setStateFn(SequencerState.CREATING_BLOCK, this.
|
|
909
|
-
//
|
|
910
|
-
|
|
911
|
-
|
|
1140
|
+
this.setStateFn(SequencerState.CREATING_BLOCK, this.targetSlot);
|
|
1141
|
+
// Per-block limits are operator overrides (from SEQ_MAX_L2_BLOCK_GAS etc.) further capped
|
|
1142
|
+
// by remaining checkpoint-level budgets inside CheckpointBuilder before each block is built.
|
|
1143
|
+
// minValidTxs is passed into the builder so it can reject the block *before* updating state.
|
|
1144
|
+
const minValidTxs = forceCreate ? 0 : this.config.minValidTxsPerBlock ?? minTxs;
|
|
912
1145
|
const blockBuilderOptions = {
|
|
913
1146
|
maxTransactions: this.config.maxTxsPerBlock,
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
1147
|
+
maxBlockGas: this.config.maxL2BlockGas !== undefined || this.config.maxDABlockGas !== undefined ? new Gas(this.config.maxDABlockGas ?? Infinity, this.config.maxL2BlockGas ?? Infinity) : undefined,
|
|
1148
|
+
deadline: buildDeadline,
|
|
1149
|
+
isBuildingProposal: true,
|
|
1150
|
+
minValidTxs,
|
|
1151
|
+
maxBlocksPerCheckpoint: this.timetable.maxNumberOfBlocks,
|
|
1152
|
+
perBlockAllocationMultiplier: this.config.perBlockAllocationMultiplier
|
|
918
1153
|
};
|
|
919
|
-
// Actually build the block by executing txs
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
const
|
|
1154
|
+
// Actually build the block by executing txs. The builder throws InsufficientValidTxsError
|
|
1155
|
+
// if the number of successfully processed txs is below minValidTxs, ensuring state is not
|
|
1156
|
+
// updated for blocks that will be discarded.
|
|
1157
|
+
const buildResult = await this.buildSingleBlockWithCheckpointBuilder(checkpointBuilder, pendingTxs, blockNumber, blockTimestamp, blockBuilderOptions);
|
|
923
1158
|
// If any txs failed during execution, drop them from the mempool so we don't pick them up again
|
|
924
|
-
await this.dropFailedTxsFromP2P(failedTxs);
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
if (!forceCreate && numTxs < minValidTxs) {
|
|
929
|
-
this.log.warn(`Block ${blockNumber} at index ${indexWithinCheckpoint} on slot ${this.slot} has too few valid txs to be proposed (got ${numTxs} but required ${minValidTxs})`, {
|
|
930
|
-
slot: this.slot,
|
|
1159
|
+
await this.dropFailedTxsFromP2P(buildResult.failedTxs);
|
|
1160
|
+
if (buildResult.status === 'insufficient-valid-txs') {
|
|
1161
|
+
this.log.warn(`Block ${blockNumber} at index ${indexWithinCheckpoint} on slot ${this.targetSlot} has too few valid txs to be proposed`, {
|
|
1162
|
+
slot: this.targetSlot,
|
|
931
1163
|
blockNumber,
|
|
932
|
-
numTxs,
|
|
933
|
-
indexWithinCheckpoint
|
|
1164
|
+
numTxs: buildResult.processedCount,
|
|
1165
|
+
indexWithinCheckpoint,
|
|
1166
|
+
minValidTxs
|
|
934
1167
|
});
|
|
935
|
-
this.eventEmitter.emit('block-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
slot: this.slot
|
|
1168
|
+
this.eventEmitter.emit('block-build-failed', {
|
|
1169
|
+
reason: `Insufficient valid txs`,
|
|
1170
|
+
slot: this.targetSlot
|
|
939
1171
|
});
|
|
940
1172
|
this.metrics.recordBlockProposalFailed('insufficient_valid_txs');
|
|
941
|
-
return
|
|
1173
|
+
return {
|
|
1174
|
+
failure: 'insufficient-valid-txs'
|
|
1175
|
+
};
|
|
942
1176
|
}
|
|
943
1177
|
// Block creation succeeded, emit stats and metrics
|
|
1178
|
+
const { block, publicProcessorDuration, usedTxs, blockBuildDuration, numTxs } = buildResult;
|
|
944
1179
|
const blockStats = {
|
|
945
1180
|
eventName: 'l2-block-built',
|
|
946
1181
|
duration: blockBuildDuration,
|
|
947
1182
|
publicProcessDuration: publicProcessorDuration,
|
|
948
|
-
rollupCircuitsDuration: blockBuildingTimer.ms(),
|
|
949
1183
|
...block.getStats()
|
|
950
1184
|
};
|
|
951
1185
|
const blockHash = await block.hash();
|
|
952
1186
|
const txHashes = block.body.txEffects.map((tx)=>tx.txHash);
|
|
953
|
-
const manaPerSec =
|
|
954
|
-
this.log.info(`Built block ${block.number} at checkpoint ${this.checkpointNumber} for slot ${this.
|
|
1187
|
+
const manaPerSec = block.header.totalManaUsed.toNumberUnsafe() / (blockBuildDuration / 1000);
|
|
1188
|
+
this.log.info(`Built block ${block.number} at checkpoint ${this.checkpointNumber} for slot ${this.targetSlot} with ${numTxs} txs`, {
|
|
955
1189
|
blockHash,
|
|
956
1190
|
txHashes,
|
|
957
1191
|
manaPerSec,
|
|
958
1192
|
...blockStats
|
|
959
1193
|
});
|
|
1194
|
+
// `slot` is the target/submission slot (may be one ahead when pipelining),
|
|
1195
|
+
// `buildSlot` is the wall-clock slot during which the block was actually built.
|
|
960
1196
|
this.eventEmitter.emit('block-proposed', {
|
|
961
1197
|
blockNumber: block.number,
|
|
962
|
-
slot: this.
|
|
1198
|
+
slot: this.targetSlot,
|
|
1199
|
+
buildSlot: this.slotNow
|
|
963
1200
|
});
|
|
964
|
-
this.metrics.recordBuiltBlock(blockBuildDuration,
|
|
1201
|
+
this.metrics.recordBuiltBlock(blockBuildDuration, block.header.totalManaUsed.toNumberUnsafe(), this.targetSlot);
|
|
965
1202
|
return {
|
|
966
1203
|
block,
|
|
967
|
-
usedTxs
|
|
968
|
-
remainingBlobFields: maxBlobFieldsForTxs - usedTxBlobFields
|
|
1204
|
+
usedTxs
|
|
969
1205
|
};
|
|
970
1206
|
} catch (err) {
|
|
971
1207
|
this.eventEmitter.emit('block-build-failed', {
|
|
972
1208
|
reason: err.message,
|
|
973
|
-
slot: this.
|
|
1209
|
+
slot: this.targetSlot
|
|
974
1210
|
});
|
|
975
1211
|
this.log.error(`Error building block`, err, {
|
|
976
1212
|
blockNumber,
|
|
977
|
-
slot: this.
|
|
1213
|
+
slot: this.targetSlot
|
|
978
1214
|
});
|
|
979
1215
|
this.metrics.recordBlockProposalFailed(err.name || 'unknown_error');
|
|
980
1216
|
this.metrics.recordFailedBlock();
|
|
@@ -983,9 +1219,31 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
983
1219
|
};
|
|
984
1220
|
}
|
|
985
1221
|
}
|
|
1222
|
+
/** Uses the checkpoint builder to build a block, catching InsufficientValidTxsError. */ async buildSingleBlockWithCheckpointBuilder(checkpointBuilder, pendingTxs, blockNumber, blockTimestamp, blockBuilderOptions) {
|
|
1223
|
+
try {
|
|
1224
|
+
const workTimer = new Timer();
|
|
1225
|
+
const result = await checkpointBuilder.buildBlock(pendingTxs, blockNumber, blockTimestamp, blockBuilderOptions);
|
|
1226
|
+
const blockBuildDuration = workTimer.ms();
|
|
1227
|
+
return {
|
|
1228
|
+
...result,
|
|
1229
|
+
blockBuildDuration,
|
|
1230
|
+
status: 'success'
|
|
1231
|
+
};
|
|
1232
|
+
} catch (err) {
|
|
1233
|
+
if (isErrorClass(err, InsufficientValidTxsError)) {
|
|
1234
|
+
return {
|
|
1235
|
+
failedTxs: err.failedTxs,
|
|
1236
|
+
processedCount: err.processedCount,
|
|
1237
|
+
status: 'insufficient-valid-txs'
|
|
1238
|
+
};
|
|
1239
|
+
}
|
|
1240
|
+
throw err;
|
|
1241
|
+
}
|
|
1242
|
+
}
|
|
986
1243
|
/** Waits until minTxs are available on the pool for building a block. */ async waitForMinTxs(opts) {
|
|
987
|
-
const minTxs = this.config.minTxsPerBlock;
|
|
988
1244
|
const { indexWithinCheckpoint, blockNumber, buildDeadline, forceCreate } = opts;
|
|
1245
|
+
// We only allow a block with 0 txs in the first block of the checkpoint
|
|
1246
|
+
const minTxs = indexWithinCheckpoint > 0 && this.config.minTxsPerBlock === 0 ? 1 : this.config.minTxsPerBlock;
|
|
989
1247
|
// Deadline is undefined if we are not enforcing the timetable, meaning we'll exit immediately when out of time
|
|
990
1248
|
const startBuildingDeadline = buildDeadline ? new Date(buildDeadline.getTime() - this.timetable.minExecutionTime * 1000) : undefined;
|
|
991
1249
|
let availableTxs = await this.p2pClient.getPendingTxCount();
|
|
@@ -995,24 +1253,50 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
995
1253
|
if (startBuildingDeadline === undefined || now >= startBuildingDeadline) {
|
|
996
1254
|
return {
|
|
997
1255
|
canStartBuilding: false,
|
|
998
|
-
availableTxs
|
|
1256
|
+
availableTxs,
|
|
1257
|
+
minTxs
|
|
999
1258
|
};
|
|
1000
1259
|
}
|
|
1001
1260
|
// Wait a bit before checking again
|
|
1002
|
-
this.setStateFn(SequencerState.WAITING_FOR_TXS, this.
|
|
1003
|
-
this.log.verbose(`Waiting for enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.
|
|
1261
|
+
this.setStateFn(SequencerState.WAITING_FOR_TXS, this.targetSlot);
|
|
1262
|
+
this.log.verbose(`Waiting for enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.targetSlot} (have ${availableTxs} but need ${minTxs})`, {
|
|
1004
1263
|
blockNumber,
|
|
1005
|
-
slot: this.
|
|
1264
|
+
slot: this.targetSlot,
|
|
1006
1265
|
indexWithinCheckpoint
|
|
1007
1266
|
});
|
|
1008
|
-
await
|
|
1267
|
+
await this.waitForTxsPollingInterval();
|
|
1009
1268
|
availableTxs = await this.p2pClient.getPendingTxCount();
|
|
1010
1269
|
}
|
|
1011
1270
|
return {
|
|
1012
1271
|
canStartBuilding: true,
|
|
1013
|
-
availableTxs
|
|
1272
|
+
availableTxs,
|
|
1273
|
+
minTxs
|
|
1014
1274
|
};
|
|
1015
1275
|
}
|
|
1276
|
+
async getSignedCommitteeAttestations(broadcast) {
|
|
1277
|
+
const { proposal, blockProposedAt } = broadcast;
|
|
1278
|
+
this.setStateFn(SequencerState.COLLECTING_ATTESTATIONS, this.targetSlot);
|
|
1279
|
+
const attestations = await this.waitForAttestations(proposal);
|
|
1280
|
+
if (!attestations) {
|
|
1281
|
+
return undefined;
|
|
1282
|
+
}
|
|
1283
|
+
this.checkpointMetrics.recordCheckpointAttestationDelay(this.dateProvider.now() - blockProposedAt);
|
|
1284
|
+
// Proposer must sign over the attestations before pushing them to L1
|
|
1285
|
+
const signer = this.proposer ?? this.publisher.getSenderAddress();
|
|
1286
|
+
try {
|
|
1287
|
+
const attestationsSignature = await this.validatorClient.signAttestationsAndSigners(attestations, signer, this.targetSlot, this.checkpointNumber);
|
|
1288
|
+
return {
|
|
1289
|
+
attestations,
|
|
1290
|
+
attestationsSignature
|
|
1291
|
+
};
|
|
1292
|
+
} catch (err) {
|
|
1293
|
+
if (this.handleHASigningError(err, 'Attestations signature')) {
|
|
1294
|
+
return;
|
|
1295
|
+
}
|
|
1296
|
+
this.log.error(`Error signing attestations for checkpoint proposal at slot ${proposal.slotNumber}`, err);
|
|
1297
|
+
return undefined;
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1016
1300
|
/**
|
|
1017
1301
|
* Waits for enough attestations to be collected via p2p.
|
|
1018
1302
|
* This is run after all blocks for the checkpoint have been built.
|
|
@@ -1033,32 +1317,41 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
1033
1317
|
committee
|
|
1034
1318
|
});
|
|
1035
1319
|
}
|
|
1036
|
-
const numberOfRequiredAttestations =
|
|
1320
|
+
const numberOfRequiredAttestations = computeQuorum(committee.length);
|
|
1037
1321
|
if (this.config.skipCollectingAttestations) {
|
|
1038
1322
|
this.log.warn('Skipping attestation collection as per config (attesting with own keys only)');
|
|
1039
|
-
const attestations = await this.validatorClient?.collectOwnAttestations(proposal);
|
|
1323
|
+
const attestations = await this.validatorClient?.collectOwnAttestations(proposal, this.checkpointNumber);
|
|
1040
1324
|
return new CommitteeAttestationsAndSigners(orderAttestations(attestations ?? [], committee));
|
|
1041
1325
|
}
|
|
1042
|
-
const attestationTimeAllowed = this.config.enforceTimeTable ? this.timetable.
|
|
1043
|
-
const attestationDeadline = new Date(this.
|
|
1326
|
+
const attestationTimeAllowed = this.config.enforceTimeTable ? this.timetable.getCheckpointAttestationDeadline() : this.l1Constants.slotDuration;
|
|
1327
|
+
const attestationDeadline = new Date((this.getSlotStartBuildTimestamp() + attestationTimeAllowed) * 1000);
|
|
1044
1328
|
this.metrics.recordRequiredAttestations(numberOfRequiredAttestations, attestationTimeAllowed);
|
|
1045
1329
|
const collectAttestationsTimer = new Timer();
|
|
1046
1330
|
let collectedAttestationsCount = 0;
|
|
1047
1331
|
try {
|
|
1048
|
-
const attestations = await this.validatorClient.collectAttestations(proposal, numberOfRequiredAttestations, attestationDeadline);
|
|
1332
|
+
const attestations = await this.validatorClient.collectAttestations(proposal, numberOfRequiredAttestations, attestationDeadline, this.checkpointNumber);
|
|
1049
1333
|
collectedAttestationsCount = attestations.length;
|
|
1334
|
+
// Trim attestations to minimum required to save L1 calldata gas
|
|
1335
|
+
const localAddresses = this.validatorClient.getValidatorAddresses();
|
|
1336
|
+
const trimmed = trimAttestations(attestations, numberOfRequiredAttestations, this.attestorAddress, localAddresses);
|
|
1337
|
+
if (trimmed.length < attestations.length) {
|
|
1338
|
+
this.log.debug(`Trimmed attestations from ${attestations.length} to ${trimmed.length} for L1 submission`);
|
|
1339
|
+
}
|
|
1050
1340
|
// Rollup contract requires that the signatures are provided in the order of the committee
|
|
1051
|
-
const sorted = orderAttestations(
|
|
1341
|
+
const sorted = orderAttestations(trimmed, committee);
|
|
1052
1342
|
// Manipulate the attestations if we've been configured to do so
|
|
1053
|
-
if (this.config.injectFakeAttestation || this.config.shuffleAttestationOrdering) {
|
|
1343
|
+
if (this.config.injectFakeAttestation || this.config.injectHighSValueAttestation || this.config.injectUnrecoverableSignatureAttestation || this.config.shuffleAttestationOrdering) {
|
|
1054
1344
|
return this.manipulateAttestations(proposal.slotNumber, epoch, seed, committee, sorted);
|
|
1055
1345
|
}
|
|
1056
1346
|
return new CommitteeAttestationsAndSigners(sorted);
|
|
1057
1347
|
} catch (err) {
|
|
1058
1348
|
if (err && err instanceof AttestationTimeoutError) {
|
|
1059
1349
|
collectedAttestationsCount = err.collectedCount;
|
|
1350
|
+
this.log.error(`Timeout while waiting for attestations for checkpoint proposal at slot ${proposal.slotNumber} (collected ${collectedAttestationsCount}/${numberOfRequiredAttestations})`, err);
|
|
1351
|
+
} else {
|
|
1352
|
+
this.log.error(`Error collecting attestations for checkpoint proposal at slot ${proposal.slotNumber}`, err);
|
|
1060
1353
|
}
|
|
1061
|
-
|
|
1354
|
+
return undefined;
|
|
1062
1355
|
} finally{
|
|
1063
1356
|
this.metrics.recordCollectedAttestations(collectedAttestationsCount, collectAttestationsTimer.ms());
|
|
1064
1357
|
}
|
|
@@ -1067,7 +1360,7 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
1067
1360
|
// Compute the proposer index in the committee, since we dont want to tweak it.
|
|
1068
1361
|
// Otherwise, the L1 rollup contract will reject the block outright.
|
|
1069
1362
|
const proposerIndex = Number(this.epochCache.computeProposerIndex(slotNumber, epoch, seed, BigInt(committee.length)));
|
|
1070
|
-
if (this.config.injectFakeAttestation) {
|
|
1363
|
+
if (this.config.injectFakeAttestation || this.config.injectHighSValueAttestation || this.config.injectUnrecoverableSignatureAttestation) {
|
|
1071
1364
|
// Find non-empty attestations that are not from the proposer
|
|
1072
1365
|
const nonProposerIndices = [];
|
|
1073
1366
|
for(let i = 0; i < attestations.length; i++){
|
|
@@ -1077,8 +1370,16 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
1077
1370
|
}
|
|
1078
1371
|
if (nonProposerIndices.length > 0) {
|
|
1079
1372
|
const targetIndex = nonProposerIndices[randomInt(nonProposerIndices.length)];
|
|
1080
|
-
this.
|
|
1081
|
-
|
|
1373
|
+
if (this.config.injectHighSValueAttestation) {
|
|
1374
|
+
this.log.warn(`Injecting high-s value attestation in checkpoint for slot ${slotNumber} at index ${targetIndex}`);
|
|
1375
|
+
unfreeze(attestations[targetIndex]).signature = flipSignature(attestations[targetIndex].signature);
|
|
1376
|
+
} else if (this.config.injectUnrecoverableSignatureAttestation) {
|
|
1377
|
+
this.log.warn(`Injecting unrecoverable signature attestation in checkpoint for slot ${slotNumber} at index ${targetIndex}`);
|
|
1378
|
+
unfreeze(attestations[targetIndex]).signature = generateUnrecoverableSignature();
|
|
1379
|
+
} else {
|
|
1380
|
+
this.log.warn(`Injecting fake attestation in checkpoint for slot ${slotNumber} at index ${targetIndex}`);
|
|
1381
|
+
unfreeze(attestations[targetIndex]).signature = generateRecoverableSignature();
|
|
1382
|
+
}
|
|
1082
1383
|
}
|
|
1083
1384
|
return new CommitteeAttestationsAndSigners(attestations);
|
|
1084
1385
|
}
|
|
@@ -1087,14 +1388,25 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
1087
1388
|
const shuffled = [
|
|
1088
1389
|
...attestations
|
|
1089
1390
|
];
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
];
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1391
|
+
// Find two non-proposer positions that both have non-empty signatures to swap.
|
|
1392
|
+
// This ensures the bitmap doesn't change, so the MaliciousCommitteeAttestationsAndSigners
|
|
1393
|
+
// signers array stays correctly aligned with L1's committee reconstruction.
|
|
1394
|
+
const swappable = [];
|
|
1395
|
+
for(let k = 0; k < shuffled.length; k++){
|
|
1396
|
+
if (!shuffled[k].signature.isEmpty() && k !== proposerIndex) {
|
|
1397
|
+
swappable.push(k);
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
if (swappable.length >= 2) {
|
|
1401
|
+
const [i, j] = [
|
|
1402
|
+
swappable[0],
|
|
1403
|
+
swappable[1]
|
|
1404
|
+
];
|
|
1405
|
+
[shuffled[i], shuffled[j]] = [
|
|
1406
|
+
shuffled[j],
|
|
1407
|
+
shuffled[i]
|
|
1408
|
+
];
|
|
1409
|
+
}
|
|
1098
1410
|
const signers = new CommitteeAttestationsAndSigners(attestations).getSigners();
|
|
1099
1411
|
return new MaliciousCommitteeAttestationsAndSigners(shuffled, signers);
|
|
1100
1412
|
}
|
|
@@ -1107,14 +1419,18 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
1107
1419
|
const failedTxData = failedTxs.map((fail)=>fail.tx);
|
|
1108
1420
|
const failedTxHashes = failedTxData.map((tx)=>tx.getTxHash());
|
|
1109
1421
|
this.log.verbose(`Dropping failed txs ${failedTxHashes.join(', ')}`);
|
|
1110
|
-
await this.p2pClient.
|
|
1422
|
+
await this.p2pClient.handleFailedExecution(failedTxHashes);
|
|
1111
1423
|
}
|
|
1112
1424
|
/**
|
|
1113
1425
|
* Adds the proposed block to the archiver so it's available via P2P.
|
|
1114
1426
|
* Gossip doesn't echo messages back to the sender, so the proposer's archiver/world-state
|
|
1115
1427
|
* would never receive its own block without this explicit sync.
|
|
1428
|
+
*
|
|
1429
|
+
* In fisherman mode we skip this push: the fisherman builds blocks locally for validation
|
|
1430
|
+
* and fee analysis only, and pushing them to the archiver causes spurious reorg cascades
|
|
1431
|
+
* whenever the real proposer's block arrives from L1.
|
|
1116
1432
|
*/ async syncProposedBlockToArchiver(block) {
|
|
1117
|
-
if (this.config.skipPushProposedBlocksToArchiver
|
|
1433
|
+
if (this.config.skipPushProposedBlocksToArchiver || this.config.fishermanMode) {
|
|
1118
1434
|
this.log.warn(`Skipping push of proposed block ${block.number} to archiver`, {
|
|
1119
1435
|
blockNumber: block.number,
|
|
1120
1436
|
slot: block.header.globalVariables.slotNumber
|
|
@@ -1130,29 +1446,52 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
1130
1446
|
/** Runs fee analysis and logs checkpoint outcome as fisherman */ async handleCheckpointEndAsFisherman(checkpoint) {
|
|
1131
1447
|
// Perform L1 fee analysis before clearing requests
|
|
1132
1448
|
// The callback is invoked asynchronously after the next block is mined
|
|
1133
|
-
const feeAnalysis = await this.publisher.analyzeL1Fees(this.
|
|
1449
|
+
const feeAnalysis = await this.publisher.analyzeL1Fees(this.targetSlot, (analysis)=>this.metrics.recordFishermanFeeAnalysis(analysis));
|
|
1134
1450
|
if (checkpoint) {
|
|
1135
|
-
this.log.info(`Validation checkpoint building SUCCEEDED for slot ${this.
|
|
1451
|
+
this.log.info(`Validation checkpoint building SUCCEEDED for slot ${this.targetSlot}`, {
|
|
1136
1452
|
...checkpoint.toCheckpointInfo(),
|
|
1137
1453
|
...checkpoint.getStats(),
|
|
1138
1454
|
feeAnalysisId: feeAnalysis?.id
|
|
1139
1455
|
});
|
|
1140
1456
|
} else {
|
|
1141
|
-
this.log.warn(`Validation block building FAILED for slot ${this.
|
|
1142
|
-
slot: this.
|
|
1457
|
+
this.log.warn(`Validation block building FAILED for slot ${this.targetSlot}`, {
|
|
1458
|
+
slot: this.targetSlot,
|
|
1143
1459
|
feeAnalysisId: feeAnalysis?.id
|
|
1144
1460
|
});
|
|
1145
|
-
this.metrics.
|
|
1461
|
+
this.metrics.recordCheckpointProposalFailed('block_build_failed');
|
|
1146
1462
|
}
|
|
1147
1463
|
this.publisher.clearPendingRequests();
|
|
1148
1464
|
}
|
|
1465
|
+
/**
|
|
1466
|
+
* Helper to handle HA double-signing errors. Returns true if the error was handled (caller should yield).
|
|
1467
|
+
*/ handleHASigningError(err, errorContext) {
|
|
1468
|
+
if (err instanceof DutyAlreadySignedError) {
|
|
1469
|
+
this.log.info(`${errorContext} for slot ${this.targetSlot} already signed by another HA node, yielding`, {
|
|
1470
|
+
slot: this.targetSlot,
|
|
1471
|
+
signedByNode: err.signedByNode
|
|
1472
|
+
});
|
|
1473
|
+
return true;
|
|
1474
|
+
}
|
|
1475
|
+
if (err instanceof SlashingProtectionError) {
|
|
1476
|
+
this.log.info(`${errorContext} for slot ${this.targetSlot} blocked by slashing protection, yielding`, {
|
|
1477
|
+
slot: this.targetSlot,
|
|
1478
|
+
existingMessageHash: err.existingMessageHash,
|
|
1479
|
+
attemptedMessageHash: err.attemptedMessageHash
|
|
1480
|
+
});
|
|
1481
|
+
return true;
|
|
1482
|
+
}
|
|
1483
|
+
return false;
|
|
1484
|
+
}
|
|
1149
1485
|
/** Waits until a specific time within the current slot */ async waitUntilTimeInSlot(targetSecondsIntoSlot) {
|
|
1150
1486
|
const slotStartTimestamp = this.getSlotStartBuildTimestamp();
|
|
1151
1487
|
const targetTimestamp = slotStartTimestamp + targetSecondsIntoSlot;
|
|
1152
1488
|
await sleepUntil(new Date(targetTimestamp * 1000), this.dateProvider.nowAsDate());
|
|
1153
1489
|
}
|
|
1490
|
+
/** Waits the polling interval for transactions. Extracted for test overriding. */ async waitForTxsPollingInterval() {
|
|
1491
|
+
await sleep(TXS_POLLING_MS);
|
|
1492
|
+
}
|
|
1154
1493
|
getSlotStartBuildTimestamp() {
|
|
1155
|
-
return getSlotStartBuildTimestamp(this.
|
|
1494
|
+
return getSlotStartBuildTimestamp(this.slotNow, this.l1Constants);
|
|
1156
1495
|
}
|
|
1157
1496
|
getSecondsIntoSlot() {
|
|
1158
1497
|
const slotStartTimestamp = this.getSlotStartBuildTimestamp();
|