@aztec-labs/sequencer-client 6.0.0-rc.3 → 6.0.0
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 +1 -1
- package/dest/client/sequencer-client.d.ts +1 -1
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +7 -2
- package/dest/config.d.ts +2 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +5 -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 +7 -4
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +12 -10
- package/dest/publisher/gas_constants.d.ts +39 -0
- package/dest/publisher/gas_constants.d.ts.map +1 -0
- package/dest/publisher/gas_constants.js +42 -0
- package/dest/publisher/index.d.ts +2 -1
- package/dest/publisher/index.d.ts.map +1 -1
- package/dest/publisher/index.js +1 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts +1 -1
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts.map +1 -1
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.js +1 -0
- package/dest/publisher/publisher-manager-metrics.d.ts +19 -0
- package/dest/publisher/publisher-manager-metrics.d.ts.map +1 -0
- package/dest/publisher/publisher-manager-metrics.js +67 -0
- package/dest/publisher/sequencer-publisher-factory.d.ts +8 -4
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-factory.js +16 -6
- package/dest/publisher/sequencer-publisher-metrics.d.ts +1 -3
- package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-metrics.js +0 -8
- package/dest/publisher/sequencer-publisher.d.ts +17 -4
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +168 -17
- package/dest/publisher/write_json.d.ts +1 -1
- package/dest/publisher/write_json.d.ts.map +1 -1
- package/dest/publisher/write_json.js +3 -1
- package/dest/sequencer/attestation_manipulation.d.ts +24 -0
- package/dest/sequencer/attestation_manipulation.d.ts.map +1 -0
- package/dest/sequencer/attestation_manipulation.js +72 -0
- package/dest/sequencer/automine/automine_factory.d.ts +1 -1
- package/dest/sequencer/automine/automine_factory.d.ts.map +1 -1
- package/dest/sequencer/automine/automine_factory.js +5 -1
- package/dest/sequencer/checkpoint_inbox_consumption.d.ts +135 -0
- package/dest/sequencer/checkpoint_inbox_consumption.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_inbox_consumption.js +275 -0
- package/dest/sequencer/checkpoint_proposal_job.d.ts +27 -23
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_proposal_job.js +323 -527
- package/dest/sequencer/inbox_message_selection.d.ts +17 -16
- package/dest/sequencer/inbox_message_selection.d.ts.map +1 -1
- package/dest/sequencer/inbox_message_selection.js +20 -7
- package/dest/sequencer/metrics.d.ts +4 -4
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +6 -9
- package/dest/sequencer/sequencer.d.ts +9 -4
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +129 -38
- package/package.json +23 -23
- package/src/client/sequencer-client.ts +6 -1
- package/src/config.ts +7 -0
- package/src/index.ts +0 -3
- package/src/publisher/config.ts +20 -11
- package/src/publisher/gas_constants.ts +51 -0
- package/src/publisher/index.ts +1 -0
- package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +1 -0
- package/src/publisher/publisher-manager-metrics.ts +76 -0
- package/src/publisher/sequencer-publisher-factory.ts +18 -7
- package/src/publisher/sequencer-publisher-metrics.ts +0 -12
- package/src/publisher/sequencer-publisher.ts +201 -24
- package/src/publisher/write_json.ts +3 -1
- package/src/sequencer/attestation_manipulation.ts +123 -0
- package/src/sequencer/automine/automine_factory.ts +4 -0
- package/src/sequencer/checkpoint_inbox_consumption.ts +340 -0
- package/src/sequencer/checkpoint_proposal_job.ts +434 -632
- package/src/sequencer/inbox_message_selection.ts +45 -24
- package/src/sequencer/metrics.ts +7 -9
- package/src/sequencer/sequencer.ts +116 -27
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { type EpochCache, PROPOSER_PIPELINING_SLOT_OFFSET } from '@aztec-labs/epoch-cache';
|
|
1
|
+
import { type EpochCache, PROPOSER_PIPELINING_SLOT_OFFSET, requireStableCommittee } from '@aztec-labs/epoch-cache';
|
|
2
2
|
import { SimulationOverridesBuilder, type SimulationOverridesPlan } from '@aztec-labs/ethereum/contracts';
|
|
3
3
|
import type { L1FeeAnalyzer } from '@aztec-labs/ethereum/l1-fee-analysis';
|
|
4
|
-
import { maxBigint, minBigint } from '@aztec-labs/foundation/bigint';
|
|
5
4
|
import {
|
|
6
5
|
BlockNumber,
|
|
7
6
|
CheckpointNumber,
|
|
@@ -10,30 +9,24 @@ import {
|
|
|
10
9
|
SlotNumber,
|
|
11
10
|
} from '@aztec-labs/foundation/branded-types';
|
|
12
11
|
import { randomInt } from '@aztec-labs/foundation/crypto/random';
|
|
13
|
-
import {
|
|
14
|
-
flipSignature,
|
|
15
|
-
generateRecoverableSignature,
|
|
16
|
-
generateUnrecoverableSignature,
|
|
17
|
-
} from '@aztec-labs/foundation/crypto/secp256k1-signer';
|
|
18
12
|
import { Fr } from '@aztec-labs/foundation/curves/bn254';
|
|
19
13
|
import { InterruptError, TimeoutError } from '@aztec-labs/foundation/error';
|
|
20
14
|
import { EthAddress } from '@aztec-labs/foundation/eth-address';
|
|
21
15
|
import { Signature } from '@aztec-labs/foundation/eth-signature';
|
|
22
16
|
import { filter } from '@aztec-labs/foundation/iterator';
|
|
23
|
-
import { type Logger, type LoggerBindings, createLogger } from '@aztec-labs/foundation/log';
|
|
17
|
+
import { type LogData, type Logger, type LoggerBindings, createLogger } from '@aztec-labs/foundation/log';
|
|
24
18
|
import { InterruptibleSleep } from '@aztec-labs/foundation/sleep';
|
|
25
19
|
import { type DateProvider, Timer, executeTimeout } from '@aztec-labs/foundation/timer';
|
|
26
|
-
import { type TypedEventEmitter, isErrorClass
|
|
20
|
+
import { type TypedEventEmitter, isErrorClass } from '@aztec-labs/foundation/types';
|
|
27
21
|
import type { P2P } from '@aztec-labs/p2p';
|
|
28
22
|
import type { SlasherClientInterface } from '@aztec-labs/slasher';
|
|
29
23
|
import {
|
|
24
|
+
type BlockHash,
|
|
30
25
|
CommitteeAttestation,
|
|
31
26
|
CommitteeAttestationsAndSigners,
|
|
32
27
|
L2Block,
|
|
33
28
|
type L2BlockSink,
|
|
34
29
|
type L2BlockSource,
|
|
35
|
-
MaliciousCommitteeAttestationsAndSigners,
|
|
36
|
-
MaliciousYParityCommitteeAttestationsAndSigners,
|
|
37
30
|
type ProposedCheckpointSink,
|
|
38
31
|
type ValidateCheckpointResult,
|
|
39
32
|
} from '@aztec-labs/stdlib/block';
|
|
@@ -45,21 +38,15 @@ import {
|
|
|
45
38
|
getPreviousCheckpointOutHashes,
|
|
46
39
|
validateCheckpoint,
|
|
47
40
|
} from '@aztec-labs/stdlib/checkpoint';
|
|
48
|
-
import { computeQuorum, getTimestampForSlot } from '@aztec-labs/stdlib/epoch-helpers';
|
|
41
|
+
import { computeQuorum, getLastL1SlotTimestampForL2Slot, getTimestampForSlot } from '@aztec-labs/stdlib/epoch-helpers';
|
|
49
42
|
import { Gas } from '@aztec-labs/stdlib/gas';
|
|
50
43
|
import {
|
|
51
44
|
type BlockBuilderOptions,
|
|
52
45
|
InsufficientValidTxsError,
|
|
53
|
-
type MerkleTreeWriteOperations,
|
|
54
46
|
type ResolvedSequencerConfig,
|
|
55
47
|
type WorldStateSynchronizer,
|
|
56
48
|
} from '@aztec-labs/stdlib/interfaces/server';
|
|
57
|
-
import {
|
|
58
|
-
type InboxMessagePosition,
|
|
59
|
-
InboxMessagePrefixRef,
|
|
60
|
-
type InboxMessageRange,
|
|
61
|
-
type L1ToL2MessageSource,
|
|
62
|
-
} from '@aztec-labs/stdlib/messaging';
|
|
49
|
+
import type { InboxMessagePrefixRef, InboxMessageRange, L1ToL2MessageSource } from '@aztec-labs/stdlib/messaging';
|
|
63
50
|
import type {
|
|
64
51
|
BlockProposal,
|
|
65
52
|
BlockProposalOptions,
|
|
@@ -68,33 +55,27 @@ import type {
|
|
|
68
55
|
CheckpointProposalOptions,
|
|
69
56
|
CoordinationSignatureContext,
|
|
70
57
|
} from '@aztec-labs/stdlib/p2p';
|
|
71
|
-
import { orderAttestations, trimAttestations } from '@aztec-labs/stdlib/p2p';
|
|
58
|
+
import { getCoordinationSignatureTypedData, orderAttestations, trimAttestations } from '@aztec-labs/stdlib/p2p';
|
|
72
59
|
import type { CheckpointHeader } from '@aztec-labs/stdlib/rollup';
|
|
73
60
|
import type { L2BlockBuiltStats } from '@aztec-labs/stdlib/stats';
|
|
74
61
|
import type { ProposerTimetable, SubslotSelection } from '@aztec-labs/stdlib/timetable';
|
|
75
|
-
import { MerkleTreeId } from '@aztec-labs/stdlib/trees';
|
|
76
62
|
import { type FailedTx, Tx } from '@aztec-labs/stdlib/tx';
|
|
77
63
|
import { AttestationTimeoutError } from '@aztec-labs/stdlib/validators';
|
|
78
64
|
import { Attributes, type Traceable, type Tracer, trackSpan } from '@aztec-labs/telemetry-client';
|
|
79
65
|
import { CheckpointBuilder, type FullNodeCheckpointsBuilder, type ValidatorClient } from '@aztec-labs/validator-client';
|
|
80
66
|
import { DutyAlreadySignedError, SlashingProtectionError } from '@aztec-labs/validator-ha-signer/errors';
|
|
67
|
+
import { DutyType } from '@aztec-labs/validator-ha-signer/types';
|
|
81
68
|
|
|
82
69
|
import type { GlobalVariableBuilder } from '../global_variable_builder/global_builder.js';
|
|
83
70
|
import type { InvalidateCheckpointRequest, SequencerPublisher } from '../publisher/sequencer-publisher.js';
|
|
71
|
+
import { hasAttestationManipulation, manipulateAttestations } from './attestation_manipulation.js';
|
|
72
|
+
import { CheckpointInboxConsumption } from './checkpoint_inbox_consumption.js';
|
|
84
73
|
import type { CheckpointProposalJobMetricsRecorder } from './checkpoint_proposal_job_metrics.js';
|
|
85
74
|
import type { CheckpointProposalJobTestHooks } from './checkpoint_proposal_job_test_hooks.js';
|
|
86
75
|
import { CheckpointVoter } from './checkpoint_voter.js';
|
|
87
76
|
import { SequencerInterruptedError } from './errors.js';
|
|
88
77
|
import type { SequencerEvents } from './events.js';
|
|
89
|
-
import {
|
|
90
|
-
type InboxEndpointResolver,
|
|
91
|
-
PROTOCOL_INBOX_CONSUMPTION_CAPS,
|
|
92
|
-
getEndpointUpperBound,
|
|
93
|
-
mustQueryEndpoint,
|
|
94
|
-
resolveEndpoint,
|
|
95
|
-
selectOrdinaryMessageEnd,
|
|
96
|
-
selectSafeLocalEnd,
|
|
97
|
-
} from './inbox_message_selection.js';
|
|
78
|
+
import type { InboxEndpointResolver } from './inbox_message_selection.js';
|
|
98
79
|
import type { SequencerMetrics } from './metrics.js';
|
|
99
80
|
import type { RequestsTracker } from './requests_tracker.js';
|
|
100
81
|
import type { SequencerRollupConstants } from './types.js';
|
|
@@ -103,8 +84,6 @@ import { SequencerState } from './utils.js';
|
|
|
103
84
|
/** How much time to sleep while waiting for min transactions to accumulate for a block */
|
|
104
85
|
const TXS_POLLING_MS = 500;
|
|
105
86
|
const ARCHIVER_SYNC_POLLING_MS = 200;
|
|
106
|
-
/** Cap on the Inbox endpoint read a block makes near the checkpoint cap, well under a sub-slot. */
|
|
107
|
-
const INBOX_ENDPOINT_READ_TIMEOUT_MS = 2_000;
|
|
108
87
|
|
|
109
88
|
/** An empty transaction stream, for a block built over Inbox messages alone. */
|
|
110
89
|
async function* noTransactions(): AsyncGenerator<Tx> {}
|
|
@@ -122,10 +101,22 @@ type CheckpointProposalBroadcast = {
|
|
|
122
101
|
checkpoint: Checkpoint;
|
|
123
102
|
proposal: CheckpointProposal;
|
|
124
103
|
blockProposedAt: number;
|
|
125
|
-
/**
|
|
126
|
-
|
|
104
|
+
/** Cumulative Inbox message count the checkpoint consumed through, for the pre-publication preflight. */
|
|
105
|
+
consumedTotalMsgCount: bigint;
|
|
106
|
+
/**
|
|
107
|
+
* Chain state overrides built once per slot in proposeCheckpoint. Carries the pending parent override (archive +
|
|
108
|
+
* slot + fee header) for pipelining, or the invalidation pending override when rolling back. Consumed by the
|
|
109
|
+
* pre-gossip publisher.validateCheckpointHeaderAndInbox preflight, and the source of the proven pin the
|
|
110
|
+
* pre-publication preflight keeps.
|
|
111
|
+
*/
|
|
112
|
+
simulationOverridesPlan: SimulationOverridesPlan | undefined;
|
|
127
113
|
};
|
|
128
114
|
|
|
115
|
+
/** What proposeCheckpoint produced: a checkpoint broadcast to the committee, or, in fisherman mode, one only built. */
|
|
116
|
+
type CheckpointProposalOutcome =
|
|
117
|
+
| ({ kind: 'broadcast' } & CheckpointProposalBroadcast)
|
|
118
|
+
| { kind: 'built-only'; checkpoint: Checkpoint };
|
|
119
|
+
|
|
129
120
|
/** Result after attestation collection and signing, ready for L1 submission. */
|
|
130
121
|
type CheckpointProposalResult = {
|
|
131
122
|
checkpoint: Checkpoint;
|
|
@@ -135,35 +126,11 @@ type CheckpointProposalResult = {
|
|
|
135
126
|
bucketHint: bigint;
|
|
136
127
|
};
|
|
137
128
|
|
|
138
|
-
/**
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
*/
|
|
144
|
-
type StreamingCheckpointState = {
|
|
145
|
-
/** Cumulative Inbox message count consumed as of the parent checkpoint; the per-checkpoint cap origin. */
|
|
146
|
-
checkpointStartTotalMsgCount: bigint;
|
|
147
|
-
/**
|
|
148
|
-
* The message prefix consumed so far (the parent checkpoint's at the first block). Each block that builds yields a
|
|
149
|
-
* new state with the cursor at the prefix it consumed through; the state is never modified in place.
|
|
150
|
-
*/
|
|
151
|
-
cursor: InboxMessagePosition;
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
/** What a block's streaming message selection decided. */
|
|
155
|
-
type StreamingBundleSelection =
|
|
156
|
-
| {
|
|
157
|
-
/** Build the block over this range; the block signs `range.end` as its prefix reference. */
|
|
158
|
-
kind: 'consume';
|
|
159
|
-
range: InboxMessageRange;
|
|
160
|
-
}
|
|
161
|
-
| {
|
|
162
|
-
/** No checkpoint ending this way can be published; give up the slot without signing anything more. */
|
|
163
|
-
kind: 'abort';
|
|
164
|
-
reason: string;
|
|
165
|
-
context?: Record<string, unknown>;
|
|
166
|
-
};
|
|
129
|
+
/** Outcome of building a single block: built, skipped for lack of (valid) txs, or failed with an error. */
|
|
130
|
+
type BlockBuildAttempt =
|
|
131
|
+
| { kind: 'built'; block: L2Block; usedTxs: Tx[] }
|
|
132
|
+
| { kind: 'skipped'; reason: 'insufficient-txs' | 'insufficient-valid-txs' }
|
|
133
|
+
| { kind: 'failed'; error: Error };
|
|
167
134
|
|
|
168
135
|
/**
|
|
169
136
|
* Outcome of the block-building loop: the blocks built for the checkpoint, or an abort that discards them all. An
|
|
@@ -175,8 +142,6 @@ type BlockBuildingResult =
|
|
|
175
142
|
blocksInCheckpoint: L2Block[];
|
|
176
143
|
/** The last block's proposal, held back to travel with the checkpoint proposal instead of being gossiped. */
|
|
177
144
|
blockPendingBroadcast: BlockProposal | undefined;
|
|
178
|
-
/** Consumption state after the last block built, including any forced endpoint block. */
|
|
179
|
-
streamingState: StreamingCheckpointState;
|
|
180
145
|
}
|
|
181
146
|
| { aborted: true };
|
|
182
147
|
|
|
@@ -199,12 +164,12 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
199
164
|
private interrupted = false;
|
|
200
165
|
|
|
201
166
|
/**
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
* or the invalidation pending override when rolling back. Consumed by the pre-gossip
|
|
205
|
-
* publisher.validateCheckpointHeaderAndInbox preflight.
|
|
167
|
+
* Hash of this checkpoint's first block once it is in the local archiver, until the checkpoint itself is handed to
|
|
168
|
+
* the archiver. While set, giving the checkpoint up leaves blocks on the local chain that no checkpoint will cover.
|
|
206
169
|
*/
|
|
207
|
-
private
|
|
170
|
+
private unclaimedFirstBlockHash: BlockHash | undefined;
|
|
171
|
+
/** Whether an HA peer holds one of this slot's signing duties, and so may be proposing the blocks pushed here. */
|
|
172
|
+
private yieldedToHAPeer = false;
|
|
208
173
|
|
|
209
174
|
private getSignatureContext(): CoordinationSignatureContext {
|
|
210
175
|
return this.signatureContext;
|
|
@@ -325,6 +290,26 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
325
290
|
});
|
|
326
291
|
}
|
|
327
292
|
|
|
293
|
+
/** Emits a failure checkpoint event followed by the operator log line for it, both carrying the same context. */
|
|
294
|
+
private reportCheckpointFailure(
|
|
295
|
+
event: 'build-failed' | 'publish-failed' | 'block-build-failed',
|
|
296
|
+
message: string,
|
|
297
|
+
context: LogData & { reason: string },
|
|
298
|
+
log: { level: 'verbose' | 'warn' } | { level: 'error'; err: unknown },
|
|
299
|
+
): void {
|
|
300
|
+
const eventMessages = {
|
|
301
|
+
'build-failed': `Checkpoint build failed for slot ${this.targetSlot}`,
|
|
302
|
+
'publish-failed': `Checkpoint publish failed for slot ${this.targetSlot}`,
|
|
303
|
+
'block-build-failed': `Block build failed for slot ${this.targetSlot}`,
|
|
304
|
+
};
|
|
305
|
+
this.logCheckpointEvent(event, eventMessages[event], context);
|
|
306
|
+
if (log.level === 'error') {
|
|
307
|
+
this.log.error(message, log.err, context);
|
|
308
|
+
} else {
|
|
309
|
+
this.log[log.level](message, context);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
328
313
|
/**
|
|
329
314
|
* Executes the checkpoint proposal job.
|
|
330
315
|
* Builds blocks, assembles checkpoint, and broadcasts the proposal (blocking).
|
|
@@ -352,9 +337,10 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
352
337
|
|
|
353
338
|
// Build blocks, assemble checkpoint, and broadcast proposal (BLOCKING).
|
|
354
339
|
// Returns after broadcast — attestation collection is deferred.
|
|
355
|
-
const
|
|
340
|
+
const outcome = await this.proposeCheckpoint();
|
|
356
341
|
|
|
357
|
-
if (!
|
|
342
|
+
if (!outcome) {
|
|
343
|
+
await this.pruneAbandonedCheckpointBlocks();
|
|
358
344
|
await Promise.all(votesPromises);
|
|
359
345
|
// Still submit votes even without a checkpoint.
|
|
360
346
|
// Under proposer pipelining, vote-offenses signatures are EIP-712-bound to `targetSlot`
|
|
@@ -368,17 +354,17 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
368
354
|
return undefined;
|
|
369
355
|
}
|
|
370
356
|
|
|
371
|
-
const { checkpoint } =
|
|
357
|
+
const { checkpoint } = outcome;
|
|
372
358
|
this.metrics.recordCheckpointProposalSuccess();
|
|
373
359
|
|
|
374
360
|
// Do not post anything to L1 if we are fishermen, but do perform L1 fee analysis
|
|
375
|
-
if (
|
|
361
|
+
if (outcome.kind === 'built-only') {
|
|
376
362
|
await this.handleCheckpointEndAsFisherman(checkpoint);
|
|
377
363
|
return checkpoint;
|
|
378
364
|
}
|
|
379
365
|
|
|
380
366
|
// Background the attestation → signing → L1 pipeline so the work loop is unblocked
|
|
381
|
-
this.submission = this.waitForAttestationsAndEnqueueSubmissionAsync(
|
|
367
|
+
this.submission = this.waitForAttestationsAndEnqueueSubmissionAsync(outcome, votesPromises);
|
|
382
368
|
|
|
383
369
|
// Return the built checkpoint immediately — the work loop is now unblocked
|
|
384
370
|
return checkpoint;
|
|
@@ -392,7 +378,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
392
378
|
broadcast: CheckpointProposalBroadcast,
|
|
393
379
|
votesPromises: Promise<unknown>[],
|
|
394
380
|
): Promise<void> {
|
|
395
|
-
const { checkpoint,
|
|
381
|
+
const { checkpoint, consumedTotalMsgCount, simulationOverridesPlan } = broadcast;
|
|
396
382
|
|
|
397
383
|
try {
|
|
398
384
|
// Wait for all votes actions, enqueued at the beginning, to resolve
|
|
@@ -415,8 +401,19 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
415
401
|
}
|
|
416
402
|
// Attestation collection took seconds and L1 may have moved: re-run the integrated header and Inbox
|
|
417
403
|
// preflight against L1's current state, and take the bucket hint from it.
|
|
418
|
-
const bucketHint = await this.preflightBeforePublication(
|
|
404
|
+
const bucketHint = await this.preflightBeforePublication(
|
|
405
|
+
checkpoint.header,
|
|
406
|
+
consumedTotalMsgCount,
|
|
407
|
+
simulationOverridesPlan,
|
|
408
|
+
);
|
|
419
409
|
if (bucketHint !== undefined && (await this.checkpointBlocksAreStillLocal(checkpoint))) {
|
|
410
|
+
if (this.config.republishAfterFakeAttestation) {
|
|
411
|
+
await this.publishWithFakeAttestationAndEnqueueInvalidation(
|
|
412
|
+
checkpoint,
|
|
413
|
+
signedAttestations.attestations,
|
|
414
|
+
bucketHint,
|
|
415
|
+
);
|
|
416
|
+
}
|
|
420
417
|
await this.enqueueCheckpointForSubmission({ checkpoint, ...signedAttestations, bucketHint });
|
|
421
418
|
}
|
|
422
419
|
}
|
|
@@ -445,26 +442,22 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
445
442
|
});
|
|
446
443
|
this.eventEmitter.emit('checkpoint-published', { checkpoint: this.checkpointNumber, slot: this.targetSlot });
|
|
447
444
|
const coinbase = checkpoint.header.coinbase;
|
|
448
|
-
await this.metrics.incFilledSlot(
|
|
445
|
+
await this.metrics.incFilledSlot(coinbase);
|
|
449
446
|
} else {
|
|
450
|
-
this.
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
sentActions: l1Response?.sentActions,
|
|
465
|
-
expiredActions: l1Response?.expiredActions,
|
|
466
|
-
reason: 'propose_action_not_successful',
|
|
467
|
-
});
|
|
447
|
+
this.reportCheckpointFailure(
|
|
448
|
+
'publish-failed',
|
|
449
|
+
`Checkpoint publish failed for slot ${this.targetSlot}`,
|
|
450
|
+
{
|
|
451
|
+
slot: this.targetSlot,
|
|
452
|
+
checkpointNumber: this.checkpointNumber,
|
|
453
|
+
successfulActions: l1Response?.successfulActions,
|
|
454
|
+
failedActions: l1Response?.failedActions,
|
|
455
|
+
sentActions: l1Response?.sentActions,
|
|
456
|
+
expiredActions: l1Response?.expiredActions,
|
|
457
|
+
reason: 'propose_action_not_successful',
|
|
458
|
+
},
|
|
459
|
+
{ level: 'warn' },
|
|
460
|
+
);
|
|
468
461
|
this.eventEmitter.emit('checkpoint-publish-failed', { ...l1Response, slot: this.targetSlot });
|
|
469
462
|
this.metrics.recordPipelineDiscard();
|
|
470
463
|
}
|
|
@@ -472,16 +465,16 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
472
465
|
if (err instanceof SequencerInterruptedError) {
|
|
473
466
|
return;
|
|
474
467
|
}
|
|
475
|
-
this.
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
468
|
+
this.reportCheckpointFailure(
|
|
469
|
+
'publish-failed',
|
|
470
|
+
`Background attestation/L1 pipeline failed for slot ${this.targetSlot}`,
|
|
471
|
+
{
|
|
472
|
+
slot: this.targetSlot,
|
|
473
|
+
checkpointNumber: this.checkpointNumber,
|
|
474
|
+
reason: err instanceof Error ? err.message : String(err),
|
|
475
|
+
},
|
|
476
|
+
{ level: 'error', err },
|
|
477
|
+
);
|
|
485
478
|
this.eventEmitter.emit('checkpoint-publish-failed', { slot: this.targetSlot });
|
|
486
479
|
this.metrics.recordPipelineDiscard();
|
|
487
480
|
}
|
|
@@ -500,11 +493,17 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
500
493
|
*/
|
|
501
494
|
private async preflightBeforePublication(
|
|
502
495
|
header: CheckpointHeader,
|
|
503
|
-
|
|
496
|
+
consumedTotalMsgCount: bigint,
|
|
497
|
+
buildPlan: SimulationOverridesPlan | undefined,
|
|
504
498
|
): Promise<bigint | undefined> {
|
|
505
|
-
const overridesPlan = await this.getPublicationSimulationOverridesPlan();
|
|
499
|
+
const overridesPlan = await this.getPublicationSimulationOverridesPlan(buildPlan);
|
|
506
500
|
try {
|
|
507
|
-
return await this.preflightWithinDeadline(
|
|
501
|
+
return await this.preflightWithinDeadline(
|
|
502
|
+
header,
|
|
503
|
+
consumedTotalMsgCount,
|
|
504
|
+
overridesPlan,
|
|
505
|
+
this.getL1PublishDeadline(),
|
|
506
|
+
);
|
|
508
507
|
} catch (err) {
|
|
509
508
|
if (err instanceof SequencerInterruptedError) {
|
|
510
509
|
throw err;
|
|
@@ -514,15 +513,16 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
514
513
|
const context = {
|
|
515
514
|
slot: this.targetSlot,
|
|
516
515
|
checkpointNumber: this.checkpointNumber,
|
|
517
|
-
consumedTotalMsgCount
|
|
516
|
+
consumedTotalMsgCount,
|
|
518
517
|
inboxRollingHash: header.inboxRollingHash.toString(),
|
|
519
518
|
reason,
|
|
520
519
|
error: err instanceof Error ? err.message : String(err),
|
|
521
520
|
};
|
|
522
|
-
this.
|
|
523
|
-
|
|
521
|
+
this.reportCheckpointFailure(
|
|
522
|
+
'publish-failed',
|
|
524
523
|
`Pre-publication header and Inbox preflight did not clear the checkpoint; abandoning slot ${this.targetSlot}`,
|
|
525
524
|
context,
|
|
525
|
+
{ level: 'warn' },
|
|
526
526
|
);
|
|
527
527
|
this.metrics.recordCheckpointProposalFailed(reason);
|
|
528
528
|
this.eventEmitter.emit('checkpoint-publish-failed', { slot: this.targetSlot });
|
|
@@ -538,7 +538,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
538
538
|
*/
|
|
539
539
|
private async preflightWithinDeadline(
|
|
540
540
|
header: CheckpointHeader,
|
|
541
|
-
|
|
541
|
+
consumedTotalMsgCount: bigint,
|
|
542
542
|
overridesPlan: SimulationOverridesPlan | undefined,
|
|
543
543
|
deadline: Date,
|
|
544
544
|
): Promise<bigint> {
|
|
@@ -551,7 +551,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
551
551
|
this.publisher.validateCheckpointHeaderAndInbox(
|
|
552
552
|
header,
|
|
553
553
|
{
|
|
554
|
-
expectedTotal:
|
|
554
|
+
expectedTotal: consumedTotalMsgCount,
|
|
555
555
|
expectedParentCheckpointNumber: CheckpointNumber(this.checkpointNumber - 1),
|
|
556
556
|
},
|
|
557
557
|
overridesPlan,
|
|
@@ -584,11 +584,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
584
584
|
* already expired and time out before it can mine.
|
|
585
585
|
*/
|
|
586
586
|
private getL1PublishDeadline(): Date {
|
|
587
|
-
|
|
588
|
-
Number(getTimestampForSlot(this.targetSlot, this.l1Constants)) +
|
|
589
|
-
this.l1Constants.slotDuration -
|
|
590
|
-
this.l1Constants.ethereumSlotDuration;
|
|
591
|
-
return new Date(lastL1BlockInTargetSlot * 1000);
|
|
587
|
+
return new Date(Number(getLastL1SlotTimestampForL2Slot(this.targetSlot, this.l1Constants)) * 1000);
|
|
592
588
|
}
|
|
593
589
|
|
|
594
590
|
/**
|
|
@@ -603,15 +599,17 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
603
599
|
* Under the test-only `skipWaitForValidParentCheckpointOnL1` the parent was never confirmed on L1, so the build-time
|
|
604
600
|
* plan describing it is reused; that keeps the hypothetical context the test asked for and is not a production path.
|
|
605
601
|
*/
|
|
606
|
-
private async getPublicationSimulationOverridesPlan(
|
|
602
|
+
private async getPublicationSimulationOverridesPlan(
|
|
603
|
+
buildPlan: SimulationOverridesPlan | undefined,
|
|
604
|
+
): Promise<SimulationOverridesPlan | undefined> {
|
|
607
605
|
if (this.config.skipWaitForValidParentCheckpointOnL1) {
|
|
608
|
-
return
|
|
606
|
+
return buildPlan;
|
|
609
607
|
}
|
|
610
608
|
const builder = new SimulationOverridesBuilder();
|
|
611
609
|
if (this.invalidateCheckpoint && !this.config.skipInvalidateBlockAsProposer) {
|
|
612
610
|
builder.withChainTips({ pending: this.invalidateCheckpoint.forcePendingCheckpointNumber });
|
|
613
611
|
}
|
|
614
|
-
const provenPin =
|
|
612
|
+
const provenPin = buildPlan?.chainTipsOverride?.proven;
|
|
615
613
|
if (provenPin !== undefined && (await this.l2BlockSource.isPruneDueAtSlot(this.targetSlot))) {
|
|
616
614
|
this.log.warn(
|
|
617
615
|
`Assuming proof for epoch ending at checkpoint ${provenPin} lands by target slot ${this.targetSlot} for the publication preflight`,
|
|
@@ -668,11 +666,12 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
668
666
|
localBlockHash: local?.blockHash.toString(),
|
|
669
667
|
reason: 'checkpoint_blocks_pruned',
|
|
670
668
|
};
|
|
671
|
-
this.
|
|
672
|
-
|
|
669
|
+
this.reportCheckpointFailure(
|
|
670
|
+
'publish-failed',
|
|
673
671
|
`The local archiver no longer holds the blocks of this checkpoint; abandoning slot ${this.targetSlot} rather ` +
|
|
674
672
|
`than publishing a checkpoint this node cannot serve`,
|
|
675
673
|
context,
|
|
674
|
+
{ level: 'warn' },
|
|
676
675
|
);
|
|
677
676
|
this.metrics.recordCheckpointProposalFailed('checkpoint_blocks_pruned');
|
|
678
677
|
return false;
|
|
@@ -704,6 +703,63 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
704
703
|
});
|
|
705
704
|
}
|
|
706
705
|
|
|
706
|
+
/**
|
|
707
|
+
* Test-only (`republishAfterFakeAttestation`): publishes the checkpoint with one of the collected attestations
|
|
708
|
+
* replaced by a fake one, waits for the local archiver to flag it, and enqueues its invalidation, so the next send
|
|
709
|
+
* bundles the invalidation with the checkpoint carrying the collected attestations.
|
|
710
|
+
*/
|
|
711
|
+
private async publishWithFakeAttestationAndEnqueueInvalidation(
|
|
712
|
+
checkpoint: Checkpoint,
|
|
713
|
+
collected: CommitteeAttestationsAndSigners,
|
|
714
|
+
bucketHint: bigint,
|
|
715
|
+
): Promise<void> {
|
|
716
|
+
const logCtx = { slot: this.targetSlot, checkpointNumber: this.checkpointNumber };
|
|
717
|
+
const lookup = requireStableCommittee(await this.epochCache.getCommittee(this.targetSlot));
|
|
718
|
+
const fakeAttestations = manipulateAttestations({
|
|
719
|
+
config: { injectFakeAttestation: true },
|
|
720
|
+
epochCache: this.epochCache,
|
|
721
|
+
signatureContext: this.getSignatureContext(),
|
|
722
|
+
log: this.log,
|
|
723
|
+
slotNumber: this.targetSlot,
|
|
724
|
+
epoch: lookup.epoch,
|
|
725
|
+
seed: lookup.seed,
|
|
726
|
+
committee: lookup.state === 'members' ? lookup.committee : [],
|
|
727
|
+
// Copies, since the manipulation overwrites a signature in place and the collected set is published afterwards.
|
|
728
|
+
attestations: collected.attestations.map(a => new CommitteeAttestation(a.address, a.signature)),
|
|
729
|
+
});
|
|
730
|
+
|
|
731
|
+
// The slot's slashing-protected signature already covers the collected attestations, and the protection would
|
|
732
|
+
// refuse a second payload for the slot, so this throwaway set is signed under an unprotected context.
|
|
733
|
+
const signer = this.proposer ?? this.publisher.getSenderAddress();
|
|
734
|
+
const fakeAttestationsSignature = await this.validatorClient.signWithAddress(
|
|
735
|
+
signer,
|
|
736
|
+
getCoordinationSignatureTypedData(fakeAttestations),
|
|
737
|
+
{ dutyType: DutyType.AUTH_REQUEST },
|
|
738
|
+
);
|
|
739
|
+
|
|
740
|
+
await this.publisher.enqueueProposeCheckpoint(checkpoint, fakeAttestations, fakeAttestationsSignature, bucketHint, {
|
|
741
|
+
txTimeoutAt: this.getL1PublishDeadline(),
|
|
742
|
+
});
|
|
743
|
+
this.log.warn(`Publishing checkpoint ${this.checkpointNumber} with a fake attestation`, logCtx);
|
|
744
|
+
const response = await this.publisher.sendRequests(this.targetSlot);
|
|
745
|
+
if (!response?.successfulActions.includes('propose')) {
|
|
746
|
+
this.log.warn(`Checkpoint ${this.checkpointNumber} with a fake attestation did not land`, logCtx);
|
|
747
|
+
return;
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
const deadlineMs = this.getL1PublishDeadline().getTime();
|
|
751
|
+
while (this.dateProvider.now() < deadlineMs) {
|
|
752
|
+
const status = await this.l2BlockSource.getPendingChainValidationStatus();
|
|
753
|
+
if (!status.valid && status.checkpoint.checkpointNumber === this.checkpointNumber) {
|
|
754
|
+
this.log.warn(`Invalidating checkpoint ${this.checkpointNumber} before publishing it again`, logCtx);
|
|
755
|
+
await this.enqueueInvalidation(status);
|
|
756
|
+
return;
|
|
757
|
+
}
|
|
758
|
+
await this.awaitInterruptibleSleep(ARCHIVER_SYNC_POLLING_MS);
|
|
759
|
+
}
|
|
760
|
+
this.log.warn(`Archiver did not flag checkpoint ${this.checkpointNumber} before the publish deadline`, logCtx);
|
|
761
|
+
}
|
|
762
|
+
|
|
707
763
|
/**
|
|
708
764
|
* Wait until the archiver syncs past the given L2 slot number.
|
|
709
765
|
* The deadline is the end of `this.targetSlot`, beyond which any pipelined work would miss its
|
|
@@ -858,7 +914,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
858
914
|
[Attributes.SLOT_NUMBER]: this.targetSlot,
|
|
859
915
|
};
|
|
860
916
|
})
|
|
861
|
-
private async proposeCheckpoint(): Promise<
|
|
917
|
+
private async proposeCheckpoint(): Promise<CheckpointProposalOutcome | undefined> {
|
|
862
918
|
try {
|
|
863
919
|
const now = this.dateProvider.now();
|
|
864
920
|
if (this.proposedCheckpointData) {
|
|
@@ -886,7 +942,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
886
942
|
publisherAddress: this.publisher.getSenderAddress().toString(),
|
|
887
943
|
coinbase: coinbase.toString(),
|
|
888
944
|
});
|
|
889
|
-
this.metrics.incOpenSlot(this.targetSlot
|
|
945
|
+
this.metrics.incOpenSlot(this.targetSlot);
|
|
890
946
|
|
|
891
947
|
// Enqueues checkpoint invalidation (constant for the whole slot)
|
|
892
948
|
if (this.invalidateCheckpoint && !this.config.skipInvalidateBlockAsProposer) {
|
|
@@ -897,7 +953,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
897
953
|
// pending/archive/fee-header to "as if the proposed parent had landed", so both the
|
|
898
954
|
// mana-min-fee simulation (in the globals builder) and the pre-gossip
|
|
899
955
|
// validateCheckpointHeaderAndInbox preflight see the chain tip the eventual L1 send will see.
|
|
900
|
-
|
|
956
|
+
const simulationOverridesPlan = await buildCheckpointSimulationOverridesPlan({
|
|
901
957
|
checkpointNumber: this.checkpointNumber,
|
|
902
958
|
proposedCheckpointData: this.proposedCheckpointData,
|
|
903
959
|
invalidateToPendingCheckpointNumber: this.invalidateCheckpoint?.forcePendingCheckpointNumber,
|
|
@@ -911,7 +967,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
911
967
|
coinbase,
|
|
912
968
|
feeRecipient,
|
|
913
969
|
this.targetSlot,
|
|
914
|
-
|
|
970
|
+
simulationOverridesPlan,
|
|
915
971
|
);
|
|
916
972
|
|
|
917
973
|
// Collect the out hashes of all the checkpoints before this one in the same epoch.
|
|
@@ -923,6 +979,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
923
979
|
blockSource: this.l2BlockSource,
|
|
924
980
|
epoch: this.targetEpoch,
|
|
925
981
|
checkpointNumber: this.checkpointNumber,
|
|
982
|
+
// The rollup's epoch duration, as validators use: the job's own constants take it from node config.
|
|
926
983
|
l1Constants: this.epochCache.getL1Constants(),
|
|
927
984
|
pipeliningEnabled: true,
|
|
928
985
|
proposedCheckpointData: this.proposedCheckpointData,
|
|
@@ -942,7 +999,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
942
999
|
// Anchor the modifier to the predicted parent fee header: L1 will apply it against
|
|
943
1000
|
// that, not against the latest published checkpoint (which lags by one under pipelining).
|
|
944
1001
|
const predictedParentEthPerFeeAssetE12 =
|
|
945
|
-
|
|
1002
|
+
simulationOverridesPlan?.pendingCheckpointState?.feeHeader?.ethPerFeeAsset;
|
|
946
1003
|
const feeAssetPriceModifier = await this.publisher.getFeeAssetPriceModifier(predictedParentEthPerFeeAssetE12);
|
|
947
1004
|
|
|
948
1005
|
// Create a long-lived forked world state for the checkpoint builder
|
|
@@ -951,7 +1008,13 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
951
1008
|
// Streaming Inbox: the consumption cursor starts at the parent state this checkpoint builds on. The fork's
|
|
952
1009
|
// L1-to-L2 tree leaf count is the parent's cumulative consumed total (compact indexing), whose prefix hash the
|
|
953
1010
|
// local message log serves.
|
|
954
|
-
const
|
|
1011
|
+
const consumption = await CheckpointInboxConsumption.start(fork, {
|
|
1012
|
+
messageSource: this.l1ToL2MessageSource,
|
|
1013
|
+
inbox: this.inbox,
|
|
1014
|
+
dateProvider: this.dateProvider,
|
|
1015
|
+
log: this.log,
|
|
1016
|
+
logContext: { slot: this.targetSlot, checkpointNumber: this.checkpointNumber },
|
|
1017
|
+
});
|
|
955
1018
|
|
|
956
1019
|
// Create checkpoint builder for the entire slot
|
|
957
1020
|
const checkpointBuilder = await this.checkpointsBuilder.startCheckpoint(
|
|
@@ -978,10 +1041,6 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
978
1041
|
|
|
979
1042
|
let blocksInCheckpoint: L2Block[] = [];
|
|
980
1043
|
let blockPendingBroadcast: BlockProposal | undefined = undefined;
|
|
981
|
-
// Consumption state after the last block built. The pre-gossip preflight validates the header against it and it
|
|
982
|
-
// travels with the broadcast result so the pre-publication preflight can re-resolve the bucket hint. Every path
|
|
983
|
-
// that reads it below is reached only once the block loop has returned its final state.
|
|
984
|
-
let streamingState = initialStreamingState;
|
|
985
1044
|
const checkpointBuildTimer = new Timer();
|
|
986
1045
|
|
|
987
1046
|
try {
|
|
@@ -990,14 +1049,13 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
990
1049
|
checkpointBuilder,
|
|
991
1050
|
checkpointGlobalVariables.timestamp,
|
|
992
1051
|
blockProposalOptions,
|
|
993
|
-
|
|
1052
|
+
consumption,
|
|
994
1053
|
);
|
|
995
1054
|
if (result.aborted) {
|
|
996
1055
|
return undefined;
|
|
997
1056
|
}
|
|
998
1057
|
blocksInCheckpoint = result.blocksInCheckpoint;
|
|
999
1058
|
blockPendingBroadcast = result.blockPendingBroadcast;
|
|
1000
|
-
streamingState = result.streamingState;
|
|
1001
1059
|
} catch (err) {
|
|
1002
1060
|
// These errors are expected in HA mode, so we yield and let another HA node handle the slot
|
|
1003
1061
|
// The only distinction between the 2 errors is SlashingProtectionError throws when the payload is different,
|
|
@@ -1009,30 +1067,20 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
1009
1067
|
}
|
|
1010
1068
|
|
|
1011
1069
|
if (blocksInCheckpoint.length === 0) {
|
|
1012
|
-
this.
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
reason: 'no_blocks_built',
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
slot: this.targetSlot,
|
|
1019
|
-
checkpointNumber: this.checkpointNumber,
|
|
1020
|
-
reason: 'no_blocks_built',
|
|
1021
|
-
});
|
|
1070
|
+
this.reportCheckpointFailure(
|
|
1071
|
+
'build-failed',
|
|
1072
|
+
`No blocks were built for slot ${this.targetSlot}`,
|
|
1073
|
+
{ slot: this.targetSlot, checkpointNumber: this.checkpointNumber, reason: 'no_blocks_built' },
|
|
1074
|
+
{ level: 'warn' },
|
|
1075
|
+
);
|
|
1022
1076
|
this.eventEmitter.emit('checkpoint-empty', { slot: this.targetSlot });
|
|
1023
1077
|
return undefined;
|
|
1024
1078
|
}
|
|
1025
1079
|
|
|
1026
1080
|
const minBlocksForCheckpoint = this.config.minBlocksForCheckpoint;
|
|
1027
1081
|
if (minBlocksForCheckpoint !== undefined && blocksInCheckpoint.length < minBlocksForCheckpoint) {
|
|
1028
|
-
this.
|
|
1029
|
-
|
|
1030
|
-
checkpointNumber: this.checkpointNumber,
|
|
1031
|
-
blocksBuilt: blocksInCheckpoint.length,
|
|
1032
|
-
minBlocksForCheckpoint,
|
|
1033
|
-
reason: 'min_blocks_not_met',
|
|
1034
|
-
});
|
|
1035
|
-
this.log.warn(
|
|
1082
|
+
this.reportCheckpointFailure(
|
|
1083
|
+
'build-failed',
|
|
1036
1084
|
`Checkpoint has fewer blocks than minimum (${blocksInCheckpoint.length} < ${minBlocksForCheckpoint}), skipping proposal`,
|
|
1037
1085
|
{
|
|
1038
1086
|
slot: this.targetSlot,
|
|
@@ -1041,6 +1089,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
1041
1089
|
minBlocksForCheckpoint,
|
|
1042
1090
|
reason: 'min_blocks_not_met',
|
|
1043
1091
|
},
|
|
1092
|
+
{ level: 'warn' },
|
|
1044
1093
|
);
|
|
1045
1094
|
return undefined;
|
|
1046
1095
|
}
|
|
@@ -1061,20 +1110,18 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
1061
1110
|
maxTxsPerCheckpoint: this.config.maxTxsPerCheckpoint,
|
|
1062
1111
|
});
|
|
1063
1112
|
} catch (err) {
|
|
1064
|
-
this.
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
checkpoint: checkpoint.header.toInspect(),
|
|
1077
|
-
});
|
|
1113
|
+
this.reportCheckpointFailure(
|
|
1114
|
+
'build-failed',
|
|
1115
|
+
`Built an invalid checkpoint at slot ${this.targetSlot} (skipping proposal)`,
|
|
1116
|
+
{
|
|
1117
|
+
slot: this.targetSlot,
|
|
1118
|
+
checkpointNumber: this.checkpointNumber,
|
|
1119
|
+
blocksBuilt: blocksInCheckpoint.length,
|
|
1120
|
+
reason: 'invalid_checkpoint',
|
|
1121
|
+
checkpoint: checkpoint.header.toInspect(),
|
|
1122
|
+
},
|
|
1123
|
+
{ level: 'error', err },
|
|
1124
|
+
);
|
|
1078
1125
|
return undefined;
|
|
1079
1126
|
}
|
|
1080
1127
|
|
|
@@ -1109,9 +1156,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
1109
1156
|
},
|
|
1110
1157
|
);
|
|
1111
1158
|
this.metrics.recordCheckpointSuccess();
|
|
1112
|
-
|
|
1113
|
-
// publishes.
|
|
1114
|
-
return { checkpoint, proposal: undefined!, blockProposedAt: this.dateProvider.now(), streamingState };
|
|
1159
|
+
return { kind: 'built-only', checkpoint };
|
|
1115
1160
|
}
|
|
1116
1161
|
|
|
1117
1162
|
// Validate the header and the Inbox consumption against L1 state before broadcasting: the parent the header
|
|
@@ -1124,8 +1169,8 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
1124
1169
|
try {
|
|
1125
1170
|
await this.preflightWithinDeadline(
|
|
1126
1171
|
checkpoint.header,
|
|
1127
|
-
|
|
1128
|
-
|
|
1172
|
+
consumption.consumedTotalMsgCount,
|
|
1173
|
+
simulationOverridesPlan,
|
|
1129
1174
|
this.getAttestationDeadline(),
|
|
1130
1175
|
);
|
|
1131
1176
|
} catch (err) {
|
|
@@ -1136,7 +1181,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
1136
1181
|
this.log.error(`Pre-broadcast header and Inbox validation failed for slot ${this.targetSlot}; aborting`, err, {
|
|
1137
1182
|
slot: this.targetSlot,
|
|
1138
1183
|
checkpointNumber: this.checkpointNumber,
|
|
1139
|
-
consumedTotalMsgCount:
|
|
1184
|
+
consumedTotalMsgCount: consumption.consumedTotalMsgCount,
|
|
1140
1185
|
inboxRollingHash: checkpoint.header.inboxRollingHash.toString(),
|
|
1141
1186
|
reason,
|
|
1142
1187
|
});
|
|
@@ -1165,7 +1210,12 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
1165
1210
|
// checkpoint visible for pipelining the next slot. Built from local checkpoint data — never
|
|
1166
1211
|
// from the broadcast proposal archive, which may be deliberately corrupted under test flags.
|
|
1167
1212
|
// Fail closed: if this throws, the outer catch aborts the slot before gossiping.
|
|
1168
|
-
await this.syncProposedCheckpointToArchiver(
|
|
1213
|
+
await this.syncProposedCheckpointToArchiver(
|
|
1214
|
+
checkpoint,
|
|
1215
|
+
proposal,
|
|
1216
|
+
blocksInCheckpoint.length,
|
|
1217
|
+
feeAssetPriceModifier,
|
|
1218
|
+
);
|
|
1169
1219
|
|
|
1170
1220
|
const blockProposedAt = this.dateProvider.now();
|
|
1171
1221
|
if (this.config.skipBroadcastCheckpointProposal) {
|
|
@@ -1182,10 +1232,18 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
1182
1232
|
}
|
|
1183
1233
|
|
|
1184
1234
|
// Return immediately after broadcast — attestation collection happens in the background.
|
|
1185
|
-
return {
|
|
1235
|
+
return {
|
|
1236
|
+
kind: 'broadcast',
|
|
1237
|
+
checkpoint,
|
|
1238
|
+
proposal,
|
|
1239
|
+
blockProposedAt,
|
|
1240
|
+
consumedTotalMsgCount: consumption.consumedTotalMsgCount,
|
|
1241
|
+
simulationOverridesPlan,
|
|
1242
|
+
};
|
|
1186
1243
|
} catch (err) {
|
|
1187
1244
|
if (err && (err instanceof DutyAlreadySignedError || err instanceof SlashingProtectionError)) {
|
|
1188
1245
|
// swallow this error. It's already been logged by a function deeper in the stack
|
|
1246
|
+
this.yieldedToHAPeer = true;
|
|
1189
1247
|
return undefined;
|
|
1190
1248
|
}
|
|
1191
1249
|
|
|
@@ -1202,7 +1260,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
1202
1260
|
checkpointBuilder: CheckpointBuilder,
|
|
1203
1261
|
timestamp: bigint,
|
|
1204
1262
|
blockProposalOptions: BlockProposalOptions,
|
|
1205
|
-
|
|
1263
|
+
consumption: CheckpointInboxConsumption,
|
|
1206
1264
|
): Promise<BlockBuildingResult> {
|
|
1207
1265
|
const blocksInCheckpoint: L2Block[] = [];
|
|
1208
1266
|
const txHashesAlreadyIncluded = new Set<string>();
|
|
@@ -1210,10 +1268,6 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
1210
1268
|
|
|
1211
1269
|
// Last block in the checkpoint will usually be flagged as pending broadcast, so we send it along with the checkpoint proposal
|
|
1212
1270
|
let blockPendingBroadcast: BlockProposal | undefined = undefined;
|
|
1213
|
-
let streamingState = initialStreamingState;
|
|
1214
|
-
// Streaming Inbox: the loop ran out of sub-slots rather than finishing the checkpoint, so the cursor may be
|
|
1215
|
-
// sitting at a prefix that is not a live L1 bucket end.
|
|
1216
|
-
let ranOutOfSubslots = false;
|
|
1217
1271
|
|
|
1218
1272
|
while (true) {
|
|
1219
1273
|
const blocksBuilt = blocksInCheckpoint.length;
|
|
@@ -1238,7 +1292,26 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
1238
1292
|
blocksBuilt,
|
|
1239
1293
|
nowSeconds,
|
|
1240
1294
|
});
|
|
1241
|
-
|
|
1295
|
+
// Streaming Inbox: the sub-slot schedule ran out mid-checkpoint, so the cursor may sit at a prefix that is not
|
|
1296
|
+
// a live L1 bucket end, which no checkpoint can be published on. Resolve once and, if it is not one, build one
|
|
1297
|
+
// more block rather than lose the slot; this is the only place the loop overrides the timetable. A cursor
|
|
1298
|
+
// still at the checkpoint start needs nothing: the parent checkpoint already ended on a live bucket end.
|
|
1299
|
+
if (consumption.hasConsumedInThisCheckpoint) {
|
|
1300
|
+
const forced = await this.buildForcedEndpointBlock(checkpointBuilder, consumption, {
|
|
1301
|
+
blockTimestamp: timestamp,
|
|
1302
|
+
blockNumber,
|
|
1303
|
+
indexWithinCheckpoint,
|
|
1304
|
+
txHashesAlreadyIncluded,
|
|
1305
|
+
blockProposalOptions,
|
|
1306
|
+
});
|
|
1307
|
+
if (forced.kind === 'aborted') {
|
|
1308
|
+
return { aborted: true };
|
|
1309
|
+
}
|
|
1310
|
+
if (forced.kind === 'built') {
|
|
1311
|
+
blocksInCheckpoint.push(forced.block);
|
|
1312
|
+
blockPendingBroadcast = forced.proposal;
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1242
1315
|
break;
|
|
1243
1316
|
}
|
|
1244
1317
|
|
|
@@ -1249,7 +1322,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
1249
1322
|
// includes the block that reaches the per-checkpoint block cap, not just the timetable's last sub-slot.
|
|
1250
1323
|
const maxBlocks = Math.min(this.config.maxBlocksPerCheckpoint, this.timetable.getMaxBlocksPerCheckpoint());
|
|
1251
1324
|
const isCheckpointFinalBlock = timingInfo.isLastBlock || blocksBuilt + 1 >= maxBlocks;
|
|
1252
|
-
const selection = await
|
|
1325
|
+
const selection = await consumption.selectRange({
|
|
1253
1326
|
isFinalBlock: isCheckpointFinalBlock,
|
|
1254
1327
|
buildDeadline: timingInfo.deadline,
|
|
1255
1328
|
});
|
|
@@ -1257,7 +1330,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
1257
1330
|
// No checkpoint ending on the messages this block could consume can be published: stop before signing
|
|
1258
1331
|
// anything more and give up the slot.
|
|
1259
1332
|
if (selection.kind === 'abort') {
|
|
1260
|
-
this.reportStreamingAbort(
|
|
1333
|
+
this.reportStreamingAbort(consumption, selection.reason, {
|
|
1261
1334
|
blocksBuilt,
|
|
1262
1335
|
blockNumber,
|
|
1263
1336
|
...selection.context,
|
|
@@ -1278,7 +1351,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
1278
1351
|
});
|
|
1279
1352
|
|
|
1280
1353
|
// If we failed to build the block due to insufficient txs, we try again if there is still time left in the slot
|
|
1281
|
-
if ('
|
|
1354
|
+
if (buildResult.kind === 'skipped') {
|
|
1282
1355
|
// If this was the last subslot, we're done.
|
|
1283
1356
|
if (timingInfo.isLastBlock) {
|
|
1284
1357
|
break;
|
|
@@ -1290,7 +1363,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
1290
1363
|
|
|
1291
1364
|
// If there was an error building the block, we just exit the loop and give up the rest of the slot.
|
|
1292
1365
|
// We don't want to risk building more blocks if something went wrong.
|
|
1293
|
-
if ('
|
|
1366
|
+
if (buildResult.kind === 'failed') {
|
|
1294
1367
|
if (!(buildResult.error instanceof SequencerInterruptedError)) {
|
|
1295
1368
|
this.log.warn(`Halting block building for slot ${this.targetSlot}`, {
|
|
1296
1369
|
slot: this.targetSlot,
|
|
@@ -1310,40 +1383,21 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
1310
1383
|
blocksInCheckpoint.push(block);
|
|
1311
1384
|
usedTxs.forEach(tx => txHashesAlreadyIncluded.add(tx.txHash.toString()));
|
|
1312
1385
|
|
|
1313
|
-
|
|
1314
|
-
// sign that prefix as this block's reference. A block that consumed nothing re-signs the cursor's prefix.
|
|
1315
|
-
streamingState = { ...streamingState, cursor: selection.range.end };
|
|
1316
|
-
const blockPrefixRef = InboxMessagePrefixRef.fromPosition(streamingState.cursor);
|
|
1317
|
-
|
|
1318
|
-
// Sign the block proposal. This will throw if HA signing fails.
|
|
1319
|
-
const proposal = await this.createBlockProposal(
|
|
1386
|
+
const { proposal, blockPrefixRef } = await this.commitBuiltBlock(
|
|
1320
1387
|
block,
|
|
1321
1388
|
usedTxs,
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
blockProposalOptions.broadcastInvalidBlockProposal ||
|
|
1326
|
-
block.indexWithinCheckpoint === this.config.invalidBlockProposalIndexWithinCheckpoint,
|
|
1327
|
-
},
|
|
1328
|
-
blockPrefixRef,
|
|
1389
|
+
selection.range,
|
|
1390
|
+
consumption,
|
|
1391
|
+
blockProposalOptions,
|
|
1329
1392
|
);
|
|
1330
1393
|
|
|
1331
|
-
// Sync the proposed block to the archiver to make it available, only after we've managed to sign the proposal,
|
|
1332
|
-
// so we avoid polluting our archive with a block that would fail.
|
|
1333
|
-
// We wait for the sync to succeed, as this helps catch consistency errors, even if it means we lose some time for block-building.
|
|
1334
|
-
// If this throws, we abort the entire checkpoint.
|
|
1335
|
-
await this.syncProposedBlockToArchiver(block, blockPrefixRef);
|
|
1336
|
-
|
|
1337
1394
|
await this.notifyBlockReadyToBroadcast({
|
|
1338
1395
|
block,
|
|
1339
1396
|
blockNumber,
|
|
1340
1397
|
indexWithinCheckpoint,
|
|
1398
|
+
timingInfo,
|
|
1341
1399
|
inboxPrefixRef: blockPrefixRef,
|
|
1342
|
-
consumedMessageCount:
|
|
1343
|
-
isStandalone: !timingInfo.isLastBlock,
|
|
1344
|
-
remainingBuildSubslots: Math.max(0, maxBlocks - (timingInfo.index + 1)),
|
|
1345
|
-
subslotIndex: timingInfo.index,
|
|
1346
|
-
subslotDeadline: timingInfo.deadline,
|
|
1400
|
+
consumedMessageCount: consumption.consumedTotalMsgCount,
|
|
1347
1401
|
blocksBuiltIncludingThis: blocksInCheckpoint.length,
|
|
1348
1402
|
maxBlocksInCheckpoint: maxBlocks,
|
|
1349
1403
|
});
|
|
@@ -1369,40 +1423,12 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
1369
1423
|
await this.waitUntilNextSubslot(timingInfo.deadline);
|
|
1370
1424
|
}
|
|
1371
1425
|
|
|
1372
|
-
// Streaming Inbox: the sub-slot schedule ran out mid-checkpoint, so the cursor may sit at a prefix that is not a
|
|
1373
|
-
// live L1 bucket end, which no checkpoint can be published on. Resolve once and, if it is not one, build one more
|
|
1374
|
-
// block rather than lose the slot; this is the only place the loop overrides the timetable. A cursor still at the
|
|
1375
|
-
// checkpoint start needs nothing: the parent checkpoint already ended on a live bucket end.
|
|
1376
|
-
if (
|
|
1377
|
-
ranOutOfSubslots &&
|
|
1378
|
-
blocksInCheckpoint.length > 0 &&
|
|
1379
|
-
streamingState.cursor.totalMessageCount > streamingState.checkpointStartTotalMsgCount
|
|
1380
|
-
) {
|
|
1381
|
-
const forced = await this.buildForcedEndpointBlock(checkpointBuilder, streamingState, {
|
|
1382
|
-
blockTimestamp: timestamp,
|
|
1383
|
-
blockNumber: BlockNumber(initialBlockNumber + blocksInCheckpoint.length),
|
|
1384
|
-
indexWithinCheckpoint: IndexWithinCheckpoint(blocksInCheckpoint.length),
|
|
1385
|
-
txHashesAlreadyIncluded,
|
|
1386
|
-
blockProposalOptions,
|
|
1387
|
-
});
|
|
1388
|
-
if (forced !== undefined) {
|
|
1389
|
-
if ('aborted' in forced) {
|
|
1390
|
-
return { aborted: true };
|
|
1391
|
-
}
|
|
1392
|
-
blocksInCheckpoint.push(forced.block);
|
|
1393
|
-
blockPendingBroadcast = forced.proposal;
|
|
1394
|
-
// The tail consumed through its endpoint, so the checkpoint's final cursor is the tail's, not the one the
|
|
1395
|
-
// loop stopped at. Both preflights read this state.
|
|
1396
|
-
streamingState = forced.streamingState;
|
|
1397
|
-
}
|
|
1398
|
-
}
|
|
1399
|
-
|
|
1400
1426
|
this.log.verbose(`Block building loop completed for slot ${this.targetSlot}`, {
|
|
1401
1427
|
slot: this.targetSlot,
|
|
1402
1428
|
blocksBuilt: blocksInCheckpoint.length,
|
|
1403
1429
|
});
|
|
1404
1430
|
|
|
1405
|
-
return { aborted: false, blocksInCheckpoint, blockPendingBroadcast
|
|
1431
|
+
return { aborted: false, blocksInCheckpoint, blockPendingBroadcast };
|
|
1406
1432
|
}
|
|
1407
1433
|
|
|
1408
1434
|
/**
|
|
@@ -1419,12 +1445,9 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
1419
1445
|
block: L2Block;
|
|
1420
1446
|
blockNumber: BlockNumber;
|
|
1421
1447
|
indexWithinCheckpoint: IndexWithinCheckpoint;
|
|
1448
|
+
timingInfo: Extract<SubslotSelection, { canStart: true }>;
|
|
1422
1449
|
inboxPrefixRef: InboxMessagePrefixRef;
|
|
1423
1450
|
consumedMessageCount: bigint;
|
|
1424
|
-
isStandalone: boolean;
|
|
1425
|
-
remainingBuildSubslots: number;
|
|
1426
|
-
subslotIndex: number;
|
|
1427
|
-
subslotDeadline: number;
|
|
1428
1451
|
blocksBuiltIncludingThis: number;
|
|
1429
1452
|
maxBlocksInCheckpoint: number;
|
|
1430
1453
|
}): Promise<void> {
|
|
@@ -1432,6 +1455,9 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
1432
1455
|
if (onCheckpointPhase === undefined) {
|
|
1433
1456
|
return;
|
|
1434
1457
|
}
|
|
1458
|
+
const { block, timingInfo } = opts;
|
|
1459
|
+
const subslotIndex = timingInfo.index;
|
|
1460
|
+
const subslotDeadline = timingInfo.deadline;
|
|
1435
1461
|
const sendDeadline =
|
|
1436
1462
|
this.timetable.getCheckpointProposalReceiveDeadline(this.targetSlot) - this.timetable.p2pPropagationTime;
|
|
1437
1463
|
await onCheckpointPhase({
|
|
@@ -1440,22 +1466,22 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
1440
1466
|
checkpointNumber: this.checkpointNumber,
|
|
1441
1467
|
blockNumber: opts.blockNumber,
|
|
1442
1468
|
indexWithinCheckpoint: opts.indexWithinCheckpoint,
|
|
1443
|
-
blockHash: await
|
|
1444
|
-
isStandalone:
|
|
1445
|
-
remainingBuildSubslots: opts.
|
|
1446
|
-
subslotIndex
|
|
1469
|
+
blockHash: await block.hash(),
|
|
1470
|
+
isStandalone: !timingInfo.isLastBlock,
|
|
1471
|
+
remainingBuildSubslots: Math.max(0, opts.maxBlocksInCheckpoint - (subslotIndex + 1)),
|
|
1472
|
+
subslotIndex,
|
|
1447
1473
|
proposalSendDeadline: new Date(sendDeadline * 1000),
|
|
1448
1474
|
consumedMessageCount: opts.consumedMessageCount,
|
|
1449
1475
|
inboxPrefixRef: opts.inboxPrefixRef,
|
|
1450
1476
|
schedule: {
|
|
1451
1477
|
nowMs: () => this.dateProvider.now(),
|
|
1452
|
-
selectNextBuildSubslot: nowSeconds => this.selectNextBuildSubslot(nowSeconds,
|
|
1478
|
+
selectNextBuildSubslot: nowSeconds => this.selectNextBuildSubslot(nowSeconds, subslotDeadline),
|
|
1453
1479
|
canBuildAnotherBlock: nowSeconds => {
|
|
1454
1480
|
if (opts.blocksBuiltIncludingThis >= opts.maxBlocksInCheckpoint) {
|
|
1455
1481
|
return false;
|
|
1456
1482
|
}
|
|
1457
|
-
const next = this.selectNextBuildSubslot(nowSeconds,
|
|
1458
|
-
return next.canStart && next.index >
|
|
1483
|
+
const next = this.selectNextBuildSubslot(nowSeconds, subslotDeadline);
|
|
1484
|
+
return next.canStart && next.index > subslotIndex;
|
|
1459
1485
|
},
|
|
1460
1486
|
getProposalReceiveDeadlineSeconds: () => this.timetable.getCheckpointProposalReceiveDeadline(this.targetSlot),
|
|
1461
1487
|
getProposalReceiveStartSeconds: () => this.timetable.getCheckpointProposalReceiveStart(this.targetSlot),
|
|
@@ -1479,13 +1505,13 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
1479
1505
|
* one, nothing is built and the checkpoint publishes as it stands. The block carries no transactions: it is
|
|
1480
1506
|
* already past the schedule, so it must not spend its remaining time executing any.
|
|
1481
1507
|
*
|
|
1482
|
-
* Returns the block
|
|
1483
|
-
*
|
|
1484
|
-
*
|
|
1508
|
+
* Returns the block and its signed proposal, `not-needed` when the cursor already sits on a live bucket end, or an
|
|
1509
|
+
* abort when the checkpoint has to be abandoned. The abort is already reported. The consumption cursor advances to
|
|
1510
|
+
* the endpoint only once the block has built.
|
|
1485
1511
|
*/
|
|
1486
1512
|
private async buildForcedEndpointBlock(
|
|
1487
1513
|
checkpointBuilder: CheckpointBuilder,
|
|
1488
|
-
|
|
1514
|
+
consumption: CheckpointInboxConsumption,
|
|
1489
1515
|
opts: {
|
|
1490
1516
|
blockTimestamp: bigint;
|
|
1491
1517
|
blockNumber: BlockNumber;
|
|
@@ -1494,85 +1520,53 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
1494
1520
|
blockProposalOptions: BlockProposalOptions;
|
|
1495
1521
|
},
|
|
1496
1522
|
): Promise<
|
|
1497
|
-
| { block: L2Block; proposal: BlockProposal | undefined
|
|
1498
|
-
| {
|
|
1499
|
-
|
|
|
1523
|
+
| { kind: 'built'; block: L2Block; proposal: BlockProposal | undefined }
|
|
1524
|
+
| { kind: 'not-needed' }
|
|
1525
|
+
| { kind: 'aborted' }
|
|
1500
1526
|
> {
|
|
1501
|
-
const
|
|
1502
|
-
const localSyncedCount = (await this.l1ToL2MessageSource.getSyncedMessagePosition()).totalMessageCount;
|
|
1503
|
-
const upperBound = getEndpointUpperBound({
|
|
1504
|
-
cursorCount: cursor.totalMessageCount,
|
|
1505
|
-
localSyncedCount,
|
|
1506
|
-
checkpointStartCount,
|
|
1507
|
-
isFinalBlock: true,
|
|
1508
|
-
caps: PROTOCOL_INBOX_CONSUMPTION_CAPS,
|
|
1509
|
-
});
|
|
1510
|
-
const { deadline, pastLastBlockBuildTime } = this.getForcedEndpointBlockDeadline();
|
|
1511
|
-
this.log.warn(`Ending checkpoint ${this.checkpointNumber} with a forced Inbox endpoint block`, {
|
|
1512
|
-
slot: this.targetSlot,
|
|
1513
|
-
checkpointNumber: this.checkpointNumber,
|
|
1527
|
+
const decision = await consumption.resolveForcedEndpoint({
|
|
1514
1528
|
blockNumber: opts.blockNumber,
|
|
1515
|
-
|
|
1516
|
-
upperBound,
|
|
1517
|
-
deadline: deadline.toISOString(),
|
|
1518
|
-
pastLastBlockBuildTime,
|
|
1529
|
+
getDeadline: () => this.getForcedEndpointBlockDeadline(),
|
|
1519
1530
|
});
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
const reason =
|
|
1524
|
-
resolved.reason === 'local_prefix_changed' ? 'inbox_prefix_reorged' : 'inbox_completion_unresolved';
|
|
1525
|
-
this.reportStreamingAbort(streamingState, reason, {
|
|
1526
|
-
phase: 'forced_tail_block',
|
|
1527
|
-
cause: resolved.reason,
|
|
1528
|
-
upperBound,
|
|
1529
|
-
endpointTotal: resolved.endpointTotal,
|
|
1530
|
-
localSyncedCount,
|
|
1531
|
-
});
|
|
1532
|
-
return { aborted: true };
|
|
1531
|
+
if (decision.kind === 'abort') {
|
|
1532
|
+
this.reportStreamingAbort(consumption, decision.reason, { phase: 'forced_tail_block', ...decision.context });
|
|
1533
|
+
return { kind: 'aborted' };
|
|
1533
1534
|
}
|
|
1534
|
-
if (
|
|
1535
|
-
|
|
1536
|
-
slot: this.targetSlot,
|
|
1537
|
-
checkpointNumber: this.checkpointNumber,
|
|
1538
|
-
cursorTotalMsgCount: cursor.totalMessageCount,
|
|
1539
|
-
});
|
|
1540
|
-
return undefined;
|
|
1535
|
+
if (decision.kind === 'already-at-endpoint') {
|
|
1536
|
+
return { kind: 'not-needed' };
|
|
1541
1537
|
}
|
|
1542
1538
|
|
|
1543
1539
|
const buildResult = await this.buildSingleBlock(checkpointBuilder, {
|
|
1544
1540
|
forceCreate: true,
|
|
1545
1541
|
skipTransactions: true,
|
|
1546
1542
|
blockTimestamp: opts.blockTimestamp,
|
|
1547
|
-
buildDeadline: deadline,
|
|
1543
|
+
buildDeadline: decision.deadline,
|
|
1548
1544
|
blockNumber: opts.blockNumber,
|
|
1549
1545
|
indexWithinCheckpoint: opts.indexWithinCheckpoint,
|
|
1550
1546
|
txHashesAlreadyIncluded: opts.txHashesAlreadyIncluded,
|
|
1551
|
-
l1ToL2Messages:
|
|
1547
|
+
l1ToL2Messages: decision.range.messages,
|
|
1552
1548
|
});
|
|
1553
|
-
if (
|
|
1554
|
-
this.reportStreamingAbort(
|
|
1549
|
+
if (buildResult.kind !== 'built') {
|
|
1550
|
+
this.reportStreamingAbort(consumption, 'inbox_completion_unresolved', {
|
|
1555
1551
|
phase: 'forced_tail_block',
|
|
1556
|
-
cause: '
|
|
1557
|
-
endpointTotalMsgCount:
|
|
1552
|
+
cause: buildResult.kind === 'skipped' ? buildResult.reason : buildResult.error.message,
|
|
1553
|
+
endpointTotalMsgCount: decision.range.end.totalMessageCount,
|
|
1558
1554
|
});
|
|
1559
|
-
return {
|
|
1555
|
+
return { kind: 'aborted' };
|
|
1560
1556
|
}
|
|
1561
1557
|
|
|
1562
|
-
const
|
|
1563
|
-
const blockPrefixRef = InboxMessagePrefixRef.fromPosition(advancedState.cursor);
|
|
1564
|
-
const proposal = await this.createBlockProposal(
|
|
1558
|
+
const { proposal } = await this.commitBuiltBlock(
|
|
1565
1559
|
buildResult.block,
|
|
1566
1560
|
buildResult.usedTxs,
|
|
1561
|
+
decision.range,
|
|
1562
|
+
consumption,
|
|
1567
1563
|
opts.blockProposalOptions,
|
|
1568
|
-
blockPrefixRef,
|
|
1569
1564
|
);
|
|
1570
|
-
await this.syncProposedBlockToArchiver(buildResult.block, blockPrefixRef);
|
|
1571
1565
|
this.checkpointMetrics.noteCheckpointBlockBuilt(this.dateProvider.now(), {
|
|
1572
1566
|
isFirstBlock: false,
|
|
1573
1567
|
isLastBlock: true,
|
|
1574
1568
|
});
|
|
1575
|
-
return { block: buildResult.block, proposal
|
|
1569
|
+
return { kind: 'built', block: buildResult.block, proposal };
|
|
1576
1570
|
}
|
|
1577
1571
|
|
|
1578
1572
|
/**
|
|
@@ -1591,6 +1585,43 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
1591
1585
|
return { deadline: new Date(hardStop * 1000), pastLastBlockBuildTime: true };
|
|
1592
1586
|
}
|
|
1593
1587
|
|
|
1588
|
+
/**
|
|
1589
|
+
* Commits the Inbox range a block was built over, then signs and stores the block. The loop and the forced tail
|
|
1590
|
+
* block share it; what to do with the signed proposal (gossip it or hold it for the checkpoint) stays theirs.
|
|
1591
|
+
*/
|
|
1592
|
+
private async commitBuiltBlock(
|
|
1593
|
+
block: L2Block,
|
|
1594
|
+
usedTxs: Tx[],
|
|
1595
|
+
range: InboxMessageRange,
|
|
1596
|
+
consumption: CheckpointInboxConsumption,
|
|
1597
|
+
blockProposalOptions: BlockProposalOptions,
|
|
1598
|
+
): Promise<{ proposal: BlockProposal | undefined; blockPrefixRef: InboxMessagePrefixRef }> {
|
|
1599
|
+
// Streaming Inbox: the block built successfully, so advance the cursor to the prefix it consumed through and
|
|
1600
|
+
// sign that prefix as this block's reference. A block that consumed nothing re-signs the cursor's prefix.
|
|
1601
|
+
const blockPrefixRef = consumption.commit(range);
|
|
1602
|
+
|
|
1603
|
+
// Sign the block proposal. This will throw if HA signing fails.
|
|
1604
|
+
const proposal = await this.createBlockProposal(
|
|
1605
|
+
block,
|
|
1606
|
+
usedTxs,
|
|
1607
|
+
{
|
|
1608
|
+
...blockProposalOptions,
|
|
1609
|
+
broadcastInvalidBlockProposal:
|
|
1610
|
+
blockProposalOptions.broadcastInvalidBlockProposal ||
|
|
1611
|
+
block.indexWithinCheckpoint === this.config.invalidBlockProposalIndexWithinCheckpoint,
|
|
1612
|
+
},
|
|
1613
|
+
blockPrefixRef,
|
|
1614
|
+
);
|
|
1615
|
+
|
|
1616
|
+
// Sync the proposed block to the archiver to make it available, only after we've managed to sign the proposal,
|
|
1617
|
+
// so we avoid polluting our archive with a block that would fail.
|
|
1618
|
+
// We wait for the sync to succeed, as this helps catch consistency errors, even if it means we lose some time for block-building.
|
|
1619
|
+
// If this throws, we abort the entire checkpoint.
|
|
1620
|
+
await this.syncProposedBlockToArchiver(block, blockPrefixRef);
|
|
1621
|
+
|
|
1622
|
+
return { proposal, blockPrefixRef };
|
|
1623
|
+
}
|
|
1624
|
+
|
|
1594
1625
|
/** Creates a block proposal for a given block via the validator client (unless in fisherman mode) */
|
|
1595
1626
|
private createBlockProposal(
|
|
1596
1627
|
block: L2Block,
|
|
@@ -1614,198 +1645,35 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
1614
1645
|
);
|
|
1615
1646
|
}
|
|
1616
1647
|
|
|
1617
|
-
/**
|
|
1618
|
-
* Resolves where a streaming-Inbox checkpoint's consumption starts: the parent checkpoint's consumed message
|
|
1619
|
-
* prefix. The parent's cumulative consumed total is the L1-to-L2 message tree leaf count of the fork this
|
|
1620
|
-
* checkpoint builds on (compact indexing makes leaf count equal cumulative message count), and the local message
|
|
1621
|
-
* log serves the prefix hash at that count. Genesis is the `total = 0` case with a zero hash.
|
|
1622
|
-
*/
|
|
1623
|
-
private async resolveStreamingCheckpointStart(fork: MerkleTreeWriteOperations): Promise<StreamingCheckpointState> {
|
|
1624
|
-
const parentInfo = await fork.getTreeInfo(MerkleTreeId.L1_TO_L2_MESSAGE_TREE);
|
|
1625
|
-
const parentTotalMsgCount = parentInfo.size;
|
|
1626
|
-
const cursor = await this.l1ToL2MessageSource.getMessagePosition(parentTotalMsgCount);
|
|
1627
|
-
if (cursor === undefined) {
|
|
1628
|
-
throw new Error(
|
|
1629
|
-
`Streaming inbox: cannot resolve the Inbox message prefix at cumulative total ${parentTotalMsgCount} ` +
|
|
1630
|
-
`(checkpoint ${this.checkpointNumber}); local Inbox view has not synced it`,
|
|
1631
|
-
);
|
|
1632
|
-
}
|
|
1633
|
-
return { checkpointStartTotalMsgCount: parentTotalMsgCount, cursor };
|
|
1634
|
-
}
|
|
1635
|
-
|
|
1636
|
-
/**
|
|
1637
|
-
* Selects the message range this block consumes. Does not modify `state`; the caller records a state advanced to
|
|
1638
|
-
* `range.end` only after the block builds successfully.
|
|
1639
|
-
*
|
|
1640
|
-
* Selection is greedy on the local log: every message the archiver has observed, up to the per-block and
|
|
1641
|
-
* checkpoint caps. A block consults L1 only when it is the checkpoint's final block, whose position must be a live
|
|
1642
|
-
* L1 bucket end, or when its prospective end would pass the threshold one bucket below the cap and could leave the
|
|
1643
|
-
* last legal endpoint behind. The lookup is bounded by the checkpoint cap on a non-final block, so a mandatory
|
|
1644
|
-
* bucket beyond this block's own reach is not stranded by a nearer endpoint, and additionally by one block's
|
|
1645
|
-
* capacity on the final block. A non-final block then ends at the further of what the lookup allows and the safe
|
|
1646
|
-
* local step, so consulting L1 never consumes less than staying below the threshold would have, and it may
|
|
1647
|
-
* legitimately end inside a bucket. The final block instead ends exactly on the resolved boundary, so whenever the
|
|
1648
|
-
* last live boundary within reach sits behind the safe local step it consumes fewer messages than the local log
|
|
1649
|
-
* alone would allow. Nothing is retained: the next attempt decides again.
|
|
1650
|
-
*
|
|
1651
|
-
* An endpoint that cannot be resolved on a non-final block (local lag, no live endpoint yet) leaves the block with
|
|
1652
|
-
* that safe local step and is retried on the next block; on the final block it abandons the checkpoint. A local
|
|
1653
|
-
* prefix that no longer matches the cursor means the blocks already signed were built on messages the local log
|
|
1654
|
-
* has since replaced, which also abandons the checkpoint.
|
|
1655
|
-
*/
|
|
1656
|
-
private async selectStreamingBundle(
|
|
1657
|
-
state: StreamingCheckpointState,
|
|
1658
|
-
opts: { isFinalBlock: boolean; buildDeadline: number },
|
|
1659
|
-
): Promise<StreamingBundleSelection> {
|
|
1660
|
-
const caps = PROTOCOL_INBOX_CONSUMPTION_CAPS;
|
|
1661
|
-
const { cursor, checkpointStartTotalMsgCount: checkpointStartCount } = state;
|
|
1662
|
-
const cursorCount = cursor.totalMessageCount;
|
|
1663
|
-
const localSyncedCount = (await this.l1ToL2MessageSource.getSyncedMessagePosition()).totalMessageCount;
|
|
1664
|
-
const greedyEnd = selectOrdinaryMessageEnd({ cursorCount, localSyncedCount, checkpointStartCount, caps });
|
|
1665
|
-
|
|
1666
|
-
if (
|
|
1667
|
-
!mustQueryEndpoint({ prospectiveEnd: greedyEnd, checkpointStartCount, isFinalBlock: opts.isFinalBlock, caps })
|
|
1668
|
-
) {
|
|
1669
|
-
return this.readStreamingRange(state, greedyEnd);
|
|
1670
|
-
}
|
|
1671
|
-
|
|
1672
|
-
const upperBound = getEndpointUpperBound({
|
|
1673
|
-
cursorCount,
|
|
1674
|
-
localSyncedCount,
|
|
1675
|
-
checkpointStartCount,
|
|
1676
|
-
isFinalBlock: opts.isFinalBlock,
|
|
1677
|
-
caps,
|
|
1678
|
-
});
|
|
1679
|
-
const resolved = await this.resolveEndpointWithinDeadline(cursor, upperBound, opts.buildDeadline);
|
|
1680
|
-
const safeLocalEnd = selectSafeLocalEnd({ cursorCount, localSyncedCount, checkpointStartCount, caps });
|
|
1681
|
-
if (!resolved.ok) {
|
|
1682
|
-
if (resolved.reason === 'local_prefix_changed') {
|
|
1683
|
-
return { kind: 'abort', reason: 'inbox_prefix_reorged', context: { upperBound } };
|
|
1684
|
-
}
|
|
1685
|
-
if (opts.isFinalBlock) {
|
|
1686
|
-
return {
|
|
1687
|
-
kind: 'abort',
|
|
1688
|
-
reason: 'inbox_completion_unresolved',
|
|
1689
|
-
context: { cause: resolved.reason, upperBound, endpointTotal: resolved.endpointTotal, localSyncedCount },
|
|
1690
|
-
};
|
|
1691
|
-
}
|
|
1692
|
-
this.log.warn(`Streaming Inbox endpoint not resolvable yet, taking the safe local step`, {
|
|
1693
|
-
slot: this.targetSlot,
|
|
1694
|
-
checkpointNumber: this.checkpointNumber,
|
|
1695
|
-
cause: resolved.reason,
|
|
1696
|
-
cursorTotalMsgCount: cursorCount,
|
|
1697
|
-
localSyncedCount,
|
|
1698
|
-
upperBound,
|
|
1699
|
-
endpointTotal: resolved.endpointTotal,
|
|
1700
|
-
safeLocalEnd,
|
|
1701
|
-
});
|
|
1702
|
-
return this.readStreamingRange(state, safeLocalEnd);
|
|
1703
|
-
}
|
|
1704
|
-
|
|
1705
|
-
const endpointTotal = resolved.endpoint.totalMessageCount;
|
|
1706
|
-
const endpointEnd = minBigint(cursorCount + BigInt(caps.perBlockCap), endpointTotal);
|
|
1707
|
-
// The final block has to land on the endpoint, so it takes it even when the safe local step reaches further; any
|
|
1708
|
-
// other block takes the further of the two, so consulting L1 never consumes less than staying below the
|
|
1709
|
-
// threshold would have.
|
|
1710
|
-
const end = opts.isFinalBlock ? endpointEnd : maxBigint(safeLocalEnd, endpointEnd);
|
|
1711
|
-
this.log.verbose(`Streaming Inbox resolved endpoint ${endpointTotal}, consuming through ${end}`, {
|
|
1712
|
-
slot: this.targetSlot,
|
|
1713
|
-
checkpointNumber: this.checkpointNumber,
|
|
1714
|
-
cursorTotalMsgCount: cursorCount,
|
|
1715
|
-
localSyncedCount,
|
|
1716
|
-
upperBound,
|
|
1717
|
-
endpointTotalMsgCount: endpointTotal,
|
|
1718
|
-
bucketSeq: resolved.bucketSeq,
|
|
1719
|
-
end,
|
|
1720
|
-
});
|
|
1721
|
-
// An end short of or past the endpoint needs its own read, so the signed hash is the one at `end` and never the
|
|
1722
|
-
// endpoint's; landing exactly on the endpoint reuses the snapshot the resolver already read and checked against
|
|
1723
|
-
// the cursor's hash.
|
|
1724
|
-
return end === endpointTotal ? { kind: 'consume', range: resolved.range } : this.readStreamingRange(state, end);
|
|
1725
|
-
}
|
|
1726
|
-
|
|
1727
|
-
/**
|
|
1728
|
-
* Reads the messages from the cursor to `end` together with the positions at both ends from one snapshot of the
|
|
1729
|
-
* local log, and checks that the log still starts where the cursor says: the blocks signed so far were built on
|
|
1730
|
-
* that prefix, so a changed prefix (a content-changing L1 reorg) means the checkpoint cannot continue. A range the
|
|
1731
|
-
* log can no longer serve whole is the same condition.
|
|
1732
|
-
*/
|
|
1733
|
-
private async readStreamingRange(state: StreamingCheckpointState, end: bigint): Promise<StreamingBundleSelection> {
|
|
1734
|
-
const { cursor } = state;
|
|
1735
|
-
let range: InboxMessageRange;
|
|
1736
|
-
try {
|
|
1737
|
-
range = await this.l1ToL2MessageSource.getL1ToL2MessageRange(cursor.totalMessageCount, end);
|
|
1738
|
-
} catch (err) {
|
|
1739
|
-
return {
|
|
1740
|
-
kind: 'abort',
|
|
1741
|
-
reason: 'inbox_range_unavailable',
|
|
1742
|
-
context: { end, error: err instanceof Error ? err.message : String(err) },
|
|
1743
|
-
};
|
|
1744
|
-
}
|
|
1745
|
-
if (!range.start.rollingHash.equals(cursor.rollingHash)) {
|
|
1746
|
-
return {
|
|
1747
|
-
kind: 'abort',
|
|
1748
|
-
reason: 'inbox_prefix_reorged',
|
|
1749
|
-
context: { end, localPrefixHash: range.start.rollingHash.toString() },
|
|
1750
|
-
};
|
|
1751
|
-
}
|
|
1752
|
-
return { kind: 'consume', range };
|
|
1753
|
-
}
|
|
1754
|
-
|
|
1755
|
-
/** Runs the single Inbox endpoint query of an endpoint block within the block's build deadline. */
|
|
1756
|
-
private resolveEndpointWithinDeadline(cursor: InboxMessagePosition, upperBound: bigint, buildDeadline: number) {
|
|
1757
|
-
const remainingMs = buildDeadline * 1000 - this.dateProvider.now();
|
|
1758
|
-
const timeoutMs = Math.max(1, Math.min(INBOX_ENDPOINT_READ_TIMEOUT_MS, remainingMs));
|
|
1759
|
-
return executeTimeout(
|
|
1760
|
-
() =>
|
|
1761
|
-
resolveEndpoint({
|
|
1762
|
-
inbox: this.inbox,
|
|
1763
|
-
messageSource: this.l1ToL2MessageSource,
|
|
1764
|
-
cursor,
|
|
1765
|
-
upperBound,
|
|
1766
|
-
}),
|
|
1767
|
-
timeoutMs,
|
|
1768
|
-
`Inbox endpoint lookup at or before message total ${upperBound}`,
|
|
1769
|
-
).catch((err): ReturnType<typeof resolveEndpoint> => {
|
|
1770
|
-
this.log.warn(`Inbox endpoint lookup failed, treating the endpoint as unresolved: ${err}`, {
|
|
1771
|
-
slot: this.targetSlot,
|
|
1772
|
-
checkpointNumber: this.checkpointNumber,
|
|
1773
|
-
upperBound,
|
|
1774
|
-
});
|
|
1775
|
-
return Promise.resolve({ ok: false, reason: 'no_live_endpoint', upperBound });
|
|
1776
|
-
});
|
|
1777
|
-
}
|
|
1778
|
-
|
|
1779
1648
|
/**
|
|
1780
1649
|
* Reports that the streaming Inbox selection cannot complete this checkpoint and the slot is abandoned: the
|
|
1781
1650
|
* checkpoint event, an operator warning and the failure metric. The blocks already signed are content-valid; only
|
|
1782
1651
|
* the checkpoint that would end on them is unpublishable.
|
|
1783
1652
|
*/
|
|
1784
1653
|
private reportStreamingAbort(
|
|
1785
|
-
|
|
1654
|
+
consumption: CheckpointInboxConsumption,
|
|
1786
1655
|
reason: string,
|
|
1787
1656
|
extraContext: Record<string, unknown> = {},
|
|
1788
1657
|
): void {
|
|
1789
1658
|
const context = {
|
|
1790
1659
|
slot: this.targetSlot,
|
|
1791
1660
|
checkpointNumber: this.checkpointNumber,
|
|
1792
|
-
|
|
1793
|
-
consumedTotalMsgCount: state.cursor.totalMessageCount,
|
|
1794
|
-
inboxRollingHash: state.cursor.rollingHash.toString(),
|
|
1661
|
+
...consumption.toLogContext(),
|
|
1795
1662
|
reason,
|
|
1796
1663
|
...extraContext,
|
|
1797
1664
|
};
|
|
1798
|
-
this.
|
|
1799
|
-
|
|
1665
|
+
this.reportCheckpointFailure(
|
|
1666
|
+
'build-failed',
|
|
1800
1667
|
`Streaming Inbox consumption cannot complete this checkpoint; abandoning slot ${this.targetSlot}`,
|
|
1801
1668
|
context,
|
|
1669
|
+
{ level: 'warn' },
|
|
1802
1670
|
);
|
|
1803
1671
|
this.metrics.recordCheckpointProposalFailed(reason);
|
|
1804
1672
|
this.eventEmitter.emit('checkpoint-build-aborted', {
|
|
1805
1673
|
slot: this.targetSlot,
|
|
1806
1674
|
checkpointNumber: this.checkpointNumber,
|
|
1807
1675
|
reason,
|
|
1808
|
-
consumedTotalMsgCount:
|
|
1676
|
+
consumedTotalMsgCount: consumption.consumedTotalMsgCount,
|
|
1809
1677
|
});
|
|
1810
1678
|
}
|
|
1811
1679
|
|
|
@@ -1838,9 +1706,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
1838
1706
|
/** Streaming Inbox message bundle for this block's L1-to-L2 tree; empty when it consumes nothing. */
|
|
1839
1707
|
l1ToL2Messages: Fr[];
|
|
1840
1708
|
},
|
|
1841
|
-
): Promise<
|
|
1842
|
-
{ block: L2Block; usedTxs: Tx[] } | { failure: 'insufficient-txs' | 'insufficient-valid-txs' } | { error: Error }
|
|
1843
|
-
> {
|
|
1709
|
+
): Promise<BlockBuildAttempt> {
|
|
1844
1710
|
const {
|
|
1845
1711
|
blockTimestamp,
|
|
1846
1712
|
forceCreate,
|
|
@@ -1861,15 +1727,8 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
1861
1727
|
// Wait until we have enough txs to build the block
|
|
1862
1728
|
const { canStartBuilding, minTxs } = await this.waitForMinTxs(opts);
|
|
1863
1729
|
if (!canStartBuilding) {
|
|
1864
|
-
this.
|
|
1865
|
-
|
|
1866
|
-
blockNumber,
|
|
1867
|
-
slot: this.targetSlot,
|
|
1868
|
-
checkpointNumber: this.checkpointNumber,
|
|
1869
|
-
indexWithinCheckpoint,
|
|
1870
|
-
minTxs,
|
|
1871
|
-
});
|
|
1872
|
-
this.log.verbose(
|
|
1730
|
+
this.reportCheckpointFailure(
|
|
1731
|
+
'block-build-failed',
|
|
1873
1732
|
`Not enough age-eligible txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.targetSlot} (needs ${minTxs} eligible)`,
|
|
1874
1733
|
{
|
|
1875
1734
|
reason: 'insufficient_txs',
|
|
@@ -1879,10 +1738,11 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
1879
1738
|
indexWithinCheckpoint,
|
|
1880
1739
|
minTxs,
|
|
1881
1740
|
},
|
|
1741
|
+
{ level: 'verbose' },
|
|
1882
1742
|
);
|
|
1883
1743
|
this.eventEmitter.emit('block-tx-count-check-failed', { minTxs, slot: this.targetSlot });
|
|
1884
1744
|
this.metrics.recordBlockProposalFailed('insufficient_txs');
|
|
1885
|
-
return {
|
|
1745
|
+
return { kind: 'skipped', reason: 'insufficient-txs' };
|
|
1886
1746
|
}
|
|
1887
1747
|
|
|
1888
1748
|
// Create iterator to pending txs. We filter out txs already included in previous blocks in the checkpoint
|
|
@@ -1943,16 +1803,8 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
1943
1803
|
await this.dropFailedTxsFromP2P(buildResult.failedTxs);
|
|
1944
1804
|
|
|
1945
1805
|
if (buildResult.status === 'insufficient-valid-txs') {
|
|
1946
|
-
this.
|
|
1947
|
-
|
|
1948
|
-
slot: this.targetSlot,
|
|
1949
|
-
checkpointNumber: this.checkpointNumber,
|
|
1950
|
-
blockNumber,
|
|
1951
|
-
numTxs: buildResult.processedCount,
|
|
1952
|
-
indexWithinCheckpoint,
|
|
1953
|
-
minValidTxs,
|
|
1954
|
-
});
|
|
1955
|
-
this.log.warn(
|
|
1806
|
+
this.reportCheckpointFailure(
|
|
1807
|
+
'block-build-failed',
|
|
1956
1808
|
`Block ${blockNumber} at index ${indexWithinCheckpoint} on slot ${this.targetSlot} has too few valid txs to be proposed`,
|
|
1957
1809
|
{
|
|
1958
1810
|
reason: 'insufficient_valid_txs',
|
|
@@ -1963,13 +1815,14 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
1963
1815
|
indexWithinCheckpoint,
|
|
1964
1816
|
minValidTxs,
|
|
1965
1817
|
},
|
|
1818
|
+
{ level: 'warn' },
|
|
1966
1819
|
);
|
|
1967
1820
|
this.eventEmitter.emit('block-build-failed', {
|
|
1968
1821
|
reason: `Insufficient valid txs`,
|
|
1969
1822
|
slot: this.targetSlot,
|
|
1970
1823
|
});
|
|
1971
1824
|
this.metrics.recordBlockProposalFailed('insufficient_valid_txs');
|
|
1972
|
-
return {
|
|
1825
|
+
return { kind: 'skipped', reason: 'insufficient-valid-txs' };
|
|
1973
1826
|
}
|
|
1974
1827
|
|
|
1975
1828
|
// Block creation succeeded, emit stats and metrics
|
|
@@ -2003,27 +1856,26 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
2003
1856
|
});
|
|
2004
1857
|
this.metrics.recordBuiltBlock(blockBuildDuration, block.header.totalManaUsed.toNumberUnsafe(), this.targetSlot);
|
|
2005
1858
|
|
|
2006
|
-
return { block, usedTxs };
|
|
1859
|
+
return { kind: 'built', block, usedTxs };
|
|
2007
1860
|
} catch (err: any) {
|
|
2008
1861
|
this.eventEmitter.emit('block-build-failed', {
|
|
2009
1862
|
reason: err.message,
|
|
2010
1863
|
slot: this.targetSlot,
|
|
2011
1864
|
});
|
|
2012
|
-
this.
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
});
|
|
1865
|
+
this.reportCheckpointFailure(
|
|
1866
|
+
'block-build-failed',
|
|
1867
|
+
`Error building block`,
|
|
1868
|
+
{
|
|
1869
|
+
reason: err instanceof Error ? err.message : String(err),
|
|
1870
|
+
slot: this.targetSlot,
|
|
1871
|
+
checkpointNumber: this.checkpointNumber,
|
|
1872
|
+
blockNumber,
|
|
1873
|
+
},
|
|
1874
|
+
{ level: 'error', err },
|
|
1875
|
+
);
|
|
2024
1876
|
this.metrics.recordBlockProposalFailed(err.name || 'unknown_error');
|
|
2025
1877
|
this.metrics.recordFailedBlock();
|
|
2026
|
-
return { error: err };
|
|
1878
|
+
return { kind: 'failed', error: err };
|
|
2027
1879
|
}
|
|
2028
1880
|
}
|
|
2029
1881
|
|
|
@@ -2139,22 +1991,17 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
2139
1991
|
private async waitForAttestations(
|
|
2140
1992
|
proposal: CheckpointProposal,
|
|
2141
1993
|
): Promise<CommitteeAttestationsAndSigners | undefined> {
|
|
2142
|
-
if (this.config.fishermanMode) {
|
|
2143
|
-
this.log.debug('Skipping attestation collection in fisherman mode');
|
|
2144
|
-
return CommitteeAttestationsAndSigners.empty(this.getSignatureContext());
|
|
2145
|
-
}
|
|
2146
|
-
|
|
2147
1994
|
const slotNumber = proposal.slotNumber;
|
|
2148
|
-
const
|
|
1995
|
+
const lookup = requireStableCommittee(await this.epochCache.getCommittee(slotNumber));
|
|
2149
1996
|
|
|
2150
|
-
if (
|
|
1997
|
+
if (lookup.state === 'none') {
|
|
2151
1998
|
throw new Error('No committee when collecting attestations');
|
|
2152
|
-
} else if (
|
|
1999
|
+
} else if (lookup.state === 'open') {
|
|
2153
2000
|
this.log.verbose(`Attesting committee is empty`);
|
|
2154
2001
|
return CommitteeAttestationsAndSigners.empty(this.getSignatureContext());
|
|
2155
|
-
} else {
|
|
2156
|
-
this.log.debug(`Attesting committee length is ${committee.length}`, { committee });
|
|
2157
2002
|
}
|
|
2003
|
+
const { committee, seed, epoch } = lookup;
|
|
2004
|
+
this.log.debug(`Attesting committee length is ${committee.length}`, { committee });
|
|
2158
2005
|
|
|
2159
2006
|
const numberOfRequiredAttestations = computeQuorum(committee.length);
|
|
2160
2007
|
|
|
@@ -2210,14 +2057,18 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
2210
2057
|
});
|
|
2211
2058
|
|
|
2212
2059
|
// Manipulate the attestations if we've been configured to do so
|
|
2213
|
-
if (
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2060
|
+
if (hasAttestationManipulation(this.config)) {
|
|
2061
|
+
return manipulateAttestations({
|
|
2062
|
+
config: this.config,
|
|
2063
|
+
epochCache: this.epochCache,
|
|
2064
|
+
signatureContext: this.getSignatureContext(),
|
|
2065
|
+
log: this.log,
|
|
2066
|
+
slotNumber: proposal.slotNumber,
|
|
2067
|
+
epoch,
|
|
2068
|
+
seed,
|
|
2069
|
+
committee,
|
|
2070
|
+
attestations: sorted,
|
|
2071
|
+
});
|
|
2221
2072
|
}
|
|
2222
2073
|
|
|
2223
2074
|
return new CommitteeAttestationsAndSigners(sorted, this.getSignatureContext());
|
|
@@ -2270,91 +2121,6 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
2270
2121
|
});
|
|
2271
2122
|
}
|
|
2272
2123
|
|
|
2273
|
-
/** Breaks the attestations before publishing based on attack configs */
|
|
2274
|
-
private manipulateAttestations(
|
|
2275
|
-
slotNumber: SlotNumber,
|
|
2276
|
-
epoch: EpochNumber,
|
|
2277
|
-
seed: bigint,
|
|
2278
|
-
committee: EthAddress[],
|
|
2279
|
-
attestations: CommitteeAttestation[],
|
|
2280
|
-
) {
|
|
2281
|
-
// Compute the proposer index in the committee, since we dont want to tweak it.
|
|
2282
|
-
// Otherwise, the L1 rollup contract will reject the block outright.
|
|
2283
|
-
const proposerIndex = Number(
|
|
2284
|
-
this.epochCache.computeProposerIndex(slotNumber, epoch, seed, BigInt(committee.length)),
|
|
2285
|
-
);
|
|
2286
|
-
|
|
2287
|
-
if (
|
|
2288
|
-
this.config.injectFakeAttestation ||
|
|
2289
|
-
this.config.injectHighSValueAttestation ||
|
|
2290
|
-
this.config.injectUnrecoverableSignatureAttestation
|
|
2291
|
-
) {
|
|
2292
|
-
// Find non-empty attestations that are not from the proposer
|
|
2293
|
-
const nonProposerIndices: number[] = [];
|
|
2294
|
-
for (let i = 0; i < attestations.length; i++) {
|
|
2295
|
-
if (!attestations[i].signature.isEmpty() && i !== proposerIndex) {
|
|
2296
|
-
nonProposerIndices.push(i);
|
|
2297
|
-
}
|
|
2298
|
-
}
|
|
2299
|
-
if (nonProposerIndices.length > 0) {
|
|
2300
|
-
const targetIndex = nonProposerIndices[randomInt(nonProposerIndices.length)];
|
|
2301
|
-
if (this.config.injectHighSValueAttestation) {
|
|
2302
|
-
this.log.warn(
|
|
2303
|
-
`Injecting high-s value attestation in checkpoint for slot ${slotNumber} at index ${targetIndex}`,
|
|
2304
|
-
);
|
|
2305
|
-
unfreeze(attestations[targetIndex]).signature = flipSignature(attestations[targetIndex].signature);
|
|
2306
|
-
} else if (this.config.injectUnrecoverableSignatureAttestation) {
|
|
2307
|
-
this.log.warn(
|
|
2308
|
-
`Injecting unrecoverable signature attestation in checkpoint for slot ${slotNumber} at index ${targetIndex}`,
|
|
2309
|
-
);
|
|
2310
|
-
unfreeze(attestations[targetIndex]).signature = generateUnrecoverableSignature();
|
|
2311
|
-
} else {
|
|
2312
|
-
this.log.warn(`Injecting fake attestation in checkpoint for slot ${slotNumber} at index ${targetIndex}`);
|
|
2313
|
-
unfreeze(attestations[targetIndex]).signature = generateRecoverableSignature();
|
|
2314
|
-
}
|
|
2315
|
-
}
|
|
2316
|
-
return new CommitteeAttestationsAndSigners(attestations, this.getSignatureContext());
|
|
2317
|
-
}
|
|
2318
|
-
|
|
2319
|
-
if (this.config.injectYParityAttestation) {
|
|
2320
|
-
// Force every non-proposer signed slot's recovery byte to yParity (v ∈ {0, 1}) form in the packed L1
|
|
2321
|
-
// tuple, after packAttestations has canonicalized it. The proposer's own slot is left canonical so
|
|
2322
|
-
// propose() still passes verifyProposer. Models a malicious proposer landing a checkpoint L1 accepts
|
|
2323
|
-
// but that can never be proven (ECDSA.recover rejects v ∉ {27, 28}).
|
|
2324
|
-
this.log.warn(`Injecting yParity attestations in checkpoint for slot ${slotNumber} (proposer #${proposerIndex})`);
|
|
2325
|
-
return new MaliciousYParityCommitteeAttestationsAndSigners(
|
|
2326
|
-
attestations,
|
|
2327
|
-
proposerIndex,
|
|
2328
|
-
this.getSignatureContext(),
|
|
2329
|
-
);
|
|
2330
|
-
}
|
|
2331
|
-
|
|
2332
|
-
if (this.config.shuffleAttestationOrdering) {
|
|
2333
|
-
this.log.warn(`Shuffling attestation ordering in checkpoint for slot ${slotNumber} (proposer #${proposerIndex})`);
|
|
2334
|
-
|
|
2335
|
-
const shuffled = [...attestations];
|
|
2336
|
-
|
|
2337
|
-
// Find two non-proposer positions that both have non-empty signatures to swap.
|
|
2338
|
-
// This ensures the bitmap doesn't change, so the MaliciousCommitteeAttestationsAndSigners
|
|
2339
|
-
// signers array stays correctly aligned with L1's committee reconstruction.
|
|
2340
|
-
const swappable: number[] = [];
|
|
2341
|
-
for (let k = 0; k < shuffled.length; k++) {
|
|
2342
|
-
if (!shuffled[k].signature.isEmpty() && k !== proposerIndex) {
|
|
2343
|
-
swappable.push(k);
|
|
2344
|
-
}
|
|
2345
|
-
}
|
|
2346
|
-
if (swappable.length >= 2) {
|
|
2347
|
-
const [i, j] = [swappable[0], swappable[1]];
|
|
2348
|
-
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
|
|
2349
|
-
}
|
|
2350
|
-
|
|
2351
|
-
const signers = new CommitteeAttestationsAndSigners(attestations, this.getSignatureContext()).getSigners();
|
|
2352
|
-
return new MaliciousCommitteeAttestationsAndSigners(shuffled, signers, this.getSignatureContext());
|
|
2353
|
-
}
|
|
2354
|
-
|
|
2355
|
-
return new CommitteeAttestationsAndSigners(attestations, this.getSignatureContext());
|
|
2356
|
-
}
|
|
2357
|
-
|
|
2358
2124
|
private async dropFailedTxsFromP2P(failedTxs: FailedTx[]) {
|
|
2359
2125
|
if (failedTxs.length === 0) {
|
|
2360
2126
|
return;
|
|
@@ -2393,6 +2159,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
2393
2159
|
slot: block.header.globalVariables.slotNumber,
|
|
2394
2160
|
});
|
|
2395
2161
|
await this.blockSink.addBlock(block, inboxPrefixRef);
|
|
2162
|
+
this.unclaimedFirstBlockHash ??= await block.hash();
|
|
2396
2163
|
}
|
|
2397
2164
|
|
|
2398
2165
|
/**
|
|
@@ -2407,6 +2174,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
2407
2174
|
*/
|
|
2408
2175
|
private async syncProposedCheckpointToArchiver(
|
|
2409
2176
|
checkpoint: Checkpoint,
|
|
2177
|
+
proposal: CheckpointProposal,
|
|
2410
2178
|
blockCount: number,
|
|
2411
2179
|
feeAssetPriceModifier: bigint,
|
|
2412
2180
|
): Promise<void> {
|
|
@@ -2427,30 +2195,61 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
2427
2195
|
blockCount,
|
|
2428
2196
|
totalManaUsed: checkpoint.header.totalManaUsed.toBigInt(),
|
|
2429
2197
|
feeAssetPriceModifier,
|
|
2198
|
+
signer: proposal.getSender(),
|
|
2430
2199
|
});
|
|
2200
|
+
this.unclaimedFirstBlockHash = undefined;
|
|
2201
|
+
}
|
|
2202
|
+
|
|
2203
|
+
/**
|
|
2204
|
+
* Prunes this checkpoint's blocks from the local archiver once the job has given the checkpoint up after pushing
|
|
2205
|
+
* them. Until then the node serves them as its chain tip: world state applies them, the tx pool marks their txs
|
|
2206
|
+
* mined, and RPC users build txs on them, all of which the orphan prune would only undo seconds later. Pruning
|
|
2207
|
+
* every block after the parent rather than just the last one, since without the checkpoint none of them can land.
|
|
2208
|
+
*
|
|
2209
|
+
* Left to the orphan prune when the job was interrupted, since the sequencer is then stopping and the archiver sync
|
|
2210
|
+
* loop that runs the prune may be stopping with it, and when an HA peer holds one of the slot's duties, since the
|
|
2211
|
+
* peer may be proposing these very blocks and the orphan prune waits for its checkpoint proposal. Never throws: a
|
|
2212
|
+
* failed prune only leaves the blocks to the orphan prune.
|
|
2213
|
+
*/
|
|
2214
|
+
private async pruneAbandonedCheckpointBlocks(): Promise<void> {
|
|
2215
|
+
const firstBlockHash = this.unclaimedFirstBlockHash;
|
|
2216
|
+
if (firstBlockHash === undefined || this.interrupted || this.yieldedToHAPeer) {
|
|
2217
|
+
return;
|
|
2218
|
+
}
|
|
2219
|
+
this.unclaimedFirstBlockHash = undefined;
|
|
2220
|
+
const context = {
|
|
2221
|
+
slot: this.targetSlot,
|
|
2222
|
+
checkpointNumber: this.checkpointNumber,
|
|
2223
|
+
parentBlockNumber: this.syncedToBlockNumber,
|
|
2224
|
+
firstBlockHash: firstBlockHash.toString(),
|
|
2225
|
+
};
|
|
2226
|
+
try {
|
|
2227
|
+
const prunedBlocks = await this.blockSink.pruneAbandonedProposedBlocks(this.syncedToBlockNumber, firstBlockHash);
|
|
2228
|
+
this.log.info(`Pruned the blocks of abandoned checkpoint ${this.checkpointNumber} from the local archiver`, {
|
|
2229
|
+
...context,
|
|
2230
|
+
prunedBlocks,
|
|
2231
|
+
});
|
|
2232
|
+
} catch (err) {
|
|
2233
|
+
this.log.warn(
|
|
2234
|
+
`Failed to prune the blocks of abandoned checkpoint ${this.checkpointNumber}; leaving them to the orphan prune`,
|
|
2235
|
+
{ ...context, error: err instanceof Error ? err.message : String(err) },
|
|
2236
|
+
);
|
|
2237
|
+
}
|
|
2431
2238
|
}
|
|
2432
2239
|
|
|
2433
2240
|
/** Runs fee analysis and logs checkpoint outcome as fisherman */
|
|
2434
|
-
private async handleCheckpointEndAsFisherman(checkpoint: Checkpoint
|
|
2241
|
+
private async handleCheckpointEndAsFisherman(checkpoint: Checkpoint) {
|
|
2435
2242
|
// Perform L1 fee analysis before clearing requests
|
|
2436
2243
|
// The callback is invoked asynchronously after the next block is mined
|
|
2437
2244
|
const feeAnalysis = await this.publisher.analyzeL1Fees(this.targetSlot, analysis =>
|
|
2438
2245
|
this.metrics.recordFishermanFeeAnalysis(analysis),
|
|
2439
2246
|
);
|
|
2440
2247
|
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
});
|
|
2447
|
-
} else {
|
|
2448
|
-
this.log.warn(`Validation block building FAILED for slot ${this.targetSlot}`, {
|
|
2449
|
-
slot: this.targetSlot,
|
|
2450
|
-
feeAnalysisId: feeAnalysis?.id,
|
|
2451
|
-
});
|
|
2452
|
-
this.metrics.recordCheckpointProposalFailed('block_build_failed');
|
|
2453
|
-
}
|
|
2248
|
+
this.log.info(`Validation checkpoint building SUCCEEDED for slot ${this.targetSlot}`, {
|
|
2249
|
+
...checkpoint.toCheckpointInfo(),
|
|
2250
|
+
...checkpoint.getStats(),
|
|
2251
|
+
feeAnalysisId: feeAnalysis?.id,
|
|
2252
|
+
});
|
|
2454
2253
|
|
|
2455
2254
|
this.publisher.clearPendingRequests();
|
|
2456
2255
|
}
|
|
@@ -2459,6 +2258,9 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
2459
2258
|
* Helper to handle HA double-signing errors. Returns true if the error was handled (caller should yield).
|
|
2460
2259
|
*/
|
|
2461
2260
|
private handleHASigningError(err: any, errorContext: string): boolean {
|
|
2261
|
+
if (err instanceof DutyAlreadySignedError || err instanceof SlashingProtectionError) {
|
|
2262
|
+
this.yieldedToHAPeer = true;
|
|
2263
|
+
}
|
|
2462
2264
|
if (err instanceof DutyAlreadySignedError) {
|
|
2463
2265
|
this.log.info(`${errorContext} for slot ${this.targetSlot} already signed by another HA node, yielding`, {
|
|
2464
2266
|
slot: this.targetSlot,
|