@aztec/sequencer-client 0.0.1-commit.03f7ef2 → 0.0.1-commit.0658669b3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/client/sequencer-client.d.ts +15 -11
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +15 -4
- package/dest/config.d.ts +3 -4
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +22 -12
- package/dest/global_variable_builder/global_builder.d.ts +5 -7
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +13 -13
- package/dest/index.d.ts +2 -3
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -2
- package/dest/publisher/config.d.ts +35 -17
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +106 -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 +59 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.js +1 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts +15 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.js +34 -0
- package/dest/publisher/l1_tx_failed_store/index.d.ts +4 -0
- package/dest/publisher/l1_tx_failed_store/index.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/index.js +2 -0
- package/dest/publisher/sequencer-publisher-factory.d.ts +12 -4
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-factory.js +13 -2
- 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 +23 -86
- package/dest/publisher/sequencer-publisher.d.ts +40 -25
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +740 -100
- package/dest/sequencer/checkpoint_proposal_job.d.ts +40 -12
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_proposal_job.js +643 -64
- package/dest/sequencer/checkpoint_voter.d.ts +3 -2
- package/dest/sequencer/checkpoint_voter.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_voter.js +34 -10
- package/dest/sequencer/index.d.ts +1 -3
- package/dest/sequencer/index.d.ts.map +1 -1
- package/dest/sequencer/index.js +0 -2
- package/dest/sequencer/metrics.d.ts +19 -7
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +131 -141
- package/dest/sequencer/sequencer.d.ts +38 -18
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +513 -66
- package/dest/sequencer/timetable.d.ts +1 -4
- package/dest/sequencer/timetable.d.ts.map +1 -1
- package/dest/sequencer/timetable.js +1 -4
- package/dest/test/index.d.ts +4 -7
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.d.ts +25 -11
- package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.js +52 -9
- package/dest/test/utils.d.ts +13 -9
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +27 -17
- package/package.json +30 -28
- package/src/client/sequencer-client.ts +29 -12
- package/src/config.ts +31 -19
- package/src/global_variable_builder/global_builder.ts +14 -14
- package/src/index.ts +1 -9
- package/src/publisher/config.ts +121 -43
- 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 +55 -0
- package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +46 -0
- package/src/publisher/l1_tx_failed_store/index.ts +3 -0
- package/src/publisher/sequencer-publisher-factory.ts +24 -7
- package/src/publisher/sequencer-publisher-metrics.ts +17 -69
- package/src/publisher/sequencer-publisher.ts +361 -130
- package/src/sequencer/checkpoint_proposal_job.ts +316 -93
- package/src/sequencer/checkpoint_voter.ts +32 -7
- package/src/sequencer/index.ts +0 -2
- package/src/sequencer/metrics.ts +132 -148
- package/src/sequencer/sequencer.ts +159 -68
- package/src/sequencer/timetable.ts +6 -5
- package/src/test/index.ts +3 -6
- package/src/test/mock_checkpoint_builder.ts +102 -29
- package/src/test/utils.ts +58 -28
- 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/dest/sequencer/checkpoint_builder.d.ts +0 -63
- package/dest/sequencer/checkpoint_builder.d.ts.map +0 -1
- package/dest/sequencer/checkpoint_builder.js +0 -131
- package/dest/tx_validator/nullifier_cache.d.ts +0 -14
- package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
- package/dest/tx_validator/nullifier_cache.js +0 -24
- package/dest/tx_validator/tx_validator_factory.d.ts +0 -18
- package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
- package/dest/tx_validator/tx_validator_factory.js +0 -53
- package/src/sequencer/block_builder.ts +0 -217
- package/src/sequencer/checkpoint_builder.ts +0 -217
- package/src/tx_validator/nullifier_cache.ts +0 -30
- package/src/tx_validator/tx_validator_factory.ts +0 -133
|
@@ -1,42 +1,53 @@
|
|
|
1
|
+
import { NUM_CHECKPOINT_END_MARKER_FIELDS, getNumBlockEndBlobFields } from '@aztec/blob-lib/encoding';
|
|
1
2
|
import { BLOBS_PER_CHECKPOINT, FIELDS_PER_BLOB } from '@aztec/constants';
|
|
2
3
|
import type { EpochCache } from '@aztec/epoch-cache';
|
|
3
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
BlockNumber,
|
|
6
|
+
CheckpointNumber,
|
|
7
|
+
EpochNumber,
|
|
8
|
+
IndexWithinCheckpoint,
|
|
9
|
+
SlotNumber,
|
|
10
|
+
} from '@aztec/foundation/branded-types';
|
|
4
11
|
import { randomInt } from '@aztec/foundation/crypto/random';
|
|
12
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
5
13
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
6
14
|
import { Signature } from '@aztec/foundation/eth-signature';
|
|
7
15
|
import { filter } from '@aztec/foundation/iterator';
|
|
8
|
-
import type
|
|
16
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
9
17
|
import { sleep, sleepUntil } from '@aztec/foundation/sleep';
|
|
10
18
|
import { type DateProvider, Timer } from '@aztec/foundation/timer';
|
|
11
|
-
import { type TypedEventEmitter, unfreeze } from '@aztec/foundation/types';
|
|
19
|
+
import { type TypedEventEmitter, isErrorClass, unfreeze } from '@aztec/foundation/types';
|
|
12
20
|
import type { P2P } from '@aztec/p2p';
|
|
13
21
|
import type { SlasherClientInterface } from '@aztec/slasher';
|
|
14
22
|
import {
|
|
15
23
|
CommitteeAttestation,
|
|
16
24
|
CommitteeAttestationsAndSigners,
|
|
17
|
-
|
|
25
|
+
L2Block,
|
|
26
|
+
type L2BlockSink,
|
|
27
|
+
type L2BlockSource,
|
|
18
28
|
MaliciousCommitteeAttestationsAndSigners,
|
|
19
29
|
} from '@aztec/stdlib/block';
|
|
20
30
|
import type { Checkpoint } from '@aztec/stdlib/checkpoint';
|
|
21
31
|
import { getSlotStartBuildTimestamp } from '@aztec/stdlib/epoch-helpers';
|
|
22
32
|
import { Gas } from '@aztec/stdlib/gas';
|
|
23
|
-
import
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
33
|
+
import {
|
|
34
|
+
NoValidTxsError,
|
|
35
|
+
type PublicProcessorLimits,
|
|
36
|
+
type ResolvedSequencerConfig,
|
|
37
|
+
type WorldStateSynchronizer,
|
|
27
38
|
} from '@aztec/stdlib/interfaces/server';
|
|
28
|
-
import type
|
|
29
|
-
import type {
|
|
30
|
-
import { orderAttestations } from '@aztec/stdlib/p2p';
|
|
31
|
-
import { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
39
|
+
import { type L1ToL2MessageSource, computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
|
|
40
|
+
import type { BlockProposalOptions, CheckpointProposal, CheckpointProposalOptions } from '@aztec/stdlib/p2p';
|
|
41
|
+
import { orderAttestations, trimAttestations } from '@aztec/stdlib/p2p';
|
|
32
42
|
import type { L2BlockBuiltStats } from '@aztec/stdlib/stats';
|
|
33
43
|
import { type FailedTx, Tx } from '@aztec/stdlib/tx';
|
|
34
44
|
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
35
|
-
import type
|
|
45
|
+
import { Attributes, type Traceable, type Tracer, trackSpan } from '@aztec/telemetry-client';
|
|
46
|
+
import { CheckpointBuilder, type FullNodeCheckpointsBuilder, type ValidatorClient } from '@aztec/validator-client';
|
|
47
|
+
import { DutyAlreadySignedError, SlashingProtectionError } from '@aztec/validator-ha-signer/errors';
|
|
36
48
|
|
|
37
49
|
import type { GlobalVariableBuilder } from '../global_variable_builder/global_builder.js';
|
|
38
|
-
import type {
|
|
39
|
-
import { CheckpointBuilder, type FullNodeCheckpointsBuilder } from './checkpoint_builder.js';
|
|
50
|
+
import type { InvalidateCheckpointRequest, SequencerPublisher } from '../publisher/sequencer-publisher.js';
|
|
40
51
|
import { CheckpointVoter } from './checkpoint_voter.js';
|
|
41
52
|
import { SequencerInterruptedError } from './errors.js';
|
|
42
53
|
import type { SequencerEvents } from './events.js';
|
|
@@ -54,8 +65,11 @@ const TXS_POLLING_MS = 500;
|
|
|
54
65
|
* as well as enqueueing votes for slashing and governance proposals. This class is created from
|
|
55
66
|
* the Sequencer once the check for being the proposer for the slot has succeeded.
|
|
56
67
|
*/
|
|
57
|
-
export class CheckpointProposalJob {
|
|
68
|
+
export class CheckpointProposalJob implements Traceable {
|
|
69
|
+
protected readonly log: Logger;
|
|
70
|
+
|
|
58
71
|
constructor(
|
|
72
|
+
private readonly epoch: EpochNumber,
|
|
59
73
|
private readonly slot: SlotNumber,
|
|
60
74
|
private readonly checkpointNumber: CheckpointNumber,
|
|
61
75
|
private readonly syncedToBlockNumber: BlockNumber,
|
|
@@ -63,13 +77,15 @@ export class CheckpointProposalJob {
|
|
|
63
77
|
private readonly proposer: EthAddress | undefined,
|
|
64
78
|
private readonly publisher: SequencerPublisher,
|
|
65
79
|
private readonly attestorAddress: EthAddress,
|
|
66
|
-
private readonly
|
|
80
|
+
private readonly invalidateCheckpoint: InvalidateCheckpointRequest | undefined,
|
|
67
81
|
private readonly validatorClient: ValidatorClient,
|
|
68
82
|
private readonly globalsBuilder: GlobalVariableBuilder,
|
|
69
83
|
private readonly p2pClient: P2P,
|
|
70
84
|
private readonly worldState: WorldStateSynchronizer,
|
|
71
85
|
private readonly l1ToL2MessageSource: L1ToL2MessageSource,
|
|
86
|
+
private readonly l2BlockSource: L2BlockSource,
|
|
72
87
|
private readonly checkpointsBuilder: FullNodeCheckpointsBuilder,
|
|
88
|
+
private readonly blockSink: L2BlockSink,
|
|
73
89
|
private readonly l1Constants: SequencerRollupConstants,
|
|
74
90
|
protected config: ResolvedSequencerConfig,
|
|
75
91
|
protected timetable: SequencerTimetable,
|
|
@@ -79,13 +95,17 @@ export class CheckpointProposalJob {
|
|
|
79
95
|
private readonly metrics: SequencerMetrics,
|
|
80
96
|
private readonly eventEmitter: TypedEventEmitter<SequencerEvents>,
|
|
81
97
|
private readonly setStateFn: (state: SequencerState, slot?: SlotNumber) => void,
|
|
82
|
-
|
|
83
|
-
|
|
98
|
+
public readonly tracer: Tracer,
|
|
99
|
+
bindings?: LoggerBindings,
|
|
100
|
+
) {
|
|
101
|
+
this.log = createLogger('sequencer:checkpoint-proposal', { ...bindings, instanceId: `slot-${slot}` });
|
|
102
|
+
}
|
|
84
103
|
|
|
85
104
|
/**
|
|
86
105
|
* Executes the checkpoint proposal job.
|
|
87
106
|
* Returns the published checkpoint if successful, undefined otherwise.
|
|
88
107
|
*/
|
|
108
|
+
@trackSpan('CheckpointProposalJob.execute')
|
|
89
109
|
public async execute(): Promise<Checkpoint | undefined> {
|
|
90
110
|
// Enqueue governance and slashing votes (returns promises that will be awaited later)
|
|
91
111
|
// In fisherman mode, we simulate slashing but don't actually publish to L1
|
|
@@ -108,6 +128,10 @@ export class CheckpointProposalJob {
|
|
|
108
128
|
// Wait until the voting promises have resolved, so all requests are enqueued (not sent)
|
|
109
129
|
await Promise.all(votesPromises);
|
|
110
130
|
|
|
131
|
+
if (checkpoint) {
|
|
132
|
+
this.metrics.recordCheckpointProposalSuccess();
|
|
133
|
+
}
|
|
134
|
+
|
|
111
135
|
// Do not post anything to L1 if we are fishermen, but do perform L1 fee analysis
|
|
112
136
|
if (this.config.fishermanMode) {
|
|
113
137
|
await this.handleCheckpointEndAsFisherman(checkpoint);
|
|
@@ -128,6 +152,13 @@ export class CheckpointProposalJob {
|
|
|
128
152
|
}
|
|
129
153
|
}
|
|
130
154
|
|
|
155
|
+
@trackSpan('CheckpointProposalJob.proposeCheckpoint', function () {
|
|
156
|
+
return {
|
|
157
|
+
// nullish operator needed for tests
|
|
158
|
+
[Attributes.COINBASE]: this.validatorClient.getCoinbaseForAttestor(this.attestorAddress)?.toString(),
|
|
159
|
+
[Attributes.SLOT_NUMBER]: this.slot,
|
|
160
|
+
};
|
|
161
|
+
})
|
|
131
162
|
private async proposeCheckpoint(): Promise<Checkpoint | undefined> {
|
|
132
163
|
try {
|
|
133
164
|
// Get operator configured coinbase and fee recipient for this attestor
|
|
@@ -138,9 +169,9 @@ export class CheckpointProposalJob {
|
|
|
138
169
|
this.setStateFn(SequencerState.INITIALIZING_CHECKPOINT, this.slot);
|
|
139
170
|
this.metrics.incOpenSlot(this.slot, this.proposer?.toString() ?? 'unknown');
|
|
140
171
|
|
|
141
|
-
// Enqueues
|
|
142
|
-
if (this.
|
|
143
|
-
this.publisher.
|
|
172
|
+
// Enqueues checkpoint invalidation (constant for the whole slot)
|
|
173
|
+
if (this.invalidateCheckpoint && !this.config.skipInvalidateBlockAsProposer) {
|
|
174
|
+
this.publisher.enqueueInvalidateCheckpoint(this.invalidateCheckpoint);
|
|
144
175
|
}
|
|
145
176
|
|
|
146
177
|
// Create checkpoint builder for the slot
|
|
@@ -150,18 +181,30 @@ export class CheckpointProposalJob {
|
|
|
150
181
|
this.slot,
|
|
151
182
|
);
|
|
152
183
|
|
|
153
|
-
// Collect L1 to L2 messages for the checkpoint
|
|
184
|
+
// Collect L1 to L2 messages for the checkpoint and compute their hash
|
|
154
185
|
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(this.checkpointNumber);
|
|
186
|
+
const inHash = computeInHashFromL1ToL2Messages(l1ToL2Messages);
|
|
187
|
+
|
|
188
|
+
// Collect the out hashes of all the checkpoints before this one in the same epoch
|
|
189
|
+
const previousCheckpointOutHashes = (await this.l2BlockSource.getCheckpointsDataForEpoch(this.epoch))
|
|
190
|
+
.filter(c => c.checkpointNumber < this.checkpointNumber)
|
|
191
|
+
.map(c => c.checkpointOutHash);
|
|
192
|
+
|
|
193
|
+
// Get the fee asset price modifier from the oracle
|
|
194
|
+
const feeAssetPriceModifier = await this.publisher.getFeeAssetPriceModifier();
|
|
155
195
|
|
|
156
196
|
// Create a long-lived forked world state for the checkpoint builder
|
|
157
|
-
using fork = await this.worldState.fork(this.syncedToBlockNumber, { closeDelayMs: 12_000 });
|
|
197
|
+
await using fork = await this.worldState.fork(this.syncedToBlockNumber, { closeDelayMs: 12_000 });
|
|
158
198
|
|
|
159
199
|
// Create checkpoint builder for the entire slot
|
|
160
200
|
const checkpointBuilder = await this.checkpointsBuilder.startCheckpoint(
|
|
161
201
|
this.checkpointNumber,
|
|
162
202
|
checkpointGlobalVariables,
|
|
203
|
+
feeAssetPriceModifier,
|
|
163
204
|
l1ToL2Messages,
|
|
205
|
+
previousCheckpointOutHashes,
|
|
164
206
|
fork,
|
|
207
|
+
this.log.getBindings(),
|
|
165
208
|
);
|
|
166
209
|
|
|
167
210
|
// Options for the validator client when creating block and checkpoint proposals
|
|
@@ -170,12 +213,34 @@ export class CheckpointProposalJob {
|
|
|
170
213
|
broadcastInvalidBlockProposal: this.config.broadcastInvalidBlockProposal,
|
|
171
214
|
};
|
|
172
215
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
216
|
+
const checkpointProposalOptions: CheckpointProposalOptions = {
|
|
217
|
+
publishFullTxs: !!this.config.publishTxsWithProposals,
|
|
218
|
+
broadcastInvalidCheckpointProposal: this.config.broadcastInvalidBlockProposal,
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
let blocksInCheckpoint: L2Block[] = [];
|
|
222
|
+
let blockPendingBroadcast: { block: L2Block; txs: Tx[] } | undefined = undefined;
|
|
223
|
+
const checkpointBuildTimer = new Timer();
|
|
224
|
+
|
|
225
|
+
try {
|
|
226
|
+
// Main loop: build blocks for the checkpoint
|
|
227
|
+
const result = await this.buildBlocksForCheckpoint(
|
|
228
|
+
checkpointBuilder,
|
|
229
|
+
checkpointGlobalVariables.timestamp,
|
|
230
|
+
inHash,
|
|
231
|
+
blockProposalOptions,
|
|
232
|
+
);
|
|
233
|
+
blocksInCheckpoint = result.blocksInCheckpoint;
|
|
234
|
+
blockPendingBroadcast = result.blockPendingBroadcast;
|
|
235
|
+
} catch (err) {
|
|
236
|
+
// These errors are expected in HA mode, so we yield and let another HA node handle the slot
|
|
237
|
+
// The only distinction between the 2 errors is SlashingProtectionError throws when the payload is different,
|
|
238
|
+
// which is normal for block building (may have picked different txs)
|
|
239
|
+
if (this.handleHASigningError(err, 'Block proposal')) {
|
|
240
|
+
return undefined;
|
|
241
|
+
}
|
|
242
|
+
throw err;
|
|
243
|
+
}
|
|
179
244
|
|
|
180
245
|
if (blocksInCheckpoint.length === 0) {
|
|
181
246
|
this.log.warn(`No blocks were built for slot ${this.slot}`, { slot: this.slot });
|
|
@@ -183,11 +248,28 @@ export class CheckpointProposalJob {
|
|
|
183
248
|
return undefined;
|
|
184
249
|
}
|
|
185
250
|
|
|
251
|
+
const minBlocksForCheckpoint = this.config.minBlocksForCheckpoint;
|
|
252
|
+
if (minBlocksForCheckpoint !== undefined && blocksInCheckpoint.length < minBlocksForCheckpoint) {
|
|
253
|
+
this.log.warn(
|
|
254
|
+
`Checkpoint has fewer blocks than minimum (${blocksInCheckpoint.length} < ${minBlocksForCheckpoint}), skipping proposal`,
|
|
255
|
+
{ slot: this.slot, blocksBuilt: blocksInCheckpoint.length, minBlocksForCheckpoint },
|
|
256
|
+
);
|
|
257
|
+
return undefined;
|
|
258
|
+
}
|
|
259
|
+
|
|
186
260
|
// Assemble and broadcast the checkpoint proposal, including the last block that was not
|
|
187
261
|
// broadcasted yet, and wait to collect the committee attestations.
|
|
188
262
|
this.setStateFn(SequencerState.ASSEMBLING_CHECKPOINT, this.slot);
|
|
189
263
|
const checkpoint = await checkpointBuilder.completeCheckpoint();
|
|
190
264
|
|
|
265
|
+
// Record checkpoint-level build metrics
|
|
266
|
+
this.metrics.recordCheckpointBuild(
|
|
267
|
+
checkpointBuildTimer.ms(),
|
|
268
|
+
blocksInCheckpoint.length,
|
|
269
|
+
checkpoint.getStats().txCount,
|
|
270
|
+
Number(checkpoint.header.totalManaUsed.toBigInt()),
|
|
271
|
+
);
|
|
272
|
+
|
|
191
273
|
// Do not collect attestations nor publish to L1 in fisherman mode
|
|
192
274
|
if (this.config.fishermanMode) {
|
|
193
275
|
this.log.info(
|
|
@@ -203,39 +285,83 @@ export class CheckpointProposalJob {
|
|
|
203
285
|
return checkpoint;
|
|
204
286
|
}
|
|
205
287
|
|
|
206
|
-
//
|
|
288
|
+
// Include the block pending broadcast in the checkpoint proposal if any
|
|
289
|
+
const lastBlock = blockPendingBroadcast && {
|
|
290
|
+
blockHeader: blockPendingBroadcast.block.header,
|
|
291
|
+
indexWithinCheckpoint: blockPendingBroadcast.block.indexWithinCheckpoint,
|
|
292
|
+
txs: blockPendingBroadcast.txs,
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
// Create the checkpoint proposal and broadcast it
|
|
207
296
|
const proposal = await this.validatorClient.createCheckpointProposal(
|
|
208
297
|
checkpoint.header,
|
|
209
298
|
checkpoint.archive.root,
|
|
210
|
-
|
|
299
|
+
feeAssetPriceModifier,
|
|
300
|
+
lastBlock,
|
|
211
301
|
this.proposer,
|
|
212
|
-
|
|
302
|
+
checkpointProposalOptions,
|
|
213
303
|
);
|
|
304
|
+
|
|
214
305
|
const blockProposedAt = this.dateProvider.now();
|
|
215
|
-
await this.p2pClient.
|
|
306
|
+
await this.p2pClient.broadcastCheckpointProposal(proposal);
|
|
216
307
|
|
|
217
308
|
this.setStateFn(SequencerState.COLLECTING_ATTESTATIONS, this.slot);
|
|
218
309
|
const attestations = await this.waitForAttestations(proposal);
|
|
219
310
|
const blockAttestedAt = this.dateProvider.now();
|
|
220
311
|
|
|
221
|
-
this.metrics.
|
|
312
|
+
this.metrics.recordCheckpointAttestationDelay(blockAttestedAt - blockProposedAt);
|
|
222
313
|
|
|
223
314
|
// Proposer must sign over the attestations before pushing them to L1
|
|
224
315
|
const signer = this.proposer ?? this.publisher.getSenderAddress();
|
|
225
|
-
|
|
316
|
+
let attestationsSignature: Signature;
|
|
317
|
+
try {
|
|
318
|
+
attestationsSignature = await this.validatorClient.signAttestationsAndSigners(
|
|
319
|
+
attestations,
|
|
320
|
+
signer,
|
|
321
|
+
this.slot,
|
|
322
|
+
this.checkpointNumber,
|
|
323
|
+
);
|
|
324
|
+
} catch (err) {
|
|
325
|
+
// We shouldn't really get here since we yield to another HA node
|
|
326
|
+
// as soon as we see these errors when creating block or checkpoint proposals.
|
|
327
|
+
if (this.handleHASigningError(err, 'Attestations signature')) {
|
|
328
|
+
return undefined;
|
|
329
|
+
}
|
|
330
|
+
throw err;
|
|
331
|
+
}
|
|
226
332
|
|
|
227
333
|
// Enqueue publishing the checkpoint to L1
|
|
228
334
|
this.setStateFn(SequencerState.PUBLISHING_CHECKPOINT, this.slot);
|
|
229
335
|
const aztecSlotDuration = this.l1Constants.slotDuration;
|
|
230
336
|
const slotStartBuildTimestamp = this.getSlotStartBuildTimestamp();
|
|
231
337
|
const txTimeoutAt = new Date((slotStartBuildTimestamp + aztecSlotDuration) * 1000);
|
|
338
|
+
|
|
339
|
+
// If we have been configured to potentially skip publishing checkpoint then roll the dice here
|
|
340
|
+
if (
|
|
341
|
+
this.config.skipPublishingCheckpointsPercent !== undefined &&
|
|
342
|
+
this.config.skipPublishingCheckpointsPercent > 0
|
|
343
|
+
) {
|
|
344
|
+
const result = Math.max(0, randomInt(100));
|
|
345
|
+
if (result < this.config.skipPublishingCheckpointsPercent) {
|
|
346
|
+
this.log.warn(
|
|
347
|
+
`Skipping publishing proposal for checkpoint ${checkpoint.number}. Configured percentage: ${this.config.skipPublishingCheckpointsPercent}, generated value: ${result}`,
|
|
348
|
+
);
|
|
349
|
+
return checkpoint;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
232
353
|
await this.publisher.enqueueProposeCheckpoint(checkpoint, attestations, attestationsSignature, {
|
|
233
354
|
txTimeoutAt,
|
|
234
|
-
|
|
355
|
+
forcePendingCheckpointNumber: this.invalidateCheckpoint?.forcePendingCheckpointNumber,
|
|
235
356
|
});
|
|
236
357
|
|
|
237
358
|
return checkpoint;
|
|
238
359
|
} catch (err) {
|
|
360
|
+
if (err && (err instanceof DutyAlreadySignedError || err instanceof SlashingProtectionError)) {
|
|
361
|
+
// swallow this error. It's already been logged by a function deeper in the stack
|
|
362
|
+
return undefined;
|
|
363
|
+
}
|
|
364
|
+
|
|
239
365
|
this.log.error(`Error building checkpoint at slot ${this.slot}`, err);
|
|
240
366
|
return undefined;
|
|
241
367
|
}
|
|
@@ -244,24 +370,29 @@ export class CheckpointProposalJob {
|
|
|
244
370
|
/**
|
|
245
371
|
* Builds blocks for a checkpoint within the current slot.
|
|
246
372
|
*/
|
|
373
|
+
@trackSpan('CheckpointProposalJob.buildBlocksForCheckpoint')
|
|
247
374
|
private async buildBlocksForCheckpoint(
|
|
248
375
|
checkpointBuilder: CheckpointBuilder,
|
|
249
376
|
timestamp: bigint,
|
|
377
|
+
inHash: Fr,
|
|
250
378
|
blockProposalOptions: BlockProposalOptions,
|
|
251
379
|
): Promise<{
|
|
252
|
-
blocksInCheckpoint:
|
|
253
|
-
|
|
380
|
+
blocksInCheckpoint: L2Block[];
|
|
381
|
+
blockPendingBroadcast: { block: L2Block; txs: Tx[] } | undefined;
|
|
254
382
|
}> {
|
|
255
|
-
const blocksInCheckpoint:
|
|
383
|
+
const blocksInCheckpoint: L2Block[] = [];
|
|
256
384
|
const txHashesAlreadyIncluded = new Set<string>();
|
|
257
385
|
const initialBlockNumber = BlockNumber(this.syncedToBlockNumber + 1);
|
|
258
386
|
|
|
387
|
+
// Remaining blob fields available for blocks (checkpoint end marker already subtracted)
|
|
388
|
+
let remainingBlobFields = BLOBS_PER_CHECKPOINT * FIELDS_PER_BLOB - NUM_CHECKPOINT_END_MARKER_FIELDS;
|
|
389
|
+
|
|
259
390
|
// Last block in the checkpoint will usually be flagged as pending broadcast, so we send it along with the checkpoint proposal
|
|
260
|
-
let
|
|
391
|
+
let blockPendingBroadcast: { block: L2Block; txs: Tx[] } | undefined = undefined;
|
|
261
392
|
|
|
262
393
|
while (true) {
|
|
263
394
|
const blocksBuilt = blocksInCheckpoint.length;
|
|
264
|
-
const indexWithinCheckpoint = blocksBuilt;
|
|
395
|
+
const indexWithinCheckpoint = IndexWithinCheckpoint(blocksBuilt);
|
|
265
396
|
const blockNumber = BlockNumber(initialBlockNumber + blocksBuilt);
|
|
266
397
|
|
|
267
398
|
const secondsIntoSlot = this.getSecondsIntoSlot();
|
|
@@ -288,8 +419,10 @@ export class CheckpointProposalJob {
|
|
|
288
419
|
blockNumber,
|
|
289
420
|
indexWithinCheckpoint,
|
|
290
421
|
txHashesAlreadyIncluded,
|
|
422
|
+
remainingBlobFields,
|
|
291
423
|
});
|
|
292
424
|
|
|
425
|
+
// TODO(palla/mbps): Review these conditions. We may want to keep trying in some scenarios.
|
|
293
426
|
if (!buildResult && timingInfo.isLastBlock) {
|
|
294
427
|
// If no block was produced due to not enough txs and this was the last subslot, exit
|
|
295
428
|
break;
|
|
@@ -312,13 +445,21 @@ export class CheckpointProposalJob {
|
|
|
312
445
|
break;
|
|
313
446
|
}
|
|
314
447
|
|
|
315
|
-
const { block, usedTxs } = buildResult;
|
|
448
|
+
const { block, usedTxs, remainingBlobFields: newRemainingBlobFields } = buildResult;
|
|
316
449
|
blocksInCheckpoint.push(block);
|
|
317
450
|
|
|
451
|
+
// Update remaining blob fields for the next block
|
|
452
|
+
remainingBlobFields = newRemainingBlobFields;
|
|
453
|
+
|
|
318
454
|
// Sync the proposed block to the archiver to make it available
|
|
319
455
|
// Note that the checkpoint builder uses its own fork so it should not need to wait for this syncing
|
|
320
456
|
// Eventually we should refactor the checkpoint builder to not need a separate long-lived fork
|
|
321
|
-
|
|
457
|
+
// Fire and forget - don't block the critical path, but log errors
|
|
458
|
+
this.syncProposedBlockToArchiver(block).catch(err => {
|
|
459
|
+
this.log.error(`Failed to sync proposed block ${block.number} to archiver`, { blockNumber: block.number, err });
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
usedTxs.forEach(tx => txHashesAlreadyIncluded.add(tx.txHash.toString()));
|
|
322
463
|
|
|
323
464
|
// If this is the last block, exit the loop now so we start collecting attestations
|
|
324
465
|
if (timingInfo.isLastBlock) {
|
|
@@ -327,17 +468,17 @@ export class CheckpointProposalJob {
|
|
|
327
468
|
blockNumber,
|
|
328
469
|
blocksBuilt,
|
|
329
470
|
});
|
|
330
|
-
|
|
471
|
+
blockPendingBroadcast = { block, txs: usedTxs };
|
|
331
472
|
break;
|
|
332
473
|
}
|
|
333
474
|
|
|
334
475
|
// For non-last blocks, broadcast the block proposal (unless we're in fisherman mode)
|
|
335
476
|
// If the block is the last one, we'll broadcast it along with the checkpoint at the end of the loop
|
|
336
477
|
if (!this.config.fishermanMode) {
|
|
337
|
-
// TODO(palla/mbps): Wire this to the new p2p API once available
|
|
338
478
|
const proposal = await this.validatorClient.createBlockProposal(
|
|
339
|
-
block.header
|
|
340
|
-
|
|
479
|
+
block.header,
|
|
480
|
+
block.indexWithinCheckpoint,
|
|
481
|
+
inHash,
|
|
341
482
|
block.archive.root,
|
|
342
483
|
usedTxs,
|
|
343
484
|
this.proposer,
|
|
@@ -355,13 +496,11 @@ export class CheckpointProposalJob {
|
|
|
355
496
|
blocksBuilt: blocksInCheckpoint.length,
|
|
356
497
|
});
|
|
357
498
|
|
|
358
|
-
return {
|
|
359
|
-
blocksInCheckpoint,
|
|
360
|
-
pendingBroadcast,
|
|
361
|
-
};
|
|
499
|
+
return { blocksInCheckpoint, blockPendingBroadcast };
|
|
362
500
|
}
|
|
363
501
|
|
|
364
502
|
/** Sleeps until it is time to produce the next block in the slot */
|
|
503
|
+
@trackSpan('CheckpointProposalJob.waitUntilNextSubslot')
|
|
365
504
|
private async waitUntilNextSubslot(nextSubslotStart: number) {
|
|
366
505
|
this.setStateFn(SequencerState.WAITING_UNTIL_NEXT_BLOCK, this.slot);
|
|
367
506
|
this.log.verbose(`Waiting until time for the next block at ${nextSubslotStart}s into slot`, { slot: this.slot });
|
|
@@ -369,19 +508,28 @@ export class CheckpointProposalJob {
|
|
|
369
508
|
}
|
|
370
509
|
|
|
371
510
|
/** Builds a single block. Called from the main block building loop. */
|
|
372
|
-
|
|
511
|
+
@trackSpan('CheckpointProposalJob.buildSingleBlock')
|
|
512
|
+
protected async buildSingleBlock(
|
|
373
513
|
checkpointBuilder: CheckpointBuilder,
|
|
374
514
|
opts: {
|
|
375
515
|
forceCreate?: boolean;
|
|
376
516
|
blockTimestamp: bigint;
|
|
377
517
|
blockNumber: BlockNumber;
|
|
378
|
-
indexWithinCheckpoint:
|
|
518
|
+
indexWithinCheckpoint: IndexWithinCheckpoint;
|
|
379
519
|
buildDeadline: Date | undefined;
|
|
380
520
|
txHashesAlreadyIncluded: Set<string>;
|
|
521
|
+
remainingBlobFields: number;
|
|
381
522
|
},
|
|
382
|
-
): Promise<{ block:
|
|
383
|
-
const {
|
|
384
|
-
|
|
523
|
+
): Promise<{ block: L2Block; usedTxs: Tx[]; remainingBlobFields: number } | { error: Error } | undefined> {
|
|
524
|
+
const {
|
|
525
|
+
blockTimestamp,
|
|
526
|
+
forceCreate,
|
|
527
|
+
blockNumber,
|
|
528
|
+
indexWithinCheckpoint,
|
|
529
|
+
buildDeadline,
|
|
530
|
+
txHashesAlreadyIncluded,
|
|
531
|
+
remainingBlobFields,
|
|
532
|
+
} = opts;
|
|
385
533
|
|
|
386
534
|
this.log.verbose(
|
|
387
535
|
`Preparing block ${blockNumber} index ${indexWithinCheckpoint} at checkpoint ${this.checkpointNumber} for slot ${this.slot}`,
|
|
@@ -405,7 +553,7 @@ export class CheckpointProposalJob {
|
|
|
405
553
|
// Create iterator to pending txs. We filter out txs already included in previous blocks in the checkpoint
|
|
406
554
|
// just in case p2p failed to sync the provisional block and didn't get to remove those txs from the mempool yet.
|
|
407
555
|
const pendingTxs = filter(
|
|
408
|
-
this.p2pClient.
|
|
556
|
+
this.p2pClient.iterateEligiblePendingTxs(),
|
|
409
557
|
tx => !txHashesAlreadyIncluded.has(tx.txHash.toString()),
|
|
410
558
|
);
|
|
411
559
|
|
|
@@ -414,46 +562,52 @@ export class CheckpointProposalJob {
|
|
|
414
562
|
{ slot: this.slot, blockNumber, indexWithinCheckpoint },
|
|
415
563
|
);
|
|
416
564
|
this.setStateFn(SequencerState.CREATING_BLOCK, this.slot);
|
|
565
|
+
|
|
566
|
+
// Calculate blob fields limit for txs (remaining capacity - this block's end overhead)
|
|
567
|
+
const blockEndOverhead = getNumBlockEndBlobFields(indexWithinCheckpoint === 0);
|
|
568
|
+
const maxBlobFieldsForTxs = remainingBlobFields - blockEndOverhead;
|
|
569
|
+
|
|
417
570
|
const blockBuilderOptions: PublicProcessorLimits = {
|
|
418
571
|
maxTransactions: this.config.maxTxsPerBlock,
|
|
419
572
|
maxBlockSize: this.config.maxBlockSizeInBytes,
|
|
420
573
|
maxBlockGas: new Gas(this.config.maxDABlockGas, this.config.maxL2BlockGas),
|
|
421
|
-
maxBlobFields:
|
|
574
|
+
maxBlobFields: maxBlobFieldsForTxs,
|
|
422
575
|
deadline: buildDeadline,
|
|
423
576
|
};
|
|
424
577
|
|
|
425
578
|
// Actually build the block by executing txs
|
|
426
|
-
const
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
579
|
+
const buildResult = await this.buildSingleBlockWithCheckpointBuilder(
|
|
580
|
+
checkpointBuilder,
|
|
581
|
+
pendingTxs,
|
|
582
|
+
blockNumber,
|
|
583
|
+
blockTimestamp,
|
|
584
|
+
blockBuilderOptions,
|
|
585
|
+
);
|
|
430
586
|
|
|
431
587
|
// If any txs failed during execution, drop them from the mempool so we don't pick them up again
|
|
432
|
-
await this.dropFailedTxsFromP2P(failedTxs);
|
|
588
|
+
await this.dropFailedTxsFromP2P(buildResult.failedTxs);
|
|
433
589
|
|
|
434
590
|
// Check if we have created a block with enough txs. If there were invalid txs in the pool, or if execution took
|
|
435
591
|
// too long, then we may not get to minTxsPerBlock after executing public functions.
|
|
436
592
|
const minValidTxs = this.config.minValidTxsPerBlock ?? minTxs;
|
|
437
|
-
|
|
593
|
+
const numTxs = buildResult.status === 'no-valid-txs' ? 0 : buildResult.numTxs;
|
|
594
|
+
if (buildResult.status === 'no-valid-txs' || (!forceCreate && numTxs < minValidTxs)) {
|
|
438
595
|
this.log.warn(
|
|
439
|
-
`Block ${blockNumber} at index ${indexWithinCheckpoint} on slot ${this.slot} has too few valid txs to be proposed
|
|
440
|
-
{ slot: this.slot, blockNumber, numTxs, indexWithinCheckpoint },
|
|
596
|
+
`Block ${blockNumber} at index ${indexWithinCheckpoint} on slot ${this.slot} has too few valid txs to be proposed`,
|
|
597
|
+
{ slot: this.slot, blockNumber, numTxs, indexWithinCheckpoint, minValidTxs, buildResult: buildResult.status },
|
|
441
598
|
);
|
|
442
|
-
this.eventEmitter.emit('block-
|
|
443
|
-
minTxs: minValidTxs,
|
|
444
|
-
availableTxs: numTxs,
|
|
445
|
-
slot: this.slot,
|
|
446
|
-
});
|
|
599
|
+
this.eventEmitter.emit('block-build-failed', { reason: `Insufficient valid txs`, slot: this.slot });
|
|
447
600
|
this.metrics.recordBlockProposalFailed('insufficient_valid_txs');
|
|
448
601
|
return undefined;
|
|
449
602
|
}
|
|
450
603
|
|
|
451
604
|
// Block creation succeeded, emit stats and metrics
|
|
605
|
+
const { publicGas, block, publicProcessorDuration, usedTxs, usedTxBlobFields, blockBuildDuration } = buildResult;
|
|
606
|
+
|
|
452
607
|
const blockStats = {
|
|
453
608
|
eventName: 'l2-block-built',
|
|
454
609
|
duration: blockBuildDuration,
|
|
455
610
|
publicProcessDuration: publicProcessorDuration,
|
|
456
|
-
rollupCircuitsDuration: blockBuildingTimer.ms(),
|
|
457
611
|
...block.getStats(),
|
|
458
612
|
} satisfies L2BlockBuiltStats;
|
|
459
613
|
|
|
@@ -469,7 +623,7 @@ export class CheckpointProposalJob {
|
|
|
469
623
|
this.eventEmitter.emit('block-proposed', { blockNumber: block.number, slot: this.slot });
|
|
470
624
|
this.metrics.recordBuiltBlock(blockBuildDuration, publicGas.l2Gas);
|
|
471
625
|
|
|
472
|
-
return { block, usedTxs };
|
|
626
|
+
return { block, usedTxs, remainingBlobFields: maxBlobFieldsForTxs - usedTxBlobFields };
|
|
473
627
|
} catch (err: any) {
|
|
474
628
|
this.eventEmitter.emit('block-build-failed', { reason: err.message, slot: this.slot });
|
|
475
629
|
this.log.error(`Error building block`, err, { blockNumber, slot: this.slot });
|
|
@@ -479,16 +633,40 @@ export class CheckpointProposalJob {
|
|
|
479
633
|
}
|
|
480
634
|
}
|
|
481
635
|
|
|
636
|
+
/** Uses the checkpoint builder to build a block, catching specific txs */
|
|
637
|
+
private async buildSingleBlockWithCheckpointBuilder(
|
|
638
|
+
checkpointBuilder: CheckpointBuilder,
|
|
639
|
+
pendingTxs: AsyncIterable<Tx>,
|
|
640
|
+
blockNumber: BlockNumber,
|
|
641
|
+
blockTimestamp: bigint,
|
|
642
|
+
blockBuilderOptions: PublicProcessorLimits,
|
|
643
|
+
) {
|
|
644
|
+
try {
|
|
645
|
+
const workTimer = new Timer();
|
|
646
|
+
const result = await checkpointBuilder.buildBlock(pendingTxs, blockNumber, blockTimestamp, blockBuilderOptions);
|
|
647
|
+
const blockBuildDuration = workTimer.ms();
|
|
648
|
+
return { ...result, blockBuildDuration, status: 'success' as const };
|
|
649
|
+
} catch (err: unknown) {
|
|
650
|
+
if (isErrorClass(err, NoValidTxsError)) {
|
|
651
|
+
return { failedTxs: err.failedTxs, status: 'no-valid-txs' as const };
|
|
652
|
+
}
|
|
653
|
+
throw err;
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
|
|
482
657
|
/** Waits until minTxs are available on the pool for building a block. */
|
|
658
|
+
@trackSpan('CheckpointProposalJob.waitForMinTxs')
|
|
483
659
|
private async waitForMinTxs(opts: {
|
|
484
660
|
forceCreate?: boolean;
|
|
485
661
|
blockNumber: BlockNumber;
|
|
486
|
-
indexWithinCheckpoint:
|
|
662
|
+
indexWithinCheckpoint: IndexWithinCheckpoint;
|
|
487
663
|
buildDeadline: Date | undefined;
|
|
488
664
|
}): Promise<{ canStartBuilding: boolean; availableTxs: number }> {
|
|
489
|
-
const minTxs = this.config.minTxsPerBlock;
|
|
490
665
|
const { indexWithinCheckpoint, blockNumber, buildDeadline, forceCreate } = opts;
|
|
491
666
|
|
|
667
|
+
// We only allow a block with 0 txs in the first block of the checkpoint
|
|
668
|
+
const minTxs = indexWithinCheckpoint > 0 && this.config.minTxsPerBlock === 0 ? 1 : this.config.minTxsPerBlock;
|
|
669
|
+
|
|
492
670
|
// Deadline is undefined if we are not enforcing the timetable, meaning we'll exit immediately when out of time
|
|
493
671
|
const startBuildingDeadline = buildDeadline
|
|
494
672
|
? new Date(buildDeadline.getTime() - this.timetable.minExecutionTime * 1000)
|
|
@@ -509,7 +687,7 @@ export class CheckpointProposalJob {
|
|
|
509
687
|
`Waiting for enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.slot} (have ${availableTxs} but need ${minTxs})`,
|
|
510
688
|
{ blockNumber, slot: this.slot, indexWithinCheckpoint },
|
|
511
689
|
);
|
|
512
|
-
await
|
|
690
|
+
await this.waitForTxsPollingInterval();
|
|
513
691
|
availableTxs = await this.p2pClient.getPendingTxCount();
|
|
514
692
|
}
|
|
515
693
|
|
|
@@ -520,7 +698,8 @@ export class CheckpointProposalJob {
|
|
|
520
698
|
* Waits for enough attestations to be collected via p2p.
|
|
521
699
|
* This is run after all blocks for the checkpoint have been built.
|
|
522
700
|
*/
|
|
523
|
-
|
|
701
|
+
@trackSpan('CheckpointProposalJob.waitForAttestations')
|
|
702
|
+
private async waitForAttestations(proposal: CheckpointProposal): Promise<CommitteeAttestationsAndSigners> {
|
|
524
703
|
if (this.config.fishermanMode) {
|
|
525
704
|
this.log.debug('Skipping attestation collection in fisherman mode');
|
|
526
705
|
return CommitteeAttestationsAndSigners.empty();
|
|
@@ -549,7 +728,7 @@ export class CheckpointProposalJob {
|
|
|
549
728
|
const attestationTimeAllowed = this.config.enforceTimeTable
|
|
550
729
|
? this.timetable.getMaxAllowedTime(SequencerState.PUBLISHING_CHECKPOINT)!
|
|
551
730
|
: this.l1Constants.slotDuration;
|
|
552
|
-
const attestationDeadline = new Date(this.
|
|
731
|
+
const attestationDeadline = new Date((this.getSlotStartBuildTimestamp() + attestationTimeAllowed) * 1000);
|
|
553
732
|
|
|
554
733
|
this.metrics.recordRequiredAttestations(numberOfRequiredAttestations, attestationTimeAllowed);
|
|
555
734
|
|
|
@@ -564,13 +743,24 @@ export class CheckpointProposalJob {
|
|
|
564
743
|
|
|
565
744
|
collectedAttestationsCount = attestations.length;
|
|
566
745
|
|
|
746
|
+
// Trim attestations to minimum required to save L1 calldata gas
|
|
747
|
+
const localAddresses = this.validatorClient.getValidatorAddresses();
|
|
748
|
+
const trimmed = trimAttestations(
|
|
749
|
+
attestations,
|
|
750
|
+
numberOfRequiredAttestations,
|
|
751
|
+
this.attestorAddress,
|
|
752
|
+
localAddresses,
|
|
753
|
+
);
|
|
754
|
+
if (trimmed.length < attestations.length) {
|
|
755
|
+
this.log.debug(`Trimmed attestations from ${attestations.length} to ${trimmed.length} for L1 submission`);
|
|
756
|
+
}
|
|
757
|
+
|
|
567
758
|
// Rollup contract requires that the signatures are provided in the order of the committee
|
|
568
|
-
const sorted = orderAttestations(
|
|
759
|
+
const sorted = orderAttestations(trimmed, committee);
|
|
569
760
|
|
|
570
761
|
// Manipulate the attestations if we've been configured to do so
|
|
571
762
|
if (this.config.injectFakeAttestation || this.config.shuffleAttestationOrdering) {
|
|
572
|
-
|
|
573
|
-
return this.manipulateAttestations(checkpoint, epoch, seed, committee, sorted);
|
|
763
|
+
return this.manipulateAttestations(proposal.slotNumber, epoch, seed, committee, sorted);
|
|
574
764
|
}
|
|
575
765
|
|
|
576
766
|
return new CommitteeAttestationsAndSigners(sorted);
|
|
@@ -586,7 +776,7 @@ export class CheckpointProposalJob {
|
|
|
586
776
|
|
|
587
777
|
/** Breaks the attestations before publishing based on attack configs */
|
|
588
778
|
private manipulateAttestations(
|
|
589
|
-
|
|
779
|
+
slotNumber: SlotNumber,
|
|
590
780
|
epoch: EpochNumber,
|
|
591
781
|
seed: bigint,
|
|
592
782
|
committee: EthAddress[],
|
|
@@ -594,7 +784,6 @@ export class CheckpointProposalJob {
|
|
|
594
784
|
) {
|
|
595
785
|
// Compute the proposer index in the committee, since we dont want to tweak it.
|
|
596
786
|
// Otherwise, the L1 rollup contract will reject the block outright.
|
|
597
|
-
const { slotNumber } = checkpoint;
|
|
598
787
|
const proposerIndex = Number(
|
|
599
788
|
this.epochCache.computeProposerIndex(slotNumber, epoch, seed, BigInt(committee.length)),
|
|
600
789
|
);
|
|
@@ -639,20 +828,27 @@ export class CheckpointProposalJob {
|
|
|
639
828
|
const failedTxData = failedTxs.map(fail => fail.tx);
|
|
640
829
|
const failedTxHashes = failedTxData.map(tx => tx.getTxHash());
|
|
641
830
|
this.log.verbose(`Dropping failed txs ${failedTxHashes.join(', ')}`);
|
|
642
|
-
await this.p2pClient.
|
|
831
|
+
await this.p2pClient.handleFailedExecution(failedTxHashes);
|
|
643
832
|
}
|
|
644
833
|
|
|
645
834
|
/**
|
|
646
|
-
*
|
|
647
|
-
*
|
|
835
|
+
* Adds the proposed block to the archiver so it's available via P2P.
|
|
836
|
+
* Gossip doesn't echo messages back to the sender, so the proposer's archiver/world-state
|
|
837
|
+
* would never receive its own block without this explicit sync.
|
|
648
838
|
*/
|
|
649
|
-
private async syncProposedBlockToArchiver(block:
|
|
650
|
-
this.
|
|
839
|
+
private async syncProposedBlockToArchiver(block: L2Block): Promise<void> {
|
|
840
|
+
if (this.config.skipPushProposedBlocksToArchiver !== false) {
|
|
841
|
+
this.log.warn(`Skipping push of proposed block ${block.number} to archiver`, {
|
|
842
|
+
blockNumber: block.number,
|
|
843
|
+
slot: block.header.globalVariables.slotNumber,
|
|
844
|
+
});
|
|
845
|
+
return;
|
|
846
|
+
}
|
|
847
|
+
this.log.debug(`Syncing proposed block ${block.number} to archiver`, {
|
|
651
848
|
blockNumber: block.number,
|
|
652
849
|
slot: block.header.globalVariables.slotNumber,
|
|
653
850
|
});
|
|
654
|
-
|
|
655
|
-
await Promise.resolve();
|
|
851
|
+
await this.blockSink.addBlock(block);
|
|
656
852
|
}
|
|
657
853
|
|
|
658
854
|
/** Runs fee analysis and logs checkpoint outcome as fisherman */
|
|
@@ -669,25 +865,52 @@ export class CheckpointProposalJob {
|
|
|
669
865
|
...checkpoint.getStats(),
|
|
670
866
|
feeAnalysisId: feeAnalysis?.id,
|
|
671
867
|
});
|
|
672
|
-
this.metrics.recordBlockProposalSuccess();
|
|
673
868
|
} else {
|
|
674
869
|
this.log.warn(`Validation block building FAILED for slot ${this.slot}`, {
|
|
675
870
|
slot: this.slot,
|
|
676
871
|
feeAnalysisId: feeAnalysis?.id,
|
|
677
872
|
});
|
|
678
|
-
this.metrics.
|
|
873
|
+
this.metrics.recordCheckpointProposalFailed('block_build_failed');
|
|
679
874
|
}
|
|
680
875
|
|
|
681
876
|
this.publisher.clearPendingRequests();
|
|
682
877
|
}
|
|
683
878
|
|
|
879
|
+
/**
|
|
880
|
+
* Helper to handle HA double-signing errors. Returns true if the error was handled (caller should yield).
|
|
881
|
+
*/
|
|
882
|
+
private handleHASigningError(err: any, errorContext: string): boolean {
|
|
883
|
+
if (err instanceof DutyAlreadySignedError) {
|
|
884
|
+
this.log.info(`${errorContext} for slot ${this.slot} already signed by another HA node, yielding`, {
|
|
885
|
+
slot: this.slot,
|
|
886
|
+
signedByNode: err.signedByNode,
|
|
887
|
+
});
|
|
888
|
+
return true;
|
|
889
|
+
}
|
|
890
|
+
if (err instanceof SlashingProtectionError) {
|
|
891
|
+
this.log.info(`${errorContext} for slot ${this.slot} blocked by slashing protection, yielding`, {
|
|
892
|
+
slot: this.slot,
|
|
893
|
+
existingMessageHash: err.existingMessageHash,
|
|
894
|
+
attemptedMessageHash: err.attemptedMessageHash,
|
|
895
|
+
});
|
|
896
|
+
return true;
|
|
897
|
+
}
|
|
898
|
+
return false;
|
|
899
|
+
}
|
|
900
|
+
|
|
684
901
|
/** Waits until a specific time within the current slot */
|
|
902
|
+
@trackSpan('CheckpointProposalJob.waitUntilTimeInSlot')
|
|
685
903
|
protected async waitUntilTimeInSlot(targetSecondsIntoSlot: number): Promise<void> {
|
|
686
904
|
const slotStartTimestamp = this.getSlotStartBuildTimestamp();
|
|
687
905
|
const targetTimestamp = slotStartTimestamp + targetSecondsIntoSlot;
|
|
688
906
|
await sleepUntil(new Date(targetTimestamp * 1000), this.dateProvider.nowAsDate());
|
|
689
907
|
}
|
|
690
908
|
|
|
909
|
+
/** Waits the polling interval for transactions. Extracted for test overriding. */
|
|
910
|
+
protected async waitForTxsPollingInterval(): Promise<void> {
|
|
911
|
+
await sleep(TXS_POLLING_MS);
|
|
912
|
+
}
|
|
913
|
+
|
|
691
914
|
private getSlotStartBuildTimestamp(): number {
|
|
692
915
|
return getSlotStartBuildTimestamp(this.slot, this.l1Constants);
|
|
693
916
|
}
|