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