@aztec/ethereum 3.0.0-devnet.2 → 3.0.0-devnet.20251212
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 +1 -1
- package/dest/config.d.ts +7 -4
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +55 -17
- package/dest/constants.d.ts +1 -1
- package/dest/contracts/empire_base.d.ts +6 -5
- package/dest/contracts/empire_base.d.ts.map +1 -1
- package/dest/contracts/empire_base.js +1 -1
- package/dest/contracts/empire_slashing_proposer.d.ts +5 -4
- package/dest/contracts/empire_slashing_proposer.d.ts.map +1 -1
- package/dest/contracts/empire_slashing_proposer.js +8 -2
- 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 +1 -1
- package/dest/contracts/fee_asset_handler.d.ts.map +1 -1
- 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 +16 -16
- package/dest/contracts/governance.d.ts.map +1 -1
- package/dest/contracts/governance_proposer.d.ts +5 -4
- package/dest/contracts/governance_proposer.d.ts.map +1 -1
- package/dest/contracts/governance_proposer.js +8 -2
- package/dest/contracts/gse.d.ts +1 -1
- package/dest/contracts/gse.d.ts.map +1 -1
- package/dest/contracts/inbox.d.ts +1 -1
- package/dest/contracts/inbox.d.ts.map +1 -1
- package/dest/contracts/index.d.ts +1 -1
- package/dest/contracts/multicall.d.ts +2 -2
- package/dest/contracts/multicall.d.ts.map +1 -1
- package/dest/contracts/registry.d.ts +1 -1
- package/dest/contracts/registry.d.ts.map +1 -1
- package/dest/contracts/rollup.d.ts +55 -64
- package/dest/contracts/rollup.d.ts.map +1 -1
- package/dest/contracts/rollup.js +76 -67
- 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 +9 -7
- package/dest/contracts/tally_slashing_proposer.d.ts.map +1 -1
- package/dest/contracts/tally_slashing_proposer.js +4 -4
- package/dest/contracts/utils.d.ts +1 -1
- package/dest/deploy_l1_contracts.d.ts +456 -9
- package/dest/deploy_l1_contracts.d.ts.map +1 -1
- package/dest/deploy_l1_contracts.js +68 -37
- 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/l1_artifacts.d.ts +6400 -872
- package/dest/l1_artifacts.d.ts.map +1 -1
- package/dest/l1_contract_addresses.d.ts +3 -3
- package/dest/l1_reader.d.ts +3 -1
- package/dest/l1_reader.d.ts.map +1 -1
- package/dest/l1_reader.js +6 -0
- package/dest/l1_tx_utils/config.d.ts +5 -5
- package/dest/l1_tx_utils/config.d.ts.map +1 -1
- package/dest/l1_tx_utils/config.js +32 -9
- package/dest/l1_tx_utils/constants.d.ts +1 -1
- package/dest/l1_tx_utils/factory.d.ts +1 -1
- 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 +48 -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 +1 -1
- 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_tx_utils.d.ts +1 -2
- package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -1
- package/dest/l1_tx_utils/l1_tx_utils.js +17 -4
- package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts +1 -1
- package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts.map +1 -1
- package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts +29 -16
- package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -1
- package/dest/l1_tx_utils/readonly_l1_tx_utils.js +171 -34
- package/dest/l1_tx_utils/signer.d.ts +1 -1
- 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 +1 -1
- package/dest/publisher_manager.d.ts.map +1 -1
- package/dest/queries.d.ts +1 -1
- package/dest/queries.d.ts.map +1 -1
- package/dest/queries.js +5 -3
- package/dest/test/chain_monitor.d.ts +27 -24
- package/dest/test/chain_monitor.d.ts.map +1 -1
- package/dest/test/chain_monitor.js +32 -34
- package/dest/test/delayed_tx_utils.d.ts +1 -1
- package/dest/test/delayed_tx_utils.d.ts.map +1 -1
- package/dest/test/eth_cheat_codes.d.ts +8 -12
- package/dest/test/eth_cheat_codes.d.ts.map +1 -1
- package/dest/test/eth_cheat_codes.js +9 -3
- 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 -1
- package/dest/test/rollup_cheat_codes.d.ts +14 -13
- package/dest/test/rollup_cheat_codes.d.ts.map +1 -1
- package/dest/test/rollup_cheat_codes.js +43 -38
- package/dest/test/start_anvil.d.ts +2 -1
- package/dest/test/start_anvil.d.ts.map +1 -1
- package/dest/test/start_anvil.js +2 -1
- package/dest/test/tx_delayer.d.ts +1 -1
- package/dest/test/tx_delayer.d.ts.map +1 -1
- package/dest/test/tx_delayer.js +3 -2
- package/dest/test/upgrade_utils.d.ts +1 -1
- package/dest/types.d.ts +57 -2
- package/dest/types.d.ts.map +1 -1
- package/dest/utils.d.ts +2 -2
- package/dest/utils.d.ts.map +1 -1
- package/dest/zkPassportVerifierAddress.d.ts +1 -1
- package/package.json +27 -13
- package/src/config.ts +62 -18
- package/src/contracts/empire_base.ts +6 -5
- package/src/contracts/empire_slashing_proposer.ts +11 -5
- package/src/contracts/governance_proposer.ts +11 -5
- package/src/contracts/rollup.ts +81 -80
- package/src/contracts/tally_slashing_proposer.ts +11 -8
- package/src/deploy_l1_contracts.ts +63 -32
- package/src/forwarder_proxy.ts +108 -0
- package/src/l1_reader.ts +8 -0
- package/src/l1_tx_utils/config.ts +34 -13
- package/src/l1_tx_utils/forwarder_l1_tx_utils.ts +119 -0
- package/src/l1_tx_utils/index-blobs.ts +2 -0
- package/src/l1_tx_utils/interfaces.ts +1 -1
- package/src/l1_tx_utils/l1_tx_utils.ts +24 -4
- package/src/l1_tx_utils/readonly_l1_tx_utils.ts +223 -38
- package/src/queries.ts +6 -3
- package/src/test/chain_monitor.ts +50 -48
- package/src/test/eth_cheat_codes.ts +8 -2
- package/src/test/rollup_cheat_codes.ts +44 -42
- package/src/test/start_anvil.ts +2 -0
- package/src/test/tx_delayer.ts +4 -2
- package/src/types.ts +62 -0
- package/src/utils.ts +1 -1
- package/dest/index.d.ts +0 -18
- package/dest/index.d.ts.map +0 -1
- package/dest/index.js +0 -17
- package/src/index.ts +0 -17
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getKeys, merge, pick, times } from '@aztec/foundation/collection';
|
|
1
|
+
import { getKeys, median, merge, pick, times } from '@aztec/foundation/collection';
|
|
2
2
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
3
3
|
import { makeBackoff, retry } from '@aztec/foundation/retry';
|
|
4
4
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
@@ -33,6 +33,8 @@ import {
|
|
|
33
33
|
import type { GasPrice, L1BlobInputs, L1TxRequest, TransactionStats } from './types.js';
|
|
34
34
|
import { getCalldataGasUsage, tryGetCustomErrorNameContractFunction } from './utils.js';
|
|
35
35
|
|
|
36
|
+
const HISTORICAL_BLOCK_COUNT = 5;
|
|
37
|
+
|
|
36
38
|
export class ReadOnlyL1TxUtils {
|
|
37
39
|
public config: Required<L1TxUtilsConfig>;
|
|
38
40
|
protected interrupted = false;
|
|
@@ -63,6 +65,124 @@ export class ReadOnlyL1TxUtils {
|
|
|
63
65
|
return this.client.getBlockNumber();
|
|
64
66
|
}
|
|
65
67
|
|
|
68
|
+
/**
|
|
69
|
+
* Analyzes pending transactions and recent fee history to determine a competitive priority fee.
|
|
70
|
+
* Falls back to network estimate if data is unavailable or fails.
|
|
71
|
+
* @param networkEstimateResult - Result from estimateMaxPriorityFeePerGas RPC call
|
|
72
|
+
* @param pendingBlockResult - Result from getBlock with pending tag RPC call
|
|
73
|
+
* @param feeHistoryResult - Result from getFeeHistory RPC call
|
|
74
|
+
* @returns A competitive priority fee based on pending txs and recent block history
|
|
75
|
+
*/
|
|
76
|
+
protected getCompetitivePriorityFee(
|
|
77
|
+
networkEstimateResult: PromiseSettledResult<bigint | null>,
|
|
78
|
+
pendingBlockResult: PromiseSettledResult<Awaited<ReturnType<ViemClient['getBlock']>> | null>,
|
|
79
|
+
feeHistoryResult: PromiseSettledResult<Awaited<ReturnType<ViemClient['getFeeHistory']>> | null>,
|
|
80
|
+
): bigint {
|
|
81
|
+
const networkEstimate =
|
|
82
|
+
networkEstimateResult.status === 'fulfilled' && typeof networkEstimateResult.value === 'bigint'
|
|
83
|
+
? networkEstimateResult.value
|
|
84
|
+
: 0n;
|
|
85
|
+
let competitiveFee = networkEstimate;
|
|
86
|
+
|
|
87
|
+
if (
|
|
88
|
+
pendingBlockResult.status === 'fulfilled' &&
|
|
89
|
+
pendingBlockResult.value !== null &&
|
|
90
|
+
pendingBlockResult.value.transactions &&
|
|
91
|
+
pendingBlockResult.value.transactions.length > 0
|
|
92
|
+
) {
|
|
93
|
+
const pendingBlock = pendingBlockResult.value;
|
|
94
|
+
// Extract priority fees from pending transactions
|
|
95
|
+
const pendingFees = pendingBlock.transactions
|
|
96
|
+
.map(tx => {
|
|
97
|
+
// Transaction can be just a hash string, so we need to check if it's an object
|
|
98
|
+
if (typeof tx === 'string') {
|
|
99
|
+
return 0n;
|
|
100
|
+
}
|
|
101
|
+
const fee = tx.maxPriorityFeePerGas || 0n;
|
|
102
|
+
// Debug: Log suspicious fees
|
|
103
|
+
if (fee > 100n * WEI_CONST) {
|
|
104
|
+
this.logger?.warn('Suspicious high priority fee in pending tx', {
|
|
105
|
+
txHash: tx.hash,
|
|
106
|
+
maxPriorityFeePerGas: formatGwei(fee),
|
|
107
|
+
maxFeePerGas: formatGwei(tx.maxFeePerGas || 0n),
|
|
108
|
+
maxFeePerBlobGas: tx.maxFeePerBlobGas ? formatGwei(tx.maxFeePerBlobGas) : 'N/A',
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
return fee;
|
|
112
|
+
})
|
|
113
|
+
.filter((fee: bigint) => fee > 0n);
|
|
114
|
+
|
|
115
|
+
if (pendingFees.length > 0) {
|
|
116
|
+
// Use 75th percentile of pending fees to be competitive
|
|
117
|
+
const sortedPendingFees = [...pendingFees].sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
|
|
118
|
+
const percentile75Index = Math.floor((sortedPendingFees.length - 1) * 0.75);
|
|
119
|
+
const pendingCompetitiveFee = sortedPendingFees[percentile75Index];
|
|
120
|
+
|
|
121
|
+
if (pendingCompetitiveFee > competitiveFee) {
|
|
122
|
+
competitiveFee = pendingCompetitiveFee;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
this.logger?.debug('Analyzed pending transactions for competitive pricing', {
|
|
126
|
+
pendingTxCount: pendingFees.length,
|
|
127
|
+
pendingP75: formatGwei(pendingCompetitiveFee),
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (
|
|
132
|
+
feeHistoryResult.status === 'fulfilled' &&
|
|
133
|
+
feeHistoryResult.value !== null &&
|
|
134
|
+
feeHistoryResult.value.reward &&
|
|
135
|
+
feeHistoryResult.value.reward.length > 0
|
|
136
|
+
) {
|
|
137
|
+
const feeHistory = feeHistoryResult.value;
|
|
138
|
+
// Extract 75th percentile fees from each block
|
|
139
|
+
const percentile75Fees = feeHistory.reward!.map(rewards => rewards[0] || 0n).filter(fee => fee > 0n);
|
|
140
|
+
|
|
141
|
+
if (percentile75Fees.length > 0) {
|
|
142
|
+
// Calculate median of the 75th percentile fees across blocks
|
|
143
|
+
const medianHistoricalFee = median(percentile75Fees) ?? 0n;
|
|
144
|
+
|
|
145
|
+
// Debug: Log suspicious fees from history
|
|
146
|
+
if (medianHistoricalFee > 100n * WEI_CONST) {
|
|
147
|
+
this.logger?.warn('Suspicious high fee in history', {
|
|
148
|
+
historicalMedian: formatGwei(medianHistoricalFee),
|
|
149
|
+
allP75Fees: percentile75Fees.map(f => formatGwei(f)),
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (medianHistoricalFee > competitiveFee) {
|
|
154
|
+
competitiveFee = medianHistoricalFee;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
this.logger?.debug('Analyzed fee history for competitive pricing', {
|
|
158
|
+
historicalMedian: formatGwei(medianHistoricalFee),
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Sanity check: cap competitive fee at 100x network estimate to avoid using unrealistic fees
|
|
164
|
+
// (e.g., Anvil returns inflated historical fees that don't reflect actual network conditions)
|
|
165
|
+
const maxReasonableFee = networkEstimate * 100n;
|
|
166
|
+
if (competitiveFee > maxReasonableFee) {
|
|
167
|
+
this.logger?.warn('Competitive fee exceeds sanity cap, using capped value', {
|
|
168
|
+
competitiveFee: formatGwei(competitiveFee),
|
|
169
|
+
networkEstimate: formatGwei(networkEstimate),
|
|
170
|
+
cappedTo: formatGwei(maxReasonableFee),
|
|
171
|
+
});
|
|
172
|
+
competitiveFee = maxReasonableFee;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Log final decision
|
|
176
|
+
if (competitiveFee > networkEstimate) {
|
|
177
|
+
this.logger?.debug('Using competitive fee from market analysis', {
|
|
178
|
+
networkEstimate: formatGwei(networkEstimate),
|
|
179
|
+
competitive: formatGwei(competitiveFee),
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return competitiveFee;
|
|
184
|
+
}
|
|
185
|
+
|
|
66
186
|
/**
|
|
67
187
|
* Gets the current gas price with bounds checking
|
|
68
188
|
*/
|
|
@@ -73,35 +193,71 @@ export class ReadOnlyL1TxUtils {
|
|
|
73
193
|
previousGasPrice?: typeof attempt extends 0 ? never : GasPrice,
|
|
74
194
|
): Promise<GasPrice> {
|
|
75
195
|
const gasConfig = merge(this.config, gasConfigOverrides);
|
|
76
|
-
|
|
77
|
-
|
|
196
|
+
|
|
197
|
+
// Make all RPC calls in parallel upfront with retry logic
|
|
198
|
+
const latestBlockPromise = this.tryTwice(
|
|
199
|
+
() => this.client.getBlock({ blockTag: 'latest' }),
|
|
200
|
+
'Getting latest block',
|
|
201
|
+
);
|
|
202
|
+
const networkEstimatePromise = this.tryTwice(
|
|
203
|
+
() => this.client.estimateMaxPriorityFeePerGas(),
|
|
204
|
+
'Estimating max priority fee per gas',
|
|
205
|
+
);
|
|
206
|
+
const pendingBlockPromise = this.tryTwice(
|
|
207
|
+
() => this.client.getBlock({ blockTag: 'pending', includeTransactions: true }),
|
|
208
|
+
'Getting pending block',
|
|
209
|
+
);
|
|
210
|
+
const feeHistoryPromise = this.tryTwice(
|
|
211
|
+
() => this.client.getFeeHistory({ blockCount: HISTORICAL_BLOCK_COUNT, rewardPercentiles: [75] }),
|
|
212
|
+
'Getting fee history',
|
|
213
|
+
);
|
|
214
|
+
const blobBaseFeePromise = isBlobTx
|
|
215
|
+
? this.tryTwice(() => this.client.getBlobBaseFee(), 'Getting blob base fee')
|
|
216
|
+
: null;
|
|
217
|
+
|
|
218
|
+
const [latestBlockResult, networkEstimateResult, pendingBlockResult, feeHistoryResult, blobBaseFeeResult] =
|
|
219
|
+
await Promise.allSettled([
|
|
220
|
+
latestBlockPromise,
|
|
221
|
+
networkEstimatePromise,
|
|
222
|
+
pendingBlockPromise,
|
|
223
|
+
feeHistoryPromise,
|
|
224
|
+
blobBaseFeePromise ?? Promise.resolve(0n),
|
|
225
|
+
]);
|
|
226
|
+
|
|
227
|
+
// Extract results
|
|
228
|
+
const baseFee =
|
|
229
|
+
latestBlockResult.status === 'fulfilled' &&
|
|
230
|
+
typeof latestBlockResult.value === 'object' &&
|
|
231
|
+
latestBlockResult.value.baseFeePerGas
|
|
232
|
+
? latestBlockResult.value.baseFeePerGas
|
|
233
|
+
: 0n;
|
|
78
234
|
|
|
79
235
|
// Get blob base fee if available
|
|
80
236
|
let blobBaseFee = 0n;
|
|
81
|
-
if (isBlobTx) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
'Getting L1 blob base fee',
|
|
86
|
-
makeBackoff(times(2, () => 1)),
|
|
87
|
-
this.logger,
|
|
88
|
-
true,
|
|
89
|
-
);
|
|
90
|
-
} catch {
|
|
91
|
-
this.logger?.warn('Failed to get L1 blob base fee', attempt);
|
|
92
|
-
}
|
|
237
|
+
if (isBlobTx && blobBaseFeeResult.status === 'fulfilled' && typeof blobBaseFeeResult.value === 'bigint') {
|
|
238
|
+
blobBaseFee = blobBaseFeeResult.value;
|
|
239
|
+
} else if (isBlobTx) {
|
|
240
|
+
this.logger?.warn('Failed to get L1 blob base fee', attempt);
|
|
93
241
|
}
|
|
94
242
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
243
|
+
// Get competitive priority fee
|
|
244
|
+
let priorityFee = this.getCompetitivePriorityFee(networkEstimateResult, pendingBlockResult, feeHistoryResult);
|
|
245
|
+
|
|
246
|
+
// Apply minimum priority fee as a floor if configured
|
|
247
|
+
if (gasConfig.minimumPriorityFeePerGas) {
|
|
248
|
+
const minimumFee = BigInt(Math.trunc(gasConfig.minimumPriorityFeePerGas * Number(WEI_CONST)));
|
|
249
|
+
if (minimumFee > priorityFee) {
|
|
250
|
+
this.logger?.debug('Using minimum priority fee as floor', {
|
|
251
|
+
minimumPriorityFeePerGas: formatGwei(minimumFee),
|
|
252
|
+
competitiveFee: formatGwei(priorityFee),
|
|
253
|
+
});
|
|
254
|
+
priorityFee = minimumFee;
|
|
255
|
+
} else {
|
|
256
|
+
this.logger?.debug('Competitive fee exceeds minimum, using competitive fee', {
|
|
257
|
+
minimumPriorityFeePerGas: formatGwei(minimumFee),
|
|
258
|
+
competitiveFee: formatGwei(priorityFee),
|
|
259
|
+
});
|
|
260
|
+
}
|
|
105
261
|
}
|
|
106
262
|
let maxFeePerGas = baseFee;
|
|
107
263
|
|
|
@@ -115,6 +271,7 @@ export class ReadOnlyL1TxUtils {
|
|
|
115
271
|
// same for blob gas fee
|
|
116
272
|
maxFeePerBlobGas = (maxFeePerBlobGas * (1_000n + 125n)) / 1_000n;
|
|
117
273
|
}
|
|
274
|
+
|
|
118
275
|
if (attempt > 0) {
|
|
119
276
|
const configBump =
|
|
120
277
|
gasConfig.priorityFeeRetryBumpPercentage ?? defaultL1TxUtilsConfig.priorityFeeRetryBumpPercentage!;
|
|
@@ -129,29 +286,50 @@ export class ReadOnlyL1TxUtils {
|
|
|
129
286
|
(previousGasPrice!.maxPriorityFeePerGas * (100_00n + BigInt(bumpPercentage * 1_00))) / 100_00n;
|
|
130
287
|
const minMaxFee = (previousGasPrice!.maxFeePerGas * (100_00n + BigInt(bumpPercentage * 1_00))) / 100_00n;
|
|
131
288
|
|
|
132
|
-
//
|
|
133
|
-
|
|
289
|
+
// Apply bump percentage to competitive fee
|
|
290
|
+
const competitivePriorityFee = (priorityFee * (100_00n + BigInt(configBump * 1_00))) / 100_00n;
|
|
134
291
|
|
|
135
|
-
|
|
136
|
-
|
|
292
|
+
this.logger?.debug(`Speed-up attempt ${attempt}: using competitive fee strategy`, {
|
|
293
|
+
networkEstimate: formatGwei(priorityFee),
|
|
294
|
+
competitiveFee: formatGwei(competitivePriorityFee),
|
|
295
|
+
minRequired: formatGwei(minPriorityFee),
|
|
296
|
+
bumpPercentage: configBump,
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
// Use maximum between competitive fee and minimum required bump
|
|
300
|
+
const finalPriorityFee = competitivePriorityFee > minPriorityFee ? competitivePriorityFee : minPriorityFee;
|
|
301
|
+
const feeSource = finalPriorityFee === competitivePriorityFee ? 'competitive' : 'minimum-bump';
|
|
302
|
+
|
|
303
|
+
priorityFee = finalPriorityFee;
|
|
304
|
+
// Add the final priority fee to maxFeePerGas
|
|
305
|
+
maxFeePerGas += finalPriorityFee;
|
|
137
306
|
maxFeePerGas = maxFeePerGas > minMaxFee ? maxFeePerGas : minMaxFee;
|
|
307
|
+
|
|
308
|
+
this.logger?.debug(`Speed-up fee decision: using ${feeSource} fee`, {
|
|
309
|
+
finalPriorityFee: formatGwei(finalPriorityFee),
|
|
310
|
+
});
|
|
138
311
|
} else {
|
|
139
|
-
//
|
|
312
|
+
// First attempt: apply configured bump percentage to competitive fee
|
|
140
313
|
// multiply by 100 & divide by 100 to maintain some precision
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
314
|
+
priorityFee = (priorityFee * (100_00n + BigInt((gasConfig.priorityFeeBumpPercentage || 0) * 1_00))) / 100_00n;
|
|
315
|
+
this.logger?.debug('Initial transaction: using competitive fee from market analysis', {
|
|
316
|
+
networkEstimate: formatGwei(priorityFee),
|
|
317
|
+
});
|
|
144
318
|
maxFeePerGas += priorityFee;
|
|
145
319
|
}
|
|
146
320
|
|
|
321
|
+
// maxGwei and maxBlobGwei are hard limits
|
|
322
|
+
const effectiveMaxGwei = BigInt(Math.trunc(gasConfig.maxGwei! * Number(WEI_CONST)));
|
|
323
|
+
const effectiveMaxBlobGwei = BigInt(Math.trunc(gasConfig.maxBlobGwei! * Number(WEI_CONST)));
|
|
324
|
+
|
|
147
325
|
// Ensure we don't exceed maxGwei
|
|
148
|
-
|
|
149
|
-
|
|
326
|
+
if (effectiveMaxGwei > 0n) {
|
|
327
|
+
maxFeePerGas = maxFeePerGas > effectiveMaxGwei ? effectiveMaxGwei : maxFeePerGas;
|
|
328
|
+
}
|
|
150
329
|
|
|
151
330
|
// Ensure we don't exceed maxBlobGwei
|
|
152
|
-
if (maxFeePerBlobGas) {
|
|
153
|
-
|
|
154
|
-
maxFeePerBlobGas = maxFeePerBlobGas > maxBlobGweiInWei ? maxBlobGweiInWei : maxFeePerBlobGas;
|
|
331
|
+
if (maxFeePerBlobGas && effectiveMaxBlobGwei > 0n) {
|
|
332
|
+
maxFeePerBlobGas = maxFeePerBlobGas > effectiveMaxBlobGwei ? effectiveMaxBlobGwei : maxFeePerBlobGas;
|
|
155
333
|
}
|
|
156
334
|
|
|
157
335
|
// Ensure priority fee doesn't exceed max fee
|
|
@@ -369,4 +547,11 @@ export class ReadOnlyL1TxUtils {
|
|
|
369
547
|
});
|
|
370
548
|
return bumpedGasLimit;
|
|
371
549
|
}
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
* Helper function to retry RPC calls twice
|
|
553
|
+
*/
|
|
554
|
+
private tryTwice<T>(fn: () => Promise<T>, description: string): Promise<T> {
|
|
555
|
+
return retry<T>(fn, description, makeBackoff(times(2, () => 0)), this.logger, true);
|
|
556
|
+
}
|
|
372
557
|
}
|
package/src/queries.ts
CHANGED
|
@@ -33,7 +33,8 @@ export async function getL1ContractsConfig(
|
|
|
33
33
|
aztecSlotDuration,
|
|
34
34
|
aztecProofSubmissionEpochs,
|
|
35
35
|
aztecTargetCommitteeSize,
|
|
36
|
-
|
|
36
|
+
lagInEpochsForValidatorSet,
|
|
37
|
+
lagInEpochsForRandao,
|
|
37
38
|
activationThreshold,
|
|
38
39
|
ejectionThreshold,
|
|
39
40
|
localEjectionThreshold,
|
|
@@ -59,7 +60,8 @@ export async function getL1ContractsConfig(
|
|
|
59
60
|
rollup.getSlotDuration(),
|
|
60
61
|
rollup.getProofSubmissionEpochs(),
|
|
61
62
|
rollup.getTargetCommitteeSize(),
|
|
62
|
-
rollup.
|
|
63
|
+
rollup.getLagInEpochsForValidatorSet(),
|
|
64
|
+
rollup.getLagInEpochsForRandao(),
|
|
63
65
|
rollup.getActivationThreshold(),
|
|
64
66
|
rollup.getEjectionThreshold(),
|
|
65
67
|
rollup.getLocalEjectionThreshold(),
|
|
@@ -87,7 +89,8 @@ export async function getL1ContractsConfig(
|
|
|
87
89
|
aztecSlotDuration: Number(aztecSlotDuration),
|
|
88
90
|
aztecProofSubmissionEpochs: Number(aztecProofSubmissionEpochs),
|
|
89
91
|
aztecTargetCommitteeSize: Number(aztecTargetCommitteeSize),
|
|
90
|
-
|
|
92
|
+
lagInEpochsForValidatorSet: Number(lagInEpochsForValidatorSet),
|
|
93
|
+
lagInEpochsForRandao: Number(lagInEpochsForRandao),
|
|
91
94
|
governanceProposerQuorum: Number(governanceProposerQuorum),
|
|
92
95
|
governanceProposerRoundSize: Number(governanceProposerRoundSize),
|
|
93
96
|
activationThreshold,
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { RollupContract } from '@aztec/ethereum/contracts';
|
|
2
|
+
import { InboxContract } from '@aztec/ethereum/contracts';
|
|
3
|
+
import { CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
4
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
5
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
6
|
import { promiseWithResolvers } from '@aztec/foundation/promise';
|
|
@@ -10,11 +12,13 @@ import type { ViemClient } from '../types.js';
|
|
|
10
12
|
|
|
11
13
|
export type ChainMonitorEventMap = {
|
|
12
14
|
'l1-block': [{ l1BlockNumber: number; timestamp: bigint }];
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
checkpoint: [
|
|
16
|
+
{ checkpointNumber: CheckpointNumber; l1BlockNumber: number; l2SlotNumber: SlotNumber; timestamp: bigint },
|
|
17
|
+
];
|
|
18
|
+
'checkpoint-proven': [{ provenCheckpointNumber: CheckpointNumber; l1BlockNumber: number; timestamp: bigint }];
|
|
15
19
|
'l2-messages': [{ totalL2Messages: number; l1BlockNumber: number }];
|
|
16
|
-
'l2-epoch': [{ l2EpochNumber:
|
|
17
|
-
'l2-slot': [{ l2SlotNumber:
|
|
20
|
+
'l2-epoch': [{ l2EpochNumber: EpochNumber; timestamp: bigint; committee: EthAddress[] | undefined }];
|
|
21
|
+
'l2-slot': [{ l2SlotNumber: SlotNumber; timestamp: bigint }];
|
|
18
22
|
};
|
|
19
23
|
|
|
20
24
|
/** Utility class that polls the chain on quick intervals and logs new L1 blocks, L2 blocks, and L2 proofs. */
|
|
@@ -27,20 +31,20 @@ export class ChainMonitor extends EventEmitter<ChainMonitorEventMap> {
|
|
|
27
31
|
|
|
28
32
|
/** Current L1 block number */
|
|
29
33
|
public l1BlockNumber!: number;
|
|
30
|
-
/** Current
|
|
31
|
-
public
|
|
32
|
-
/** Current
|
|
33
|
-
public
|
|
34
|
-
/** L1 timestamp for the current
|
|
35
|
-
public
|
|
36
|
-
/** L1 timestamp for the proven
|
|
37
|
-
public
|
|
34
|
+
/** Current checkpoint number */
|
|
35
|
+
public checkpointNumber!: CheckpointNumber;
|
|
36
|
+
/** Current proven checkpoint number */
|
|
37
|
+
public provenCheckpointNumber!: CheckpointNumber;
|
|
38
|
+
/** L1 timestamp for the current checkpoint */
|
|
39
|
+
public checkpointTimestamp!: bigint;
|
|
40
|
+
/** L1 timestamp for the proven checkpoint */
|
|
41
|
+
public provenCheckpointTimestamp!: bigint;
|
|
38
42
|
/** Total number of L2 messages pushed into the Inbox */
|
|
39
43
|
public totalL2Messages: number = 0;
|
|
40
44
|
/** Current L2 epoch number */
|
|
41
|
-
public l2EpochNumber!:
|
|
45
|
+
public l2EpochNumber!: EpochNumber;
|
|
42
46
|
/** Current L2 slot number */
|
|
43
|
-
public l2SlotNumber!:
|
|
47
|
+
public l2SlotNumber!: SlotNumber;
|
|
44
48
|
|
|
45
49
|
constructor(
|
|
46
50
|
private readonly rollup: RollupContract,
|
|
@@ -114,28 +118,28 @@ export class ChainMonitor extends EventEmitter<ChainMonitorEventMap> {
|
|
|
114
118
|
this.emit('l1-block', { l1BlockNumber: newL1BlockNumber, timestamp });
|
|
115
119
|
let msg = `L1 block ${newL1BlockNumber} mined at ${timestampString}`;
|
|
116
120
|
|
|
117
|
-
const
|
|
118
|
-
if (this.
|
|
119
|
-
const epochNumber = await this.rollup.
|
|
120
|
-
msg += ` with new
|
|
121
|
-
this.
|
|
122
|
-
this.
|
|
123
|
-
this.emit('
|
|
124
|
-
|
|
121
|
+
const newCheckpointNumber = await this.rollup.getCheckpointNumber();
|
|
122
|
+
if (this.checkpointNumber !== newCheckpointNumber) {
|
|
123
|
+
const epochNumber = await this.rollup.getEpochNumberForCheckpoint(newCheckpointNumber);
|
|
124
|
+
msg += ` with new checkpoint ${newCheckpointNumber} for epoch ${epochNumber}`;
|
|
125
|
+
this.checkpointNumber = newCheckpointNumber;
|
|
126
|
+
this.checkpointTimestamp = timestamp;
|
|
127
|
+
this.emit('checkpoint', {
|
|
128
|
+
checkpointNumber: newCheckpointNumber,
|
|
125
129
|
l1BlockNumber: newL1BlockNumber,
|
|
126
|
-
l2SlotNumber
|
|
130
|
+
l2SlotNumber,
|
|
127
131
|
timestamp,
|
|
128
132
|
});
|
|
129
133
|
}
|
|
130
134
|
|
|
131
|
-
const
|
|
132
|
-
if (this.
|
|
133
|
-
const epochNumber = await this.rollup.
|
|
134
|
-
msg += ` with proof up to
|
|
135
|
-
this.
|
|
136
|
-
this.
|
|
137
|
-
this.emit('
|
|
138
|
-
|
|
135
|
+
const newProvenCheckpointNumber = await this.rollup.getProvenCheckpointNumber();
|
|
136
|
+
if (this.provenCheckpointNumber !== newProvenCheckpointNumber) {
|
|
137
|
+
const epochNumber = await this.rollup.getEpochNumberForCheckpoint(newProvenCheckpointNumber);
|
|
138
|
+
msg += ` with proof up to checkpoint ${newProvenCheckpointNumber} for epoch ${epochNumber}`;
|
|
139
|
+
this.provenCheckpointNumber = newProvenCheckpointNumber;
|
|
140
|
+
this.provenCheckpointTimestamp = timestamp;
|
|
141
|
+
this.emit('checkpoint-proven', {
|
|
142
|
+
provenCheckpointNumber: newProvenCheckpointNumber,
|
|
139
143
|
l1BlockNumber: newL1BlockNumber,
|
|
140
144
|
timestamp,
|
|
141
145
|
});
|
|
@@ -153,13 +157,13 @@ export class ChainMonitor extends EventEmitter<ChainMonitorEventMap> {
|
|
|
153
157
|
if (l2Epoch !== this.l2EpochNumber) {
|
|
154
158
|
this.l2EpochNumber = l2Epoch;
|
|
155
159
|
committee = (await this.rollup.getCurrentEpochCommittee())?.map(addr => EthAddress.fromString(addr));
|
|
156
|
-
this.emit('l2-epoch', { l2EpochNumber:
|
|
160
|
+
this.emit('l2-epoch', { l2EpochNumber: l2Epoch, timestamp, committee });
|
|
157
161
|
msg += ` starting new epoch ${this.l2EpochNumber} `;
|
|
158
162
|
}
|
|
159
163
|
|
|
160
164
|
if (l2SlotNumber !== this.l2SlotNumber) {
|
|
161
165
|
this.l2SlotNumber = l2SlotNumber;
|
|
162
|
-
this.emit('l2-slot', { l2SlotNumber
|
|
166
|
+
this.emit('l2-slot', { l2SlotNumber, timestamp });
|
|
163
167
|
}
|
|
164
168
|
|
|
165
169
|
this.logger.info(msg, {
|
|
@@ -168,8 +172,8 @@ export class ChainMonitor extends EventEmitter<ChainMonitorEventMap> {
|
|
|
168
172
|
l1BlockNumber: this.l1BlockNumber,
|
|
169
173
|
l2SlotNumber,
|
|
170
174
|
l2Epoch,
|
|
171
|
-
|
|
172
|
-
|
|
175
|
+
checkpointNumber: this.checkpointNumber,
|
|
176
|
+
provenCheckpointNumber: this.provenCheckpointNumber,
|
|
173
177
|
totalL2Messages: this.totalL2Messages,
|
|
174
178
|
committee,
|
|
175
179
|
});
|
|
@@ -177,14 +181,13 @@ export class ChainMonitor extends EventEmitter<ChainMonitorEventMap> {
|
|
|
177
181
|
return this;
|
|
178
182
|
}
|
|
179
183
|
|
|
180
|
-
public waitUntilL2Slot(slot:
|
|
181
|
-
|
|
182
|
-
if (this.l2SlotNumber >= targetSlot) {
|
|
184
|
+
public waitUntilL2Slot(slot: SlotNumber): Promise<void> {
|
|
185
|
+
if (this.l2SlotNumber >= slot) {
|
|
183
186
|
return Promise.resolve();
|
|
184
187
|
}
|
|
185
188
|
return new Promise(resolve => {
|
|
186
|
-
const listener = (data: { l2SlotNumber:
|
|
187
|
-
if (data.l2SlotNumber >=
|
|
189
|
+
const listener = (data: { l2SlotNumber: SlotNumber; timestamp: bigint }) => {
|
|
190
|
+
if (data.l2SlotNumber >= slot) {
|
|
188
191
|
this.off('l2-slot', listener);
|
|
189
192
|
resolve();
|
|
190
193
|
}
|
|
@@ -225,19 +228,18 @@ export class ChainMonitor extends EventEmitter<ChainMonitorEventMap> {
|
|
|
225
228
|
});
|
|
226
229
|
}
|
|
227
230
|
|
|
228
|
-
public
|
|
229
|
-
|
|
230
|
-
if (this.l2BlockNumber >= targetBlock) {
|
|
231
|
+
public waitUntilCheckpoint(checkpointNumber: CheckpointNumber): Promise<void> {
|
|
232
|
+
if (this.checkpointNumber >= checkpointNumber) {
|
|
231
233
|
return Promise.resolve();
|
|
232
234
|
}
|
|
233
235
|
return new Promise(resolve => {
|
|
234
|
-
const listener = (data: {
|
|
235
|
-
if (data.
|
|
236
|
-
this.off('
|
|
236
|
+
const listener = (data: { checkpointNumber: CheckpointNumber; timestamp: bigint }) => {
|
|
237
|
+
if (data.checkpointNumber >= checkpointNumber) {
|
|
238
|
+
this.off('checkpoint', listener);
|
|
237
239
|
resolve();
|
|
238
240
|
}
|
|
239
241
|
};
|
|
240
|
-
this.on('
|
|
242
|
+
this.on('checkpoint', listener);
|
|
241
243
|
});
|
|
242
244
|
}
|
|
243
245
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { toBigIntBE, toHex } from '@aztec/foundation/bigint-buffer';
|
|
2
|
-
import { keccak256 } from '@aztec/foundation/crypto';
|
|
2
|
+
import { keccak256 } from '@aztec/foundation/crypto/keccak';
|
|
3
3
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
4
4
|
import { jsonStringify } from '@aztec/foundation/json-rpc';
|
|
5
5
|
import { createLogger } from '@aztec/foundation/log';
|
|
6
6
|
import { pluralize } from '@aztec/foundation/string';
|
|
7
7
|
import type { DateProvider, TestDateProvider } from '@aztec/foundation/timer';
|
|
8
8
|
|
|
9
|
-
import { type Hex, type Transaction, createPublicClient, fallback, hexToNumber, http } from 'viem';
|
|
9
|
+
import { type Chain, type Hex, type Transaction, createPublicClient, fallback, hexToNumber, http } from 'viem';
|
|
10
|
+
import { foundry } from 'viem/chains';
|
|
10
11
|
|
|
11
12
|
import type { ViemPublicClient } from '../types.js';
|
|
12
13
|
|
|
@@ -28,9 +29,14 @@ export class EthCheatCodes {
|
|
|
28
29
|
* The logger to use for the eth cheatcodes
|
|
29
30
|
*/
|
|
30
31
|
public logger = createLogger('ethereum:cheat_codes'),
|
|
32
|
+
/**
|
|
33
|
+
* The chain configuration provided to Anvil
|
|
34
|
+
*/
|
|
35
|
+
public chain: Chain = foundry,
|
|
31
36
|
) {
|
|
32
37
|
this.publicClient = createPublicClient({
|
|
33
38
|
transport: fallback(this.rpcUrls.map(url => http(url))),
|
|
39
|
+
chain: chain,
|
|
34
40
|
});
|
|
35
41
|
}
|
|
36
42
|
|