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