@aztec/sequencer-client 0.0.0-test.1 → 0.0.1-commit.5daedc8
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/index.d.ts +1 -1
- package/dest/client/sequencer-client.d.ts +26 -26
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +66 -51
- package/dest/config.d.ts +7 -15
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +59 -54
- package/dest/global_variable_builder/global_builder.d.ts +12 -10
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +43 -35
- package/dest/global_variable_builder/index.d.ts +1 -1
- 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 +9 -9
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +24 -17
- package/dest/publisher/index.d.ts +3 -1
- package/dest/publisher/index.d.ts.map +1 -1
- package/dest/publisher/index.js +3 -0
- package/dest/publisher/sequencer-publisher-factory.d.ts +43 -0
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -0
- package/dest/publisher/sequencer-publisher-factory.js +51 -0
- package/dest/publisher/sequencer-publisher-metrics.d.ts +3 -2
- package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-metrics.js +37 -2
- package/dest/publisher/sequencer-publisher.d.ts +112 -73
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +681 -236
- package/dest/sequencer/block_builder.d.ts +27 -0
- package/dest/sequencer/block_builder.d.ts.map +1 -0
- package/dest/sequencer/block_builder.js +134 -0
- package/dest/sequencer/config.d.ts +6 -1
- package/dest/sequencer/config.d.ts.map +1 -1
- package/dest/sequencer/errors.d.ts +11 -0
- package/dest/sequencer/errors.d.ts.map +1 -0
- package/dest/sequencer/errors.js +15 -0
- package/dest/sequencer/index.d.ts +2 -2
- package/dest/sequencer/index.d.ts.map +1 -1
- package/dest/sequencer/index.js +1 -1
- package/dest/sequencer/metrics.d.ts +28 -12
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +122 -50
- package/dest/sequencer/sequencer.d.ts +122 -91
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +723 -370
- package/dest/sequencer/timetable.d.ts +33 -21
- package/dest/sequencer/timetable.d.ts.map +1 -1
- package/dest/sequencer/timetable.js +57 -30
- package/dest/sequencer/utils.d.ts +12 -36
- package/dest/sequencer/utils.d.ts.map +1 -1
- package/dest/sequencer/utils.js +9 -47
- package/dest/test/index.d.ts +8 -1
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/index.js +0 -4
- package/dest/tx_validator/nullifier_cache.d.ts +1 -3
- package/dest/tx_validator/nullifier_cache.d.ts.map +1 -1
- package/dest/tx_validator/tx_validator_factory.d.ts +10 -11
- package/dest/tx_validator/tx_validator_factory.d.ts.map +1 -1
- package/dest/tx_validator/tx_validator_factory.js +27 -24
- package/package.json +45 -45
- package/src/client/sequencer-client.ts +95 -85
- package/src/config.ts +67 -61
- package/src/global_variable_builder/global_builder.ts +52 -27
- package/src/index.ts +6 -2
- package/src/publisher/config.ts +34 -24
- package/src/publisher/index.ts +4 -0
- package/src/publisher/sequencer-publisher-factory.ts +91 -0
- package/src/publisher/sequencer-publisher-metrics.ts +24 -2
- package/src/publisher/sequencer-publisher.ts +817 -268
- package/src/sequencer/block_builder.ts +222 -0
- package/src/sequencer/config.ts +7 -0
- package/src/sequencer/errors.ts +21 -0
- package/src/sequencer/index.ts +1 -1
- package/src/sequencer/metrics.ts +156 -53
- package/src/sequencer/sequencer.ts +918 -423
- package/src/sequencer/timetable.ts +98 -33
- package/src/sequencer/utils.ts +17 -58
- package/src/test/index.ts +11 -4
- package/src/tx_validator/tx_validator_factory.ts +44 -32
- package/dest/sequencer/allowed.d.ts +0 -3
- package/dest/sequencer/allowed.d.ts.map +0 -1
- package/dest/sequencer/allowed.js +0 -27
- package/dest/slasher/factory.d.ts +0 -7
- package/dest/slasher/factory.d.ts.map +0 -1
- package/dest/slasher/factory.js +0 -8
- package/dest/slasher/index.d.ts +0 -3
- package/dest/slasher/index.d.ts.map +0 -1
- package/dest/slasher/index.js +0 -2
- package/dest/slasher/slasher_client.d.ts +0 -75
- package/dest/slasher/slasher_client.d.ts.map +0 -1
- package/dest/slasher/slasher_client.js +0 -132
- package/dest/tx_validator/archive_cache.d.ts +0 -14
- package/dest/tx_validator/archive_cache.d.ts.map +0 -1
- package/dest/tx_validator/archive_cache.js +0 -22
- package/dest/tx_validator/gas_validator.d.ts +0 -14
- package/dest/tx_validator/gas_validator.d.ts.map +0 -1
- package/dest/tx_validator/gas_validator.js +0 -78
- package/dest/tx_validator/phases_validator.d.ts +0 -12
- package/dest/tx_validator/phases_validator.d.ts.map +0 -1
- package/dest/tx_validator/phases_validator.js +0 -80
- package/dest/tx_validator/test_utils.d.ts +0 -23
- package/dest/tx_validator/test_utils.d.ts.map +0 -1
- package/dest/tx_validator/test_utils.js +0 -26
- package/src/sequencer/allowed.ts +0 -36
- package/src/slasher/factory.ts +0 -15
- package/src/slasher/index.ts +0 -2
- package/src/slasher/slasher_client.ts +0 -193
- package/src/tx_validator/archive_cache.ts +0 -28
- package/src/tx_validator/gas_validator.ts +0 -101
- package/src/tx_validator/phases_validator.ts +0 -98
- package/src/tx_validator/test_utils.ts +0 -48
|
@@ -1,74 +1,97 @@
|
|
|
1
|
-
import { Blob } from '@aztec/blob-lib';
|
|
1
|
+
import { Blob, getBlobsPerL1Block, getPrefixedEthBlobCommitments } from '@aztec/blob-lib';
|
|
2
2
|
import { createBlobSinkClient } from '@aztec/blob-sink/client';
|
|
3
|
-
import { FormattedViemError, RollupContract, formatViemError } from '@aztec/ethereum';
|
|
4
|
-
import {
|
|
3
|
+
import { FormattedViemError, MULTI_CALL_3_ADDRESS, Multicall3, RollupContract, WEI_CONST, formatViemError, tryExtractEvent } from '@aztec/ethereum';
|
|
4
|
+
import { sumBigint } from '@aztec/foundation/bigint';
|
|
5
|
+
import { toHex as toPaddedHex } from '@aztec/foundation/bigint-buffer';
|
|
6
|
+
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
5
7
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
8
|
+
import { Signature } from '@aztec/foundation/eth-signature';
|
|
6
9
|
import { createLogger } from '@aztec/foundation/log';
|
|
10
|
+
import { bufferToHex } from '@aztec/foundation/string';
|
|
7
11
|
import { Timer } from '@aztec/foundation/timer';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
12
|
+
import { EmpireBaseAbi, ErrorsAbi, RollupAbi } from '@aztec/l1-artifacts';
|
|
13
|
+
import { encodeSlashConsensusVotes } from '@aztec/slasher';
|
|
14
|
+
import { CommitteeAttestation, CommitteeAttestationsAndSigners } from '@aztec/stdlib/block';
|
|
10
15
|
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
11
|
-
import
|
|
12
|
-
import { encodeFunctionData } from 'viem';
|
|
16
|
+
import { encodeFunctionData, toHex } from 'viem';
|
|
13
17
|
import { SequencerPublisherMetrics } from './sequencer-publisher-metrics.js';
|
|
14
|
-
export
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
export const Actions = [
|
|
19
|
+
'invalidate-by-invalid-attestation',
|
|
20
|
+
'invalidate-by-insufficient-attestations',
|
|
21
|
+
'propose',
|
|
22
|
+
'governance-signal',
|
|
23
|
+
'empire-slashing-signal',
|
|
24
|
+
'create-empire-payload',
|
|
25
|
+
'execute-empire-payload',
|
|
26
|
+
'vote-offenses',
|
|
27
|
+
'execute-slash'
|
|
28
|
+
];
|
|
29
|
+
// Sorting for actions such that invalidations go before proposals, and proposals go before votes
|
|
30
|
+
export const compareActions = (a, b)=>Actions.indexOf(a) - Actions.indexOf(b);
|
|
19
31
|
export class SequencerPublisher {
|
|
20
|
-
|
|
32
|
+
config;
|
|
33
|
+
interrupted;
|
|
21
34
|
metrics;
|
|
22
35
|
epochCache;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
slashingLog = createLogger('sequencer:publisher:slashing');
|
|
28
|
-
slashingProposerAddress;
|
|
29
|
-
getSlashPayload = undefined;
|
|
30
|
-
myLastVotes = {
|
|
31
|
-
[0]: 0n,
|
|
32
|
-
[1]: 0n
|
|
33
|
-
};
|
|
34
|
-
log = createLogger('sequencer:publisher');
|
|
36
|
+
governanceLog;
|
|
37
|
+
slashingLog;
|
|
38
|
+
lastActions;
|
|
39
|
+
log;
|
|
35
40
|
ethereumSlotDuration;
|
|
36
41
|
blobSinkClient;
|
|
42
|
+
/** Address to use for simulations in fisherman mode (actual proposer's address) */ proposerAddressForSimulation;
|
|
37
43
|
// @note - with blobs, the below estimate seems too large.
|
|
38
44
|
// Total used for full block from int_l1_pub e2e test: 1m (of which 86k is 1x blob)
|
|
39
45
|
// Total used for emptier block from above test: 429k (of which 84k is 1x blob)
|
|
40
46
|
static PROPOSE_GAS_GUESS = 12_000_000n;
|
|
47
|
+
// A CALL to a cold address is 2700 gas
|
|
48
|
+
static MULTICALL_OVERHEAD_GAS_GUESS = 5000n;
|
|
49
|
+
// Gas report for VotingWithSigTest shows a max gas of 100k, but we've seen it cost 700k+ in testnet
|
|
50
|
+
static VOTE_GAS_GUESS = 800_000n;
|
|
41
51
|
l1TxUtils;
|
|
42
52
|
rollupContract;
|
|
43
53
|
govProposerContract;
|
|
44
54
|
slashingProposerContract;
|
|
45
|
-
|
|
55
|
+
slashFactoryContract;
|
|
56
|
+
requests;
|
|
46
57
|
constructor(config, deps){
|
|
58
|
+
this.config = config;
|
|
59
|
+
this.interrupted = false;
|
|
60
|
+
this.governanceLog = createLogger('sequencer:publisher:governance');
|
|
61
|
+
this.slashingLog = createLogger('sequencer:publisher:slashing');
|
|
62
|
+
this.lastActions = {};
|
|
63
|
+
this.requests = [];
|
|
64
|
+
this.log = deps.log ?? createLogger('sequencer:publisher');
|
|
47
65
|
this.ethereumSlotDuration = BigInt(config.ethereumSlotDuration);
|
|
48
66
|
this.epochCache = deps.epochCache;
|
|
49
|
-
this.
|
|
67
|
+
this.lastActions = deps.lastActions;
|
|
68
|
+
this.blobSinkClient = deps.blobSinkClient ?? createBlobSinkClient(config, {
|
|
69
|
+
logger: createLogger('sequencer:blob-sink:client')
|
|
70
|
+
});
|
|
50
71
|
const telemetry = deps.telemetry ?? getTelemetryClient();
|
|
51
|
-
this.metrics = new SequencerPublisherMetrics(telemetry, 'SequencerPublisher');
|
|
72
|
+
this.metrics = deps.metrics ?? new SequencerPublisherMetrics(telemetry, 'SequencerPublisher');
|
|
52
73
|
this.l1TxUtils = deps.l1TxUtils;
|
|
53
74
|
this.rollupContract = deps.rollupContract;
|
|
54
|
-
this.forwarderContract = deps.forwarderContract;
|
|
55
75
|
this.govProposerContract = deps.governanceProposerContract;
|
|
56
76
|
this.slashingProposerContract = deps.slashingProposerContract;
|
|
77
|
+
this.rollupContract.listenToSlasherChanged(async ()=>{
|
|
78
|
+
this.log.info('Slashing proposer changed');
|
|
79
|
+
const newSlashingProposer = await this.rollupContract.getSlashingProposer();
|
|
80
|
+
this.slashingProposerContract = newSlashingProposer;
|
|
81
|
+
});
|
|
82
|
+
this.slashFactoryContract = deps.slashFactoryContract;
|
|
57
83
|
}
|
|
58
|
-
|
|
59
|
-
this.
|
|
60
|
-
}
|
|
61
|
-
getForwarderAddress() {
|
|
62
|
-
return EthAddress.fromString(this.forwarderContract.getAddress());
|
|
84
|
+
getRollupContract() {
|
|
85
|
+
return this.rollupContract;
|
|
63
86
|
}
|
|
64
87
|
getSenderAddress() {
|
|
65
|
-
return
|
|
66
|
-
}
|
|
67
|
-
getGovernancePayload() {
|
|
68
|
-
return this.governancePayload;
|
|
88
|
+
return this.l1TxUtils.getSenderAddress();
|
|
69
89
|
}
|
|
70
|
-
|
|
71
|
-
|
|
90
|
+
/**
|
|
91
|
+
* Sets the proposer address to use for simulations in fisherman mode.
|
|
92
|
+
* @param proposerAddress - The actual proposer's address to use for balance lookups in simulations
|
|
93
|
+
*/ setProposerAddressForSimulation(proposerAddress) {
|
|
94
|
+
this.proposerAddressForSimulation = proposerAddress;
|
|
72
95
|
}
|
|
73
96
|
addRequest(request) {
|
|
74
97
|
this.requests.push(request);
|
|
@@ -77,6 +100,15 @@ export class SequencerPublisher {
|
|
|
77
100
|
return this.epochCache.getEpochAndSlotNow().slot;
|
|
78
101
|
}
|
|
79
102
|
/**
|
|
103
|
+
* Clears all pending requests without sending them.
|
|
104
|
+
*/ clearPendingRequests() {
|
|
105
|
+
const count = this.requests.length;
|
|
106
|
+
this.requests = [];
|
|
107
|
+
if (count > 0) {
|
|
108
|
+
this.log.debug(`Cleared ${count} pending request(s)`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
80
112
|
* Sends all requests that are still valid.
|
|
81
113
|
* @returns one of:
|
|
82
114
|
* - A receipt and stats if the tx succeeded
|
|
@@ -91,8 +123,10 @@ export class SequencerPublisher {
|
|
|
91
123
|
return undefined;
|
|
92
124
|
}
|
|
93
125
|
const currentL2Slot = this.getCurrentL2Slot();
|
|
94
|
-
this.log.debug(`
|
|
126
|
+
this.log.debug(`Sending requests on L2 slot ${currentL2Slot}`);
|
|
95
127
|
const validRequests = requestsToProcess.filter((request)=>request.lastValidL2Slot >= currentL2Slot);
|
|
128
|
+
const validActions = validRequests.map((x)=>x.action);
|
|
129
|
+
const expiredActions = requestsToProcess.filter((request)=>request.lastValidL2Slot < currentL2Slot).map((x)=>x.action);
|
|
96
130
|
if (validRequests.length !== requestsToProcess.length) {
|
|
97
131
|
this.log.warn(`Some requests were expired for slot ${currentL2Slot}`, {
|
|
98
132
|
validRequests: validRequests.map((request)=>({
|
|
@@ -109,56 +143,98 @@ export class SequencerPublisher {
|
|
|
109
143
|
this.log.debug(`No valid requests to send`);
|
|
110
144
|
return undefined;
|
|
111
145
|
}
|
|
112
|
-
// @note - we can only have one
|
|
146
|
+
// @note - we can only have one blob config per bundle
|
|
113
147
|
// find requests with gas and blob configs
|
|
114
148
|
// See https://github.com/AztecProtocol/aztec-packages/issues/11513
|
|
115
|
-
const gasConfigs = requestsToProcess.filter((request)=>request.gasConfig);
|
|
116
|
-
const blobConfigs = requestsToProcess.filter((request)=>request.blobConfig);
|
|
117
|
-
if (
|
|
118
|
-
throw new Error('Multiple
|
|
149
|
+
const gasConfigs = requestsToProcess.filter((request)=>request.gasConfig).map((request)=>request.gasConfig);
|
|
150
|
+
const blobConfigs = requestsToProcess.filter((request)=>request.blobConfig).map((request)=>request.blobConfig);
|
|
151
|
+
if (blobConfigs.length > 1) {
|
|
152
|
+
throw new Error('Multiple blob configs found');
|
|
119
153
|
}
|
|
120
|
-
const
|
|
121
|
-
|
|
154
|
+
const blobConfig = blobConfigs[0];
|
|
155
|
+
// Merge gasConfigs. Yields the sum of gasLimits, and the earliest txTimeoutAt, or undefined if no gasConfig sets them.
|
|
156
|
+
const gasLimits = gasConfigs.map((g)=>g?.gasLimit).filter((g)=>g !== undefined);
|
|
157
|
+
const gasLimit = gasLimits.length > 0 ? sumBigint(gasLimits) : undefined; // sum
|
|
158
|
+
const txTimeoutAts = gasConfigs.map((g)=>g?.txTimeoutAt).filter((g)=>g !== undefined);
|
|
159
|
+
const txTimeoutAt = txTimeoutAts.length > 0 ? new Date(Math.min(...txTimeoutAts.map((g)=>g.getTime()))) : undefined; // earliest
|
|
160
|
+
const txConfig = {
|
|
161
|
+
gasLimit,
|
|
162
|
+
txTimeoutAt
|
|
163
|
+
};
|
|
164
|
+
// Sort the requests so that proposals always go first
|
|
165
|
+
// This ensures the committee gets precomputed correctly
|
|
166
|
+
validRequests.sort((a, b)=>compareActions(a.action, b.action));
|
|
122
167
|
try {
|
|
123
168
|
this.log.debug('Forwarding transactions', {
|
|
124
|
-
validRequests: validRequests.map((request)=>request.action)
|
|
169
|
+
validRequests: validRequests.map((request)=>request.action),
|
|
170
|
+
txConfig
|
|
125
171
|
});
|
|
126
|
-
const result = await
|
|
127
|
-
this.callbackBundledTransactions(validRequests, result);
|
|
128
|
-
return
|
|
172
|
+
const result = await Multicall3.forward(validRequests.map((request)=>request.request), this.l1TxUtils, txConfig, blobConfig, this.rollupContract.address, this.log);
|
|
173
|
+
const { successfulActions = [], failedActions = [] } = this.callbackBundledTransactions(validRequests, result);
|
|
174
|
+
return {
|
|
175
|
+
result,
|
|
176
|
+
expiredActions,
|
|
177
|
+
sentActions: validActions,
|
|
178
|
+
successfulActions,
|
|
179
|
+
failedActions
|
|
180
|
+
};
|
|
129
181
|
} catch (err) {
|
|
130
182
|
const viemError = formatViemError(err);
|
|
131
183
|
this.log.error(`Failed to publish bundled transactions`, viemError);
|
|
132
184
|
return undefined;
|
|
133
185
|
} finally{
|
|
134
186
|
try {
|
|
135
|
-
this.metrics.recordSenderBalance(await this.l1TxUtils.getSenderBalance(), this.l1TxUtils.getSenderAddress());
|
|
187
|
+
this.metrics.recordSenderBalance(await this.l1TxUtils.getSenderBalance(), this.l1TxUtils.getSenderAddress().toString());
|
|
136
188
|
} catch (err) {
|
|
137
189
|
this.log.warn(`Failed to record balance after sending tx: ${err}`);
|
|
138
190
|
}
|
|
139
191
|
}
|
|
140
192
|
}
|
|
141
193
|
callbackBundledTransactions(requests, result) {
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
194
|
+
const actionsListStr = requests.map((r)=>r.action).join(', ');
|
|
195
|
+
if (result instanceof FormattedViemError) {
|
|
196
|
+
this.log.error(`Failed to publish bundled transactions (${actionsListStr})`, result);
|
|
197
|
+
return {
|
|
198
|
+
failedActions: requests.map((r)=>r.action)
|
|
199
|
+
};
|
|
200
|
+
} else {
|
|
201
|
+
this.log.verbose(`Published bundled transactions (${actionsListStr})`, {
|
|
202
|
+
result,
|
|
203
|
+
requests
|
|
204
|
+
});
|
|
205
|
+
const successfulActions = [];
|
|
206
|
+
const failedActions = [];
|
|
207
|
+
for (const request of requests){
|
|
208
|
+
if (request.checkSuccess(request.request, result)) {
|
|
209
|
+
successfulActions.push(request.action);
|
|
210
|
+
} else {
|
|
211
|
+
failedActions.push(request.action);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return {
|
|
215
|
+
successfulActions,
|
|
216
|
+
failedActions
|
|
217
|
+
};
|
|
147
218
|
}
|
|
148
219
|
}
|
|
149
220
|
/**
|
|
150
221
|
* @notice Will call `canProposeAtNextEthBlock` to make sure that it is possible to propose
|
|
151
222
|
* @param tipArchive - The archive to check
|
|
152
223
|
* @returns The slot and block number if it is possible to propose, undefined otherwise
|
|
153
|
-
*/ canProposeAtNextEthBlock(tipArchive) {
|
|
224
|
+
*/ canProposeAtNextEthBlock(tipArchive, msgSender, opts = {}) {
|
|
225
|
+
// TODO: #14291 - should loop through multiple keys to check if any of them can propose
|
|
154
226
|
const ignoredErrors = [
|
|
155
227
|
'SlotAlreadyInChain',
|
|
156
228
|
'InvalidProposer',
|
|
157
229
|
'InvalidArchive'
|
|
158
230
|
];
|
|
159
|
-
return this.rollupContract.canProposeAtNextEthBlock(tipArchive
|
|
231
|
+
return this.rollupContract.canProposeAtNextEthBlock(tipArchive.toBuffer(), msgSender.toString(), Number(this.ethereumSlotDuration), {
|
|
232
|
+
forcePendingCheckpointNumber: opts.forcePendingBlockNumber
|
|
233
|
+
}).catch((err)=>{
|
|
160
234
|
if (err instanceof FormattedViemError && ignoredErrors.find((e)=>err.message.includes(e))) {
|
|
161
|
-
this.log.
|
|
235
|
+
this.log.warn(`Failed canProposeAtTime check with ${ignoredErrors.find((e)=>err.message.includes(e))}`, {
|
|
236
|
+
error: err.message
|
|
237
|
+
});
|
|
162
238
|
} else {
|
|
163
239
|
this.log.error(err.name, err);
|
|
164
240
|
}
|
|
@@ -166,137 +242,479 @@ export class SequencerPublisher {
|
|
|
166
242
|
});
|
|
167
243
|
}
|
|
168
244
|
/**
|
|
169
|
-
* @notice Will
|
|
245
|
+
* @notice Will simulate `validateHeader` to make sure that the block header is valid
|
|
246
|
+
* @dev This is a convenience function that can be used by the sequencer to validate a "partial" header.
|
|
247
|
+
* It will throw if the block header is invalid.
|
|
248
|
+
* @param header - The block header to validate
|
|
249
|
+
*/ async validateBlockHeader(header, opts) {
|
|
250
|
+
const flags = {
|
|
251
|
+
ignoreDA: true,
|
|
252
|
+
ignoreSignatures: true
|
|
253
|
+
};
|
|
254
|
+
const args = [
|
|
255
|
+
header.toViem(),
|
|
256
|
+
CommitteeAttestationsAndSigners.empty().getPackedAttestations(),
|
|
257
|
+
[],
|
|
258
|
+
Signature.empty().toViemSignature(),
|
|
259
|
+
`0x${'0'.repeat(64)}`,
|
|
260
|
+
header.contentCommitment.blobsHash.toString(),
|
|
261
|
+
flags
|
|
262
|
+
];
|
|
263
|
+
const ts = BigInt((await this.l1TxUtils.getBlock()).timestamp + this.ethereumSlotDuration);
|
|
264
|
+
const stateOverrides = await this.rollupContract.makePendingCheckpointNumberOverride(opts?.forcePendingBlockNumber);
|
|
265
|
+
let balance = 0n;
|
|
266
|
+
if (this.config.fishermanMode) {
|
|
267
|
+
// In fisherman mode, we can't know where the proposer is publishing from
|
|
268
|
+
// so we just add sufficient balance to the multicall3 address
|
|
269
|
+
balance = 10n * WEI_CONST * WEI_CONST; // 10 ETH
|
|
270
|
+
} else {
|
|
271
|
+
balance = await this.l1TxUtils.getSenderBalance();
|
|
272
|
+
}
|
|
273
|
+
stateOverrides.push({
|
|
274
|
+
address: MULTI_CALL_3_ADDRESS,
|
|
275
|
+
balance
|
|
276
|
+
});
|
|
277
|
+
await this.l1TxUtils.simulate({
|
|
278
|
+
to: this.rollupContract.address,
|
|
279
|
+
data: encodeFunctionData({
|
|
280
|
+
abi: RollupAbi,
|
|
281
|
+
functionName: 'validateHeaderWithAttestations',
|
|
282
|
+
args
|
|
283
|
+
}),
|
|
284
|
+
from: MULTI_CALL_3_ADDRESS
|
|
285
|
+
}, {
|
|
286
|
+
time: ts + 1n
|
|
287
|
+
}, stateOverrides);
|
|
288
|
+
this.log.debug(`Simulated validateHeader`);
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Simulate making a call to invalidate a block with invalid attestations. Returns undefined if no need to invalidate.
|
|
292
|
+
* @param block - The block to invalidate and the criteria for invalidation (as returned by the archiver)
|
|
293
|
+
*/ async simulateInvalidateBlock(validationResult) {
|
|
294
|
+
if (validationResult.valid) {
|
|
295
|
+
return undefined;
|
|
296
|
+
}
|
|
297
|
+
const { reason, block } = validationResult;
|
|
298
|
+
const blockNumber = block.blockNumber;
|
|
299
|
+
const logData = {
|
|
300
|
+
...block,
|
|
301
|
+
reason
|
|
302
|
+
};
|
|
303
|
+
const currentBlockNumber = await this.rollupContract.getCheckpointNumber();
|
|
304
|
+
if (currentBlockNumber < validationResult.block.blockNumber) {
|
|
305
|
+
this.log.verbose(`Skipping block ${blockNumber} invalidation since it has already been removed from the pending chain`, {
|
|
306
|
+
currentBlockNumber,
|
|
307
|
+
...logData
|
|
308
|
+
});
|
|
309
|
+
return undefined;
|
|
310
|
+
}
|
|
311
|
+
const request = this.buildInvalidateBlockRequest(validationResult);
|
|
312
|
+
this.log.debug(`Simulating invalidate block ${blockNumber}`, {
|
|
313
|
+
...logData,
|
|
314
|
+
request
|
|
315
|
+
});
|
|
316
|
+
try {
|
|
317
|
+
const { gasUsed } = await this.l1TxUtils.simulate(request, undefined, undefined, ErrorsAbi);
|
|
318
|
+
this.log.verbose(`Simulation for invalidate block ${blockNumber} succeeded`, {
|
|
319
|
+
...logData,
|
|
320
|
+
request,
|
|
321
|
+
gasUsed
|
|
322
|
+
});
|
|
323
|
+
return {
|
|
324
|
+
request,
|
|
325
|
+
gasUsed,
|
|
326
|
+
blockNumber,
|
|
327
|
+
forcePendingBlockNumber: blockNumber - 1,
|
|
328
|
+
reason
|
|
329
|
+
};
|
|
330
|
+
} catch (err) {
|
|
331
|
+
const viemError = formatViemError(err);
|
|
332
|
+
// If the error is due to the block not being in the pending chain, and it was indeed removed by someone else,
|
|
333
|
+
// we can safely ignore it and return undefined so we go ahead with block building.
|
|
334
|
+
if (viemError.message?.includes('Rollup__BlockNotInPendingChain')) {
|
|
335
|
+
this.log.verbose(`Simulation for invalidate block ${blockNumber} failed due to block not being in pending chain`, {
|
|
336
|
+
...logData,
|
|
337
|
+
request,
|
|
338
|
+
error: viemError.message
|
|
339
|
+
});
|
|
340
|
+
const latestPendingBlockNumber = await this.rollupContract.getCheckpointNumber();
|
|
341
|
+
if (latestPendingBlockNumber < blockNumber) {
|
|
342
|
+
this.log.verbose(`Block number ${blockNumber} has already been invalidated`, {
|
|
343
|
+
...logData
|
|
344
|
+
});
|
|
345
|
+
return undefined;
|
|
346
|
+
} else {
|
|
347
|
+
this.log.error(`Simulation for invalidate ${blockNumber} failed and it is still in pending chain`, viemError, logData);
|
|
348
|
+
throw new Error(`Failed to simulate invalidate block ${blockNumber} while it is still in pending chain`, {
|
|
349
|
+
cause: viemError
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
// Otherwise, throw. We cannot build the next block if we cannot invalidate the previous one.
|
|
354
|
+
this.log.error(`Simulation for invalidate block ${blockNumber} failed`, viemError, logData);
|
|
355
|
+
throw new Error(`Failed to simulate invalidate block ${blockNumber}`, {
|
|
356
|
+
cause: viemError
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
buildInvalidateBlockRequest(validationResult) {
|
|
361
|
+
if (validationResult.valid) {
|
|
362
|
+
throw new Error('Cannot invalidate a valid block');
|
|
363
|
+
}
|
|
364
|
+
const { block, committee, reason } = validationResult;
|
|
365
|
+
const logData = {
|
|
366
|
+
...block,
|
|
367
|
+
reason
|
|
368
|
+
};
|
|
369
|
+
this.log.debug(`Simulating invalidate block ${block.blockNumber}`, logData);
|
|
370
|
+
const attestationsAndSigners = new CommitteeAttestationsAndSigners(validationResult.attestations).getPackedAttestations();
|
|
371
|
+
if (reason === 'invalid-attestation') {
|
|
372
|
+
return this.rollupContract.buildInvalidateBadAttestationRequest(block.blockNumber, attestationsAndSigners, committee, validationResult.invalidIndex);
|
|
373
|
+
} else if (reason === 'insufficient-attestations') {
|
|
374
|
+
return this.rollupContract.buildInvalidateInsufficientAttestationsRequest(block.blockNumber, attestationsAndSigners, committee);
|
|
375
|
+
} else {
|
|
376
|
+
const _ = reason;
|
|
377
|
+
throw new Error(`Unknown reason for invalidation`);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* @notice Will simulate `propose` to make sure that the block is valid for submission
|
|
170
382
|
*
|
|
171
383
|
* @dev Throws if unable to propose
|
|
172
384
|
*
|
|
173
|
-
* @param
|
|
174
|
-
* @param
|
|
385
|
+
* @param block - The block to propose
|
|
386
|
+
* @param attestationData - The block's attestation data
|
|
175
387
|
*
|
|
176
|
-
*/ async validateBlockForSubmission(
|
|
177
|
-
digest: Buffer.alloc(32),
|
|
178
|
-
signatures: []
|
|
179
|
-
}) {
|
|
388
|
+
*/ async validateBlockForSubmission(block, attestationsAndSigners, attestationsAndSignersSignature, options) {
|
|
180
389
|
const ts = BigInt((await this.l1TxUtils.getBlock()).timestamp + this.ethereumSlotDuration);
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
390
|
+
// If we have no attestations, we still need to provide the empty attestations
|
|
391
|
+
// so that the committee is recalculated correctly
|
|
392
|
+
const ignoreSignatures = attestationsAndSigners.attestations.length === 0;
|
|
393
|
+
if (ignoreSignatures) {
|
|
394
|
+
const { committee } = await this.epochCache.getCommittee(block.header.globalVariables.slotNumber);
|
|
395
|
+
if (!committee) {
|
|
396
|
+
this.log.warn(`No committee found for slot ${block.header.globalVariables.slotNumber}`);
|
|
397
|
+
throw new Error(`No committee found for slot ${block.header.globalVariables.slotNumber}`);
|
|
398
|
+
}
|
|
399
|
+
attestationsAndSigners.attestations = committee.map((committeeMember)=>CommitteeAttestation.fromAddress(committeeMember));
|
|
400
|
+
}
|
|
401
|
+
const blobFields = block.getCheckpointBlobFields();
|
|
402
|
+
const blobs = getBlobsPerL1Block(blobFields);
|
|
403
|
+
const blobInput = getPrefixedEthBlobCommitments(blobs);
|
|
186
404
|
const args = [
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
405
|
+
{
|
|
406
|
+
header: block.getCheckpointHeader().toViem(),
|
|
407
|
+
archive: toHex(block.archive.root.toBuffer()),
|
|
408
|
+
oracleInput: {
|
|
409
|
+
feeAssetPriceModifier: 0n
|
|
410
|
+
}
|
|
411
|
+
},
|
|
412
|
+
attestationsAndSigners.getPackedAttestations(),
|
|
413
|
+
attestationsAndSigners.getSigners().map((signer)=>signer.toString()),
|
|
414
|
+
attestationsAndSignersSignature.toViemSignature(),
|
|
415
|
+
blobInput
|
|
193
416
|
];
|
|
194
|
-
await this.
|
|
417
|
+
await this.simulateProposeTx(args, ts, options);
|
|
195
418
|
return ts;
|
|
196
419
|
}
|
|
197
|
-
async
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
}
|
|
201
|
-
async enqueueCastVoteHelper(slotNumber, timestamp, voteType, payload, base) {
|
|
202
|
-
if (this.myLastVotes[voteType] >= slotNumber) {
|
|
420
|
+
async enqueueCastSignalHelper(slotNumber, timestamp, signalType, payload, base, signerAddress, signer) {
|
|
421
|
+
if (this.lastActions[signalType] && this.lastActions[signalType] === slotNumber) {
|
|
422
|
+
this.log.debug(`Skipping duplicate vote cast signal ${signalType} for slot ${slotNumber}`);
|
|
203
423
|
return false;
|
|
204
424
|
}
|
|
205
425
|
if (payload.equals(EthAddress.ZERO)) {
|
|
206
426
|
return false;
|
|
207
427
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
this.rollupContract.getProposerAt(timestamp),
|
|
211
|
-
base.getRoundInfo(this.rollupContract.address, round)
|
|
212
|
-
]);
|
|
213
|
-
if (proposer.toLowerCase() !== this.getForwarderAddress().toString().toLowerCase()) {
|
|
428
|
+
if (signerAddress.equals(EthAddress.ZERO)) {
|
|
429
|
+
this.log.warn(`Cannot enqueue vote cast signal ${signalType} for address zero at slot ${slotNumber}`);
|
|
214
430
|
return false;
|
|
215
431
|
}
|
|
216
|
-
|
|
432
|
+
const round = await base.computeRound(slotNumber);
|
|
433
|
+
const roundInfo = await base.getRoundInfo(this.rollupContract.address, round);
|
|
434
|
+
if (roundInfo.lastSignalSlot >= slotNumber) {
|
|
217
435
|
return false;
|
|
218
436
|
}
|
|
219
|
-
const cachedLastVote = this.
|
|
220
|
-
this.
|
|
437
|
+
const cachedLastVote = this.lastActions[signalType];
|
|
438
|
+
this.lastActions[signalType] = slotNumber;
|
|
439
|
+
const action = signalType;
|
|
440
|
+
const request = await base.createSignalRequestWithSignature(payload.toString(), slotNumber, this.config.l1ChainId, signerAddress.toString(), signer);
|
|
441
|
+
this.log.debug(`Created ${action} request with signature`, {
|
|
442
|
+
request,
|
|
443
|
+
round,
|
|
444
|
+
signer: this.l1TxUtils.client.account?.address,
|
|
445
|
+
lastValidL2Slot: slotNumber
|
|
446
|
+
});
|
|
447
|
+
try {
|
|
448
|
+
await this.l1TxUtils.simulate(request, {
|
|
449
|
+
time: timestamp
|
|
450
|
+
}, [], ErrorsAbi);
|
|
451
|
+
this.log.debug(`Simulation for ${action} at slot ${slotNumber} succeeded`, {
|
|
452
|
+
request
|
|
453
|
+
});
|
|
454
|
+
} catch (err) {
|
|
455
|
+
this.log.error(`Failed simulation for ${action} at slot ${slotNumber} (enqueuing the action anyway)`, err);
|
|
456
|
+
// Yes, we enqueue the request anyway, in case there was a bug with the simulation itself
|
|
457
|
+
}
|
|
458
|
+
// TODO(palla/slash): All votes (governance and slashing) should txTimeoutAt at the end of the slot.
|
|
221
459
|
this.addRequest({
|
|
222
|
-
|
|
223
|
-
|
|
460
|
+
gasConfig: {
|
|
461
|
+
gasLimit: SequencerPublisher.VOTE_GAS_GUESS
|
|
462
|
+
},
|
|
463
|
+
action,
|
|
464
|
+
request,
|
|
224
465
|
lastValidL2Slot: slotNumber,
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
466
|
+
checkSuccess: (_request, result)=>{
|
|
467
|
+
const success = result && result.receipt && result.receipt.status === 'success' && tryExtractEvent(result.receipt.logs, base.address.toString(), EmpireBaseAbi, 'SignalCast');
|
|
468
|
+
const logData = {
|
|
469
|
+
...result,
|
|
470
|
+
slotNumber,
|
|
471
|
+
round,
|
|
472
|
+
payload: payload.toString()
|
|
473
|
+
};
|
|
474
|
+
if (!success) {
|
|
475
|
+
this.log.error(`Signaling in [${action}] for ${payload} at slot ${slotNumber} in round ${round} failed`, logData);
|
|
476
|
+
this.lastActions[signalType] = cachedLastVote;
|
|
477
|
+
return false;
|
|
228
478
|
} else {
|
|
229
|
-
this.log.info(`
|
|
479
|
+
this.log.info(`Signaling in [${action}] for ${payload} at slot ${slotNumber} in round ${round} succeeded`, logData);
|
|
480
|
+
return true;
|
|
230
481
|
}
|
|
231
482
|
}
|
|
232
483
|
});
|
|
233
484
|
return true;
|
|
234
485
|
}
|
|
235
|
-
async getVoteConfig(slotNumber, voteType) {
|
|
236
|
-
if (voteType === 0) {
|
|
237
|
-
return {
|
|
238
|
-
payload: this.governancePayload,
|
|
239
|
-
base: this.govProposerContract
|
|
240
|
-
};
|
|
241
|
-
} else if (voteType === 1) {
|
|
242
|
-
if (!this.getSlashPayload) {
|
|
243
|
-
return undefined;
|
|
244
|
-
}
|
|
245
|
-
const slashPayload = await this.getSlashPayload(slotNumber);
|
|
246
|
-
if (!slashPayload) {
|
|
247
|
-
return undefined;
|
|
248
|
-
}
|
|
249
|
-
return {
|
|
250
|
-
payload: slashPayload,
|
|
251
|
-
base: this.slashingProposerContract
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
throw new Error('Unreachable: Invalid vote type');
|
|
255
|
-
}
|
|
256
486
|
/**
|
|
257
|
-
* Enqueues a
|
|
258
|
-
* @param slotNumber - The slot number to cast a
|
|
259
|
-
* @param timestamp - The timestamp of the slot to cast a
|
|
260
|
-
* @
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
487
|
+
* Enqueues a governance castSignal transaction to cast a signal for a given slot number.
|
|
488
|
+
* @param slotNumber - The slot number to cast a signal for.
|
|
489
|
+
* @param timestamp - The timestamp of the slot to cast a signal for.
|
|
490
|
+
* @returns True if the signal was successfully enqueued, false otherwise.
|
|
491
|
+
*/ enqueueGovernanceCastSignal(governancePayload, slotNumber, timestamp, signerAddress, signer) {
|
|
492
|
+
return this.enqueueCastSignalHelper(slotNumber, timestamp, 'governance-signal', governancePayload, this.govProposerContract, signerAddress, signer);
|
|
493
|
+
}
|
|
494
|
+
/** Enqueues all slashing actions as returned by the slasher client. */ async enqueueSlashingActions(actions, slotNumber, timestamp, signerAddress, signer) {
|
|
495
|
+
if (actions.length === 0) {
|
|
496
|
+
this.log.debug(`No slashing actions to enqueue for slot ${slotNumber}`);
|
|
265
497
|
return false;
|
|
266
498
|
}
|
|
267
|
-
const
|
|
268
|
-
|
|
499
|
+
for (const action of actions){
|
|
500
|
+
switch(action.type){
|
|
501
|
+
case 'vote-empire-payload':
|
|
502
|
+
{
|
|
503
|
+
if (this.slashingProposerContract?.type !== 'empire') {
|
|
504
|
+
this.log.error('Cannot vote for empire payload on non-empire slashing contract');
|
|
505
|
+
break;
|
|
506
|
+
}
|
|
507
|
+
this.log.debug(`Enqueuing slashing vote for payload ${action.payload} at slot ${slotNumber}`, {
|
|
508
|
+
signerAddress
|
|
509
|
+
});
|
|
510
|
+
await this.enqueueCastSignalHelper(slotNumber, timestamp, 'empire-slashing-signal', action.payload, this.slashingProposerContract, signerAddress, signer);
|
|
511
|
+
break;
|
|
512
|
+
}
|
|
513
|
+
case 'create-empire-payload':
|
|
514
|
+
{
|
|
515
|
+
this.log.debug(`Enqueuing slashing create payload at slot ${slotNumber}`, {
|
|
516
|
+
slotNumber,
|
|
517
|
+
signerAddress
|
|
518
|
+
});
|
|
519
|
+
const request = this.slashFactoryContract.buildCreatePayloadRequest(action.data);
|
|
520
|
+
await this.simulateAndEnqueueRequest('create-empire-payload', request, (receipt)=>!!this.slashFactoryContract.tryExtractSlashPayloadCreatedEvent(receipt.logs), slotNumber, timestamp);
|
|
521
|
+
break;
|
|
522
|
+
}
|
|
523
|
+
case 'execute-empire-payload':
|
|
524
|
+
{
|
|
525
|
+
this.log.debug(`Enqueuing slashing execute payload at slot ${slotNumber}`, {
|
|
526
|
+
slotNumber,
|
|
527
|
+
signerAddress
|
|
528
|
+
});
|
|
529
|
+
if (this.slashingProposerContract?.type !== 'empire') {
|
|
530
|
+
this.log.error('Cannot execute slashing payload on non-empire slashing contract');
|
|
531
|
+
return false;
|
|
532
|
+
}
|
|
533
|
+
const empireSlashingProposer = this.slashingProposerContract;
|
|
534
|
+
const request = empireSlashingProposer.buildExecuteRoundRequest(action.round);
|
|
535
|
+
await this.simulateAndEnqueueRequest('execute-empire-payload', request, (receipt)=>!!empireSlashingProposer.tryExtractPayloadSubmittedEvent(receipt.logs), slotNumber, timestamp);
|
|
536
|
+
break;
|
|
537
|
+
}
|
|
538
|
+
case 'vote-offenses':
|
|
539
|
+
{
|
|
540
|
+
this.log.debug(`Enqueuing slashing vote for ${action.votes.length} votes at slot ${slotNumber}`, {
|
|
541
|
+
slotNumber,
|
|
542
|
+
round: action.round,
|
|
543
|
+
votesCount: action.votes.length,
|
|
544
|
+
signerAddress
|
|
545
|
+
});
|
|
546
|
+
if (this.slashingProposerContract?.type !== 'tally') {
|
|
547
|
+
this.log.error('Cannot vote for slashing offenses on non-tally slashing contract');
|
|
548
|
+
return false;
|
|
549
|
+
}
|
|
550
|
+
const tallySlashingProposer = this.slashingProposerContract;
|
|
551
|
+
const votes = bufferToHex(encodeSlashConsensusVotes(action.votes));
|
|
552
|
+
const request = await tallySlashingProposer.buildVoteRequestFromSigner(votes, slotNumber, signer);
|
|
553
|
+
await this.simulateAndEnqueueRequest('vote-offenses', request, (receipt)=>!!tallySlashingProposer.tryExtractVoteCastEvent(receipt.logs), slotNumber, timestamp);
|
|
554
|
+
break;
|
|
555
|
+
}
|
|
556
|
+
case 'execute-slash':
|
|
557
|
+
{
|
|
558
|
+
this.log.debug(`Enqueuing slash execution for round ${action.round} at slot ${slotNumber}`, {
|
|
559
|
+
slotNumber,
|
|
560
|
+
round: action.round,
|
|
561
|
+
signerAddress
|
|
562
|
+
});
|
|
563
|
+
if (this.slashingProposerContract?.type !== 'tally') {
|
|
564
|
+
this.log.error('Cannot execute slashing offenses on non-tally slashing contract');
|
|
565
|
+
return false;
|
|
566
|
+
}
|
|
567
|
+
const tallySlashingProposer = this.slashingProposerContract;
|
|
568
|
+
const request = tallySlashingProposer.buildExecuteRoundRequest(action.round, action.committees);
|
|
569
|
+
await this.simulateAndEnqueueRequest('execute-slash', request, (receipt)=>!!tallySlashingProposer.tryExtractRoundExecutedEvent(receipt.logs), slotNumber, timestamp);
|
|
570
|
+
break;
|
|
571
|
+
}
|
|
572
|
+
default:
|
|
573
|
+
{
|
|
574
|
+
const _ = action;
|
|
575
|
+
throw new Error(`Unknown slashing action type: ${action.type}`);
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
return true;
|
|
269
580
|
}
|
|
270
581
|
/**
|
|
271
582
|
* Proposes a L2 block on L1.
|
|
272
583
|
*
|
|
273
584
|
* @param block - L2 block to propose.
|
|
274
585
|
* @returns True if the tx has been enqueued, throws otherwise. See #9315
|
|
275
|
-
*/ async enqueueProposeL2Block(block,
|
|
276
|
-
const
|
|
277
|
-
const
|
|
278
|
-
const blobs =
|
|
586
|
+
*/ async enqueueProposeL2Block(block, attestationsAndSigners, attestationsAndSignersSignature, opts = {}) {
|
|
587
|
+
const checkpointHeader = block.getCheckpointHeader();
|
|
588
|
+
const blobFields = block.getCheckpointBlobFields();
|
|
589
|
+
const blobs = getBlobsPerL1Block(blobFields);
|
|
279
590
|
const proposeTxArgs = {
|
|
280
|
-
header:
|
|
591
|
+
header: checkpointHeader,
|
|
281
592
|
archive: block.archive.root.toBuffer(),
|
|
282
|
-
blockHash: (await block.header.hash()).toBuffer(),
|
|
283
593
|
body: block.body.toBuffer(),
|
|
284
594
|
blobs,
|
|
285
|
-
|
|
286
|
-
|
|
595
|
+
attestationsAndSigners,
|
|
596
|
+
attestationsAndSignersSignature
|
|
287
597
|
};
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
598
|
+
let ts;
|
|
599
|
+
try {
|
|
600
|
+
// @note This will make sure that we are passing the checks for our header ASSUMING that the data is also made available
|
|
601
|
+
// This means that we can avoid the simulation issues in later checks.
|
|
602
|
+
// By simulation issue, I mean the fact that the block.timestamp is equal to the last block, not the next, which
|
|
603
|
+
// make time consistency checks break.
|
|
604
|
+
// TODO(palla): Check whether we're validating twice, once here and once within addProposeTx, since we call simulateProposeTx in both places.
|
|
605
|
+
ts = await this.validateBlockForSubmission(block, attestationsAndSigners, attestationsAndSignersSignature, opts);
|
|
606
|
+
} catch (err) {
|
|
607
|
+
this.log.error(`Block validation failed. ${err instanceof Error ? err.message : 'No error message'}`, err, {
|
|
608
|
+
...block.getStats(),
|
|
609
|
+
slotNumber: block.header.globalVariables.slotNumber,
|
|
610
|
+
forcePendingBlockNumber: opts.forcePendingBlockNumber
|
|
611
|
+
});
|
|
612
|
+
throw err;
|
|
613
|
+
}
|
|
614
|
+
this.log.verbose(`Enqueuing block propose transaction`, {
|
|
615
|
+
...block.toBlockInfo(),
|
|
616
|
+
...opts
|
|
295
617
|
});
|
|
296
|
-
this.log.debug(`Submitting propose transaction`);
|
|
297
618
|
await this.addProposeTx(block, proposeTxArgs, opts, ts);
|
|
298
619
|
return true;
|
|
299
620
|
}
|
|
621
|
+
enqueueInvalidateBlock(request, opts = {}) {
|
|
622
|
+
if (!request) {
|
|
623
|
+
return;
|
|
624
|
+
}
|
|
625
|
+
// We issued the simulation against the rollup contract, so we need to account for the overhead of the multicall3
|
|
626
|
+
const gasLimit = this.l1TxUtils.bumpGasLimit(BigInt(Math.ceil(Number(request.gasUsed) * 64 / 63)));
|
|
627
|
+
const { gasUsed, blockNumber } = request;
|
|
628
|
+
const logData = {
|
|
629
|
+
gasUsed,
|
|
630
|
+
blockNumber,
|
|
631
|
+
gasLimit,
|
|
632
|
+
opts
|
|
633
|
+
};
|
|
634
|
+
this.log.verbose(`Enqueuing invalidate block request`, logData);
|
|
635
|
+
this.addRequest({
|
|
636
|
+
action: `invalidate-by-${request.reason}`,
|
|
637
|
+
request: request.request,
|
|
638
|
+
gasConfig: {
|
|
639
|
+
gasLimit,
|
|
640
|
+
txTimeoutAt: opts.txTimeoutAt
|
|
641
|
+
},
|
|
642
|
+
lastValidL2Slot: SlotNumber(this.getCurrentL2Slot() + 2),
|
|
643
|
+
checkSuccess: (_req, result)=>{
|
|
644
|
+
const success = result && result.receipt && result.receipt.status === 'success' && tryExtractEvent(result.receipt.logs, this.rollupContract.address, RollupAbi, 'CheckpointInvalidated');
|
|
645
|
+
if (!success) {
|
|
646
|
+
this.log.warn(`Invalidate block ${request.blockNumber} failed`, {
|
|
647
|
+
...result,
|
|
648
|
+
...logData
|
|
649
|
+
});
|
|
650
|
+
} else {
|
|
651
|
+
this.log.info(`Invalidate block ${request.blockNumber} succeeded`, {
|
|
652
|
+
...result,
|
|
653
|
+
...logData
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
return !!success;
|
|
657
|
+
}
|
|
658
|
+
});
|
|
659
|
+
}
|
|
660
|
+
async simulateAndEnqueueRequest(action, request, checkSuccess, slotNumber, timestamp) {
|
|
661
|
+
const logData = {
|
|
662
|
+
slotNumber,
|
|
663
|
+
timestamp,
|
|
664
|
+
gasLimit: undefined
|
|
665
|
+
};
|
|
666
|
+
if (this.lastActions[action] && this.lastActions[action] === slotNumber) {
|
|
667
|
+
this.log.debug(`Skipping duplicate action ${action} for slot ${slotNumber}`);
|
|
668
|
+
return false;
|
|
669
|
+
}
|
|
670
|
+
const cachedLastActionSlot = this.lastActions[action];
|
|
671
|
+
this.lastActions[action] = slotNumber;
|
|
672
|
+
this.log.debug(`Simulating ${action} for slot ${slotNumber}`, logData);
|
|
673
|
+
let gasUsed;
|
|
674
|
+
try {
|
|
675
|
+
({ gasUsed } = await this.l1TxUtils.simulate(request, {
|
|
676
|
+
time: timestamp
|
|
677
|
+
}, [], ErrorsAbi)); // TODO(palla/slash): Check the timestamp logic
|
|
678
|
+
this.log.verbose(`Simulation for ${action} succeeded`, {
|
|
679
|
+
...logData,
|
|
680
|
+
request,
|
|
681
|
+
gasUsed
|
|
682
|
+
});
|
|
683
|
+
} catch (err) {
|
|
684
|
+
const viemError = formatViemError(err);
|
|
685
|
+
this.log.error(`Simulation for ${action} at ${slotNumber} failed`, viemError, logData);
|
|
686
|
+
return false;
|
|
687
|
+
}
|
|
688
|
+
// We issued the simulation against the rollup contract, so we need to account for the overhead of the multicall3
|
|
689
|
+
const gasLimit = this.l1TxUtils.bumpGasLimit(BigInt(Math.ceil(Number(gasUsed) * 64 / 63)));
|
|
690
|
+
logData.gasLimit = gasLimit;
|
|
691
|
+
this.log.debug(`Enqueuing ${action}`, logData);
|
|
692
|
+
this.addRequest({
|
|
693
|
+
action,
|
|
694
|
+
request,
|
|
695
|
+
gasConfig: {
|
|
696
|
+
gasLimit
|
|
697
|
+
},
|
|
698
|
+
lastValidL2Slot: slotNumber,
|
|
699
|
+
checkSuccess: (_req, result)=>{
|
|
700
|
+
const success = result && result.receipt && result.receipt.status === 'success' && checkSuccess(result.receipt);
|
|
701
|
+
if (!success) {
|
|
702
|
+
this.log.warn(`Action ${action} at ${slotNumber} failed`, {
|
|
703
|
+
...result,
|
|
704
|
+
...logData
|
|
705
|
+
});
|
|
706
|
+
this.lastActions[action] = cachedLastActionSlot;
|
|
707
|
+
} else {
|
|
708
|
+
this.log.info(`Action ${action} at ${slotNumber} succeeded`, {
|
|
709
|
+
...result,
|
|
710
|
+
...logData
|
|
711
|
+
});
|
|
712
|
+
}
|
|
713
|
+
return !!success;
|
|
714
|
+
}
|
|
715
|
+
});
|
|
716
|
+
return true;
|
|
717
|
+
}
|
|
300
718
|
/**
|
|
301
719
|
* Calling `interrupt` will cause any in progress call to `publishRollup` to return `false` asap.
|
|
302
720
|
* Be warned, the call may return false even if the tx subsequently gets successfully mined.
|
|
@@ -310,97 +728,127 @@ export class SequencerPublisher {
|
|
|
310
728
|
this.interrupted = false;
|
|
311
729
|
this.l1TxUtils.restart();
|
|
312
730
|
}
|
|
313
|
-
async prepareProposeTx(encodedData, timestamp) {
|
|
731
|
+
async prepareProposeTx(encodedData, timestamp, options) {
|
|
314
732
|
const kzg = Blob.getViemKzgInstance();
|
|
315
|
-
const blobInput =
|
|
733
|
+
const blobInput = getPrefixedEthBlobCommitments(encodedData.blobs);
|
|
316
734
|
this.log.debug('Validating blob input', {
|
|
317
735
|
blobInput
|
|
318
736
|
});
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
737
|
+
// Get blob evaluation gas
|
|
738
|
+
let blobEvaluationGas;
|
|
739
|
+
if (this.config.fishermanMode) {
|
|
740
|
+
// In fisherman mode, we can't estimate blob gas because estimateGas doesn't support state overrides
|
|
741
|
+
// Use a fixed estimate.
|
|
742
|
+
blobEvaluationGas = BigInt(encodedData.blobs.length) * 21_000n;
|
|
743
|
+
this.log.debug(`Using fixed blob evaluation gas estimate in fisherman mode: ${blobEvaluationGas}`);
|
|
744
|
+
} else {
|
|
745
|
+
// Normal mode - use estimateGas with blob inputs
|
|
746
|
+
blobEvaluationGas = await this.l1TxUtils.estimateGas(this.getSenderAddress().toString(), {
|
|
747
|
+
to: this.rollupContract.address,
|
|
748
|
+
data: encodeFunctionData({
|
|
749
|
+
abi: RollupAbi,
|
|
750
|
+
functionName: 'validateBlobs',
|
|
751
|
+
args: [
|
|
752
|
+
blobInput
|
|
753
|
+
]
|
|
754
|
+
})
|
|
755
|
+
}, {}, {
|
|
756
|
+
blobs: encodedData.blobs.map((b)=>b.data),
|
|
757
|
+
kzg
|
|
758
|
+
}).catch((err)=>{
|
|
759
|
+
const { message, metaMessages } = formatViemError(err);
|
|
760
|
+
this.log.error(`Failed to validate blobs`, message, {
|
|
761
|
+
metaMessages
|
|
762
|
+
});
|
|
763
|
+
throw new Error('Failed to validate blobs');
|
|
335
764
|
});
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
const attestations = encodedData.attestations ? encodedData.attestations.map((attest)=>attest.toViemSignature()) : [];
|
|
339
|
-
const txHashes = encodedData.txHashes ? encodedData.txHashes.map((txHash)=>txHash.toString()) : [];
|
|
765
|
+
}
|
|
766
|
+
const signers = encodedData.attestationsAndSigners.getSigners().map((signer)=>signer.toString());
|
|
340
767
|
const args = [
|
|
341
768
|
{
|
|
342
|
-
header:
|
|
343
|
-
archive:
|
|
769
|
+
header: encodedData.header.toViem(),
|
|
770
|
+
archive: toHex(encodedData.archive),
|
|
344
771
|
oracleInput: {
|
|
345
772
|
// We are currently not modifying these. See #9963
|
|
346
773
|
feeAssetPriceModifier: 0n
|
|
347
|
-
}
|
|
348
|
-
blockHash: `0x${encodedData.blockHash.toString('hex')}`,
|
|
349
|
-
txHashes
|
|
774
|
+
}
|
|
350
775
|
},
|
|
351
|
-
|
|
776
|
+
encodedData.attestationsAndSigners.getPackedAttestations(),
|
|
777
|
+
signers,
|
|
778
|
+
encodedData.attestationsAndSignersSignature.toViemSignature(),
|
|
352
779
|
blobInput
|
|
353
780
|
];
|
|
781
|
+
const { rollupData, simulationResult } = await this.simulateProposeTx(args, timestamp, options);
|
|
782
|
+
return {
|
|
783
|
+
args,
|
|
784
|
+
blobEvaluationGas,
|
|
785
|
+
rollupData,
|
|
786
|
+
simulationResult
|
|
787
|
+
};
|
|
788
|
+
}
|
|
789
|
+
/**
|
|
790
|
+
* Simulates the propose tx with eth_simulateV1
|
|
791
|
+
* @param args - The propose tx args
|
|
792
|
+
* @param timestamp - The timestamp to simulate proposal at
|
|
793
|
+
* @returns The simulation result
|
|
794
|
+
*/ async simulateProposeTx(args, timestamp, options) {
|
|
354
795
|
const rollupData = encodeFunctionData({
|
|
355
796
|
abi: RollupAbi,
|
|
356
797
|
functionName: 'propose',
|
|
357
798
|
args
|
|
358
799
|
});
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
args: [
|
|
363
|
-
[
|
|
364
|
-
this.rollupContract.address
|
|
365
|
-
],
|
|
366
|
-
[
|
|
367
|
-
rollupData
|
|
368
|
-
]
|
|
369
|
-
]
|
|
370
|
-
});
|
|
371
|
-
const simulationResult = await this.l1TxUtils.simulateGasUsed({
|
|
372
|
-
to: this.getForwarderAddress().toString(),
|
|
373
|
-
data: forwarderData,
|
|
374
|
-
gas: SequencerPublisher.PROPOSE_GAS_GUESS
|
|
375
|
-
}, {
|
|
376
|
-
// @note we add 1n to the timestamp because geth implementation doesn't like simulation timestamp to be equal to the current block timestamp
|
|
377
|
-
time: timestamp + 1n,
|
|
378
|
-
// @note reth should have a 30m gas limit per block but throws errors that this tx is beyond limit
|
|
379
|
-
gasLimit: SequencerPublisher.PROPOSE_GAS_GUESS * 2n
|
|
380
|
-
}, [
|
|
800
|
+
// override the pending block number if requested
|
|
801
|
+
const forcePendingBlockNumberStateDiff = (options.forcePendingBlockNumber !== undefined ? await this.rollupContract.makePendingCheckpointNumberOverride(options.forcePendingBlockNumber) : []).flatMap((override)=>override.stateDiff ?? []);
|
|
802
|
+
const stateOverrides = [
|
|
381
803
|
{
|
|
382
804
|
address: this.rollupContract.address,
|
|
383
805
|
// @note we override checkBlob to false since blobs are not part simulate()
|
|
384
806
|
stateDiff: [
|
|
385
807
|
{
|
|
386
|
-
slot:
|
|
387
|
-
value:
|
|
388
|
-
}
|
|
808
|
+
slot: toPaddedHex(RollupContract.checkBlobStorageSlot, true),
|
|
809
|
+
value: toPaddedHex(0n, true)
|
|
810
|
+
},
|
|
811
|
+
...forcePendingBlockNumberStateDiff
|
|
389
812
|
]
|
|
390
813
|
}
|
|
391
|
-
]
|
|
814
|
+
];
|
|
815
|
+
// In fisherman mode, simulate as the proposer but with sufficient balance
|
|
816
|
+
if (this.proposerAddressForSimulation) {
|
|
817
|
+
stateOverrides.push({
|
|
818
|
+
address: this.proposerAddressForSimulation.toString(),
|
|
819
|
+
balance: 10n * WEI_CONST * WEI_CONST
|
|
820
|
+
});
|
|
821
|
+
}
|
|
822
|
+
const simulationResult = await this.l1TxUtils.simulate({
|
|
823
|
+
to: this.rollupContract.address,
|
|
824
|
+
data: rollupData,
|
|
825
|
+
gas: SequencerPublisher.PROPOSE_GAS_GUESS,
|
|
826
|
+
...this.proposerAddressForSimulation && {
|
|
827
|
+
from: this.proposerAddressForSimulation.toString()
|
|
828
|
+
}
|
|
829
|
+
}, {
|
|
830
|
+
// @note we add 1n to the timestamp because geth implementation doesn't like simulation timestamp to be equal to the current block timestamp
|
|
831
|
+
time: timestamp + 1n,
|
|
832
|
+
// @note reth should have a 30m gas limit per block but throws errors that this tx is beyond limit so we increase here
|
|
833
|
+
gasLimit: SequencerPublisher.PROPOSE_GAS_GUESS * 2n
|
|
834
|
+
}, stateOverrides, RollupAbi, {
|
|
392
835
|
// @note fallback gas estimate to use if the node doesn't support simulation API
|
|
393
836
|
fallbackGasEstimate: SequencerPublisher.PROPOSE_GAS_GUESS
|
|
394
837
|
}).catch((err)=>{
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
838
|
+
// In fisherman mode, we expect ValidatorSelection__MissingProposerSignature since fisherman doesn't have proposer signature
|
|
839
|
+
const viemError = formatViemError(err);
|
|
840
|
+
if (this.config.fishermanMode && viemError.message?.includes('ValidatorSelection__MissingProposerSignature')) {
|
|
841
|
+
this.log.debug(`Ignoring expected ValidatorSelection__MissingProposerSignature error in fisherman mode`);
|
|
842
|
+
// Return a minimal simulation result with the fallback gas estimate
|
|
843
|
+
return {
|
|
844
|
+
gasUsed: SequencerPublisher.PROPOSE_GAS_GUESS,
|
|
845
|
+
logs: []
|
|
846
|
+
};
|
|
847
|
+
}
|
|
848
|
+
this.log.error(`Failed to simulate propose tx`, viemError);
|
|
849
|
+
throw err;
|
|
400
850
|
});
|
|
401
851
|
return {
|
|
402
|
-
args,
|
|
403
|
-
blobEvaluationGas,
|
|
404
852
|
rollupData,
|
|
405
853
|
simulationResult
|
|
406
854
|
};
|
|
@@ -408,74 +856,71 @@ export class SequencerPublisher {
|
|
|
408
856
|
async addProposeTx(block, encodedData, opts = {}, timestamp) {
|
|
409
857
|
const timer = new Timer();
|
|
410
858
|
const kzg = Blob.getViemKzgInstance();
|
|
411
|
-
const { rollupData, simulationResult, blobEvaluationGas } = await this.prepareProposeTx(encodedData, timestamp);
|
|
859
|
+
const { rollupData, simulationResult, blobEvaluationGas } = await this.prepareProposeTx(encodedData, timestamp, opts);
|
|
412
860
|
const startBlock = await this.l1TxUtils.getBlockNumber();
|
|
413
|
-
const
|
|
861
|
+
const gasLimit = this.l1TxUtils.bumpGasLimit(BigInt(Math.ceil(Number(simulationResult.gasUsed) * 64 / 63)) + blobEvaluationGas + SequencerPublisher.MULTICALL_OVERHEAD_GAS_GUESS);
|
|
862
|
+
// Send the blobs to the blob sink preemptively. This helps in tests where the sequencer mistakingly thinks that the propose
|
|
863
|
+
// tx fails but it does get mined. We make sure that the blobs are sent to the blob sink regardless of the tx outcome.
|
|
864
|
+
void this.blobSinkClient.sendBlobsToBlobSink(encodedData.blobs).catch((_err)=>{
|
|
865
|
+
this.log.error('Failed to send blobs to blob sink');
|
|
866
|
+
});
|
|
414
867
|
return this.addRequest({
|
|
415
868
|
action: 'propose',
|
|
416
869
|
request: {
|
|
417
870
|
to: this.rollupContract.address,
|
|
418
871
|
data: rollupData
|
|
419
872
|
},
|
|
420
|
-
lastValidL2Slot: block.header.globalVariables.slotNumber
|
|
873
|
+
lastValidL2Slot: block.header.globalVariables.slotNumber,
|
|
421
874
|
gasConfig: {
|
|
422
875
|
...opts,
|
|
423
|
-
gasLimit
|
|
876
|
+
gasLimit
|
|
424
877
|
},
|
|
425
878
|
blobConfig: {
|
|
426
879
|
blobs: encodedData.blobs.map((b)=>b.data),
|
|
427
880
|
kzg
|
|
428
881
|
},
|
|
429
|
-
|
|
882
|
+
checkSuccess: (_request, result)=>{
|
|
430
883
|
if (!result) {
|
|
431
|
-
return;
|
|
884
|
+
return false;
|
|
432
885
|
}
|
|
433
886
|
const { receipt, stats, errorMsg } = result;
|
|
434
|
-
|
|
887
|
+
const success = receipt && receipt.status === 'success' && tryExtractEvent(receipt.logs, this.rollupContract.address, RollupAbi, 'CheckpointProposed');
|
|
888
|
+
if (success) {
|
|
435
889
|
const endBlock = receipt.blockNumber;
|
|
436
890
|
const inclusionBlocks = Number(endBlock - startBlock);
|
|
891
|
+
const { calldataGas, calldataSize, sender } = stats;
|
|
437
892
|
const publishStats = {
|
|
438
893
|
gasPrice: receipt.effectiveGasPrice,
|
|
439
894
|
gasUsed: receipt.gasUsed,
|
|
440
895
|
blobGasUsed: receipt.blobGasUsed ?? 0n,
|
|
441
896
|
blobDataGas: receipt.blobGasPrice ?? 0n,
|
|
442
897
|
transactionHash: receipt.transactionHash,
|
|
443
|
-
|
|
898
|
+
calldataGas,
|
|
899
|
+
calldataSize,
|
|
900
|
+
sender,
|
|
444
901
|
...block.getStats(),
|
|
445
902
|
eventName: 'rollup-published-to-l1',
|
|
446
903
|
blobCount: encodedData.blobs.length,
|
|
447
904
|
inclusionBlocks
|
|
448
905
|
};
|
|
449
|
-
this.log.
|
|
906
|
+
this.log.info(`Published L2 block to L1 rollup contract`, {
|
|
450
907
|
...stats,
|
|
451
|
-
...block.getStats()
|
|
908
|
+
...block.getStats(),
|
|
909
|
+
...receipt
|
|
452
910
|
});
|
|
453
911
|
this.metrics.recordProcessBlockTx(timer.ms(), publishStats);
|
|
454
|
-
// Send the blobs to the blob sink
|
|
455
|
-
this.sendBlobsToBlobSink(receipt.blockHash, encodedData.blobs).catch((_err)=>{
|
|
456
|
-
this.log.error('Failed to send blobs to blob sink');
|
|
457
|
-
});
|
|
458
912
|
return true;
|
|
459
913
|
} else {
|
|
460
914
|
this.metrics.recordFailedTx('process');
|
|
461
|
-
this.log.error(`Rollup process tx
|
|
915
|
+
this.log.error(`Rollup process tx failed: ${errorMsg ?? 'no error message'}`, undefined, {
|
|
462
916
|
...block.getStats(),
|
|
917
|
+
receipt,
|
|
463
918
|
txHash: receipt.transactionHash,
|
|
464
|
-
|
|
465
|
-
slotNumber: block.header.globalVariables.slotNumber.toBigInt()
|
|
919
|
+
slotNumber: block.header.globalVariables.slotNumber
|
|
466
920
|
});
|
|
921
|
+
return false;
|
|
467
922
|
}
|
|
468
923
|
}
|
|
469
924
|
});
|
|
470
925
|
}
|
|
471
|
-
/**
|
|
472
|
-
* Send blobs to the blob sink
|
|
473
|
-
*
|
|
474
|
-
* If a blob sink url is configured, then we send blobs to the blob sink
|
|
475
|
-
* - for now we use the blockHash as the identifier for the blobs;
|
|
476
|
-
* In the future this will move to be the beacon block id - which takes a bit more work
|
|
477
|
-
* to calculate and will need to be mocked in e2e tests
|
|
478
|
-
*/ sendBlobsToBlobSink(blockHash, blobs) {
|
|
479
|
-
return this.blobSinkClient.sendBlobsToBlobSink(blockHash, blobs);
|
|
480
|
-
}
|
|
481
926
|
}
|