@aztec/sequencer-client 0.0.1-commit.b2a5d0dd1 → 0.0.1-commit.b3d3157a
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +281 -21
- package/dest/client/sequencer-client.d.ts +3 -3
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +6 -6
- package/dest/config.d.ts +6 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +33 -10
- package/dest/global_variable_builder/fee_provider.js +1 -1
- package/dest/global_variable_builder/global_builder.d.ts +2 -3
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +1 -1
- package/dest/index.d.ts +2 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -1
- package/dest/publisher/config.d.ts +3 -3
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/sequencer-bundle-simulator.d.ts +96 -0
- package/dest/publisher/sequencer-bundle-simulator.d.ts.map +1 -0
- package/dest/publisher/sequencer-bundle-simulator.js +198 -0
- package/dest/publisher/sequencer-publisher.d.ts +36 -36
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +271 -500
- package/dest/sequencer/automine/automine_factory.d.ts +54 -0
- package/dest/sequencer/automine/automine_factory.d.ts.map +1 -0
- package/dest/sequencer/automine/automine_factory.js +84 -0
- package/dest/sequencer/automine/automine_sequencer.d.ts +151 -0
- package/dest/sequencer/automine/automine_sequencer.d.ts.map +1 -0
- package/dest/sequencer/automine/automine_sequencer.js +509 -0
- package/dest/sequencer/chain_state_overrides.d.ts +52 -16
- package/dest/sequencer/chain_state_overrides.d.ts.map +1 -1
- package/dest/sequencer/chain_state_overrides.js +86 -27
- package/dest/sequencer/checkpoint_proposal_job.d.ts +24 -6
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_proposal_job.js +373 -83
- package/dest/sequencer/events.d.ts +42 -2
- package/dest/sequencer/events.d.ts.map +1 -1
- package/dest/sequencer/index.d.ts +3 -1
- package/dest/sequencer/index.d.ts.map +1 -1
- package/dest/sequencer/index.js +2 -0
- package/dest/sequencer/metrics.d.ts +3 -1
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +7 -0
- package/dest/sequencer/sequencer.d.ts +44 -9
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +256 -79
- package/dest/sequencer/timetable.d.ts +3 -6
- package/dest/sequencer/timetable.d.ts.map +1 -1
- package/dest/sequencer/timetable.js +3 -7
- package/dest/sequencer/types.d.ts +2 -2
- package/dest/sequencer/types.d.ts.map +1 -1
- package/dest/test/utils.d.ts +1 -1
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +7 -6
- package/package.json +27 -27
- package/src/client/sequencer-client.ts +12 -7
- package/src/config.ts +38 -10
- package/src/global_variable_builder/fee_provider.ts +1 -1
- package/src/global_variable_builder/global_builder.ts +2 -3
- package/src/index.ts +10 -1
- package/src/publisher/config.ts +2 -2
- package/src/publisher/sequencer-bundle-simulator.ts +254 -0
- package/src/publisher/sequencer-publisher.ts +286 -521
- package/src/sequencer/README.md +162 -520
- package/src/sequencer/automine/README.md +46 -0
- package/src/sequencer/automine/automine_factory.ts +145 -0
- package/src/sequencer/automine/automine_sequencer.ts +595 -0
- package/src/sequencer/chain_state_overrides.ts +133 -58
- package/src/sequencer/checkpoint_proposal_job.ts +420 -100
- package/src/sequencer/events.ts +46 -2
- package/src/sequencer/index.ts +2 -0
- package/src/sequencer/metrics.ts +9 -0
- package/src/sequencer/sequencer.ts +284 -95
- package/src/sequencer/timetable.ts +2 -9
- package/src/sequencer/types.ts +1 -1
- package/src/test/utils.ts +28 -10
|
@@ -439,14 +439,14 @@ var _dec, _dec1, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _initProto;
|
|
|
439
439
|
import { BlockNumber, CheckpointNumber, IndexWithinCheckpoint } from '@aztec/foundation/branded-types';
|
|
440
440
|
import { randomInt } from '@aztec/foundation/crypto/random';
|
|
441
441
|
import { flipSignature, generateRecoverableSignature, generateUnrecoverableSignature } from '@aztec/foundation/crypto/secp256k1-signer';
|
|
442
|
+
import { InterruptError, TimeoutError } from '@aztec/foundation/error';
|
|
442
443
|
import { filter } from '@aztec/foundation/iterator';
|
|
443
444
|
import { createLogger } from '@aztec/foundation/log';
|
|
444
|
-
import {
|
|
445
|
-
import { sleep, sleepUntil } from '@aztec/foundation/sleep';
|
|
445
|
+
import { InterruptibleSleep } from '@aztec/foundation/sleep';
|
|
446
446
|
import { Timer } from '@aztec/foundation/timer';
|
|
447
447
|
import { isErrorClass, unfreeze } from '@aztec/foundation/types';
|
|
448
448
|
import { CommitteeAttestationsAndSigners, MaliciousCommitteeAttestationsAndSigners } from '@aztec/stdlib/block';
|
|
449
|
-
import { validateCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
449
|
+
import { getPreviousCheckpointOutHashes, validateCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
450
450
|
import { computeQuorum, getSlotStartBuildTimestamp, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
451
451
|
import { Gas } from '@aztec/stdlib/gas';
|
|
452
452
|
import { InsufficientValidTxsError } from '@aztec/stdlib/interfaces/server';
|
|
@@ -455,11 +455,12 @@ import { orderAttestations, trimAttestations } from '@aztec/stdlib/p2p';
|
|
|
455
455
|
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
456
456
|
import { Attributes, trackSpan } from '@aztec/telemetry-client';
|
|
457
457
|
import { DutyAlreadySignedError, SlashingProtectionError } from '@aztec/validator-ha-signer/errors';
|
|
458
|
-
import {
|
|
458
|
+
import { buildCheckpointSimulationOverridesPlan } from './chain_state_overrides.js';
|
|
459
459
|
import { CheckpointVoter } from './checkpoint_voter.js';
|
|
460
460
|
import { SequencerInterruptedError } from './errors.js';
|
|
461
461
|
import { SequencerState } from './utils.js';
|
|
462
462
|
/** How much time to sleep while waiting for min transactions to accumulate for a block */ const TXS_POLLING_MS = 500;
|
|
463
|
+
const ARCHIVER_SYNC_POLLING_MS = 200;
|
|
463
464
|
_dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('CheckpointProposalJob.proposeCheckpoint', function() {
|
|
464
465
|
return {
|
|
465
466
|
// nullish operator needed for tests
|
|
@@ -478,6 +479,7 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
478
479
|
targetEpoch;
|
|
479
480
|
checkpointNumber;
|
|
480
481
|
syncedToBlockNumber;
|
|
482
|
+
checkpointedCheckpointNumber;
|
|
481
483
|
proposer;
|
|
482
484
|
publisher;
|
|
483
485
|
attestorAddress;
|
|
@@ -491,6 +493,7 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
491
493
|
checkpointsBuilder;
|
|
492
494
|
blockSink;
|
|
493
495
|
l1Constants;
|
|
496
|
+
signatureContext;
|
|
494
497
|
config;
|
|
495
498
|
timetable;
|
|
496
499
|
slasherClient;
|
|
@@ -547,15 +550,27 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
547
550
|
], []));
|
|
548
551
|
}
|
|
549
552
|
log;
|
|
553
|
+
checkpointEventLog;
|
|
550
554
|
/** Tracks the fire-and-forget L1 submission promise so it can be awaited during shutdown. */ pendingL1Submission;
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
555
|
+
interruptibleSleep;
|
|
556
|
+
interrupted;
|
|
557
|
+
/**
|
|
558
|
+
* Chain state overrides built once per slot in proposeCheckpoint after the checkpoint is
|
|
559
|
+
* complete. Carries the pending parent override (archive + slot + fee header) for pipelining,
|
|
560
|
+
* or the invalidation pending override when rolling back. Consumed by
|
|
561
|
+
* publisher.validateBlockHeader before broadcast.
|
|
562
|
+
*/ checkpointSimulationOverridesPlan;
|
|
563
|
+
getSignatureContext() {
|
|
564
|
+
return this.signatureContext;
|
|
565
|
+
}
|
|
566
|
+
constructor(slotNow, targetSlot, targetEpoch, checkpointNumber, syncedToBlockNumber, checkpointedCheckpointNumber, // TODO(palla/mbps): Can we remove the proposer in favor of attestorAddress? Need to check fisherman-node flows.
|
|
567
|
+
proposer, publisher, attestorAddress, invalidateCheckpoint, validatorClient, globalsBuilder, p2pClient, worldState, l1ToL2MessageSource, l2BlockSource, checkpointsBuilder, blockSink, l1Constants, signatureContext, config, timetable, slasherClient, epochCache, dateProvider, metrics, checkpointMetrics, eventEmitter, setStateFn, tracer, bindings, proposedCheckpointData){
|
|
554
568
|
this.slotNow = slotNow;
|
|
555
569
|
this.targetSlot = targetSlot;
|
|
556
570
|
this.targetEpoch = targetEpoch;
|
|
557
571
|
this.checkpointNumber = checkpointNumber;
|
|
558
572
|
this.syncedToBlockNumber = syncedToBlockNumber;
|
|
573
|
+
this.checkpointedCheckpointNumber = checkpointedCheckpointNumber;
|
|
559
574
|
this.proposer = proposer;
|
|
560
575
|
this.publisher = publisher;
|
|
561
576
|
this.attestorAddress = attestorAddress;
|
|
@@ -569,6 +584,7 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
569
584
|
this.checkpointsBuilder = checkpointsBuilder;
|
|
570
585
|
this.blockSink = blockSink;
|
|
571
586
|
this.l1Constants = l1Constants;
|
|
587
|
+
this.signatureContext = signatureContext;
|
|
572
588
|
this.config = config;
|
|
573
589
|
this.timetable = timetable;
|
|
574
590
|
this.slasherClient = slasherClient;
|
|
@@ -580,16 +596,48 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
580
596
|
this.setStateFn = setStateFn;
|
|
581
597
|
this.tracer = tracer;
|
|
582
598
|
this.proposedCheckpointData = proposedCheckpointData;
|
|
583
|
-
_initProto(this);
|
|
599
|
+
this.interruptibleSleep = (_initProto(this), new InterruptibleSleep());
|
|
600
|
+
this.interrupted = false;
|
|
584
601
|
this.log = createLogger('sequencer:checkpoint-proposal', {
|
|
585
602
|
...bindings,
|
|
586
603
|
instanceId: `slot-${this.slotNow}`
|
|
587
604
|
});
|
|
605
|
+
this.checkpointEventLog = createLogger('sequencer:checkpoint-events', {
|
|
606
|
+
...bindings,
|
|
607
|
+
instanceId: `slot-${this.slotNow}`
|
|
608
|
+
});
|
|
588
609
|
}
|
|
589
610
|
/** Awaits the pending L1 submission if one is in progress. Call during shutdown. */ async awaitPendingSubmission() {
|
|
590
611
|
this.log.info('Awaiting pending L1 payload submission');
|
|
591
612
|
await this.pendingL1Submission;
|
|
592
613
|
}
|
|
614
|
+
/** Interrupts job-owned waits, including the publisher's send-at-slot sleep, so shutdown can finish. */ interrupt() {
|
|
615
|
+
this.interrupted = true;
|
|
616
|
+
this.interruptibleSleep.interrupt(true);
|
|
617
|
+
this.publisher.interrupt();
|
|
618
|
+
}
|
|
619
|
+
async awaitInterruptibleSleep(ms) {
|
|
620
|
+
if (this.interrupted) {
|
|
621
|
+
throw new SequencerInterruptedError();
|
|
622
|
+
}
|
|
623
|
+
if (ms <= 0) {
|
|
624
|
+
return;
|
|
625
|
+
}
|
|
626
|
+
try {
|
|
627
|
+
await this.interruptibleSleep.sleep(ms);
|
|
628
|
+
} catch (err) {
|
|
629
|
+
if (err instanceof InterruptError) {
|
|
630
|
+
throw new SequencerInterruptedError();
|
|
631
|
+
}
|
|
632
|
+
throw err;
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
logCheckpointEvent(eventName, message, fields) {
|
|
636
|
+
this.checkpointEventLog.debug(message, {
|
|
637
|
+
eventName: `sequencer-checkpoint-${eventName}`,
|
|
638
|
+
...fields
|
|
639
|
+
});
|
|
640
|
+
}
|
|
593
641
|
/**
|
|
594
642
|
* Executes the checkpoint proposal job.
|
|
595
643
|
* Builds blocks, assembles checkpoint, and broadcasts the proposal (blocking).
|
|
@@ -606,9 +654,14 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
606
654
|
const broadcast = await this.proposeCheckpoint();
|
|
607
655
|
if (!broadcast) {
|
|
608
656
|
await Promise.all(votesPromises);
|
|
609
|
-
// Still submit votes even without a checkpoint
|
|
657
|
+
// Still submit votes even without a checkpoint.
|
|
658
|
+
// Under proposer pipelining, vote-offenses signatures are EIP-712-bound to `targetSlot`
|
|
659
|
+
// (the pipelined slot in which the multicall is expected to mine). Submitting at the
|
|
660
|
+
// wall-clock time would let the multicall mine in a different L2 slot, causing
|
|
661
|
+
// signature verification to fail silently inside Multicall3. Delay submission to the
|
|
662
|
+
// start of `targetSlot` so the tx mines in the slot the vote was signed for.
|
|
610
663
|
if (!this.config.fishermanMode) {
|
|
611
|
-
this.pendingL1Submission = this.publisher.sendRequestsAt(this.
|
|
664
|
+
this.pendingL1Submission = this.publisher.sendRequestsAt(this.targetSlot).then(()=>{});
|
|
612
665
|
}
|
|
613
666
|
return undefined;
|
|
614
667
|
}
|
|
@@ -629,23 +682,21 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
629
682
|
* Runs as a fire-and-forget task stored in `pendingL1Submission` so the work loop is unblocked.
|
|
630
683
|
*/ async waitForAttestationsAndEnqueueSubmissionAsync(broadcast, votesPromises) {
|
|
631
684
|
const { checkpoint } = broadcast;
|
|
632
|
-
const isPipelining = this.epochCache.isProposerPipeliningEnabled();
|
|
633
685
|
try {
|
|
634
686
|
// Wait for all votes actions, enqueued at the beginning, to resolve
|
|
635
687
|
await Promise.all(votesPromises);
|
|
636
688
|
// Try to collect attestations from the committee
|
|
637
689
|
const signedAttestations = await this.getSignedCommitteeAttestations(broadcast);
|
|
638
|
-
//
|
|
639
|
-
//
|
|
640
|
-
if (signedAttestations &&
|
|
690
|
+
// Wait for the previous checkpoint to land on L1 before submitting, so we can check it
|
|
691
|
+
// matches the proposed checkpoint we used as parent, and has valid attestations.
|
|
692
|
+
if (signedAttestations && await this.waitForValidParentCheckpointOnL1()) {
|
|
641
693
|
await this.enqueueCheckpointForSubmission({
|
|
642
694
|
checkpoint,
|
|
643
695
|
...signedAttestations
|
|
644
696
|
});
|
|
645
697
|
}
|
|
646
698
|
// If we failed to collect attestations, at least check if we need to issue an invalidation
|
|
647
|
-
|
|
648
|
-
if (!signedAttestations && isPipelining && await this.waitForSyncedL2SlotNumber(this.slotNow)) {
|
|
699
|
+
if (!signedAttestations && await this.waitForSyncedL2SlotNumber(this.slotNow)) {
|
|
649
700
|
const validationStatus = await this.l2BlockSource.getPendingChainValidationStatus();
|
|
650
701
|
if (!validationStatus.valid) {
|
|
651
702
|
this.log.warn(`Checkpoint ${validationStatus.checkpoint.checkpointNumber} has invalid attestations, enqueuing invalidation in spite of attestation collection failure`, {
|
|
@@ -656,11 +707,15 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
656
707
|
}
|
|
657
708
|
}
|
|
658
709
|
// Send whatever was enqueued: votes + (propose | invalidation | nothing).
|
|
659
|
-
|
|
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);
|
|
710
|
+
const l1Response = await this.publisher.sendRequestsAt(this.targetSlot);
|
|
662
711
|
const proposedAction = l1Response?.successfulActions.find((a)=>a === 'propose');
|
|
663
712
|
if (proposedAction) {
|
|
713
|
+
this.logCheckpointEvent('published', `Checkpoint published for slot ${this.targetSlot}`, {
|
|
714
|
+
slot: this.targetSlot,
|
|
715
|
+
checkpointNumber: this.checkpointNumber,
|
|
716
|
+
successfulActions: l1Response?.successfulActions,
|
|
717
|
+
sentActions: l1Response?.sentActions
|
|
718
|
+
});
|
|
664
719
|
this.eventEmitter.emit('checkpoint-published', {
|
|
665
720
|
checkpoint: this.checkpointNumber,
|
|
666
721
|
slot: this.targetSlot
|
|
@@ -668,30 +723,54 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
668
723
|
const coinbase = checkpoint.header.coinbase;
|
|
669
724
|
await this.metrics.incFilledSlot(this.publisher.getSenderAddress().toString(), coinbase);
|
|
670
725
|
} else {
|
|
726
|
+
this.logCheckpointEvent('publish-failed', `Checkpoint publish failed for slot ${this.targetSlot}`, {
|
|
727
|
+
slot: this.targetSlot,
|
|
728
|
+
checkpointNumber: this.checkpointNumber,
|
|
729
|
+
successfulActions: l1Response?.successfulActions,
|
|
730
|
+
failedActions: l1Response?.failedActions,
|
|
731
|
+
sentActions: l1Response?.sentActions,
|
|
732
|
+
expiredActions: l1Response?.expiredActions,
|
|
733
|
+
reason: 'propose_action_not_successful'
|
|
734
|
+
});
|
|
735
|
+
this.log.warn(`Checkpoint publish failed for slot ${this.targetSlot}`, {
|
|
736
|
+
slot: this.targetSlot,
|
|
737
|
+
checkpointNumber: this.checkpointNumber,
|
|
738
|
+
successfulActions: l1Response?.successfulActions,
|
|
739
|
+
failedActions: l1Response?.failedActions,
|
|
740
|
+
sentActions: l1Response?.sentActions,
|
|
741
|
+
expiredActions: l1Response?.expiredActions,
|
|
742
|
+
reason: 'propose_action_not_successful'
|
|
743
|
+
});
|
|
671
744
|
this.eventEmitter.emit('checkpoint-publish-failed', {
|
|
672
745
|
...l1Response,
|
|
673
746
|
slot: this.targetSlot
|
|
674
747
|
});
|
|
675
|
-
|
|
676
|
-
this.metrics.recordPipelineDiscard();
|
|
677
|
-
}
|
|
748
|
+
this.metrics.recordPipelineDiscard();
|
|
678
749
|
}
|
|
679
750
|
} catch (err) {
|
|
680
751
|
if (err instanceof SequencerInterruptedError) {
|
|
681
752
|
return;
|
|
682
753
|
}
|
|
683
|
-
this.
|
|
754
|
+
this.logCheckpointEvent('publish-failed', `Checkpoint publish failed for slot ${this.targetSlot}`, {
|
|
755
|
+
slot: this.targetSlot,
|
|
756
|
+
checkpointNumber: this.checkpointNumber,
|
|
757
|
+
reason: err instanceof Error ? err.message : String(err)
|
|
758
|
+
});
|
|
759
|
+
this.log.error(`Background attestation/L1 pipeline failed for slot ${this.targetSlot}`, err, {
|
|
760
|
+
slot: this.targetSlot,
|
|
761
|
+
checkpointNumber: this.checkpointNumber,
|
|
762
|
+
reason: err instanceof Error ? err.message : String(err)
|
|
763
|
+
});
|
|
684
764
|
this.eventEmitter.emit('checkpoint-publish-failed', {
|
|
685
765
|
slot: this.targetSlot
|
|
686
766
|
});
|
|
687
|
-
|
|
688
|
-
this.metrics.recordPipelineDiscard();
|
|
689
|
-
}
|
|
767
|
+
this.metrics.recordPipelineDiscard();
|
|
690
768
|
}
|
|
691
769
|
}
|
|
692
770
|
/** Enqueues the checkpoint for L1 submission. Called after pipeline sleep in execute(). */ async enqueueCheckpointForSubmission(result) {
|
|
693
771
|
const { checkpoint, attestations, attestationsSignature } = result;
|
|
694
|
-
|
|
772
|
+
// Build-frame deadlines are measured against `slotNow`; observers still see `targetSlot`.
|
|
773
|
+
this.setStateFn(SequencerState.PUBLISHING_CHECKPOINT, this.targetSlot, this.slotNow);
|
|
695
774
|
const aztecSlotDuration = this.l1Constants.slotDuration;
|
|
696
775
|
const submissionSlotStart = Number(getTimestampForSlot(this.targetSlot, this.l1Constants));
|
|
697
776
|
const txTimeoutAt = new Date((submissionSlotStart + aztecSlotDuration) * 1000);
|
|
@@ -703,18 +782,8 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
703
782
|
return;
|
|
704
783
|
}
|
|
705
784
|
}
|
|
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
785
|
await this.publisher.enqueueProposeCheckpoint(checkpoint, attestations, attestationsSignature, {
|
|
714
|
-
txTimeoutAt
|
|
715
|
-
...submissionSimulationOverridesPlan ? {
|
|
716
|
-
simulationOverridesPlan: submissionSimulationOverridesPlan
|
|
717
|
-
} : {}
|
|
786
|
+
txTimeoutAt
|
|
718
787
|
});
|
|
719
788
|
}
|
|
720
789
|
/**
|
|
@@ -727,11 +796,21 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
727
796
|
const syncDelayTolerance = this.l1Constants.ethereumSlotDuration * 2 * 1000;
|
|
728
797
|
const timeoutSeconds = Math.max(0.1, (targetSlotEndMs + syncDelayTolerance - this.dateProvider.now()) / 1000);
|
|
729
798
|
try {
|
|
730
|
-
|
|
799
|
+
const timer = new Timer();
|
|
800
|
+
while(true){
|
|
731
801
|
const syncedSlot = await this.l2BlockSource.getSyncedL2SlotNumber();
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
802
|
+
if (syncedSlot !== undefined && syncedSlot >= waitForSlot) {
|
|
803
|
+
return true;
|
|
804
|
+
}
|
|
805
|
+
if (timeoutSeconds && timer.s() > timeoutSeconds) {
|
|
806
|
+
throw new TimeoutError(`Timeout awaiting archiver sync past slot ${waitForSlot}`);
|
|
807
|
+
}
|
|
808
|
+
await this.awaitInterruptibleSleep(ARCHIVER_SYNC_POLLING_MS);
|
|
809
|
+
}
|
|
810
|
+
} catch (err) {
|
|
811
|
+
if (err instanceof SequencerInterruptedError) {
|
|
812
|
+
throw err;
|
|
813
|
+
}
|
|
735
814
|
this.log.warn(`Archiver did not sync L1 past slot ${waitForSlot} before slot ${this.targetSlot} expired, discarding pipelined work`, {
|
|
736
815
|
checkpointNumber: this.checkpointNumber
|
|
737
816
|
});
|
|
@@ -746,6 +825,12 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
746
825
|
* - If we built without a proposed parent: no new checkpoint must have appeared for that slot.
|
|
747
826
|
* If the parent has invalid attestations, enqueues an invalidation. Returns whether to proceed with the proposal.
|
|
748
827
|
*/ async waitForValidParentCheckpointOnL1() {
|
|
828
|
+
if (this.config.skipWaitForValidParentCheckpointOnL1) {
|
|
829
|
+
this.log.warn(`Skipping waitForValidParentCheckpointOnL1 due to test configuration`, {
|
|
830
|
+
checkpointNumber: this.checkpointNumber
|
|
831
|
+
});
|
|
832
|
+
return true;
|
|
833
|
+
}
|
|
749
834
|
const parentCheckpointNumber = CheckpointNumber(this.checkpointNumber - 1);
|
|
750
835
|
// Wait until archiver has synced L1 past the parent's slot (slotNow)
|
|
751
836
|
if (!await this.waitForSyncedL2SlotNumber(this.slotNow)) {
|
|
@@ -841,7 +926,7 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
841
926
|
};
|
|
842
927
|
try {
|
|
843
928
|
const now = this.dateProvider.now();
|
|
844
|
-
if (this.
|
|
929
|
+
if (this.proposedCheckpointData) {
|
|
845
930
|
// Measure against the wall-clock slot whose build window we are currently using.
|
|
846
931
|
// In pipelining mode `targetSlot` is intentionally one slot ahead, which makes the
|
|
847
932
|
// target-slot boundary a full slot away from the actual build start time.
|
|
@@ -853,12 +938,15 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
853
938
|
const coinbase = this.validatorClient.getCoinbaseForAttestor(this.attestorAddress);
|
|
854
939
|
const feeRecipient = this.validatorClient.getFeeRecipientForAttestor(this.attestorAddress);
|
|
855
940
|
// Start the checkpoint
|
|
856
|
-
this.setStateFn(SequencerState.INITIALIZING_CHECKPOINT, this.targetSlot);
|
|
857
|
-
this.
|
|
941
|
+
this.setStateFn(SequencerState.INITIALIZING_CHECKPOINT, this.targetSlot, this.slotNow);
|
|
942
|
+
this.logCheckpointEvent('slot-started', `Starting checkpoint proposal for slot ${this.targetSlot}`, {
|
|
858
943
|
buildSlot: this.slotNow,
|
|
859
944
|
submissionSlot: this.targetSlot,
|
|
860
|
-
|
|
945
|
+
slot: this.targetSlot,
|
|
946
|
+
checkpointNumber: this.checkpointNumber,
|
|
861
947
|
proposer: this.proposer?.toString(),
|
|
948
|
+
attestorAddress: this.attestorAddress.toString(),
|
|
949
|
+
publisherAddress: this.publisher.getSenderAddress().toString(),
|
|
862
950
|
coinbase: coinbase.toString()
|
|
863
951
|
});
|
|
864
952
|
this.metrics.incOpenSlot(this.targetSlot, this.proposer?.toString() ?? 'unknown');
|
|
@@ -866,24 +954,41 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
866
954
|
if (this.invalidateCheckpoint && !this.config.skipInvalidateBlockAsProposer) {
|
|
867
955
|
this.publisher.enqueueInvalidateCheckpoint(this.invalidateCheckpoint);
|
|
868
956
|
}
|
|
869
|
-
//
|
|
870
|
-
//
|
|
871
|
-
// fee
|
|
872
|
-
|
|
873
|
-
this.
|
|
957
|
+
// Build the simulation plan for this slot. When pipelining, this overrides L1's view of
|
|
958
|
+
// pending/archive/fee-header to "as if the proposed parent had landed", so both the
|
|
959
|
+
// mana-min-fee simulation (in the globals builder) and the pre-broadcast
|
|
960
|
+
// validateBlockHeader see the chain tip the eventual L1 send will see.
|
|
961
|
+
this.checkpointSimulationOverridesPlan = await buildCheckpointSimulationOverridesPlan({
|
|
874
962
|
checkpointNumber: this.checkpointNumber,
|
|
875
963
|
proposedCheckpointData: this.proposedCheckpointData,
|
|
964
|
+
invalidateToPendingCheckpointNumber: this.invalidateCheckpoint?.forcePendingCheckpointNumber,
|
|
965
|
+
checkpointedCheckpointNumber: this.checkpointedCheckpointNumber,
|
|
876
966
|
rollup: this.publisher.rollupContract,
|
|
967
|
+
signatureContext: this.signatureContext,
|
|
877
968
|
log: this.log
|
|
878
|
-
})
|
|
879
|
-
const checkpointGlobalVariables = await this.globalsBuilder.buildCheckpointGlobalVariables(coinbase, feeRecipient, this.targetSlot, this.
|
|
969
|
+
});
|
|
970
|
+
const checkpointGlobalVariables = await this.globalsBuilder.buildCheckpointGlobalVariables(coinbase, feeRecipient, this.targetSlot, this.checkpointSimulationOverridesPlan);
|
|
880
971
|
// Collect L1 to L2 messages for the checkpoint and compute their hash
|
|
881
972
|
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(this.checkpointNumber);
|
|
882
973
|
const inHash = computeInHashFromL1ToL2Messages(l1ToL2Messages);
|
|
883
|
-
// Collect the out hashes of all the checkpoints before this one in the same epoch
|
|
884
|
-
|
|
885
|
-
//
|
|
886
|
-
|
|
974
|
+
// Collect the out hashes of all the checkpoints before this one in the same epoch.
|
|
975
|
+
// Under pipelining the parent checkpoint may not be on L1 yet at build time, so the helper
|
|
976
|
+
// splices in the parent's checkpointOutHash from the locally-known proposed checkpoint so
|
|
977
|
+
// the resulting `epochOutHash` matches what validators (and L1) compute once the parent
|
|
978
|
+
// lands on L1.
|
|
979
|
+
const previousCheckpointOutHashes = await getPreviousCheckpointOutHashes({
|
|
980
|
+
blockSource: this.l2BlockSource,
|
|
981
|
+
epoch: this.targetEpoch,
|
|
982
|
+
checkpointNumber: this.checkpointNumber,
|
|
983
|
+
l1Constants: this.epochCache.getL1Constants(),
|
|
984
|
+
pipeliningEnabled: true,
|
|
985
|
+
proposedCheckpointData: this.proposedCheckpointData,
|
|
986
|
+
log: this.log
|
|
987
|
+
});
|
|
988
|
+
// Anchor the modifier to the predicted parent fee header: L1 will apply it against
|
|
989
|
+
// that, not against the latest published checkpoint (which lags by one under pipelining).
|
|
990
|
+
const predictedParentEthPerFeeAssetE12 = this.checkpointSimulationOverridesPlan?.pendingCheckpointState?.feeHeader?.ethPerFeeAsset;
|
|
991
|
+
const feeAssetPriceModifier = await this.publisher.getFeeAssetPriceModifier(predictedParentEthPerFeeAssetE12);
|
|
887
992
|
const fork = _ts_add_disposable_resource(env, await this.worldState.fork(this.syncedToBlockNumber, {
|
|
888
993
|
closeDelayMs: 12_000
|
|
889
994
|
}), true);
|
|
@@ -896,7 +1001,7 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
896
1001
|
};
|
|
897
1002
|
const checkpointProposalOptions = {
|
|
898
1003
|
publishFullTxs: !!this.config.publishTxsWithProposals,
|
|
899
|
-
broadcastInvalidCheckpointProposal: this.config.broadcastInvalidBlockProposal
|
|
1004
|
+
broadcastInvalidCheckpointProposal: this.config.broadcastInvalidCheckpointProposalOnly || this.config.broadcastInvalidBlockProposal
|
|
900
1005
|
};
|
|
901
1006
|
let blocksInCheckpoint = [];
|
|
902
1007
|
let blockPendingBroadcast = undefined;
|
|
@@ -916,8 +1021,15 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
916
1021
|
throw err;
|
|
917
1022
|
}
|
|
918
1023
|
if (blocksInCheckpoint.length === 0) {
|
|
1024
|
+
this.logCheckpointEvent('build-failed', `Checkpoint build failed for slot ${this.targetSlot}`, {
|
|
1025
|
+
slot: this.targetSlot,
|
|
1026
|
+
checkpointNumber: this.checkpointNumber,
|
|
1027
|
+
reason: 'no_blocks_built'
|
|
1028
|
+
});
|
|
919
1029
|
this.log.warn(`No blocks were built for slot ${this.targetSlot}`, {
|
|
920
|
-
slot: this.targetSlot
|
|
1030
|
+
slot: this.targetSlot,
|
|
1031
|
+
checkpointNumber: this.checkpointNumber,
|
|
1032
|
+
reason: 'no_blocks_built'
|
|
921
1033
|
});
|
|
922
1034
|
this.eventEmitter.emit('checkpoint-empty', {
|
|
923
1035
|
slot: this.targetSlot
|
|
@@ -926,16 +1038,25 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
926
1038
|
}
|
|
927
1039
|
const minBlocksForCheckpoint = this.config.minBlocksForCheckpoint;
|
|
928
1040
|
if (minBlocksForCheckpoint !== undefined && blocksInCheckpoint.length < minBlocksForCheckpoint) {
|
|
1041
|
+
this.logCheckpointEvent('build-failed', `Checkpoint build failed for slot ${this.targetSlot}`, {
|
|
1042
|
+
slot: this.targetSlot,
|
|
1043
|
+
checkpointNumber: this.checkpointNumber,
|
|
1044
|
+
blocksBuilt: blocksInCheckpoint.length,
|
|
1045
|
+
minBlocksForCheckpoint,
|
|
1046
|
+
reason: 'min_blocks_not_met'
|
|
1047
|
+
});
|
|
929
1048
|
this.log.warn(`Checkpoint has fewer blocks than minimum (${blocksInCheckpoint.length} < ${minBlocksForCheckpoint}), skipping proposal`, {
|
|
930
1049
|
slot: this.targetSlot,
|
|
1050
|
+
checkpointNumber: this.checkpointNumber,
|
|
931
1051
|
blocksBuilt: blocksInCheckpoint.length,
|
|
932
|
-
minBlocksForCheckpoint
|
|
1052
|
+
minBlocksForCheckpoint,
|
|
1053
|
+
reason: 'min_blocks_not_met'
|
|
933
1054
|
});
|
|
934
1055
|
return undefined;
|
|
935
1056
|
}
|
|
936
1057
|
// Assemble and broadcast the checkpoint proposal, including the last block that was not
|
|
937
1058
|
// broadcasted yet, and wait to collect the committee attestations.
|
|
938
|
-
this.setStateFn(SequencerState.ASSEMBLING_CHECKPOINT, this.targetSlot);
|
|
1059
|
+
this.setStateFn(SequencerState.ASSEMBLING_CHECKPOINT, this.targetSlot, this.slotNow);
|
|
939
1060
|
const checkpoint = await checkpointBuilder.completeCheckpoint();
|
|
940
1061
|
// Final validation: per-block limits are only checked if the operator set them explicitly.
|
|
941
1062
|
// Otherwise, checkpoint-level budgets were already enforced by the redistribution logic.
|
|
@@ -948,13 +1069,35 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
948
1069
|
maxTxsPerCheckpoint: this.config.maxTxsPerCheckpoint
|
|
949
1070
|
});
|
|
950
1071
|
} catch (err) {
|
|
1072
|
+
this.logCheckpointEvent('build-failed', `Checkpoint build failed for slot ${this.targetSlot}`, {
|
|
1073
|
+
slot: this.targetSlot,
|
|
1074
|
+
checkpointNumber: this.checkpointNumber,
|
|
1075
|
+
blocksBuilt: blocksInCheckpoint.length,
|
|
1076
|
+
reason: 'invalid_checkpoint',
|
|
1077
|
+
checkpoint: checkpoint.header.toInspect()
|
|
1078
|
+
});
|
|
951
1079
|
this.log.error(`Built an invalid checkpoint at slot ${this.slotNow} (skipping proposal)`, err, {
|
|
1080
|
+
slot: this.targetSlot,
|
|
1081
|
+
checkpointNumber: this.checkpointNumber,
|
|
1082
|
+
blocksBuilt: blocksInCheckpoint.length,
|
|
1083
|
+
reason: 'invalid_checkpoint',
|
|
952
1084
|
checkpoint: checkpoint.header.toInspect()
|
|
953
1085
|
});
|
|
954
1086
|
return undefined;
|
|
955
1087
|
}
|
|
956
1088
|
// Record checkpoint-level build metrics
|
|
957
1089
|
this.checkpointMetrics.recordCheckpointBuild(checkpointBuildTimer.ms(), blocksInCheckpoint.length, checkpoint.getStats().txCount, Number(checkpoint.header.totalManaUsed.toBigInt()));
|
|
1090
|
+
this.logCheckpointEvent('built', `Checkpoint built for slot ${this.targetSlot}`, {
|
|
1091
|
+
slot: this.targetSlot,
|
|
1092
|
+
buildSlot: this.slotNow,
|
|
1093
|
+
checkpointNumber: this.checkpointNumber,
|
|
1094
|
+
proposer: this.proposer?.toString(),
|
|
1095
|
+
attestorAddress: this.attestorAddress.toString(),
|
|
1096
|
+
publisherAddress: this.publisher.getSenderAddress().toString(),
|
|
1097
|
+
blocksBuilt: blocksInCheckpoint.length,
|
|
1098
|
+
txCount: checkpoint.getStats().txCount,
|
|
1099
|
+
totalMana: Number(checkpoint.header.totalManaUsed.toBigInt())
|
|
1100
|
+
});
|
|
958
1101
|
// In fisherman mode, return the checkpoint without broadcasting or collecting attestations
|
|
959
1102
|
if (this.config.fishermanMode) {
|
|
960
1103
|
this.log.info(`Built checkpoint for slot ${this.targetSlot} with ${blocksInCheckpoint.length} blocks. ` + `Skipping proposal in fisherman mode.`, {
|
|
@@ -970,11 +1113,45 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
970
1113
|
blockProposedAt: this.dateProvider.now()
|
|
971
1114
|
};
|
|
972
1115
|
}
|
|
1116
|
+
// Validate the header against L1 state before broadcasting.
|
|
1117
|
+
// If this fails the slot is aborted before any gossip work; state drift between here
|
|
1118
|
+
// and the eventual L1 send is caught by the bundle simulate at send time.
|
|
1119
|
+
try {
|
|
1120
|
+
await this.publisher.validateBlockHeader(checkpoint.header, this.checkpointSimulationOverridesPlan);
|
|
1121
|
+
} catch (err) {
|
|
1122
|
+
this.log.error(`Pre-broadcast header validation failed for slot ${this.targetSlot}; aborting`, err, {
|
|
1123
|
+
slot: this.targetSlot,
|
|
1124
|
+
checkpointNumber: this.checkpointNumber
|
|
1125
|
+
});
|
|
1126
|
+
this.metrics.recordCheckpointProposalFailed('header_validation_failed');
|
|
1127
|
+
this.eventEmitter.emit('header-validation-failed', {
|
|
1128
|
+
slot: this.targetSlot,
|
|
1129
|
+
checkpointNumber: this.checkpointNumber,
|
|
1130
|
+
reason: err instanceof Error ? err.message : String(err)
|
|
1131
|
+
});
|
|
1132
|
+
return undefined;
|
|
1133
|
+
}
|
|
973
1134
|
// Create the checkpoint proposal and broadcast it
|
|
974
1135
|
const proposal = await this.validatorClient.createCheckpointProposal(checkpoint.header, checkpoint.archive.root, this.checkpointNumber, feeAssetPriceModifier, blockPendingBroadcast, this.proposer, checkpointProposalOptions);
|
|
1136
|
+
// Advance our own optimistic proposed-checkpoint tip locally before gossiping. Gossipsub
|
|
1137
|
+
// doesn't echo our own messages back, so this is how the proposer makes its own proposed
|
|
1138
|
+
// checkpoint visible for pipelining the next slot. Built from local checkpoint data — never
|
|
1139
|
+
// from the broadcast proposal archive, which may be deliberately corrupted under test flags.
|
|
1140
|
+
// Fail closed: if this throws, the outer catch aborts the slot before gossiping.
|
|
1141
|
+
await this.syncProposedCheckpointToArchiver(checkpoint, blocksInCheckpoint.length, feeAssetPriceModifier);
|
|
975
1142
|
const blockProposedAt = this.dateProvider.now();
|
|
976
|
-
|
|
977
|
-
|
|
1143
|
+
if (this.config.skipBroadcastCheckpointProposal) {
|
|
1144
|
+
// Test-only: suppress the CheckpointProposal so peers never see a proposed checkpoint for
|
|
1145
|
+
// this slot, but still broadcast the held last block standalone so peers' archivers ingest
|
|
1146
|
+
// it as a proposed-but-uncheckpointed tip — the exact orphan-block state that
|
|
1147
|
+
// pruneOrphanProposedBlocks / checkSync must handle.
|
|
1148
|
+
if (blockPendingBroadcast && !this.config.skipBroadcastProposals) {
|
|
1149
|
+
await this.p2pClient.broadcastProposal(blockPendingBroadcast);
|
|
1150
|
+
}
|
|
1151
|
+
} else if (!this.config.skipBroadcastProposals) {
|
|
1152
|
+
await this.p2pClient.broadcastCheckpointProposal(proposal);
|
|
1153
|
+
this.checkpointMetrics.noteCheckpointBroadcast(this.dateProvider.now());
|
|
1154
|
+
}
|
|
978
1155
|
// Return immediately after broadcast — attestation collection happens in the background
|
|
979
1156
|
return {
|
|
980
1157
|
checkpoint,
|
|
@@ -1009,6 +1186,14 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
1009
1186
|
const blocksBuilt = blocksInCheckpoint.length;
|
|
1010
1187
|
const indexWithinCheckpoint = IndexWithinCheckpoint(blocksBuilt);
|
|
1011
1188
|
const blockNumber = BlockNumber(initialBlockNumber + blocksBuilt);
|
|
1189
|
+
if (blocksBuilt >= this.config.maxBlocksPerCheckpoint) {
|
|
1190
|
+
this.log.debug(`Reached max blocks per checkpoint`, {
|
|
1191
|
+
slot: this.targetSlot,
|
|
1192
|
+
blocksBuilt,
|
|
1193
|
+
maxBlocksPerCheckpoint: this.config.maxBlocksPerCheckpoint
|
|
1194
|
+
});
|
|
1195
|
+
break;
|
|
1196
|
+
}
|
|
1012
1197
|
const secondsIntoSlot = this.getSecondsIntoSlot();
|
|
1013
1198
|
const timingInfo = this.timetable.canStartNextBlock(secondsIntoSlot);
|
|
1014
1199
|
if (!timingInfo.canStart) {
|
|
@@ -1060,7 +1245,10 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
1060
1245
|
blocksInCheckpoint.push(block);
|
|
1061
1246
|
usedTxs.forEach((tx)=>txHashesAlreadyIncluded.add(tx.txHash.toString()));
|
|
1062
1247
|
// Sign the block proposal. This will throw if HA signing fails.
|
|
1063
|
-
const proposal = await this.createBlockProposal(block, inHash, usedTxs,
|
|
1248
|
+
const proposal = await this.createBlockProposal(block, inHash, usedTxs, {
|
|
1249
|
+
...blockProposalOptions,
|
|
1250
|
+
broadcastInvalidBlockProposal: blockProposalOptions.broadcastInvalidBlockProposal || block.indexWithinCheckpoint === this.config.invalidBlockProposalIndexWithinCheckpoint
|
|
1251
|
+
});
|
|
1064
1252
|
// Sync the proposed block to the archiver to make it available, only after we've managed to sign the proposal,
|
|
1065
1253
|
// so we avoid polluting our archive with a block that would fail.
|
|
1066
1254
|
// We wait for the sync to succeed, as this helps catch consistency errors, even if it means we lose some time for block-building.
|
|
@@ -1077,7 +1265,9 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
1077
1265
|
break;
|
|
1078
1266
|
}
|
|
1079
1267
|
// Once we have a signed proposal and the archiver agreed with our proposed block, then we broadcast it.
|
|
1080
|
-
proposal &&
|
|
1268
|
+
if (proposal && !this.config.skipBroadcastProposals) {
|
|
1269
|
+
await this.p2pClient.broadcastProposal(proposal);
|
|
1270
|
+
}
|
|
1081
1271
|
// Wait until the next block's start time
|
|
1082
1272
|
await this.waitUntilNextSubslot(timingInfo.deadline);
|
|
1083
1273
|
}
|
|
@@ -1098,7 +1288,7 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
1098
1288
|
return this.validatorClient.createBlockProposal(block.header, this.checkpointNumber, block.indexWithinCheckpoint, inHash, block.archive.root, usedTxs, this.proposer, blockProposalOptions);
|
|
1099
1289
|
}
|
|
1100
1290
|
/** Sleeps until it is time to produce the next block in the slot */ async waitUntilNextSubslot(nextSubslotStart) {
|
|
1101
|
-
this.setStateFn(SequencerState.WAITING_UNTIL_NEXT_BLOCK, this.targetSlot);
|
|
1291
|
+
this.setStateFn(SequencerState.WAITING_UNTIL_NEXT_BLOCK, this.targetSlot, this.slotNow);
|
|
1102
1292
|
this.log.verbose(`Waiting until time for the next block at ${nextSubslotStart}s into slot`, {
|
|
1103
1293
|
slot: this.targetSlot
|
|
1104
1294
|
});
|
|
@@ -1114,10 +1304,23 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
1114
1304
|
// Wait until we have enough txs to build the block
|
|
1115
1305
|
const { availableTxs, canStartBuilding, minTxs } = await this.waitForMinTxs(opts);
|
|
1116
1306
|
if (!canStartBuilding) {
|
|
1307
|
+
this.logCheckpointEvent('block-build-failed', `Block build failed for slot ${this.targetSlot}`, {
|
|
1308
|
+
reason: 'insufficient_txs',
|
|
1309
|
+
blockNumber,
|
|
1310
|
+
slot: this.targetSlot,
|
|
1311
|
+
checkpointNumber: this.checkpointNumber,
|
|
1312
|
+
indexWithinCheckpoint,
|
|
1313
|
+
availableTxs,
|
|
1314
|
+
minTxs
|
|
1315
|
+
});
|
|
1117
1316
|
this.log.warn(`Not enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.targetSlot} (got ${availableTxs} txs but needs ${minTxs})`, {
|
|
1317
|
+
reason: 'insufficient_txs',
|
|
1118
1318
|
blockNumber,
|
|
1119
1319
|
slot: this.targetSlot,
|
|
1120
|
-
|
|
1320
|
+
checkpointNumber: this.checkpointNumber,
|
|
1321
|
+
indexWithinCheckpoint,
|
|
1322
|
+
availableTxs,
|
|
1323
|
+
minTxs
|
|
1121
1324
|
});
|
|
1122
1325
|
this.eventEmitter.emit('block-tx-count-check-failed', {
|
|
1123
1326
|
minTxs,
|
|
@@ -1137,7 +1340,7 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
1137
1340
|
blockNumber,
|
|
1138
1341
|
indexWithinCheckpoint
|
|
1139
1342
|
});
|
|
1140
|
-
this.setStateFn(SequencerState.CREATING_BLOCK, this.targetSlot);
|
|
1343
|
+
this.setStateFn(SequencerState.CREATING_BLOCK, this.targetSlot, this.slotNow);
|
|
1141
1344
|
// Per-block limits are operator overrides (from SEQ_MAX_L2_BLOCK_GAS etc.) further capped
|
|
1142
1345
|
// by remaining checkpoint-level budgets inside CheckpointBuilder before each block is built.
|
|
1143
1346
|
// minValidTxs is passed into the builder so it can reject the block *before* updating state.
|
|
@@ -1158,8 +1361,19 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
1158
1361
|
// If any txs failed during execution, drop them from the mempool so we don't pick them up again
|
|
1159
1362
|
await this.dropFailedTxsFromP2P(buildResult.failedTxs);
|
|
1160
1363
|
if (buildResult.status === 'insufficient-valid-txs') {
|
|
1364
|
+
this.logCheckpointEvent('block-build-failed', `Block build failed for slot ${this.targetSlot}`, {
|
|
1365
|
+
reason: 'insufficient_valid_txs',
|
|
1366
|
+
slot: this.targetSlot,
|
|
1367
|
+
checkpointNumber: this.checkpointNumber,
|
|
1368
|
+
blockNumber,
|
|
1369
|
+
numTxs: buildResult.processedCount,
|
|
1370
|
+
indexWithinCheckpoint,
|
|
1371
|
+
minValidTxs
|
|
1372
|
+
});
|
|
1161
1373
|
this.log.warn(`Block ${blockNumber} at index ${indexWithinCheckpoint} on slot ${this.targetSlot} has too few valid txs to be proposed`, {
|
|
1374
|
+
reason: 'insufficient_valid_txs',
|
|
1162
1375
|
slot: this.targetSlot,
|
|
1376
|
+
checkpointNumber: this.checkpointNumber,
|
|
1163
1377
|
blockNumber,
|
|
1164
1378
|
numTxs: buildResult.processedCount,
|
|
1165
1379
|
indexWithinCheckpoint,
|
|
@@ -1195,6 +1409,9 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
1195
1409
|
// `buildSlot` is the wall-clock slot during which the block was actually built.
|
|
1196
1410
|
this.eventEmitter.emit('block-proposed', {
|
|
1197
1411
|
blockNumber: block.number,
|
|
1412
|
+
blockHash,
|
|
1413
|
+
checkpointNumber: this.checkpointNumber,
|
|
1414
|
+
indexWithinCheckpoint: block.indexWithinCheckpoint,
|
|
1198
1415
|
slot: this.targetSlot,
|
|
1199
1416
|
buildSlot: this.slotNow
|
|
1200
1417
|
});
|
|
@@ -1208,9 +1425,17 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
1208
1425
|
reason: err.message,
|
|
1209
1426
|
slot: this.targetSlot
|
|
1210
1427
|
});
|
|
1428
|
+
this.logCheckpointEvent('block-build-failed', `Block build failed for slot ${this.targetSlot}`, {
|
|
1429
|
+
reason: err instanceof Error ? err.message : String(err),
|
|
1430
|
+
slot: this.targetSlot,
|
|
1431
|
+
checkpointNumber: this.checkpointNumber,
|
|
1432
|
+
blockNumber
|
|
1433
|
+
});
|
|
1211
1434
|
this.log.error(`Error building block`, err, {
|
|
1212
|
-
|
|
1213
|
-
slot: this.targetSlot
|
|
1435
|
+
reason: err instanceof Error ? err.message : String(err),
|
|
1436
|
+
slot: this.targetSlot,
|
|
1437
|
+
checkpointNumber: this.checkpointNumber,
|
|
1438
|
+
blockNumber
|
|
1214
1439
|
});
|
|
1215
1440
|
this.metrics.recordBlockProposalFailed(err.name || 'unknown_error');
|
|
1216
1441
|
this.metrics.recordFailedBlock();
|
|
@@ -1258,7 +1483,7 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
1258
1483
|
};
|
|
1259
1484
|
}
|
|
1260
1485
|
// Wait a bit before checking again
|
|
1261
|
-
this.setStateFn(SequencerState.WAITING_FOR_TXS, this.targetSlot);
|
|
1486
|
+
this.setStateFn(SequencerState.WAITING_FOR_TXS, this.targetSlot, this.slotNow);
|
|
1262
1487
|
this.log.verbose(`Waiting for enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.targetSlot} (have ${availableTxs} but need ${minTxs})`, {
|
|
1263
1488
|
blockNumber,
|
|
1264
1489
|
slot: this.targetSlot,
|
|
@@ -1275,7 +1500,7 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
1275
1500
|
}
|
|
1276
1501
|
async getSignedCommitteeAttestations(broadcast) {
|
|
1277
1502
|
const { proposal, blockProposedAt } = broadcast;
|
|
1278
|
-
this.setStateFn(SequencerState.COLLECTING_ATTESTATIONS, this.targetSlot);
|
|
1503
|
+
this.setStateFn(SequencerState.COLLECTING_ATTESTATIONS, this.targetSlot, this.slotNow);
|
|
1279
1504
|
const attestations = await this.waitForAttestations(proposal);
|
|
1280
1505
|
if (!attestations) {
|
|
1281
1506
|
return undefined;
|
|
@@ -1303,7 +1528,7 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
1303
1528
|
*/ async waitForAttestations(proposal) {
|
|
1304
1529
|
if (this.config.fishermanMode) {
|
|
1305
1530
|
this.log.debug('Skipping attestation collection in fisherman mode');
|
|
1306
|
-
return CommitteeAttestationsAndSigners.empty();
|
|
1531
|
+
return CommitteeAttestationsAndSigners.empty(this.getSignatureContext());
|
|
1307
1532
|
}
|
|
1308
1533
|
const slotNumber = proposal.slotNumber;
|
|
1309
1534
|
const { committee, seed, epoch } = await this.epochCache.getCommittee(slotNumber);
|
|
@@ -1311,7 +1536,7 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
1311
1536
|
throw new Error('No committee when collecting attestations');
|
|
1312
1537
|
} else if (committee.length === 0) {
|
|
1313
1538
|
this.log.verbose(`Attesting committee is empty`);
|
|
1314
|
-
return CommitteeAttestationsAndSigners.empty();
|
|
1539
|
+
return CommitteeAttestationsAndSigners.empty(this.getSignatureContext());
|
|
1315
1540
|
} else {
|
|
1316
1541
|
this.log.debug(`Attesting committee length is ${committee.length}`, {
|
|
1317
1542
|
committee
|
|
@@ -1321,7 +1546,10 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
1321
1546
|
if (this.config.skipCollectingAttestations) {
|
|
1322
1547
|
this.log.warn('Skipping attestation collection as per config (attesting with own keys only)');
|
|
1323
1548
|
const attestations = await this.validatorClient?.collectOwnAttestations(proposal, this.checkpointNumber);
|
|
1324
|
-
|
|
1549
|
+
this.logCheckpointAttestations('collected', committee, attestations ?? [], numberOfRequiredAttestations, {
|
|
1550
|
+
reason: 'collect_own_only'
|
|
1551
|
+
});
|
|
1552
|
+
return new CommitteeAttestationsAndSigners(orderAttestations(attestations ?? [], committee), this.getSignatureContext());
|
|
1325
1553
|
}
|
|
1326
1554
|
const attestationTimeAllowed = this.config.enforceTimeTable ? this.timetable.getCheckpointAttestationDeadline() : this.l1Constants.slotDuration;
|
|
1327
1555
|
const attestationDeadline = new Date((this.getSlotStartBuildTimestamp() + attestationTimeAllowed) * 1000);
|
|
@@ -1339,16 +1567,27 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
1339
1567
|
}
|
|
1340
1568
|
// Rollup contract requires that the signatures are provided in the order of the committee
|
|
1341
1569
|
const sorted = orderAttestations(trimmed, committee);
|
|
1570
|
+
this.logCheckpointAttestations('collected', committee, attestations, numberOfRequiredAttestations, {
|
|
1571
|
+
submittedCount: trimmed.length
|
|
1572
|
+
});
|
|
1342
1573
|
// Manipulate the attestations if we've been configured to do so
|
|
1343
1574
|
if (this.config.injectFakeAttestation || this.config.injectHighSValueAttestation || this.config.injectUnrecoverableSignatureAttestation || this.config.shuffleAttestationOrdering) {
|
|
1344
1575
|
return this.manipulateAttestations(proposal.slotNumber, epoch, seed, committee, sorted);
|
|
1345
1576
|
}
|
|
1346
|
-
return new CommitteeAttestationsAndSigners(sorted);
|
|
1577
|
+
return new CommitteeAttestationsAndSigners(sorted, this.getSignatureContext());
|
|
1347
1578
|
} catch (err) {
|
|
1348
1579
|
if (err && err instanceof AttestationTimeoutError) {
|
|
1349
1580
|
collectedAttestationsCount = err.collectedCount;
|
|
1581
|
+
this.logCheckpointAttestations('failed', committee, undefined, numberOfRequiredAttestations, {
|
|
1582
|
+
collectedCount: collectedAttestationsCount,
|
|
1583
|
+
reason: 'timeout'
|
|
1584
|
+
});
|
|
1350
1585
|
this.log.error(`Timeout while waiting for attestations for checkpoint proposal at slot ${proposal.slotNumber} (collected ${collectedAttestationsCount}/${numberOfRequiredAttestations})`, err);
|
|
1351
1586
|
} else {
|
|
1587
|
+
this.logCheckpointAttestations('failed', committee, undefined, numberOfRequiredAttestations, {
|
|
1588
|
+
collectedCount: collectedAttestationsCount,
|
|
1589
|
+
reason: err instanceof Error ? err.message : String(err)
|
|
1590
|
+
});
|
|
1352
1591
|
this.log.error(`Error collecting attestations for checkpoint proposal at slot ${proposal.slotNumber}`, err);
|
|
1353
1592
|
}
|
|
1354
1593
|
return undefined;
|
|
@@ -1356,6 +1595,27 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
1356
1595
|
this.metrics.recordCollectedAttestations(collectedAttestationsCount, collectAttestationsTimer.ms());
|
|
1357
1596
|
}
|
|
1358
1597
|
}
|
|
1598
|
+
logCheckpointAttestations(status, committee, attestations, requiredAttestations, opts = {}) {
|
|
1599
|
+
const signedValidators = attestations?.map((attestation)=>attestation.getSender()?.toString()).filter((address)=>address !== undefined) ?? [];
|
|
1600
|
+
const collectedCount = opts.collectedCount ?? new Set(signedValidators).size;
|
|
1601
|
+
const missingValidatorCount = status === 'failed' ? Math.max(0, requiredAttestations - collectedCount) : undefined;
|
|
1602
|
+
this.logCheckpointEvent(`attestations-${status}`, `Checkpoint attestations ${status} for slot ${this.targetSlot}`, {
|
|
1603
|
+
slot: this.targetSlot,
|
|
1604
|
+
checkpointNumber: this.checkpointNumber,
|
|
1605
|
+
committeeSize: committee.length,
|
|
1606
|
+
requiredAttestations,
|
|
1607
|
+
collectedAttestations: collectedCount,
|
|
1608
|
+
...opts.submittedCount !== undefined && {
|
|
1609
|
+
submittedAttestations: opts.submittedCount
|
|
1610
|
+
},
|
|
1611
|
+
...missingValidatorCount !== undefined && {
|
|
1612
|
+
missingValidatorCount
|
|
1613
|
+
},
|
|
1614
|
+
...opts.reason !== undefined && {
|
|
1615
|
+
reason: opts.reason
|
|
1616
|
+
}
|
|
1617
|
+
});
|
|
1618
|
+
}
|
|
1359
1619
|
/** Breaks the attestations before publishing based on attack configs */ manipulateAttestations(slotNumber, epoch, seed, committee, attestations) {
|
|
1360
1620
|
// Compute the proposer index in the committee, since we dont want to tweak it.
|
|
1361
1621
|
// Otherwise, the L1 rollup contract will reject the block outright.
|
|
@@ -1381,7 +1641,7 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
1381
1641
|
unfreeze(attestations[targetIndex]).signature = generateRecoverableSignature();
|
|
1382
1642
|
}
|
|
1383
1643
|
}
|
|
1384
|
-
return new CommitteeAttestationsAndSigners(attestations);
|
|
1644
|
+
return new CommitteeAttestationsAndSigners(attestations, this.getSignatureContext());
|
|
1385
1645
|
}
|
|
1386
1646
|
if (this.config.shuffleAttestationOrdering) {
|
|
1387
1647
|
this.log.warn(`Shuffling attestation ordering in checkpoint for slot ${slotNumber} (proposer #${proposerIndex})`);
|
|
@@ -1407,10 +1667,10 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
1407
1667
|
shuffled[i]
|
|
1408
1668
|
];
|
|
1409
1669
|
}
|
|
1410
|
-
const signers = new CommitteeAttestationsAndSigners(attestations).getSigners();
|
|
1411
|
-
return new MaliciousCommitteeAttestationsAndSigners(shuffled, signers);
|
|
1670
|
+
const signers = new CommitteeAttestationsAndSigners(attestations, this.getSignatureContext()).getSigners();
|
|
1671
|
+
return new MaliciousCommitteeAttestationsAndSigners(shuffled, signers, this.getSignatureContext());
|
|
1412
1672
|
}
|
|
1413
|
-
return new CommitteeAttestationsAndSigners(attestations);
|
|
1673
|
+
return new CommitteeAttestationsAndSigners(attestations, this.getSignatureContext());
|
|
1414
1674
|
}
|
|
1415
1675
|
async dropFailedTxsFromP2P(failedTxs) {
|
|
1416
1676
|
if (failedTxs.length === 0) {
|
|
@@ -1443,6 +1703,35 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
1443
1703
|
});
|
|
1444
1704
|
await this.blockSink.addBlock(block);
|
|
1445
1705
|
}
|
|
1706
|
+
/**
|
|
1707
|
+
* Adds the proposed checkpoint to the archiver so the proposer's optimistic proposed-checkpoint
|
|
1708
|
+
* tip advances locally. Gossip doesn't echo our own messages back, so without this the proposer
|
|
1709
|
+
* would never see its own proposed checkpoint and couldn't pipeline the next slot.
|
|
1710
|
+
*
|
|
1711
|
+
* Skipped whenever proposed blocks aren't pushed (`skipPushProposedBlocksToArchiver`, fisherman
|
|
1712
|
+
* mode): the archiver derives the checkpoint archive from its stored blocks, so without them the
|
|
1713
|
+
* push would fail. All blocks were already added (and awaited) during block building, so this
|
|
1714
|
+
* needs no retry — they are guaranteed present by the time we get here.
|
|
1715
|
+
*/ async syncProposedCheckpointToArchiver(checkpoint, blockCount, feeAssetPriceModifier) {
|
|
1716
|
+
if (this.config.skipPushProposedBlocksToArchiver || this.config.fishermanMode) {
|
|
1717
|
+
return;
|
|
1718
|
+
}
|
|
1719
|
+
const startBlock = BlockNumber(this.syncedToBlockNumber + 1);
|
|
1720
|
+
this.log.debug(`Syncing proposed checkpoint ${this.checkpointNumber} to archiver`, {
|
|
1721
|
+
checkpointNumber: this.checkpointNumber,
|
|
1722
|
+
slot: this.targetSlot,
|
|
1723
|
+
startBlock,
|
|
1724
|
+
blockCount
|
|
1725
|
+
});
|
|
1726
|
+
await this.blockSink.addProposedCheckpoint({
|
|
1727
|
+
header: checkpoint.header,
|
|
1728
|
+
checkpointNumber: this.checkpointNumber,
|
|
1729
|
+
startBlock,
|
|
1730
|
+
blockCount,
|
|
1731
|
+
totalManaUsed: checkpoint.header.totalManaUsed.toBigInt(),
|
|
1732
|
+
feeAssetPriceModifier
|
|
1733
|
+
});
|
|
1734
|
+
}
|
|
1446
1735
|
/** Runs fee analysis and logs checkpoint outcome as fisherman */ async handleCheckpointEndAsFisherman(checkpoint) {
|
|
1447
1736
|
// Perform L1 fee analysis before clearing requests
|
|
1448
1737
|
// The callback is invoked asynchronously after the next block is mined
|
|
@@ -1485,10 +1774,11 @@ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('Checkpoint
|
|
|
1485
1774
|
/** Waits until a specific time within the current slot */ async waitUntilTimeInSlot(targetSecondsIntoSlot) {
|
|
1486
1775
|
const slotStartTimestamp = this.getSlotStartBuildTimestamp();
|
|
1487
1776
|
const targetTimestamp = slotStartTimestamp + targetSecondsIntoSlot;
|
|
1488
|
-
|
|
1777
|
+
const delayMs = targetTimestamp * 1000 - this.dateProvider.nowAsDate().getTime();
|
|
1778
|
+
await this.awaitInterruptibleSleep(delayMs);
|
|
1489
1779
|
}
|
|
1490
|
-
/**
|
|
1491
|
-
await
|
|
1780
|
+
/** Pause between mempool polls in waitForMinTxs. Extracted for test overriding. */ async waitForTxsPollingInterval() {
|
|
1781
|
+
await this.awaitInterruptibleSleep(TXS_POLLING_MS);
|
|
1492
1782
|
}
|
|
1493
1783
|
getSlotStartBuildTimestamp() {
|
|
1494
1784
|
return getSlotStartBuildTimestamp(this.slotNow, this.l1Constants);
|