@aztec/sequencer-client 0.72.1 → 0.74.0
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 +11 -6
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +46 -10
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +3 -4
- package/dest/publisher/config.d.ts +5 -0
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +9 -2
- package/dest/publisher/index.d.ts +1 -1
- package/dest/publisher/index.d.ts.map +1 -1
- package/dest/publisher/index.js +2 -2
- package/dest/publisher/{l1-publisher-metrics.d.ts → sequencer-publisher-metrics.d.ts} +6 -2
- package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -0
- package/dest/publisher/sequencer-publisher-metrics.js +111 -0
- package/dest/publisher/sequencer-publisher.d.ts +163 -0
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -0
- package/dest/publisher/sequencer-publisher.js +528 -0
- package/dest/sequencer/allowed.d.ts +1 -1
- package/dest/sequencer/allowed.d.ts.map +1 -1
- package/dest/sequencer/allowed.js +4 -4
- package/dest/sequencer/metrics.d.ts +1 -1
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +3 -4
- package/dest/sequencer/sequencer.d.ts +17 -10
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +103 -109
- package/dest/sequencer/utils.d.ts +1 -1
- package/dest/sequencer/utils.d.ts.map +1 -1
- package/dest/sequencer/utils.js +3 -3
- package/dest/slasher/factory.d.ts +2 -2
- package/dest/slasher/factory.d.ts.map +1 -1
- package/dest/slasher/factory.js +2 -2
- package/dest/slasher/slasher_client.d.ts +4 -4
- package/dest/slasher/slasher_client.d.ts.map +1 -1
- package/dest/slasher/slasher_client.js +38 -26
- package/dest/test/index.d.ts +3 -3
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/index.js +1 -2
- package/dest/tx_validator/gas_validator.d.ts.map +1 -1
- package/dest/tx_validator/gas_validator.js +4 -3
- package/dest/tx_validator/test_utils.d.ts +4 -4
- package/dest/tx_validator/test_utils.d.ts.map +1 -1
- package/dest/tx_validator/test_utils.js +3 -3
- package/package.json +21 -20
- package/src/client/sequencer-client.ts +81 -14
- package/src/config.ts +3 -3
- package/src/publisher/config.ts +13 -1
- package/src/publisher/index.ts +1 -1
- package/src/publisher/{l1-publisher-metrics.ts → sequencer-publisher-metrics.ts} +41 -2
- package/src/publisher/sequencer-publisher.ts +710 -0
- package/src/sequencer/allowed.ts +3 -3
- package/src/sequencer/metrics.ts +2 -3
- package/src/sequencer/sequencer.ts +138 -125
- package/src/sequencer/utils.ts +5 -2
- package/src/slasher/factory.ts +3 -3
- package/src/slasher/slasher_client.ts +44 -30
- package/src/test/index.ts +2 -4
- package/src/tx_validator/gas_validator.ts +5 -4
- package/src/tx_validator/test_utils.ts +5 -5
- package/dest/publisher/l1-publisher-metrics.d.ts.map +0 -1
- package/dest/publisher/l1-publisher-metrics.js +0 -85
- package/dest/publisher/l1-publisher.d.ts +0 -195
- package/dest/publisher/l1-publisher.d.ts.map +0 -1
- package/dest/publisher/l1-publisher.js +0 -930
- package/dest/test/test-l1-publisher.d.ts +0 -9
- package/dest/test/test-l1-publisher.d.ts.map +0 -1
- package/dest/test/test-l1-publisher.js +0 -11
- package/src/publisher/l1-publisher.ts +0 -1288
- package/src/test/test-l1-publisher.ts +0 -20
|
@@ -0,0 +1,710 @@
|
|
|
1
|
+
import { type BlobSinkClientInterface, createBlobSinkClient } from '@aztec/blob-sink/client';
|
|
2
|
+
import {
|
|
3
|
+
ConsensusPayload,
|
|
4
|
+
type EpochProofQuote,
|
|
5
|
+
type L2Block,
|
|
6
|
+
SignatureDomainSeparator,
|
|
7
|
+
type TxHash,
|
|
8
|
+
getHashedSignaturePayload,
|
|
9
|
+
} from '@aztec/circuit-types';
|
|
10
|
+
import type { L1PublishBlockStats, L1PublishStats } from '@aztec/circuit-types/stats';
|
|
11
|
+
import { type BlockHeader, EthAddress } from '@aztec/circuits.js';
|
|
12
|
+
import { type EpochCache } from '@aztec/epoch-cache';
|
|
13
|
+
import {
|
|
14
|
+
FormattedViemError,
|
|
15
|
+
type ForwarderContract,
|
|
16
|
+
type GasPrice,
|
|
17
|
+
type GovernanceProposerContract,
|
|
18
|
+
type IEmpireBase,
|
|
19
|
+
type L1BlobInputs,
|
|
20
|
+
type L1ContractsConfig,
|
|
21
|
+
type L1GasConfig,
|
|
22
|
+
type L1TxRequest,
|
|
23
|
+
type L1TxUtilsWithBlobs,
|
|
24
|
+
RollupContract,
|
|
25
|
+
type SlashingProposerContract,
|
|
26
|
+
type TransactionStats,
|
|
27
|
+
formatViemError,
|
|
28
|
+
} from '@aztec/ethereum';
|
|
29
|
+
import { toHex } from '@aztec/foundation/bigint-buffer';
|
|
30
|
+
import { Blob } from '@aztec/foundation/blob';
|
|
31
|
+
import { type Signature } from '@aztec/foundation/eth-signature';
|
|
32
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
33
|
+
import { Timer } from '@aztec/foundation/timer';
|
|
34
|
+
import { ForwarderAbi, RollupAbi } from '@aztec/l1-artifacts';
|
|
35
|
+
import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
|
|
36
|
+
|
|
37
|
+
import pick from 'lodash.pick';
|
|
38
|
+
import { type TransactionReceipt, encodeFunctionData } from 'viem';
|
|
39
|
+
|
|
40
|
+
import { type PublisherConfig, type TxSenderConfig } from './config.js';
|
|
41
|
+
import { SequencerPublisherMetrics } from './sequencer-publisher-metrics.js';
|
|
42
|
+
|
|
43
|
+
/** Arguments to the process method of the rollup contract */
|
|
44
|
+
type L1ProcessArgs = {
|
|
45
|
+
/** The L2 block header. */
|
|
46
|
+
header: Buffer;
|
|
47
|
+
/** A root of the archive tree after the L2 block is applied. */
|
|
48
|
+
archive: Buffer;
|
|
49
|
+
/** The L2 block's leaf in the archive tree. */
|
|
50
|
+
blockHash: Buffer;
|
|
51
|
+
/** L2 block body. TODO(#9101): Remove block body once we can extract blobs. */
|
|
52
|
+
body: Buffer;
|
|
53
|
+
/** L2 block blobs containing all tx effects. */
|
|
54
|
+
blobs: Blob[];
|
|
55
|
+
/** L2 block tx hashes */
|
|
56
|
+
txHashes: TxHash[];
|
|
57
|
+
/** Attestations */
|
|
58
|
+
attestations?: Signature[];
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export enum VoteType {
|
|
62
|
+
GOVERNANCE,
|
|
63
|
+
SLASHING,
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
type GetSlashPayloadCallBack = (slotNumber: bigint) => Promise<EthAddress | undefined>;
|
|
67
|
+
|
|
68
|
+
type Action = 'propose' | 'claim' | 'governance-vote' | 'slashing-vote';
|
|
69
|
+
interface RequestWithExpiry {
|
|
70
|
+
action: Action;
|
|
71
|
+
request: L1TxRequest;
|
|
72
|
+
lastValidL2Slot: bigint;
|
|
73
|
+
gasConfig?: L1GasConfig;
|
|
74
|
+
blobConfig?: L1BlobInputs;
|
|
75
|
+
onResult?: (
|
|
76
|
+
request: L1TxRequest,
|
|
77
|
+
result?: { receipt: TransactionReceipt; gasPrice: GasPrice; stats?: TransactionStats; errorMsg?: string },
|
|
78
|
+
) => void;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export class SequencerPublisher {
|
|
82
|
+
private interrupted = false;
|
|
83
|
+
private metrics: SequencerPublisherMetrics;
|
|
84
|
+
private epochCache: EpochCache;
|
|
85
|
+
private forwarderContract: ForwarderContract;
|
|
86
|
+
|
|
87
|
+
protected governanceLog = createLogger('sequencer:publisher:governance');
|
|
88
|
+
protected governanceProposerAddress?: EthAddress;
|
|
89
|
+
private governancePayload: EthAddress = EthAddress.ZERO;
|
|
90
|
+
|
|
91
|
+
protected slashingLog = createLogger('sequencer:publisher:slashing');
|
|
92
|
+
protected slashingProposerAddress?: EthAddress;
|
|
93
|
+
private getSlashPayload?: GetSlashPayloadCallBack = undefined;
|
|
94
|
+
|
|
95
|
+
private myLastVotes: Record<VoteType, bigint> = {
|
|
96
|
+
[VoteType.GOVERNANCE]: 0n,
|
|
97
|
+
[VoteType.SLASHING]: 0n,
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
protected log = createLogger('sequencer:publisher');
|
|
101
|
+
protected ethereumSlotDuration: bigint;
|
|
102
|
+
|
|
103
|
+
private blobSinkClient: BlobSinkClientInterface;
|
|
104
|
+
// @note - with blobs, the below estimate seems too large.
|
|
105
|
+
// Total used for full block from int_l1_pub e2e test: 1m (of which 86k is 1x blob)
|
|
106
|
+
// Total used for emptier block from above test: 429k (of which 84k is 1x blob)
|
|
107
|
+
public static PROPOSE_GAS_GUESS: bigint = 12_000_000n;
|
|
108
|
+
public static PROPOSE_AND_CLAIM_GAS_GUESS: bigint = this.PROPOSE_GAS_GUESS + 100_000n;
|
|
109
|
+
|
|
110
|
+
public l1TxUtils: L1TxUtilsWithBlobs;
|
|
111
|
+
public rollupContract: RollupContract;
|
|
112
|
+
public govProposerContract: GovernanceProposerContract;
|
|
113
|
+
public slashingProposerContract: SlashingProposerContract;
|
|
114
|
+
|
|
115
|
+
protected requests: RequestWithExpiry[] = [];
|
|
116
|
+
|
|
117
|
+
constructor(
|
|
118
|
+
config: TxSenderConfig & PublisherConfig & Pick<L1ContractsConfig, 'ethereumSlotDuration'>,
|
|
119
|
+
deps: {
|
|
120
|
+
telemetry?: TelemetryClient;
|
|
121
|
+
blobSinkClient?: BlobSinkClientInterface;
|
|
122
|
+
forwarderContract: ForwarderContract;
|
|
123
|
+
l1TxUtils: L1TxUtilsWithBlobs;
|
|
124
|
+
rollupContract: RollupContract;
|
|
125
|
+
slashingProposerContract: SlashingProposerContract;
|
|
126
|
+
governanceProposerContract: GovernanceProposerContract;
|
|
127
|
+
epochCache: EpochCache;
|
|
128
|
+
},
|
|
129
|
+
) {
|
|
130
|
+
this.ethereumSlotDuration = BigInt(config.ethereumSlotDuration);
|
|
131
|
+
this.epochCache = deps.epochCache;
|
|
132
|
+
|
|
133
|
+
this.blobSinkClient = deps.blobSinkClient ?? createBlobSinkClient(config);
|
|
134
|
+
|
|
135
|
+
const telemetry = deps.telemetry ?? getTelemetryClient();
|
|
136
|
+
this.metrics = new SequencerPublisherMetrics(telemetry, 'SequencerPublisher');
|
|
137
|
+
this.l1TxUtils = deps.l1TxUtils;
|
|
138
|
+
|
|
139
|
+
this.rollupContract = deps.rollupContract;
|
|
140
|
+
this.forwarderContract = deps.forwarderContract;
|
|
141
|
+
|
|
142
|
+
this.govProposerContract = deps.governanceProposerContract;
|
|
143
|
+
this.slashingProposerContract = deps.slashingProposerContract;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
public registerSlashPayloadGetter(callback: GetSlashPayloadCallBack) {
|
|
147
|
+
this.getSlashPayload = callback;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
public getForwarderAddress() {
|
|
151
|
+
return EthAddress.fromString(this.forwarderContract.getAddress());
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
public getSenderAddress() {
|
|
155
|
+
return EthAddress.fromString(this.l1TxUtils.getSenderAddress());
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
public getGovernancePayload() {
|
|
159
|
+
return this.governancePayload;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
public setGovernancePayload(payload: EthAddress) {
|
|
163
|
+
this.governancePayload = payload;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
public addRequest(request: RequestWithExpiry) {
|
|
167
|
+
this.requests.push(request);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
public getCurrentL2Slot(): bigint {
|
|
171
|
+
return this.epochCache.getEpochAndSlotNow().slot;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Sends all requests that are still valid.
|
|
176
|
+
* @returns one of:
|
|
177
|
+
* - A receipt and stats if the tx succeeded
|
|
178
|
+
* - a receipt and errorMsg if it failed on L1
|
|
179
|
+
* - undefined if no valid requests are found OR the tx failed to send.
|
|
180
|
+
*/
|
|
181
|
+
public async sendRequests() {
|
|
182
|
+
const requestsToProcess = [...this.requests];
|
|
183
|
+
this.requests = [];
|
|
184
|
+
if (this.interrupted) {
|
|
185
|
+
return undefined;
|
|
186
|
+
}
|
|
187
|
+
const currentL2Slot = this.getCurrentL2Slot();
|
|
188
|
+
this.log.debug(`Current L2 slot: ${currentL2Slot}`);
|
|
189
|
+
const validRequests = requestsToProcess.filter(request => request.lastValidL2Slot >= currentL2Slot);
|
|
190
|
+
|
|
191
|
+
if (validRequests.length !== requestsToProcess.length) {
|
|
192
|
+
this.log.warn(`Some requests were expired for slot ${currentL2Slot}`, {
|
|
193
|
+
validRequests: validRequests.map(request => ({
|
|
194
|
+
action: request.action,
|
|
195
|
+
lastValidL2Slot: request.lastValidL2Slot,
|
|
196
|
+
})),
|
|
197
|
+
requests: requestsToProcess.map(request => ({
|
|
198
|
+
action: request.action,
|
|
199
|
+
lastValidL2Slot: request.lastValidL2Slot,
|
|
200
|
+
})),
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (validRequests.length === 0) {
|
|
205
|
+
this.log.debug(`No valid requests to send`);
|
|
206
|
+
return undefined;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// @note - we can only have one gas config and one blob config per bundle
|
|
210
|
+
// find requests with gas and blob configs
|
|
211
|
+
// See https://github.com/AztecProtocol/aztec-packages/issues/11513
|
|
212
|
+
const gasConfigs = requestsToProcess.filter(request => request.gasConfig);
|
|
213
|
+
const blobConfigs = requestsToProcess.filter(request => request.blobConfig);
|
|
214
|
+
|
|
215
|
+
if (gasConfigs.length > 1 || blobConfigs.length > 1) {
|
|
216
|
+
throw new Error('Multiple gas or blob configs found');
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const gasConfig = gasConfigs[0]?.gasConfig;
|
|
220
|
+
const blobConfig = blobConfigs[0]?.blobConfig;
|
|
221
|
+
|
|
222
|
+
try {
|
|
223
|
+
this.log.debug('Forwarding transactions', {
|
|
224
|
+
validRequests: validRequests.map(request => request.action),
|
|
225
|
+
});
|
|
226
|
+
const result = await this.forwarderContract.forward(
|
|
227
|
+
validRequests.map(request => request.request),
|
|
228
|
+
this.l1TxUtils,
|
|
229
|
+
gasConfig,
|
|
230
|
+
blobConfig,
|
|
231
|
+
this.log,
|
|
232
|
+
);
|
|
233
|
+
this.callbackBundledTransactions(validRequests, result);
|
|
234
|
+
return result;
|
|
235
|
+
} catch (err) {
|
|
236
|
+
const viemError = formatViemError(err);
|
|
237
|
+
this.log.error(`Failed to publish bundled transactions`, viemError);
|
|
238
|
+
return undefined;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
private callbackBundledTransactions(
|
|
243
|
+
requests: RequestWithExpiry[],
|
|
244
|
+
result?: { receipt: TransactionReceipt; gasPrice: GasPrice },
|
|
245
|
+
) {
|
|
246
|
+
const success = result?.receipt.status === 'success';
|
|
247
|
+
const logger = success ? this.log.info : this.log.error;
|
|
248
|
+
for (const request of requests) {
|
|
249
|
+
logger(`Bundled [${request.action}] transaction [${success ? 'succeeded' : 'failed'}]`);
|
|
250
|
+
request.onResult?.(request.request, result);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* @notice Will call `canProposeAtNextEthBlock` to make sure that it is possible to propose
|
|
256
|
+
* @param tipArchive - The archive to check
|
|
257
|
+
* @returns The slot and block number if it is possible to propose, undefined otherwise
|
|
258
|
+
*/
|
|
259
|
+
public canProposeAtNextEthBlock(tipArchive: Buffer) {
|
|
260
|
+
const ignoredErrors = ['SlotAlreadyInChain', 'InvalidProposer', 'InvalidArchive'];
|
|
261
|
+
return this.rollupContract
|
|
262
|
+
.canProposeAtNextEthBlock(tipArchive, this.getForwarderAddress().toString(), this.ethereumSlotDuration)
|
|
263
|
+
.catch(err => {
|
|
264
|
+
if (err instanceof FormattedViemError && ignoredErrors.find(e => err.message.includes(e))) {
|
|
265
|
+
this.log.debug(err.message);
|
|
266
|
+
} else {
|
|
267
|
+
this.log.error(err.name, err);
|
|
268
|
+
}
|
|
269
|
+
return undefined;
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* @returns The epoch that is currently claimable, undefined otherwise
|
|
275
|
+
*/
|
|
276
|
+
public getClaimableEpoch() {
|
|
277
|
+
const acceptedErrors = ['Rollup__NoEpochToProve', 'Rollup__ProofRightAlreadyClaimed'] as const;
|
|
278
|
+
return this.rollupContract.getClaimableEpoch().catch(err => {
|
|
279
|
+
if (acceptedErrors.find(e => err.message.includes(e))) {
|
|
280
|
+
return undefined;
|
|
281
|
+
}
|
|
282
|
+
throw err;
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* @notice Will filter out invalid quotes according to L1
|
|
288
|
+
* @param quotes - The quotes to filter
|
|
289
|
+
* @returns The filtered quotes
|
|
290
|
+
*/
|
|
291
|
+
public filterValidQuotes(quotes: EpochProofQuote[]): Promise<EpochProofQuote[]> {
|
|
292
|
+
return Promise.all(
|
|
293
|
+
quotes.map(x =>
|
|
294
|
+
this.rollupContract
|
|
295
|
+
// validate throws if the quote is not valid
|
|
296
|
+
// else returns void
|
|
297
|
+
.validateProofQuote(x.toViemArgs(), this.getForwarderAddress().toString(), this.ethereumSlotDuration)
|
|
298
|
+
.then(() => x)
|
|
299
|
+
.catch(err => {
|
|
300
|
+
this.log.error(`Failed to validate proof quote`, err, { quote: x.toInspect() });
|
|
301
|
+
return undefined;
|
|
302
|
+
}),
|
|
303
|
+
),
|
|
304
|
+
).then(quotes => quotes.filter((q): q is EpochProofQuote => !!q));
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* @notice Will call `validateHeader` to make sure that it is possible to propose
|
|
309
|
+
*
|
|
310
|
+
* @dev Throws if unable to propose
|
|
311
|
+
*
|
|
312
|
+
* @param header - The header to propose
|
|
313
|
+
* @param digest - The digest that attestations are signing over
|
|
314
|
+
*
|
|
315
|
+
*/
|
|
316
|
+
public async validateBlockForSubmission(
|
|
317
|
+
header: BlockHeader,
|
|
318
|
+
attestationData: { digest: Buffer; signatures: Signature[] } = {
|
|
319
|
+
digest: Buffer.alloc(32),
|
|
320
|
+
signatures: [],
|
|
321
|
+
},
|
|
322
|
+
): Promise<bigint> {
|
|
323
|
+
const ts = BigInt((await this.l1TxUtils.getBlock()).timestamp + this.ethereumSlotDuration);
|
|
324
|
+
|
|
325
|
+
const formattedSignatures = attestationData.signatures.map(attest => attest.toViemSignature());
|
|
326
|
+
const flags = { ignoreDA: true, ignoreSignatures: formattedSignatures.length == 0 };
|
|
327
|
+
|
|
328
|
+
const args = [
|
|
329
|
+
`0x${header.toBuffer().toString('hex')}`,
|
|
330
|
+
formattedSignatures,
|
|
331
|
+
`0x${attestationData.digest.toString('hex')}`,
|
|
332
|
+
ts,
|
|
333
|
+
`0x${header.contentCommitment.blobsHash.toString('hex')}`,
|
|
334
|
+
flags,
|
|
335
|
+
] as const;
|
|
336
|
+
|
|
337
|
+
await this.rollupContract.validateHeader(args, this.getForwarderAddress().toString());
|
|
338
|
+
return ts;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
public async getCurrentEpochCommittee(): Promise<EthAddress[]> {
|
|
342
|
+
const committee = await this.rollupContract.getCurrentEpochCommittee();
|
|
343
|
+
return committee.map(EthAddress.fromString);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
private async enqueueCastVoteHelper(
|
|
347
|
+
slotNumber: bigint,
|
|
348
|
+
timestamp: bigint,
|
|
349
|
+
voteType: VoteType,
|
|
350
|
+
payload: EthAddress,
|
|
351
|
+
base: IEmpireBase,
|
|
352
|
+
): Promise<boolean> {
|
|
353
|
+
if (this.myLastVotes[voteType] >= slotNumber) {
|
|
354
|
+
return false;
|
|
355
|
+
}
|
|
356
|
+
if (payload.equals(EthAddress.ZERO)) {
|
|
357
|
+
return false;
|
|
358
|
+
}
|
|
359
|
+
const round = await base.computeRound(slotNumber);
|
|
360
|
+
const [proposer, roundInfo] = await Promise.all([
|
|
361
|
+
this.rollupContract.getProposerAt(timestamp),
|
|
362
|
+
base.getRoundInfo(this.rollupContract.address, round),
|
|
363
|
+
]);
|
|
364
|
+
|
|
365
|
+
if (proposer.toLowerCase() !== this.getForwarderAddress().toString().toLowerCase()) {
|
|
366
|
+
return false;
|
|
367
|
+
}
|
|
368
|
+
if (roundInfo.lastVote >= slotNumber) {
|
|
369
|
+
return false;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
const cachedLastVote = this.myLastVotes[voteType];
|
|
373
|
+
this.myLastVotes[voteType] = slotNumber;
|
|
374
|
+
|
|
375
|
+
this.addRequest({
|
|
376
|
+
action: voteType === VoteType.GOVERNANCE ? 'governance-vote' : 'slashing-vote',
|
|
377
|
+
request: base.createVoteRequest(payload.toString()),
|
|
378
|
+
lastValidL2Slot: slotNumber,
|
|
379
|
+
onResult: (_request, result) => {
|
|
380
|
+
if (!result || result.receipt.status !== 'success') {
|
|
381
|
+
this.myLastVotes[voteType] = cachedLastVote;
|
|
382
|
+
} else {
|
|
383
|
+
this.log.info(`Cast [${voteType}] vote for slot ${slotNumber}`);
|
|
384
|
+
}
|
|
385
|
+
},
|
|
386
|
+
});
|
|
387
|
+
return true;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
private async getVoteConfig(
|
|
391
|
+
slotNumber: bigint,
|
|
392
|
+
voteType: VoteType,
|
|
393
|
+
): Promise<{ payload: EthAddress; base: IEmpireBase } | undefined> {
|
|
394
|
+
if (voteType === VoteType.GOVERNANCE) {
|
|
395
|
+
return { payload: this.governancePayload, base: this.govProposerContract };
|
|
396
|
+
} else if (voteType === VoteType.SLASHING) {
|
|
397
|
+
if (!this.getSlashPayload) {
|
|
398
|
+
return undefined;
|
|
399
|
+
}
|
|
400
|
+
const slashPayload = await this.getSlashPayload(slotNumber);
|
|
401
|
+
if (!slashPayload) {
|
|
402
|
+
return undefined;
|
|
403
|
+
}
|
|
404
|
+
return { payload: slashPayload, base: this.slashingProposerContract };
|
|
405
|
+
}
|
|
406
|
+
throw new Error('Unreachable: Invalid vote type');
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* Enqueues a castVote transaction to cast a vote for a given slot number.
|
|
411
|
+
* @param slotNumber - The slot number to cast a vote for.
|
|
412
|
+
* @param timestamp - The timestamp of the slot to cast a vote for.
|
|
413
|
+
* @param voteType - The type of vote to cast.
|
|
414
|
+
* @returns True if the vote was successfully enqueued, false otherwise.
|
|
415
|
+
*/
|
|
416
|
+
public async enqueueCastVote(slotNumber: bigint, timestamp: bigint, voteType: VoteType): Promise<boolean> {
|
|
417
|
+
const voteConfig = await this.getVoteConfig(slotNumber, voteType);
|
|
418
|
+
if (!voteConfig) {
|
|
419
|
+
return false;
|
|
420
|
+
}
|
|
421
|
+
const { payload, base } = voteConfig;
|
|
422
|
+
return this.enqueueCastVoteHelper(slotNumber, timestamp, voteType, payload, base);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* Proposes a L2 block on L1.
|
|
427
|
+
*
|
|
428
|
+
* @param block - L2 block to propose.
|
|
429
|
+
* @returns True if the tx has been enqueued, throws otherwise. See #9315
|
|
430
|
+
*/
|
|
431
|
+
public async enqueueProposeL2Block(
|
|
432
|
+
block: L2Block,
|
|
433
|
+
attestations?: Signature[],
|
|
434
|
+
txHashes?: TxHash[],
|
|
435
|
+
opts: { txTimeoutAt?: Date } = {},
|
|
436
|
+
): Promise<boolean> {
|
|
437
|
+
const consensusPayload = new ConsensusPayload(block.header, block.archive.root, txHashes ?? []);
|
|
438
|
+
|
|
439
|
+
const digest = await getHashedSignaturePayload(consensusPayload, SignatureDomainSeparator.blockAttestation);
|
|
440
|
+
|
|
441
|
+
const blobs = await Blob.getBlobs(block.body.toBlobFields());
|
|
442
|
+
const proposeTxArgs = {
|
|
443
|
+
header: block.header.toBuffer(),
|
|
444
|
+
archive: block.archive.root.toBuffer(),
|
|
445
|
+
blockHash: (await block.header.hash()).toBuffer(),
|
|
446
|
+
body: block.body.toBuffer(),
|
|
447
|
+
blobs,
|
|
448
|
+
attestations,
|
|
449
|
+
txHashes: txHashes ?? [],
|
|
450
|
+
};
|
|
451
|
+
|
|
452
|
+
// @note This will make sure that we are passing the checks for our header ASSUMING that the data is also made available
|
|
453
|
+
// This means that we can avoid the simulation issues in later checks.
|
|
454
|
+
// By simulation issue, I mean the fact that the block.timestamp is equal to the last block, not the next, which
|
|
455
|
+
// make time consistency checks break.
|
|
456
|
+
const ts = await this.validateBlockForSubmission(block.header, {
|
|
457
|
+
digest: digest.toBuffer(),
|
|
458
|
+
signatures: attestations ?? [],
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
this.log.debug(`Submitting propose transaction`);
|
|
462
|
+
await this.addProposeTx(block, proposeTxArgs, opts, ts);
|
|
463
|
+
return true;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
/** Enqueues a claimEpochProofRight transaction to submit a chosen prover quote for the previous epoch. */
|
|
467
|
+
public enqueueClaimEpochProofRight(proofQuote: EpochProofQuote): boolean {
|
|
468
|
+
const timer = new Timer();
|
|
469
|
+
this.addRequest({
|
|
470
|
+
action: 'claim',
|
|
471
|
+
request: {
|
|
472
|
+
to: this.rollupContract.address,
|
|
473
|
+
data: encodeFunctionData({
|
|
474
|
+
abi: RollupAbi,
|
|
475
|
+
functionName: 'claimEpochProofRight',
|
|
476
|
+
args: [proofQuote.toViemArgs()],
|
|
477
|
+
}),
|
|
478
|
+
},
|
|
479
|
+
lastValidL2Slot: this.getCurrentL2Slot(),
|
|
480
|
+
onResult: (_request, result) => {
|
|
481
|
+
if (!result) {
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
484
|
+
const { receipt, stats } = result;
|
|
485
|
+
if (receipt.status === 'success') {
|
|
486
|
+
const publishStats: L1PublishStats = {
|
|
487
|
+
gasPrice: receipt.effectiveGasPrice,
|
|
488
|
+
gasUsed: receipt.gasUsed,
|
|
489
|
+
transactionHash: receipt.transactionHash,
|
|
490
|
+
blobDataGas: 0n,
|
|
491
|
+
blobGasUsed: 0n,
|
|
492
|
+
...pick(stats!, 'calldataGas', 'calldataSize', 'sender'),
|
|
493
|
+
};
|
|
494
|
+
this.log.verbose(`Submitted claim epoch proof right to L1 rollup contract`, {
|
|
495
|
+
...publishStats,
|
|
496
|
+
...proofQuote.toInspect(),
|
|
497
|
+
});
|
|
498
|
+
this.metrics.recordClaimEpochProofRightTx(timer.ms(), publishStats);
|
|
499
|
+
} else {
|
|
500
|
+
this.metrics.recordFailedTx('claimEpochProofRight');
|
|
501
|
+
// TODO: Get the error message from the reverted tx
|
|
502
|
+
this.log.error(`Claim epoch proof right tx reverted`, {
|
|
503
|
+
txHash: receipt.transactionHash,
|
|
504
|
+
...proofQuote.toInspect(),
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
},
|
|
508
|
+
});
|
|
509
|
+
return true;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* Calling `interrupt` will cause any in progress call to `publishRollup` to return `false` asap.
|
|
514
|
+
* Be warned, the call may return false even if the tx subsequently gets successfully mined.
|
|
515
|
+
* In practice this shouldn't matter, as we'll only ever be calling `interrupt` when we know it's going to fail.
|
|
516
|
+
* A call to `restart` is required before you can continue publishing.
|
|
517
|
+
*/
|
|
518
|
+
public interrupt() {
|
|
519
|
+
this.interrupted = true;
|
|
520
|
+
this.l1TxUtils.interrupt();
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
/** Restarts the publisher after calling `interrupt`. */
|
|
524
|
+
public restart() {
|
|
525
|
+
this.interrupted = false;
|
|
526
|
+
this.l1TxUtils.restart();
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
private async prepareProposeTx(encodedData: L1ProcessArgs, timestamp: bigint) {
|
|
530
|
+
const kzg = Blob.getViemKzgInstance();
|
|
531
|
+
const blobInput = Blob.getEthBlobEvaluationInputs(encodedData.blobs);
|
|
532
|
+
this.log.debug('Validating blob input', { blobInput });
|
|
533
|
+
const blobEvaluationGas = await this.l1TxUtils
|
|
534
|
+
.estimateGas(
|
|
535
|
+
this.l1TxUtils.walletClient.account,
|
|
536
|
+
{
|
|
537
|
+
to: this.rollupContract.address,
|
|
538
|
+
data: encodeFunctionData({
|
|
539
|
+
abi: RollupAbi,
|
|
540
|
+
functionName: 'validateBlobs',
|
|
541
|
+
args: [blobInput],
|
|
542
|
+
}),
|
|
543
|
+
},
|
|
544
|
+
{},
|
|
545
|
+
{
|
|
546
|
+
blobs: encodedData.blobs.map(b => b.data),
|
|
547
|
+
kzg,
|
|
548
|
+
},
|
|
549
|
+
)
|
|
550
|
+
.catch(err => {
|
|
551
|
+
const { message, metaMessages } = formatViemError(err);
|
|
552
|
+
this.log.error(`Failed to validate blobs`, message, { metaMessages });
|
|
553
|
+
throw new Error('Failed to validate blobs');
|
|
554
|
+
});
|
|
555
|
+
|
|
556
|
+
const attestations = encodedData.attestations
|
|
557
|
+
? encodedData.attestations.map(attest => attest.toViemSignature())
|
|
558
|
+
: [];
|
|
559
|
+
const txHashes = encodedData.txHashes ? encodedData.txHashes.map(txHash => txHash.toString()) : [];
|
|
560
|
+
const args = [
|
|
561
|
+
{
|
|
562
|
+
header: `0x${encodedData.header.toString('hex')}`,
|
|
563
|
+
archive: `0x${encodedData.archive.toString('hex')}`,
|
|
564
|
+
oracleInput: {
|
|
565
|
+
// We are currently not modifying these. See #9963
|
|
566
|
+
feeAssetPriceModifier: 0n,
|
|
567
|
+
provingCostModifier: 0n,
|
|
568
|
+
},
|
|
569
|
+
blockHash: `0x${encodedData.blockHash.toString('hex')}`,
|
|
570
|
+
txHashes,
|
|
571
|
+
},
|
|
572
|
+
attestations,
|
|
573
|
+
// TODO(#9101): Extract blobs from beacon chain => calldata will only contain what's needed to verify blob and body input can be removed
|
|
574
|
+
`0x${encodedData.body.toString('hex')}`,
|
|
575
|
+
blobInput,
|
|
576
|
+
] as const;
|
|
577
|
+
|
|
578
|
+
const rollupData = encodeFunctionData({
|
|
579
|
+
abi: RollupAbi,
|
|
580
|
+
functionName: 'propose',
|
|
581
|
+
args,
|
|
582
|
+
});
|
|
583
|
+
|
|
584
|
+
const forwarderData = encodeFunctionData({
|
|
585
|
+
abi: ForwarderAbi,
|
|
586
|
+
functionName: 'forward',
|
|
587
|
+
args: [[this.rollupContract.address], [rollupData]],
|
|
588
|
+
});
|
|
589
|
+
|
|
590
|
+
const simulationResult = await this.l1TxUtils
|
|
591
|
+
.simulateGasUsed(
|
|
592
|
+
{
|
|
593
|
+
to: this.getForwarderAddress().toString(),
|
|
594
|
+
data: forwarderData,
|
|
595
|
+
gas: SequencerPublisher.PROPOSE_GAS_GUESS,
|
|
596
|
+
},
|
|
597
|
+
{
|
|
598
|
+
// @note we add 1n to the timestamp because geth implementation doesn't like simulation timestamp to be equal to the current block timestamp
|
|
599
|
+
time: timestamp + 1n,
|
|
600
|
+
// @note reth should have a 30m gas limit per block but throws errors that this tx is beyond limit
|
|
601
|
+
gasLimit: SequencerPublisher.PROPOSE_GAS_GUESS * 2n,
|
|
602
|
+
},
|
|
603
|
+
[
|
|
604
|
+
{
|
|
605
|
+
address: this.rollupContract.address,
|
|
606
|
+
// @note we override checkBlob to false since blobs are not part simulate()
|
|
607
|
+
stateDiff: [
|
|
608
|
+
{
|
|
609
|
+
slot: toHex(RollupContract.checkBlobStorageSlot, true),
|
|
610
|
+
value: toHex(0n, true),
|
|
611
|
+
},
|
|
612
|
+
],
|
|
613
|
+
},
|
|
614
|
+
],
|
|
615
|
+
{
|
|
616
|
+
// @note fallback gas estimate to use if the node doesn't support simulation API
|
|
617
|
+
fallbackGasEstimate: SequencerPublisher.PROPOSE_GAS_GUESS,
|
|
618
|
+
},
|
|
619
|
+
)
|
|
620
|
+
.catch(err => {
|
|
621
|
+
const { message, metaMessages } = formatViemError(err);
|
|
622
|
+
this.log.error(`Failed to simulate gas used`, message, { metaMessages });
|
|
623
|
+
throw new Error('Failed to simulate gas used');
|
|
624
|
+
});
|
|
625
|
+
|
|
626
|
+
return { args, blobEvaluationGas, rollupData, simulationResult };
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
private async addProposeTx(
|
|
630
|
+
block: L2Block,
|
|
631
|
+
encodedData: L1ProcessArgs,
|
|
632
|
+
opts: { txTimeoutAt?: Date } = {},
|
|
633
|
+
timestamp: bigint,
|
|
634
|
+
): Promise<void> {
|
|
635
|
+
const timer = new Timer();
|
|
636
|
+
const kzg = Blob.getViemKzgInstance();
|
|
637
|
+
const { rollupData, simulationResult, blobEvaluationGas } = await this.prepareProposeTx(encodedData, timestamp);
|
|
638
|
+
const startBlock = await this.l1TxUtils.getBlockNumber();
|
|
639
|
+
const blockHash = await block.hash();
|
|
640
|
+
|
|
641
|
+
return this.addRequest({
|
|
642
|
+
action: 'propose',
|
|
643
|
+
request: {
|
|
644
|
+
to: this.rollupContract.address,
|
|
645
|
+
data: rollupData,
|
|
646
|
+
},
|
|
647
|
+
lastValidL2Slot: block.header.globalVariables.slotNumber.toBigInt(),
|
|
648
|
+
gasConfig: {
|
|
649
|
+
...opts,
|
|
650
|
+
gasLimit: this.l1TxUtils.bumpGasLimit(simulationResult + blobEvaluationGas),
|
|
651
|
+
},
|
|
652
|
+
blobConfig: {
|
|
653
|
+
blobs: encodedData.blobs.map(b => b.data),
|
|
654
|
+
kzg,
|
|
655
|
+
},
|
|
656
|
+
onResult: (request, result) => {
|
|
657
|
+
if (!result) {
|
|
658
|
+
return;
|
|
659
|
+
}
|
|
660
|
+
const { receipt, stats, errorMsg } = result;
|
|
661
|
+
if (receipt.status === 'success') {
|
|
662
|
+
const endBlock = receipt.blockNumber;
|
|
663
|
+
const inclusionBlocks = Number(endBlock - startBlock);
|
|
664
|
+
const publishStats: L1PublishBlockStats = {
|
|
665
|
+
gasPrice: receipt.effectiveGasPrice,
|
|
666
|
+
gasUsed: receipt.gasUsed,
|
|
667
|
+
blobGasUsed: receipt.blobGasUsed ?? 0n,
|
|
668
|
+
blobDataGas: receipt.blobGasPrice ?? 0n,
|
|
669
|
+
transactionHash: receipt.transactionHash,
|
|
670
|
+
...pick(stats!, 'calldataGas', 'calldataSize', 'sender'),
|
|
671
|
+
...block.getStats(),
|
|
672
|
+
eventName: 'rollup-published-to-l1',
|
|
673
|
+
blobCount: encodedData.blobs.length,
|
|
674
|
+
inclusionBlocks,
|
|
675
|
+
};
|
|
676
|
+
this.log.verbose(`Published L2 block to L1 rollup contract`, { ...stats, ...block.getStats() });
|
|
677
|
+
this.metrics.recordProcessBlockTx(timer.ms(), publishStats);
|
|
678
|
+
|
|
679
|
+
// Send the blobs to the blob sink
|
|
680
|
+
this.sendBlobsToBlobSink(receipt.blockHash, encodedData.blobs).catch(_err => {
|
|
681
|
+
this.log.error('Failed to send blobs to blob sink');
|
|
682
|
+
});
|
|
683
|
+
|
|
684
|
+
return true;
|
|
685
|
+
} else {
|
|
686
|
+
this.metrics.recordFailedTx('process');
|
|
687
|
+
|
|
688
|
+
this.log.error(`Rollup process tx reverted. ${errorMsg ?? 'No error message'}`, undefined, {
|
|
689
|
+
...block.getStats(),
|
|
690
|
+
txHash: receipt.transactionHash,
|
|
691
|
+
blockHash,
|
|
692
|
+
slotNumber: block.header.globalVariables.slotNumber.toBigInt(),
|
|
693
|
+
});
|
|
694
|
+
}
|
|
695
|
+
},
|
|
696
|
+
});
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
/**
|
|
700
|
+
* Send blobs to the blob sink
|
|
701
|
+
*
|
|
702
|
+
* If a blob sink url is configured, then we send blobs to the blob sink
|
|
703
|
+
* - for now we use the blockHash as the identifier for the blobs;
|
|
704
|
+
* In the future this will move to be the beacon block id - which takes a bit more work
|
|
705
|
+
* to calculate and will need to be mocked in e2e tests
|
|
706
|
+
*/
|
|
707
|
+
protected sendBlobsToBlobSink(blockHash: string, blobs: Blob[]): Promise<boolean> {
|
|
708
|
+
return this.blobSinkClient.sendBlobsToBlobSink(blockHash, blobs);
|
|
709
|
+
}
|
|
710
|
+
}
|