@aztec/ethereum 0.0.1-commit.24de95ac → 0.0.1-commit.2606882
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/account.d.ts +1 -1
- package/dest/chain.d.ts +1 -1
- package/dest/client.d.ts +25 -3
- package/dest/client.d.ts.map +1 -1
- package/dest/client.js +60 -4
- package/dest/config.d.ts +29 -73
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +70 -387
- package/dest/constants.d.ts +1 -1
- package/dest/contracts/chain_state_override.d.ts +78 -0
- package/dest/contracts/chain_state_override.d.ts.map +1 -0
- package/dest/contracts/chain_state_override.js +137 -0
- package/dest/contracts/empire_base.d.ts +7 -5
- package/dest/contracts/empire_base.d.ts.map +1 -1
- package/dest/contracts/empire_base.js +1 -1
- package/dest/contracts/errors.d.ts +1 -1
- package/dest/contracts/errors.d.ts.map +1 -1
- package/dest/contracts/fee_asset_handler.d.ts +6 -5
- package/dest/contracts/fee_asset_handler.d.ts.map +1 -1
- package/dest/contracts/fee_asset_handler.js +11 -9
- package/dest/contracts/fee_asset_price_oracle.d.ts +105 -0
- package/dest/contracts/fee_asset_price_oracle.d.ts.map +1 -0
- package/dest/contracts/fee_asset_price_oracle.js +656 -0
- package/dest/contracts/fee_juice.d.ts +1 -1
- package/dest/contracts/fee_juice.d.ts.map +1 -1
- package/dest/contracts/governance.d.ts +113 -36
- package/dest/contracts/governance.d.ts.map +1 -1
- package/dest/contracts/governance.js +207 -16
- package/dest/contracts/governance_proposer.d.ts +38 -4
- package/dest/contracts/governance_proposer.d.ts.map +1 -1
- package/dest/contracts/governance_proposer.js +455 -12
- package/dest/contracts/gse.d.ts +1 -1
- package/dest/contracts/gse.d.ts.map +1 -1
- package/dest/contracts/inbox.d.ts +24 -3
- package/dest/contracts/inbox.d.ts.map +1 -1
- package/dest/contracts/inbox.js +42 -2
- package/dest/contracts/index.d.ts +6 -3
- package/dest/contracts/index.d.ts.map +1 -1
- package/dest/contracts/index.js +5 -2
- package/dest/contracts/log.d.ts +13 -0
- package/dest/contracts/log.d.ts.map +1 -0
- package/dest/contracts/log.js +1 -0
- package/dest/contracts/multicall.d.ts +127 -12
- package/dest/contracts/multicall.d.ts.map +1 -1
- package/dest/contracts/multicall.js +201 -93
- package/dest/contracts/outbox.d.ts +64 -0
- package/dest/contracts/outbox.d.ts.map +1 -0
- package/dest/contracts/outbox.js +113 -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 +5432 -131
- package/dest/contracts/rollup.d.ts.map +1 -1
- package/dest/contracts/rollup.js +1114 -231
- package/dest/contracts/slasher_contract.d.ts +1 -1
- package/dest/contracts/slasher_contract.d.ts.map +1 -1
- package/dest/contracts/{tally_slashing_proposer.d.ts → slashing_proposer.d.ts} +11 -10
- package/dest/contracts/slashing_proposer.d.ts.map +1 -0
- package/dest/contracts/{tally_slashing_proposer.js → slashing_proposer.js} +21 -16
- package/dest/contracts/utils.d.ts +1 -1
- package/dest/deploy_aztec_l1_contracts.d.ts +256 -0
- package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -0
- package/dest/deploy_aztec_l1_contracts.js +411 -0
- package/dest/deploy_l1_contract.d.ts +68 -0
- package/dest/deploy_l1_contract.d.ts.map +1 -0
- package/dest/deploy_l1_contract.js +312 -0
- package/dest/eth-signer/eth-signer.d.ts +1 -1
- package/dest/eth-signer/index.d.ts +1 -1
- package/dest/forwarder_proxy.d.ts +32 -0
- package/dest/forwarder_proxy.d.ts.map +1 -0
- package/dest/forwarder_proxy.js +93 -0
- package/dest/generated/l1-contracts-defaults.d.ts +30 -0
- package/dest/generated/l1-contracts-defaults.d.ts.map +1 -0
- package/dest/generated/l1-contracts-defaults.js +30 -0
- package/dest/l1_artifacts.d.ts +19816 -16730
- package/dest/l1_artifacts.d.ts.map +1 -1
- package/dest/l1_artifacts.js +9 -24
- package/dest/l1_contract_addresses.d.ts +61 -65
- package/dest/l1_contract_addresses.d.ts.map +1 -1
- package/dest/l1_contract_addresses.js +99 -80
- package/dest/l1_reader.d.ts +7 -5
- package/dest/l1_reader.d.ts.map +1 -1
- package/dest/l1_reader.js +15 -7
- package/dest/l1_tx_utils/config.d.ts +11 -5
- package/dest/l1_tx_utils/config.d.ts.map +1 -1
- package/dest/l1_tx_utils/config.js +43 -7
- package/dest/l1_tx_utils/constants.d.ts +8 -2
- package/dest/l1_tx_utils/constants.d.ts.map +1 -1
- package/dest/l1_tx_utils/constants.js +27 -2
- package/dest/l1_tx_utils/factory.d.ts +18 -10
- package/dest/l1_tx_utils/factory.d.ts.map +1 -1
- package/dest/l1_tx_utils/factory.js +17 -7
- package/dest/l1_tx_utils/fee-strategies/index.d.ts +10 -0
- package/dest/l1_tx_utils/fee-strategies/index.d.ts.map +1 -0
- package/dest/l1_tx_utils/fee-strategies/index.js +12 -0
- package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts +8 -0
- package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts.map +1 -0
- package/dest/l1_tx_utils/fee-strategies/p75_competitive.js +129 -0
- package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts +23 -0
- package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts.map +1 -0
- package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.js +191 -0
- package/dest/l1_tx_utils/fee-strategies/types.d.ts +51 -0
- package/dest/l1_tx_utils/fee-strategies/types.d.ts.map +1 -0
- package/dest/l1_tx_utils/fee-strategies/types.js +3 -0
- package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts +41 -0
- package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts.map +1 -0
- package/dest/l1_tx_utils/forwarder_l1_tx_utils.js +42 -0
- package/dest/l1_tx_utils/index-blobs.d.ts +3 -0
- package/dest/l1_tx_utils/index-blobs.d.ts.map +1 -0
- package/dest/l1_tx_utils/index-blobs.js +2 -0
- package/dest/l1_tx_utils/index.d.ts +4 -1
- package/dest/l1_tx_utils/index.d.ts.map +1 -1
- package/dest/l1_tx_utils/index.js +3 -0
- package/dest/l1_tx_utils/interfaces.d.ts +2 -2
- package/dest/l1_tx_utils/interfaces.d.ts.map +1 -1
- package/dest/l1_tx_utils/l1_fee_analyzer.d.ts +233 -0
- package/dest/l1_tx_utils/l1_fee_analyzer.d.ts.map +1 -0
- package/dest/l1_tx_utils/l1_fee_analyzer.js +506 -0
- package/dest/l1_tx_utils/l1_tx_utils.d.ts +26 -8
- package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -1
- package/dest/l1_tx_utils/l1_tx_utils.js +118 -70
- package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts +19 -30
- package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -1
- package/dest/l1_tx_utils/readonly_l1_tx_utils.js +65 -168
- package/dest/l1_tx_utils/signer.d.ts +1 -1
- package/dest/l1_tx_utils/tx_delayer.d.ts +58 -0
- package/dest/l1_tx_utils/tx_delayer.d.ts.map +1 -0
- package/dest/{test → l1_tx_utils}/tx_delayer.js +70 -39
- package/dest/l1_tx_utils/types.d.ts +1 -1
- package/dest/l1_tx_utils/types.d.ts.map +1 -1
- package/dest/l1_tx_utils/utils.d.ts +1 -1
- package/dest/l1_types.d.ts +1 -1
- package/dest/publisher_manager.d.ts +21 -6
- package/dest/publisher_manager.d.ts.map +1 -1
- package/dest/publisher_manager.js +81 -7
- package/dest/queries.d.ts +14 -3
- package/dest/queries.d.ts.map +1 -1
- package/dest/queries.js +78 -9
- package/dest/test/chain_monitor.d.ts +48 -25
- package/dest/test/chain_monitor.d.ts.map +1 -1
- package/dest/test/chain_monitor.js +71 -38
- package/dest/test/eth_cheat_codes.d.ts +22 -6
- package/dest/test/eth_cheat_codes.d.ts.map +1 -1
- package/dest/test/eth_cheat_codes.js +28 -7
- package/dest/test/eth_cheat_codes_with_state.d.ts +1 -1
- package/dest/test/eth_cheat_codes_with_state.d.ts.map +1 -1
- package/dest/test/index.d.ts +1 -3
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/index.js +0 -2
- package/dest/test/rollup_cheat_codes.d.ts +46 -14
- package/dest/test/rollup_cheat_codes.d.ts.map +1 -1
- package/dest/test/rollup_cheat_codes.js +118 -42
- package/dest/test/start_anvil.d.ts +25 -2
- package/dest/test/start_anvil.d.ts.map +1 -1
- package/dest/test/start_anvil.js +143 -28
- package/dest/test/upgrade_utils.d.ts +1 -1
- package/dest/test/upgrade_utils.js +2 -2
- package/dest/types.d.ts +57 -2
- package/dest/types.d.ts.map +1 -1
- package/dest/utils.d.ts +24 -4
- package/dest/utils.d.ts.map +1 -1
- package/dest/utils.js +112 -16
- package/dest/zkPassportVerifierAddress.d.ts +1 -1
- package/package.json +35 -17
- package/src/client.ts +66 -2
- package/src/config.ts +91 -469
- package/src/contracts/README.md +157 -0
- package/src/contracts/chain_state_override.ts +200 -0
- package/src/contracts/empire_base.ts +6 -5
- package/src/contracts/fee_asset_handler.ts +10 -7
- package/src/contracts/fee_asset_price_oracle.ts +285 -0
- package/src/contracts/governance.ts +279 -13
- package/src/contracts/governance_proposer.ts +74 -7
- package/src/contracts/inbox.ts +64 -4
- package/src/contracts/index.ts +5 -2
- package/src/contracts/log.ts +13 -0
- package/src/contracts/multicall.ts +243 -102
- package/src/contracts/outbox.ts +132 -0
- package/src/contracts/registry.ts +31 -1
- package/src/contracts/rollup.ts +819 -192
- package/src/contracts/{tally_slashing_proposer.ts → slashing_proposer.ts} +26 -21
- package/src/deploy_aztec_l1_contracts.ts +646 -0
- package/src/deploy_l1_contract.ts +362 -0
- package/src/forwarder_proxy.ts +108 -0
- package/src/generated/l1-contracts-defaults.ts +32 -0
- package/src/l1_artifacts.ts +12 -35
- package/src/l1_contract_addresses.ts +120 -92
- package/src/l1_reader.ts +25 -10
- package/src/l1_tx_utils/config.ts +52 -11
- package/src/l1_tx_utils/constants.ts +13 -2
- package/src/l1_tx_utils/factory.ts +31 -31
- package/src/l1_tx_utils/fee-strategies/index.ts +22 -0
- package/src/l1_tx_utils/fee-strategies/p75_competitive.ts +163 -0
- package/src/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.ts +245 -0
- package/src/l1_tx_utils/fee-strategies/types.ts +56 -0
- package/src/l1_tx_utils/forwarder_l1_tx_utils.ts +108 -0
- package/src/l1_tx_utils/index-blobs.ts +2 -0
- package/src/l1_tx_utils/index.ts +3 -0
- package/src/l1_tx_utils/interfaces.ts +1 -1
- package/src/l1_tx_utils/l1_fee_analyzer.ts +803 -0
- package/src/l1_tx_utils/l1_tx_utils.ts +123 -52
- package/src/l1_tx_utils/readonly_l1_tx_utils.ts +79 -214
- package/src/{test → l1_tx_utils}/tx_delayer.ts +97 -58
- package/src/publisher_manager.ts +107 -10
- package/src/queries.ts +87 -10
- package/src/test/chain_monitor.ts +115 -51
- package/src/test/eth_cheat_codes.ts +25 -7
- package/src/test/index.ts +0 -2
- package/src/test/rollup_cheat_codes.ts +123 -45
- package/src/test/start_anvil.ts +179 -27
- package/src/test/upgrade_utils.ts +2 -2
- package/src/types.ts +62 -0
- package/src/utils.ts +128 -19
- package/dest/contracts/empire_slashing_proposer.d.ts +0 -65
- package/dest/contracts/empire_slashing_proposer.d.ts.map +0 -1
- package/dest/contracts/empire_slashing_proposer.js +0 -194
- package/dest/contracts/tally_slashing_proposer.d.ts.map +0 -1
- package/dest/deploy_l1_contracts.d.ts +0 -226
- package/dest/deploy_l1_contracts.d.ts.map +0 -1
- package/dest/deploy_l1_contracts.js +0 -1473
- package/dest/index.d.ts +0 -18
- package/dest/index.d.ts.map +0 -1
- package/dest/index.js +0 -17
- package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts +0 -26
- package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts.map +0 -1
- package/dest/l1_tx_utils/l1_tx_utils_with_blobs.js +0 -26
- package/dest/test/delayed_tx_utils.d.ts +0 -13
- package/dest/test/delayed_tx_utils.d.ts.map +0 -1
- package/dest/test/delayed_tx_utils.js +0 -28
- package/dest/test/tx_delayer.d.ts +0 -36
- package/dest/test/tx_delayer.d.ts.map +0 -1
- package/src/contracts/empire_slashing_proposer.ts +0 -259
- package/src/deploy_l1_contracts.ts +0 -1849
- package/src/index.ts +0 -17
- package/src/l1_tx_utils/l1_tx_utils_with_blobs.ts +0 -77
- package/src/test/delayed_tx_utils.ts +0 -52
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { omit } from '@aztec/foundation/collection';
|
|
2
|
-
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
2
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
3
3
|
import { retryUntil } from '@aztec/foundation/retry';
|
|
4
4
|
import type { DateProvider } from '@aztec/foundation/timer';
|
|
5
5
|
|
|
@@ -9,14 +9,18 @@ import {
|
|
|
9
9
|
type Hex,
|
|
10
10
|
type PublicClient,
|
|
11
11
|
type TransactionSerializableEIP4844,
|
|
12
|
+
type TransactionSerialized,
|
|
12
13
|
keccak256,
|
|
13
14
|
parseTransaction,
|
|
14
15
|
publicActions,
|
|
16
|
+
recoverTransactionAddress,
|
|
15
17
|
serializeTransaction,
|
|
16
18
|
walletActions,
|
|
17
19
|
} from 'viem';
|
|
18
20
|
|
|
19
|
-
import {
|
|
21
|
+
import type { ExtendedViemWalletClient, ViemClient } from '../types.js';
|
|
22
|
+
|
|
23
|
+
const MAX_WAIT_TIME_SECONDS = 180;
|
|
20
24
|
|
|
21
25
|
export function waitUntilBlock<T extends Client>(
|
|
22
26
|
client: T,
|
|
@@ -36,7 +40,7 @@ export function waitUntilBlock<T extends Client>(
|
|
|
36
40
|
return currentBlockNumber >= BigInt(blockNumber);
|
|
37
41
|
},
|
|
38
42
|
`Wait until L1 block ${blockNumber}`,
|
|
39
|
-
timeout ??
|
|
43
|
+
timeout ?? MAX_WAIT_TIME_SECONDS,
|
|
40
44
|
0.1,
|
|
41
45
|
);
|
|
42
46
|
}
|
|
@@ -66,87 +70,107 @@ export function waitUntilL1Timestamp<T extends Client>(
|
|
|
66
70
|
return currentTs >= BigInt(timestamp);
|
|
67
71
|
},
|
|
68
72
|
`Wait until L1 timestamp ${timestamp}`,
|
|
69
|
-
timeout ??
|
|
73
|
+
timeout ?? MAX_WAIT_TIME_SECONDS,
|
|
70
74
|
0.1,
|
|
71
75
|
);
|
|
72
76
|
}
|
|
73
77
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
* since the last L1 block was mined, then any tx will not be mined in the current
|
|
88
|
-
* L1 slot but will be deferred for the next one.
|
|
89
|
-
*/
|
|
90
|
-
setMaxInclusionTimeIntoSlot(seconds: number | bigint | undefined): void;
|
|
91
|
-
}
|
|
78
|
+
/** Manages tx delaying for testing, intercepting sendRawTransaction calls to delay or cancel them. */
|
|
79
|
+
export class Delayer {
|
|
80
|
+
private logger: Logger;
|
|
81
|
+
|
|
82
|
+
public maxInclusionTimeIntoSlot: number | undefined = undefined;
|
|
83
|
+
public ethereumSlotDuration: bigint;
|
|
84
|
+
public nextWait:
|
|
85
|
+
| { l1Timestamp: bigint; timeoutSeconds?: number }
|
|
86
|
+
| { l1BlockNumber: bigint; timeoutSeconds?: number }
|
|
87
|
+
| { indefinitely: true }
|
|
88
|
+
| undefined = undefined;
|
|
89
|
+
public sentTxHashes: Hex[] = [];
|
|
90
|
+
public cancelledTxs: Hex[] = [];
|
|
92
91
|
|
|
93
|
-
class DelayerImpl implements Delayer {
|
|
94
|
-
private logger = createLogger('ethereum:tx_delayer');
|
|
95
92
|
constructor(
|
|
96
93
|
public dateProvider: DateProvider,
|
|
97
94
|
opts: { ethereumSlotDuration: bigint | number },
|
|
95
|
+
bindings: LoggerBindings,
|
|
98
96
|
) {
|
|
99
97
|
this.ethereumSlotDuration = BigInt(opts.ethereumSlotDuration);
|
|
98
|
+
this.logger = createLogger('ethereum:tx_delayer', bindings);
|
|
100
99
|
}
|
|
101
100
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
public cancelledTxs: Hex[] = [];
|
|
101
|
+
/** Returns the logger instance used by this delayer. */
|
|
102
|
+
getLogger(): Logger {
|
|
103
|
+
return this.logger;
|
|
104
|
+
}
|
|
107
105
|
|
|
106
|
+
/** Returns the hashes of all effectively sent txs. */
|
|
108
107
|
getSentTxHashes() {
|
|
109
108
|
return this.sentTxHashes;
|
|
110
109
|
}
|
|
111
110
|
|
|
111
|
+
/** Returns the raw hex for all cancelled txs. */
|
|
112
112
|
getCancelledTxs(): Hex[] {
|
|
113
113
|
return this.cancelledTxs;
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
/** Delays the next tx to be sent so it lands on the given L1 block number. */
|
|
117
|
+
pauseNextTxUntilBlock(l1BlockNumber: number | bigint, timeoutSeconds?: number) {
|
|
118
|
+
this.nextWait = { l1BlockNumber: BigInt(l1BlockNumber), timeoutSeconds };
|
|
118
119
|
}
|
|
119
120
|
|
|
120
|
-
|
|
121
|
-
|
|
121
|
+
/** Delays the next tx to be sent so it lands on the given timestamp. */
|
|
122
|
+
pauseNextTxUntilTimestamp(l1Timestamp: number | bigint, timeoutSeconds?: number) {
|
|
123
|
+
this.nextWait = { l1Timestamp: BigInt(l1Timestamp), timeoutSeconds };
|
|
122
124
|
}
|
|
123
125
|
|
|
126
|
+
/** Delays the next tx to be sent indefinitely. */
|
|
124
127
|
cancelNextTx() {
|
|
125
128
|
this.nextWait = { indefinitely: true };
|
|
126
129
|
}
|
|
127
130
|
|
|
131
|
+
/**
|
|
132
|
+
* Sets max inclusion time into slot. If more than this many seconds have passed
|
|
133
|
+
* since the last L1 block was mined, then any tx will not be mined in the current
|
|
134
|
+
* L1 slot but will be deferred for the next one.
|
|
135
|
+
*/
|
|
128
136
|
setMaxInclusionTimeIntoSlot(seconds: number | undefined) {
|
|
129
137
|
this.maxInclusionTimeIntoSlot = seconds;
|
|
130
138
|
}
|
|
131
139
|
}
|
|
132
140
|
|
|
133
141
|
/**
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
* TODO(#10824): This doesn't play along well with blob txs for some reason.
|
|
142
|
+
* Creates a new Delayer instance. Exposed so callers can create a single shared delayer
|
|
143
|
+
* and pass it to multiple `wrapClientWithDelayer` calls.
|
|
137
144
|
*/
|
|
138
|
-
export function
|
|
139
|
-
client: T,
|
|
145
|
+
export function createDelayer(
|
|
140
146
|
dateProvider: DateProvider,
|
|
141
147
|
opts: { ethereumSlotDuration: bigint | number },
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
148
|
+
bindings: LoggerBindings,
|
|
149
|
+
): Delayer {
|
|
150
|
+
return new Delayer(dateProvider, opts, bindings);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** Tries to recover the sender address from a serialized signed transaction. */
|
|
154
|
+
async function tryRecoverSender(serializedTransaction: Hex): Promise<string | undefined> {
|
|
155
|
+
try {
|
|
156
|
+
return await recoverTransactionAddress({
|
|
157
|
+
serializedTransaction: serializedTransaction as TransactionSerialized,
|
|
158
|
+
});
|
|
159
|
+
} catch {
|
|
160
|
+
return undefined;
|
|
145
161
|
}
|
|
146
|
-
|
|
147
|
-
const delayer = new DelayerImpl(dateProvider, opts);
|
|
162
|
+
}
|
|
148
163
|
|
|
149
|
-
|
|
164
|
+
/**
|
|
165
|
+
* Wraps a viem client with tx delaying logic. Returns the wrapped client.
|
|
166
|
+
* The delayer intercepts sendRawTransaction calls and delays them based on the delayer's state.
|
|
167
|
+
*/
|
|
168
|
+
export function wrapClientWithDelayer<T extends ViemClient>(client: T, delayer: Delayer): T {
|
|
169
|
+
const logger = delayer.getLogger();
|
|
170
|
+
|
|
171
|
+
// Cast to ExtendedViemWalletClient for the extend chain since it has sendRawTransaction.
|
|
172
|
+
// The sendRawTransaction override is applied to all clients regardless of type.
|
|
173
|
+
const withRawTx = (client as unknown as ExtendedViemWalletClient)
|
|
150
174
|
// Tweak sendRawTransaction so it uses the delay defined in the delayer.
|
|
151
175
|
// Note that this will only work with local accounts (ie accounts for which we have the private key).
|
|
152
176
|
// Transactions signed by the node will not be delayed since they use sendTransaction directly,
|
|
@@ -158,6 +182,7 @@ export function withDelayer<T extends ViemClient>(
|
|
|
158
182
|
|
|
159
183
|
const { serializedTransaction } = args[0];
|
|
160
184
|
const publicClient = client as unknown as PublicClient;
|
|
185
|
+
const sender = await tryRecoverSender(serializedTransaction);
|
|
161
186
|
|
|
162
187
|
if (delayer.nextWait !== undefined) {
|
|
163
188
|
// Check if we have been instructed to delay the next tx.
|
|
@@ -169,7 +194,7 @@ export function withDelayer<T extends ViemClient>(
|
|
|
169
194
|
|
|
170
195
|
// Cancel tx outright if instructed
|
|
171
196
|
if ('indefinitely' in waitUntil && waitUntil.indefinitely) {
|
|
172
|
-
logger.info(`Cancelling tx ${txHash}
|
|
197
|
+
logger.info(`Cancelling tx ${txHash}`, { sender });
|
|
173
198
|
delayer.cancelledTxs.push(serializedTransaction);
|
|
174
199
|
return Promise.resolve(txHash);
|
|
175
200
|
}
|
|
@@ -177,12 +202,18 @@ export function withDelayer<T extends ViemClient>(
|
|
|
177
202
|
// Or wait until the desired block number or timestamp
|
|
178
203
|
wait =
|
|
179
204
|
'l1BlockNumber' in waitUntil
|
|
180
|
-
? waitUntilBlock(publicClient, waitUntil.l1BlockNumber - 1n, logger)
|
|
205
|
+
? waitUntilBlock(publicClient, waitUntil.l1BlockNumber - 1n, logger, waitUntil.timeoutSeconds)
|
|
181
206
|
: 'l1Timestamp' in waitUntil
|
|
182
|
-
? waitUntilL1Timestamp(
|
|
207
|
+
? waitUntilL1Timestamp(
|
|
208
|
+
publicClient,
|
|
209
|
+
waitUntil.l1Timestamp - delayer.ethereumSlotDuration,
|
|
210
|
+
logger,
|
|
211
|
+
waitUntil.timeoutSeconds,
|
|
212
|
+
)
|
|
183
213
|
: undefined;
|
|
184
214
|
|
|
185
215
|
logger.info(`Delaying tx ${txHash} until ${inspect(waitUntil)}`, {
|
|
216
|
+
sender,
|
|
186
217
|
argsLen: args.length,
|
|
187
218
|
...omit(parseTransaction(serializedTransaction), 'data', 'sidecars'),
|
|
188
219
|
});
|
|
@@ -194,6 +225,7 @@ export function withDelayer<T extends ViemClient>(
|
|
|
194
225
|
|
|
195
226
|
txHash = computeTxHash(serializedTransaction);
|
|
196
227
|
const logData = {
|
|
228
|
+
sender,
|
|
197
229
|
...omit(parseTransaction(serializedTransaction), 'data', 'sidecars'),
|
|
198
230
|
lastBlockTimestamp,
|
|
199
231
|
now,
|
|
@@ -223,28 +255,35 @@ export function withDelayer<T extends ViemClient>(
|
|
|
223
255
|
computedTxHash: txHash,
|
|
224
256
|
});
|
|
225
257
|
}
|
|
226
|
-
logger.info(`Sent previously delayed tx ${clientTxHash}
|
|
258
|
+
logger.info(`Sent previously delayed tx ${clientTxHash}`, { sender });
|
|
227
259
|
delayer.sentTxHashes.push(clientTxHash);
|
|
228
260
|
})
|
|
229
261
|
.catch(err => logger.error(`Error sending tx after delay`, err));
|
|
230
262
|
return Promise.resolve(txHash!);
|
|
231
263
|
} else {
|
|
232
264
|
const txHash = await client.sendRawTransaction(...args);
|
|
233
|
-
logger.
|
|
265
|
+
logger.debug(`Sent tx immediately ${txHash}`, { sender });
|
|
234
266
|
delayer.sentTxHashes.push(txHash);
|
|
235
267
|
return txHash;
|
|
236
268
|
}
|
|
237
269
|
},
|
|
238
|
-
}))
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
270
|
+
}));
|
|
271
|
+
|
|
272
|
+
// Only re-bind wallet actions (sendTransaction, writeContract, deployContract) for wallet clients.
|
|
273
|
+
// This is needed for tests that use wallet actions directly rather than sendRawTransaction.
|
|
274
|
+
const isWalletClient = 'account' in client && client.account !== undefined;
|
|
275
|
+
const extended = isWalletClient
|
|
276
|
+
? withRawTx
|
|
277
|
+
// Re-extend with sendTransaction so it uses the modified sendRawTransaction.
|
|
278
|
+
.extend(client => ({ sendTransaction: walletActions(client).sendTransaction }))
|
|
279
|
+
// And with the actions that depend on the modified sendTransaction
|
|
280
|
+
.extend(client => ({
|
|
281
|
+
writeContract: walletActions(client).writeContract,
|
|
282
|
+
deployContract: walletActions(client).deployContract,
|
|
283
|
+
}))
|
|
284
|
+
: withRawTx;
|
|
246
285
|
|
|
247
|
-
return
|
|
286
|
+
return extended as T;
|
|
248
287
|
}
|
|
249
288
|
|
|
250
289
|
/**
|
package/src/publisher_manager.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { pick } from '@aztec/foundation/collection';
|
|
2
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
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,22 +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
|
-
private log
|
|
32
|
-
private config:
|
|
40
|
+
private log: Logger;
|
|
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:
|
|
48
|
+
config: PublisherManagerConfig,
|
|
49
|
+
opts?: { bindings?: LoggerBindings; funder?: UtilsType },
|
|
37
50
|
) {
|
|
51
|
+
this.funder = opts?.funder;
|
|
52
|
+
this.log = createLogger('publisher:manager', opts?.bindings);
|
|
38
53
|
this.log.info(`PublisherManager initialized with ${publishers.length} publishers.`);
|
|
39
54
|
this.publishers = publishers;
|
|
40
|
-
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
|
+
}
|
|
41
70
|
}
|
|
42
71
|
|
|
43
|
-
/** Loads the state of all publishers and
|
|
44
|
-
public async
|
|
45
|
-
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();
|
|
46
98
|
}
|
|
47
99
|
|
|
48
100
|
// Finds and prioritises available publishers based on
|
|
@@ -100,7 +152,52 @@ export class PublisherManager<UtilsType extends L1TxUtils = L1TxUtils> {
|
|
|
100
152
|
return sortedPublishers[0].publisher;
|
|
101
153
|
}
|
|
102
154
|
|
|
103
|
-
|
|
104
|
-
|
|
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`);
|
|
105
202
|
}
|
|
106
203
|
}
|
package/src/queries.ts
CHANGED
|
@@ -1,10 +1,77 @@
|
|
|
1
1
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
2
|
|
|
3
|
-
import type
|
|
3
|
+
import { BaseError, type Block } from 'viem';
|
|
4
|
+
|
|
5
|
+
import { DefaultL1ContractsConfig, type L1ContractsConfig } from './config.js';
|
|
4
6
|
import { ReadOnlyGovernanceContract } from './contracts/governance.js';
|
|
5
7
|
import { GovernanceProposerContract } from './contracts/governance_proposer.js';
|
|
8
|
+
import { InboxContract } from './contracts/inbox.js';
|
|
6
9
|
import { RollupContract } from './contracts/rollup.js';
|
|
7
|
-
import type { ViemPublicClient } from './types.js';
|
|
10
|
+
import type { ViemClient, ViemPublicClient } from './types.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Returns the L1 finalized block, or `undefined` if the chain does not yet have one
|
|
14
|
+
* (common on freshly started devnets). Rethrows any other RPC error.
|
|
15
|
+
*/
|
|
16
|
+
export async function getFinalizedL1Block(client: ViemClient): Promise<Block<bigint, false, 'finalized'> | undefined> {
|
|
17
|
+
try {
|
|
18
|
+
return await client.getBlock({ blockTag: 'finalized', includeTransactions: false });
|
|
19
|
+
} catch (err) {
|
|
20
|
+
if (isFinalizedBlockTagNotFoundError(err)) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
throw err;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Error messages returned by popular Ethereum execution clients when
|
|
28
|
+
// eth_getBlockByNumber / eth_call is called with blockTag "finalized" or
|
|
29
|
+
// "safe" and no such block has been produced yet:
|
|
30
|
+
//
|
|
31
|
+
// geth "finalized block not found"
|
|
32
|
+
// "safe block not found"
|
|
33
|
+
// reth "block not found: finalized"
|
|
34
|
+
// "block not found: safe"
|
|
35
|
+
// nethermind "Unknown block error" (same for both tags)
|
|
36
|
+
// besu "Unknown block"
|
|
37
|
+
// erigon 'block "finalized" not available (head block: N)'
|
|
38
|
+
// 'block "safe" not available (head block: N)'
|
|
39
|
+
//
|
|
40
|
+
// A combined regex covers all five:
|
|
41
|
+
const FINALIZED_BLOCK_TAG_NOT_FOUND_MESSAGE_RE =
|
|
42
|
+
/(finalized|safe) block not found|block not found: (finalized|safe)|unknown block|block "(finalized|safe)" not available/i;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Returns true if the error originates from an RPC call that failed because
|
|
46
|
+
* the "finalized" (or "safe") block tag is not yet available on the chain.
|
|
47
|
+
*/
|
|
48
|
+
export function isFinalizedBlockTagNotFoundError(err: unknown): boolean {
|
|
49
|
+
if (!err) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (err instanceof BaseError) {
|
|
54
|
+
const hit = err.walk((e: any) => matchesFinalizedBlockTagNotFound(e));
|
|
55
|
+
if (hit) {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
for (let cur: any = err, i = 0; cur && i < 10; cur = cur.cause, i++) {
|
|
61
|
+
if (matchesFinalizedBlockTagNotFound(cur)) {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function matchesFinalizedBlockTagNotFound(e: any): boolean {
|
|
69
|
+
if (!e) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
const text = `${e.details ?? ''} ${e.message ?? ''} ${e.shortMessage ?? ''}`;
|
|
73
|
+
return FINALIZED_BLOCK_TAG_NOT_FOUND_MESSAGE_RE.test(text);
|
|
74
|
+
}
|
|
8
75
|
|
|
9
76
|
/** Reads the L1ContractsConfig from L1 contracts. */
|
|
10
77
|
export async function getL1ContractsConfig(
|
|
@@ -25,6 +92,8 @@ export async function getL1ContractsConfig(
|
|
|
25
92
|
const rollup = new RollupContract(publicClient, rollupAddress.toString());
|
|
26
93
|
const slasherProposer = await rollup.getSlashingProposer();
|
|
27
94
|
const slasher = await rollup.getSlasherContract();
|
|
95
|
+
const rollupAddresses = await rollup.getRollupAddresses();
|
|
96
|
+
const inboxContract = new InboxContract(publicClient, rollupAddresses.inboxAddress.toString());
|
|
28
97
|
|
|
29
98
|
const [
|
|
30
99
|
l1StartBlock,
|
|
@@ -33,7 +102,9 @@ export async function getL1ContractsConfig(
|
|
|
33
102
|
aztecSlotDuration,
|
|
34
103
|
aztecProofSubmissionEpochs,
|
|
35
104
|
aztecTargetCommitteeSize,
|
|
36
|
-
|
|
105
|
+
lagInEpochsForValidatorSet,
|
|
106
|
+
lagInEpochsForRandao,
|
|
107
|
+
inboxLag,
|
|
37
108
|
activationThreshold,
|
|
38
109
|
ejectionThreshold,
|
|
39
110
|
localEjectionThreshold,
|
|
@@ -59,7 +130,9 @@ export async function getL1ContractsConfig(
|
|
|
59
130
|
rollup.getSlotDuration(),
|
|
60
131
|
rollup.getProofSubmissionEpochs(),
|
|
61
132
|
rollup.getTargetCommitteeSize(),
|
|
62
|
-
rollup.
|
|
133
|
+
rollup.getLagInEpochsForValidatorSet(),
|
|
134
|
+
rollup.getLagInEpochsForRandao(),
|
|
135
|
+
inboxContract.getLag(),
|
|
63
136
|
rollup.getActivationThreshold(),
|
|
64
137
|
rollup.getEjectionThreshold(),
|
|
65
138
|
rollup.getLocalEjectionThreshold(),
|
|
@@ -69,8 +142,8 @@ export async function getL1ContractsConfig(
|
|
|
69
142
|
slasherProposer?.getRoundSize() ?? 0n,
|
|
70
143
|
slasherProposer?.getLifetimeInRounds() ?? 0n,
|
|
71
144
|
slasherProposer?.getExecutionDelayInRounds() ?? 0n,
|
|
72
|
-
slasherProposer?.
|
|
73
|
-
slasherProposer?.
|
|
145
|
+
slasherProposer?.getSlashOffsetInRounds() ?? 0n,
|
|
146
|
+
slasherProposer?.getSlashingAmounts() ?? [0n, 0n, 0n],
|
|
74
147
|
slasher?.getVetoer() ?? EthAddress.ZERO,
|
|
75
148
|
slasher?.getSlashingDisableDuration() ?? 0,
|
|
76
149
|
rollup.getManaTarget(),
|
|
@@ -87,14 +160,17 @@ export async function getL1ContractsConfig(
|
|
|
87
160
|
aztecSlotDuration: Number(aztecSlotDuration),
|
|
88
161
|
aztecProofSubmissionEpochs: Number(aztecProofSubmissionEpochs),
|
|
89
162
|
aztecTargetCommitteeSize: Number(aztecTargetCommitteeSize),
|
|
90
|
-
|
|
163
|
+
lagInEpochsForValidatorSet: Number(lagInEpochsForValidatorSet),
|
|
164
|
+
lagInEpochsForRandao: Number(lagInEpochsForRandao),
|
|
165
|
+
inboxLag: Number(inboxLag),
|
|
91
166
|
governanceProposerQuorum: Number(governanceProposerQuorum),
|
|
92
167
|
governanceProposerRoundSize: Number(governanceProposerRoundSize),
|
|
168
|
+
governanceVotingDuration: DefaultL1ContractsConfig.governanceVotingDuration,
|
|
93
169
|
activationThreshold,
|
|
94
170
|
ejectionThreshold,
|
|
95
171
|
localEjectionThreshold,
|
|
96
172
|
slashingQuorum: Number(slashingQuorum),
|
|
97
|
-
slashingRoundSizeInEpochs: Number(slashingRoundSize / aztecEpochDuration),
|
|
173
|
+
slashingRoundSizeInEpochs: Number(Number(slashingRoundSize) / aztecEpochDuration),
|
|
98
174
|
slashingLifetimeInRounds: Number(slashingLifetimeInRounds),
|
|
99
175
|
slashingExecutionDelayInRounds: Number(slashingExecutionDelayInRounds),
|
|
100
176
|
slashingVetoer,
|
|
@@ -102,12 +178,13 @@ export async function getL1ContractsConfig(
|
|
|
102
178
|
manaTarget,
|
|
103
179
|
provingCostPerMana: provingCostPerMana,
|
|
104
180
|
rollupVersion: Number(rollupVersion),
|
|
105
|
-
genesisArchiveTreeRoot,
|
|
181
|
+
genesisArchiveTreeRoot: genesisArchiveTreeRoot.toString(),
|
|
106
182
|
exitDelaySeconds: Number(exitDelay),
|
|
107
|
-
|
|
183
|
+
slasherEnabled: !!slasherProposer,
|
|
108
184
|
slashingOffsetInRounds: Number(slashingOffsetInRounds),
|
|
109
185
|
slashAmountSmall: slashingAmounts[0],
|
|
110
186
|
slashAmountMedium: slashingAmounts[1],
|
|
111
187
|
slashAmountLarge: slashingAmounts[2],
|
|
188
|
+
initialEthPerFeeAsset: DefaultL1ContractsConfig.initialEthPerFeeAsset,
|
|
112
189
|
};
|
|
113
190
|
}
|