@aztec/sequencer-client 0.0.1-commit.1bb068fb5 → 0.0.1-commit.1dcfe2301
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/client/sequencer-client.d.ts +17 -7
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +63 -30
- package/dest/config.d.ts +26 -6
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +49 -29
- package/dest/global_variable_builder/fee_predictor.d.ts +37 -0
- package/dest/global_variable_builder/fee_predictor.d.ts.map +1 -0
- package/dest/global_variable_builder/fee_predictor.js +128 -0
- package/dest/global_variable_builder/fee_provider.d.ts +21 -0
- package/dest/global_variable_builder/fee_provider.d.ts.map +1 -0
- package/dest/global_variable_builder/fee_provider.js +58 -0
- package/dest/global_variable_builder/global_builder.d.ts +15 -16
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +16 -50
- package/dest/global_variable_builder/index.d.ts +4 -2
- package/dest/global_variable_builder/index.d.ts.map +1 -1
- package/dest/global_variable_builder/index.js +2 -0
- package/dest/publisher/config.d.ts +47 -17
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +121 -42
- package/dest/publisher/index.d.ts +2 -1
- package/dest/publisher/index.d.ts.map +1 -1
- package/dest/publisher/l1_tx_failed_store/factory.d.ts +11 -0
- package/dest/publisher/l1_tx_failed_store/factory.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/factory.js +22 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +58 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.js +1 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts +15 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.js +34 -0
- package/dest/publisher/l1_tx_failed_store/index.d.ts +4 -0
- package/dest/publisher/l1_tx_failed_store/index.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/index.js +2 -0
- package/dest/publisher/sequencer-publisher-factory.d.ts +11 -5
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-factory.js +27 -3
- package/dest/publisher/sequencer-publisher.d.ts +68 -48
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +419 -135
- package/dest/sequencer/chain_state_overrides.d.ts +25 -0
- package/dest/sequencer/chain_state_overrides.d.ts.map +1 -0
- package/dest/sequencer/chain_state_overrides.js +39 -0
- package/dest/sequencer/checkpoint_proposal_job.d.ts +26 -9
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_proposal_job.js +372 -210
- package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts +34 -0
- package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_proposal_job_metrics.js +72 -0
- package/dest/sequencer/checkpoint_voter.d.ts +1 -2
- package/dest/sequencer/checkpoint_voter.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_voter.js +2 -5
- package/dest/sequencer/events.d.ts +2 -1
- package/dest/sequencer/events.d.ts.map +1 -1
- package/dest/sequencer/metrics.d.ts +16 -8
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +70 -21
- package/dest/sequencer/sequencer.d.ts +43 -17
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +158 -97
- package/dest/sequencer/timetable.d.ts +17 -3
- package/dest/sequencer/timetable.d.ts.map +1 -1
- package/dest/sequencer/timetable.js +51 -43
- package/dest/sequencer/types.d.ts +2 -2
- package/dest/sequencer/types.d.ts.map +1 -1
- package/dest/test/index.d.ts +3 -5
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.d.ts +7 -9
- package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.js +39 -30
- package/package.json +27 -28
- package/src/client/sequencer-client.ts +81 -30
- package/src/config.ts +61 -35
- package/src/global_variable_builder/README.md +44 -0
- package/src/global_variable_builder/fee_predictor.ts +172 -0
- package/src/global_variable_builder/fee_provider.ts +75 -0
- package/src/global_variable_builder/global_builder.ts +27 -63
- package/src/global_variable_builder/index.ts +3 -1
- package/src/publisher/config.ts +157 -45
- package/src/publisher/index.ts +3 -0
- package/src/publisher/l1_tx_failed_store/factory.ts +32 -0
- package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +57 -0
- package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +46 -0
- package/src/publisher/l1_tx_failed_store/index.ts +3 -0
- package/src/publisher/sequencer-publisher-factory.ts +38 -9
- package/src/publisher/sequencer-publisher.ts +472 -193
- package/src/sequencer/README.md +83 -13
- package/src/sequencer/chain_state_overrides.ts +87 -0
- package/src/sequencer/checkpoint_proposal_job.ts +486 -231
- package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
- package/src/sequencer/checkpoint_voter.ts +1 -12
- package/src/sequencer/events.ts +1 -1
- package/src/sequencer/metrics.ts +80 -26
- package/src/sequencer/sequencer.ts +227 -109
- package/src/sequencer/timetable.ts +64 -52
- package/src/sequencer/types.ts +1 -1
- package/src/test/index.ts +2 -4
- package/src/test/mock_checkpoint_builder.ts +51 -48
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { NUM_CHECKPOINT_END_MARKER_FIELDS, getNumBlockEndBlobFields } from '@aztec/blob-lib/encoding';
|
|
2
|
-
import { BLOBS_PER_CHECKPOINT, FIELDS_PER_BLOB } from '@aztec/constants';
|
|
3
1
|
import type { EpochCache } from '@aztec/epoch-cache';
|
|
2
|
+
import type { SimulationOverridesPlan } from '@aztec/ethereum/contracts';
|
|
4
3
|
import {
|
|
5
4
|
BlockNumber,
|
|
6
5
|
CheckpointNumber,
|
|
@@ -9,6 +8,11 @@ import {
|
|
|
9
8
|
SlotNumber,
|
|
10
9
|
} from '@aztec/foundation/branded-types';
|
|
11
10
|
import { randomInt } from '@aztec/foundation/crypto/random';
|
|
11
|
+
import {
|
|
12
|
+
flipSignature,
|
|
13
|
+
generateRecoverableSignature,
|
|
14
|
+
generateUnrecoverableSignature,
|
|
15
|
+
} from '@aztec/foundation/crypto/secp256k1-signer';
|
|
12
16
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
13
17
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
14
18
|
import { Signature } from '@aztec/foundation/eth-signature';
|
|
@@ -27,18 +31,23 @@ import {
|
|
|
27
31
|
type L2BlockSource,
|
|
28
32
|
MaliciousCommitteeAttestationsAndSigners,
|
|
29
33
|
} from '@aztec/stdlib/block';
|
|
30
|
-
import type
|
|
31
|
-
import { getSlotStartBuildTimestamp } from '@aztec/stdlib/epoch-helpers';
|
|
34
|
+
import { type Checkpoint, type ProposedCheckpointData, validateCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
35
|
+
import { computeQuorum, getSlotStartBuildTimestamp, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
32
36
|
import { Gas } from '@aztec/stdlib/gas';
|
|
33
37
|
import {
|
|
34
|
-
|
|
35
|
-
|
|
38
|
+
type BlockBuilderOptions,
|
|
39
|
+
InsufficientValidTxsError,
|
|
36
40
|
type ResolvedSequencerConfig,
|
|
37
41
|
type WorldStateSynchronizer,
|
|
38
42
|
} from '@aztec/stdlib/interfaces/server';
|
|
39
43
|
import { type L1ToL2MessageSource, computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
|
|
40
|
-
import type {
|
|
41
|
-
|
|
44
|
+
import type {
|
|
45
|
+
BlockProposal,
|
|
46
|
+
BlockProposalOptions,
|
|
47
|
+
CheckpointProposal,
|
|
48
|
+
CheckpointProposalOptions,
|
|
49
|
+
} from '@aztec/stdlib/p2p';
|
|
50
|
+
import { orderAttestations, trimAttestations } from '@aztec/stdlib/p2p';
|
|
42
51
|
import type { L2BlockBuiltStats } from '@aztec/stdlib/stats';
|
|
43
52
|
import { type FailedTx, Tx } from '@aztec/stdlib/tx';
|
|
44
53
|
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
@@ -48,6 +57,11 @@ import { DutyAlreadySignedError, SlashingProtectionError } from '@aztec/validato
|
|
|
48
57
|
|
|
49
58
|
import type { GlobalVariableBuilder } from '../global_variable_builder/global_builder.js';
|
|
50
59
|
import type { InvalidateCheckpointRequest, SequencerPublisher } from '../publisher/sequencer-publisher.js';
|
|
60
|
+
import {
|
|
61
|
+
buildPipelinedParentSimulationOverridesPlan,
|
|
62
|
+
buildSubmissionSimulationOverridesPlan,
|
|
63
|
+
} from './chain_state_overrides.js';
|
|
64
|
+
import type { CheckpointProposalJobMetricsRecorder } from './checkpoint_proposal_job_metrics.js';
|
|
51
65
|
import { CheckpointVoter } from './checkpoint_voter.js';
|
|
52
66
|
import { SequencerInterruptedError } from './errors.js';
|
|
53
67
|
import type { SequencerEvents } from './events.js';
|
|
@@ -59,6 +73,20 @@ import { SequencerState } from './utils.js';
|
|
|
59
73
|
/** How much time to sleep while waiting for min transactions to accumulate for a block */
|
|
60
74
|
const TXS_POLLING_MS = 500;
|
|
61
75
|
|
|
76
|
+
/** Result from proposeCheckpoint when a checkpoint was successfully built and broadcast. */
|
|
77
|
+
type CheckpointProposalBroadcast = {
|
|
78
|
+
checkpoint: Checkpoint;
|
|
79
|
+
proposal: CheckpointProposal;
|
|
80
|
+
blockProposedAt: number;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/** Result after attestation collection and signing, ready for L1 submission. */
|
|
84
|
+
type CheckpointProposalResult = {
|
|
85
|
+
checkpoint: Checkpoint;
|
|
86
|
+
attestations: CommitteeAttestationsAndSigners;
|
|
87
|
+
attestationsSignature: Signature;
|
|
88
|
+
};
|
|
89
|
+
|
|
62
90
|
/**
|
|
63
91
|
* Handles the execution of a checkpoint proposal after the initial preparation phase.
|
|
64
92
|
* This includes building blocks, collecting attestations, and publishing the checkpoint to L1,
|
|
@@ -68,9 +96,16 @@ const TXS_POLLING_MS = 500;
|
|
|
68
96
|
export class CheckpointProposalJob implements Traceable {
|
|
69
97
|
protected readonly log: Logger;
|
|
70
98
|
|
|
99
|
+
/** Tracks the fire-and-forget L1 submission promise so it can be awaited during shutdown. */
|
|
100
|
+
private pendingL1Submission: Promise<void> | undefined;
|
|
101
|
+
|
|
102
|
+
/** Pipelined parent chain state used while building and later submitting this checkpoint. */
|
|
103
|
+
private pipelinedParentSimulationOverridesPlan?: SimulationOverridesPlan;
|
|
104
|
+
|
|
71
105
|
constructor(
|
|
72
|
-
private readonly
|
|
73
|
-
private readonly
|
|
106
|
+
private readonly slotNow: SlotNumber,
|
|
107
|
+
private readonly targetSlot: SlotNumber,
|
|
108
|
+
private readonly targetEpoch: EpochNumber,
|
|
74
109
|
private readonly checkpointNumber: CheckpointNumber,
|
|
75
110
|
private readonly syncedToBlockNumber: BlockNumber,
|
|
76
111
|
// TODO(palla/mbps): Can we remove the proposer in favor of attestorAddress? Need to check fisherman-node flows.
|
|
@@ -93,17 +128,31 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
93
128
|
private readonly epochCache: EpochCache,
|
|
94
129
|
private readonly dateProvider: DateProvider,
|
|
95
130
|
private readonly metrics: SequencerMetrics,
|
|
131
|
+
private readonly checkpointMetrics: CheckpointProposalJobMetricsRecorder,
|
|
96
132
|
private readonly eventEmitter: TypedEventEmitter<SequencerEvents>,
|
|
97
133
|
private readonly setStateFn: (state: SequencerState, slot?: SlotNumber) => void,
|
|
98
134
|
public readonly tracer: Tracer,
|
|
99
135
|
bindings?: LoggerBindings,
|
|
136
|
+
private readonly proposedCheckpointData?: ProposedCheckpointData,
|
|
100
137
|
) {
|
|
101
|
-
this.log = createLogger('sequencer:checkpoint-proposal', {
|
|
138
|
+
this.log = createLogger('sequencer:checkpoint-proposal', {
|
|
139
|
+
...bindings,
|
|
140
|
+
instanceId: `slot-${this.slotNow}`,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Awaits the pending L1 submission if one is in progress. Call during shutdown. */
|
|
145
|
+
public async awaitPendingSubmission(): Promise<void> {
|
|
146
|
+
this.log.info('Awaiting pending L1 payload submission');
|
|
147
|
+
await this.pendingL1Submission;
|
|
102
148
|
}
|
|
103
149
|
|
|
104
150
|
/**
|
|
105
151
|
* Executes the checkpoint proposal job.
|
|
106
|
-
*
|
|
152
|
+
* Builds blocks, assembles checkpoint, and broadcasts the proposal (blocking).
|
|
153
|
+
* Attestation collection, signing, and L1 submission are backgrounded so the
|
|
154
|
+
* work loop can return to IDLE immediately for consecutive slot proposals.
|
|
155
|
+
* Returns the built checkpoint if successful, undefined otherwise.
|
|
107
156
|
*/
|
|
108
157
|
@trackSpan('CheckpointProposalJob.execute')
|
|
109
158
|
public async execute(): Promise<Checkpoint | undefined> {
|
|
@@ -111,7 +160,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
111
160
|
// In fisherman mode, we simulate slashing but don't actually publish to L1
|
|
112
161
|
// These are constant for the whole slot, so we only enqueue them once
|
|
113
162
|
const votesPromises = new CheckpointVoter(
|
|
114
|
-
this.
|
|
163
|
+
this.targetSlot,
|
|
115
164
|
this.publisher,
|
|
116
165
|
this.attestorAddress,
|
|
117
166
|
this.validatorClient,
|
|
@@ -122,63 +171,195 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
122
171
|
this.log,
|
|
123
172
|
).enqueueVotes();
|
|
124
173
|
|
|
125
|
-
// Build
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
// Wait until the voting promises have resolved, so all requests are enqueued (not sent)
|
|
129
|
-
await Promise.all(votesPromises);
|
|
174
|
+
// Build blocks, assemble checkpoint, and broadcast proposal (BLOCKING).
|
|
175
|
+
// Returns after broadcast — attestation collection is deferred.
|
|
176
|
+
const broadcast = await this.proposeCheckpoint();
|
|
130
177
|
|
|
131
|
-
if (
|
|
132
|
-
|
|
178
|
+
if (!broadcast) {
|
|
179
|
+
await Promise.all(votesPromises);
|
|
180
|
+
// Still submit votes even without a checkpoint
|
|
181
|
+
if (!this.config.fishermanMode) {
|
|
182
|
+
this.pendingL1Submission = this.publisher.sendRequestsAt(this.dateProvider.nowAsDate()).then(() => {});
|
|
183
|
+
}
|
|
184
|
+
return undefined;
|
|
133
185
|
}
|
|
134
186
|
|
|
187
|
+
const { checkpoint } = broadcast;
|
|
188
|
+
this.metrics.recordCheckpointProposalSuccess();
|
|
189
|
+
|
|
135
190
|
// Do not post anything to L1 if we are fishermen, but do perform L1 fee analysis
|
|
136
191
|
if (this.config.fishermanMode) {
|
|
137
192
|
await this.handleCheckpointEndAsFisherman(checkpoint);
|
|
138
|
-
return;
|
|
193
|
+
return checkpoint;
|
|
139
194
|
}
|
|
140
195
|
|
|
141
|
-
//
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
196
|
+
// Background the attestation → signing → L1 pipeline so the work loop is unblocked
|
|
197
|
+
this.pendingL1Submission = this.waitForAttestationsAndEnqueueSubmissionAsync(broadcast, votesPromises);
|
|
198
|
+
|
|
199
|
+
// Return the built checkpoint immediately — the work loop is now unblocked
|
|
200
|
+
return checkpoint;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Background pipeline: collects attestations, signs them, enqueues the checkpoint, and submits to L1.
|
|
205
|
+
* Runs as a fire-and-forget task stored in `pendingL1Submission` so the work loop is unblocked.
|
|
206
|
+
*/
|
|
207
|
+
private async waitForAttestationsAndEnqueueSubmissionAsync(
|
|
208
|
+
broadcast: CheckpointProposalBroadcast,
|
|
209
|
+
votesPromises: Promise<unknown>[],
|
|
210
|
+
): Promise<void> {
|
|
211
|
+
const { checkpoint, proposal, blockProposedAt } = broadcast;
|
|
212
|
+
try {
|
|
213
|
+
await Promise.all(votesPromises);
|
|
214
|
+
|
|
215
|
+
this.setStateFn(SequencerState.COLLECTING_ATTESTATIONS, this.targetSlot);
|
|
216
|
+
const attestations = await this.waitForAttestations(proposal);
|
|
217
|
+
|
|
218
|
+
this.checkpointMetrics.recordCheckpointAttestationDelay(this.dateProvider.now() - blockProposedAt);
|
|
219
|
+
|
|
220
|
+
// Proposer must sign over the attestations before pushing them to L1
|
|
221
|
+
const signer = this.proposer ?? this.publisher.getSenderAddress();
|
|
222
|
+
let attestationsSignature: Signature;
|
|
223
|
+
try {
|
|
224
|
+
attestationsSignature = await this.validatorClient.signAttestationsAndSigners(
|
|
225
|
+
attestations,
|
|
226
|
+
signer,
|
|
227
|
+
this.targetSlot,
|
|
228
|
+
this.checkpointNumber,
|
|
229
|
+
);
|
|
230
|
+
} catch (err) {
|
|
231
|
+
if (this.handleHASigningError(err, 'Attestations signature')) {
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
throw err;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// Enqueue the checkpoint for L1 submission
|
|
238
|
+
await this.enqueueCheckpointForSubmission({ checkpoint, attestations, attestationsSignature });
|
|
239
|
+
|
|
240
|
+
// Compute the earliest time to submit: pipeline slot start when pipelining, now otherwise.
|
|
241
|
+
const submitAfter = this.epochCache.isProposerPipeliningEnabled()
|
|
242
|
+
? new Date(Number(getTimestampForSlot(this.targetSlot, this.l1Constants)) * 1000)
|
|
243
|
+
: new Date(this.dateProvider.now());
|
|
244
|
+
|
|
245
|
+
const l1Response = await this.publisher.sendRequestsAt(submitAfter);
|
|
246
|
+
const proposedAction = l1Response?.successfulActions.find(a => a === 'propose');
|
|
247
|
+
if (proposedAction) {
|
|
248
|
+
this.eventEmitter.emit('checkpoint-published', { checkpoint: this.checkpointNumber, slot: this.targetSlot });
|
|
249
|
+
const coinbase = checkpoint.header.coinbase;
|
|
250
|
+
await this.metrics.incFilledSlot(this.publisher.getSenderAddress().toString(), coinbase);
|
|
251
|
+
} else {
|
|
252
|
+
this.eventEmitter.emit('checkpoint-publish-failed', { ...l1Response, slot: this.targetSlot });
|
|
253
|
+
if (this.epochCache.isProposerPipeliningEnabled()) {
|
|
254
|
+
this.metrics.recordPipelineDiscard();
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
} catch (err) {
|
|
258
|
+
if (err instanceof SequencerInterruptedError) {
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
this.log.error(`Background attestation/L1 pipeline failed for slot ${this.targetSlot}`, err);
|
|
262
|
+
this.eventEmitter.emit('checkpoint-publish-failed', { slot: this.targetSlot });
|
|
263
|
+
if (this.epochCache.isProposerPipeliningEnabled()) {
|
|
264
|
+
this.metrics.recordPipelineDiscard();
|
|
265
|
+
}
|
|
152
266
|
}
|
|
153
267
|
}
|
|
154
268
|
|
|
269
|
+
/** Enqueues the checkpoint for L1 submission. Called after pipeline sleep in execute(). */
|
|
270
|
+
private async enqueueCheckpointForSubmission(result: CheckpointProposalResult): Promise<void> {
|
|
271
|
+
const { checkpoint, attestations, attestationsSignature } = result;
|
|
272
|
+
|
|
273
|
+
this.setStateFn(SequencerState.PUBLISHING_CHECKPOINT, this.targetSlot);
|
|
274
|
+
const aztecSlotDuration = this.l1Constants.slotDuration;
|
|
275
|
+
const submissionSlotStart = Number(getTimestampForSlot(this.targetSlot, this.l1Constants));
|
|
276
|
+
const txTimeoutAt = new Date((submissionSlotStart + aztecSlotDuration) * 1000);
|
|
277
|
+
|
|
278
|
+
// If we have been configured to potentially skip publishing checkpoint then roll the dice here
|
|
279
|
+
if (
|
|
280
|
+
this.config.skipPublishingCheckpointsPercent !== undefined &&
|
|
281
|
+
this.config.skipPublishingCheckpointsPercent > 0
|
|
282
|
+
) {
|
|
283
|
+
const roll = Math.max(0, randomInt(100));
|
|
284
|
+
if (roll < this.config.skipPublishingCheckpointsPercent) {
|
|
285
|
+
this.log.warn(
|
|
286
|
+
`Skipping publishing proposal for checkpoint ${checkpoint.number}. Configured percentage: ${this.config.skipPublishingCheckpointsPercent}, generated value: ${roll}`,
|
|
287
|
+
);
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
const isPipelining = this.epochCache.isProposerPipeliningEnabled();
|
|
293
|
+
const submissionSimulationOverridesPlan = buildSubmissionSimulationOverridesPlan({
|
|
294
|
+
pipelinedParentPlan: this.pipelinedParentSimulationOverridesPlan,
|
|
295
|
+
invalidateToPendingCheckpointNumber: this.invalidateCheckpoint?.forcePendingCheckpointNumber,
|
|
296
|
+
lastArchiveRoot: checkpoint.header.lastArchiveRoot,
|
|
297
|
+
pipeliningEnabled: isPipelining,
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
await this.publisher.enqueueProposeCheckpoint(checkpoint, attestations, attestationsSignature, {
|
|
301
|
+
txTimeoutAt,
|
|
302
|
+
...(submissionSimulationOverridesPlan ? { simulationOverridesPlan: submissionSimulationOverridesPlan } : {}),
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
|
|
155
306
|
@trackSpan('CheckpointProposalJob.proposeCheckpoint', function () {
|
|
156
307
|
return {
|
|
157
308
|
// nullish operator needed for tests
|
|
158
309
|
[Attributes.COINBASE]: this.validatorClient.getCoinbaseForAttestor(this.attestorAddress)?.toString(),
|
|
159
|
-
[Attributes.SLOT_NUMBER]: this.
|
|
310
|
+
[Attributes.SLOT_NUMBER]: this.targetSlot,
|
|
160
311
|
};
|
|
161
312
|
})
|
|
162
|
-
private async proposeCheckpoint(): Promise<
|
|
313
|
+
private async proposeCheckpoint(): Promise<CheckpointProposalBroadcast | undefined> {
|
|
163
314
|
try {
|
|
315
|
+
const now = this.dateProvider.now();
|
|
316
|
+
if (this.epochCache.isProposerPipeliningEnabled() && this.proposedCheckpointData) {
|
|
317
|
+
// Measure against the wall-clock slot whose build window we are currently using.
|
|
318
|
+
// In pipelining mode `targetSlot` is intentionally one slot ahead, which makes the
|
|
319
|
+
// target-slot boundary a full slot away from the actual build start time.
|
|
320
|
+
const slotBoundaryMs = Number(getTimestampForSlot(this.slotNow, this.l1Constants)) * 1000;
|
|
321
|
+
this.checkpointMetrics.recordPipelinedCheckpointBuildStartOffsetFromSlotBoundary(now - slotBoundaryMs);
|
|
322
|
+
}
|
|
323
|
+
this.checkpointMetrics.startCheckpointTiming(now);
|
|
324
|
+
|
|
164
325
|
// Get operator configured coinbase and fee recipient for this attestor
|
|
165
326
|
const coinbase = this.validatorClient.getCoinbaseForAttestor(this.attestorAddress);
|
|
166
327
|
const feeRecipient = this.validatorClient.getFeeRecipientForAttestor(this.attestorAddress);
|
|
167
328
|
|
|
168
329
|
// Start the checkpoint
|
|
169
|
-
this.setStateFn(SequencerState.INITIALIZING_CHECKPOINT, this.
|
|
170
|
-
this.
|
|
330
|
+
this.setStateFn(SequencerState.INITIALIZING_CHECKPOINT, this.targetSlot);
|
|
331
|
+
this.log.info(`Starting checkpoint proposal`, {
|
|
332
|
+
buildSlot: this.slotNow,
|
|
333
|
+
submissionSlot: this.targetSlot,
|
|
334
|
+
pipelining: this.epochCache.isProposerPipeliningEnabled(),
|
|
335
|
+
proposer: this.proposer?.toString(),
|
|
336
|
+
coinbase: coinbase.toString(),
|
|
337
|
+
});
|
|
338
|
+
this.metrics.incOpenSlot(this.targetSlot, this.proposer?.toString() ?? 'unknown');
|
|
171
339
|
|
|
172
340
|
// Enqueues checkpoint invalidation (constant for the whole slot)
|
|
173
341
|
if (this.invalidateCheckpoint && !this.config.skipInvalidateBlockAsProposer) {
|
|
174
342
|
this.publisher.enqueueInvalidateCheckpoint(this.invalidateCheckpoint);
|
|
175
343
|
}
|
|
176
344
|
|
|
177
|
-
// Create checkpoint builder for the slot
|
|
345
|
+
// Create checkpoint builder for the slot.
|
|
346
|
+
// When pipelining, force the proposed checkpoint number and fee header to our parent so the
|
|
347
|
+
// fee computation sees the same chain tip that L1 will see once the previous pipelined checkpoint lands.
|
|
348
|
+
const isPipelining = this.epochCache.isProposerPipeliningEnabled();
|
|
349
|
+
this.pipelinedParentSimulationOverridesPlan = isPipelining
|
|
350
|
+
? await buildPipelinedParentSimulationOverridesPlan({
|
|
351
|
+
checkpointNumber: this.checkpointNumber,
|
|
352
|
+
proposedCheckpointData: this.proposedCheckpointData,
|
|
353
|
+
rollup: this.publisher.rollupContract,
|
|
354
|
+
log: this.log,
|
|
355
|
+
})
|
|
356
|
+
: undefined;
|
|
357
|
+
|
|
178
358
|
const checkpointGlobalVariables = await this.globalsBuilder.buildCheckpointGlobalVariables(
|
|
179
359
|
coinbase,
|
|
180
360
|
feeRecipient,
|
|
181
|
-
this.
|
|
361
|
+
this.targetSlot,
|
|
362
|
+
this.pipelinedParentSimulationOverridesPlan,
|
|
182
363
|
);
|
|
183
364
|
|
|
184
365
|
// Collect L1 to L2 messages for the checkpoint and compute their hash
|
|
@@ -186,16 +367,15 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
186
367
|
const inHash = computeInHashFromL1ToL2Messages(l1ToL2Messages);
|
|
187
368
|
|
|
188
369
|
// Collect the out hashes of all the checkpoints before this one in the same epoch
|
|
189
|
-
const
|
|
190
|
-
c => c.
|
|
191
|
-
|
|
192
|
-
const previousCheckpointOutHashes = previousCheckpoints.map(c => c.getCheckpointOutHash());
|
|
370
|
+
const previousCheckpointOutHashes = (await this.l2BlockSource.getCheckpointsDataForEpoch(this.targetEpoch))
|
|
371
|
+
.filter(c => c.checkpointNumber < this.checkpointNumber)
|
|
372
|
+
.map(c => c.checkpointOutHash);
|
|
193
373
|
|
|
194
374
|
// Get the fee asset price modifier from the oracle
|
|
195
375
|
const feeAssetPriceModifier = await this.publisher.getFeeAssetPriceModifier();
|
|
196
376
|
|
|
197
377
|
// Create a long-lived forked world state for the checkpoint builder
|
|
198
|
-
using fork = await this.worldState.fork(this.syncedToBlockNumber, { closeDelayMs: 12_000 });
|
|
378
|
+
await using fork = await this.worldState.fork(this.syncedToBlockNumber, { closeDelayMs: 12_000 });
|
|
199
379
|
|
|
200
380
|
// Create checkpoint builder for the entire slot
|
|
201
381
|
const checkpointBuilder = await this.checkpointsBuilder.startCheckpoint(
|
|
@@ -220,7 +400,8 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
220
400
|
};
|
|
221
401
|
|
|
222
402
|
let blocksInCheckpoint: L2Block[] = [];
|
|
223
|
-
let blockPendingBroadcast:
|
|
403
|
+
let blockPendingBroadcast: BlockProposal | undefined = undefined;
|
|
404
|
+
const checkpointBuildTimer = new Timer();
|
|
224
405
|
|
|
225
406
|
try {
|
|
226
407
|
// Main loop: build blocks for the checkpoint
|
|
@@ -243,94 +424,90 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
243
424
|
}
|
|
244
425
|
|
|
245
426
|
if (blocksInCheckpoint.length === 0) {
|
|
246
|
-
this.log.warn(`No blocks were built for slot ${this.
|
|
247
|
-
this.eventEmitter.emit('checkpoint-empty', { slot: this.
|
|
427
|
+
this.log.warn(`No blocks were built for slot ${this.targetSlot}`, { slot: this.targetSlot });
|
|
428
|
+
this.eventEmitter.emit('checkpoint-empty', { slot: this.targetSlot });
|
|
429
|
+
return undefined;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
const minBlocksForCheckpoint = this.config.minBlocksForCheckpoint;
|
|
433
|
+
if (minBlocksForCheckpoint !== undefined && blocksInCheckpoint.length < minBlocksForCheckpoint) {
|
|
434
|
+
this.log.warn(
|
|
435
|
+
`Checkpoint has fewer blocks than minimum (${blocksInCheckpoint.length} < ${minBlocksForCheckpoint}), skipping proposal`,
|
|
436
|
+
{ slot: this.targetSlot, blocksBuilt: blocksInCheckpoint.length, minBlocksForCheckpoint },
|
|
437
|
+
);
|
|
248
438
|
return undefined;
|
|
249
439
|
}
|
|
250
440
|
|
|
251
441
|
// Assemble and broadcast the checkpoint proposal, including the last block that was not
|
|
252
442
|
// broadcasted yet, and wait to collect the committee attestations.
|
|
253
|
-
this.setStateFn(SequencerState.ASSEMBLING_CHECKPOINT, this.
|
|
443
|
+
this.setStateFn(SequencerState.ASSEMBLING_CHECKPOINT, this.targetSlot);
|
|
254
444
|
const checkpoint = await checkpointBuilder.completeCheckpoint();
|
|
255
445
|
|
|
256
|
-
//
|
|
446
|
+
// Final validation: per-block limits are only checked if the operator set them explicitly.
|
|
447
|
+
// Otherwise, checkpoint-level budgets were already enforced by the redistribution logic.
|
|
448
|
+
try {
|
|
449
|
+
validateCheckpoint(checkpoint, {
|
|
450
|
+
rollupManaLimit: this.l1Constants.rollupManaLimit,
|
|
451
|
+
maxL2BlockGas: this.config.maxL2BlockGas,
|
|
452
|
+
maxDABlockGas: this.config.maxDABlockGas,
|
|
453
|
+
maxTxsPerBlock: this.config.maxTxsPerBlock,
|
|
454
|
+
maxTxsPerCheckpoint: this.config.maxTxsPerCheckpoint,
|
|
455
|
+
});
|
|
456
|
+
} catch (err) {
|
|
457
|
+
this.log.error(`Built an invalid checkpoint at slot ${this.slotNow} (skipping proposal)`, err, {
|
|
458
|
+
checkpoint: checkpoint.header.toInspect(),
|
|
459
|
+
});
|
|
460
|
+
return undefined;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
// Record checkpoint-level build metrics
|
|
464
|
+
this.checkpointMetrics.recordCheckpointBuild(
|
|
465
|
+
checkpointBuildTimer.ms(),
|
|
466
|
+
blocksInCheckpoint.length,
|
|
467
|
+
checkpoint.getStats().txCount,
|
|
468
|
+
Number(checkpoint.header.totalManaUsed.toBigInt()),
|
|
469
|
+
);
|
|
470
|
+
|
|
471
|
+
// In fisherman mode, return the checkpoint without broadcasting or collecting attestations
|
|
257
472
|
if (this.config.fishermanMode) {
|
|
258
473
|
this.log.info(
|
|
259
|
-
`Built checkpoint for slot ${this.
|
|
474
|
+
`Built checkpoint for slot ${this.targetSlot} with ${blocksInCheckpoint.length} blocks. ` +
|
|
260
475
|
`Skipping proposal in fisherman mode.`,
|
|
261
476
|
{
|
|
262
|
-
slot: this.
|
|
477
|
+
slot: this.targetSlot,
|
|
263
478
|
checkpoint: checkpoint.header.toInspect(),
|
|
264
479
|
blocksBuilt: blocksInCheckpoint.length,
|
|
265
480
|
},
|
|
266
481
|
);
|
|
267
482
|
this.metrics.recordCheckpointSuccess();
|
|
268
|
-
|
|
483
|
+
// Return a broadcast result with a dummy proposal — fisherman mode skips attestation collection
|
|
484
|
+
return { checkpoint, proposal: undefined!, blockProposedAt: this.dateProvider.now() };
|
|
269
485
|
}
|
|
270
486
|
|
|
271
|
-
// Include the block pending broadcast in the checkpoint proposal if any
|
|
272
|
-
const lastBlock = blockPendingBroadcast && {
|
|
273
|
-
blockHeader: blockPendingBroadcast.block.header,
|
|
274
|
-
indexWithinCheckpoint: blockPendingBroadcast.block.indexWithinCheckpoint,
|
|
275
|
-
txs: blockPendingBroadcast.txs,
|
|
276
|
-
};
|
|
277
|
-
|
|
278
487
|
// Create the checkpoint proposal and broadcast it
|
|
279
488
|
const proposal = await this.validatorClient.createCheckpointProposal(
|
|
280
489
|
checkpoint.header,
|
|
281
490
|
checkpoint.archive.root,
|
|
491
|
+
this.checkpointNumber,
|
|
282
492
|
feeAssetPriceModifier,
|
|
283
|
-
|
|
493
|
+
blockPendingBroadcast,
|
|
284
494
|
this.proposer,
|
|
285
495
|
checkpointProposalOptions,
|
|
286
496
|
);
|
|
287
497
|
|
|
288
498
|
const blockProposedAt = this.dateProvider.now();
|
|
289
499
|
await this.p2pClient.broadcastCheckpointProposal(proposal);
|
|
500
|
+
this.checkpointMetrics.noteCheckpointBroadcast(this.dateProvider.now());
|
|
290
501
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
const blockAttestedAt = this.dateProvider.now();
|
|
294
|
-
|
|
295
|
-
this.metrics.recordCheckpointAttestationDelay(blockAttestedAt - blockProposedAt);
|
|
296
|
-
|
|
297
|
-
// Proposer must sign over the attestations before pushing them to L1
|
|
298
|
-
const signer = this.proposer ?? this.publisher.getSenderAddress();
|
|
299
|
-
let attestationsSignature: Signature;
|
|
300
|
-
try {
|
|
301
|
-
attestationsSignature = await this.validatorClient.signAttestationsAndSigners(
|
|
302
|
-
attestations,
|
|
303
|
-
signer,
|
|
304
|
-
this.slot,
|
|
305
|
-
this.checkpointNumber,
|
|
306
|
-
);
|
|
307
|
-
} catch (err) {
|
|
308
|
-
// We shouldn't really get here since we yield to another HA node
|
|
309
|
-
// as soon as we see these errors when creating block or checkpoint proposals.
|
|
310
|
-
if (this.handleHASigningError(err, 'Attestations signature')) {
|
|
311
|
-
return undefined;
|
|
312
|
-
}
|
|
313
|
-
throw err;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
// Enqueue publishing the checkpoint to L1
|
|
317
|
-
this.setStateFn(SequencerState.PUBLISHING_CHECKPOINT, this.slot);
|
|
318
|
-
const aztecSlotDuration = this.l1Constants.slotDuration;
|
|
319
|
-
const slotStartBuildTimestamp = this.getSlotStartBuildTimestamp();
|
|
320
|
-
const txTimeoutAt = new Date((slotStartBuildTimestamp + aztecSlotDuration) * 1000);
|
|
321
|
-
await this.publisher.enqueueProposeCheckpoint(checkpoint, attestations, attestationsSignature, {
|
|
322
|
-
txTimeoutAt,
|
|
323
|
-
forcePendingCheckpointNumber: this.invalidateCheckpoint?.forcePendingCheckpointNumber,
|
|
324
|
-
});
|
|
325
|
-
|
|
326
|
-
return checkpoint;
|
|
502
|
+
// Return immediately after broadcast — attestation collection happens in the background
|
|
503
|
+
return { checkpoint, proposal, blockProposedAt };
|
|
327
504
|
} catch (err) {
|
|
328
505
|
if (err && (err instanceof DutyAlreadySignedError || err instanceof SlashingProtectionError)) {
|
|
329
506
|
// swallow this error. It's already been logged by a function deeper in the stack
|
|
330
507
|
return undefined;
|
|
331
508
|
}
|
|
332
509
|
|
|
333
|
-
this.log.error(`Error building checkpoint at slot ${this.
|
|
510
|
+
this.log.error(`Error building checkpoint at slot ${this.targetSlot}`, err);
|
|
334
511
|
return undefined;
|
|
335
512
|
}
|
|
336
513
|
}
|
|
@@ -346,17 +523,14 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
346
523
|
blockProposalOptions: BlockProposalOptions,
|
|
347
524
|
): Promise<{
|
|
348
525
|
blocksInCheckpoint: L2Block[];
|
|
349
|
-
blockPendingBroadcast:
|
|
526
|
+
blockPendingBroadcast: BlockProposal | undefined;
|
|
350
527
|
}> {
|
|
351
528
|
const blocksInCheckpoint: L2Block[] = [];
|
|
352
529
|
const txHashesAlreadyIncluded = new Set<string>();
|
|
353
530
|
const initialBlockNumber = BlockNumber(this.syncedToBlockNumber + 1);
|
|
354
531
|
|
|
355
|
-
// Remaining blob fields available for blocks (checkpoint end marker already subtracted)
|
|
356
|
-
let remainingBlobFields = BLOBS_PER_CHECKPOINT * FIELDS_PER_BLOB - NUM_CHECKPOINT_END_MARKER_FIELDS;
|
|
357
|
-
|
|
358
532
|
// Last block in the checkpoint will usually be flagged as pending broadcast, so we send it along with the checkpoint proposal
|
|
359
|
-
let blockPendingBroadcast:
|
|
533
|
+
let blockPendingBroadcast: BlockProposal | undefined = undefined;
|
|
360
534
|
|
|
361
535
|
while (true) {
|
|
362
536
|
const blocksBuilt = blocksInCheckpoint.length;
|
|
@@ -368,7 +542,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
368
542
|
|
|
369
543
|
if (!timingInfo.canStart) {
|
|
370
544
|
this.log.debug(`Not enough time left in slot to start another block`, {
|
|
371
|
-
slot: this.
|
|
545
|
+
slot: this.targetSlot,
|
|
372
546
|
blocksBuilt,
|
|
373
547
|
secondsIntoSlot,
|
|
374
548
|
});
|
|
@@ -387,25 +561,25 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
387
561
|
blockNumber,
|
|
388
562
|
indexWithinCheckpoint,
|
|
389
563
|
txHashesAlreadyIncluded,
|
|
390
|
-
remainingBlobFields,
|
|
391
564
|
});
|
|
392
565
|
|
|
393
|
-
//
|
|
394
|
-
if (
|
|
395
|
-
// If
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
566
|
+
// If we failed to build the block due to insufficient txs, we try again if there is still time left in the slot
|
|
567
|
+
if ('failure' in buildResult) {
|
|
568
|
+
// If this was the last subslot, or we're running with a single block per slot, we're done
|
|
569
|
+
if (timingInfo.isLastBlock || timingInfo.deadline === undefined) {
|
|
570
|
+
break;
|
|
571
|
+
}
|
|
572
|
+
// Otherwise, if there is still time for more blocks, we wait until the next subslot and try again
|
|
399
573
|
await this.waitUntilNextSubslot(timingInfo.deadline);
|
|
400
574
|
continue;
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
// If there was an error building the block, we just exit the loop and give up the rest of the slot.
|
|
578
|
+
// We don't want to risk building more blocks if something went wrong.
|
|
579
|
+
if ('error' in buildResult) {
|
|
406
580
|
if (!(buildResult.error instanceof SequencerInterruptedError)) {
|
|
407
|
-
this.log.warn(`Halting block building for slot ${this.
|
|
408
|
-
slot: this.
|
|
581
|
+
this.log.warn(`Halting block building for slot ${this.targetSlot}`, {
|
|
582
|
+
slot: this.targetSlot,
|
|
409
583
|
blocksBuilt,
|
|
410
584
|
error: buildResult.error,
|
|
411
585
|
});
|
|
@@ -413,65 +587,81 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
413
587
|
break;
|
|
414
588
|
}
|
|
415
589
|
|
|
416
|
-
const { block, usedTxs
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
remainingBlobFields = newRemainingBlobFields;
|
|
421
|
-
|
|
422
|
-
// Sync the proposed block to the archiver to make it available
|
|
423
|
-
// Note that the checkpoint builder uses its own fork so it should not need to wait for this syncing
|
|
424
|
-
// Eventually we should refactor the checkpoint builder to not need a separate long-lived fork
|
|
425
|
-
// Fire and forget - don't block the critical path, but log errors
|
|
426
|
-
this.syncProposedBlockToArchiver(block).catch(err => {
|
|
427
|
-
this.log.error(`Failed to sync proposed block ${block.number} to archiver`, { blockNumber: block.number, err });
|
|
590
|
+
const { block, usedTxs } = buildResult;
|
|
591
|
+
this.checkpointMetrics.noteCheckpointBlockBuilt(this.dateProvider.now(), {
|
|
592
|
+
isFirstBlock: blocksBuilt === 0,
|
|
593
|
+
isLastBlock: timingInfo.isLastBlock,
|
|
428
594
|
});
|
|
429
595
|
|
|
596
|
+
blocksInCheckpoint.push(block);
|
|
430
597
|
usedTxs.forEach(tx => txHashesAlreadyIncluded.add(tx.txHash.toString()));
|
|
431
598
|
|
|
432
|
-
//
|
|
599
|
+
// Sign the block proposal. This will throw if HA signing fails.
|
|
600
|
+
const proposal = await this.createBlockProposal(block, inHash, usedTxs, blockProposalOptions);
|
|
601
|
+
|
|
602
|
+
// Sync the proposed block to the archiver to make it available, only after we've managed to sign the proposal,
|
|
603
|
+
// so we avoid polluting our archive with a block that would fail.
|
|
604
|
+
// We wait for the sync to succeed, as this helps catch consistency errors, even if it means we lose some time for block-building.
|
|
605
|
+
// If this throws, we abort the entire checkpoint.
|
|
606
|
+
await this.syncProposedBlockToArchiver(block);
|
|
607
|
+
|
|
608
|
+
// If this is the last block, do not broadcast it, since it will be included in the checkpoint proposal.
|
|
433
609
|
if (timingInfo.isLastBlock) {
|
|
434
|
-
this.log.verbose(`Completed final block ${blockNumber} for slot ${this.
|
|
435
|
-
slot: this.
|
|
610
|
+
this.log.verbose(`Completed final block ${blockNumber} for slot ${this.targetSlot}`, {
|
|
611
|
+
slot: this.targetSlot,
|
|
436
612
|
blockNumber,
|
|
437
613
|
blocksBuilt,
|
|
438
614
|
});
|
|
439
|
-
|
|
615
|
+
|
|
616
|
+
blockPendingBroadcast = proposal;
|
|
440
617
|
break;
|
|
441
618
|
}
|
|
442
619
|
|
|
443
|
-
//
|
|
444
|
-
|
|
445
|
-
if (!this.config.fishermanMode) {
|
|
446
|
-
const proposal = await this.validatorClient.createBlockProposal(
|
|
447
|
-
block.header,
|
|
448
|
-
block.indexWithinCheckpoint,
|
|
449
|
-
inHash,
|
|
450
|
-
block.archive.root,
|
|
451
|
-
usedTxs,
|
|
452
|
-
this.proposer,
|
|
453
|
-
blockProposalOptions,
|
|
454
|
-
);
|
|
455
|
-
await this.p2pClient.broadcastProposal(proposal);
|
|
456
|
-
}
|
|
620
|
+
// Once we have a signed proposal and the archiver agreed with our proposed block, then we broadcast it.
|
|
621
|
+
proposal && (await this.p2pClient.broadcastProposal(proposal));
|
|
457
622
|
|
|
458
623
|
// Wait until the next block's start time
|
|
459
624
|
await this.waitUntilNextSubslot(timingInfo.deadline);
|
|
460
625
|
}
|
|
461
626
|
|
|
462
|
-
this.log.verbose(`Block building loop completed for slot ${this.
|
|
463
|
-
slot: this.
|
|
627
|
+
this.log.verbose(`Block building loop completed for slot ${this.targetSlot}`, {
|
|
628
|
+
slot: this.targetSlot,
|
|
464
629
|
blocksBuilt: blocksInCheckpoint.length,
|
|
465
630
|
});
|
|
466
631
|
|
|
467
632
|
return { blocksInCheckpoint, blockPendingBroadcast };
|
|
468
633
|
}
|
|
469
634
|
|
|
635
|
+
/** Creates a block proposal for a given block via the validator client (unless in fisherman mode) */
|
|
636
|
+
private createBlockProposal(
|
|
637
|
+
block: L2Block,
|
|
638
|
+
inHash: Fr,
|
|
639
|
+
usedTxs: Tx[],
|
|
640
|
+
blockProposalOptions: BlockProposalOptions,
|
|
641
|
+
): Promise<BlockProposal | undefined> {
|
|
642
|
+
if (this.config.fishermanMode) {
|
|
643
|
+
this.log.info(`Skipping block proposal for block ${block.number} in fisherman mode`);
|
|
644
|
+
return Promise.resolve(undefined);
|
|
645
|
+
}
|
|
646
|
+
return this.validatorClient.createBlockProposal(
|
|
647
|
+
block.header,
|
|
648
|
+
this.checkpointNumber,
|
|
649
|
+
block.indexWithinCheckpoint,
|
|
650
|
+
inHash,
|
|
651
|
+
block.archive.root,
|
|
652
|
+
usedTxs,
|
|
653
|
+
this.proposer,
|
|
654
|
+
blockProposalOptions,
|
|
655
|
+
);
|
|
656
|
+
}
|
|
657
|
+
|
|
470
658
|
/** Sleeps until it is time to produce the next block in the slot */
|
|
471
659
|
@trackSpan('CheckpointProposalJob.waitUntilNextSubslot')
|
|
472
660
|
private async waitUntilNextSubslot(nextSubslotStart: number) {
|
|
473
|
-
this.setStateFn(SequencerState.WAITING_UNTIL_NEXT_BLOCK, this.
|
|
474
|
-
this.log.verbose(`Waiting until time for the next block at ${nextSubslotStart}s into slot`, {
|
|
661
|
+
this.setStateFn(SequencerState.WAITING_UNTIL_NEXT_BLOCK, this.targetSlot);
|
|
662
|
+
this.log.verbose(`Waiting until time for the next block at ${nextSubslotStart}s into slot`, {
|
|
663
|
+
slot: this.targetSlot,
|
|
664
|
+
});
|
|
475
665
|
await this.waitUntilTimeInSlot(nextSubslotStart);
|
|
476
666
|
}
|
|
477
667
|
|
|
@@ -486,36 +676,29 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
486
676
|
indexWithinCheckpoint: IndexWithinCheckpoint;
|
|
487
677
|
buildDeadline: Date | undefined;
|
|
488
678
|
txHashesAlreadyIncluded: Set<string>;
|
|
489
|
-
remainingBlobFields: number;
|
|
490
679
|
},
|
|
491
|
-
): Promise<
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
indexWithinCheckpoint,
|
|
497
|
-
buildDeadline,
|
|
498
|
-
txHashesAlreadyIncluded,
|
|
499
|
-
remainingBlobFields,
|
|
500
|
-
} = opts;
|
|
680
|
+
): Promise<
|
|
681
|
+
{ block: L2Block; usedTxs: Tx[] } | { failure: 'insufficient-txs' | 'insufficient-valid-txs' } | { error: Error }
|
|
682
|
+
> {
|
|
683
|
+
const { blockTimestamp, forceCreate, blockNumber, indexWithinCheckpoint, buildDeadline, txHashesAlreadyIncluded } =
|
|
684
|
+
opts;
|
|
501
685
|
|
|
502
686
|
this.log.verbose(
|
|
503
|
-
`Preparing block ${blockNumber} index ${indexWithinCheckpoint} at checkpoint ${this.checkpointNumber} for slot ${this.
|
|
687
|
+
`Preparing block ${blockNumber} index ${indexWithinCheckpoint} at checkpoint ${this.checkpointNumber} for slot ${this.targetSlot}`,
|
|
504
688
|
{ ...checkpointBuilder.getConstantData(), ...opts },
|
|
505
689
|
);
|
|
506
690
|
|
|
507
691
|
try {
|
|
508
692
|
// Wait until we have enough txs to build the block
|
|
509
|
-
const minTxs = this.
|
|
510
|
-
const { availableTxs, canStartBuilding } = await this.waitForMinTxs(opts);
|
|
693
|
+
const { availableTxs, canStartBuilding, minTxs } = await this.waitForMinTxs(opts);
|
|
511
694
|
if (!canStartBuilding) {
|
|
512
695
|
this.log.warn(
|
|
513
|
-
`Not enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.
|
|
514
|
-
{ blockNumber, slot: this.
|
|
696
|
+
`Not enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.targetSlot} (got ${availableTxs} txs but needs ${minTxs})`,
|
|
697
|
+
{ blockNumber, slot: this.targetSlot, indexWithinCheckpoint },
|
|
515
698
|
);
|
|
516
|
-
this.eventEmitter.emit('block-tx-count-check-failed', { minTxs, availableTxs, slot: this.
|
|
699
|
+
this.eventEmitter.emit('block-tx-count-check-failed', { minTxs, availableTxs, slot: this.targetSlot });
|
|
517
700
|
this.metrics.recordBlockProposalFailed('insufficient_txs');
|
|
518
|
-
return
|
|
701
|
+
return { failure: 'insufficient-txs' };
|
|
519
702
|
}
|
|
520
703
|
|
|
521
704
|
// Create iterator to pending txs. We filter out txs already included in previous blocks in the checkpoint
|
|
@@ -526,24 +709,31 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
526
709
|
);
|
|
527
710
|
|
|
528
711
|
this.log.debug(
|
|
529
|
-
`Building block ${blockNumber} at index ${indexWithinCheckpoint} for slot ${this.
|
|
530
|
-
{ slot: this.
|
|
712
|
+
`Building block ${blockNumber} at index ${indexWithinCheckpoint} for slot ${this.targetSlot} with ${availableTxs} available txs`,
|
|
713
|
+
{ slot: this.targetSlot, blockNumber, indexWithinCheckpoint },
|
|
531
714
|
);
|
|
532
|
-
this.setStateFn(SequencerState.CREATING_BLOCK, this.
|
|
715
|
+
this.setStateFn(SequencerState.CREATING_BLOCK, this.targetSlot);
|
|
533
716
|
|
|
534
|
-
//
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
const blockBuilderOptions:
|
|
717
|
+
// Per-block limits are operator overrides (from SEQ_MAX_L2_BLOCK_GAS etc.) further capped
|
|
718
|
+
// by remaining checkpoint-level budgets inside CheckpointBuilder before each block is built.
|
|
719
|
+
// minValidTxs is passed into the builder so it can reject the block *before* updating state.
|
|
720
|
+
const minValidTxs = forceCreate ? 0 : (this.config.minValidTxsPerBlock ?? minTxs);
|
|
721
|
+
const blockBuilderOptions: BlockBuilderOptions = {
|
|
539
722
|
maxTransactions: this.config.maxTxsPerBlock,
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
723
|
+
maxBlockGas:
|
|
724
|
+
this.config.maxL2BlockGas !== undefined || this.config.maxDABlockGas !== undefined
|
|
725
|
+
? new Gas(this.config.maxDABlockGas ?? Infinity, this.config.maxL2BlockGas ?? Infinity)
|
|
726
|
+
: undefined,
|
|
543
727
|
deadline: buildDeadline,
|
|
728
|
+
isBuildingProposal: true,
|
|
729
|
+
minValidTxs,
|
|
730
|
+
maxBlocksPerCheckpoint: this.timetable.maxNumberOfBlocks,
|
|
731
|
+
perBlockAllocationMultiplier: this.config.perBlockAllocationMultiplier,
|
|
544
732
|
};
|
|
545
733
|
|
|
546
|
-
// Actually build the block by executing txs
|
|
734
|
+
// Actually build the block by executing txs. The builder throws InsufficientValidTxsError
|
|
735
|
+
// if the number of successfully processed txs is below minValidTxs, ensuring state is not
|
|
736
|
+
// updated for blocks that will be discarded.
|
|
547
737
|
const buildResult = await this.buildSingleBlockWithCheckpointBuilder(
|
|
548
738
|
checkpointBuilder,
|
|
549
739
|
pendingTxs,
|
|
@@ -555,22 +745,27 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
555
745
|
// If any txs failed during execution, drop them from the mempool so we don't pick them up again
|
|
556
746
|
await this.dropFailedTxsFromP2P(buildResult.failedTxs);
|
|
557
747
|
|
|
558
|
-
|
|
559
|
-
// too long, then we may not get to minTxsPerBlock after executing public functions.
|
|
560
|
-
const minValidTxs = this.config.minValidTxsPerBlock ?? minTxs;
|
|
561
|
-
const numTxs = buildResult.status === 'no-valid-txs' ? 0 : buildResult.numTxs;
|
|
562
|
-
if (buildResult.status === 'no-valid-txs' || (!forceCreate && numTxs < minValidTxs)) {
|
|
748
|
+
if (buildResult.status === 'insufficient-valid-txs') {
|
|
563
749
|
this.log.warn(
|
|
564
|
-
`Block ${blockNumber} at index ${indexWithinCheckpoint} on slot ${this.
|
|
565
|
-
{
|
|
750
|
+
`Block ${blockNumber} at index ${indexWithinCheckpoint} on slot ${this.targetSlot} has too few valid txs to be proposed`,
|
|
751
|
+
{
|
|
752
|
+
slot: this.targetSlot,
|
|
753
|
+
blockNumber,
|
|
754
|
+
numTxs: buildResult.processedCount,
|
|
755
|
+
indexWithinCheckpoint,
|
|
756
|
+
minValidTxs,
|
|
757
|
+
},
|
|
566
758
|
);
|
|
567
|
-
this.eventEmitter.emit('block-build-failed', {
|
|
759
|
+
this.eventEmitter.emit('block-build-failed', {
|
|
760
|
+
reason: `Insufficient valid txs`,
|
|
761
|
+
slot: this.targetSlot,
|
|
762
|
+
});
|
|
568
763
|
this.metrics.recordBlockProposalFailed('insufficient_valid_txs');
|
|
569
|
-
return
|
|
764
|
+
return { failure: 'insufficient-valid-txs' };
|
|
570
765
|
}
|
|
571
766
|
|
|
572
767
|
// Block creation succeeded, emit stats and metrics
|
|
573
|
-
const {
|
|
768
|
+
const { block, publicProcessorDuration, usedTxs, blockBuildDuration, numTxs } = buildResult;
|
|
574
769
|
|
|
575
770
|
const blockStats = {
|
|
576
771
|
eventName: 'l2-block-built',
|
|
@@ -581,33 +776,42 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
581
776
|
|
|
582
777
|
const blockHash = await block.hash();
|
|
583
778
|
const txHashes = block.body.txEffects.map(tx => tx.txHash);
|
|
584
|
-
const manaPerSec =
|
|
779
|
+
const manaPerSec = block.header.totalManaUsed.toNumberUnsafe() / (blockBuildDuration / 1000);
|
|
585
780
|
|
|
586
781
|
this.log.info(
|
|
587
|
-
`Built block ${block.number} at checkpoint ${this.checkpointNumber} for slot ${this.
|
|
782
|
+
`Built block ${block.number} at checkpoint ${this.checkpointNumber} for slot ${this.targetSlot} with ${numTxs} txs`,
|
|
588
783
|
{ blockHash, txHashes, manaPerSec, ...blockStats },
|
|
589
784
|
);
|
|
590
785
|
|
|
591
|
-
|
|
592
|
-
|
|
786
|
+
// `slot` is the target/submission slot (may be one ahead when pipelining),
|
|
787
|
+
// `buildSlot` is the wall-clock slot during which the block was actually built.
|
|
788
|
+
this.eventEmitter.emit('block-proposed', {
|
|
789
|
+
blockNumber: block.number,
|
|
790
|
+
slot: this.targetSlot,
|
|
791
|
+
buildSlot: this.slotNow,
|
|
792
|
+
});
|
|
793
|
+
this.metrics.recordBuiltBlock(blockBuildDuration, block.header.totalManaUsed.toNumberUnsafe(), this.targetSlot);
|
|
593
794
|
|
|
594
|
-
return { block, usedTxs
|
|
795
|
+
return { block, usedTxs };
|
|
595
796
|
} catch (err: any) {
|
|
596
|
-
this.eventEmitter.emit('block-build-failed', {
|
|
597
|
-
|
|
797
|
+
this.eventEmitter.emit('block-build-failed', {
|
|
798
|
+
reason: err.message,
|
|
799
|
+
slot: this.targetSlot,
|
|
800
|
+
});
|
|
801
|
+
this.log.error(`Error building block`, err, { blockNumber, slot: this.targetSlot });
|
|
598
802
|
this.metrics.recordBlockProposalFailed(err.name || 'unknown_error');
|
|
599
803
|
this.metrics.recordFailedBlock();
|
|
600
804
|
return { error: err };
|
|
601
805
|
}
|
|
602
806
|
}
|
|
603
807
|
|
|
604
|
-
/** Uses the checkpoint builder to build a block, catching
|
|
808
|
+
/** Uses the checkpoint builder to build a block, catching InsufficientValidTxsError. */
|
|
605
809
|
private async buildSingleBlockWithCheckpointBuilder(
|
|
606
810
|
checkpointBuilder: CheckpointBuilder,
|
|
607
811
|
pendingTxs: AsyncIterable<Tx>,
|
|
608
812
|
blockNumber: BlockNumber,
|
|
609
813
|
blockTimestamp: bigint,
|
|
610
|
-
blockBuilderOptions:
|
|
814
|
+
blockBuilderOptions: BlockBuilderOptions,
|
|
611
815
|
) {
|
|
612
816
|
try {
|
|
613
817
|
const workTimer = new Timer();
|
|
@@ -615,8 +819,12 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
615
819
|
const blockBuildDuration = workTimer.ms();
|
|
616
820
|
return { ...result, blockBuildDuration, status: 'success' as const };
|
|
617
821
|
} catch (err: unknown) {
|
|
618
|
-
if (isErrorClass(err,
|
|
619
|
-
return {
|
|
822
|
+
if (isErrorClass(err, InsufficientValidTxsError)) {
|
|
823
|
+
return {
|
|
824
|
+
failedTxs: err.failedTxs,
|
|
825
|
+
processedCount: err.processedCount,
|
|
826
|
+
status: 'insufficient-valid-txs' as const,
|
|
827
|
+
};
|
|
620
828
|
}
|
|
621
829
|
throw err;
|
|
622
830
|
}
|
|
@@ -629,7 +837,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
629
837
|
blockNumber: BlockNumber;
|
|
630
838
|
indexWithinCheckpoint: IndexWithinCheckpoint;
|
|
631
839
|
buildDeadline: Date | undefined;
|
|
632
|
-
}): Promise<{ canStartBuilding: boolean; availableTxs: number }> {
|
|
840
|
+
}): Promise<{ canStartBuilding: boolean; availableTxs: number; minTxs: number }> {
|
|
633
841
|
const { indexWithinCheckpoint, blockNumber, buildDeadline, forceCreate } = opts;
|
|
634
842
|
|
|
635
843
|
// We only allow a block with 0 txs in the first block of the checkpoint
|
|
@@ -646,20 +854,20 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
646
854
|
// If we're past deadline, or we have no deadline, give up
|
|
647
855
|
const now = this.dateProvider.nowAsDate();
|
|
648
856
|
if (startBuildingDeadline === undefined || now >= startBuildingDeadline) {
|
|
649
|
-
return { canStartBuilding: false, availableTxs
|
|
857
|
+
return { canStartBuilding: false, availableTxs, minTxs };
|
|
650
858
|
}
|
|
651
859
|
|
|
652
860
|
// Wait a bit before checking again
|
|
653
|
-
this.setStateFn(SequencerState.WAITING_FOR_TXS, this.
|
|
861
|
+
this.setStateFn(SequencerState.WAITING_FOR_TXS, this.targetSlot);
|
|
654
862
|
this.log.verbose(
|
|
655
|
-
`Waiting for enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.
|
|
656
|
-
{ blockNumber, slot: this.
|
|
863
|
+
`Waiting for enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.targetSlot} (have ${availableTxs} but need ${minTxs})`,
|
|
864
|
+
{ blockNumber, slot: this.targetSlot, indexWithinCheckpoint },
|
|
657
865
|
);
|
|
658
866
|
await this.waitForTxsPollingInterval();
|
|
659
867
|
availableTxs = await this.p2pClient.getPendingTxCount();
|
|
660
868
|
}
|
|
661
869
|
|
|
662
|
-
return { canStartBuilding: true, availableTxs };
|
|
870
|
+
return { canStartBuilding: true, availableTxs, minTxs };
|
|
663
871
|
}
|
|
664
872
|
|
|
665
873
|
/**
|
|
@@ -685,16 +893,16 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
685
893
|
this.log.debug(`Attesting committee length is ${committee.length}`, { committee });
|
|
686
894
|
}
|
|
687
895
|
|
|
688
|
-
const numberOfRequiredAttestations =
|
|
896
|
+
const numberOfRequiredAttestations = computeQuorum(committee.length);
|
|
689
897
|
|
|
690
898
|
if (this.config.skipCollectingAttestations) {
|
|
691
899
|
this.log.warn('Skipping attestation collection as per config (attesting with own keys only)');
|
|
692
|
-
const attestations = await this.validatorClient?.collectOwnAttestations(proposal);
|
|
900
|
+
const attestations = await this.validatorClient?.collectOwnAttestations(proposal, this.checkpointNumber);
|
|
693
901
|
return new CommitteeAttestationsAndSigners(orderAttestations(attestations ?? [], committee));
|
|
694
902
|
}
|
|
695
903
|
|
|
696
904
|
const attestationTimeAllowed = this.config.enforceTimeTable
|
|
697
|
-
? this.timetable.
|
|
905
|
+
? this.timetable.getCheckpointAttestationDeadline()
|
|
698
906
|
: this.l1Constants.slotDuration;
|
|
699
907
|
const attestationDeadline = new Date((this.getSlotStartBuildTimestamp() + attestationTimeAllowed) * 1000);
|
|
700
908
|
|
|
@@ -707,15 +915,33 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
707
915
|
proposal,
|
|
708
916
|
numberOfRequiredAttestations,
|
|
709
917
|
attestationDeadline,
|
|
918
|
+
this.checkpointNumber,
|
|
710
919
|
);
|
|
711
920
|
|
|
712
921
|
collectedAttestationsCount = attestations.length;
|
|
713
922
|
|
|
923
|
+
// Trim attestations to minimum required to save L1 calldata gas
|
|
924
|
+
const localAddresses = this.validatorClient.getValidatorAddresses();
|
|
925
|
+
const trimmed = trimAttestations(
|
|
926
|
+
attestations,
|
|
927
|
+
numberOfRequiredAttestations,
|
|
928
|
+
this.attestorAddress,
|
|
929
|
+
localAddresses,
|
|
930
|
+
);
|
|
931
|
+
if (trimmed.length < attestations.length) {
|
|
932
|
+
this.log.debug(`Trimmed attestations from ${attestations.length} to ${trimmed.length} for L1 submission`);
|
|
933
|
+
}
|
|
934
|
+
|
|
714
935
|
// Rollup contract requires that the signatures are provided in the order of the committee
|
|
715
|
-
const sorted = orderAttestations(
|
|
936
|
+
const sorted = orderAttestations(trimmed, committee);
|
|
716
937
|
|
|
717
938
|
// Manipulate the attestations if we've been configured to do so
|
|
718
|
-
if (
|
|
939
|
+
if (
|
|
940
|
+
this.config.injectFakeAttestation ||
|
|
941
|
+
this.config.injectHighSValueAttestation ||
|
|
942
|
+
this.config.injectUnrecoverableSignatureAttestation ||
|
|
943
|
+
this.config.shuffleAttestationOrdering
|
|
944
|
+
) {
|
|
719
945
|
return this.manipulateAttestations(proposal.slotNumber, epoch, seed, committee, sorted);
|
|
720
946
|
}
|
|
721
947
|
|
|
@@ -744,7 +970,11 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
744
970
|
this.epochCache.computeProposerIndex(slotNumber, epoch, seed, BigInt(committee.length)),
|
|
745
971
|
);
|
|
746
972
|
|
|
747
|
-
if (
|
|
973
|
+
if (
|
|
974
|
+
this.config.injectFakeAttestation ||
|
|
975
|
+
this.config.injectHighSValueAttestation ||
|
|
976
|
+
this.config.injectUnrecoverableSignatureAttestation
|
|
977
|
+
) {
|
|
748
978
|
// Find non-empty attestations that are not from the proposer
|
|
749
979
|
const nonProposerIndices: number[] = [];
|
|
750
980
|
for (let i = 0; i < attestations.length; i++) {
|
|
@@ -754,8 +984,20 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
754
984
|
}
|
|
755
985
|
if (nonProposerIndices.length > 0) {
|
|
756
986
|
const targetIndex = nonProposerIndices[randomInt(nonProposerIndices.length)];
|
|
757
|
-
this.
|
|
758
|
-
|
|
987
|
+
if (this.config.injectHighSValueAttestation) {
|
|
988
|
+
this.log.warn(
|
|
989
|
+
`Injecting high-s value attestation in checkpoint for slot ${slotNumber} at index ${targetIndex}`,
|
|
990
|
+
);
|
|
991
|
+
unfreeze(attestations[targetIndex]).signature = flipSignature(attestations[targetIndex].signature);
|
|
992
|
+
} else if (this.config.injectUnrecoverableSignatureAttestation) {
|
|
993
|
+
this.log.warn(
|
|
994
|
+
`Injecting unrecoverable signature attestation in checkpoint for slot ${slotNumber} at index ${targetIndex}`,
|
|
995
|
+
);
|
|
996
|
+
unfreeze(attestations[targetIndex]).signature = generateUnrecoverableSignature();
|
|
997
|
+
} else {
|
|
998
|
+
this.log.warn(`Injecting fake attestation in checkpoint for slot ${slotNumber} at index ${targetIndex}`);
|
|
999
|
+
unfreeze(attestations[targetIndex]).signature = generateRecoverableSignature();
|
|
1000
|
+
}
|
|
759
1001
|
}
|
|
760
1002
|
return new CommitteeAttestationsAndSigners(attestations);
|
|
761
1003
|
}
|
|
@@ -764,11 +1006,20 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
764
1006
|
this.log.warn(`Shuffling attestation ordering in checkpoint for slot ${slotNumber} (proposer #${proposerIndex})`);
|
|
765
1007
|
|
|
766
1008
|
const shuffled = [...attestations];
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
1009
|
+
|
|
1010
|
+
// Find two non-proposer positions that both have non-empty signatures to swap.
|
|
1011
|
+
// This ensures the bitmap doesn't change, so the MaliciousCommitteeAttestationsAndSigners
|
|
1012
|
+
// signers array stays correctly aligned with L1's committee reconstruction.
|
|
1013
|
+
const swappable: number[] = [];
|
|
1014
|
+
for (let k = 0; k < shuffled.length; k++) {
|
|
1015
|
+
if (!shuffled[k].signature.isEmpty() && k !== proposerIndex) {
|
|
1016
|
+
swappable.push(k);
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
if (swappable.length >= 2) {
|
|
1020
|
+
const [i, j] = [swappable[0], swappable[1]];
|
|
1021
|
+
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
|
|
1022
|
+
}
|
|
772
1023
|
|
|
773
1024
|
const signers = new CommitteeAttestationsAndSigners(attestations).getSigners();
|
|
774
1025
|
return new MaliciousCommitteeAttestationsAndSigners(shuffled, signers);
|
|
@@ -791,9 +1042,13 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
791
1042
|
* Adds the proposed block to the archiver so it's available via P2P.
|
|
792
1043
|
* Gossip doesn't echo messages back to the sender, so the proposer's archiver/world-state
|
|
793
1044
|
* would never receive its own block without this explicit sync.
|
|
1045
|
+
*
|
|
1046
|
+
* In fisherman mode we skip this push: the fisherman builds blocks locally for validation
|
|
1047
|
+
* and fee analysis only, and pushing them to the archiver causes spurious reorg cascades
|
|
1048
|
+
* whenever the real proposer's block arrives from L1.
|
|
794
1049
|
*/
|
|
795
1050
|
private async syncProposedBlockToArchiver(block: L2Block): Promise<void> {
|
|
796
|
-
if (this.config.skipPushProposedBlocksToArchiver
|
|
1051
|
+
if (this.config.skipPushProposedBlocksToArchiver || this.config.fishermanMode) {
|
|
797
1052
|
this.log.warn(`Skipping push of proposed block ${block.number} to archiver`, {
|
|
798
1053
|
blockNumber: block.number,
|
|
799
1054
|
slot: block.header.globalVariables.slotNumber,
|
|
@@ -811,22 +1066,22 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
811
1066
|
private async handleCheckpointEndAsFisherman(checkpoint: Checkpoint | undefined) {
|
|
812
1067
|
// Perform L1 fee analysis before clearing requests
|
|
813
1068
|
// The callback is invoked asynchronously after the next block is mined
|
|
814
|
-
const feeAnalysis = await this.publisher.analyzeL1Fees(this.
|
|
1069
|
+
const feeAnalysis = await this.publisher.analyzeL1Fees(this.targetSlot, analysis =>
|
|
815
1070
|
this.metrics.recordFishermanFeeAnalysis(analysis),
|
|
816
1071
|
);
|
|
817
1072
|
|
|
818
1073
|
if (checkpoint) {
|
|
819
|
-
this.log.info(`Validation checkpoint building SUCCEEDED for slot ${this.
|
|
1074
|
+
this.log.info(`Validation checkpoint building SUCCEEDED for slot ${this.targetSlot}`, {
|
|
820
1075
|
...checkpoint.toCheckpointInfo(),
|
|
821
1076
|
...checkpoint.getStats(),
|
|
822
1077
|
feeAnalysisId: feeAnalysis?.id,
|
|
823
1078
|
});
|
|
824
1079
|
} else {
|
|
825
|
-
this.log.warn(`Validation block building FAILED for slot ${this.
|
|
826
|
-
slot: this.
|
|
1080
|
+
this.log.warn(`Validation block building FAILED for slot ${this.targetSlot}`, {
|
|
1081
|
+
slot: this.targetSlot,
|
|
827
1082
|
feeAnalysisId: feeAnalysis?.id,
|
|
828
1083
|
});
|
|
829
|
-
this.metrics.
|
|
1084
|
+
this.metrics.recordCheckpointProposalFailed('block_build_failed');
|
|
830
1085
|
}
|
|
831
1086
|
|
|
832
1087
|
this.publisher.clearPendingRequests();
|
|
@@ -837,15 +1092,15 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
837
1092
|
*/
|
|
838
1093
|
private handleHASigningError(err: any, errorContext: string): boolean {
|
|
839
1094
|
if (err instanceof DutyAlreadySignedError) {
|
|
840
|
-
this.log.info(`${errorContext} for slot ${this.
|
|
841
|
-
slot: this.
|
|
1095
|
+
this.log.info(`${errorContext} for slot ${this.targetSlot} already signed by another HA node, yielding`, {
|
|
1096
|
+
slot: this.targetSlot,
|
|
842
1097
|
signedByNode: err.signedByNode,
|
|
843
1098
|
});
|
|
844
1099
|
return true;
|
|
845
1100
|
}
|
|
846
1101
|
if (err instanceof SlashingProtectionError) {
|
|
847
|
-
this.log.info(`${errorContext} for slot ${this.
|
|
848
|
-
slot: this.
|
|
1102
|
+
this.log.info(`${errorContext} for slot ${this.targetSlot} blocked by slashing protection, yielding`, {
|
|
1103
|
+
slot: this.targetSlot,
|
|
849
1104
|
existingMessageHash: err.existingMessageHash,
|
|
850
1105
|
attemptedMessageHash: err.attemptedMessageHash,
|
|
851
1106
|
});
|
|
@@ -868,7 +1123,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
868
1123
|
}
|
|
869
1124
|
|
|
870
1125
|
private getSlotStartBuildTimestamp(): number {
|
|
871
|
-
return getSlotStartBuildTimestamp(this.
|
|
1126
|
+
return getSlotStartBuildTimestamp(this.slotNow, this.l1Constants);
|
|
872
1127
|
}
|
|
873
1128
|
|
|
874
1129
|
private getSecondsIntoSlot(): number {
|