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