@aztec/ethereum 0.0.1-commit.ff7989d6c → 0.0.1-commit.ffe5b04ea
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/config.d.ts +3 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +6 -0
- package/dest/contracts/registry.d.ts +3 -1
- package/dest/contracts/registry.d.ts.map +1 -1
- package/dest/contracts/registry.js +30 -1
- package/dest/contracts/rollup.d.ts +5 -5
- package/dest/contracts/rollup.d.ts.map +1 -1
- package/dest/contracts/rollup.js +12 -2
- package/dest/generated/l1-contracts-defaults.d.ts +1 -1
- package/dest/generated/l1-contracts-defaults.js +1 -1
- package/dest/l1_tx_utils/l1_tx_utils.d.ts +4 -3
- package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -1
- package/dest/l1_tx_utils/l1_tx_utils.js +14 -32
- package/dest/test/start_anvil.d.ts +9 -3
- package/dest/test/start_anvil.d.ts.map +1 -1
- package/dest/test/start_anvil.js +128 -29
- package/dest/utils.d.ts +1 -1
- package/dest/utils.d.ts.map +1 -1
- package/dest/utils.js +16 -12
- package/package.json +5 -7
- package/src/config.ts +12 -0
- package/src/contracts/registry.ts +31 -1
- package/src/contracts/rollup.ts +20 -6
- package/src/generated/l1-contracts-defaults.ts +1 -1
- package/src/l1_tx_utils/l1_tx_utils.ts +14 -21
- package/src/test/start_anvil.ts +146 -29
- package/src/utils.ts +17 -14
package/dest/test/start_anvil.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createLogger } from '@aztec/foundation/log';
|
|
2
2
|
import { makeBackoff, retry } from '@aztec/foundation/retry';
|
|
3
3
|
import { fileURLToPath } from '@aztec/foundation/url';
|
|
4
|
-
import {
|
|
4
|
+
import { spawn } from 'child_process';
|
|
5
5
|
import { dirname, resolve } from 'path';
|
|
6
6
|
/**
|
|
7
7
|
* Ensures there's a running Anvil instance and returns the RPC URL.
|
|
@@ -9,47 +9,146 @@ import { dirname, resolve } from 'path';
|
|
|
9
9
|
const anvilBinary = resolve(dirname(fileURLToPath(import.meta.url)), '../../', 'scripts/anvil_kill_wrapper.sh');
|
|
10
10
|
const logger = opts.log ? createLogger('ethereum:anvil') : undefined;
|
|
11
11
|
const methodCalls = opts.captureMethodCalls ? [] : undefined;
|
|
12
|
-
let
|
|
13
|
-
// Start anvil.
|
|
14
|
-
// We go via a wrapper script to ensure if the parent dies, anvil dies.
|
|
12
|
+
let detectedPort;
|
|
15
13
|
const anvil = await retry(async ()=>{
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
host
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
accounts
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
14
|
+
const port = opts.port ?? (process.env.ANVIL_PORT ? parseInt(process.env.ANVIL_PORT) : 8545);
|
|
15
|
+
const args = [
|
|
16
|
+
'--host',
|
|
17
|
+
'127.0.0.1',
|
|
18
|
+
'--port',
|
|
19
|
+
String(port),
|
|
20
|
+
'--accounts',
|
|
21
|
+
String(opts.accounts ?? 20),
|
|
22
|
+
'--gas-limit',
|
|
23
|
+
String(45_000_000),
|
|
24
|
+
'--chain-id',
|
|
25
|
+
String(opts.chainId ?? 31337)
|
|
26
|
+
];
|
|
27
|
+
if (opts.l1BlockTime !== undefined) {
|
|
28
|
+
args.push('--block-time', String(opts.l1BlockTime));
|
|
29
|
+
}
|
|
30
|
+
if (opts.hardfork !== undefined) {
|
|
31
|
+
args.push('--hardfork', opts.hardfork);
|
|
32
|
+
}
|
|
33
|
+
const child = spawn(anvilBinary, args, {
|
|
34
|
+
stdio: [
|
|
35
|
+
'ignore',
|
|
36
|
+
'pipe',
|
|
37
|
+
'pipe'
|
|
38
|
+
],
|
|
39
|
+
env: {
|
|
40
|
+
...process.env,
|
|
41
|
+
RAYON_NUM_THREADS: '1'
|
|
32
42
|
}
|
|
33
43
|
});
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
44
|
+
// Wait for "Listening on" or an early exit.
|
|
45
|
+
await new Promise((resolve, reject)=>{
|
|
46
|
+
let stderr = '';
|
|
47
|
+
const onStdout = (data)=>{
|
|
48
|
+
const text = data.toString();
|
|
49
|
+
logger?.debug(text.trim());
|
|
50
|
+
methodCalls?.push(...text.match(/eth_[^\s]+/g) || []);
|
|
51
|
+
if (detectedPort === undefined && text.includes('Listening on')) {
|
|
52
|
+
const match = text.match(/Listening on ([^:]+):(\d+)/);
|
|
53
|
+
if (match) {
|
|
54
|
+
detectedPort = parseInt(match[2]);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (detectedPort !== undefined) {
|
|
58
|
+
child.stdout?.removeListener('data', onStdout);
|
|
59
|
+
child.stderr?.removeListener('data', onStderr);
|
|
60
|
+
child.removeListener('close', onClose);
|
|
61
|
+
resolve();
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
const onStderr = (data)=>{
|
|
65
|
+
stderr += data.toString();
|
|
66
|
+
logger?.debug(data.toString().trim());
|
|
67
|
+
};
|
|
68
|
+
const onClose = (code)=>{
|
|
69
|
+
child.stdout?.removeListener('data', onStdout);
|
|
70
|
+
child.stderr?.removeListener('data', onStderr);
|
|
71
|
+
reject(new Error(`Anvil exited with code ${code} before listening. stderr: ${stderr}`));
|
|
72
|
+
};
|
|
73
|
+
child.stdout?.on('data', onStdout);
|
|
74
|
+
child.stderr?.on('data', onStderr);
|
|
75
|
+
child.once('close', onClose);
|
|
76
|
+
});
|
|
77
|
+
// Continue piping for logging / method-call capture after startup.
|
|
78
|
+
if (logger || opts.captureMethodCalls) {
|
|
79
|
+
child.stdout?.on('data', (data)=>{
|
|
80
|
+
const text = data.toString();
|
|
81
|
+
logger?.debug(text.trim());
|
|
82
|
+
methodCalls?.push(...text.match(/eth_[^\s]+/g) || []);
|
|
83
|
+
});
|
|
84
|
+
child.stderr?.on('data', (data)=>{
|
|
85
|
+
logger?.debug(data.toString().trim());
|
|
86
|
+
});
|
|
87
|
+
} else {
|
|
88
|
+
// Consume streams so the child process doesn't block on full pipe buffers.
|
|
89
|
+
child.stdout?.resume();
|
|
90
|
+
child.stderr?.resume();
|
|
37
91
|
}
|
|
38
|
-
return
|
|
92
|
+
return child;
|
|
39
93
|
}, 'Start anvil', makeBackoff([
|
|
40
94
|
5,
|
|
41
95
|
5,
|
|
42
96
|
5
|
|
43
97
|
]));
|
|
44
|
-
if (!
|
|
98
|
+
if (!detectedPort) {
|
|
45
99
|
throw new Error('Failed to start anvil');
|
|
46
100
|
}
|
|
47
|
-
|
|
48
|
-
|
|
101
|
+
const port = detectedPort;
|
|
102
|
+
let status = 'listening';
|
|
103
|
+
anvil.once('close', ()=>{
|
|
104
|
+
status = 'idle';
|
|
105
|
+
});
|
|
106
|
+
const stop = async ()=>{
|
|
107
|
+
if (status === 'idle') {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
await killChild(anvil);
|
|
111
|
+
};
|
|
112
|
+
const anvilObj = {
|
|
113
|
+
port,
|
|
114
|
+
host: '127.0.0.1',
|
|
115
|
+
get status () {
|
|
116
|
+
return status;
|
|
117
|
+
},
|
|
118
|
+
stop
|
|
119
|
+
};
|
|
49
120
|
return {
|
|
50
|
-
anvil,
|
|
121
|
+
anvil: anvilObj,
|
|
51
122
|
methodCalls,
|
|
52
|
-
stop
|
|
123
|
+
stop,
|
|
53
124
|
rpcUrl: `http://127.0.0.1:${port}`
|
|
54
125
|
};
|
|
55
126
|
}
|
|
127
|
+
/** Send SIGTERM, wait up to 5 s, then SIGKILL. All timers are always cleared. */ function killChild(child) {
|
|
128
|
+
return new Promise((resolve)=>{
|
|
129
|
+
if (child.exitCode !== null || child.killed) {
|
|
130
|
+
child.stdout?.destroy();
|
|
131
|
+
child.stderr?.destroy();
|
|
132
|
+
resolve();
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
let killTimer;
|
|
136
|
+
const onClose = ()=>{
|
|
137
|
+
if (killTimer !== undefined) {
|
|
138
|
+
clearTimeout(killTimer);
|
|
139
|
+
}
|
|
140
|
+
// Destroy stdio streams so their PipeWrap handles don't keep the event loop alive.
|
|
141
|
+
child.stdout?.destroy();
|
|
142
|
+
child.stderr?.destroy();
|
|
143
|
+
resolve();
|
|
144
|
+
};
|
|
145
|
+
child.once('close', onClose);
|
|
146
|
+
child.kill('SIGTERM');
|
|
147
|
+
killTimer = setTimeout(()=>{
|
|
148
|
+
killTimer = undefined;
|
|
149
|
+
child.kill('SIGKILL');
|
|
150
|
+
}, 5000);
|
|
151
|
+
// Ensure the timer does not prevent Node from exiting.
|
|
152
|
+
killTimer.unref();
|
|
153
|
+
});
|
|
154
|
+
}
|
package/dest/utils.d.ts
CHANGED
|
@@ -35,4 +35,4 @@ export declare function isBlobTransaction(tx: FormattedTransaction): tx is Forma
|
|
|
35
35
|
* Calculates a percentile from an array of bigints
|
|
36
36
|
*/
|
|
37
37
|
export declare function calculatePercentile(values: bigint[], percentile: number): bigint;
|
|
38
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
38
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbHMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy91dGlscy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxFQUFFLEVBQUUsTUFBTSxnQ0FBZ0MsQ0FBQztBQUN6RCxPQUFPLEtBQUssRUFBRSxNQUFNLEVBQUUsTUFBTSx1QkFBdUIsQ0FBQztBQUdwRCxPQUFPLEVBQ0wsS0FBSyxHQUFHLEVBR1IsS0FBSyxpQkFBaUIsRUFFdEIsS0FBSyx3QkFBd0IsRUFDN0IsS0FBSyxvQkFBb0IsRUFDekIsS0FBSyxHQUFHLEVBQ1IsS0FBSyxHQU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EAAE,MAAM,EAAE,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAOhF"}
|
package/dest/utils.js
CHANGED
|
@@ -112,6 +112,19 @@ function getNestedErrorData(error) {
|
|
|
112
112
|
// Not found
|
|
113
113
|
return undefined;
|
|
114
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* Truncates an error message to a safe length for log renderers.
|
|
117
|
+
* LogExplorer can only render up to 2500 characters in its summary view.
|
|
118
|
+
* We cap at 2000 to leave room for decorating context added by callers.
|
|
119
|
+
*/ function truncateErrorMessage(message) {
|
|
120
|
+
const MAX = 2000;
|
|
121
|
+
const CHUNK = 950;
|
|
122
|
+
if (message.length <= MAX) {
|
|
123
|
+
return message;
|
|
124
|
+
}
|
|
125
|
+
const truncated = message.length - 2 * CHUNK;
|
|
126
|
+
return message.slice(0, CHUNK) + `...${truncated} characters truncated...` + message.slice(-CHUNK);
|
|
127
|
+
}
|
|
115
128
|
/**
|
|
116
129
|
* Formats a Viem error into a FormattedViemError instance.
|
|
117
130
|
* @param error - The error to format.
|
|
@@ -162,18 +175,9 @@ function getNestedErrorData(error) {
|
|
|
162
175
|
}
|
|
163
176
|
// If it's a regular Error instance, return it with its message
|
|
164
177
|
if (error instanceof Error) {
|
|
165
|
-
return new FormattedViemError(error.message, error?.metaMessages);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
const length = body.length;
|
|
169
|
-
// LogExplorer can only render up to 2500 characters in it's summary view. Try to keep the whole message below this number
|
|
170
|
-
// Limit the error to 2000 chacaters in order to allow code higher up to decorate this error with extra details (up to 500 characters)
|
|
171
|
-
if (length > 2000) {
|
|
172
|
-
const chunk = 950;
|
|
173
|
-
const truncated = length - 2 * chunk;
|
|
174
|
-
return new FormattedViemError(body.slice(0, chunk) + `...${truncated} characters truncated...` + body.slice(-1 * chunk));
|
|
175
|
-
}
|
|
176
|
-
return new FormattedViemError(body);
|
|
178
|
+
return new FormattedViemError(truncateErrorMessage(error.message), error?.metaMessages);
|
|
179
|
+
}
|
|
180
|
+
return new FormattedViemError(truncateErrorMessage(String(error)));
|
|
177
181
|
}
|
|
178
182
|
function stripAbis(obj) {
|
|
179
183
|
if (!obj || typeof obj !== 'object') {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/ethereum",
|
|
3
|
-
"version": "0.0.1-commit.
|
|
3
|
+
"version": "0.0.1-commit.ffe5b04ea",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./account": "./dest/account.js",
|
|
@@ -50,11 +50,10 @@
|
|
|
50
50
|
"../package.common.json"
|
|
51
51
|
],
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@aztec/blob-lib": "0.0.1-commit.
|
|
54
|
-
"@aztec/constants": "0.0.1-commit.
|
|
55
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
56
|
-
"@aztec/l1-artifacts": "0.0.1-commit.
|
|
57
|
-
"@viem/anvil": "^0.0.10",
|
|
53
|
+
"@aztec/blob-lib": "0.0.1-commit.ffe5b04ea",
|
|
54
|
+
"@aztec/constants": "0.0.1-commit.ffe5b04ea",
|
|
55
|
+
"@aztec/foundation": "0.0.1-commit.ffe5b04ea",
|
|
56
|
+
"@aztec/l1-artifacts": "0.0.1-commit.ffe5b04ea",
|
|
58
57
|
"dotenv": "^16.0.3",
|
|
59
58
|
"lodash.chunk": "^4.2.0",
|
|
60
59
|
"lodash.pickby": "^4.5.0",
|
|
@@ -69,7 +68,6 @@
|
|
|
69
68
|
"@types/lodash.pickby": "^4",
|
|
70
69
|
"@types/node": "^22.15.17",
|
|
71
70
|
"@typescript/native-preview": "7.0.0-dev.20260113.1",
|
|
72
|
-
"@viem/anvil": "^0.0.10",
|
|
73
71
|
"get-port": "^7.1.0",
|
|
74
72
|
"jest": "^30.0.0",
|
|
75
73
|
"jest-mock-extended": "^4.0.0",
|
package/src/config.ts
CHANGED
|
@@ -19,6 +19,8 @@ export type GenesisStateConfig = {
|
|
|
19
19
|
testAccounts: boolean;
|
|
20
20
|
/** Whether to populate the genesis state with initial fee juice for the sponsored FPC */
|
|
21
21
|
sponsoredFPC: boolean;
|
|
22
|
+
/** Additional addresses to prefund with fee juice at genesis */
|
|
23
|
+
prefundAddresses: string[];
|
|
22
24
|
};
|
|
23
25
|
|
|
24
26
|
export type L1ContractsConfig = {
|
|
@@ -259,6 +261,16 @@ export const genesisStateConfigMappings: ConfigMappingsType<GenesisStateConfig>
|
|
|
259
261
|
description: 'Whether to populate the genesis state with initial fee juice for the sponsored FPC.',
|
|
260
262
|
...booleanConfigHelper(false),
|
|
261
263
|
},
|
|
264
|
+
prefundAddresses: {
|
|
265
|
+
env: 'PREFUND_ADDRESSES',
|
|
266
|
+
description: 'Comma-separated list of Aztec addresses to prefund with fee juice at genesis (local network only).',
|
|
267
|
+
parseEnv: (val: string) =>
|
|
268
|
+
val
|
|
269
|
+
.split(',')
|
|
270
|
+
.map(a => a.trim())
|
|
271
|
+
.filter(a => a.length > 0),
|
|
272
|
+
defaultValue: [],
|
|
273
|
+
},
|
|
262
274
|
};
|
|
263
275
|
|
|
264
276
|
export function getL1ContractsConfigEnvVars(): L1ContractsConfig {
|
|
@@ -3,7 +3,7 @@ import { createLogger } from '@aztec/foundation/log';
|
|
|
3
3
|
import { RegistryAbi } from '@aztec/l1-artifacts/RegistryAbi';
|
|
4
4
|
import { TestERC20Abi } from '@aztec/l1-artifacts/TestERC20Abi';
|
|
5
5
|
|
|
6
|
-
import { type GetContractReturnType, type Hex, getContract } from 'viem';
|
|
6
|
+
import { type GetContractReturnType, type Hex, getAbiItem, getContract } from 'viem';
|
|
7
7
|
|
|
8
8
|
import type { L1ContractAddresses } from '../l1_contract_addresses.js';
|
|
9
9
|
import type { ViemClient } from '../types.js';
|
|
@@ -128,4 +128,34 @@ export class RegistryContract {
|
|
|
128
128
|
public async getRewardDistributor(): Promise<EthAddress> {
|
|
129
129
|
return EthAddress.fromString(await this.registry.read.getRewardDistributor());
|
|
130
130
|
}
|
|
131
|
+
|
|
132
|
+
/** Returns the L1 timestamp at which the given rollup was registered via addRollup(). */
|
|
133
|
+
public async getCanonicalRollupRegistrationTimestamp(
|
|
134
|
+
rollupAddress: EthAddress,
|
|
135
|
+
fromBlock?: bigint,
|
|
136
|
+
): Promise<bigint | undefined> {
|
|
137
|
+
const event = getAbiItem({ abi: RegistryAbi, name: 'CanonicalRollupUpdated' });
|
|
138
|
+
const start = fromBlock ?? 0n;
|
|
139
|
+
const latestBlock = await this.client.getBlockNumber();
|
|
140
|
+
const chunkSize = 1_000n;
|
|
141
|
+
|
|
142
|
+
for (let from = start; from <= latestBlock; from += chunkSize) {
|
|
143
|
+
const to = from + chunkSize - 1n > latestBlock ? latestBlock : from + chunkSize - 1n;
|
|
144
|
+
const logs = await this.client.getLogs({
|
|
145
|
+
address: this.address.toString(),
|
|
146
|
+
fromBlock: from,
|
|
147
|
+
toBlock: to,
|
|
148
|
+
strict: true,
|
|
149
|
+
event,
|
|
150
|
+
args: { instance: rollupAddress.toString() },
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
if (logs.length > 0) {
|
|
154
|
+
const block = await this.client.getBlock({ blockNumber: logs[0].blockNumber });
|
|
155
|
+
return block.timestamp;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return undefined;
|
|
160
|
+
}
|
|
131
161
|
}
|
package/src/contracts/rollup.ts
CHANGED
|
@@ -193,10 +193,10 @@ export type CheckpointProposedArgs = {
|
|
|
193
193
|
checkpointNumber: CheckpointNumber;
|
|
194
194
|
archive: Fr;
|
|
195
195
|
versionedBlobHashes: Buffer[];
|
|
196
|
-
/** Hash of attestations
|
|
197
|
-
attestationsHash
|
|
198
|
-
/** Digest of the payload
|
|
199
|
-
payloadDigest
|
|
196
|
+
/** Hash of attestations emitted in the CheckpointProposed event. */
|
|
197
|
+
attestationsHash: Buffer32;
|
|
198
|
+
/** Digest of the payload emitted in the CheckpointProposed event. */
|
|
199
|
+
payloadDigest: Buffer32;
|
|
200
200
|
};
|
|
201
201
|
|
|
202
202
|
/** Log type for CheckpointProposed events. */
|
|
@@ -1060,8 +1060,22 @@ export class RollupContract {
|
|
|
1060
1060
|
checkpointNumber: CheckpointNumber.fromBigInt(log.args.checkpointNumber!),
|
|
1061
1061
|
archive: Fr.fromString(log.args.archive!),
|
|
1062
1062
|
versionedBlobHashes: log.args.versionedBlobHashes!.map(h => Buffer.from(h.slice(2), 'hex')),
|
|
1063
|
-
attestationsHash:
|
|
1064
|
-
|
|
1063
|
+
attestationsHash: (() => {
|
|
1064
|
+
if (!log.args.attestationsHash) {
|
|
1065
|
+
throw new Error(
|
|
1066
|
+
`CheckpointProposed event missing attestationsHash for checkpoint ${log.args.checkpointNumber}`,
|
|
1067
|
+
);
|
|
1068
|
+
}
|
|
1069
|
+
return Buffer32.fromString(log.args.attestationsHash);
|
|
1070
|
+
})(),
|
|
1071
|
+
payloadDigest: (() => {
|
|
1072
|
+
if (!log.args.payloadDigest) {
|
|
1073
|
+
throw new Error(
|
|
1074
|
+
`CheckpointProposed event missing payloadDigest for checkpoint ${log.args.checkpointNumber}`,
|
|
1075
|
+
);
|
|
1076
|
+
}
|
|
1077
|
+
return Buffer32.fromString(log.args.payloadDigest);
|
|
1078
|
+
})(),
|
|
1065
1079
|
},
|
|
1066
1080
|
}));
|
|
1067
1081
|
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
/** Default L1 contracts configuration values from network-defaults.yml */
|
|
5
5
|
export const l1ContractsDefaultEnv = {
|
|
6
6
|
ETHEREUM_SLOT_DURATION: 12,
|
|
7
|
-
AZTEC_SLOT_DURATION:
|
|
7
|
+
AZTEC_SLOT_DURATION: 72,
|
|
8
8
|
AZTEC_EPOCH_DURATION: 32,
|
|
9
9
|
AZTEC_TARGET_COMMITTEE_SIZE: 48,
|
|
10
10
|
AZTEC_LAG_IN_EPOCHS_FOR_VALIDATOR_SET: 2,
|
|
@@ -14,16 +14,13 @@ import {
|
|
|
14
14
|
type Abi,
|
|
15
15
|
type BlockOverrides,
|
|
16
16
|
type Hex,
|
|
17
|
-
type NonceManager,
|
|
18
17
|
type PrepareTransactionRequestRequest,
|
|
19
18
|
type StateOverride,
|
|
20
19
|
type TransactionReceipt,
|
|
21
20
|
type TransactionSerializable,
|
|
22
|
-
createNonceManager,
|
|
23
21
|
formatGwei,
|
|
24
22
|
serializeTransaction,
|
|
25
23
|
} from 'viem';
|
|
26
|
-
import { jsonRpc } from 'viem/nonce';
|
|
27
24
|
|
|
28
25
|
import type { ViemClient } from '../types.js';
|
|
29
26
|
import { formatViemError } from '../utils.js';
|
|
@@ -47,8 +44,9 @@ import {
|
|
|
47
44
|
const MAX_L1_TX_STATES = 32;
|
|
48
45
|
|
|
49
46
|
export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
50
|
-
protected nonceManager: NonceManager;
|
|
51
47
|
protected txs: L1TxState[] = [];
|
|
48
|
+
/** Last nonce successfully sent to the chain. Used as a lower bound when a fallback RPC node returns a stale count. */
|
|
49
|
+
private lastSentNonce: number | undefined;
|
|
52
50
|
/** Tx delayer for testing. Only set when enableDelayer config is true. */
|
|
53
51
|
public delayer?: Delayer;
|
|
54
52
|
/** KZG instance for blob operations. */
|
|
@@ -68,7 +66,6 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
68
66
|
delayer?: Delayer,
|
|
69
67
|
) {
|
|
70
68
|
super(client, logger, dateProvider, config, debugMaxGasLimit);
|
|
71
|
-
this.nonceManager = createNonceManager({ source: jsonRpc() });
|
|
72
69
|
this.kzg = kzg;
|
|
73
70
|
|
|
74
71
|
// Set up delayer: use provided one or create new
|
|
@@ -110,6 +107,11 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
110
107
|
this.metrics?.recordMinedTx(l1TxState, new Date(l1Timestamp));
|
|
111
108
|
} else if (newState === TxUtilsState.NOT_MINED) {
|
|
112
109
|
this.metrics?.recordDroppedTx(l1TxState);
|
|
110
|
+
// The tx was dropped: the chain nonce reverted to l1TxState.nonce, so our lower bound is
|
|
111
|
+
// no longer valid. Clear it so the next send fetches the real nonce from the chain.
|
|
112
|
+
if (this.lastSentNonce === l1TxState.nonce) {
|
|
113
|
+
this.lastSentNonce = undefined;
|
|
114
|
+
}
|
|
113
115
|
}
|
|
114
116
|
|
|
115
117
|
// Update state in the store
|
|
@@ -244,9 +246,6 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
244
246
|
throw new InterruptError(`Transaction sending is interrupted`);
|
|
245
247
|
}
|
|
246
248
|
|
|
247
|
-
// Check timeout before consuming nonce to avoid leaking a nonce that was never sent.
|
|
248
|
-
// A leaked nonce creates a gap (e.g. nonce 107 consumed but unsent), so all subsequent
|
|
249
|
-
// transactions (108, 109, ...) can never be mined since the chain expects 107 first.
|
|
250
249
|
const now = new Date(await this.getL1Timestamp());
|
|
251
250
|
if (gasConfig.txTimeoutAt && now > gasConfig.txTimeoutAt) {
|
|
252
251
|
throw new TimeoutError(
|
|
@@ -254,11 +253,11 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
254
253
|
);
|
|
255
254
|
}
|
|
256
255
|
|
|
257
|
-
const
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
256
|
+
const chainNonce = await this.client.getTransactionCount({ address: account, blockTag: 'pending' });
|
|
257
|
+
// If a fallback RPC node returns a stale count (lower than what we last sent), use our
|
|
258
|
+
// local lower bound to avoid sending a duplicate of an already-pending transaction.
|
|
259
|
+
const nonce =
|
|
260
|
+
this.lastSentNonce !== undefined && chainNonce <= this.lastSentNonce ? this.lastSentNonce + 1 : chainNonce;
|
|
262
261
|
|
|
263
262
|
const baseState = { request, gasLimit, blobInputs, gasPrice, nonce };
|
|
264
263
|
const txData = this.makeTxData(baseState, { isCancelTx: false });
|
|
@@ -266,6 +265,8 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
266
265
|
// Send the new tx
|
|
267
266
|
const signedRequest = await this.prepareSignedTransaction(txData);
|
|
268
267
|
const txHash = await this.client.sendRawTransaction({ serializedTransaction: signedRequest });
|
|
268
|
+
// Update after tx is sent successfully
|
|
269
|
+
this.lastSentNonce = nonce;
|
|
269
270
|
|
|
270
271
|
// Create the new state for monitoring
|
|
271
272
|
const l1TxState: L1TxState = {
|
|
@@ -449,7 +450,6 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
449
450
|
{ nonce, account, pendingNonce, timePassed },
|
|
450
451
|
);
|
|
451
452
|
await this.updateState(state, TxUtilsState.NOT_MINED);
|
|
452
|
-
this.nonceManager.reset({ address: account, chainId: this.client.chain.id });
|
|
453
453
|
throw new DroppedTransactionError(nonce, account);
|
|
454
454
|
}
|
|
455
455
|
|
|
@@ -541,12 +541,7 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
541
541
|
|
|
542
542
|
// Oh no, the transaction has timed out!
|
|
543
543
|
if (isCancelTx || !gasConfig.cancelTxOnTimeout) {
|
|
544
|
-
// If this was already a cancellation tx, or we are configured to not cancel txs, we just mark it as NOT_MINED
|
|
545
|
-
// and reset the nonce manager, so the next tx that comes along can reuse the nonce if/when this tx gets dropped.
|
|
546
|
-
// This is the nastiest scenario for us, since the new tx could acquire the next nonce, but then this tx is dropped,
|
|
547
|
-
// and the new tx would never get mined. Eventually, the new tx would also drop.
|
|
548
544
|
await this.updateState(state, TxUtilsState.NOT_MINED);
|
|
549
|
-
this.nonceManager.reset({ address: account, chainId: this.client.chain.id });
|
|
550
545
|
} else {
|
|
551
546
|
// Otherwise we fire the cancellation without awaiting to avoid blocking the caller,
|
|
552
547
|
// and monitor it in the background so we can speed it up as needed.
|
|
@@ -685,7 +680,6 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
685
680
|
{ nonce, account },
|
|
686
681
|
);
|
|
687
682
|
await this.updateState(state, TxUtilsState.NOT_MINED);
|
|
688
|
-
this.nonceManager.reset({ address: account, chainId: this.client.chain.id });
|
|
689
683
|
return;
|
|
690
684
|
}
|
|
691
685
|
|
|
@@ -697,7 +691,6 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
697
691
|
{ nonce, account, currentNonce },
|
|
698
692
|
);
|
|
699
693
|
await this.updateState(state, TxUtilsState.NOT_MINED);
|
|
700
|
-
this.nonceManager.reset({ address: account, chainId: this.client.chain.id });
|
|
701
694
|
return;
|
|
702
695
|
}
|
|
703
696
|
|