@aztec/sequencer-client 0.0.1-commit.2ed92850 → 0.0.1-commit.2f68f620
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +281 -21
- package/dest/client/sequencer-client.d.ts +19 -9
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +65 -32
- package/dest/config.d.ts +28 -6
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +76 -37
- package/dest/global_variable_builder/fee_predictor.d.ts +37 -0
- package/dest/global_variable_builder/fee_predictor.d.ts.map +1 -0
- package/dest/global_variable_builder/fee_predictor.js +128 -0
- package/dest/global_variable_builder/fee_provider.d.ts +21 -0
- package/dest/global_variable_builder/fee_provider.d.ts.map +1 -0
- package/dest/global_variable_builder/fee_provider.js +58 -0
- package/dest/global_variable_builder/global_builder.d.ts +14 -16
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +16 -50
- package/dest/global_variable_builder/index.d.ts +4 -2
- package/dest/global_variable_builder/index.d.ts.map +1 -1
- package/dest/global_variable_builder/index.js +2 -0
- package/dest/index.d.ts +2 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -1
- package/dest/publisher/config.d.ts +47 -17
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +121 -42
- package/dest/publisher/index.d.ts +2 -1
- package/dest/publisher/index.d.ts.map +1 -1
- package/dest/publisher/l1_tx_failed_store/factory.d.ts +11 -0
- package/dest/publisher/l1_tx_failed_store/factory.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/factory.js +22 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +58 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.js +1 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts +15 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.js +34 -0
- package/dest/publisher/l1_tx_failed_store/index.d.ts +4 -0
- package/dest/publisher/l1_tx_failed_store/index.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/index.js +2 -0
- package/dest/publisher/sequencer-bundle-simulator.d.ts +96 -0
- package/dest/publisher/sequencer-bundle-simulator.d.ts.map +1 -0
- package/dest/publisher/sequencer-bundle-simulator.js +198 -0
- package/dest/publisher/sequencer-publisher-factory.d.ts +11 -5
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-factory.js +27 -3
- package/dest/publisher/sequencer-publisher-metrics.d.ts +1 -1
- package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-metrics.js +12 -4
- package/dest/publisher/sequencer-publisher.d.ts +94 -68
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +448 -363
- package/dest/sequencer/automine/automine_factory.d.ts +54 -0
- package/dest/sequencer/automine/automine_factory.d.ts.map +1 -0
- package/dest/sequencer/automine/automine_factory.js +84 -0
- package/dest/sequencer/automine/automine_sequencer.d.ts +151 -0
- package/dest/sequencer/automine/automine_sequencer.d.ts.map +1 -0
- package/dest/sequencer/automine/automine_sequencer.js +509 -0
- package/dest/sequencer/chain_state_overrides.d.ts +61 -0
- package/dest/sequencer/chain_state_overrides.d.ts.map +1 -0
- package/dest/sequencer/chain_state_overrides.js +98 -0
- package/dest/sequencer/checkpoint_proposal_job.d.ts +85 -14
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_proposal_job.js +882 -254
- package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts +34 -0
- package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_proposal_job_metrics.js +72 -0
- package/dest/sequencer/checkpoint_voter.d.ts +1 -2
- package/dest/sequencer/checkpoint_voter.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_voter.js +2 -5
- package/dest/sequencer/events.d.ts +48 -2
- package/dest/sequencer/events.d.ts.map +1 -1
- package/dest/sequencer/index.d.ts +3 -1
- package/dest/sequencer/index.d.ts.map +1 -1
- package/dest/sequencer/index.js +2 -0
- package/dest/sequencer/metrics.d.ts +23 -8
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +142 -36
- package/dest/sequencer/sequencer.d.ts +85 -22
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +380 -137
- package/dest/sequencer/timetable.d.ts +14 -6
- package/dest/sequencer/timetable.d.ts.map +1 -1
- package/dest/sequencer/timetable.js +47 -46
- package/dest/sequencer/types.d.ts +2 -2
- package/dest/sequencer/types.d.ts.map +1 -1
- package/dest/test/index.d.ts +3 -5
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.d.ts +12 -12
- package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.js +45 -36
- package/dest/test/utils.d.ts +3 -3
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +10 -8
- package/package.json +27 -28
- package/src/client/sequencer-client.ts +91 -35
- package/src/config.ts +98 -46
- package/src/global_variable_builder/README.md +44 -0
- package/src/global_variable_builder/fee_predictor.ts +172 -0
- package/src/global_variable_builder/fee_provider.ts +75 -0
- package/src/global_variable_builder/global_builder.ts +26 -63
- package/src/global_variable_builder/index.ts +3 -1
- package/src/index.ts +10 -1
- package/src/publisher/config.ts +157 -45
- package/src/publisher/index.ts +3 -0
- package/src/publisher/l1_tx_failed_store/factory.ts +32 -0
- package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +57 -0
- package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +46 -0
- package/src/publisher/l1_tx_failed_store/index.ts +3 -0
- package/src/publisher/sequencer-bundle-simulator.ts +254 -0
- package/src/publisher/sequencer-publisher-factory.ts +38 -9
- package/src/publisher/sequencer-publisher-metrics.ts +7 -3
- package/src/publisher/sequencer-publisher.ts +542 -460
- package/src/sequencer/README.md +162 -450
- package/src/sequencer/automine/README.md +46 -0
- package/src/sequencer/automine/automine_factory.ts +145 -0
- package/src/sequencer/automine/automine_sequencer.ts +595 -0
- package/src/sequencer/chain_state_overrides.ts +162 -0
- package/src/sequencer/checkpoint_proposal_job.ts +1078 -290
- package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
- package/src/sequencer/checkpoint_voter.ts +1 -12
- package/src/sequencer/events.ts +51 -2
- package/src/sequencer/index.ts +2 -0
- package/src/sequencer/metrics.ts +164 -39
- package/src/sequencer/sequencer.ts +471 -157
- package/src/sequencer/timetable.ts +62 -56
- package/src/sequencer/types.ts +1 -1
- package/src/test/index.ts +2 -4
- package/src/test/mock_checkpoint_builder.ts +65 -53
- package/src/test/utils.ts +31 -10
|
@@ -1,16 +1,27 @@
|
|
|
1
|
-
import { NUM_CHECKPOINT_END_MARKER_FIELDS, getNumBlockEndBlobFields } from '@aztec/blob-lib/encoding';
|
|
2
|
-
import { BLOBS_PER_CHECKPOINT, FIELDS_PER_BLOB } from '@aztec/constants';
|
|
3
1
|
import type { EpochCache } from '@aztec/epoch-cache';
|
|
4
|
-
import {
|
|
2
|
+
import type { SimulationOverridesPlan } from '@aztec/ethereum/contracts';
|
|
3
|
+
import {
|
|
4
|
+
BlockNumber,
|
|
5
|
+
CheckpointNumber,
|
|
6
|
+
EpochNumber,
|
|
7
|
+
IndexWithinCheckpoint,
|
|
8
|
+
SlotNumber,
|
|
9
|
+
} from '@aztec/foundation/branded-types';
|
|
5
10
|
import { randomInt } from '@aztec/foundation/crypto/random';
|
|
11
|
+
import {
|
|
12
|
+
flipSignature,
|
|
13
|
+
generateRecoverableSignature,
|
|
14
|
+
generateUnrecoverableSignature,
|
|
15
|
+
} from '@aztec/foundation/crypto/secp256k1-signer';
|
|
6
16
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
17
|
+
import { InterruptError, TimeoutError } from '@aztec/foundation/error';
|
|
7
18
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
8
19
|
import { Signature } from '@aztec/foundation/eth-signature';
|
|
9
20
|
import { filter } from '@aztec/foundation/iterator';
|
|
10
|
-
import type
|
|
11
|
-
import {
|
|
21
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
22
|
+
import { InterruptibleSleep } from '@aztec/foundation/sleep';
|
|
12
23
|
import { type DateProvider, Timer } from '@aztec/foundation/timer';
|
|
13
|
-
import { type TypedEventEmitter, unfreeze } from '@aztec/foundation/types';
|
|
24
|
+
import { type TypedEventEmitter, isErrorClass, unfreeze } from '@aztec/foundation/types';
|
|
14
25
|
import type { P2P } from '@aztec/p2p';
|
|
15
26
|
import type { SlasherClientInterface } from '@aztec/slasher';
|
|
16
27
|
import {
|
|
@@ -20,18 +31,33 @@ import {
|
|
|
20
31
|
type L2BlockSink,
|
|
21
32
|
type L2BlockSource,
|
|
22
33
|
MaliciousCommitteeAttestationsAndSigners,
|
|
34
|
+
type ProposedCheckpointSink,
|
|
35
|
+
type ValidateCheckpointResult,
|
|
23
36
|
} from '@aztec/stdlib/block';
|
|
24
|
-
import
|
|
25
|
-
|
|
37
|
+
import {
|
|
38
|
+
type Checkpoint,
|
|
39
|
+
type ProposedCheckpointData,
|
|
40
|
+
getPreviousCheckpointOutHashes,
|
|
41
|
+
validateCheckpoint,
|
|
42
|
+
} from '@aztec/stdlib/checkpoint';
|
|
43
|
+
import { computeQuorum, getSlotStartBuildTimestamp, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
26
44
|
import { Gas } from '@aztec/stdlib/gas';
|
|
27
|
-
import
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
45
|
+
import {
|
|
46
|
+
type BlockBuilderOptions,
|
|
47
|
+
InsufficientValidTxsError,
|
|
48
|
+
type ResolvedSequencerConfig,
|
|
49
|
+
type WorldStateSynchronizer,
|
|
31
50
|
} from '@aztec/stdlib/interfaces/server';
|
|
32
51
|
import { type L1ToL2MessageSource, computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
|
|
33
|
-
import type {
|
|
34
|
-
|
|
52
|
+
import type {
|
|
53
|
+
BlockProposal,
|
|
54
|
+
BlockProposalOptions,
|
|
55
|
+
CheckpointAttestation,
|
|
56
|
+
CheckpointProposal,
|
|
57
|
+
CheckpointProposalOptions,
|
|
58
|
+
CoordinationSignatureContext,
|
|
59
|
+
} from '@aztec/stdlib/p2p';
|
|
60
|
+
import { orderAttestations, trimAttestations } from '@aztec/stdlib/p2p';
|
|
35
61
|
import type { L2BlockBuiltStats } from '@aztec/stdlib/stats';
|
|
36
62
|
import { type FailedTx, Tx } from '@aztec/stdlib/tx';
|
|
37
63
|
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
@@ -41,6 +67,8 @@ import { DutyAlreadySignedError, SlashingProtectionError } from '@aztec/validato
|
|
|
41
67
|
|
|
42
68
|
import type { GlobalVariableBuilder } from '../global_variable_builder/global_builder.js';
|
|
43
69
|
import type { InvalidateCheckpointRequest, SequencerPublisher } from '../publisher/sequencer-publisher.js';
|
|
70
|
+
import { buildCheckpointSimulationOverridesPlan } from './chain_state_overrides.js';
|
|
71
|
+
import type { CheckpointProposalJobMetricsRecorder } from './checkpoint_proposal_job_metrics.js';
|
|
44
72
|
import { CheckpointVoter } from './checkpoint_voter.js';
|
|
45
73
|
import { SequencerInterruptedError } from './errors.js';
|
|
46
74
|
import type { SequencerEvents } from './events.js';
|
|
@@ -51,6 +79,21 @@ import { SequencerState } from './utils.js';
|
|
|
51
79
|
|
|
52
80
|
/** How much time to sleep while waiting for min transactions to accumulate for a block */
|
|
53
81
|
const TXS_POLLING_MS = 500;
|
|
82
|
+
const ARCHIVER_SYNC_POLLING_MS = 200;
|
|
83
|
+
|
|
84
|
+
/** Result from proposeCheckpoint when a checkpoint was successfully built and broadcast. */
|
|
85
|
+
type CheckpointProposalBroadcast = {
|
|
86
|
+
checkpoint: Checkpoint;
|
|
87
|
+
proposal: CheckpointProposal;
|
|
88
|
+
blockProposedAt: number;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
/** Result after attestation collection and signing, ready for L1 submission. */
|
|
92
|
+
type CheckpointProposalResult = {
|
|
93
|
+
checkpoint: Checkpoint;
|
|
94
|
+
attestations: CommitteeAttestationsAndSigners;
|
|
95
|
+
attestationsSignature: Signature;
|
|
96
|
+
};
|
|
54
97
|
|
|
55
98
|
/**
|
|
56
99
|
* Handles the execution of a checkpoint proposal after the initial preparation phase.
|
|
@@ -59,11 +102,33 @@ const TXS_POLLING_MS = 500;
|
|
|
59
102
|
* the Sequencer once the check for being the proposer for the slot has succeeded.
|
|
60
103
|
*/
|
|
61
104
|
export class CheckpointProposalJob implements Traceable {
|
|
105
|
+
protected readonly log: Logger;
|
|
106
|
+
private readonly checkpointEventLog: Logger;
|
|
107
|
+
|
|
108
|
+
/** Tracks the fire-and-forget L1 submission promise so it can be awaited during shutdown. */
|
|
109
|
+
private pendingL1Submission: Promise<void> | undefined;
|
|
110
|
+
private readonly interruptibleSleep = new InterruptibleSleep();
|
|
111
|
+
private interrupted = false;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Chain state overrides built once per slot in proposeCheckpoint after the checkpoint is
|
|
115
|
+
* complete. Carries the pending parent override (archive + slot + fee header) for pipelining,
|
|
116
|
+
* or the invalidation pending override when rolling back. Consumed by
|
|
117
|
+
* publisher.validateBlockHeader before broadcast.
|
|
118
|
+
*/
|
|
119
|
+
private checkpointSimulationOverridesPlan?: SimulationOverridesPlan;
|
|
120
|
+
|
|
121
|
+
private getSignatureContext(): CoordinationSignatureContext {
|
|
122
|
+
return this.signatureContext;
|
|
123
|
+
}
|
|
124
|
+
|
|
62
125
|
constructor(
|
|
63
|
-
private readonly
|
|
64
|
-
private readonly
|
|
126
|
+
private readonly slotNow: SlotNumber,
|
|
127
|
+
private readonly targetSlot: SlotNumber,
|
|
128
|
+
private readonly targetEpoch: EpochNumber,
|
|
65
129
|
private readonly checkpointNumber: CheckpointNumber,
|
|
66
130
|
private readonly syncedToBlockNumber: BlockNumber,
|
|
131
|
+
private readonly checkpointedCheckpointNumber: CheckpointNumber,
|
|
67
132
|
// TODO(palla/mbps): Can we remove the proposer in favor of attestorAddress? Need to check fisherman-node flows.
|
|
68
133
|
private readonly proposer: EthAddress | undefined,
|
|
69
134
|
private readonly publisher: SequencerPublisher,
|
|
@@ -76,23 +141,75 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
76
141
|
private readonly l1ToL2MessageSource: L1ToL2MessageSource,
|
|
77
142
|
private readonly l2BlockSource: L2BlockSource,
|
|
78
143
|
private readonly checkpointsBuilder: FullNodeCheckpointsBuilder,
|
|
79
|
-
private readonly blockSink: L2BlockSink,
|
|
144
|
+
private readonly blockSink: L2BlockSink & ProposedCheckpointSink,
|
|
80
145
|
private readonly l1Constants: SequencerRollupConstants,
|
|
146
|
+
private readonly signatureContext: CoordinationSignatureContext,
|
|
81
147
|
protected config: ResolvedSequencerConfig,
|
|
82
148
|
protected timetable: SequencerTimetable,
|
|
83
149
|
private readonly slasherClient: SlasherClientInterface | undefined,
|
|
84
150
|
private readonly epochCache: EpochCache,
|
|
85
151
|
private readonly dateProvider: DateProvider,
|
|
86
152
|
private readonly metrics: SequencerMetrics,
|
|
87
|
-
private readonly
|
|
88
|
-
|
|
89
|
-
|
|
153
|
+
private readonly checkpointMetrics: CheckpointProposalJobMetricsRecorder,
|
|
154
|
+
protected readonly eventEmitter: TypedEventEmitter<SequencerEvents>,
|
|
155
|
+
private readonly setStateFn: (state: SequencerState, slot?: SlotNumber, timeReferenceSlot?: SlotNumber) => void,
|
|
90
156
|
public readonly tracer: Tracer,
|
|
91
|
-
|
|
157
|
+
bindings?: LoggerBindings,
|
|
158
|
+
private readonly proposedCheckpointData?: ProposedCheckpointData,
|
|
159
|
+
) {
|
|
160
|
+
this.log = createLogger('sequencer:checkpoint-proposal', {
|
|
161
|
+
...bindings,
|
|
162
|
+
instanceId: `slot-${this.slotNow}`,
|
|
163
|
+
});
|
|
164
|
+
this.checkpointEventLog = createLogger('sequencer:checkpoint-events', {
|
|
165
|
+
...bindings,
|
|
166
|
+
instanceId: `slot-${this.slotNow}`,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** Awaits the pending L1 submission if one is in progress. Call during shutdown. */
|
|
171
|
+
public async awaitPendingSubmission(): Promise<void> {
|
|
172
|
+
this.log.info('Awaiting pending L1 payload submission');
|
|
173
|
+
await this.pendingL1Submission;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** Interrupts job-owned waits, including the publisher's send-at-slot sleep, so shutdown can finish. */
|
|
177
|
+
public interrupt(): void {
|
|
178
|
+
this.interrupted = true;
|
|
179
|
+
this.interruptibleSleep.interrupt(true);
|
|
180
|
+
this.publisher.interrupt();
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
private async awaitInterruptibleSleep(ms: number): Promise<void> {
|
|
184
|
+
if (this.interrupted) {
|
|
185
|
+
throw new SequencerInterruptedError();
|
|
186
|
+
}
|
|
187
|
+
if (ms <= 0) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
try {
|
|
191
|
+
await this.interruptibleSleep.sleep(ms);
|
|
192
|
+
} catch (err) {
|
|
193
|
+
if (err instanceof InterruptError) {
|
|
194
|
+
throw new SequencerInterruptedError();
|
|
195
|
+
}
|
|
196
|
+
throw err;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
private logCheckpointEvent(eventName: string, message: string, fields: Record<string, unknown>): void {
|
|
201
|
+
this.checkpointEventLog.debug(message, {
|
|
202
|
+
eventName: `sequencer-checkpoint-${eventName}`,
|
|
203
|
+
...fields,
|
|
204
|
+
});
|
|
205
|
+
}
|
|
92
206
|
|
|
93
207
|
/**
|
|
94
208
|
* Executes the checkpoint proposal job.
|
|
95
|
-
*
|
|
209
|
+
* Builds blocks, assembles checkpoint, and broadcasts the proposal (blocking).
|
|
210
|
+
* Attestation collection, signing, and L1 submission are backgrounded so the
|
|
211
|
+
* work loop can return to IDLE immediately for consecutive slot proposals.
|
|
212
|
+
* Returns the built checkpoint if successful, undefined otherwise.
|
|
96
213
|
*/
|
|
97
214
|
@trackSpan('CheckpointProposalJob.execute')
|
|
98
215
|
public async execute(): Promise<Checkpoint | undefined> {
|
|
@@ -100,7 +217,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
100
217
|
// In fisherman mode, we simulate slashing but don't actually publish to L1
|
|
101
218
|
// These are constant for the whole slot, so we only enqueue them once
|
|
102
219
|
const votesPromises = new CheckpointVoter(
|
|
103
|
-
this.
|
|
220
|
+
this.targetSlot,
|
|
104
221
|
this.publisher,
|
|
105
222
|
this.attestorAddress,
|
|
106
223
|
this.validatorClient,
|
|
@@ -111,33 +228,302 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
111
228
|
this.log,
|
|
112
229
|
).enqueueVotes();
|
|
113
230
|
|
|
114
|
-
// Build
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
231
|
+
// Build blocks, assemble checkpoint, and broadcast proposal (BLOCKING).
|
|
232
|
+
// Returns after broadcast — attestation collection is deferred.
|
|
233
|
+
const broadcast = await this.proposeCheckpoint();
|
|
234
|
+
|
|
235
|
+
if (!broadcast) {
|
|
236
|
+
await Promise.all(votesPromises);
|
|
237
|
+
// Still submit votes even without a checkpoint.
|
|
238
|
+
// Under proposer pipelining, vote-offenses signatures are EIP-712-bound to `targetSlot`
|
|
239
|
+
// (the pipelined slot in which the multicall is expected to mine). Submitting at the
|
|
240
|
+
// wall-clock time would let the multicall mine in a different L2 slot, causing
|
|
241
|
+
// signature verification to fail silently inside Multicall3. Delay submission to the
|
|
242
|
+
// start of `targetSlot` so the tx mines in the slot the vote was signed for.
|
|
243
|
+
if (!this.config.fishermanMode) {
|
|
244
|
+
this.pendingL1Submission = this.publisher.sendRequestsAt(this.targetSlot).then(() => {});
|
|
245
|
+
}
|
|
246
|
+
return undefined;
|
|
122
247
|
}
|
|
123
248
|
|
|
249
|
+
const { checkpoint } = broadcast;
|
|
250
|
+
this.metrics.recordCheckpointProposalSuccess();
|
|
251
|
+
|
|
124
252
|
// Do not post anything to L1 if we are fishermen, but do perform L1 fee analysis
|
|
125
253
|
if (this.config.fishermanMode) {
|
|
126
254
|
await this.handleCheckpointEndAsFisherman(checkpoint);
|
|
127
|
-
return;
|
|
255
|
+
return checkpoint;
|
|
128
256
|
}
|
|
129
257
|
|
|
130
|
-
//
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
258
|
+
// Background the attestation → signing → L1 pipeline so the work loop is unblocked
|
|
259
|
+
this.pendingL1Submission = this.waitForAttestationsAndEnqueueSubmissionAsync(broadcast, votesPromises);
|
|
260
|
+
|
|
261
|
+
// Return the built checkpoint immediately — the work loop is now unblocked
|
|
262
|
+
return checkpoint;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Background pipeline: collects attestations, signs them, enqueues the checkpoint, and submits to L1.
|
|
267
|
+
* Runs as a fire-and-forget task stored in `pendingL1Submission` so the work loop is unblocked.
|
|
268
|
+
*/
|
|
269
|
+
private async waitForAttestationsAndEnqueueSubmissionAsync(
|
|
270
|
+
broadcast: CheckpointProposalBroadcast,
|
|
271
|
+
votesPromises: Promise<unknown>[],
|
|
272
|
+
): Promise<void> {
|
|
273
|
+
const { checkpoint } = broadcast;
|
|
274
|
+
|
|
275
|
+
try {
|
|
276
|
+
// Wait for all votes actions, enqueued at the beginning, to resolve
|
|
277
|
+
await Promise.all(votesPromises);
|
|
278
|
+
|
|
279
|
+
// Try to collect attestations from the committee
|
|
280
|
+
const signedAttestations = await this.getSignedCommitteeAttestations(broadcast);
|
|
281
|
+
|
|
282
|
+
// Wait for the previous checkpoint to land on L1 before submitting, so we can check it
|
|
283
|
+
// matches the proposed checkpoint we used as parent, and has valid attestations.
|
|
284
|
+
if (signedAttestations && (await this.waitForValidParentCheckpointOnL1())) {
|
|
285
|
+
await this.enqueueCheckpointForSubmission({ checkpoint, ...signedAttestations });
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// If we failed to collect attestations, at least check if we need to issue an invalidation
|
|
289
|
+
if (!signedAttestations && (await this.waitForSyncedL2SlotNumber(this.slotNow))) {
|
|
290
|
+
const validationStatus = await this.l2BlockSource.getPendingChainValidationStatus();
|
|
291
|
+
if (!validationStatus.valid) {
|
|
292
|
+
this.log.warn(
|
|
293
|
+
`Checkpoint ${validationStatus.checkpoint.checkpointNumber} has invalid attestations, enqueuing invalidation in spite of attestation collection failure`,
|
|
294
|
+
{ checkpoint: validationStatus.checkpoint, reason: validationStatus.reason },
|
|
295
|
+
);
|
|
296
|
+
await this.enqueueInvalidation(validationStatus);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// Send whatever was enqueued: votes + (propose | invalidation | nothing).
|
|
301
|
+
const l1Response = await this.publisher.sendRequestsAt(this.targetSlot);
|
|
302
|
+
const proposedAction = l1Response?.successfulActions.find(a => a === 'propose');
|
|
303
|
+
if (proposedAction) {
|
|
304
|
+
this.logCheckpointEvent('published', `Checkpoint published for slot ${this.targetSlot}`, {
|
|
305
|
+
slot: this.targetSlot,
|
|
306
|
+
checkpointNumber: this.checkpointNumber,
|
|
307
|
+
successfulActions: l1Response?.successfulActions,
|
|
308
|
+
sentActions: l1Response?.sentActions,
|
|
309
|
+
});
|
|
310
|
+
this.eventEmitter.emit('checkpoint-published', { checkpoint: this.checkpointNumber, slot: this.targetSlot });
|
|
311
|
+
const coinbase = checkpoint.header.coinbase;
|
|
312
|
+
await this.metrics.incFilledSlot(this.publisher.getSenderAddress().toString(), coinbase);
|
|
313
|
+
} else {
|
|
314
|
+
this.logCheckpointEvent('publish-failed', `Checkpoint publish failed for slot ${this.targetSlot}`, {
|
|
315
|
+
slot: this.targetSlot,
|
|
316
|
+
checkpointNumber: this.checkpointNumber,
|
|
317
|
+
successfulActions: l1Response?.successfulActions,
|
|
318
|
+
failedActions: l1Response?.failedActions,
|
|
319
|
+
sentActions: l1Response?.sentActions,
|
|
320
|
+
expiredActions: l1Response?.expiredActions,
|
|
321
|
+
reason: 'propose_action_not_successful',
|
|
322
|
+
});
|
|
323
|
+
this.log.warn(`Checkpoint publish failed for slot ${this.targetSlot}`, {
|
|
324
|
+
slot: this.targetSlot,
|
|
325
|
+
checkpointNumber: this.checkpointNumber,
|
|
326
|
+
successfulActions: l1Response?.successfulActions,
|
|
327
|
+
failedActions: l1Response?.failedActions,
|
|
328
|
+
sentActions: l1Response?.sentActions,
|
|
329
|
+
expiredActions: l1Response?.expiredActions,
|
|
330
|
+
reason: 'propose_action_not_successful',
|
|
331
|
+
});
|
|
332
|
+
this.eventEmitter.emit('checkpoint-publish-failed', { ...l1Response, slot: this.targetSlot });
|
|
333
|
+
this.metrics.recordPipelineDiscard();
|
|
334
|
+
}
|
|
335
|
+
} catch (err) {
|
|
336
|
+
if (err instanceof SequencerInterruptedError) {
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
this.logCheckpointEvent('publish-failed', `Checkpoint publish failed for slot ${this.targetSlot}`, {
|
|
340
|
+
slot: this.targetSlot,
|
|
341
|
+
checkpointNumber: this.checkpointNumber,
|
|
342
|
+
reason: err instanceof Error ? err.message : String(err),
|
|
343
|
+
});
|
|
344
|
+
this.log.error(`Background attestation/L1 pipeline failed for slot ${this.targetSlot}`, err, {
|
|
345
|
+
slot: this.targetSlot,
|
|
346
|
+
checkpointNumber: this.checkpointNumber,
|
|
347
|
+
reason: err instanceof Error ? err.message : String(err),
|
|
348
|
+
});
|
|
349
|
+
this.eventEmitter.emit('checkpoint-publish-failed', { slot: this.targetSlot });
|
|
350
|
+
this.metrics.recordPipelineDiscard();
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/** Enqueues the checkpoint for L1 submission. Called after pipeline sleep in execute(). */
|
|
355
|
+
private async enqueueCheckpointForSubmission(result: CheckpointProposalResult): Promise<void> {
|
|
356
|
+
const { checkpoint, attestations, attestationsSignature } = result;
|
|
357
|
+
|
|
358
|
+
// Build-frame deadlines are measured against `slotNow`; observers still see `targetSlot`.
|
|
359
|
+
this.setStateFn(SequencerState.PUBLISHING_CHECKPOINT, this.targetSlot, this.slotNow);
|
|
360
|
+
const aztecSlotDuration = this.l1Constants.slotDuration;
|
|
361
|
+
const submissionSlotStart = Number(getTimestampForSlot(this.targetSlot, this.l1Constants));
|
|
362
|
+
const txTimeoutAt = new Date((submissionSlotStart + aztecSlotDuration) * 1000);
|
|
363
|
+
|
|
364
|
+
// If we have been configured to potentially skip publishing checkpoint then roll the dice here
|
|
365
|
+
if (
|
|
366
|
+
this.config.skipPublishingCheckpointsPercent !== undefined &&
|
|
367
|
+
this.config.skipPublishingCheckpointsPercent > 0
|
|
368
|
+
) {
|
|
369
|
+
const roll = Math.max(0, randomInt(100));
|
|
370
|
+
if (roll < this.config.skipPublishingCheckpointsPercent) {
|
|
371
|
+
this.log.warn(
|
|
372
|
+
`Skipping publishing proposal for checkpoint ${checkpoint.number}. Configured percentage: ${this.config.skipPublishingCheckpointsPercent}, generated value: ${roll}`,
|
|
373
|
+
);
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
await this.publisher.enqueueProposeCheckpoint(checkpoint, attestations, attestationsSignature, {
|
|
379
|
+
txTimeoutAt,
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Wait until the archiver syncs past the given L2 slot number.
|
|
385
|
+
* The deadline is the end of `this.targetSlot`, beyond which any pipelined work would miss its
|
|
386
|
+
* L1 submission window and is no longer useful.
|
|
387
|
+
*/
|
|
388
|
+
private async waitForSyncedL2SlotNumber(waitForSlot: SlotNumber): Promise<boolean> {
|
|
389
|
+
const targetSlotStart = Number(getTimestampForSlot(this.targetSlot, this.l1Constants));
|
|
390
|
+
const targetSlotEndMs = (targetSlotStart + this.l1Constants.slotDuration) * 1000;
|
|
391
|
+
const syncDelayTolerance = this.l1Constants.ethereumSlotDuration * 2 * 1000;
|
|
392
|
+
const timeoutSeconds = Math.max(0.1, (targetSlotEndMs + syncDelayTolerance - this.dateProvider.now()) / 1000);
|
|
393
|
+
|
|
394
|
+
try {
|
|
395
|
+
const timer = new Timer();
|
|
396
|
+
while (true) {
|
|
397
|
+
const syncedSlot = await this.l2BlockSource.getSyncedL2SlotNumber();
|
|
398
|
+
if (syncedSlot !== undefined && syncedSlot >= waitForSlot) {
|
|
399
|
+
return true;
|
|
400
|
+
}
|
|
401
|
+
if (timeoutSeconds && timer.s() > timeoutSeconds) {
|
|
402
|
+
throw new TimeoutError(`Timeout awaiting archiver sync past slot ${waitForSlot}`);
|
|
403
|
+
}
|
|
404
|
+
await this.awaitInterruptibleSleep(ARCHIVER_SYNC_POLLING_MS);
|
|
405
|
+
}
|
|
406
|
+
} catch (err) {
|
|
407
|
+
if (err instanceof SequencerInterruptedError) {
|
|
408
|
+
throw err;
|
|
409
|
+
}
|
|
410
|
+
this.log.warn(
|
|
411
|
+
`Archiver did not sync L1 past slot ${waitForSlot} before slot ${this.targetSlot} expired, discarding pipelined work`,
|
|
412
|
+
{ checkpointNumber: this.checkpointNumber },
|
|
413
|
+
);
|
|
414
|
+
this.emitPipelinedCheckpointDiscarded('archiver-sync-timeout');
|
|
415
|
+
return false;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* Waits for the parent checkpoint to land on L1 before submitting a pipelined checkpoint.
|
|
421
|
+
* Polls until the archiver has synced L1 past the parent's slot, then verifies:
|
|
422
|
+
* - If we built on a proposed parent: it must have landed on L1 with matching hash and valid attestations.
|
|
423
|
+
* - If we built without a proposed parent: no new checkpoint must have appeared for that slot.
|
|
424
|
+
* If the parent has invalid attestations, enqueues an invalidation. Returns whether to proceed with the proposal.
|
|
425
|
+
*/
|
|
426
|
+
protected async waitForValidParentCheckpointOnL1(): Promise<boolean> {
|
|
427
|
+
if (this.config.skipWaitForValidParentCheckpointOnL1) {
|
|
428
|
+
this.log.warn(`Skipping waitForValidParentCheckpointOnL1 due to test configuration`, {
|
|
429
|
+
checkpointNumber: this.checkpointNumber,
|
|
430
|
+
});
|
|
431
|
+
return true;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
const parentCheckpointNumber = CheckpointNumber(this.checkpointNumber - 1);
|
|
435
|
+
|
|
436
|
+
// Wait until archiver has synced L1 past the parent's slot (slotNow)
|
|
437
|
+
if (!(await this.waitForSyncedL2SlotNumber(this.slotNow))) {
|
|
438
|
+
return false;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
const tips = await this.l2BlockSource.getL2Tips();
|
|
442
|
+
const checkpointedNumber = tips.checkpointed.checkpoint.number;
|
|
443
|
+
|
|
444
|
+
// We built on top of a proposed checkpoint. Verify it landed on L1 as expected.
|
|
445
|
+
if (this.proposedCheckpointData) {
|
|
446
|
+
// After syncing from L1 we see the chain tip has invalid attestations. This means the parent checkpoint was posted
|
|
447
|
+
// with invalid attestations, or it built on top of something with invalid attestations and didnt invalidate them.
|
|
448
|
+
// Either way, we thought our parent would be valid, so we have to throw away our work. But at least we'll try and
|
|
449
|
+
// invalidate on L1 so we clean up the chain for the next proposer. And we'll slash them, but that's handled elsewhere.
|
|
450
|
+
const validationStatus = await this.l2BlockSource.getPendingChainValidationStatus();
|
|
451
|
+
if (!validationStatus.valid) {
|
|
452
|
+
this.log.warn(
|
|
453
|
+
`Parent checkpoint ${parentCheckpointNumber} has invalid attestations, discarding pipelined work`,
|
|
454
|
+
{ checkpointNumber: this.checkpointNumber, reason: validationStatus.reason },
|
|
455
|
+
);
|
|
456
|
+
this.emitPipelinedCheckpointDiscarded('parent-invalid-attestations');
|
|
457
|
+
await this.enqueueInvalidation(validationStatus);
|
|
458
|
+
return false;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
// The pending chain is valid. But did the parent checkpoint land on L1 at all?
|
|
462
|
+
if (checkpointedNumber < parentCheckpointNumber) {
|
|
463
|
+
this.log.warn(`Parent checkpoint ${parentCheckpointNumber} did not land on L1, discarding pipelined work`, {
|
|
464
|
+
checkpointNumber: this.checkpointNumber,
|
|
465
|
+
checkpointedNumber,
|
|
466
|
+
});
|
|
467
|
+
this.emitPipelinedCheckpointDiscarded('parent-not-on-l1');
|
|
468
|
+
return false;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
// It landed. But is it the one we were expecting?
|
|
472
|
+
const expectedHash = this.proposedCheckpointData.header.hash().toString();
|
|
473
|
+
if (tips.checkpointed.checkpoint.hash !== expectedHash) {
|
|
474
|
+
this.log.warn(`Parent checkpoint ${parentCheckpointNumber} hash mismatch on L1, discarding pipelined work`, {
|
|
475
|
+
checkpointNumber: this.checkpointNumber,
|
|
476
|
+
expectedHash,
|
|
477
|
+
actualHash: tips.checkpointed.checkpoint.hash,
|
|
478
|
+
});
|
|
479
|
+
this.emitPipelinedCheckpointDiscarded('parent-hash-mismatch');
|
|
480
|
+
return false;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
return true;
|
|
484
|
+
} else {
|
|
485
|
+
// We didn't see a proposed checkpoint at build time, so we built on checkpointed parent from two slots ago.
|
|
486
|
+
// But if a new checkpoint for the previous slot appeared on L1 in the meantime, our checkpoint assumed the wrong parent,
|
|
487
|
+
// so we have to discard our work. This can happen if we're somehow cut off from p2p and fail to see the checkpoint
|
|
488
|
+
// proposal for the previous slot.
|
|
489
|
+
if (checkpointedNumber > parentCheckpointNumber) {
|
|
490
|
+
this.log.warn(
|
|
491
|
+
`Unexpected checkpoint ${checkpointedNumber} landed on L1 after we built on top of parent ${parentCheckpointNumber}, discarding pipelined work`,
|
|
492
|
+
{ checkpointNumber: this.checkpointNumber, checkpointedNumber },
|
|
493
|
+
);
|
|
494
|
+
this.emitPipelinedCheckpointDiscarded('unexpected-parent-appeared');
|
|
495
|
+
return false;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
return true;
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
/** Emits the pipelined-checkpoint-discarded event and records the metric. */
|
|
503
|
+
private emitPipelinedCheckpointDiscarded(reason: string): void {
|
|
504
|
+
this.metrics.recordPipelineParentCheckpointMismatch(reason);
|
|
505
|
+
this.eventEmitter.emit('pipelined-checkpoint-discarded', {
|
|
506
|
+
slot: this.targetSlot,
|
|
507
|
+
checkpointNumber: this.checkpointNumber,
|
|
508
|
+
reason,
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
/** Simulates and enqueues an invalidation request for the invalid parent checkpoint. */
|
|
513
|
+
private async enqueueInvalidation(validationStatus: ValidateCheckpointResult): Promise<void> {
|
|
514
|
+
if (this.config.skipInvalidateBlockAsProposer) {
|
|
515
|
+
this.log.warn(`Skipping checkpoint invalidation as proposer due to test configuration`);
|
|
516
|
+
return;
|
|
517
|
+
}
|
|
518
|
+
const invalidateRequest = await this.publisher.simulateInvalidateCheckpoint(validationStatus);
|
|
519
|
+
if (invalidateRequest) {
|
|
520
|
+
const submissionSlotStart = Number(getTimestampForSlot(this.targetSlot, this.l1Constants));
|
|
521
|
+
const txTimeoutAt = new Date((submissionSlotStart + this.l1Constants.slotDuration) * 1000);
|
|
522
|
+
this.publisher.enqueueInvalidateCheckpoint(invalidateRequest, { txTimeoutAt });
|
|
523
|
+
} else {
|
|
524
|
+
this.log.info(`Invalidation simulation returned undefined, checkpoint may have been removed already`, {
|
|
525
|
+
checkpointNumber: this.checkpointNumber,
|
|
526
|
+
});
|
|
141
527
|
}
|
|
142
528
|
}
|
|
143
529
|
|
|
@@ -145,51 +531,102 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
145
531
|
return {
|
|
146
532
|
// nullish operator needed for tests
|
|
147
533
|
[Attributes.COINBASE]: this.validatorClient.getCoinbaseForAttestor(this.attestorAddress)?.toString(),
|
|
148
|
-
[Attributes.SLOT_NUMBER]: this.
|
|
534
|
+
[Attributes.SLOT_NUMBER]: this.targetSlot,
|
|
149
535
|
};
|
|
150
536
|
})
|
|
151
|
-
private async proposeCheckpoint(): Promise<
|
|
537
|
+
private async proposeCheckpoint(): Promise<CheckpointProposalBroadcast | undefined> {
|
|
152
538
|
try {
|
|
539
|
+
const now = this.dateProvider.now();
|
|
540
|
+
if (this.proposedCheckpointData) {
|
|
541
|
+
// Measure against the wall-clock slot whose build window we are currently using.
|
|
542
|
+
// In pipelining mode `targetSlot` is intentionally one slot ahead, which makes the
|
|
543
|
+
// target-slot boundary a full slot away from the actual build start time.
|
|
544
|
+
const slotBoundaryMs = Number(getTimestampForSlot(this.slotNow, this.l1Constants)) * 1000;
|
|
545
|
+
this.checkpointMetrics.recordPipelinedCheckpointBuildStartOffsetFromSlotBoundary(now - slotBoundaryMs);
|
|
546
|
+
}
|
|
547
|
+
this.checkpointMetrics.startCheckpointTiming(now);
|
|
548
|
+
|
|
153
549
|
// Get operator configured coinbase and fee recipient for this attestor
|
|
154
550
|
const coinbase = this.validatorClient.getCoinbaseForAttestor(this.attestorAddress);
|
|
155
551
|
const feeRecipient = this.validatorClient.getFeeRecipientForAttestor(this.attestorAddress);
|
|
156
552
|
|
|
157
553
|
// Start the checkpoint
|
|
158
|
-
this.setStateFn(SequencerState.INITIALIZING_CHECKPOINT, this.
|
|
159
|
-
this.
|
|
554
|
+
this.setStateFn(SequencerState.INITIALIZING_CHECKPOINT, this.targetSlot, this.slotNow);
|
|
555
|
+
this.logCheckpointEvent('slot-started', `Starting checkpoint proposal for slot ${this.targetSlot}`, {
|
|
556
|
+
buildSlot: this.slotNow,
|
|
557
|
+
submissionSlot: this.targetSlot,
|
|
558
|
+
slot: this.targetSlot,
|
|
559
|
+
checkpointNumber: this.checkpointNumber,
|
|
560
|
+
proposer: this.proposer?.toString(),
|
|
561
|
+
attestorAddress: this.attestorAddress.toString(),
|
|
562
|
+
publisherAddress: this.publisher.getSenderAddress().toString(),
|
|
563
|
+
coinbase: coinbase.toString(),
|
|
564
|
+
});
|
|
565
|
+
this.metrics.incOpenSlot(this.targetSlot, this.proposer?.toString() ?? 'unknown');
|
|
160
566
|
|
|
161
567
|
// Enqueues checkpoint invalidation (constant for the whole slot)
|
|
162
568
|
if (this.invalidateCheckpoint && !this.config.skipInvalidateBlockAsProposer) {
|
|
163
569
|
this.publisher.enqueueInvalidateCheckpoint(this.invalidateCheckpoint);
|
|
164
570
|
}
|
|
165
571
|
|
|
166
|
-
//
|
|
572
|
+
// Build the simulation plan for this slot. When pipelining, this overrides L1's view of
|
|
573
|
+
// pending/archive/fee-header to "as if the proposed parent had landed", so both the
|
|
574
|
+
// mana-min-fee simulation (in the globals builder) and the pre-broadcast
|
|
575
|
+
// validateBlockHeader see the chain tip the eventual L1 send will see.
|
|
576
|
+
this.checkpointSimulationOverridesPlan = await buildCheckpointSimulationOverridesPlan({
|
|
577
|
+
checkpointNumber: this.checkpointNumber,
|
|
578
|
+
proposedCheckpointData: this.proposedCheckpointData,
|
|
579
|
+
invalidateToPendingCheckpointNumber: this.invalidateCheckpoint?.forcePendingCheckpointNumber,
|
|
580
|
+
checkpointedCheckpointNumber: this.checkpointedCheckpointNumber,
|
|
581
|
+
rollup: this.publisher.rollupContract,
|
|
582
|
+
signatureContext: this.signatureContext,
|
|
583
|
+
log: this.log,
|
|
584
|
+
});
|
|
585
|
+
|
|
167
586
|
const checkpointGlobalVariables = await this.globalsBuilder.buildCheckpointGlobalVariables(
|
|
168
587
|
coinbase,
|
|
169
588
|
feeRecipient,
|
|
170
|
-
this.
|
|
589
|
+
this.targetSlot,
|
|
590
|
+
this.checkpointSimulationOverridesPlan,
|
|
171
591
|
);
|
|
172
592
|
|
|
173
593
|
// Collect L1 to L2 messages for the checkpoint and compute their hash
|
|
174
594
|
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(this.checkpointNumber);
|
|
175
595
|
const inHash = computeInHashFromL1ToL2Messages(l1ToL2Messages);
|
|
176
596
|
|
|
177
|
-
// Collect the out hashes of all the checkpoints before this one in the same epoch
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
)
|
|
181
|
-
|
|
597
|
+
// Collect the out hashes of all the checkpoints before this one in the same epoch.
|
|
598
|
+
// Under pipelining the parent checkpoint may not be on L1 yet at build time, so the helper
|
|
599
|
+
// splices in the parent's checkpointOutHash from the locally-known proposed checkpoint so
|
|
600
|
+
// the resulting `epochOutHash` matches what validators (and L1) compute once the parent
|
|
601
|
+
// lands on L1.
|
|
602
|
+
const previousCheckpointOutHashes = await getPreviousCheckpointOutHashes({
|
|
603
|
+
blockSource: this.l2BlockSource,
|
|
604
|
+
epoch: this.targetEpoch,
|
|
605
|
+
checkpointNumber: this.checkpointNumber,
|
|
606
|
+
l1Constants: this.epochCache.getL1Constants(),
|
|
607
|
+
pipeliningEnabled: true,
|
|
608
|
+
proposedCheckpointData: this.proposedCheckpointData,
|
|
609
|
+
log: this.log,
|
|
610
|
+
});
|
|
611
|
+
|
|
612
|
+
// Anchor the modifier to the predicted parent fee header: L1 will apply it against
|
|
613
|
+
// that, not against the latest published checkpoint (which lags by one under pipelining).
|
|
614
|
+
const predictedParentEthPerFeeAssetE12 =
|
|
615
|
+
this.checkpointSimulationOverridesPlan?.pendingCheckpointState?.feeHeader?.ethPerFeeAsset;
|
|
616
|
+
const feeAssetPriceModifier = await this.publisher.getFeeAssetPriceModifier(predictedParentEthPerFeeAssetE12);
|
|
182
617
|
|
|
183
618
|
// Create a long-lived forked world state for the checkpoint builder
|
|
184
|
-
using fork = await this.worldState.fork(this.syncedToBlockNumber, { closeDelayMs: 12_000 });
|
|
619
|
+
await using fork = await this.worldState.fork(this.syncedToBlockNumber, { closeDelayMs: 12_000 });
|
|
185
620
|
|
|
186
621
|
// Create checkpoint builder for the entire slot
|
|
187
622
|
const checkpointBuilder = await this.checkpointsBuilder.startCheckpoint(
|
|
188
623
|
this.checkpointNumber,
|
|
189
624
|
checkpointGlobalVariables,
|
|
625
|
+
feeAssetPriceModifier,
|
|
190
626
|
l1ToL2Messages,
|
|
191
627
|
previousCheckpointOutHashes,
|
|
192
628
|
fork,
|
|
629
|
+
this.log.getBindings(),
|
|
193
630
|
);
|
|
194
631
|
|
|
195
632
|
// Options for the validator client when creating block and checkpoint proposals
|
|
@@ -200,11 +637,13 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
200
637
|
|
|
201
638
|
const checkpointProposalOptions: CheckpointProposalOptions = {
|
|
202
639
|
publishFullTxs: !!this.config.publishTxsWithProposals,
|
|
203
|
-
broadcastInvalidCheckpointProposal:
|
|
640
|
+
broadcastInvalidCheckpointProposal:
|
|
641
|
+
this.config.broadcastInvalidCheckpointProposalOnly || this.config.broadcastInvalidBlockProposal,
|
|
204
642
|
};
|
|
205
643
|
|
|
206
644
|
let blocksInCheckpoint: L2Block[] = [];
|
|
207
|
-
let blockPendingBroadcast:
|
|
645
|
+
let blockPendingBroadcast: BlockProposal | undefined = undefined;
|
|
646
|
+
const checkpointBuildTimer = new Timer();
|
|
208
647
|
|
|
209
648
|
try {
|
|
210
649
|
// Main loop: build blocks for the checkpoint
|
|
@@ -220,124 +659,177 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
220
659
|
// These errors are expected in HA mode, so we yield and let another HA node handle the slot
|
|
221
660
|
// The only distinction between the 2 errors is SlashingProtectionError throws when the payload is different,
|
|
222
661
|
// which is normal for block building (may have picked different txs)
|
|
223
|
-
if (err
|
|
224
|
-
this.log.info(`Checkpoint proposal for slot ${this.slot} already signed by another HA node, yielding`, {
|
|
225
|
-
slot: this.slot,
|
|
226
|
-
signedByNode: err.signedByNode,
|
|
227
|
-
});
|
|
228
|
-
return undefined;
|
|
229
|
-
}
|
|
230
|
-
if (err instanceof SlashingProtectionError) {
|
|
231
|
-
this.log.info(`Checkpoint proposal for slot ${this.slot} blocked by slashing protection, yielding`, {
|
|
232
|
-
slot: this.slot,
|
|
233
|
-
existingMessageHash: err.existingMessageHash,
|
|
234
|
-
attemptedMessageHash: err.attemptedMessageHash,
|
|
235
|
-
});
|
|
662
|
+
if (this.handleHASigningError(err, 'Block proposal')) {
|
|
236
663
|
return undefined;
|
|
237
664
|
}
|
|
238
665
|
throw err;
|
|
239
666
|
}
|
|
240
667
|
|
|
241
668
|
if (blocksInCheckpoint.length === 0) {
|
|
242
|
-
this.
|
|
243
|
-
|
|
669
|
+
this.logCheckpointEvent('build-failed', `Checkpoint build failed for slot ${this.targetSlot}`, {
|
|
670
|
+
slot: this.targetSlot,
|
|
671
|
+
checkpointNumber: this.checkpointNumber,
|
|
672
|
+
reason: 'no_blocks_built',
|
|
673
|
+
});
|
|
674
|
+
this.log.warn(`No blocks were built for slot ${this.targetSlot}`, {
|
|
675
|
+
slot: this.targetSlot,
|
|
676
|
+
checkpointNumber: this.checkpointNumber,
|
|
677
|
+
reason: 'no_blocks_built',
|
|
678
|
+
});
|
|
679
|
+
this.eventEmitter.emit('checkpoint-empty', { slot: this.targetSlot });
|
|
680
|
+
return undefined;
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
const minBlocksForCheckpoint = this.config.minBlocksForCheckpoint;
|
|
684
|
+
if (minBlocksForCheckpoint !== undefined && blocksInCheckpoint.length < minBlocksForCheckpoint) {
|
|
685
|
+
this.logCheckpointEvent('build-failed', `Checkpoint build failed for slot ${this.targetSlot}`, {
|
|
686
|
+
slot: this.targetSlot,
|
|
687
|
+
checkpointNumber: this.checkpointNumber,
|
|
688
|
+
blocksBuilt: blocksInCheckpoint.length,
|
|
689
|
+
minBlocksForCheckpoint,
|
|
690
|
+
reason: 'min_blocks_not_met',
|
|
691
|
+
});
|
|
692
|
+
this.log.warn(
|
|
693
|
+
`Checkpoint has fewer blocks than minimum (${blocksInCheckpoint.length} < ${minBlocksForCheckpoint}), skipping proposal`,
|
|
694
|
+
{
|
|
695
|
+
slot: this.targetSlot,
|
|
696
|
+
checkpointNumber: this.checkpointNumber,
|
|
697
|
+
blocksBuilt: blocksInCheckpoint.length,
|
|
698
|
+
minBlocksForCheckpoint,
|
|
699
|
+
reason: 'min_blocks_not_met',
|
|
700
|
+
},
|
|
701
|
+
);
|
|
244
702
|
return undefined;
|
|
245
703
|
}
|
|
246
704
|
|
|
247
705
|
// Assemble and broadcast the checkpoint proposal, including the last block that was not
|
|
248
706
|
// broadcasted yet, and wait to collect the committee attestations.
|
|
249
|
-
this.setStateFn(SequencerState.ASSEMBLING_CHECKPOINT, this.
|
|
707
|
+
this.setStateFn(SequencerState.ASSEMBLING_CHECKPOINT, this.targetSlot, this.slotNow);
|
|
250
708
|
const checkpoint = await checkpointBuilder.completeCheckpoint();
|
|
251
709
|
|
|
252
|
-
//
|
|
710
|
+
// Final validation: per-block limits are only checked if the operator set them explicitly.
|
|
711
|
+
// Otherwise, checkpoint-level budgets were already enforced by the redistribution logic.
|
|
712
|
+
try {
|
|
713
|
+
validateCheckpoint(checkpoint, {
|
|
714
|
+
rollupManaLimit: this.l1Constants.rollupManaLimit,
|
|
715
|
+
maxL2BlockGas: this.config.maxL2BlockGas,
|
|
716
|
+
maxDABlockGas: this.config.maxDABlockGas,
|
|
717
|
+
maxTxsPerBlock: this.config.maxTxsPerBlock,
|
|
718
|
+
maxTxsPerCheckpoint: this.config.maxTxsPerCheckpoint,
|
|
719
|
+
});
|
|
720
|
+
} catch (err) {
|
|
721
|
+
this.logCheckpointEvent('build-failed', `Checkpoint build failed for slot ${this.targetSlot}`, {
|
|
722
|
+
slot: this.targetSlot,
|
|
723
|
+
checkpointNumber: this.checkpointNumber,
|
|
724
|
+
blocksBuilt: blocksInCheckpoint.length,
|
|
725
|
+
reason: 'invalid_checkpoint',
|
|
726
|
+
checkpoint: checkpoint.header.toInspect(),
|
|
727
|
+
});
|
|
728
|
+
this.log.error(`Built an invalid checkpoint at slot ${this.slotNow} (skipping proposal)`, err, {
|
|
729
|
+
slot: this.targetSlot,
|
|
730
|
+
checkpointNumber: this.checkpointNumber,
|
|
731
|
+
blocksBuilt: blocksInCheckpoint.length,
|
|
732
|
+
reason: 'invalid_checkpoint',
|
|
733
|
+
checkpoint: checkpoint.header.toInspect(),
|
|
734
|
+
});
|
|
735
|
+
return undefined;
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
// Record checkpoint-level build metrics
|
|
739
|
+
this.checkpointMetrics.recordCheckpointBuild(
|
|
740
|
+
checkpointBuildTimer.ms(),
|
|
741
|
+
blocksInCheckpoint.length,
|
|
742
|
+
checkpoint.getStats().txCount,
|
|
743
|
+
Number(checkpoint.header.totalManaUsed.toBigInt()),
|
|
744
|
+
);
|
|
745
|
+
this.logCheckpointEvent('built', `Checkpoint built for slot ${this.targetSlot}`, {
|
|
746
|
+
slot: this.targetSlot,
|
|
747
|
+
buildSlot: this.slotNow,
|
|
748
|
+
checkpointNumber: this.checkpointNumber,
|
|
749
|
+
proposer: this.proposer?.toString(),
|
|
750
|
+
attestorAddress: this.attestorAddress.toString(),
|
|
751
|
+
publisherAddress: this.publisher.getSenderAddress().toString(),
|
|
752
|
+
blocksBuilt: blocksInCheckpoint.length,
|
|
753
|
+
txCount: checkpoint.getStats().txCount,
|
|
754
|
+
totalMana: Number(checkpoint.header.totalManaUsed.toBigInt()),
|
|
755
|
+
});
|
|
756
|
+
|
|
757
|
+
// In fisherman mode, return the checkpoint without broadcasting or collecting attestations
|
|
253
758
|
if (this.config.fishermanMode) {
|
|
254
759
|
this.log.info(
|
|
255
|
-
`Built checkpoint for slot ${this.
|
|
760
|
+
`Built checkpoint for slot ${this.targetSlot} with ${blocksInCheckpoint.length} blocks. ` +
|
|
256
761
|
`Skipping proposal in fisherman mode.`,
|
|
257
762
|
{
|
|
258
|
-
slot: this.
|
|
763
|
+
slot: this.targetSlot,
|
|
259
764
|
checkpoint: checkpoint.header.toInspect(),
|
|
260
765
|
blocksBuilt: blocksInCheckpoint.length,
|
|
261
766
|
},
|
|
262
767
|
);
|
|
263
768
|
this.metrics.recordCheckpointSuccess();
|
|
264
|
-
|
|
769
|
+
// Return a broadcast result with a dummy proposal — fisherman mode skips attestation collection
|
|
770
|
+
return { checkpoint, proposal: undefined!, blockProposedAt: this.dateProvider.now() };
|
|
265
771
|
}
|
|
266
772
|
|
|
267
|
-
//
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
}
|
|
773
|
+
// Validate the header against L1 state before broadcasting.
|
|
774
|
+
// If this fails the slot is aborted before any gossip work; state drift between here
|
|
775
|
+
// and the eventual L1 send is caught by the bundle simulate at send time.
|
|
776
|
+
try {
|
|
777
|
+
await this.publisher.validateBlockHeader(checkpoint.header, this.checkpointSimulationOverridesPlan);
|
|
778
|
+
} catch (err) {
|
|
779
|
+
this.log.error(`Pre-broadcast header validation failed for slot ${this.targetSlot}; aborting`, err, {
|
|
780
|
+
slot: this.targetSlot,
|
|
781
|
+
checkpointNumber: this.checkpointNumber,
|
|
782
|
+
});
|
|
783
|
+
this.metrics.recordCheckpointProposalFailed('header_validation_failed');
|
|
784
|
+
this.eventEmitter.emit('header-validation-failed', {
|
|
785
|
+
slot: this.targetSlot,
|
|
786
|
+
checkpointNumber: this.checkpointNumber,
|
|
787
|
+
reason: err instanceof Error ? err.message : String(err),
|
|
788
|
+
});
|
|
789
|
+
return undefined;
|
|
790
|
+
}
|
|
273
791
|
|
|
274
792
|
// Create the checkpoint proposal and broadcast it
|
|
275
793
|
const proposal = await this.validatorClient.createCheckpointProposal(
|
|
276
794
|
checkpoint.header,
|
|
277
795
|
checkpoint.archive.root,
|
|
278
|
-
|
|
796
|
+
this.checkpointNumber,
|
|
797
|
+
feeAssetPriceModifier,
|
|
798
|
+
blockPendingBroadcast,
|
|
279
799
|
this.proposer,
|
|
280
800
|
checkpointProposalOptions,
|
|
281
801
|
);
|
|
282
802
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
803
|
+
// Advance our own optimistic proposed-checkpoint tip locally before gossiping. Gossipsub
|
|
804
|
+
// doesn't echo our own messages back, so this is how the proposer makes its own proposed
|
|
805
|
+
// checkpoint visible for pipelining the next slot. Built from local checkpoint data — never
|
|
806
|
+
// from the broadcast proposal archive, which may be deliberately corrupted under test flags.
|
|
807
|
+
// Fail closed: if this throws, the outer catch aborts the slot before gossiping.
|
|
808
|
+
await this.syncProposedCheckpointToArchiver(checkpoint, blocksInCheckpoint.length, feeAssetPriceModifier);
|
|
289
809
|
|
|
290
|
-
this.
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
signer,
|
|
299
|
-
this.slot,
|
|
300
|
-
this.checkpointNumber,
|
|
301
|
-
);
|
|
302
|
-
} catch (err) {
|
|
303
|
-
// We shouldn't really get here since we yield to another HA node
|
|
304
|
-
// as soon as we see these errors when creating block proposals.
|
|
305
|
-
if (err instanceof DutyAlreadySignedError) {
|
|
306
|
-
this.log.info(`Attestations signature for slot ${this.slot} already signed by another HA node, yielding`, {
|
|
307
|
-
slot: this.slot,
|
|
308
|
-
signedByNode: err.signedByNode,
|
|
309
|
-
});
|
|
310
|
-
return undefined;
|
|
311
|
-
}
|
|
312
|
-
if (err instanceof SlashingProtectionError) {
|
|
313
|
-
this.log.info(`Attestations signature for slot ${this.slot} blocked by slashing protection, yielding`, {
|
|
314
|
-
slot: this.slot,
|
|
315
|
-
existingMessageHash: err.existingMessageHash,
|
|
316
|
-
attemptedMessageHash: err.attemptedMessageHash,
|
|
317
|
-
});
|
|
318
|
-
return undefined;
|
|
810
|
+
const blockProposedAt = this.dateProvider.now();
|
|
811
|
+
if (this.config.skipBroadcastCheckpointProposal) {
|
|
812
|
+
// Test-only: suppress the CheckpointProposal so peers never see a proposed checkpoint for
|
|
813
|
+
// this slot, but still broadcast the held last block standalone so peers' archivers ingest
|
|
814
|
+
// it as a proposed-but-uncheckpointed tip — the exact orphan-block state that
|
|
815
|
+
// pruneOrphanProposedBlocks / checkSync must handle.
|
|
816
|
+
if (blockPendingBroadcast && !this.config.skipBroadcastProposals) {
|
|
817
|
+
await this.p2pClient.broadcastProposal(blockPendingBroadcast);
|
|
319
818
|
}
|
|
320
|
-
|
|
819
|
+
} else if (!this.config.skipBroadcastProposals) {
|
|
820
|
+
await this.p2pClient.broadcastCheckpointProposal(proposal);
|
|
821
|
+
this.checkpointMetrics.noteCheckpointBroadcast(this.dateProvider.now());
|
|
321
822
|
}
|
|
322
823
|
|
|
323
|
-
//
|
|
324
|
-
|
|
325
|
-
const aztecSlotDuration = this.l1Constants.slotDuration;
|
|
326
|
-
const slotStartBuildTimestamp = this.getSlotStartBuildTimestamp();
|
|
327
|
-
const txTimeoutAt = new Date((slotStartBuildTimestamp + aztecSlotDuration) * 1000);
|
|
328
|
-
await this.publisher.enqueueProposeCheckpoint(checkpoint, attestations, attestationsSignature, {
|
|
329
|
-
txTimeoutAt,
|
|
330
|
-
forcePendingCheckpointNumber: this.invalidateCheckpoint?.forcePendingCheckpointNumber,
|
|
331
|
-
});
|
|
332
|
-
|
|
333
|
-
return checkpoint;
|
|
824
|
+
// Return immediately after broadcast — attestation collection happens in the background
|
|
825
|
+
return { checkpoint, proposal, blockProposedAt };
|
|
334
826
|
} catch (err) {
|
|
335
827
|
if (err && (err instanceof DutyAlreadySignedError || err instanceof SlashingProtectionError)) {
|
|
336
828
|
// swallow this error. It's already been logged by a function deeper in the stack
|
|
337
829
|
return undefined;
|
|
338
830
|
}
|
|
339
831
|
|
|
340
|
-
this.log.error(`Error building checkpoint at slot ${this.
|
|
832
|
+
this.log.error(`Error building checkpoint at slot ${this.targetSlot}`, err);
|
|
341
833
|
return undefined;
|
|
342
834
|
}
|
|
343
835
|
}
|
|
@@ -353,29 +845,35 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
353
845
|
blockProposalOptions: BlockProposalOptions,
|
|
354
846
|
): Promise<{
|
|
355
847
|
blocksInCheckpoint: L2Block[];
|
|
356
|
-
blockPendingBroadcast:
|
|
848
|
+
blockPendingBroadcast: BlockProposal | undefined;
|
|
357
849
|
}> {
|
|
358
850
|
const blocksInCheckpoint: L2Block[] = [];
|
|
359
851
|
const txHashesAlreadyIncluded = new Set<string>();
|
|
360
852
|
const initialBlockNumber = BlockNumber(this.syncedToBlockNumber + 1);
|
|
361
853
|
|
|
362
|
-
// Remaining blob fields available for blocks (checkpoint end marker already subtracted)
|
|
363
|
-
let remainingBlobFields = BLOBS_PER_CHECKPOINT * FIELDS_PER_BLOB - NUM_CHECKPOINT_END_MARKER_FIELDS;
|
|
364
|
-
|
|
365
854
|
// Last block in the checkpoint will usually be flagged as pending broadcast, so we send it along with the checkpoint proposal
|
|
366
|
-
let blockPendingBroadcast:
|
|
855
|
+
let blockPendingBroadcast: BlockProposal | undefined = undefined;
|
|
367
856
|
|
|
368
857
|
while (true) {
|
|
369
858
|
const blocksBuilt = blocksInCheckpoint.length;
|
|
370
|
-
const indexWithinCheckpoint = blocksBuilt;
|
|
859
|
+
const indexWithinCheckpoint = IndexWithinCheckpoint(blocksBuilt);
|
|
371
860
|
const blockNumber = BlockNumber(initialBlockNumber + blocksBuilt);
|
|
372
861
|
|
|
862
|
+
if (blocksBuilt >= this.config.maxBlocksPerCheckpoint) {
|
|
863
|
+
this.log.debug(`Reached max blocks per checkpoint`, {
|
|
864
|
+
slot: this.targetSlot,
|
|
865
|
+
blocksBuilt,
|
|
866
|
+
maxBlocksPerCheckpoint: this.config.maxBlocksPerCheckpoint,
|
|
867
|
+
});
|
|
868
|
+
break;
|
|
869
|
+
}
|
|
870
|
+
|
|
373
871
|
const secondsIntoSlot = this.getSecondsIntoSlot();
|
|
374
872
|
const timingInfo = this.timetable.canStartNextBlock(secondsIntoSlot);
|
|
375
873
|
|
|
376
874
|
if (!timingInfo.canStart) {
|
|
377
875
|
this.log.debug(`Not enough time left in slot to start another block`, {
|
|
378
|
-
slot: this.
|
|
876
|
+
slot: this.targetSlot,
|
|
379
877
|
blocksBuilt,
|
|
380
878
|
secondsIntoSlot,
|
|
381
879
|
});
|
|
@@ -394,24 +892,25 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
394
892
|
blockNumber,
|
|
395
893
|
indexWithinCheckpoint,
|
|
396
894
|
txHashesAlreadyIncluded,
|
|
397
|
-
remainingBlobFields,
|
|
398
895
|
});
|
|
399
896
|
|
|
400
|
-
if
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
897
|
+
// If we failed to build the block due to insufficient txs, we try again if there is still time left in the slot
|
|
898
|
+
if ('failure' in buildResult) {
|
|
899
|
+
// If this was the last subslot, or we're running with a single block per slot, we're done
|
|
900
|
+
if (timingInfo.isLastBlock || timingInfo.deadline === undefined) {
|
|
901
|
+
break;
|
|
902
|
+
}
|
|
903
|
+
// Otherwise, if there is still time for more blocks, we wait until the next subslot and try again
|
|
405
904
|
await this.waitUntilNextSubslot(timingInfo.deadline);
|
|
406
905
|
continue;
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
// If there was an error building the block, we just exit the loop and give up the rest of the slot.
|
|
909
|
+
// We don't want to risk building more blocks if something went wrong.
|
|
910
|
+
if ('error' in buildResult) {
|
|
412
911
|
if (!(buildResult.error instanceof SequencerInterruptedError)) {
|
|
413
|
-
this.log.warn(`Halting block building for slot ${this.
|
|
414
|
-
slot: this.
|
|
912
|
+
this.log.warn(`Halting block building for slot ${this.targetSlot}`, {
|
|
913
|
+
slot: this.targetSlot,
|
|
415
914
|
blocksBuilt,
|
|
416
915
|
error: buildResult.error,
|
|
417
916
|
});
|
|
@@ -419,45 +918,43 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
419
918
|
break;
|
|
420
919
|
}
|
|
421
920
|
|
|
422
|
-
const { block, usedTxs
|
|
423
|
-
|
|
921
|
+
const { block, usedTxs } = buildResult;
|
|
922
|
+
this.checkpointMetrics.noteCheckpointBlockBuilt(this.dateProvider.now(), {
|
|
923
|
+
isFirstBlock: blocksBuilt === 0,
|
|
924
|
+
isLastBlock: timingInfo.isLastBlock,
|
|
925
|
+
});
|
|
424
926
|
|
|
425
|
-
|
|
426
|
-
|
|
927
|
+
blocksInCheckpoint.push(block);
|
|
928
|
+
usedTxs.forEach(tx => txHashesAlreadyIncluded.add(tx.txHash.toString()));
|
|
427
929
|
|
|
428
|
-
//
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
930
|
+
// Sign the block proposal. This will throw if HA signing fails.
|
|
931
|
+
const proposal = await this.createBlockProposal(block, inHash, usedTxs, {
|
|
932
|
+
...blockProposalOptions,
|
|
933
|
+
broadcastInvalidBlockProposal:
|
|
934
|
+
blockProposalOptions.broadcastInvalidBlockProposal ||
|
|
935
|
+
block.indexWithinCheckpoint === this.config.invalidBlockProposalIndexWithinCheckpoint,
|
|
434
936
|
});
|
|
435
937
|
|
|
436
|
-
|
|
938
|
+
// Sync the proposed block to the archiver to make it available, only after we've managed to sign the proposal,
|
|
939
|
+
// so we avoid polluting our archive with a block that would fail.
|
|
940
|
+
// We wait for the sync to succeed, as this helps catch consistency errors, even if it means we lose some time for block-building.
|
|
941
|
+
// If this throws, we abort the entire checkpoint.
|
|
942
|
+
await this.syncProposedBlockToArchiver(block);
|
|
437
943
|
|
|
438
|
-
// If this is the last block,
|
|
944
|
+
// If this is the last block, do not broadcast it, since it will be included in the checkpoint proposal.
|
|
439
945
|
if (timingInfo.isLastBlock) {
|
|
440
|
-
this.log.verbose(`Completed final block ${blockNumber} for slot ${this.
|
|
441
|
-
slot: this.
|
|
946
|
+
this.log.verbose(`Completed final block ${blockNumber} for slot ${this.targetSlot}`, {
|
|
947
|
+
slot: this.targetSlot,
|
|
442
948
|
blockNumber,
|
|
443
949
|
blocksBuilt,
|
|
444
950
|
});
|
|
445
|
-
|
|
951
|
+
|
|
952
|
+
blockPendingBroadcast = proposal;
|
|
446
953
|
break;
|
|
447
954
|
}
|
|
448
955
|
|
|
449
|
-
//
|
|
450
|
-
|
|
451
|
-
if (!this.config.fishermanMode) {
|
|
452
|
-
const proposal = await this.validatorClient.createBlockProposal(
|
|
453
|
-
block.header,
|
|
454
|
-
block.indexWithinCheckpoint,
|
|
455
|
-
inHash,
|
|
456
|
-
block.archive.root,
|
|
457
|
-
usedTxs,
|
|
458
|
-
this.proposer,
|
|
459
|
-
blockProposalOptions,
|
|
460
|
-
);
|
|
956
|
+
// Once we have a signed proposal and the archiver agreed with our proposed block, then we broadcast it.
|
|
957
|
+
if (proposal && !this.config.skipBroadcastProposals) {
|
|
461
958
|
await this.p2pClient.broadcastProposal(proposal);
|
|
462
959
|
}
|
|
463
960
|
|
|
@@ -465,166 +962,267 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
465
962
|
await this.waitUntilNextSubslot(timingInfo.deadline);
|
|
466
963
|
}
|
|
467
964
|
|
|
468
|
-
this.log.verbose(`Block building loop completed for slot ${this.
|
|
469
|
-
slot: this.
|
|
965
|
+
this.log.verbose(`Block building loop completed for slot ${this.targetSlot}`, {
|
|
966
|
+
slot: this.targetSlot,
|
|
470
967
|
blocksBuilt: blocksInCheckpoint.length,
|
|
471
968
|
});
|
|
472
969
|
|
|
473
970
|
return { blocksInCheckpoint, blockPendingBroadcast };
|
|
474
971
|
}
|
|
475
972
|
|
|
973
|
+
/** Creates a block proposal for a given block via the validator client (unless in fisherman mode) */
|
|
974
|
+
private createBlockProposal(
|
|
975
|
+
block: L2Block,
|
|
976
|
+
inHash: Fr,
|
|
977
|
+
usedTxs: Tx[],
|
|
978
|
+
blockProposalOptions: BlockProposalOptions,
|
|
979
|
+
): Promise<BlockProposal | undefined> {
|
|
980
|
+
if (this.config.fishermanMode) {
|
|
981
|
+
this.log.info(`Skipping block proposal for block ${block.number} in fisherman mode`);
|
|
982
|
+
return Promise.resolve(undefined);
|
|
983
|
+
}
|
|
984
|
+
return this.validatorClient.createBlockProposal(
|
|
985
|
+
block.header,
|
|
986
|
+
this.checkpointNumber,
|
|
987
|
+
block.indexWithinCheckpoint,
|
|
988
|
+
inHash,
|
|
989
|
+
block.archive.root,
|
|
990
|
+
usedTxs,
|
|
991
|
+
this.proposer,
|
|
992
|
+
blockProposalOptions,
|
|
993
|
+
);
|
|
994
|
+
}
|
|
995
|
+
|
|
476
996
|
/** Sleeps until it is time to produce the next block in the slot */
|
|
477
997
|
@trackSpan('CheckpointProposalJob.waitUntilNextSubslot')
|
|
478
998
|
private async waitUntilNextSubslot(nextSubslotStart: number) {
|
|
479
|
-
this.setStateFn(SequencerState.WAITING_UNTIL_NEXT_BLOCK, this.
|
|
480
|
-
this.log.verbose(`Waiting until time for the next block at ${nextSubslotStart}s into slot`, {
|
|
999
|
+
this.setStateFn(SequencerState.WAITING_UNTIL_NEXT_BLOCK, this.targetSlot, this.slotNow);
|
|
1000
|
+
this.log.verbose(`Waiting until time for the next block at ${nextSubslotStart}s into slot`, {
|
|
1001
|
+
slot: this.targetSlot,
|
|
1002
|
+
});
|
|
481
1003
|
await this.waitUntilTimeInSlot(nextSubslotStart);
|
|
482
1004
|
}
|
|
483
1005
|
|
|
484
1006
|
/** Builds a single block. Called from the main block building loop. */
|
|
485
1007
|
@trackSpan('CheckpointProposalJob.buildSingleBlock')
|
|
486
|
-
|
|
1008
|
+
protected async buildSingleBlock(
|
|
487
1009
|
checkpointBuilder: CheckpointBuilder,
|
|
488
1010
|
opts: {
|
|
489
1011
|
forceCreate?: boolean;
|
|
490
1012
|
blockTimestamp: bigint;
|
|
491
1013
|
blockNumber: BlockNumber;
|
|
492
|
-
indexWithinCheckpoint:
|
|
1014
|
+
indexWithinCheckpoint: IndexWithinCheckpoint;
|
|
493
1015
|
buildDeadline: Date | undefined;
|
|
494
1016
|
txHashesAlreadyIncluded: Set<string>;
|
|
495
|
-
remainingBlobFields: number;
|
|
496
1017
|
},
|
|
497
|
-
): Promise<
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
indexWithinCheckpoint,
|
|
503
|
-
buildDeadline,
|
|
504
|
-
txHashesAlreadyIncluded,
|
|
505
|
-
remainingBlobFields,
|
|
506
|
-
} = opts;
|
|
1018
|
+
): Promise<
|
|
1019
|
+
{ block: L2Block; usedTxs: Tx[] } | { failure: 'insufficient-txs' | 'insufficient-valid-txs' } | { error: Error }
|
|
1020
|
+
> {
|
|
1021
|
+
const { blockTimestamp, forceCreate, blockNumber, indexWithinCheckpoint, buildDeadline, txHashesAlreadyIncluded } =
|
|
1022
|
+
opts;
|
|
507
1023
|
|
|
508
1024
|
this.log.verbose(
|
|
509
|
-
`Preparing block ${blockNumber} index ${indexWithinCheckpoint} at checkpoint ${this.checkpointNumber} for slot ${this.
|
|
1025
|
+
`Preparing block ${blockNumber} index ${indexWithinCheckpoint} at checkpoint ${this.checkpointNumber} for slot ${this.targetSlot}`,
|
|
510
1026
|
{ ...checkpointBuilder.getConstantData(), ...opts },
|
|
511
1027
|
);
|
|
512
1028
|
|
|
513
1029
|
try {
|
|
514
1030
|
// Wait until we have enough txs to build the block
|
|
515
|
-
const minTxs = this.
|
|
516
|
-
const { availableTxs, canStartBuilding } = await this.waitForMinTxs(opts);
|
|
1031
|
+
const { availableTxs, canStartBuilding, minTxs } = await this.waitForMinTxs(opts);
|
|
517
1032
|
if (!canStartBuilding) {
|
|
1033
|
+
this.logCheckpointEvent('block-build-failed', `Block build failed for slot ${this.targetSlot}`, {
|
|
1034
|
+
reason: 'insufficient_txs',
|
|
1035
|
+
blockNumber,
|
|
1036
|
+
slot: this.targetSlot,
|
|
1037
|
+
checkpointNumber: this.checkpointNumber,
|
|
1038
|
+
indexWithinCheckpoint,
|
|
1039
|
+
availableTxs,
|
|
1040
|
+
minTxs,
|
|
1041
|
+
});
|
|
518
1042
|
this.log.warn(
|
|
519
|
-
`Not enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.
|
|
520
|
-
{
|
|
1043
|
+
`Not enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.targetSlot} (got ${availableTxs} txs but needs ${minTxs})`,
|
|
1044
|
+
{
|
|
1045
|
+
reason: 'insufficient_txs',
|
|
1046
|
+
blockNumber,
|
|
1047
|
+
slot: this.targetSlot,
|
|
1048
|
+
checkpointNumber: this.checkpointNumber,
|
|
1049
|
+
indexWithinCheckpoint,
|
|
1050
|
+
availableTxs,
|
|
1051
|
+
minTxs,
|
|
1052
|
+
},
|
|
521
1053
|
);
|
|
522
|
-
this.eventEmitter.emit('block-tx-count-check-failed', { minTxs, availableTxs, slot: this.
|
|
1054
|
+
this.eventEmitter.emit('block-tx-count-check-failed', { minTxs, availableTxs, slot: this.targetSlot });
|
|
523
1055
|
this.metrics.recordBlockProposalFailed('insufficient_txs');
|
|
524
|
-
return
|
|
1056
|
+
return { failure: 'insufficient-txs' };
|
|
525
1057
|
}
|
|
526
1058
|
|
|
527
1059
|
// Create iterator to pending txs. We filter out txs already included in previous blocks in the checkpoint
|
|
528
1060
|
// just in case p2p failed to sync the provisional block and didn't get to remove those txs from the mempool yet.
|
|
529
1061
|
const pendingTxs = filter(
|
|
530
|
-
this.p2pClient.
|
|
1062
|
+
this.p2pClient.iterateEligiblePendingTxs(),
|
|
531
1063
|
tx => !txHashesAlreadyIncluded.has(tx.txHash.toString()),
|
|
532
1064
|
);
|
|
533
1065
|
|
|
534
1066
|
this.log.debug(
|
|
535
|
-
`Building block ${blockNumber} at index ${indexWithinCheckpoint} for slot ${this.
|
|
536
|
-
{ slot: this.
|
|
1067
|
+
`Building block ${blockNumber} at index ${indexWithinCheckpoint} for slot ${this.targetSlot} with ${availableTxs} available txs`,
|
|
1068
|
+
{ slot: this.targetSlot, blockNumber, indexWithinCheckpoint },
|
|
537
1069
|
);
|
|
538
|
-
this.setStateFn(SequencerState.CREATING_BLOCK, this.
|
|
539
|
-
|
|
540
|
-
// Calculate blob fields limit for txs (remaining capacity - this block's end overhead)
|
|
541
|
-
const blockEndOverhead = getNumBlockEndBlobFields(indexWithinCheckpoint === 0);
|
|
542
|
-
const maxBlobFieldsForTxs = remainingBlobFields - blockEndOverhead;
|
|
1070
|
+
this.setStateFn(SequencerState.CREATING_BLOCK, this.targetSlot, this.slotNow);
|
|
543
1071
|
|
|
544
|
-
|
|
1072
|
+
// Per-block limits are operator overrides (from SEQ_MAX_L2_BLOCK_GAS etc.) further capped
|
|
1073
|
+
// by remaining checkpoint-level budgets inside CheckpointBuilder before each block is built.
|
|
1074
|
+
// minValidTxs is passed into the builder so it can reject the block *before* updating state.
|
|
1075
|
+
const minValidTxs = forceCreate ? 0 : (this.config.minValidTxsPerBlock ?? minTxs);
|
|
1076
|
+
const blockBuilderOptions: BlockBuilderOptions = {
|
|
545
1077
|
maxTransactions: this.config.maxTxsPerBlock,
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
1078
|
+
maxBlockGas:
|
|
1079
|
+
this.config.maxL2BlockGas !== undefined || this.config.maxDABlockGas !== undefined
|
|
1080
|
+
? new Gas(this.config.maxDABlockGas ?? Infinity, this.config.maxL2BlockGas ?? Infinity)
|
|
1081
|
+
: undefined,
|
|
549
1082
|
deadline: buildDeadline,
|
|
1083
|
+
isBuildingProposal: true,
|
|
1084
|
+
minValidTxs,
|
|
1085
|
+
maxBlocksPerCheckpoint: this.timetable.maxNumberOfBlocks,
|
|
1086
|
+
perBlockAllocationMultiplier: this.config.perBlockAllocationMultiplier,
|
|
550
1087
|
};
|
|
551
1088
|
|
|
552
|
-
// Actually build the block by executing txs
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
usedTxBlobFields,
|
|
563
|
-
} = await checkpointBuilder.buildBlock(pendingTxs, blockNumber, blockTimestamp, blockBuilderOptions);
|
|
564
|
-
const blockBuildDuration = workTimer.ms();
|
|
1089
|
+
// Actually build the block by executing txs. The builder throws InsufficientValidTxsError
|
|
1090
|
+
// if the number of successfully processed txs is below minValidTxs, ensuring state is not
|
|
1091
|
+
// updated for blocks that will be discarded.
|
|
1092
|
+
const buildResult = await this.buildSingleBlockWithCheckpointBuilder(
|
|
1093
|
+
checkpointBuilder,
|
|
1094
|
+
pendingTxs,
|
|
1095
|
+
blockNumber,
|
|
1096
|
+
blockTimestamp,
|
|
1097
|
+
blockBuilderOptions,
|
|
1098
|
+
);
|
|
565
1099
|
|
|
566
1100
|
// If any txs failed during execution, drop them from the mempool so we don't pick them up again
|
|
567
|
-
await this.dropFailedTxsFromP2P(failedTxs);
|
|
1101
|
+
await this.dropFailedTxsFromP2P(buildResult.failedTxs);
|
|
568
1102
|
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
1103
|
+
if (buildResult.status === 'insufficient-valid-txs') {
|
|
1104
|
+
this.logCheckpointEvent('block-build-failed', `Block build failed for slot ${this.targetSlot}`, {
|
|
1105
|
+
reason: 'insufficient_valid_txs',
|
|
1106
|
+
slot: this.targetSlot,
|
|
1107
|
+
checkpointNumber: this.checkpointNumber,
|
|
1108
|
+
blockNumber,
|
|
1109
|
+
numTxs: buildResult.processedCount,
|
|
1110
|
+
indexWithinCheckpoint,
|
|
1111
|
+
minValidTxs,
|
|
1112
|
+
});
|
|
573
1113
|
this.log.warn(
|
|
574
|
-
`Block ${blockNumber} at index ${indexWithinCheckpoint} on slot ${this.
|
|
575
|
-
{
|
|
1114
|
+
`Block ${blockNumber} at index ${indexWithinCheckpoint} on slot ${this.targetSlot} has too few valid txs to be proposed`,
|
|
1115
|
+
{
|
|
1116
|
+
reason: 'insufficient_valid_txs',
|
|
1117
|
+
slot: this.targetSlot,
|
|
1118
|
+
checkpointNumber: this.checkpointNumber,
|
|
1119
|
+
blockNumber,
|
|
1120
|
+
numTxs: buildResult.processedCount,
|
|
1121
|
+
indexWithinCheckpoint,
|
|
1122
|
+
minValidTxs,
|
|
1123
|
+
},
|
|
576
1124
|
);
|
|
577
|
-
this.eventEmitter.emit('block-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
slot: this.slot,
|
|
1125
|
+
this.eventEmitter.emit('block-build-failed', {
|
|
1126
|
+
reason: `Insufficient valid txs`,
|
|
1127
|
+
slot: this.targetSlot,
|
|
581
1128
|
});
|
|
582
1129
|
this.metrics.recordBlockProposalFailed('insufficient_valid_txs');
|
|
583
|
-
return
|
|
1130
|
+
return { failure: 'insufficient-valid-txs' };
|
|
584
1131
|
}
|
|
585
1132
|
|
|
586
1133
|
// Block creation succeeded, emit stats and metrics
|
|
1134
|
+
const { block, publicProcessorDuration, usedTxs, blockBuildDuration, numTxs } = buildResult;
|
|
1135
|
+
|
|
587
1136
|
const blockStats = {
|
|
588
1137
|
eventName: 'l2-block-built',
|
|
589
1138
|
duration: blockBuildDuration,
|
|
590
1139
|
publicProcessDuration: publicProcessorDuration,
|
|
591
|
-
rollupCircuitsDuration: blockBuildingTimer.ms(),
|
|
592
1140
|
...block.getStats(),
|
|
593
1141
|
} satisfies L2BlockBuiltStats;
|
|
594
1142
|
|
|
595
1143
|
const blockHash = await block.hash();
|
|
596
1144
|
const txHashes = block.body.txEffects.map(tx => tx.txHash);
|
|
597
|
-
const manaPerSec =
|
|
1145
|
+
const manaPerSec = block.header.totalManaUsed.toNumberUnsafe() / (blockBuildDuration / 1000);
|
|
598
1146
|
|
|
599
1147
|
this.log.info(
|
|
600
|
-
`Built block ${block.number} at checkpoint ${this.checkpointNumber} for slot ${this.
|
|
1148
|
+
`Built block ${block.number} at checkpoint ${this.checkpointNumber} for slot ${this.targetSlot} with ${numTxs} txs`,
|
|
601
1149
|
{ blockHash, txHashes, manaPerSec, ...blockStats },
|
|
602
1150
|
);
|
|
603
1151
|
|
|
604
|
-
|
|
605
|
-
|
|
1152
|
+
// `slot` is the target/submission slot (may be one ahead when pipelining),
|
|
1153
|
+
// `buildSlot` is the wall-clock slot during which the block was actually built.
|
|
1154
|
+
this.eventEmitter.emit('block-proposed', {
|
|
1155
|
+
blockNumber: block.number,
|
|
1156
|
+
blockHash,
|
|
1157
|
+
checkpointNumber: this.checkpointNumber,
|
|
1158
|
+
indexWithinCheckpoint: block.indexWithinCheckpoint,
|
|
1159
|
+
slot: this.targetSlot,
|
|
1160
|
+
buildSlot: this.slotNow,
|
|
1161
|
+
});
|
|
1162
|
+
this.metrics.recordBuiltBlock(blockBuildDuration, block.header.totalManaUsed.toNumberUnsafe(), this.targetSlot);
|
|
606
1163
|
|
|
607
|
-
return { block, usedTxs
|
|
1164
|
+
return { block, usedTxs };
|
|
608
1165
|
} catch (err: any) {
|
|
609
|
-
this.eventEmitter.emit('block-build-failed', {
|
|
610
|
-
|
|
1166
|
+
this.eventEmitter.emit('block-build-failed', {
|
|
1167
|
+
reason: err.message,
|
|
1168
|
+
slot: this.targetSlot,
|
|
1169
|
+
});
|
|
1170
|
+
this.logCheckpointEvent('block-build-failed', `Block build failed for slot ${this.targetSlot}`, {
|
|
1171
|
+
reason: err instanceof Error ? err.message : String(err),
|
|
1172
|
+
slot: this.targetSlot,
|
|
1173
|
+
checkpointNumber: this.checkpointNumber,
|
|
1174
|
+
blockNumber,
|
|
1175
|
+
});
|
|
1176
|
+
this.log.error(`Error building block`, err, {
|
|
1177
|
+
reason: err instanceof Error ? err.message : String(err),
|
|
1178
|
+
slot: this.targetSlot,
|
|
1179
|
+
checkpointNumber: this.checkpointNumber,
|
|
1180
|
+
blockNumber,
|
|
1181
|
+
});
|
|
611
1182
|
this.metrics.recordBlockProposalFailed(err.name || 'unknown_error');
|
|
612
1183
|
this.metrics.recordFailedBlock();
|
|
613
1184
|
return { error: err };
|
|
614
1185
|
}
|
|
615
1186
|
}
|
|
616
1187
|
|
|
1188
|
+
/** Uses the checkpoint builder to build a block, catching InsufficientValidTxsError. */
|
|
1189
|
+
private async buildSingleBlockWithCheckpointBuilder(
|
|
1190
|
+
checkpointBuilder: CheckpointBuilder,
|
|
1191
|
+
pendingTxs: AsyncIterable<Tx>,
|
|
1192
|
+
blockNumber: BlockNumber,
|
|
1193
|
+
blockTimestamp: bigint,
|
|
1194
|
+
blockBuilderOptions: BlockBuilderOptions,
|
|
1195
|
+
) {
|
|
1196
|
+
try {
|
|
1197
|
+
const workTimer = new Timer();
|
|
1198
|
+
const result = await checkpointBuilder.buildBlock(pendingTxs, blockNumber, blockTimestamp, blockBuilderOptions);
|
|
1199
|
+
const blockBuildDuration = workTimer.ms();
|
|
1200
|
+
return { ...result, blockBuildDuration, status: 'success' as const };
|
|
1201
|
+
} catch (err: unknown) {
|
|
1202
|
+
if (isErrorClass(err, InsufficientValidTxsError)) {
|
|
1203
|
+
return {
|
|
1204
|
+
failedTxs: err.failedTxs,
|
|
1205
|
+
processedCount: err.processedCount,
|
|
1206
|
+
status: 'insufficient-valid-txs' as const,
|
|
1207
|
+
};
|
|
1208
|
+
}
|
|
1209
|
+
throw err;
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
|
|
617
1213
|
/** Waits until minTxs are available on the pool for building a block. */
|
|
618
1214
|
@trackSpan('CheckpointProposalJob.waitForMinTxs')
|
|
619
1215
|
private async waitForMinTxs(opts: {
|
|
620
1216
|
forceCreate?: boolean;
|
|
621
1217
|
blockNumber: BlockNumber;
|
|
622
|
-
indexWithinCheckpoint:
|
|
1218
|
+
indexWithinCheckpoint: IndexWithinCheckpoint;
|
|
623
1219
|
buildDeadline: Date | undefined;
|
|
624
|
-
}): Promise<{ canStartBuilding: boolean; availableTxs: number }> {
|
|
625
|
-
const minTxs = this.config.minTxsPerBlock;
|
|
1220
|
+
}): Promise<{ canStartBuilding: boolean; availableTxs: number; minTxs: number }> {
|
|
626
1221
|
const { indexWithinCheckpoint, blockNumber, buildDeadline, forceCreate } = opts;
|
|
627
1222
|
|
|
1223
|
+
// We only allow a block with 0 txs in the first block of the checkpoint
|
|
1224
|
+
const minTxs = indexWithinCheckpoint > 0 && this.config.minTxsPerBlock === 0 ? 1 : this.config.minTxsPerBlock;
|
|
1225
|
+
|
|
628
1226
|
// Deadline is undefined if we are not enforcing the timetable, meaning we'll exit immediately when out of time
|
|
629
1227
|
const startBuildingDeadline = buildDeadline
|
|
630
1228
|
? new Date(buildDeadline.getTime() - this.timetable.minExecutionTime * 1000)
|
|
@@ -636,20 +1234,50 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
636
1234
|
// If we're past deadline, or we have no deadline, give up
|
|
637
1235
|
const now = this.dateProvider.nowAsDate();
|
|
638
1236
|
if (startBuildingDeadline === undefined || now >= startBuildingDeadline) {
|
|
639
|
-
return { canStartBuilding: false, availableTxs
|
|
1237
|
+
return { canStartBuilding: false, availableTxs, minTxs };
|
|
640
1238
|
}
|
|
641
1239
|
|
|
642
1240
|
// Wait a bit before checking again
|
|
643
|
-
this.setStateFn(SequencerState.WAITING_FOR_TXS, this.
|
|
1241
|
+
this.setStateFn(SequencerState.WAITING_FOR_TXS, this.targetSlot, this.slotNow);
|
|
644
1242
|
this.log.verbose(
|
|
645
|
-
`Waiting for enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.
|
|
646
|
-
{ blockNumber, slot: this.
|
|
1243
|
+
`Waiting for enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.targetSlot} (have ${availableTxs} but need ${minTxs})`,
|
|
1244
|
+
{ blockNumber, slot: this.targetSlot, indexWithinCheckpoint },
|
|
647
1245
|
);
|
|
648
|
-
await
|
|
1246
|
+
await this.waitForTxsPollingInterval();
|
|
649
1247
|
availableTxs = await this.p2pClient.getPendingTxCount();
|
|
650
1248
|
}
|
|
651
1249
|
|
|
652
|
-
return { canStartBuilding: true, availableTxs };
|
|
1250
|
+
return { canStartBuilding: true, availableTxs, minTxs };
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
private async getSignedCommitteeAttestations(
|
|
1254
|
+
broadcast: CheckpointProposalBroadcast,
|
|
1255
|
+
): Promise<{ attestations: CommitteeAttestationsAndSigners; attestationsSignature: Signature } | undefined> {
|
|
1256
|
+
const { proposal, blockProposedAt } = broadcast;
|
|
1257
|
+
this.setStateFn(SequencerState.COLLECTING_ATTESTATIONS, this.targetSlot, this.slotNow);
|
|
1258
|
+
const attestations = await this.waitForAttestations(proposal);
|
|
1259
|
+
if (!attestations) {
|
|
1260
|
+
return undefined;
|
|
1261
|
+
}
|
|
1262
|
+
this.checkpointMetrics.recordCheckpointAttestationDelay(this.dateProvider.now() - blockProposedAt);
|
|
1263
|
+
|
|
1264
|
+
// Proposer must sign over the attestations before pushing them to L1
|
|
1265
|
+
const signer = this.proposer ?? this.publisher.getSenderAddress();
|
|
1266
|
+
try {
|
|
1267
|
+
const attestationsSignature = await this.validatorClient.signAttestationsAndSigners(
|
|
1268
|
+
attestations,
|
|
1269
|
+
signer,
|
|
1270
|
+
this.targetSlot,
|
|
1271
|
+
this.checkpointNumber,
|
|
1272
|
+
);
|
|
1273
|
+
return { attestations, attestationsSignature };
|
|
1274
|
+
} catch (err) {
|
|
1275
|
+
if (this.handleHASigningError(err, 'Attestations signature')) {
|
|
1276
|
+
return;
|
|
1277
|
+
}
|
|
1278
|
+
this.log.error(`Error signing attestations for checkpoint proposal at slot ${proposal.slotNumber}`, err);
|
|
1279
|
+
return undefined;
|
|
1280
|
+
}
|
|
653
1281
|
}
|
|
654
1282
|
|
|
655
1283
|
/**
|
|
@@ -657,10 +1285,12 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
657
1285
|
* This is run after all blocks for the checkpoint have been built.
|
|
658
1286
|
*/
|
|
659
1287
|
@trackSpan('CheckpointProposalJob.waitForAttestations')
|
|
660
|
-
private async waitForAttestations(
|
|
1288
|
+
private async waitForAttestations(
|
|
1289
|
+
proposal: CheckpointProposal,
|
|
1290
|
+
): Promise<CommitteeAttestationsAndSigners | undefined> {
|
|
661
1291
|
if (this.config.fishermanMode) {
|
|
662
1292
|
this.log.debug('Skipping attestation collection in fisherman mode');
|
|
663
|
-
return CommitteeAttestationsAndSigners.empty();
|
|
1293
|
+
return CommitteeAttestationsAndSigners.empty(this.getSignatureContext());
|
|
664
1294
|
}
|
|
665
1295
|
|
|
666
1296
|
const slotNumber = proposal.slotNumber;
|
|
@@ -670,23 +1300,29 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
670
1300
|
throw new Error('No committee when collecting attestations');
|
|
671
1301
|
} else if (committee.length === 0) {
|
|
672
1302
|
this.log.verbose(`Attesting committee is empty`);
|
|
673
|
-
return CommitteeAttestationsAndSigners.empty();
|
|
1303
|
+
return CommitteeAttestationsAndSigners.empty(this.getSignatureContext());
|
|
674
1304
|
} else {
|
|
675
1305
|
this.log.debug(`Attesting committee length is ${committee.length}`, { committee });
|
|
676
1306
|
}
|
|
677
1307
|
|
|
678
|
-
const numberOfRequiredAttestations =
|
|
1308
|
+
const numberOfRequiredAttestations = computeQuorum(committee.length);
|
|
679
1309
|
|
|
680
1310
|
if (this.config.skipCollectingAttestations) {
|
|
681
1311
|
this.log.warn('Skipping attestation collection as per config (attesting with own keys only)');
|
|
682
|
-
const attestations = await this.validatorClient?.collectOwnAttestations(proposal);
|
|
683
|
-
|
|
1312
|
+
const attestations = await this.validatorClient?.collectOwnAttestations(proposal, this.checkpointNumber);
|
|
1313
|
+
this.logCheckpointAttestations('collected', committee, attestations ?? [], numberOfRequiredAttestations, {
|
|
1314
|
+
reason: 'collect_own_only',
|
|
1315
|
+
});
|
|
1316
|
+
return new CommitteeAttestationsAndSigners(
|
|
1317
|
+
orderAttestations(attestations ?? [], committee),
|
|
1318
|
+
this.getSignatureContext(),
|
|
1319
|
+
);
|
|
684
1320
|
}
|
|
685
1321
|
|
|
686
1322
|
const attestationTimeAllowed = this.config.enforceTimeTable
|
|
687
|
-
? this.timetable.
|
|
1323
|
+
? this.timetable.getCheckpointAttestationDeadline()
|
|
688
1324
|
: this.l1Constants.slotDuration;
|
|
689
|
-
const attestationDeadline = new Date(this.
|
|
1325
|
+
const attestationDeadline = new Date((this.getSlotStartBuildTimestamp() + attestationTimeAllowed) * 1000);
|
|
690
1326
|
|
|
691
1327
|
this.metrics.recordRequiredAttestations(numberOfRequiredAttestations, attestationTimeAllowed);
|
|
692
1328
|
|
|
@@ -697,29 +1333,89 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
697
1333
|
proposal,
|
|
698
1334
|
numberOfRequiredAttestations,
|
|
699
1335
|
attestationDeadline,
|
|
1336
|
+
this.checkpointNumber,
|
|
700
1337
|
);
|
|
701
1338
|
|
|
702
1339
|
collectedAttestationsCount = attestations.length;
|
|
703
1340
|
|
|
1341
|
+
// Trim attestations to minimum required to save L1 calldata gas
|
|
1342
|
+
const localAddresses = this.validatorClient.getValidatorAddresses();
|
|
1343
|
+
const trimmed = trimAttestations(
|
|
1344
|
+
attestations,
|
|
1345
|
+
numberOfRequiredAttestations,
|
|
1346
|
+
this.attestorAddress,
|
|
1347
|
+
localAddresses,
|
|
1348
|
+
);
|
|
1349
|
+
if (trimmed.length < attestations.length) {
|
|
1350
|
+
this.log.debug(`Trimmed attestations from ${attestations.length} to ${trimmed.length} for L1 submission`);
|
|
1351
|
+
}
|
|
1352
|
+
|
|
704
1353
|
// Rollup contract requires that the signatures are provided in the order of the committee
|
|
705
|
-
const sorted = orderAttestations(
|
|
1354
|
+
const sorted = orderAttestations(trimmed, committee);
|
|
1355
|
+
this.logCheckpointAttestations('collected', committee, attestations, numberOfRequiredAttestations, {
|
|
1356
|
+
submittedCount: trimmed.length,
|
|
1357
|
+
});
|
|
706
1358
|
|
|
707
1359
|
// Manipulate the attestations if we've been configured to do so
|
|
708
|
-
if (
|
|
1360
|
+
if (
|
|
1361
|
+
this.config.injectFakeAttestation ||
|
|
1362
|
+
this.config.injectHighSValueAttestation ||
|
|
1363
|
+
this.config.injectUnrecoverableSignatureAttestation ||
|
|
1364
|
+
this.config.shuffleAttestationOrdering
|
|
1365
|
+
) {
|
|
709
1366
|
return this.manipulateAttestations(proposal.slotNumber, epoch, seed, committee, sorted);
|
|
710
1367
|
}
|
|
711
1368
|
|
|
712
|
-
return new CommitteeAttestationsAndSigners(sorted);
|
|
1369
|
+
return new CommitteeAttestationsAndSigners(sorted, this.getSignatureContext());
|
|
713
1370
|
} catch (err) {
|
|
714
1371
|
if (err && err instanceof AttestationTimeoutError) {
|
|
715
1372
|
collectedAttestationsCount = err.collectedCount;
|
|
1373
|
+
this.logCheckpointAttestations('failed', committee, undefined, numberOfRequiredAttestations, {
|
|
1374
|
+
collectedCount: collectedAttestationsCount,
|
|
1375
|
+
reason: 'timeout',
|
|
1376
|
+
});
|
|
1377
|
+
this.log.error(
|
|
1378
|
+
`Timeout while waiting for attestations for checkpoint proposal at slot ${proposal.slotNumber} (collected ${collectedAttestationsCount}/${numberOfRequiredAttestations})`,
|
|
1379
|
+
err,
|
|
1380
|
+
);
|
|
1381
|
+
} else {
|
|
1382
|
+
this.logCheckpointAttestations('failed', committee, undefined, numberOfRequiredAttestations, {
|
|
1383
|
+
collectedCount: collectedAttestationsCount,
|
|
1384
|
+
reason: err instanceof Error ? err.message : String(err),
|
|
1385
|
+
});
|
|
1386
|
+
this.log.error(`Error collecting attestations for checkpoint proposal at slot ${proposal.slotNumber}`, err);
|
|
716
1387
|
}
|
|
717
|
-
|
|
1388
|
+
return undefined;
|
|
718
1389
|
} finally {
|
|
719
1390
|
this.metrics.recordCollectedAttestations(collectedAttestationsCount, collectAttestationsTimer.ms());
|
|
720
1391
|
}
|
|
721
1392
|
}
|
|
722
1393
|
|
|
1394
|
+
private logCheckpointAttestations(
|
|
1395
|
+
status: 'collected' | 'failed',
|
|
1396
|
+
committee: EthAddress[],
|
|
1397
|
+
attestations: CheckpointAttestation[] | undefined,
|
|
1398
|
+
requiredAttestations: number,
|
|
1399
|
+
opts: { collectedCount?: number; submittedCount?: number; reason?: string } = {},
|
|
1400
|
+
) {
|
|
1401
|
+
const signedValidators =
|
|
1402
|
+
attestations
|
|
1403
|
+
?.map(attestation => attestation.getSender()?.toString())
|
|
1404
|
+
.filter((address): address is `0x${string}` => address !== undefined) ?? [];
|
|
1405
|
+
const collectedCount = opts.collectedCount ?? new Set(signedValidators).size;
|
|
1406
|
+
const missingValidatorCount = status === 'failed' ? Math.max(0, requiredAttestations - collectedCount) : undefined;
|
|
1407
|
+
this.logCheckpointEvent(`attestations-${status}`, `Checkpoint attestations ${status} for slot ${this.targetSlot}`, {
|
|
1408
|
+
slot: this.targetSlot,
|
|
1409
|
+
checkpointNumber: this.checkpointNumber,
|
|
1410
|
+
committeeSize: committee.length,
|
|
1411
|
+
requiredAttestations,
|
|
1412
|
+
collectedAttestations: collectedCount,
|
|
1413
|
+
...(opts.submittedCount !== undefined && { submittedAttestations: opts.submittedCount }),
|
|
1414
|
+
...(missingValidatorCount !== undefined && { missingValidatorCount }),
|
|
1415
|
+
...(opts.reason !== undefined && { reason: opts.reason }),
|
|
1416
|
+
});
|
|
1417
|
+
}
|
|
1418
|
+
|
|
723
1419
|
/** Breaks the attestations before publishing based on attack configs */
|
|
724
1420
|
private manipulateAttestations(
|
|
725
1421
|
slotNumber: SlotNumber,
|
|
@@ -734,7 +1430,11 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
734
1430
|
this.epochCache.computeProposerIndex(slotNumber, epoch, seed, BigInt(committee.length)),
|
|
735
1431
|
);
|
|
736
1432
|
|
|
737
|
-
if (
|
|
1433
|
+
if (
|
|
1434
|
+
this.config.injectFakeAttestation ||
|
|
1435
|
+
this.config.injectHighSValueAttestation ||
|
|
1436
|
+
this.config.injectUnrecoverableSignatureAttestation
|
|
1437
|
+
) {
|
|
738
1438
|
// Find non-empty attestations that are not from the proposer
|
|
739
1439
|
const nonProposerIndices: number[] = [];
|
|
740
1440
|
for (let i = 0; i < attestations.length; i++) {
|
|
@@ -744,27 +1444,48 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
744
1444
|
}
|
|
745
1445
|
if (nonProposerIndices.length > 0) {
|
|
746
1446
|
const targetIndex = nonProposerIndices[randomInt(nonProposerIndices.length)];
|
|
747
|
-
this.
|
|
748
|
-
|
|
1447
|
+
if (this.config.injectHighSValueAttestation) {
|
|
1448
|
+
this.log.warn(
|
|
1449
|
+
`Injecting high-s value attestation in checkpoint for slot ${slotNumber} at index ${targetIndex}`,
|
|
1450
|
+
);
|
|
1451
|
+
unfreeze(attestations[targetIndex]).signature = flipSignature(attestations[targetIndex].signature);
|
|
1452
|
+
} else if (this.config.injectUnrecoverableSignatureAttestation) {
|
|
1453
|
+
this.log.warn(
|
|
1454
|
+
`Injecting unrecoverable signature attestation in checkpoint for slot ${slotNumber} at index ${targetIndex}`,
|
|
1455
|
+
);
|
|
1456
|
+
unfreeze(attestations[targetIndex]).signature = generateUnrecoverableSignature();
|
|
1457
|
+
} else {
|
|
1458
|
+
this.log.warn(`Injecting fake attestation in checkpoint for slot ${slotNumber} at index ${targetIndex}`);
|
|
1459
|
+
unfreeze(attestations[targetIndex]).signature = generateRecoverableSignature();
|
|
1460
|
+
}
|
|
749
1461
|
}
|
|
750
|
-
return new CommitteeAttestationsAndSigners(attestations);
|
|
1462
|
+
return new CommitteeAttestationsAndSigners(attestations, this.getSignatureContext());
|
|
751
1463
|
}
|
|
752
1464
|
|
|
753
1465
|
if (this.config.shuffleAttestationOrdering) {
|
|
754
1466
|
this.log.warn(`Shuffling attestation ordering in checkpoint for slot ${slotNumber} (proposer #${proposerIndex})`);
|
|
755
1467
|
|
|
756
1468
|
const shuffled = [...attestations];
|
|
757
|
-
const [i, j] = [(proposerIndex + 1) % shuffled.length, (proposerIndex + 2) % shuffled.length];
|
|
758
|
-
const valueI = shuffled[i];
|
|
759
|
-
const valueJ = shuffled[j];
|
|
760
|
-
shuffled[i] = valueJ;
|
|
761
|
-
shuffled[j] = valueI;
|
|
762
1469
|
|
|
763
|
-
|
|
764
|
-
|
|
1470
|
+
// Find two non-proposer positions that both have non-empty signatures to swap.
|
|
1471
|
+
// This ensures the bitmap doesn't change, so the MaliciousCommitteeAttestationsAndSigners
|
|
1472
|
+
// signers array stays correctly aligned with L1's committee reconstruction.
|
|
1473
|
+
const swappable: number[] = [];
|
|
1474
|
+
for (let k = 0; k < shuffled.length; k++) {
|
|
1475
|
+
if (!shuffled[k].signature.isEmpty() && k !== proposerIndex) {
|
|
1476
|
+
swappable.push(k);
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
if (swappable.length >= 2) {
|
|
1480
|
+
const [i, j] = [swappable[0], swappable[1]];
|
|
1481
|
+
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
|
|
1482
|
+
}
|
|
1483
|
+
|
|
1484
|
+
const signers = new CommitteeAttestationsAndSigners(attestations, this.getSignatureContext()).getSigners();
|
|
1485
|
+
return new MaliciousCommitteeAttestationsAndSigners(shuffled, signers, this.getSignatureContext());
|
|
765
1486
|
}
|
|
766
1487
|
|
|
767
|
-
return new CommitteeAttestationsAndSigners(attestations);
|
|
1488
|
+
return new CommitteeAttestationsAndSigners(attestations, this.getSignatureContext());
|
|
768
1489
|
}
|
|
769
1490
|
|
|
770
1491
|
private async dropFailedTxsFromP2P(failedTxs: FailedTx[]) {
|
|
@@ -774,16 +1495,20 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
774
1495
|
const failedTxData = failedTxs.map(fail => fail.tx);
|
|
775
1496
|
const failedTxHashes = failedTxData.map(tx => tx.getTxHash());
|
|
776
1497
|
this.log.verbose(`Dropping failed txs ${failedTxHashes.join(', ')}`);
|
|
777
|
-
await this.p2pClient.
|
|
1498
|
+
await this.p2pClient.handleFailedExecution(failedTxHashes);
|
|
778
1499
|
}
|
|
779
1500
|
|
|
780
1501
|
/**
|
|
781
1502
|
* Adds the proposed block to the archiver so it's available via P2P.
|
|
782
1503
|
* Gossip doesn't echo messages back to the sender, so the proposer's archiver/world-state
|
|
783
1504
|
* would never receive its own block without this explicit sync.
|
|
1505
|
+
*
|
|
1506
|
+
* In fisherman mode we skip this push: the fisherman builds blocks locally for validation
|
|
1507
|
+
* and fee analysis only, and pushing them to the archiver causes spurious reorg cascades
|
|
1508
|
+
* whenever the real proposer's block arrives from L1.
|
|
784
1509
|
*/
|
|
785
1510
|
private async syncProposedBlockToArchiver(block: L2Block): Promise<void> {
|
|
786
|
-
if (this.config.skipPushProposedBlocksToArchiver
|
|
1511
|
+
if (this.config.skipPushProposedBlocksToArchiver || this.config.fishermanMode) {
|
|
787
1512
|
this.log.warn(`Skipping push of proposed block ${block.number} to archiver`, {
|
|
788
1513
|
blockNumber: block.number,
|
|
789
1514
|
slot: block.header.globalVariables.slotNumber,
|
|
@@ -797,41 +1522,104 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
797
1522
|
await this.blockSink.addBlock(block);
|
|
798
1523
|
}
|
|
799
1524
|
|
|
1525
|
+
/**
|
|
1526
|
+
* Adds the proposed checkpoint to the archiver so the proposer's optimistic proposed-checkpoint
|
|
1527
|
+
* tip advances locally. Gossip doesn't echo our own messages back, so without this the proposer
|
|
1528
|
+
* would never see its own proposed checkpoint and couldn't pipeline the next slot.
|
|
1529
|
+
*
|
|
1530
|
+
* Skipped whenever proposed blocks aren't pushed (`skipPushProposedBlocksToArchiver`, fisherman
|
|
1531
|
+
* mode): the archiver derives the checkpoint archive from its stored blocks, so without them the
|
|
1532
|
+
* push would fail. All blocks were already added (and awaited) during block building, so this
|
|
1533
|
+
* needs no retry — they are guaranteed present by the time we get here.
|
|
1534
|
+
*/
|
|
1535
|
+
private async syncProposedCheckpointToArchiver(
|
|
1536
|
+
checkpoint: Checkpoint,
|
|
1537
|
+
blockCount: number,
|
|
1538
|
+
feeAssetPriceModifier: bigint,
|
|
1539
|
+
): Promise<void> {
|
|
1540
|
+
if (this.config.skipPushProposedBlocksToArchiver || this.config.fishermanMode) {
|
|
1541
|
+
return;
|
|
1542
|
+
}
|
|
1543
|
+
const startBlock = BlockNumber(this.syncedToBlockNumber + 1);
|
|
1544
|
+
this.log.debug(`Syncing proposed checkpoint ${this.checkpointNumber} to archiver`, {
|
|
1545
|
+
checkpointNumber: this.checkpointNumber,
|
|
1546
|
+
slot: this.targetSlot,
|
|
1547
|
+
startBlock,
|
|
1548
|
+
blockCount,
|
|
1549
|
+
});
|
|
1550
|
+
await this.blockSink.addProposedCheckpoint({
|
|
1551
|
+
header: checkpoint.header,
|
|
1552
|
+
checkpointNumber: this.checkpointNumber,
|
|
1553
|
+
startBlock,
|
|
1554
|
+
blockCount,
|
|
1555
|
+
totalManaUsed: checkpoint.header.totalManaUsed.toBigInt(),
|
|
1556
|
+
feeAssetPriceModifier,
|
|
1557
|
+
});
|
|
1558
|
+
}
|
|
1559
|
+
|
|
800
1560
|
/** Runs fee analysis and logs checkpoint outcome as fisherman */
|
|
801
1561
|
private async handleCheckpointEndAsFisherman(checkpoint: Checkpoint | undefined) {
|
|
802
1562
|
// Perform L1 fee analysis before clearing requests
|
|
803
1563
|
// The callback is invoked asynchronously after the next block is mined
|
|
804
|
-
const feeAnalysis = await this.publisher.analyzeL1Fees(this.
|
|
1564
|
+
const feeAnalysis = await this.publisher.analyzeL1Fees(this.targetSlot, analysis =>
|
|
805
1565
|
this.metrics.recordFishermanFeeAnalysis(analysis),
|
|
806
1566
|
);
|
|
807
1567
|
|
|
808
1568
|
if (checkpoint) {
|
|
809
|
-
this.log.info(`Validation checkpoint building SUCCEEDED for slot ${this.
|
|
1569
|
+
this.log.info(`Validation checkpoint building SUCCEEDED for slot ${this.targetSlot}`, {
|
|
810
1570
|
...checkpoint.toCheckpointInfo(),
|
|
811
1571
|
...checkpoint.getStats(),
|
|
812
1572
|
feeAnalysisId: feeAnalysis?.id,
|
|
813
1573
|
});
|
|
814
1574
|
} else {
|
|
815
|
-
this.log.warn(`Validation block building FAILED for slot ${this.
|
|
816
|
-
slot: this.
|
|
1575
|
+
this.log.warn(`Validation block building FAILED for slot ${this.targetSlot}`, {
|
|
1576
|
+
slot: this.targetSlot,
|
|
817
1577
|
feeAnalysisId: feeAnalysis?.id,
|
|
818
1578
|
});
|
|
819
|
-
this.metrics.
|
|
1579
|
+
this.metrics.recordCheckpointProposalFailed('block_build_failed');
|
|
820
1580
|
}
|
|
821
1581
|
|
|
822
1582
|
this.publisher.clearPendingRequests();
|
|
823
1583
|
}
|
|
824
1584
|
|
|
1585
|
+
/**
|
|
1586
|
+
* Helper to handle HA double-signing errors. Returns true if the error was handled (caller should yield).
|
|
1587
|
+
*/
|
|
1588
|
+
private handleHASigningError(err: any, errorContext: string): boolean {
|
|
1589
|
+
if (err instanceof DutyAlreadySignedError) {
|
|
1590
|
+
this.log.info(`${errorContext} for slot ${this.targetSlot} already signed by another HA node, yielding`, {
|
|
1591
|
+
slot: this.targetSlot,
|
|
1592
|
+
signedByNode: err.signedByNode,
|
|
1593
|
+
});
|
|
1594
|
+
return true;
|
|
1595
|
+
}
|
|
1596
|
+
if (err instanceof SlashingProtectionError) {
|
|
1597
|
+
this.log.info(`${errorContext} for slot ${this.targetSlot} blocked by slashing protection, yielding`, {
|
|
1598
|
+
slot: this.targetSlot,
|
|
1599
|
+
existingMessageHash: err.existingMessageHash,
|
|
1600
|
+
attemptedMessageHash: err.attemptedMessageHash,
|
|
1601
|
+
});
|
|
1602
|
+
return true;
|
|
1603
|
+
}
|
|
1604
|
+
return false;
|
|
1605
|
+
}
|
|
1606
|
+
|
|
825
1607
|
/** Waits until a specific time within the current slot */
|
|
826
1608
|
@trackSpan('CheckpointProposalJob.waitUntilTimeInSlot')
|
|
827
1609
|
protected async waitUntilTimeInSlot(targetSecondsIntoSlot: number): Promise<void> {
|
|
828
1610
|
const slotStartTimestamp = this.getSlotStartBuildTimestamp();
|
|
829
1611
|
const targetTimestamp = slotStartTimestamp + targetSecondsIntoSlot;
|
|
830
|
-
|
|
1612
|
+
const delayMs = targetTimestamp * 1000 - this.dateProvider.nowAsDate().getTime();
|
|
1613
|
+
await this.awaitInterruptibleSleep(delayMs);
|
|
1614
|
+
}
|
|
1615
|
+
|
|
1616
|
+
/** Pause between mempool polls in waitForMinTxs. Extracted for test overriding. */
|
|
1617
|
+
protected async waitForTxsPollingInterval(): Promise<void> {
|
|
1618
|
+
await this.awaitInterruptibleSleep(TXS_POLLING_MS);
|
|
831
1619
|
}
|
|
832
1620
|
|
|
833
1621
|
private getSlotStartBuildTimestamp(): number {
|
|
834
|
-
return getSlotStartBuildTimestamp(this.
|
|
1622
|
+
return getSlotStartBuildTimestamp(this.slotNow, this.l1Constants);
|
|
835
1623
|
}
|
|
836
1624
|
|
|
837
1625
|
private getSecondsIntoSlot(): number {
|