@aztec/ethereum 0.0.1-commit.6b113946b → 0.0.1-commit.6bd18f1aa
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/contracts/multicall.d.ts +51 -2
- package/dest/contracts/multicall.d.ts.map +1 -1
- package/dest/contracts/multicall.js +85 -0
- package/dest/contracts/rollup.d.ts +4 -3
- package/dest/contracts/rollup.d.ts.map +1 -1
- package/dest/contracts/rollup.js +12 -7
- package/dest/l1_artifacts.d.ts +69 -69
- package/dest/l1_tx_utils/l1_tx_utils.d.ts +3 -1
- package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -1
- package/dest/l1_tx_utils/l1_tx_utils.js +33 -25
- package/dest/publisher_manager.d.ts +21 -7
- package/dest/publisher_manager.d.ts.map +1 -1
- package/dest/publisher_manager.js +81 -7
- package/dest/test/eth_cheat_codes.d.ts +6 -4
- package/dest/test/eth_cheat_codes.d.ts.map +1 -1
- package/dest/test/eth_cheat_codes.js +6 -4
- package/dest/test/start_anvil.d.ts +8 -1
- package/dest/test/start_anvil.d.ts.map +1 -1
- package/dest/test/start_anvil.js +16 -2
- package/package.json +5 -5
- package/src/contracts/multicall.ts +65 -1
- package/src/contracts/rollup.ts +11 -8
- package/src/l1_tx_utils/l1_tx_utils.ts +23 -13
- package/src/publisher_manager.ts +105 -10
- package/src/test/eth_cheat_codes.ts +6 -4
- package/src/test/start_anvil.ts +25 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eth_cheat_codes.d.ts","sourceRoot":"","sources":["../../src/test/eth_cheat_codes.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAI3D,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE9E,OAAO,EAAE,KAAK,KAAK,EAAE,KAAK,GAAG,EAAE,KAAK,WAAW,EAAmD,MAAM,MAAM,CA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CAG7D;IAED;;;OAGG;IACU,cAAc,CAAC,UAAU,GAAE,MAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CA+CjE;IAEY,mBAAmB,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CA+BpE;IAEY,gBAAgB,kBAK5B;CACF;AAED,KAAK,WAAW,GAAG,SAAS,GAAG,QAAQ,CAAC;AAOxC,MAAM,MAAM,iBAAiB,GAAG,WAAW,GAAG;IAC5C,SAAS,EAAE,WAAW,CAAC;CACxB,CAAC"}
|
|
@@ -70,9 +70,11 @@ import { foundry } from 'viem/chains';
|
|
|
70
70
|
return parseInt(res, 16);
|
|
71
71
|
}
|
|
72
72
|
/**
|
|
73
|
-
* Get the
|
|
74
|
-
*
|
|
75
|
-
|
|
73
|
+
* Get the timestamp of the latest mined L1 block.
|
|
74
|
+
* Note: this is NOT the current time — it's the discrete timestamp of the last block.
|
|
75
|
+
* Between blocks, the actual chain time advances but no new block reflects it.
|
|
76
|
+
* @returns The latest block timestamp in seconds
|
|
77
|
+
*/ async lastBlockTimestamp() {
|
|
76
78
|
const res = await this.doRpcCall('eth_getBlockByNumber', [
|
|
77
79
|
'latest',
|
|
78
80
|
true
|
|
@@ -536,7 +538,7 @@ import { foundry } from 'viem/chains';
|
|
|
536
538
|
}
|
|
537
539
|
}
|
|
538
540
|
async syncDateProvider() {
|
|
539
|
-
const timestamp = await this.
|
|
541
|
+
const timestamp = await this.lastBlockTimestamp();
|
|
540
542
|
if ('setTime' in this.dateProvider) {
|
|
541
543
|
this.dateProvider.setTime(timestamp * 1000);
|
|
542
544
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { TestDateProvider } from '@aztec/foundation/timer';
|
|
1
2
|
/** Minimal interface matching the @viem/anvil Anvil shape used by callers. */
|
|
2
3
|
export interface Anvil {
|
|
3
4
|
readonly port: number;
|
|
@@ -24,10 +25,16 @@ export declare function startAnvil(opts?: {
|
|
|
24
25
|
* L1-finality-based logic work without needing hundreds of mined blocks.
|
|
25
26
|
*/
|
|
26
27
|
slotsInAnEpoch?: number;
|
|
28
|
+
/**
|
|
29
|
+
* If provided, the date provider will be synced to anvil's block time on every mined block.
|
|
30
|
+
* This keeps the dateProvider in lockstep with anvil's chain time, avoiding drift between
|
|
31
|
+
* the wall clock and the L1 chain when computing L1 slot timestamps.
|
|
32
|
+
*/
|
|
33
|
+
dateProvider?: TestDateProvider;
|
|
27
34
|
}): Promise<{
|
|
28
35
|
anvil: Anvil;
|
|
29
36
|
methodCalls?: string[];
|
|
30
37
|
rpcUrl: string;
|
|
31
38
|
stop: () => Promise<void>;
|
|
32
39
|
}>;
|
|
33
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
40
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3RhcnRfYW52aWwuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy90ZXN0L3N0YXJ0X2FudmlsLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUVBLE9BQU8sS0FBSyxFQUFFLGdCQUFnQixFQUFFLE1BQU0seUJBQXlCLENBQUM7QUFNaEUsOEVBQThFO0FBQzlFLE1BQU0sV0FBVyxLQUFLO0lBQ3BCLFFBQVEsQ0FBQyxJQUFJLEVBQUUsTUFBTSxDQUFDO0lBQ3RCLFFBQVEsQ0FBQyxJQUFJLEVBQUUsTUFBTSxDQUFDO0lBQ3RCLFFBQVEsQ0FBQyxNQUFNLEVBQUUsV0FBVyxHQUFHLE1BQU0sQ0FBQztJQUN0QyxJQUFJLElBQUksT0FBTyxDQUFDLElBQUksQ0FBQyxDQUFDO0NBQ3ZCO0FBRUQ7O0dBRUc7QUFDSCx3QkFBc0IsVUFBVSxDQUM5QixJQUFJLEdBQUU7SUFDSixJQUFJLENBQUMsRUFBRSxNQUFNLENBQUM7SUFDZCxXQUFXLENBQUMsRUFBRSxNQUFNLENBQUM7SUFDckIsR0FBRyxDQUFDLEVBQUUsT0FBTyxDQUFDO0lBQ2Qsa0JBQWtCLENBQUMsRUFBRSxPQUFPLENBQUM7SUFDN0IsUUFBUSxDQUFDLEVBQUUsTUFBTSxDQUFDO0lBQ2xCLE9BQU8sQ0FBQyxFQUFFLE1BQU0sQ0FBQztJQUNqQixxREFBcUQ7SUFDckQsUUFBUSxDQUFDLEVBQUUsTUFBTSxDQUFDO0lBQ2xCOzs7OztPQUtHO0lBQ0gsY0FBYyxDQUFDLEVBQUUsTUFBTSxDQUFDO0lBQ3hCOzs7O09BSUc7SUFDSCxZQUFZLENBQUMsRUFBRSxnQkFBZ0IsQ0FBQztDQUM1QixHQUNMLE9BQU8sQ0FBQztJQUFFLEtBQUssRUFBRSxLQUFLLENBQUM7SUFBQyxXQUFXLENBQUMsRUFBRSxNQUFNLEVBQUUsQ0FBQztJQUFDLE1BQU0sRUFBRSxNQUFNLENBQUM7SUFBQyxJQUFJLEVBQUUsTUFBTSxPQUFPLENBQUMsSUFBSSxDQUFDLENBQUE7Q0FBRSxDQUFDLENBK0g5RiJ9
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"start_anvil.d.ts","sourceRoot":"","sources":["../../src/test/start_anvil.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"start_anvil.d.ts","sourceRoot":"","sources":["../../src/test/start_anvil.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAMhE,8EAA8E;AAC9E,MAAM,WAAW,KAAK;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,CAAC;IACtC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACvB;AAED;;GAEG;AACH,wBAAsB,UAAU,CAC9B,IAAI,GAAE;IACJ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,qDAAqD;IACrD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;;OAKG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;;OAIG;IACH,YAAY,CAAC,EAAE,gBAAgB,CAAC;CAC5B,GACL,OAAO,CAAC;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAAE,CAAC,CA+H9F"}
|
package/dest/test/start_anvil.js
CHANGED
|
@@ -75,12 +75,15 @@ import { dirname, resolve } from 'path';
|
|
|
75
75
|
child.stderr?.on('data', onStderr);
|
|
76
76
|
child.once('close', onClose);
|
|
77
77
|
});
|
|
78
|
-
// Continue piping for logging
|
|
79
|
-
if (logger || opts.captureMethodCalls) {
|
|
78
|
+
// Continue piping for logging, method-call capture, and/or dateProvider sync after startup.
|
|
79
|
+
if (logger || opts.captureMethodCalls || opts.dateProvider) {
|
|
80
80
|
child.stdout?.on('data', (data)=>{
|
|
81
81
|
const text = data.toString();
|
|
82
82
|
logger?.debug(text.trim());
|
|
83
83
|
methodCalls?.push(...text.match(/eth_[^\s]+/g) || []);
|
|
84
|
+
if (opts.dateProvider) {
|
|
85
|
+
syncDateProviderFromAnvilOutput(text, opts.dateProvider);
|
|
86
|
+
}
|
|
84
87
|
});
|
|
85
88
|
child.stderr?.on('data', (data)=>{
|
|
86
89
|
logger?.debug(data.toString().trim());
|
|
@@ -125,6 +128,17 @@ import { dirname, resolve } from 'path';
|
|
|
125
128
|
rpcUrl: `http://127.0.0.1:${port}`
|
|
126
129
|
};
|
|
127
130
|
}
|
|
131
|
+
/** Extracts block time from anvil stdout and syncs the dateProvider. */ function syncDateProviderFromAnvilOutput(text, dateProvider) {
|
|
132
|
+
// Anvil logs mined blocks as:
|
|
133
|
+
// Block Time: "Fri, 20 Mar 2026 02:10:46 +0000"
|
|
134
|
+
const match = text.match(/Block Time:\s*"([^"]+)"/);
|
|
135
|
+
if (match) {
|
|
136
|
+
const blockTimeMs = new Date(match[1]).getTime();
|
|
137
|
+
if (!isNaN(blockTimeMs)) {
|
|
138
|
+
dateProvider.setTime(blockTimeMs);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
128
142
|
/** Send SIGTERM, wait up to 5 s, then SIGKILL. All timers are always cleared. */ function killChild(child) {
|
|
129
143
|
return new Promise((resolve)=>{
|
|
130
144
|
if (child.exitCode !== null || child.killed) {
|
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.6bd18f1aa",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./account": "./dest/account.js",
|
|
@@ -50,10 +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.
|
|
53
|
+
"@aztec/blob-lib": "0.0.1-commit.6bd18f1aa",
|
|
54
|
+
"@aztec/constants": "0.0.1-commit.6bd18f1aa",
|
|
55
|
+
"@aztec/foundation": "0.0.1-commit.6bd18f1aa",
|
|
56
|
+
"@aztec/l1-artifacts": "0.0.1-commit.6bd18f1aa",
|
|
57
57
|
"dotenv": "^16.0.3",
|
|
58
58
|
"lodash.chunk": "^4.2.0",
|
|
59
59
|
"lodash.pickby": "^4.5.0",
|
|
@@ -2,7 +2,7 @@ import { toHex as toPaddedHex } from '@aztec/foundation/bigint-buffer';
|
|
|
2
2
|
import { TimeoutError } from '@aztec/foundation/error';
|
|
3
3
|
import type { Logger } from '@aztec/foundation/log';
|
|
4
4
|
|
|
5
|
-
import { type EncodeFunctionDataParameters, type Hex, encodeFunctionData, multicall3Abi } from 'viem';
|
|
5
|
+
import { type Address, type EncodeFunctionDataParameters, type Hex, encodeFunctionData, multicall3Abi } from 'viem';
|
|
6
6
|
|
|
7
7
|
import type { L1BlobInputs, L1TxConfig, L1TxRequest, L1TxUtils } from '../l1_tx_utils/index.js';
|
|
8
8
|
import type { ExtendedViemWalletClient } from '../types.js';
|
|
@@ -11,6 +11,39 @@ import { RollupContract } from './rollup.js';
|
|
|
11
11
|
|
|
12
12
|
export const MULTI_CALL_3_ADDRESS = '0xcA11bde05977b3631167028862bE2a173976CA11' as const;
|
|
13
13
|
|
|
14
|
+
/** ABI fragment for aggregate3Value — not included in viem's multicall3Abi. */
|
|
15
|
+
export const aggregate3ValueAbi = [
|
|
16
|
+
{
|
|
17
|
+
inputs: [
|
|
18
|
+
{
|
|
19
|
+
components: [
|
|
20
|
+
{ internalType: 'address', name: 'target', type: 'address' },
|
|
21
|
+
{ internalType: 'bool', name: 'allowFailure', type: 'bool' },
|
|
22
|
+
{ internalType: 'uint256', name: 'value', type: 'uint256' },
|
|
23
|
+
{ internalType: 'bytes', name: 'callData', type: 'bytes' },
|
|
24
|
+
],
|
|
25
|
+
internalType: 'struct Multicall3.Call3Value[]',
|
|
26
|
+
name: 'calls',
|
|
27
|
+
type: 'tuple[]',
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
name: 'aggregate3Value',
|
|
31
|
+
outputs: [
|
|
32
|
+
{
|
|
33
|
+
components: [
|
|
34
|
+
{ internalType: 'bool', name: 'success', type: 'bool' },
|
|
35
|
+
{ internalType: 'bytes', name: 'returnData', type: 'bytes' },
|
|
36
|
+
],
|
|
37
|
+
internalType: 'struct Multicall3.Result[]',
|
|
38
|
+
name: 'returnData',
|
|
39
|
+
type: 'tuple[]',
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
stateMutability: 'payable',
|
|
43
|
+
type: 'function',
|
|
44
|
+
},
|
|
45
|
+
] as const;
|
|
46
|
+
|
|
14
47
|
export class Multicall3 {
|
|
15
48
|
static async forward(
|
|
16
49
|
requests: L1TxRequest[],
|
|
@@ -122,6 +155,37 @@ export class Multicall3 {
|
|
|
122
155
|
throw err;
|
|
123
156
|
}
|
|
124
157
|
}
|
|
158
|
+
|
|
159
|
+
/** Batch multiple value transfers into a single aggregate3Value call on Multicall3. */
|
|
160
|
+
static async forwardValue(calls: { to: Address; value: bigint }[], l1TxUtils: L1TxUtils, logger: Logger) {
|
|
161
|
+
const args = calls.map(c => ({
|
|
162
|
+
target: c.to,
|
|
163
|
+
allowFailure: false,
|
|
164
|
+
value: c.value,
|
|
165
|
+
callData: '0x' as Hex,
|
|
166
|
+
}));
|
|
167
|
+
|
|
168
|
+
const data = encodeFunctionData({
|
|
169
|
+
abi: aggregate3ValueAbi,
|
|
170
|
+
functionName: 'aggregate3Value',
|
|
171
|
+
args: [args],
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
const totalValue = calls.reduce((sum, c) => sum + c.value, 0n);
|
|
175
|
+
|
|
176
|
+
logger.info(`Sending aggregate3Value with ${calls.length} calls`, { totalValue });
|
|
177
|
+
const { receipt } = await l1TxUtils.sendAndMonitorTransaction({
|
|
178
|
+
to: MULTI_CALL_3_ADDRESS,
|
|
179
|
+
data,
|
|
180
|
+
value: totalValue,
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
if (receipt.status !== 'success') {
|
|
184
|
+
throw new Error(`aggregate3Value transaction reverted: ${receipt.transactionHash}`);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return { receipt };
|
|
188
|
+
}
|
|
125
189
|
}
|
|
126
190
|
|
|
127
191
|
export async function deployMulticall3(l1Client: ExtendedViemWalletClient, logger: Logger) {
|
package/src/contracts/rollup.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { Fr } from '@aztec/foundation/curves/bn254';
|
|
|
4
4
|
import { memoize } from '@aztec/foundation/decorators';
|
|
5
5
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
6
6
|
import type { ViemSignature } from '@aztec/foundation/eth-signature';
|
|
7
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
7
8
|
import { makeBackoff, retry } from '@aztec/foundation/retry';
|
|
8
9
|
import { EscapeHatchAbi } from '@aztec/l1-artifacts/EscapeHatchAbi';
|
|
9
10
|
import { RollupAbi } from '@aztec/l1-artifacts/RollupAbi';
|
|
@@ -212,6 +213,7 @@ export type CheckpointProposedLog = L1EventLog<CheckpointProposedArgs>;
|
|
|
212
213
|
|
|
213
214
|
export class RollupContract {
|
|
214
215
|
private readonly rollup: GetContractReturnType<typeof RollupAbi, ViemClient>;
|
|
216
|
+
private readonly logger = createLogger('ethereum:rollup');
|
|
215
217
|
|
|
216
218
|
private static cachedStfStorageSlot: Hex | undefined;
|
|
217
219
|
private cachedEscapeHatch?: {
|
|
@@ -495,7 +497,11 @@ export class RollupContract {
|
|
|
495
497
|
|
|
496
498
|
const [isOpen] = await escapeHatch.read.isHatchOpen([BigInt(epoch)]);
|
|
497
499
|
return isOpen;
|
|
498
|
-
} catch {
|
|
500
|
+
} catch (err) {
|
|
501
|
+
this.logger.warn('isEscapeHatchOpen failed (treating as closed); RPC or contract error may cause liveness risk', {
|
|
502
|
+
epoch: Number(epoch),
|
|
503
|
+
error: err,
|
|
504
|
+
});
|
|
499
505
|
return false;
|
|
500
506
|
}
|
|
501
507
|
}
|
|
@@ -781,12 +787,10 @@ export class RollupContract {
|
|
|
781
787
|
public async canProposeAt(
|
|
782
788
|
archive: Buffer,
|
|
783
789
|
account: `0x${string}` | Account,
|
|
784
|
-
|
|
785
|
-
slotOffset: bigint,
|
|
790
|
+
timestamp: bigint,
|
|
786
791
|
opts: { forcePendingCheckpointNumber?: CheckpointNumber } = {},
|
|
787
792
|
): Promise<{ slot: SlotNumber; checkpointNumber: CheckpointNumber; timeOfNextL1Slot: bigint }> {
|
|
788
|
-
const
|
|
789
|
-
const timeOfNextL1Slot = latestBlock.timestamp + slotDuration + slotOffset;
|
|
793
|
+
const timeOfNextL1Slot = timestamp;
|
|
790
794
|
const who = typeof account === 'string' ? account : account.address;
|
|
791
795
|
|
|
792
796
|
try {
|
|
@@ -939,11 +943,10 @@ export class RollupContract {
|
|
|
939
943
|
return this.rollup.read.getSpecificProverRewardsForEpoch([epoch, prover]);
|
|
940
944
|
}
|
|
941
945
|
|
|
942
|
-
async getAttesters(): Promise<EthAddress[]> {
|
|
946
|
+
async getAttesters(timestamp?: bigint): Promise<EthAddress[]> {
|
|
943
947
|
const attesterSize = await this.getActiveAttesterCount();
|
|
944
948
|
const gse = new GSEContract(this.client, await this.getGSE());
|
|
945
|
-
const ts = (await this.client.getBlock()).timestamp;
|
|
946
|
-
|
|
949
|
+
const ts = timestamp ?? (await this.client.getBlock()).timestamp;
|
|
947
950
|
const indices = Array.from({ length: attesterSize }, (_, i) => BigInt(i));
|
|
948
951
|
const chunks = chunk(indices, 1000);
|
|
949
952
|
|
|
@@ -4,6 +4,7 @@ import { merge, pick } from '@aztec/foundation/collection';
|
|
|
4
4
|
import { InterruptError, TimeoutError } from '@aztec/foundation/error';
|
|
5
5
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
6
6
|
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
7
|
+
import { Semaphore } from '@aztec/foundation/queue';
|
|
7
8
|
import { retryUntil } from '@aztec/foundation/retry';
|
|
8
9
|
import { sleep } from '@aztec/foundation/sleep';
|
|
9
10
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
@@ -47,6 +48,8 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
47
48
|
protected txs: L1TxState[] = [];
|
|
48
49
|
/** Last nonce successfully sent to the chain. Used as a lower bound when a fallback RPC node returns a stale count. */
|
|
49
50
|
private lastSentNonce: number | undefined;
|
|
51
|
+
/** Mutex to prevent concurrent sendTransaction calls from racing on the same nonce. */
|
|
52
|
+
private readonly sendMutex = new Semaphore(1);
|
|
50
53
|
/** Tx delayer for testing. Only set when enableDelayer config is true. */
|
|
51
54
|
public delayer?: Delayer;
|
|
52
55
|
/** KZG instance for blob operations. */
|
|
@@ -253,20 +256,27 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
253
256
|
);
|
|
254
257
|
}
|
|
255
258
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
const nonce =
|
|
260
|
-
this.lastSentNonce !== undefined && chainNonce <= this.lastSentNonce ? this.lastSentNonce + 1 : chainNonce;
|
|
259
|
+
let txHash: Hex;
|
|
260
|
+
let nonce: number;
|
|
261
|
+
let baseState: Pick<L1TxState, 'request' | 'gasLimit' | 'blobInputs' | 'gasPrice' | 'nonce'>;
|
|
261
262
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
263
|
+
await this.sendMutex.acquire();
|
|
264
|
+
try {
|
|
265
|
+
const chainNonce = await this.client.getTransactionCount({ address: account, blockTag: 'pending' });
|
|
266
|
+
// If a fallback RPC node returns a stale count (lower than what we last sent), use our
|
|
267
|
+
// local lower bound to avoid sending a duplicate of an already-pending transaction.
|
|
268
|
+
nonce =
|
|
269
|
+
this.lastSentNonce !== undefined && chainNonce <= this.lastSentNonce ? this.lastSentNonce + 1 : chainNonce;
|
|
270
|
+
|
|
271
|
+
baseState = { request, gasLimit, blobInputs, gasPrice, nonce };
|
|
272
|
+
const txData = this.makeTxData(baseState, { isCancelTx: false });
|
|
273
|
+
|
|
274
|
+
const signedRequest = await this.prepareSignedTransaction(txData);
|
|
275
|
+
txHash = await this.client.sendRawTransaction({ serializedTransaction: signedRequest });
|
|
276
|
+
this.lastSentNonce = nonce;
|
|
277
|
+
} finally {
|
|
278
|
+
this.sendMutex.release();
|
|
279
|
+
}
|
|
270
280
|
|
|
271
281
|
// Create the new state for monitoring
|
|
272
282
|
const l1TxState: L1TxState = {
|
package/src/publisher_manager.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { pick } from '@aztec/foundation/collection';
|
|
2
2
|
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
3
|
+
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
3
4
|
|
|
5
|
+
import { Multicall3 } from './contracts/multicall.js';
|
|
4
6
|
import { L1TxUtils, TxUtilsState } from './l1_tx_utils/index.js';
|
|
5
7
|
|
|
6
8
|
// Defines the order in which we prioritise publishers based on their state (first is better)
|
|
@@ -27,24 +29,72 @@ const busyStates: TxUtilsState[] = [
|
|
|
27
29
|
|
|
28
30
|
export type PublisherFilter<UtilsType extends L1TxUtils> = (utils: UtilsType) => boolean;
|
|
29
31
|
|
|
32
|
+
/** Config accepted by PublisherManager. */
|
|
33
|
+
type PublisherManagerConfig = {
|
|
34
|
+
publisherAllowInvalidStates?: boolean;
|
|
35
|
+
publisherFundingThreshold?: bigint;
|
|
36
|
+
publisherFundingAmount?: bigint;
|
|
37
|
+
};
|
|
38
|
+
|
|
30
39
|
export class PublisherManager<UtilsType extends L1TxUtils = L1TxUtils> {
|
|
31
40
|
private log: Logger;
|
|
32
|
-
private config:
|
|
41
|
+
private config: PublisherManagerConfig;
|
|
42
|
+
private static readonly FUNDING_CHECK_INTERVAL_MS = 2 * 60 * 1000;
|
|
43
|
+
private funder?: UtilsType;
|
|
44
|
+
private fundingPromise?: RunningPromise;
|
|
33
45
|
|
|
34
46
|
constructor(
|
|
35
47
|
private publishers: UtilsType[],
|
|
36
|
-
config:
|
|
37
|
-
bindings?: LoggerBindings,
|
|
48
|
+
config: PublisherManagerConfig,
|
|
49
|
+
opts?: { bindings?: LoggerBindings; funder?: UtilsType },
|
|
38
50
|
) {
|
|
39
|
-
this.
|
|
51
|
+
this.funder = opts?.funder;
|
|
52
|
+
this.log = createLogger('publisher:manager', opts?.bindings);
|
|
40
53
|
this.log.info(`PublisherManager initialized with ${publishers.length} publishers.`);
|
|
41
54
|
this.publishers = publishers;
|
|
42
|
-
this.config = pick(config, 'publisherAllowInvalidStates');
|
|
55
|
+
this.config = pick(config, 'publisherAllowInvalidStates', 'publisherFundingThreshold', 'publisherFundingAmount');
|
|
56
|
+
|
|
57
|
+
const hasThreshold = this.config.publisherFundingThreshold !== undefined;
|
|
58
|
+
const hasAmount = this.config.publisherFundingAmount !== undefined;
|
|
59
|
+
if (hasThreshold !== hasAmount) {
|
|
60
|
+
this.log.warn(`Incomplete funding config: both publisherFundingThreshold and publisherFundingAmount must be set`);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (this.funder) {
|
|
64
|
+
const funderAddress = this.funder.getSenderAddress();
|
|
65
|
+
if (publishers.some(p => p.getSenderAddress().equals(funderAddress))) {
|
|
66
|
+
this.log.error(`Funding account ${funderAddress} is also a publisher, disabling funding to avoid self-funding`);
|
|
67
|
+
this.funder = undefined;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
43
70
|
}
|
|
44
71
|
|
|
45
|
-
/** Loads the state of all publishers and
|
|
46
|
-
public async
|
|
47
|
-
await Promise.all(
|
|
72
|
+
/** Loads the state of all publishers and the funder, and starts periodic funding checks. */
|
|
73
|
+
public async start(): Promise<void> {
|
|
74
|
+
await Promise.all([
|
|
75
|
+
...this.publishers.map(pub => pub.loadStateAndResumeMonitoring()),
|
|
76
|
+
this.funder?.loadStateAndResumeMonitoring(),
|
|
77
|
+
]);
|
|
78
|
+
|
|
79
|
+
if (
|
|
80
|
+
this.funder &&
|
|
81
|
+
this.config.publisherFundingThreshold !== undefined &&
|
|
82
|
+
this.config.publisherFundingAmount !== undefined
|
|
83
|
+
) {
|
|
84
|
+
this.fundingPromise = new RunningPromise(
|
|
85
|
+
() => this.triggerFundingIfNeeded(),
|
|
86
|
+
this.log,
|
|
87
|
+
PublisherManager.FUNDING_CHECK_INTERVAL_MS,
|
|
88
|
+
);
|
|
89
|
+
this.fundingPromise.start();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Stops the funding loop and interrupts all publishers. */
|
|
94
|
+
public async stop(): Promise<void> {
|
|
95
|
+
await this.fundingPromise?.stop();
|
|
96
|
+
this.publishers.forEach(pub => pub.interrupt());
|
|
97
|
+
this.funder?.interrupt();
|
|
48
98
|
}
|
|
49
99
|
|
|
50
100
|
// Finds and prioritises available publishers based on
|
|
@@ -102,7 +152,52 @@ export class PublisherManager<UtilsType extends L1TxUtils = L1TxUtils> {
|
|
|
102
152
|
return sortedPublishers[0].publisher;
|
|
103
153
|
}
|
|
104
154
|
|
|
105
|
-
|
|
106
|
-
|
|
155
|
+
/** Check all publisher balances and fund those below threshold. */
|
|
156
|
+
private async triggerFundingIfNeeded(): Promise<void> {
|
|
157
|
+
const { funder, config } = this;
|
|
158
|
+
if (!funder || config.publisherFundingThreshold === undefined || config.publisherFundingAmount === undefined) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const allBalances = await Promise.all(
|
|
163
|
+
this.publishers.map(async pub => ({ balance: await pub.getSenderBalance(), publisher: pub })),
|
|
164
|
+
);
|
|
165
|
+
const lowBalance = allBalances.filter(p => p.balance < config.publisherFundingThreshold!);
|
|
166
|
+
if (lowBalance.length === 0) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const fundingAmount = config.publisherFundingAmount!;
|
|
171
|
+
const funderBalance = await funder.getSenderBalance();
|
|
172
|
+
|
|
173
|
+
if (funderBalance < 10n * fundingAmount) {
|
|
174
|
+
this.log.warn(`Funding account balance is low`, { funderBalance, threshold: 10n * fundingAmount });
|
|
175
|
+
}
|
|
176
|
+
const affordableCount = Number(funderBalance / fundingAmount);
|
|
177
|
+
if (affordableCount === 0) {
|
|
178
|
+
this.log.error(`Funding account balance too low to fund any publisher`, { funderBalance, fundingAmount });
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
if (affordableCount < lowBalance.length) {
|
|
182
|
+
this.log.warn(`Funder can only afford ${affordableCount}/${lowBalance.length} publishers`, {
|
|
183
|
+
funderBalance,
|
|
184
|
+
fundingAmount,
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const toFund = lowBalance.slice(0, affordableCount).map(p => p.publisher);
|
|
189
|
+
await this.fundPublishers(toFund);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** Fund publishers via a single Multicall3 aggregate3Value transaction. */
|
|
193
|
+
private async fundPublishers(publishers: UtilsType[]): Promise<void> {
|
|
194
|
+
const fundingAmount = this.config.publisherFundingAmount!;
|
|
195
|
+
const calls = publishers.map(pub => ({
|
|
196
|
+
to: pub.getSenderAddress().toString(),
|
|
197
|
+
value: fundingAmount,
|
|
198
|
+
}));
|
|
199
|
+
|
|
200
|
+
await Multicall3.forwardValue(calls, this.funder!, this.log);
|
|
201
|
+
this.log.info(`Funded ${publishers.length} publishers`);
|
|
107
202
|
}
|
|
108
203
|
}
|
|
@@ -85,10 +85,12 @@ export class EthCheatCodes {
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
/**
|
|
88
|
-
* Get the
|
|
89
|
-
*
|
|
88
|
+
* Get the timestamp of the latest mined L1 block.
|
|
89
|
+
* Note: this is NOT the current time — it's the discrete timestamp of the last block.
|
|
90
|
+
* Between blocks, the actual chain time advances but no new block reflects it.
|
|
91
|
+
* @returns The latest block timestamp in seconds
|
|
90
92
|
*/
|
|
91
|
-
public async
|
|
93
|
+
public async lastBlockTimestamp(): Promise<number> {
|
|
92
94
|
const res = await this.doRpcCall('eth_getBlockByNumber', ['latest', true]);
|
|
93
95
|
return parseInt(res.timestamp, 16);
|
|
94
96
|
}
|
|
@@ -552,7 +554,7 @@ export class EthCheatCodes {
|
|
|
552
554
|
}
|
|
553
555
|
|
|
554
556
|
public async syncDateProvider() {
|
|
555
|
-
const timestamp = await this.
|
|
557
|
+
const timestamp = await this.lastBlockTimestamp();
|
|
556
558
|
if ('setTime' in this.dateProvider) {
|
|
557
559
|
this.dateProvider.setTime(timestamp * 1000);
|
|
558
560
|
}
|
package/src/test/start_anvil.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createLogger } from '@aztec/foundation/log';
|
|
2
2
|
import { makeBackoff, retry } from '@aztec/foundation/retry';
|
|
3
|
+
import type { TestDateProvider } from '@aztec/foundation/timer';
|
|
3
4
|
import { fileURLToPath } from '@aztec/foundation/url';
|
|
4
5
|
|
|
5
6
|
import { type ChildProcess, spawn } from 'child_process';
|
|
@@ -33,6 +34,12 @@ export async function startAnvil(
|
|
|
33
34
|
* L1-finality-based logic work without needing hundreds of mined blocks.
|
|
34
35
|
*/
|
|
35
36
|
slotsInAnEpoch?: number;
|
|
37
|
+
/**
|
|
38
|
+
* If provided, the date provider will be synced to anvil's block time on every mined block.
|
|
39
|
+
* This keeps the dateProvider in lockstep with anvil's chain time, avoiding drift between
|
|
40
|
+
* the wall clock and the L1 chain when computing L1 slot timestamps.
|
|
41
|
+
*/
|
|
42
|
+
dateProvider?: TestDateProvider;
|
|
36
43
|
} = {},
|
|
37
44
|
): Promise<{ anvil: Anvil; methodCalls?: string[]; rpcUrl: string; stop: () => Promise<void> }> {
|
|
38
45
|
const anvilBinary = resolve(dirname(fileURLToPath(import.meta.url)), '../../', 'scripts/anvil_kill_wrapper.sh');
|
|
@@ -108,12 +115,15 @@ export async function startAnvil(
|
|
|
108
115
|
child.once('close', onClose);
|
|
109
116
|
});
|
|
110
117
|
|
|
111
|
-
// Continue piping for logging
|
|
112
|
-
if (logger || opts.captureMethodCalls) {
|
|
118
|
+
// Continue piping for logging, method-call capture, and/or dateProvider sync after startup.
|
|
119
|
+
if (logger || opts.captureMethodCalls || opts.dateProvider) {
|
|
113
120
|
child.stdout?.on('data', (data: Buffer) => {
|
|
114
121
|
const text = data.toString();
|
|
115
122
|
logger?.debug(text.trim());
|
|
116
123
|
methodCalls?.push(...(text.match(/eth_[^\s]+/g) || []));
|
|
124
|
+
if (opts.dateProvider) {
|
|
125
|
+
syncDateProviderFromAnvilOutput(text, opts.dateProvider);
|
|
126
|
+
}
|
|
117
127
|
});
|
|
118
128
|
child.stderr?.on('data', (data: Buffer) => {
|
|
119
129
|
logger?.debug(data.toString().trim());
|
|
@@ -160,6 +170,19 @@ export async function startAnvil(
|
|
|
160
170
|
return { anvil: anvilObj, methodCalls, stop, rpcUrl: `http://127.0.0.1:${port}` };
|
|
161
171
|
}
|
|
162
172
|
|
|
173
|
+
/** Extracts block time from anvil stdout and syncs the dateProvider. */
|
|
174
|
+
function syncDateProviderFromAnvilOutput(text: string, dateProvider: TestDateProvider): void {
|
|
175
|
+
// Anvil logs mined blocks as:
|
|
176
|
+
// Block Time: "Fri, 20 Mar 2026 02:10:46 +0000"
|
|
177
|
+
const match = text.match(/Block Time:\s*"([^"]+)"/);
|
|
178
|
+
if (match) {
|
|
179
|
+
const blockTimeMs = new Date(match[1]).getTime();
|
|
180
|
+
if (!isNaN(blockTimeMs)) {
|
|
181
|
+
dateProvider.setTime(blockTimeMs);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
163
186
|
/** Send SIGTERM, wait up to 5 s, then SIGKILL. All timers are always cleared. */
|
|
164
187
|
function killChild(child: ChildProcess): Promise<void> {
|
|
165
188
|
return new Promise<void>(resolve => {
|