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