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