@aztec/sequencer-client 3.0.3 → 3.9.9-nightly.20260312
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 +32 -15
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +116 -27
- package/dest/config.d.ts +29 -4
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +103 -40
- package/dest/global_variable_builder/global_builder.d.ts +17 -11
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +48 -39
- 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 +33 -19
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +102 -43
- package/dest/publisher/sequencer-publisher-factory.d.ts +13 -5
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-factory.js +14 -3
- package/dest/publisher/sequencer-publisher-metrics.d.ts +3 -3
- 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 +58 -45
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +628 -139
- package/dest/sequencer/checkpoint_proposal_job.d.ts +100 -0
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_proposal_job.js +1234 -0
- package/dest/sequencer/checkpoint_voter.d.ts +35 -0
- package/dest/sequencer/checkpoint_voter.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_voter.js +109 -0
- package/dest/sequencer/events.d.ts +46 -0
- package/dest/sequencer/events.d.ts.map +1 -0
- package/dest/sequencer/events.js +1 -0
- package/dest/sequencer/index.d.ts +4 -2
- package/dest/sequencer/index.d.ts.map +1 -1
- package/dest/sequencer/index.js +3 -1
- package/dest/sequencer/metrics.d.ts +37 -5
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +216 -72
- package/dest/sequencer/sequencer.d.ts +122 -131
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +705 -635
- package/dest/sequencer/timetable.d.ts +54 -16
- package/dest/sequencer/timetable.d.ts.map +1 -1
- package/dest/sequencer/timetable.js +147 -62
- package/dest/sequencer/types.d.ts +3 -0
- package/dest/sequencer/types.d.ts.map +1 -0
- package/dest/sequencer/types.js +1 -0
- package/dest/sequencer/utils.d.ts +14 -8
- package/dest/sequencer/utils.d.ts.map +1 -1
- package/dest/sequencer/utils.js +7 -4
- package/dest/test/index.d.ts +5 -6
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.d.ts +95 -0
- package/dest/test/mock_checkpoint_builder.d.ts.map +1 -0
- package/dest/test/mock_checkpoint_builder.js +233 -0
- package/dest/test/utils.d.ts +53 -0
- package/dest/test/utils.d.ts.map +1 -0
- package/dest/test/utils.js +104 -0
- package/package.json +30 -28
- package/src/client/sequencer-client.ts +154 -45
- package/src/config.ts +119 -45
- package/src/global_variable_builder/global_builder.ts +57 -51
- package/src/index.ts +1 -7
- package/src/publisher/config.ts +115 -46
- package/src/publisher/sequencer-publisher-factory.ts +26 -9
- package/src/publisher/sequencer-publisher-metrics.ts +19 -71
- package/src/publisher/sequencer-publisher.ts +334 -176
- package/src/sequencer/README.md +531 -0
- package/src/sequencer/checkpoint_proposal_job.ts +950 -0
- package/src/sequencer/checkpoint_voter.ts +130 -0
- package/src/sequencer/events.ts +27 -0
- package/src/sequencer/index.ts +3 -1
- package/src/sequencer/metrics.ts +267 -81
- package/src/sequencer/sequencer.ts +444 -834
- package/src/sequencer/timetable.ts +178 -83
- package/src/sequencer/types.ts +6 -0
- package/src/sequencer/utils.ts +18 -9
- package/src/test/index.ts +4 -5
- package/src/test/mock_checkpoint_builder.ts +325 -0
- package/src/test/utils.ts +167 -0
- package/dest/sequencer/block_builder.d.ts +0 -28
- package/dest/sequencer/block_builder.d.ts.map +0 -1
- package/dest/sequencer/block_builder.js +0 -127
- 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 -214
- package/src/tx_validator/nullifier_cache.ts +0 -30
- package/src/tx_validator/tx_validator_factory.ts +0 -133
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { BlobClientInterface } from '@aztec/blob-client/client';
|
|
2
2
|
import { Blob, getBlobsPerL1Block, getPrefixedEthBlobCommitments } from '@aztec/blob-lib';
|
|
3
|
-
import { type BlobSinkClientInterface, createBlobSinkClient } from '@aztec/blob-sink/client';
|
|
4
3
|
import type { EpochCache } from '@aztec/epoch-cache';
|
|
5
4
|
import type { L1ContractsConfig } from '@aztec/ethereum/config';
|
|
6
5
|
import {
|
|
7
6
|
type EmpireSlashingProposerContract,
|
|
7
|
+
FeeAssetPriceOracle,
|
|
8
8
|
type GovernanceProposerContract,
|
|
9
9
|
type IEmpireBase,
|
|
10
10
|
MULTI_CALL_3_ADDRESS,
|
|
@@ -14,35 +14,40 @@ import {
|
|
|
14
14
|
type ViemCommitteeAttestations,
|
|
15
15
|
type ViemHeader,
|
|
16
16
|
} from '@aztec/ethereum/contracts';
|
|
17
|
+
import { type L1FeeAnalysisResult, L1FeeAnalyzer } from '@aztec/ethereum/l1-fee-analysis';
|
|
17
18
|
import {
|
|
18
19
|
type L1BlobInputs,
|
|
19
20
|
type L1TxConfig,
|
|
20
21
|
type L1TxRequest,
|
|
22
|
+
type L1TxUtils,
|
|
23
|
+
MAX_L1_TX_LIMIT,
|
|
21
24
|
type TransactionStats,
|
|
22
25
|
WEI_CONST,
|
|
23
26
|
} from '@aztec/ethereum/l1-tx-utils';
|
|
24
|
-
import
|
|
25
|
-
import { FormattedViemError, formatViemError, tryExtractEvent } from '@aztec/ethereum/utils';
|
|
27
|
+
import { FormattedViemError, formatViemError, mergeAbis, tryExtractEvent } from '@aztec/ethereum/utils';
|
|
26
28
|
import { sumBigint } from '@aztec/foundation/bigint';
|
|
27
29
|
import { toHex as toPaddedHex } from '@aztec/foundation/bigint-buffer';
|
|
28
|
-
import {
|
|
30
|
+
import { CheckpointNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
31
|
+
import { pick } from '@aztec/foundation/collection';
|
|
29
32
|
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
30
33
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
31
34
|
import { Signature, type ViemSignature } from '@aztec/foundation/eth-signature';
|
|
32
35
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
36
|
+
import { makeBackoff, retry } from '@aztec/foundation/retry';
|
|
33
37
|
import { bufferToHex } from '@aztec/foundation/string';
|
|
34
38
|
import { DateProvider, Timer } from '@aztec/foundation/timer';
|
|
35
39
|
import { EmpireBaseAbi, ErrorsAbi, RollupAbi } from '@aztec/l1-artifacts';
|
|
36
40
|
import { type ProposerSlashAction, encodeSlashConsensusVotes } from '@aztec/slasher';
|
|
37
|
-
import {
|
|
41
|
+
import { CommitteeAttestationsAndSigners, type ValidateCheckpointResult } from '@aztec/stdlib/block';
|
|
42
|
+
import type { Checkpoint } from '@aztec/stdlib/checkpoint';
|
|
38
43
|
import { SlashFactoryContract } from '@aztec/stdlib/l1-contracts';
|
|
39
44
|
import type { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
40
|
-
import type {
|
|
41
|
-
import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
|
|
45
|
+
import type { L1PublishCheckpointStats } from '@aztec/stdlib/stats';
|
|
46
|
+
import { type TelemetryClient, type Tracer, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
42
47
|
|
|
43
48
|
import { type StateOverride, type TransactionReceipt, type TypedDataDefinition, encodeFunctionData, toHex } from 'viem';
|
|
44
49
|
|
|
45
|
-
import type {
|
|
50
|
+
import type { SequencerPublisherConfig } from './config.js';
|
|
46
51
|
import { SequencerPublisherMetrics } from './sequencer-publisher-metrics.js';
|
|
47
52
|
|
|
48
53
|
/** Arguments to the process method of the rollup contract */
|
|
@@ -57,6 +62,8 @@ type L1ProcessArgs = {
|
|
|
57
62
|
attestationsAndSigners: CommitteeAttestationsAndSigners;
|
|
58
63
|
/** Attestations and signers signature */
|
|
59
64
|
attestationsAndSignersSignature: Signature;
|
|
65
|
+
/** The fee asset price modifier in basis points (from oracle) */
|
|
66
|
+
feeAssetPriceModifier: bigint;
|
|
60
67
|
};
|
|
61
68
|
|
|
62
69
|
export const Actions = [
|
|
@@ -78,12 +85,12 @@ type GovernanceSignalAction = Extract<Action, 'governance-signal' | 'empire-slas
|
|
|
78
85
|
// Sorting for actions such that invalidations go before proposals, and proposals go before votes
|
|
79
86
|
export const compareActions = (a: Action, b: Action) => Actions.indexOf(a) - Actions.indexOf(b);
|
|
80
87
|
|
|
81
|
-
export type
|
|
88
|
+
export type InvalidateCheckpointRequest = {
|
|
82
89
|
request: L1TxRequest;
|
|
83
90
|
reason: 'invalid-attestation' | 'insufficient-attestations';
|
|
84
91
|
gasUsed: bigint;
|
|
85
|
-
|
|
86
|
-
|
|
92
|
+
checkpointNumber: CheckpointNumber;
|
|
93
|
+
forcePendingCheckpointNumber: CheckpointNumber;
|
|
87
94
|
};
|
|
88
95
|
|
|
89
96
|
interface RequestWithExpiry {
|
|
@@ -108,17 +115,22 @@ export class SequencerPublisher {
|
|
|
108
115
|
|
|
109
116
|
protected lastActions: Partial<Record<Action, SlotNumber>> = {};
|
|
110
117
|
|
|
118
|
+
private isPayloadEmptyCache: Map<string, boolean> = new Map<string, boolean>();
|
|
119
|
+
private payloadProposedCache: Set<string> = new Set<string>();
|
|
120
|
+
|
|
111
121
|
protected log: Logger;
|
|
112
122
|
protected ethereumSlotDuration: bigint;
|
|
113
123
|
|
|
114
|
-
private
|
|
124
|
+
private blobClient: BlobClientInterface;
|
|
115
125
|
|
|
116
126
|
/** Address to use for simulations in fisherman mode (actual proposer's address) */
|
|
117
127
|
private proposerAddressForSimulation?: EthAddress;
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
128
|
+
|
|
129
|
+
/** L1 fee analyzer for fisherman mode */
|
|
130
|
+
private l1FeeAnalyzer?: L1FeeAnalyzer;
|
|
131
|
+
|
|
132
|
+
/** Fee asset price oracle for computing price modifiers from Uniswap V4 */
|
|
133
|
+
private feeAssetPriceOracle: FeeAssetPriceOracle;
|
|
122
134
|
|
|
123
135
|
// A CALL to a cold address is 2700 gas
|
|
124
136
|
public static MULTICALL_OVERHEAD_GAS_GUESS = 5000n;
|
|
@@ -126,20 +138,23 @@ export class SequencerPublisher {
|
|
|
126
138
|
// Gas report for VotingWithSigTest shows a max gas of 100k, but we've seen it cost 700k+ in testnet
|
|
127
139
|
public static VOTE_GAS_GUESS: bigint = 800_000n;
|
|
128
140
|
|
|
129
|
-
public l1TxUtils:
|
|
141
|
+
public l1TxUtils: L1TxUtils;
|
|
130
142
|
public rollupContract: RollupContract;
|
|
131
143
|
public govProposerContract: GovernanceProposerContract;
|
|
132
144
|
public slashingProposerContract: EmpireSlashingProposerContract | TallySlashingProposerContract | undefined;
|
|
133
145
|
public slashFactoryContract: SlashFactoryContract;
|
|
134
146
|
|
|
147
|
+
public readonly tracer: Tracer;
|
|
148
|
+
|
|
135
149
|
protected requests: RequestWithExpiry[] = [];
|
|
136
150
|
|
|
137
151
|
constructor(
|
|
138
|
-
private config:
|
|
152
|
+
private config: Pick<SequencerPublisherConfig, 'fishermanMode'> &
|
|
153
|
+
Pick<L1ContractsConfig, 'ethereumSlotDuration'> & { l1ChainId: number },
|
|
139
154
|
deps: {
|
|
140
155
|
telemetry?: TelemetryClient;
|
|
141
|
-
|
|
142
|
-
l1TxUtils:
|
|
156
|
+
blobClient: BlobClientInterface;
|
|
157
|
+
l1TxUtils: L1TxUtils;
|
|
143
158
|
rollupContract: RollupContract;
|
|
144
159
|
slashingProposerContract: EmpireSlashingProposerContract | TallySlashingProposerContract | undefined;
|
|
145
160
|
governanceProposerContract: GovernanceProposerContract;
|
|
@@ -156,11 +171,11 @@ export class SequencerPublisher {
|
|
|
156
171
|
this.epochCache = deps.epochCache;
|
|
157
172
|
this.lastActions = deps.lastActions;
|
|
158
173
|
|
|
159
|
-
this.
|
|
160
|
-
deps.blobSinkClient ?? createBlobSinkClient(config, { logger: createLogger('sequencer:blob-sink:client') });
|
|
174
|
+
this.blobClient = deps.blobClient;
|
|
161
175
|
|
|
162
176
|
const telemetry = deps.telemetry ?? getTelemetryClient();
|
|
163
177
|
this.metrics = deps.metrics ?? new SequencerPublisherMetrics(telemetry, 'SequencerPublisher');
|
|
178
|
+
this.tracer = telemetry.getTracer('SequencerPublisher');
|
|
164
179
|
this.l1TxUtils = deps.l1TxUtils;
|
|
165
180
|
|
|
166
181
|
this.rollupContract = deps.rollupContract;
|
|
@@ -174,16 +189,47 @@ export class SequencerPublisher {
|
|
|
174
189
|
this.slashingProposerContract = newSlashingProposer;
|
|
175
190
|
});
|
|
176
191
|
this.slashFactoryContract = deps.slashFactoryContract;
|
|
192
|
+
|
|
193
|
+
// Initialize L1 fee analyzer for fisherman mode
|
|
194
|
+
if (config.fishermanMode) {
|
|
195
|
+
this.l1FeeAnalyzer = new L1FeeAnalyzer(
|
|
196
|
+
this.l1TxUtils.client,
|
|
197
|
+
deps.dateProvider,
|
|
198
|
+
createLogger('sequencer:publisher:fee-analyzer'),
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Initialize fee asset price oracle
|
|
203
|
+
this.feeAssetPriceOracle = new FeeAssetPriceOracle(
|
|
204
|
+
this.l1TxUtils.client,
|
|
205
|
+
this.rollupContract,
|
|
206
|
+
createLogger('sequencer:publisher:price-oracle'),
|
|
207
|
+
);
|
|
177
208
|
}
|
|
178
209
|
|
|
179
210
|
public getRollupContract(): RollupContract {
|
|
180
211
|
return this.rollupContract;
|
|
181
212
|
}
|
|
182
213
|
|
|
214
|
+
/**
|
|
215
|
+
* Gets the fee asset price modifier from the oracle.
|
|
216
|
+
* Returns 0n if the oracle query fails.
|
|
217
|
+
*/
|
|
218
|
+
public getFeeAssetPriceModifier(): Promise<bigint> {
|
|
219
|
+
return this.feeAssetPriceOracle.computePriceModifier();
|
|
220
|
+
}
|
|
221
|
+
|
|
183
222
|
public getSenderAddress() {
|
|
184
223
|
return this.l1TxUtils.getSenderAddress();
|
|
185
224
|
}
|
|
186
225
|
|
|
226
|
+
/**
|
|
227
|
+
* Gets the L1 fee analyzer instance (only available in fisherman mode)
|
|
228
|
+
*/
|
|
229
|
+
public getL1FeeAnalyzer(): L1FeeAnalyzer | undefined {
|
|
230
|
+
return this.l1FeeAnalyzer;
|
|
231
|
+
}
|
|
232
|
+
|
|
187
233
|
/**
|
|
188
234
|
* Sets the proposer address to use for simulations in fisherman mode.
|
|
189
235
|
* @param proposerAddress - The actual proposer's address to use for balance lookups in simulations
|
|
@@ -211,6 +257,62 @@ export class SequencerPublisher {
|
|
|
211
257
|
}
|
|
212
258
|
}
|
|
213
259
|
|
|
260
|
+
/**
|
|
261
|
+
* Analyzes L1 fees for the pending requests without sending them.
|
|
262
|
+
* This is used in fisherman mode to validate fee calculations.
|
|
263
|
+
* @param l2SlotNumber - The L2 slot number for this analysis
|
|
264
|
+
* @param onComplete - Optional callback to invoke when analysis completes (after block is mined)
|
|
265
|
+
* @returns The analysis result (incomplete until block mines), or undefined if no requests
|
|
266
|
+
*/
|
|
267
|
+
public async analyzeL1Fees(
|
|
268
|
+
l2SlotNumber: SlotNumber,
|
|
269
|
+
onComplete?: (analysis: L1FeeAnalysisResult) => void,
|
|
270
|
+
): Promise<L1FeeAnalysisResult | undefined> {
|
|
271
|
+
if (!this.l1FeeAnalyzer) {
|
|
272
|
+
this.log.warn('L1 fee analyzer not available (not in fisherman mode)');
|
|
273
|
+
return undefined;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
const requestsToAnalyze = [...this.requests];
|
|
277
|
+
if (requestsToAnalyze.length === 0) {
|
|
278
|
+
this.log.debug('No requests to analyze for L1 fees');
|
|
279
|
+
return undefined;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// Extract blob config from requests (if any)
|
|
283
|
+
const blobConfigs = requestsToAnalyze.filter(request => request.blobConfig).map(request => request.blobConfig);
|
|
284
|
+
const blobConfig = blobConfigs[0];
|
|
285
|
+
|
|
286
|
+
// Get gas configs
|
|
287
|
+
const gasConfigs = requestsToAnalyze.filter(request => request.gasConfig).map(request => request.gasConfig);
|
|
288
|
+
const gasLimits = gasConfigs.map(g => g?.gasLimit).filter((g): g is bigint => g !== undefined);
|
|
289
|
+
const gasLimit = gasLimits.length > 0 ? gasLimits.reduce((sum, g) => sum + g, 0n) : 0n;
|
|
290
|
+
|
|
291
|
+
// Get the transaction requests
|
|
292
|
+
const l1Requests = requestsToAnalyze.map(r => r.request);
|
|
293
|
+
|
|
294
|
+
// Start the analysis
|
|
295
|
+
const analysisId = await this.l1FeeAnalyzer.startAnalysis(
|
|
296
|
+
l2SlotNumber,
|
|
297
|
+
gasLimit > 0n ? gasLimit : MAX_L1_TX_LIMIT,
|
|
298
|
+
l1Requests,
|
|
299
|
+
blobConfig,
|
|
300
|
+
onComplete,
|
|
301
|
+
);
|
|
302
|
+
|
|
303
|
+
this.log.info('Started L1 fee analysis', {
|
|
304
|
+
analysisId,
|
|
305
|
+
l2SlotNumber: l2SlotNumber.toString(),
|
|
306
|
+
requestCount: requestsToAnalyze.length,
|
|
307
|
+
hasBlobConfig: !!blobConfig,
|
|
308
|
+
gasLimit: gasLimit.toString(),
|
|
309
|
+
actions: requestsToAnalyze.map(r => r.action),
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
// Return the analysis result (will be incomplete until block mines)
|
|
313
|
+
return this.l1FeeAnalyzer.getAnalysis(analysisId);
|
|
314
|
+
}
|
|
315
|
+
|
|
214
316
|
/**
|
|
215
317
|
* Sends all requests that are still valid.
|
|
216
318
|
* @returns one of:
|
|
@@ -218,10 +320,11 @@ export class SequencerPublisher {
|
|
|
218
320
|
* - a receipt and errorMsg if it failed on L1
|
|
219
321
|
* - undefined if no valid requests are found OR the tx failed to send.
|
|
220
322
|
*/
|
|
323
|
+
@trackSpan('SequencerPublisher.sendRequests')
|
|
221
324
|
public async sendRequests() {
|
|
222
325
|
const requestsToProcess = [...this.requests];
|
|
223
326
|
this.requests = [];
|
|
224
|
-
if (this.interrupted) {
|
|
327
|
+
if (this.interrupted || requestsToProcess.length === 0) {
|
|
225
328
|
return undefined;
|
|
226
329
|
}
|
|
227
330
|
const currentL2Slot = this.getCurrentL2Slot();
|
|
@@ -264,7 +367,16 @@ export class SequencerPublisher {
|
|
|
264
367
|
|
|
265
368
|
// Merge gasConfigs. Yields the sum of gasLimits, and the earliest txTimeoutAt, or undefined if no gasConfig sets them.
|
|
266
369
|
const gasLimits = gasConfigs.map(g => g?.gasLimit).filter((g): g is bigint => g !== undefined);
|
|
267
|
-
|
|
370
|
+
let gasLimit = gasLimits.length > 0 ? sumBigint(gasLimits) : undefined; // sum
|
|
371
|
+
// Cap at L1 block gas limit so the node accepts the tx ("gas limit too high" otherwise).
|
|
372
|
+
const maxGas = MAX_L1_TX_LIMIT;
|
|
373
|
+
if (gasLimit !== undefined && gasLimit > maxGas) {
|
|
374
|
+
this.log.debug('Capping bundled tx gas limit to L1 max', {
|
|
375
|
+
requested: gasLimit,
|
|
376
|
+
capped: maxGas,
|
|
377
|
+
});
|
|
378
|
+
gasLimit = maxGas;
|
|
379
|
+
}
|
|
268
380
|
const txTimeoutAts = gasConfigs.map(g => g?.txTimeoutAt).filter((g): g is Date => g !== undefined);
|
|
269
381
|
const txTimeoutAt = txTimeoutAts.length > 0 ? new Date(Math.min(...txTimeoutAts.map(g => g.getTime()))) : undefined; // earliest
|
|
270
382
|
const txConfig: RequestWithExpiry['gasConfig'] = { gasLimit, txTimeoutAt };
|
|
@@ -335,17 +447,14 @@ export class SequencerPublisher {
|
|
|
335
447
|
public canProposeAtNextEthBlock(
|
|
336
448
|
tipArchive: Fr,
|
|
337
449
|
msgSender: EthAddress,
|
|
338
|
-
opts: {
|
|
450
|
+
opts: { forcePendingCheckpointNumber?: CheckpointNumber } = {},
|
|
339
451
|
) {
|
|
340
452
|
// TODO: #14291 - should loop through multiple keys to check if any of them can propose
|
|
341
453
|
const ignoredErrors = ['SlotAlreadyInChain', 'InvalidProposer', 'InvalidArchive'];
|
|
342
454
|
|
|
343
455
|
return this.rollupContract
|
|
344
456
|
.canProposeAtNextEthBlock(tipArchive.toBuffer(), msgSender.toString(), Number(this.ethereumSlotDuration), {
|
|
345
|
-
forcePendingCheckpointNumber:
|
|
346
|
-
opts.forcePendingBlockNumber !== undefined
|
|
347
|
-
? CheckpointNumber.fromBlockNumber(opts.forcePendingBlockNumber)
|
|
348
|
-
: undefined,
|
|
457
|
+
forcePendingCheckpointNumber: opts.forcePendingCheckpointNumber,
|
|
349
458
|
})
|
|
350
459
|
.catch(err => {
|
|
351
460
|
if (err instanceof FormattedViemError && ignoredErrors.find(e => err.message.includes(e))) {
|
|
@@ -364,10 +473,11 @@ export class SequencerPublisher {
|
|
|
364
473
|
* It will throw if the block header is invalid.
|
|
365
474
|
* @param header - The block header to validate
|
|
366
475
|
*/
|
|
476
|
+
@trackSpan('SequencerPublisher.validateBlockHeader')
|
|
367
477
|
public async validateBlockHeader(
|
|
368
478
|
header: CheckpointHeader,
|
|
369
|
-
opts?: {
|
|
370
|
-
) {
|
|
479
|
+
opts?: { forcePendingCheckpointNumber: CheckpointNumber | undefined },
|
|
480
|
+
): Promise<void> {
|
|
371
481
|
const flags = { ignoreDA: true, ignoreSignatures: true };
|
|
372
482
|
|
|
373
483
|
const args = [
|
|
@@ -376,17 +486,13 @@ export class SequencerPublisher {
|
|
|
376
486
|
[], // no signers
|
|
377
487
|
Signature.empty().toViemSignature(),
|
|
378
488
|
`0x${'0'.repeat(64)}`, // 32 empty bytes
|
|
379
|
-
header.
|
|
489
|
+
header.blobsHash.toString(),
|
|
380
490
|
flags,
|
|
381
491
|
] as const;
|
|
382
492
|
|
|
383
493
|
const ts = BigInt((await this.l1TxUtils.getBlock()).timestamp + this.ethereumSlotDuration);
|
|
384
|
-
const optsForcePendingCheckpointNumber =
|
|
385
|
-
opts?.forcePendingBlockNumber !== undefined
|
|
386
|
-
? CheckpointNumber.fromBlockNumber(opts.forcePendingBlockNumber)
|
|
387
|
-
: undefined;
|
|
388
494
|
const stateOverrides = await this.rollupContract.makePendingCheckpointNumberOverride(
|
|
389
|
-
|
|
495
|
+
opts?.forcePendingCheckpointNumber,
|
|
390
496
|
);
|
|
391
497
|
let balance = 0n;
|
|
392
498
|
if (this.config.fishermanMode) {
|
|
@@ -414,77 +520,95 @@ export class SequencerPublisher {
|
|
|
414
520
|
}
|
|
415
521
|
|
|
416
522
|
/**
|
|
417
|
-
* Simulate making a call to invalidate a
|
|
418
|
-
* @param
|
|
523
|
+
* Simulate making a call to invalidate a checkpoint with invalid attestations. Returns undefined if no need to invalidate.
|
|
524
|
+
* @param validationResult - The validation result indicating which checkpoint to invalidate (as returned by the archiver)
|
|
419
525
|
*/
|
|
420
|
-
public async
|
|
421
|
-
validationResult:
|
|
422
|
-
): Promise<
|
|
526
|
+
public async simulateInvalidateCheckpoint(
|
|
527
|
+
validationResult: ValidateCheckpointResult,
|
|
528
|
+
): Promise<InvalidateCheckpointRequest | undefined> {
|
|
423
529
|
if (validationResult.valid) {
|
|
424
530
|
return undefined;
|
|
425
531
|
}
|
|
426
532
|
|
|
427
|
-
const { reason,
|
|
428
|
-
const
|
|
429
|
-
const logData = { ...
|
|
533
|
+
const { reason, checkpoint } = validationResult;
|
|
534
|
+
const checkpointNumber = checkpoint.checkpointNumber;
|
|
535
|
+
const logData = { ...checkpoint, reason };
|
|
430
536
|
|
|
431
|
-
const
|
|
432
|
-
if (
|
|
537
|
+
const currentCheckpointNumber = await this.rollupContract.getCheckpointNumber();
|
|
538
|
+
if (currentCheckpointNumber < checkpointNumber) {
|
|
433
539
|
this.log.verbose(
|
|
434
|
-
`Skipping
|
|
435
|
-
{
|
|
540
|
+
`Skipping checkpoint ${checkpointNumber} invalidation since it has already been removed from the pending chain`,
|
|
541
|
+
{ currentCheckpointNumber, ...logData },
|
|
436
542
|
);
|
|
437
543
|
return undefined;
|
|
438
544
|
}
|
|
439
545
|
|
|
440
|
-
const request = this.
|
|
441
|
-
this.log.debug(`Simulating invalidate
|
|
546
|
+
const request = this.buildInvalidateCheckpointRequest(validationResult);
|
|
547
|
+
this.log.debug(`Simulating invalidate checkpoint ${checkpointNumber}`, { ...logData, request });
|
|
442
548
|
|
|
443
549
|
try {
|
|
444
|
-
const { gasUsed } = await this.l1TxUtils.simulate(
|
|
445
|
-
|
|
550
|
+
const { gasUsed } = await this.l1TxUtils.simulate(
|
|
551
|
+
request,
|
|
552
|
+
undefined,
|
|
553
|
+
undefined,
|
|
554
|
+
mergeAbis([request.abi ?? [], ErrorsAbi]),
|
|
555
|
+
);
|
|
556
|
+
this.log.verbose(`Simulation for invalidate checkpoint ${checkpointNumber} succeeded`, {
|
|
557
|
+
...logData,
|
|
558
|
+
request,
|
|
559
|
+
gasUsed,
|
|
560
|
+
});
|
|
446
561
|
|
|
447
|
-
return {
|
|
562
|
+
return {
|
|
563
|
+
request,
|
|
564
|
+
gasUsed,
|
|
565
|
+
checkpointNumber,
|
|
566
|
+
forcePendingCheckpointNumber: CheckpointNumber(checkpointNumber - 1),
|
|
567
|
+
reason,
|
|
568
|
+
};
|
|
448
569
|
} catch (err) {
|
|
449
570
|
const viemError = formatViemError(err);
|
|
450
571
|
|
|
451
|
-
// If the error is due to the
|
|
452
|
-
// we can safely ignore it and return undefined so we go ahead with
|
|
453
|
-
if (viemError.message?.includes('
|
|
572
|
+
// If the error is due to the checkpoint not being in the pending chain, and it was indeed removed by someone else,
|
|
573
|
+
// we can safely ignore it and return undefined so we go ahead with checkpoint building.
|
|
574
|
+
if (viemError.message?.includes('Rollup__CheckpointNotInPendingChain')) {
|
|
454
575
|
this.log.verbose(
|
|
455
|
-
`Simulation for invalidate
|
|
576
|
+
`Simulation for invalidate checkpoint ${checkpointNumber} failed due to checkpoint not being in pending chain`,
|
|
456
577
|
{ ...logData, request, error: viemError.message },
|
|
457
578
|
);
|
|
458
|
-
const
|
|
459
|
-
if (
|
|
460
|
-
this.log.verbose(`
|
|
579
|
+
const latestPendingCheckpointNumber = await this.rollupContract.getCheckpointNumber();
|
|
580
|
+
if (latestPendingCheckpointNumber < checkpointNumber) {
|
|
581
|
+
this.log.verbose(`Checkpoint ${checkpointNumber} has already been invalidated`, { ...logData });
|
|
461
582
|
return undefined;
|
|
462
583
|
} else {
|
|
463
584
|
this.log.error(
|
|
464
|
-
`Simulation for invalidate ${
|
|
585
|
+
`Simulation for invalidate checkpoint ${checkpointNumber} failed and it is still in pending chain`,
|
|
465
586
|
viemError,
|
|
466
587
|
logData,
|
|
467
588
|
);
|
|
468
|
-
throw new Error(
|
|
469
|
-
|
|
470
|
-
|
|
589
|
+
throw new Error(
|
|
590
|
+
`Failed to simulate invalidate checkpoint ${checkpointNumber} while it is still in pending chain`,
|
|
591
|
+
{
|
|
592
|
+
cause: viemError,
|
|
593
|
+
},
|
|
594
|
+
);
|
|
471
595
|
}
|
|
472
596
|
}
|
|
473
597
|
|
|
474
|
-
// Otherwise, throw. We cannot build the next
|
|
475
|
-
this.log.error(`Simulation for invalidate
|
|
476
|
-
throw new Error(`Failed to simulate invalidate
|
|
598
|
+
// Otherwise, throw. We cannot build the next checkpoint if we cannot invalidate the previous one.
|
|
599
|
+
this.log.error(`Simulation for invalidate checkpoint ${checkpointNumber} failed`, viemError, logData);
|
|
600
|
+
throw new Error(`Failed to simulate invalidate checkpoint ${checkpointNumber}`, { cause: viemError });
|
|
477
601
|
}
|
|
478
602
|
}
|
|
479
603
|
|
|
480
|
-
private
|
|
604
|
+
private buildInvalidateCheckpointRequest(validationResult: ValidateCheckpointResult) {
|
|
481
605
|
if (validationResult.valid) {
|
|
482
|
-
throw new Error('Cannot invalidate a valid
|
|
606
|
+
throw new Error('Cannot invalidate a valid checkpoint');
|
|
483
607
|
}
|
|
484
608
|
|
|
485
|
-
const {
|
|
486
|
-
const logData = { ...
|
|
487
|
-
this.log.debug(`
|
|
609
|
+
const { checkpoint, committee, reason } = validationResult;
|
|
610
|
+
const logData = { ...checkpoint, reason };
|
|
611
|
+
this.log.debug(`Building invalidate checkpoint ${checkpoint.checkpointNumber} request`, logData);
|
|
488
612
|
|
|
489
613
|
const attestationsAndSigners = new CommitteeAttestationsAndSigners(
|
|
490
614
|
validationResult.attestations,
|
|
@@ -492,14 +616,14 @@ export class SequencerPublisher {
|
|
|
492
616
|
|
|
493
617
|
if (reason === 'invalid-attestation') {
|
|
494
618
|
return this.rollupContract.buildInvalidateBadAttestationRequest(
|
|
495
|
-
|
|
619
|
+
checkpoint.checkpointNumber,
|
|
496
620
|
attestationsAndSigners,
|
|
497
621
|
committee,
|
|
498
622
|
validationResult.invalidIndex,
|
|
499
623
|
);
|
|
500
624
|
} else if (reason === 'insufficient-attestations') {
|
|
501
625
|
return this.rollupContract.buildInvalidateInsufficientAttestationsRequest(
|
|
502
|
-
|
|
626
|
+
checkpoint.checkpointNumber,
|
|
503
627
|
attestationsAndSigners,
|
|
504
628
|
committee,
|
|
505
629
|
);
|
|
@@ -509,47 +633,25 @@ export class SequencerPublisher {
|
|
|
509
633
|
}
|
|
510
634
|
}
|
|
511
635
|
|
|
512
|
-
/**
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
*
|
|
517
|
-
* @param block - The block to propose
|
|
518
|
-
* @param attestationData - The block's attestation data
|
|
519
|
-
*
|
|
520
|
-
*/
|
|
521
|
-
public async validateBlockForSubmission(
|
|
522
|
-
block: L2Block,
|
|
636
|
+
/** Simulates `propose` to make sure that the checkpoint is valid for submission */
|
|
637
|
+
@trackSpan('SequencerPublisher.validateCheckpointForSubmission')
|
|
638
|
+
public async validateCheckpointForSubmission(
|
|
639
|
+
checkpoint: Checkpoint,
|
|
523
640
|
attestationsAndSigners: CommitteeAttestationsAndSigners,
|
|
524
641
|
attestationsAndSignersSignature: Signature,
|
|
525
|
-
options: {
|
|
642
|
+
options: { forcePendingCheckpointNumber?: CheckpointNumber },
|
|
526
643
|
): Promise<bigint> {
|
|
527
644
|
const ts = BigInt((await this.l1TxUtils.getBlock()).timestamp + this.ethereumSlotDuration);
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
// so that the committee is recalculated correctly
|
|
531
|
-
const ignoreSignatures = attestationsAndSigners.attestations.length === 0;
|
|
532
|
-
if (ignoreSignatures) {
|
|
533
|
-
const { committee } = await this.epochCache.getCommittee(block.header.globalVariables.slotNumber);
|
|
534
|
-
if (!committee) {
|
|
535
|
-
this.log.warn(`No committee found for slot ${block.header.globalVariables.slotNumber}`);
|
|
536
|
-
throw new Error(`No committee found for slot ${block.header.globalVariables.slotNumber}`);
|
|
537
|
-
}
|
|
538
|
-
attestationsAndSigners.attestations = committee.map(committeeMember =>
|
|
539
|
-
CommitteeAttestation.fromAddress(committeeMember),
|
|
540
|
-
);
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
const blobFields = block.getCheckpointBlobFields();
|
|
544
|
-
const blobs = getBlobsPerL1Block(blobFields);
|
|
645
|
+
const blobFields = checkpoint.toBlobFields();
|
|
646
|
+
const blobs = await getBlobsPerL1Block(blobFields);
|
|
545
647
|
const blobInput = getPrefixedEthBlobCommitments(blobs);
|
|
546
648
|
|
|
547
649
|
const args = [
|
|
548
650
|
{
|
|
549
|
-
header:
|
|
550
|
-
archive: toHex(
|
|
651
|
+
header: checkpoint.header.toViem(),
|
|
652
|
+
archive: toHex(checkpoint.archive.root.toBuffer()),
|
|
551
653
|
oracleInput: {
|
|
552
|
-
feeAssetPriceModifier:
|
|
654
|
+
feeAssetPriceModifier: checkpoint.feeAssetPriceModifier,
|
|
553
655
|
},
|
|
554
656
|
},
|
|
555
657
|
attestationsAndSigners.getPackedAttestations(),
|
|
@@ -585,10 +687,45 @@ export class SequencerPublisher {
|
|
|
585
687
|
const round = await base.computeRound(slotNumber);
|
|
586
688
|
const roundInfo = await base.getRoundInfo(this.rollupContract.address, round);
|
|
587
689
|
|
|
690
|
+
if (roundInfo.quorumReached) {
|
|
691
|
+
return false;
|
|
692
|
+
}
|
|
693
|
+
|
|
588
694
|
if (roundInfo.lastSignalSlot >= slotNumber) {
|
|
589
695
|
return false;
|
|
590
696
|
}
|
|
591
697
|
|
|
698
|
+
if (await this.isPayloadEmpty(payload)) {
|
|
699
|
+
this.log.warn(`Skipping vote cast for payload with empty code`);
|
|
700
|
+
return false;
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
// Check if payload was already submitted to governance
|
|
704
|
+
const cacheKey = payload.toString();
|
|
705
|
+
if (!this.payloadProposedCache.has(cacheKey)) {
|
|
706
|
+
try {
|
|
707
|
+
const l1StartBlock = await this.rollupContract.getL1StartBlock();
|
|
708
|
+
const proposed = await retry(
|
|
709
|
+
() => base.hasPayloadBeenProposed(payload.toString(), l1StartBlock),
|
|
710
|
+
'Check if payload was proposed',
|
|
711
|
+
makeBackoff([0, 1, 2]),
|
|
712
|
+
this.log,
|
|
713
|
+
true,
|
|
714
|
+
);
|
|
715
|
+
if (proposed) {
|
|
716
|
+
this.payloadProposedCache.add(cacheKey);
|
|
717
|
+
}
|
|
718
|
+
} catch (err) {
|
|
719
|
+
this.log.warn(`Failed to check if payload ${payload} was proposed after retries, skipping signal`, err);
|
|
720
|
+
return false;
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
if (this.payloadProposedCache.has(cacheKey)) {
|
|
725
|
+
this.log.info(`Payload ${payload} was already proposed to governance, stopping signals`);
|
|
726
|
+
return false;
|
|
727
|
+
}
|
|
728
|
+
|
|
592
729
|
const cachedLastVote = this.lastActions[signalType];
|
|
593
730
|
this.lastActions[signalType] = slotNumber;
|
|
594
731
|
const action = signalType;
|
|
@@ -608,7 +745,7 @@ export class SequencerPublisher {
|
|
|
608
745
|
});
|
|
609
746
|
|
|
610
747
|
try {
|
|
611
|
-
await this.l1TxUtils.simulate(request, { time: timestamp }, [], ErrorsAbi);
|
|
748
|
+
await this.l1TxUtils.simulate(request, { time: timestamp }, [], mergeAbis([request.abi ?? [], ErrorsAbi]));
|
|
612
749
|
this.log.debug(`Simulation for ${action} at slot ${slotNumber} succeeded`, { request });
|
|
613
750
|
} catch (err) {
|
|
614
751
|
this.log.error(`Failed simulation for ${action} at slot ${slotNumber} (enqueuing the action anyway)`, err);
|
|
@@ -631,14 +768,14 @@ export class SequencerPublisher {
|
|
|
631
768
|
const logData = { ...result, slotNumber, round, payload: payload.toString() };
|
|
632
769
|
if (!success) {
|
|
633
770
|
this.log.error(
|
|
634
|
-
`Signaling in
|
|
771
|
+
`Signaling in ${action} for ${payload} at slot ${slotNumber} in round ${round} failed`,
|
|
635
772
|
logData,
|
|
636
773
|
);
|
|
637
774
|
this.lastActions[signalType] = cachedLastVote;
|
|
638
775
|
return false;
|
|
639
776
|
} else {
|
|
640
777
|
this.log.info(
|
|
641
|
-
`Signaling in
|
|
778
|
+
`Signaling in ${action} for ${payload} at slot ${slotNumber} in round ${round} succeeded`,
|
|
642
779
|
logData,
|
|
643
780
|
);
|
|
644
781
|
return true;
|
|
@@ -648,6 +785,17 @@ export class SequencerPublisher {
|
|
|
648
785
|
return true;
|
|
649
786
|
}
|
|
650
787
|
|
|
788
|
+
private async isPayloadEmpty(payload: EthAddress): Promise<boolean> {
|
|
789
|
+
const key = payload.toString();
|
|
790
|
+
const cached = this.isPayloadEmptyCache.get(key);
|
|
791
|
+
if (cached) {
|
|
792
|
+
return cached;
|
|
793
|
+
}
|
|
794
|
+
const isEmpty = !(await this.l1TxUtils.getCode(payload));
|
|
795
|
+
this.isPayloadEmptyCache.set(key, isEmpty);
|
|
796
|
+
return isEmpty;
|
|
797
|
+
}
|
|
798
|
+
|
|
651
799
|
/**
|
|
652
800
|
* Enqueues a governance castSignal transaction to cast a signal for a given slot number.
|
|
653
801
|
* @param slotNumber - The slot number to cast a signal for.
|
|
@@ -795,30 +943,25 @@ export class SequencerPublisher {
|
|
|
795
943
|
return true;
|
|
796
944
|
}
|
|
797
945
|
|
|
798
|
-
/**
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
* @param block - L2 block to propose.
|
|
802
|
-
* @returns True if the tx has been enqueued, throws otherwise. See #9315
|
|
803
|
-
*/
|
|
804
|
-
public async enqueueProposeL2Block(
|
|
805
|
-
block: L2Block,
|
|
946
|
+
/** Simulates and enqueues a proposal for a checkpoint on L1 */
|
|
947
|
+
public async enqueueProposeCheckpoint(
|
|
948
|
+
checkpoint: Checkpoint,
|
|
806
949
|
attestationsAndSigners: CommitteeAttestationsAndSigners,
|
|
807
950
|
attestationsAndSignersSignature: Signature,
|
|
808
|
-
opts: { txTimeoutAt?: Date;
|
|
809
|
-
): Promise<
|
|
810
|
-
const checkpointHeader =
|
|
951
|
+
opts: { txTimeoutAt?: Date; forcePendingCheckpointNumber?: CheckpointNumber } = {},
|
|
952
|
+
): Promise<void> {
|
|
953
|
+
const checkpointHeader = checkpoint.header;
|
|
811
954
|
|
|
812
|
-
const blobFields =
|
|
813
|
-
const blobs = getBlobsPerL1Block(blobFields);
|
|
955
|
+
const blobFields = checkpoint.toBlobFields();
|
|
956
|
+
const blobs = await getBlobsPerL1Block(blobFields);
|
|
814
957
|
|
|
815
|
-
const proposeTxArgs = {
|
|
958
|
+
const proposeTxArgs: L1ProcessArgs = {
|
|
816
959
|
header: checkpointHeader,
|
|
817
|
-
archive:
|
|
818
|
-
body: block.body.toBuffer(),
|
|
960
|
+
archive: checkpoint.archive.root.toBuffer(),
|
|
819
961
|
blobs,
|
|
820
962
|
attestationsAndSigners,
|
|
821
963
|
attestationsAndSignersSignature,
|
|
964
|
+
feeAssetPriceModifier: checkpoint.feeAssetPriceModifier,
|
|
822
965
|
};
|
|
823
966
|
|
|
824
967
|
let ts: bigint;
|
|
@@ -829,22 +972,29 @@ export class SequencerPublisher {
|
|
|
829
972
|
// By simulation issue, I mean the fact that the block.timestamp is equal to the last block, not the next, which
|
|
830
973
|
// make time consistency checks break.
|
|
831
974
|
// TODO(palla): Check whether we're validating twice, once here and once within addProposeTx, since we call simulateProposeTx in both places.
|
|
832
|
-
ts = await this.
|
|
975
|
+
ts = await this.validateCheckpointForSubmission(
|
|
976
|
+
checkpoint,
|
|
977
|
+
attestationsAndSigners,
|
|
978
|
+
attestationsAndSignersSignature,
|
|
979
|
+
opts,
|
|
980
|
+
);
|
|
833
981
|
} catch (err: any) {
|
|
834
|
-
this.log.error(`
|
|
835
|
-
...
|
|
836
|
-
slotNumber:
|
|
837
|
-
|
|
982
|
+
this.log.error(`Checkpoint validation failed. ${err instanceof Error ? err.message : 'No error message'}`, err, {
|
|
983
|
+
...checkpoint.getStats(),
|
|
984
|
+
slotNumber: checkpoint.header.slotNumber,
|
|
985
|
+
forcePendingCheckpointNumber: opts.forcePendingCheckpointNumber,
|
|
838
986
|
});
|
|
839
987
|
throw err;
|
|
840
988
|
}
|
|
841
989
|
|
|
842
|
-
this.log.verbose(`Enqueuing
|
|
843
|
-
await this.addProposeTx(
|
|
844
|
-
return true;
|
|
990
|
+
this.log.verbose(`Enqueuing checkpoint propose transaction`, { ...checkpoint.toCheckpointInfo(), ...opts });
|
|
991
|
+
await this.addProposeTx(checkpoint, proposeTxArgs, opts, ts);
|
|
845
992
|
}
|
|
846
993
|
|
|
847
|
-
public
|
|
994
|
+
public enqueueInvalidateCheckpoint(
|
|
995
|
+
request: InvalidateCheckpointRequest | undefined,
|
|
996
|
+
opts: { txTimeoutAt?: Date } = {},
|
|
997
|
+
) {
|
|
848
998
|
if (!request) {
|
|
849
999
|
return;
|
|
850
1000
|
}
|
|
@@ -852,9 +1002,9 @@ export class SequencerPublisher {
|
|
|
852
1002
|
// We issued the simulation against the rollup contract, so we need to account for the overhead of the multicall3
|
|
853
1003
|
const gasLimit = this.l1TxUtils.bumpGasLimit(BigInt(Math.ceil((Number(request.gasUsed) * 64) / 63)));
|
|
854
1004
|
|
|
855
|
-
const { gasUsed,
|
|
856
|
-
const logData = { gasUsed,
|
|
857
|
-
this.log.verbose(`Enqueuing invalidate
|
|
1005
|
+
const { gasUsed, checkpointNumber } = request;
|
|
1006
|
+
const logData = { gasUsed, checkpointNumber, gasLimit, opts };
|
|
1007
|
+
this.log.verbose(`Enqueuing invalidate checkpoint request`, logData);
|
|
858
1008
|
this.addRequest({
|
|
859
1009
|
action: `invalidate-by-${request.reason}`,
|
|
860
1010
|
request: request.request,
|
|
@@ -867,9 +1017,9 @@ export class SequencerPublisher {
|
|
|
867
1017
|
result.receipt.status === 'success' &&
|
|
868
1018
|
tryExtractEvent(result.receipt.logs, this.rollupContract.address, RollupAbi, 'CheckpointInvalidated');
|
|
869
1019
|
if (!success) {
|
|
870
|
-
this.log.warn(`Invalidate
|
|
1020
|
+
this.log.warn(`Invalidate checkpoint ${request.checkpointNumber} failed`, { ...result, ...logData });
|
|
871
1021
|
} else {
|
|
872
|
-
this.log.info(`Invalidate
|
|
1022
|
+
this.log.info(`Invalidate checkpoint ${request.checkpointNumber} succeeded`, { ...result, ...logData });
|
|
873
1023
|
}
|
|
874
1024
|
return !!success;
|
|
875
1025
|
},
|
|
@@ -895,12 +1045,14 @@ export class SequencerPublisher {
|
|
|
895
1045
|
this.log.debug(`Simulating ${action} for slot ${slotNumber}`, logData);
|
|
896
1046
|
|
|
897
1047
|
let gasUsed: bigint;
|
|
1048
|
+
const simulateAbi = mergeAbis([request.abi ?? [], ErrorsAbi]);
|
|
898
1049
|
try {
|
|
899
|
-
({ gasUsed } = await this.l1TxUtils.simulate(request, { time: timestamp }, [],
|
|
1050
|
+
({ gasUsed } = await this.l1TxUtils.simulate(request, { time: timestamp }, [], simulateAbi)); // TODO(palla/slash): Check the timestamp logic
|
|
900
1051
|
this.log.verbose(`Simulation for ${action} succeeded`, { ...logData, request, gasUsed });
|
|
901
1052
|
} catch (err) {
|
|
902
|
-
const viemError = formatViemError(err);
|
|
1053
|
+
const viemError = formatViemError(err, simulateAbi);
|
|
903
1054
|
this.log.error(`Simulation for ${action} at ${slotNumber} failed`, viemError, logData);
|
|
1055
|
+
|
|
904
1056
|
return false;
|
|
905
1057
|
}
|
|
906
1058
|
|
|
@@ -908,10 +1060,14 @@ export class SequencerPublisher {
|
|
|
908
1060
|
const gasLimit = this.l1TxUtils.bumpGasLimit(BigInt(Math.ceil((Number(gasUsed) * 64) / 63)));
|
|
909
1061
|
logData.gasLimit = gasLimit;
|
|
910
1062
|
|
|
1063
|
+
// Store the ABI used for simulation on the request so Multicall3.forward can decode errors
|
|
1064
|
+
// when the tx is sent and a revert is diagnosed via simulation.
|
|
1065
|
+
const requestWithAbi = { ...request, abi: simulateAbi };
|
|
1066
|
+
|
|
911
1067
|
this.log.debug(`Enqueuing ${action}`, logData);
|
|
912
1068
|
this.addRequest({
|
|
913
1069
|
action,
|
|
914
|
-
request,
|
|
1070
|
+
request: requestWithAbi,
|
|
915
1071
|
gasConfig: { gasLimit },
|
|
916
1072
|
lastValidL2Slot: slotNumber,
|
|
917
1073
|
checkSuccess: (_req, result) => {
|
|
@@ -948,7 +1104,7 @@ export class SequencerPublisher {
|
|
|
948
1104
|
private async prepareProposeTx(
|
|
949
1105
|
encodedData: L1ProcessArgs,
|
|
950
1106
|
timestamp: bigint,
|
|
951
|
-
options: {
|
|
1107
|
+
options: { forcePendingCheckpointNumber?: CheckpointNumber },
|
|
952
1108
|
) {
|
|
953
1109
|
const kzg = Blob.getViemKzgInstance();
|
|
954
1110
|
const blobInput = getPrefixedEthBlobCommitments(encodedData.blobs);
|
|
@@ -993,8 +1149,7 @@ export class SequencerPublisher {
|
|
|
993
1149
|
header: encodedData.header.toViem(),
|
|
994
1150
|
archive: toHex(encodedData.archive),
|
|
995
1151
|
oracleInput: {
|
|
996
|
-
|
|
997
|
-
feeAssetPriceModifier: 0n,
|
|
1152
|
+
feeAssetPriceModifier: encodedData.feeAssetPriceModifier,
|
|
998
1153
|
},
|
|
999
1154
|
},
|
|
1000
1155
|
encodedData.attestationsAndSigners.getPackedAttestations(),
|
|
@@ -1020,7 +1175,7 @@ export class SequencerPublisher {
|
|
|
1020
1175
|
readonly header: ViemHeader;
|
|
1021
1176
|
readonly archive: `0x${string}`;
|
|
1022
1177
|
readonly oracleInput: {
|
|
1023
|
-
readonly feeAssetPriceModifier:
|
|
1178
|
+
readonly feeAssetPriceModifier: bigint;
|
|
1024
1179
|
};
|
|
1025
1180
|
},
|
|
1026
1181
|
ViemCommitteeAttestations,
|
|
@@ -1029,7 +1184,7 @@ export class SequencerPublisher {
|
|
|
1029
1184
|
`0x${string}`,
|
|
1030
1185
|
],
|
|
1031
1186
|
timestamp: bigint,
|
|
1032
|
-
options: {
|
|
1187
|
+
options: { forcePendingCheckpointNumber?: CheckpointNumber },
|
|
1033
1188
|
) {
|
|
1034
1189
|
const rollupData = encodeFunctionData({
|
|
1035
1190
|
abi: RollupAbi,
|
|
@@ -1038,13 +1193,9 @@ export class SequencerPublisher {
|
|
|
1038
1193
|
});
|
|
1039
1194
|
|
|
1040
1195
|
// override the pending checkpoint number if requested
|
|
1041
|
-
const optsForcePendingCheckpointNumber =
|
|
1042
|
-
options.forcePendingBlockNumber !== undefined
|
|
1043
|
-
? CheckpointNumber.fromBlockNumber(options.forcePendingBlockNumber)
|
|
1044
|
-
: undefined;
|
|
1045
1196
|
const forcePendingCheckpointNumberStateDiff = (
|
|
1046
|
-
|
|
1047
|
-
? await this.rollupContract.makePendingCheckpointNumberOverride(
|
|
1197
|
+
options.forcePendingCheckpointNumber !== undefined
|
|
1198
|
+
? await this.rollupContract.makePendingCheckpointNumberOverride(options.forcePendingCheckpointNumber)
|
|
1048
1199
|
: []
|
|
1049
1200
|
).flatMap(override => override.stateDiff ?? []);
|
|
1050
1201
|
|
|
@@ -1071,20 +1222,20 @@ export class SequencerPublisher {
|
|
|
1071
1222
|
{
|
|
1072
1223
|
to: this.rollupContract.address,
|
|
1073
1224
|
data: rollupData,
|
|
1074
|
-
gas:
|
|
1225
|
+
gas: MAX_L1_TX_LIMIT,
|
|
1075
1226
|
...(this.proposerAddressForSimulation && { from: this.proposerAddressForSimulation.toString() }),
|
|
1076
1227
|
},
|
|
1077
1228
|
{
|
|
1078
1229
|
// @note we add 1n to the timestamp because geth implementation doesn't like simulation timestamp to be equal to the current block timestamp
|
|
1079
1230
|
time: timestamp + 1n,
|
|
1080
1231
|
// @note reth should have a 30m gas limit per block but throws errors that this tx is beyond limit so we increase here
|
|
1081
|
-
gasLimit:
|
|
1232
|
+
gasLimit: MAX_L1_TX_LIMIT * 2n,
|
|
1082
1233
|
},
|
|
1083
1234
|
stateOverrides,
|
|
1084
1235
|
RollupAbi,
|
|
1085
1236
|
{
|
|
1086
1237
|
// @note fallback gas estimate to use if the node doesn't support simulation API
|
|
1087
|
-
fallbackGasEstimate:
|
|
1238
|
+
fallbackGasEstimate: MAX_L1_TX_LIMIT,
|
|
1088
1239
|
},
|
|
1089
1240
|
)
|
|
1090
1241
|
.catch(err => {
|
|
@@ -1094,7 +1245,7 @@ export class SequencerPublisher {
|
|
|
1094
1245
|
this.log.debug(`Ignoring expected ValidatorSelection__MissingProposerSignature error in fisherman mode`);
|
|
1095
1246
|
// Return a minimal simulation result with the fallback gas estimate
|
|
1096
1247
|
return {
|
|
1097
|
-
gasUsed:
|
|
1248
|
+
gasUsed: MAX_L1_TX_LIMIT,
|
|
1098
1249
|
logs: [],
|
|
1099
1250
|
};
|
|
1100
1251
|
}
|
|
@@ -1106,11 +1257,12 @@ export class SequencerPublisher {
|
|
|
1106
1257
|
}
|
|
1107
1258
|
|
|
1108
1259
|
private async addProposeTx(
|
|
1109
|
-
|
|
1260
|
+
checkpoint: Checkpoint,
|
|
1110
1261
|
encodedData: L1ProcessArgs,
|
|
1111
|
-
opts: { txTimeoutAt?: Date;
|
|
1262
|
+
opts: { txTimeoutAt?: Date; forcePendingCheckpointNumber?: CheckpointNumber } = {},
|
|
1112
1263
|
timestamp: bigint,
|
|
1113
1264
|
): Promise<void> {
|
|
1265
|
+
const slot = checkpoint.header.slotNumber;
|
|
1114
1266
|
const timer = new Timer();
|
|
1115
1267
|
const kzg = Blob.getViemKzgInstance();
|
|
1116
1268
|
const { rollupData, simulationResult, blobEvaluationGas } = await this.prepareProposeTx(
|
|
@@ -1125,11 +1277,13 @@ export class SequencerPublisher {
|
|
|
1125
1277
|
SequencerPublisher.MULTICALL_OVERHEAD_GAS_GUESS, // We issue the simulation against the rollup contract, so we need to account for the overhead of the multicall3
|
|
1126
1278
|
);
|
|
1127
1279
|
|
|
1128
|
-
// Send the blobs to the blob
|
|
1129
|
-
// tx fails but it does get mined. We make sure that the blobs are sent to the blob
|
|
1130
|
-
void
|
|
1131
|
-
this.
|
|
1132
|
-
|
|
1280
|
+
// Send the blobs to the blob client preemptively. This helps in tests where the sequencer mistakingly thinks that the propose
|
|
1281
|
+
// tx fails but it does get mined. We make sure that the blobs are sent to the blob client regardless of the tx outcome.
|
|
1282
|
+
void Promise.resolve().then(() =>
|
|
1283
|
+
this.blobClient.sendBlobsToFilestore(encodedData.blobs).catch(_err => {
|
|
1284
|
+
this.log.error('Failed to send blobs to blob client');
|
|
1285
|
+
}),
|
|
1286
|
+
);
|
|
1133
1287
|
|
|
1134
1288
|
return this.addRequest({
|
|
1135
1289
|
action: 'propose',
|
|
@@ -1137,7 +1291,7 @@ export class SequencerPublisher {
|
|
|
1137
1291
|
to: this.rollupContract.address,
|
|
1138
1292
|
data: rollupData,
|
|
1139
1293
|
},
|
|
1140
|
-
lastValidL2Slot:
|
|
1294
|
+
lastValidL2Slot: checkpoint.header.slotNumber,
|
|
1141
1295
|
gasConfig: { ...opts, gasLimit },
|
|
1142
1296
|
blobConfig: {
|
|
1143
1297
|
blobs: encodedData.blobs.map(b => b.data),
|
|
@@ -1152,11 +1306,12 @@ export class SequencerPublisher {
|
|
|
1152
1306
|
receipt &&
|
|
1153
1307
|
receipt.status === 'success' &&
|
|
1154
1308
|
tryExtractEvent(receipt.logs, this.rollupContract.address, RollupAbi, 'CheckpointProposed');
|
|
1309
|
+
|
|
1155
1310
|
if (success) {
|
|
1156
1311
|
const endBlock = receipt.blockNumber;
|
|
1157
1312
|
const inclusionBlocks = Number(endBlock - startBlock);
|
|
1158
1313
|
const { calldataGas, calldataSize, sender } = stats!;
|
|
1159
|
-
const publishStats:
|
|
1314
|
+
const publishStats: L1PublishCheckpointStats = {
|
|
1160
1315
|
gasPrice: receipt.effectiveGasPrice,
|
|
1161
1316
|
gasUsed: receipt.gasUsed,
|
|
1162
1317
|
blobGasUsed: receipt.blobGasUsed ?? 0n,
|
|
@@ -1165,23 +1320,26 @@ export class SequencerPublisher {
|
|
|
1165
1320
|
calldataGas,
|
|
1166
1321
|
calldataSize,
|
|
1167
1322
|
sender,
|
|
1168
|
-
...
|
|
1323
|
+
...checkpoint.getStats(),
|
|
1169
1324
|
eventName: 'rollup-published-to-l1',
|
|
1170
1325
|
blobCount: encodedData.blobs.length,
|
|
1171
1326
|
inclusionBlocks,
|
|
1172
1327
|
};
|
|
1173
|
-
this.log.info(`Published
|
|
1328
|
+
this.log.info(`Published checkpoint ${checkpoint.number} at slot ${slot} to rollup contract`, {
|
|
1329
|
+
...stats,
|
|
1330
|
+
...checkpoint.getStats(),
|
|
1331
|
+
...pick(receipt, 'transactionHash', 'blockHash'),
|
|
1332
|
+
});
|
|
1174
1333
|
this.metrics.recordProcessBlockTx(timer.ms(), publishStats);
|
|
1175
1334
|
|
|
1176
1335
|
return true;
|
|
1177
1336
|
} else {
|
|
1178
1337
|
this.metrics.recordFailedTx('process');
|
|
1179
|
-
this.log.error(
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
});
|
|
1338
|
+
this.log.error(
|
|
1339
|
+
`Publishing checkpoint at slot ${slot} failed with ${errorMsg ?? 'no error message'}`,
|
|
1340
|
+
undefined,
|
|
1341
|
+
{ ...checkpoint.getStats(), ...receipt },
|
|
1342
|
+
);
|
|
1185
1343
|
return false;
|
|
1186
1344
|
}
|
|
1187
1345
|
},
|