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