@aztec/ethereum 0.0.0-test.1 → 0.0.1-commit.b655e406
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/account.d.ts +2 -0
- package/dest/account.d.ts.map +1 -0
- package/dest/account.js +4 -0
- package/dest/client.d.ts +5 -3
- package/dest/client.d.ts.map +1 -1
- package/dest/client.js +16 -2
- package/dest/config.d.ts +107 -16
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +456 -22
- package/dest/contracts/empire_base.d.ts +21 -6
- package/dest/contracts/empire_base.d.ts.map +1 -1
- package/dest/contracts/empire_base.js +75 -2
- package/dest/contracts/empire_slashing_proposer.d.ts +65 -0
- package/dest/contracts/empire_slashing_proposer.d.ts.map +1 -0
- package/dest/contracts/empire_slashing_proposer.js +194 -0
- package/dest/contracts/errors.d.ts +7 -0
- package/dest/contracts/errors.d.ts.map +1 -0
- package/dest/contracts/errors.js +12 -0
- package/dest/contracts/fee_asset_handler.d.ts +19 -0
- package/dest/contracts/fee_asset_handler.d.ts.map +1 -0
- package/dest/contracts/fee_asset_handler.js +57 -0
- package/dest/contracts/fee_juice.d.ts +5 -6
- package/dest/contracts/fee_juice.d.ts.map +1 -1
- package/dest/contracts/fee_juice.js +27 -20
- package/dest/contracts/governance.d.ts +36 -25
- package/dest/contracts/governance.d.ts.map +1 -1
- package/dest/contracts/governance.js +87 -84
- package/dest/contracts/governance_proposer.d.ts +13 -11
- package/dest/contracts/governance_proposer.d.ts.map +1 -1
- package/dest/contracts/governance_proposer.js +32 -18
- package/dest/contracts/gse.d.ts +32 -0
- package/dest/contracts/gse.d.ts.map +1 -0
- package/dest/contracts/gse.js +72 -0
- package/dest/contracts/inbox.d.ts +26 -0
- package/dest/contracts/inbox.d.ts.map +1 -0
- package/dest/contracts/inbox.js +45 -0
- package/dest/contracts/index.d.ts +8 -2
- package/dest/contracts/index.d.ts.map +1 -1
- package/dest/contracts/index.js +8 -2
- package/dest/contracts/multicall.d.ts +21 -0
- package/dest/contracts/multicall.d.ts.map +1 -0
- package/dest/contracts/multicall.js +156 -0
- package/dest/contracts/registry.d.ts +9 -4
- package/dest/contracts/registry.d.ts.map +1 -1
- package/dest/contracts/registry.js +44 -16
- package/dest/contracts/rollup.d.ts +202 -29
- package/dest/contracts/rollup.d.ts.map +1 -1
- package/dest/contracts/rollup.js +500 -55
- package/dest/contracts/slasher_contract.d.ts +44 -0
- package/dest/contracts/slasher_contract.d.ts.map +1 -0
- package/dest/contracts/slasher_contract.js +75 -0
- package/dest/contracts/tally_slashing_proposer.d.ts +138 -0
- package/dest/contracts/tally_slashing_proposer.d.ts.map +1 -0
- package/dest/contracts/tally_slashing_proposer.js +313 -0
- package/dest/contracts/utils.d.ts +3 -0
- package/dest/contracts/utils.d.ts.map +1 -0
- package/dest/contracts/utils.js +11 -0
- package/dest/deploy_l1_contracts.d.ts +128 -21112
- package/dest/deploy_l1_contracts.d.ts.map +1 -1
- package/dest/deploy_l1_contracts.js +1204 -418
- package/dest/eth-signer/eth-signer.d.ts +21 -0
- package/dest/eth-signer/eth-signer.d.ts.map +1 -0
- package/dest/eth-signer/eth-signer.js +5 -0
- package/dest/eth-signer/index.d.ts +2 -0
- package/dest/eth-signer/index.d.ts.map +1 -0
- package/dest/eth-signer/index.js +1 -0
- package/dest/index.d.ts +6 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +6 -2
- package/dest/l1_artifacts.d.ts +76184 -0
- package/dest/l1_artifacts.d.ts.map +1 -0
- package/dest/l1_artifacts.js +166 -0
- package/dest/l1_contract_addresses.d.ts +21 -1
- package/dest/l1_contract_addresses.d.ts.map +1 -1
- package/dest/l1_contract_addresses.js +22 -18
- package/dest/l1_reader.d.ts +1 -1
- package/dest/l1_reader.d.ts.map +1 -1
- package/dest/l1_reader.js +8 -8
- package/dest/l1_tx_utils/config.d.ts +59 -0
- package/dest/l1_tx_utils/config.d.ts.map +1 -0
- package/dest/l1_tx_utils/config.js +73 -0
- package/dest/l1_tx_utils/constants.d.ts +6 -0
- package/dest/l1_tx_utils/constants.d.ts.map +1 -0
- package/dest/l1_tx_utils/constants.js +14 -0
- package/dest/l1_tx_utils/factory.d.ts +24 -0
- package/dest/l1_tx_utils/factory.d.ts.map +1 -0
- package/dest/l1_tx_utils/factory.js +12 -0
- package/dest/l1_tx_utils/index.d.ts +10 -0
- package/dest/l1_tx_utils/index.d.ts.map +1 -0
- package/dest/l1_tx_utils/index.js +10 -0
- package/dest/l1_tx_utils/interfaces.d.ts +76 -0
- package/dest/l1_tx_utils/interfaces.d.ts.map +1 -0
- package/dest/l1_tx_utils/interfaces.js +4 -0
- package/dest/l1_tx_utils/l1_tx_utils.d.ts +95 -0
- package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -0
- package/dest/l1_tx_utils/l1_tx_utils.js +610 -0
- package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts +26 -0
- package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts.map +1 -0
- package/dest/l1_tx_utils/l1_tx_utils_with_blobs.js +26 -0
- package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts +94 -0
- package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -0
- package/dest/l1_tx_utils/readonly_l1_tx_utils.js +431 -0
- package/dest/l1_tx_utils/signer.d.ts +4 -0
- package/dest/l1_tx_utils/signer.d.ts.map +1 -0
- package/dest/l1_tx_utils/signer.js +16 -0
- package/dest/l1_tx_utils/types.d.ts +67 -0
- package/dest/l1_tx_utils/types.d.ts.map +1 -0
- package/dest/l1_tx_utils/types.js +26 -0
- package/dest/l1_tx_utils/utils.d.ts +4 -0
- package/dest/l1_tx_utils/utils.d.ts.map +1 -0
- package/dest/l1_tx_utils/utils.js +14 -0
- package/dest/l1_types.d.ts +6 -0
- package/dest/l1_types.d.ts.map +1 -0
- package/dest/l1_types.js +1 -0
- package/dest/publisher_manager.d.ts +15 -0
- package/dest/publisher_manager.d.ts.map +1 -0
- package/dest/publisher_manager.js +88 -0
- package/dest/queries.d.ts +3 -1
- package/dest/queries.d.ts.map +1 -1
- package/dest/queries.js +51 -12
- package/dest/test/chain_monitor.d.ts +72 -0
- package/dest/test/chain_monitor.d.ts.map +1 -0
- package/dest/test/chain_monitor.js +216 -0
- package/dest/test/delayed_tx_utils.d.ts +7 -2
- package/dest/test/delayed_tx_utils.d.ts.map +1 -1
- package/dest/test/delayed_tx_utils.js +13 -6
- package/dest/{eth_cheat_codes.d.ts → test/eth_cheat_codes.d.ts} +87 -13
- package/dest/test/eth_cheat_codes.d.ts.map +1 -0
- package/dest/test/eth_cheat_codes.js +552 -0
- 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/eth_cheat_codes_with_state.js +1 -1
- package/dest/test/index.d.ts +3 -0
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/index.js +3 -0
- package/dest/test/rollup_cheat_codes.d.ts +86 -0
- package/dest/test/rollup_cheat_codes.d.ts.map +1 -0
- package/dest/test/rollup_cheat_codes.js +268 -0
- package/dest/test/start_anvil.d.ts +5 -0
- package/dest/test/start_anvil.d.ts.map +1 -1
- package/dest/test/start_anvil.js +15 -7
- package/dest/test/tx_delayer.d.ts +17 -6
- package/dest/test/tx_delayer.d.ts.map +1 -1
- package/dest/test/tx_delayer.js +95 -19
- package/dest/test/upgrade_utils.d.ts +5 -4
- package/dest/test/upgrade_utils.d.ts.map +1 -1
- package/dest/test/upgrade_utils.js +23 -16
- package/dest/types.d.ts +6 -7
- package/dest/types.d.ts.map +1 -1
- package/dest/types.js +3 -1
- package/dest/utils.d.ts +1 -0
- package/dest/utils.d.ts.map +1 -1
- package/dest/utils.js +43 -88
- package/dest/zkPassportVerifierAddress.d.ts +15 -0
- package/dest/zkPassportVerifierAddress.d.ts.map +1 -0
- package/dest/zkPassportVerifierAddress.js +11 -0
- package/package.json +24 -16
- package/src/account.ts +5 -0
- package/src/client.ts +42 -4
- package/src/config.ts +584 -31
- package/src/contracts/empire_base.ts +75 -6
- package/src/contracts/empire_slashing_proposer.ts +259 -0
- package/src/contracts/errors.ts +13 -0
- package/src/contracts/fee_asset_handler.ts +63 -0
- package/src/contracts/fee_juice.ts +29 -15
- package/src/contracts/governance.ts +80 -77
- package/src/contracts/governance_proposer.ts +60 -24
- package/src/contracts/gse.ts +88 -0
- package/src/contracts/inbox.ts +63 -0
- package/src/contracts/index.ts +8 -2
- package/src/contracts/multicall.ts +155 -0
- package/src/contracts/registry.ts +51 -26
- package/src/contracts/rollup.ts +585 -56
- package/src/contracts/slasher_contract.ts +89 -0
- package/src/contracts/tally_slashing_proposer.ts +315 -0
- package/src/contracts/utils.ts +14 -0
- package/src/deploy_l1_contracts.ts +1467 -566
- package/src/eth-signer/eth-signer.ts +25 -0
- package/src/eth-signer/index.ts +1 -0
- package/src/index.ts +6 -2
- package/src/l1_artifacts.ts +254 -0
- package/src/l1_contract_addresses.ts +32 -19
- package/src/l1_reader.ts +9 -9
- package/src/l1_tx_utils/README.md +177 -0
- package/src/l1_tx_utils/config.ts +140 -0
- package/src/l1_tx_utils/constants.ts +18 -0
- package/src/l1_tx_utils/factory.ts +64 -0
- package/src/l1_tx_utils/index.ts +12 -0
- package/src/l1_tx_utils/interfaces.ts +86 -0
- package/src/l1_tx_utils/l1_tx_utils.ts +718 -0
- package/src/l1_tx_utils/l1_tx_utils_with_blobs.ts +77 -0
- package/src/l1_tx_utils/readonly_l1_tx_utils.ts +559 -0
- package/src/l1_tx_utils/signer.ts +28 -0
- package/src/l1_tx_utils/types.ts +85 -0
- package/src/l1_tx_utils/utils.ts +16 -0
- package/src/l1_types.ts +6 -0
- package/src/publisher_manager.ts +106 -0
- package/src/queries.ts +70 -15
- package/src/test/chain_monitor.ts +243 -0
- package/src/test/delayed_tx_utils.ts +34 -6
- package/src/test/eth_cheat_codes.ts +582 -0
- package/src/test/eth_cheat_codes_with_state.ts +1 -1
- package/src/test/index.ts +3 -0
- package/src/test/rollup_cheat_codes.ts +310 -0
- package/src/test/start_anvil.ts +20 -5
- package/src/test/tx_delayer.ts +127 -26
- package/src/test/upgrade_utils.ts +30 -21
- package/src/types.ts +10 -8
- package/src/utils.ts +49 -90
- package/src/zkPassportVerifierAddress.ts +15 -0
- package/dest/contracts/forwarder.d.ts +0 -24
- package/dest/contracts/forwarder.d.ts.map +0 -1
- package/dest/contracts/forwarder.js +0 -101
- package/dest/contracts/slashing_proposer.d.ts +0 -21
- package/dest/contracts/slashing_proposer.d.ts.map +0 -1
- package/dest/contracts/slashing_proposer.js +0 -47
- package/dest/eth_cheat_codes.d.ts.map +0 -1
- package/dest/eth_cheat_codes.js +0 -303
- package/dest/l1_tx_utils.d.ts +0 -192
- package/dest/l1_tx_utils.d.ts.map +0 -1
- package/dest/l1_tx_utils.js +0 -641
- package/dest/l1_tx_utils_with_blobs.d.ts +0 -12
- package/dest/l1_tx_utils_with_blobs.d.ts.map +0 -1
- package/dest/l1_tx_utils_with_blobs.js +0 -64
- package/src/contracts/forwarder.ts +0 -132
- package/src/contracts/slashing_proposer.ts +0 -51
- package/src/eth_cheat_codes.ts +0 -314
- package/src/l1_tx_utils.ts +0 -847
- package/src/l1_tx_utils_with_blobs.ts +0 -86
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import { RollupContract } from '@aztec/ethereum';
|
|
2
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
4
|
+
import { RollupAbi } from '@aztec/l1-artifacts/RollupAbi';
|
|
5
|
+
import { createPublicClient, fallback, getContract, hexToBigInt, http } from 'viem';
|
|
6
|
+
import { foundry } from 'viem/chains';
|
|
7
|
+
import { EthCheatCodes } from './eth_cheat_codes.js';
|
|
8
|
+
/** Cheat codes for the L1 rollup contract. */ export class RollupCheatCodes {
|
|
9
|
+
ethCheatCodes;
|
|
10
|
+
client;
|
|
11
|
+
rollup;
|
|
12
|
+
logger;
|
|
13
|
+
constructor(ethCheatCodes, addresses){
|
|
14
|
+
this.ethCheatCodes = ethCheatCodes;
|
|
15
|
+
this.logger = createLogger('aztecjs:cheat_codes');
|
|
16
|
+
this.client = createPublicClient({
|
|
17
|
+
chain: foundry,
|
|
18
|
+
transport: fallback(ethCheatCodes.rpcUrls.map((url)=>http(url)))
|
|
19
|
+
});
|
|
20
|
+
this.rollup = getContract({
|
|
21
|
+
abi: RollupAbi,
|
|
22
|
+
address: addresses.rollupAddress.toString(),
|
|
23
|
+
client: this.client
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
static create(rpcUrls, addresses, dateProvider) {
|
|
27
|
+
const ethCheatCodes = new EthCheatCodes(rpcUrls, dateProvider);
|
|
28
|
+
return new RollupCheatCodes(ethCheatCodes, addresses);
|
|
29
|
+
}
|
|
30
|
+
/** Returns the current slot */ async getSlot() {
|
|
31
|
+
const ts = BigInt((await this.client.getBlock()).timestamp);
|
|
32
|
+
return await this.rollup.read.getSlotAt([
|
|
33
|
+
ts
|
|
34
|
+
]);
|
|
35
|
+
}
|
|
36
|
+
/** Returns the current epoch */ async getEpoch() {
|
|
37
|
+
const slotNumber = await this.getSlot();
|
|
38
|
+
return await this.rollup.read.getEpochAtSlot([
|
|
39
|
+
slotNumber
|
|
40
|
+
]);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Returns the pending and proven chain tips
|
|
44
|
+
* @returns The pending and proven chain tips
|
|
45
|
+
*/ async getTips() {
|
|
46
|
+
const res = await this.rollup.read.getTips();
|
|
47
|
+
return {
|
|
48
|
+
pending: res.pendingBlockNumber,
|
|
49
|
+
proven: res.provenBlockNumber
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Logs the current state of the rollup contract.
|
|
54
|
+
*/ async debugRollup() {
|
|
55
|
+
const rollup = new RollupContract(this.client, this.rollup.address);
|
|
56
|
+
const pendingNum = await rollup.getBlockNumber();
|
|
57
|
+
const provenNum = await rollup.getProvenBlockNumber();
|
|
58
|
+
const validators = await rollup.getAttesters();
|
|
59
|
+
const committee = await rollup.getCurrentEpochCommittee();
|
|
60
|
+
const archive = await rollup.archive();
|
|
61
|
+
const slot = await this.getSlot();
|
|
62
|
+
const epochNum = await rollup.getEpochNumberForSlotNumber(slot);
|
|
63
|
+
this.logger.info(`Pending block num: ${pendingNum}`);
|
|
64
|
+
this.logger.info(`Proven block num: ${provenNum}`);
|
|
65
|
+
this.logger.info(`Validators: ${validators.map((v)=>v.toString()).join(', ')}`);
|
|
66
|
+
this.logger.info(`Committee: ${committee?.map((v)=>v.toString()).join(', ')}`);
|
|
67
|
+
this.logger.info(`Archive: ${archive}`);
|
|
68
|
+
this.logger.info(`Epoch num: ${epochNum}`);
|
|
69
|
+
this.logger.info(`Slot: ${slot}`);
|
|
70
|
+
}
|
|
71
|
+
/** Fetches the epoch and slot duration config from the rollup contract */ async getConfig() {
|
|
72
|
+
const [epochDuration, slotDuration] = await Promise.all([
|
|
73
|
+
this.rollup.read.getEpochDuration(),
|
|
74
|
+
this.rollup.read.getSlotDuration()
|
|
75
|
+
]);
|
|
76
|
+
return {
|
|
77
|
+
epochDuration,
|
|
78
|
+
slotDuration
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Advances time to the beginning of the given epoch
|
|
83
|
+
* @param epoch - The epoch to advance to
|
|
84
|
+
* @param opts - Options
|
|
85
|
+
*/ async advanceToEpoch(epoch, opts = {}) {
|
|
86
|
+
const { epochDuration: slotsInEpoch } = await this.getConfig();
|
|
87
|
+
const timestamp = await this.rollup.read.getTimestampForSlot([
|
|
88
|
+
BigInt(epoch) * slotsInEpoch
|
|
89
|
+
]) + BigInt(opts.offset ?? 0);
|
|
90
|
+
try {
|
|
91
|
+
await this.ethCheatCodes.warp(Number(timestamp), {
|
|
92
|
+
...opts,
|
|
93
|
+
silent: true,
|
|
94
|
+
resetBlockInterval: true
|
|
95
|
+
});
|
|
96
|
+
this.logger.warn(`Warped to epoch ${epoch}`);
|
|
97
|
+
} catch (err) {
|
|
98
|
+
this.logger.warn(`Warp to epoch ${epoch} failed: ${err}`);
|
|
99
|
+
}
|
|
100
|
+
return timestamp;
|
|
101
|
+
}
|
|
102
|
+
/** Warps time in L1 until the next epoch */ async advanceToNextEpoch() {
|
|
103
|
+
const slot = await this.getSlot();
|
|
104
|
+
const { epochDuration, slotDuration } = await this.getConfig();
|
|
105
|
+
const slotsUntilNextEpoch = epochDuration - slot % epochDuration + 1n;
|
|
106
|
+
const timeToNextEpoch = slotsUntilNextEpoch * slotDuration;
|
|
107
|
+
const l1Timestamp = BigInt((await this.client.getBlock()).timestamp);
|
|
108
|
+
await this.ethCheatCodes.warp(Number(l1Timestamp + timeToNextEpoch), {
|
|
109
|
+
silent: true,
|
|
110
|
+
resetBlockInterval: true
|
|
111
|
+
});
|
|
112
|
+
this.logger.warn(`Advanced to next epoch`);
|
|
113
|
+
}
|
|
114
|
+
/** Warps time in L1 until the beginning of the next slot. */ async advanceToNextSlot() {
|
|
115
|
+
const currentSlot = await this.getSlot();
|
|
116
|
+
const timestamp = await this.rollup.read.getTimestampForSlot([
|
|
117
|
+
currentSlot + 1n
|
|
118
|
+
]);
|
|
119
|
+
await this.ethCheatCodes.warp(Number(timestamp), {
|
|
120
|
+
silent: true,
|
|
121
|
+
resetBlockInterval: true
|
|
122
|
+
});
|
|
123
|
+
this.logger.warn(`Advanced to slot ${currentSlot + 1n}`);
|
|
124
|
+
return [
|
|
125
|
+
timestamp,
|
|
126
|
+
currentSlot + 1n
|
|
127
|
+
];
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Warps time in L1 equivalent to however many slots.
|
|
131
|
+
* @param howMany - The number of slots to advance.
|
|
132
|
+
*/ async advanceSlots(howMany) {
|
|
133
|
+
const l1Timestamp = (await this.client.getBlock()).timestamp;
|
|
134
|
+
const slotDuration = await this.rollup.read.getSlotDuration();
|
|
135
|
+
const timeToWarp = BigInt(howMany) * slotDuration;
|
|
136
|
+
await this.ethCheatCodes.warp(l1Timestamp + timeToWarp, {
|
|
137
|
+
silent: true,
|
|
138
|
+
resetBlockInterval: true
|
|
139
|
+
});
|
|
140
|
+
const [slot, epoch] = await Promise.all([
|
|
141
|
+
this.getSlot(),
|
|
142
|
+
this.getEpoch()
|
|
143
|
+
]);
|
|
144
|
+
this.logger.warn(`Advanced ${howMany} slots up to slot ${slot} in epoch ${epoch}`);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Marks the specified block (or latest if none) as proven
|
|
148
|
+
* @param maybeBlockNumber - The block number to mark as proven (defaults to latest pending)
|
|
149
|
+
*/ markAsProven(maybeBlockNumber) {
|
|
150
|
+
return this.ethCheatCodes.execWithPausedAnvil(async ()=>{
|
|
151
|
+
const tipsBefore = await this.getTips();
|
|
152
|
+
const { pending, proven } = tipsBefore;
|
|
153
|
+
let blockNumber = maybeBlockNumber;
|
|
154
|
+
if (blockNumber === undefined || blockNumber > pending) {
|
|
155
|
+
blockNumber = pending;
|
|
156
|
+
}
|
|
157
|
+
if (blockNumber <= proven) {
|
|
158
|
+
this.logger.debug(`Block ${blockNumber} is already proven`);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
// @note @LHerskind this is heavily dependent on the storage layout and size of values
|
|
162
|
+
// The rollupStore is a struct and if the size of elements or the struct changes, this can break
|
|
163
|
+
const provenBlockNumberSlot = hexToBigInt(RollupContract.stfStorageSlot);
|
|
164
|
+
// Need to pack it as a single 32 byte word
|
|
165
|
+
const newValue = BigInt(tipsBefore.pending) << 128n | BigInt(blockNumber);
|
|
166
|
+
await this.ethCheatCodes.store(EthAddress.fromString(this.rollup.address), provenBlockNumberSlot, newValue);
|
|
167
|
+
const tipsAfter = await this.getTips();
|
|
168
|
+
if (tipsAfter.pending < tipsAfter.proven) {
|
|
169
|
+
throw new Error('Overwrote pending tip to a block in the past');
|
|
170
|
+
}
|
|
171
|
+
this.logger.info(`Proven tip moved: ${tipsBefore.proven} -> ${tipsAfter.proven}. Pending tip: ${tipsAfter.pending}.`);
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Overrides the inProgress field of the Inbox contract state
|
|
176
|
+
* @param howMuch - How many blocks to move it forward
|
|
177
|
+
*/ advanceInboxInProgress(howMuch) {
|
|
178
|
+
return this.ethCheatCodes.execWithPausedAnvil(async ()=>{
|
|
179
|
+
// Storage slot 2 contains the InboxState struct
|
|
180
|
+
const inboxStateSlot = 2n;
|
|
181
|
+
// Get inbox and its current state values
|
|
182
|
+
const inboxAddress = await this.rollup.read.getInbox();
|
|
183
|
+
const currentStateValue = await this.ethCheatCodes.load(EthAddress.fromString(inboxAddress), inboxStateSlot);
|
|
184
|
+
// Extract current values from the packed storage slot
|
|
185
|
+
// Storage layout: rollingHash (128 bits) | totalMessagesInserted (64 bits) | inProgress (64 bits)
|
|
186
|
+
const currentRollingHash = currentStateValue & (1n << 128n) - 1n;
|
|
187
|
+
const currentTotalMessages = currentStateValue >> 128n & (1n << 64n) - 1n;
|
|
188
|
+
const currentInProgress = currentStateValue >> 192n;
|
|
189
|
+
const newInProgress = currentInProgress + BigInt(howMuch);
|
|
190
|
+
// Pack new values: rollingHash (low 128 bits) | totalMessages (middle 64 bits) | inProgress (high 64 bits)
|
|
191
|
+
const newValue = BigInt(newInProgress) << 192n | currentTotalMessages << 128n | currentRollingHash;
|
|
192
|
+
await this.ethCheatCodes.store(EthAddress.fromString(inboxAddress), inboxStateSlot, newValue, {
|
|
193
|
+
silent: true
|
|
194
|
+
});
|
|
195
|
+
this.logger.warn(`Inbox inProgress advanced from ${currentInProgress} to ${newInProgress}`, {
|
|
196
|
+
inbox: inboxAddress,
|
|
197
|
+
oldValue: '0x' + currentStateValue.toString(16),
|
|
198
|
+
newValue: '0x' + newValue.toString(16),
|
|
199
|
+
rollingHash: currentRollingHash,
|
|
200
|
+
totalMessages: currentTotalMessages,
|
|
201
|
+
oldInProgress: currentInProgress,
|
|
202
|
+
newInProgress
|
|
203
|
+
});
|
|
204
|
+
return newInProgress;
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Executes an action impersonated as the owner of the Rollup contract.
|
|
209
|
+
* @param action - The action to execute
|
|
210
|
+
*/ async asOwner(action) {
|
|
211
|
+
const owner = await this.rollup.read.owner();
|
|
212
|
+
await this.ethCheatCodes.startImpersonating(owner);
|
|
213
|
+
await action(owner, this.rollup);
|
|
214
|
+
await this.ethCheatCodes.stopImpersonating(owner);
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Sets up the epoch.
|
|
218
|
+
*/ async setupEpoch() {
|
|
219
|
+
// Doesn't need to be done as owner, but the functionality is here...
|
|
220
|
+
await this.asOwner(async (account, rollup)=>{
|
|
221
|
+
const hash = await rollup.write.setupEpoch({
|
|
222
|
+
account
|
|
223
|
+
});
|
|
224
|
+
await this.client.waitForTransactionReceipt({
|
|
225
|
+
hash
|
|
226
|
+
});
|
|
227
|
+
this.logger.warn(`Setup epoch`);
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
/** Directly calls the L1 gas fee oracle. */ async updateL1GasFeeOracle() {
|
|
231
|
+
await this.asOwner(async (account, rollup)=>{
|
|
232
|
+
const hash = await rollup.write.updateL1GasFeeOracle({
|
|
233
|
+
account,
|
|
234
|
+
chain: this.client.chain
|
|
235
|
+
});
|
|
236
|
+
await this.client.waitForTransactionReceipt({
|
|
237
|
+
hash
|
|
238
|
+
});
|
|
239
|
+
this.logger.warn(`Updated L1 gas fee oracle`);
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Bumps proving cost per mana.
|
|
244
|
+
* @param bumper - Callback to calculate the new proving cost per mana based on current value.
|
|
245
|
+
*/ async bumpProvingCostPerMana(bumper) {
|
|
246
|
+
const currentCost = await this.rollup.read.getProvingCostPerManaInEth();
|
|
247
|
+
const newCost = bumper(currentCost);
|
|
248
|
+
await this.setProvingCostPerMana(newCost);
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Directly updates proving cost per mana.
|
|
252
|
+
* @param ethValue - The new proving cost per mana in ETH
|
|
253
|
+
*/ async setProvingCostPerMana(ethValue) {
|
|
254
|
+
await this.asOwner(async (account, rollup)=>{
|
|
255
|
+
const hash = await rollup.write.setProvingCostPerMana([
|
|
256
|
+
ethValue
|
|
257
|
+
], {
|
|
258
|
+
account,
|
|
259
|
+
chain: this.client.chain,
|
|
260
|
+
gasLimit: 1000000n
|
|
261
|
+
});
|
|
262
|
+
await this.client.waitForTransactionReceipt({
|
|
263
|
+
hash
|
|
264
|
+
});
|
|
265
|
+
this.logger.warn(`Updated proving cost per mana to ${ethValue}`);
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
}
|
|
@@ -3,9 +3,14 @@ import { type Anvil } from '@viem/anvil';
|
|
|
3
3
|
* Ensures there's a running Anvil instance and returns the RPC URL.
|
|
4
4
|
*/
|
|
5
5
|
export declare function startAnvil(opts?: {
|
|
6
|
+
port?: number;
|
|
6
7
|
l1BlockTime?: number;
|
|
8
|
+
log?: boolean;
|
|
9
|
+
captureMethodCalls?: boolean;
|
|
10
|
+
accounts?: number;
|
|
7
11
|
}): Promise<{
|
|
8
12
|
anvil: Anvil;
|
|
13
|
+
methodCalls?: string[];
|
|
9
14
|
rpcUrl: string;
|
|
10
15
|
stop: () => Promise<void>;
|
|
11
16
|
}>;
|
|
@@ -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":"AAIA,OAAO,EAAE,KAAK,KAAK,EAAe,MAAM,aAAa,CAAC;AAGtD;;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;CACd,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,CAgD9F"}
|
package/dest/test/start_anvil.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
1
2
|
import { makeBackoff, retry } from '@aztec/foundation/retry';
|
|
2
3
|
import { fileURLToPath } from '@aztec/foundation/url';
|
|
3
4
|
import { createAnvil } from '@viem/anvil';
|
|
@@ -6,24 +7,33 @@ import { dirname, resolve } from 'path';
|
|
|
6
7
|
* Ensures there's a running Anvil instance and returns the RPC URL.
|
|
7
8
|
*/ export async function startAnvil(opts = {}) {
|
|
8
9
|
const anvilBinary = resolve(dirname(fileURLToPath(import.meta.url)), '../../', 'scripts/anvil_kill_wrapper.sh');
|
|
10
|
+
const logger = opts.log ? createLogger('ethereum:anvil') : undefined;
|
|
11
|
+
const methodCalls = opts.captureMethodCalls ? [] : undefined;
|
|
9
12
|
let port;
|
|
10
13
|
// Start anvil.
|
|
11
14
|
// We go via a wrapper script to ensure if the parent dies, anvil dies.
|
|
12
15
|
const anvil = await retry(async ()=>{
|
|
13
16
|
const anvil = createAnvil({
|
|
14
17
|
anvilBinary,
|
|
15
|
-
|
|
18
|
+
host: '127.0.0.1',
|
|
19
|
+
port: opts.port ?? 8545,
|
|
16
20
|
blockTime: opts.l1BlockTime,
|
|
17
|
-
stopTimeout: 1000
|
|
21
|
+
stopTimeout: 1000,
|
|
22
|
+
accounts: opts.accounts ?? 20,
|
|
23
|
+
gasLimit: 45_000_000n
|
|
18
24
|
});
|
|
19
25
|
// Listen to the anvil output to get the port.
|
|
20
26
|
const removeHandler = anvil.on('message', (message)=>{
|
|
27
|
+
logger?.debug(message.trim());
|
|
28
|
+
methodCalls?.push(...message.match(/eth_[^\s]+/g) || []);
|
|
21
29
|
if (port === undefined && message.includes('Listening on')) {
|
|
22
30
|
port = parseInt(message.match(/Listening on ([^:]+):(\d+)/)[2]);
|
|
23
31
|
}
|
|
24
32
|
});
|
|
25
33
|
await anvil.start();
|
|
26
|
-
|
|
34
|
+
if (!logger && !opts.captureMethodCalls) {
|
|
35
|
+
removeHandler();
|
|
36
|
+
}
|
|
27
37
|
return anvil;
|
|
28
38
|
}, 'Start anvil', makeBackoff([
|
|
29
39
|
5,
|
|
@@ -34,12 +44,10 @@ import { dirname, resolve } from 'path';
|
|
|
34
44
|
throw new Error('Failed to start anvil');
|
|
35
45
|
}
|
|
36
46
|
// Monkeypatch the anvil instance to include the actually assigned port
|
|
37
|
-
Object.defineProperty(anvil, 'port', {
|
|
38
|
-
value: port,
|
|
39
|
-
writable: false
|
|
40
|
-
});
|
|
47
|
+
// Object.defineProperty(anvil, 'port', { value: port, writable: false });
|
|
41
48
|
return {
|
|
42
49
|
anvil,
|
|
50
|
+
methodCalls,
|
|
43
51
|
stop: ()=>anvil.stop(),
|
|
44
52
|
rpcUrl: `http://127.0.0.1:${port}`
|
|
45
53
|
};
|
|
@@ -1,22 +1,33 @@
|
|
|
1
1
|
import { type Logger } from '@aztec/foundation/log';
|
|
2
|
+
import type { DateProvider } from '@aztec/foundation/timer';
|
|
2
3
|
import { type Client, type Hex } from 'viem';
|
|
3
|
-
import type
|
|
4
|
-
export declare function waitUntilBlock<T extends Client>(client: T, blockNumber: number | bigint, logger?: Logger): Promise<boolean>;
|
|
5
|
-
export declare function waitUntilL1Timestamp<T extends Client>(client: T, timestamp: number | bigint, logger?: Logger): Promise<boolean>;
|
|
4
|
+
import { type ViemClient } from '../types.js';
|
|
5
|
+
export declare function waitUntilBlock<T extends Client>(client: T, blockNumber: number | bigint, logger?: Logger, timeout?: number): Promise<boolean>;
|
|
6
|
+
export declare function waitUntilL1Timestamp<T extends Client>(client: T, timestamp: number | bigint, logger?: Logger, timeout?: number): Promise<boolean>;
|
|
6
7
|
export interface Delayer {
|
|
7
|
-
/** Returns the
|
|
8
|
-
|
|
8
|
+
/** Returns the hashes of all effectively sent txs. */
|
|
9
|
+
getSentTxHashes(): Hex[];
|
|
10
|
+
/** Returns the raw hex for all cancelled txs. */
|
|
11
|
+
getCancelledTxs(): Hex[];
|
|
9
12
|
/** Delays the next tx to be sent so it lands on the given L1 block number. */
|
|
10
13
|
pauseNextTxUntilBlock(l1BlockNumber: number | bigint | undefined): void;
|
|
11
14
|
/** Delays the next tx to be sent so it lands on the given timestamp. */
|
|
12
15
|
pauseNextTxUntilTimestamp(l1Timestamp: number | bigint | undefined): void;
|
|
16
|
+
/** Delays the next tx to be sent indefinitely. */
|
|
17
|
+
cancelNextTx(): void;
|
|
18
|
+
/**
|
|
19
|
+
* Sets max inclusion time into slot. If more than this many seconds have passed
|
|
20
|
+
* since the last L1 block was mined, then any tx will not be mined in the current
|
|
21
|
+
* L1 slot but will be deferred for the next one.
|
|
22
|
+
*/
|
|
23
|
+
setMaxInclusionTimeIntoSlot(seconds: number | bigint | undefined): void;
|
|
13
24
|
}
|
|
14
25
|
/**
|
|
15
26
|
* Returns a new client (without modifying the one passed in) with an injected tx delayer.
|
|
16
27
|
* The delayer can be used to hold off the next tx to be sent until a given block number.
|
|
17
28
|
* TODO(#10824): This doesn't play along well with blob txs for some reason.
|
|
18
29
|
*/
|
|
19
|
-
export declare function withDelayer<T extends
|
|
30
|
+
export declare function withDelayer<T extends ViemClient>(client: T, dateProvider: DateProvider, opts: {
|
|
20
31
|
ethereumSlotDuration: bigint | number;
|
|
21
32
|
}): {
|
|
22
33
|
client: T;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tx_delayer.d.ts","sourceRoot":"","sources":["../../src/test/tx_delayer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"tx_delayer.d.ts","sourceRoot":"","sources":["../../src/test/tx_delayer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAElE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAG5D,OAAO,EACL,KAAK,MAAM,EACX,KAAK,GAAG,EAQT,MAAM,MAAM,CAAC;AAEd,OAAO,EAAE,KAAK,UAAU,EAAoB,MAAM,aAAa,CAAC;AAEhE,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,EAC7C,MAAM,EAAE,CAAC,EACT,WAAW,EAAE,MAAM,GAAG,MAAM,EAC5B,MAAM,CAAC,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,MAAM,oBAiBjB;AAED,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,MAAM,EACnD,MAAM,EAAE,CAAC,EACT,SAAS,EAAE,MAAM,GAAG,MAAM,EAC1B,MAAM,CAAC,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,MAAM,oBAwBjB;AAED,MAAM,WAAW,OAAO;IACtB,sDAAsD;IACtD,eAAe,IAAI,GAAG,EAAE,CAAC;IACzB,iDAAiD;IACjD,eAAe,IAAI,GAAG,EAAE,CAAC;IACzB,8EAA8E;IAC9E,qBAAqB,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;IACxE,wEAAwE;IACxE,yBAAyB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;IAC1E,kDAAkD;IAClD,YAAY,IAAI,IAAI,CAAC;IACrB;;;;OAIG;IACH,2BAA2B,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;CACzE;AA0CD;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,UAAU,EAC9C,MAAM,EAAE,CAAC,EACT,YAAY,EAAE,YAAY,EAC1B,IAAI,EAAE;IAAE,oBAAoB,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,GAC9C;IAAE,MAAM,EAAE,CAAC,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CA0GjC"}
|
package/dest/test/tx_delayer.js
CHANGED
|
@@ -2,8 +2,9 @@ import { omit } from '@aztec/foundation/collection';
|
|
|
2
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
3
3
|
import { retryUntil } from '@aztec/foundation/retry';
|
|
4
4
|
import { inspect } from 'util';
|
|
5
|
-
import { keccak256, parseTransaction, publicActions, walletActions } from 'viem';
|
|
6
|
-
|
|
5
|
+
import { keccak256, parseTransaction, publicActions, serializeTransaction, walletActions } from 'viem';
|
|
6
|
+
import { isExtendedClient } from '../types.js';
|
|
7
|
+
export function waitUntilBlock(client, blockNumber, logger, timeout) {
|
|
7
8
|
const publicClient = 'getBlockNumber' in client && typeof client.getBlockNumber === 'function' ? client : client.extend(publicActions);
|
|
8
9
|
return retryUntil(async ()=>{
|
|
9
10
|
const currentBlockNumber = await publicClient.getBlockNumber({
|
|
@@ -11,9 +12,9 @@ export function waitUntilBlock(client, blockNumber, logger) {
|
|
|
11
12
|
});
|
|
12
13
|
logger?.debug(`Block number is ${currentBlockNumber} (waiting until ${blockNumber})`);
|
|
13
14
|
return currentBlockNumber >= BigInt(blockNumber);
|
|
14
|
-
}, `Wait until L1 block ${blockNumber}`, 120, 0.1);
|
|
15
|
+
}, `Wait until L1 block ${blockNumber}`, timeout ?? 120, 0.1);
|
|
15
16
|
}
|
|
16
|
-
export function waitUntilL1Timestamp(client, timestamp, logger) {
|
|
17
|
+
export function waitUntilL1Timestamp(client, timestamp, logger, timeout) {
|
|
17
18
|
const publicClient = 'getBlockNumber' in client && typeof client.getBlockNumber === 'function' ? client : client.extend(publicActions);
|
|
18
19
|
let lastBlock = undefined;
|
|
19
20
|
return retryUntil(async ()=>{
|
|
@@ -31,17 +32,30 @@ export function waitUntilL1Timestamp(client, timestamp, logger) {
|
|
|
31
32
|
const currentTs = currentBlock.timestamp;
|
|
32
33
|
logger?.debug(`Block timstamp is ${currentTs} (waiting until ${timestamp})`);
|
|
33
34
|
return currentTs >= BigInt(timestamp);
|
|
34
|
-
}, `Wait until L1 timestamp ${timestamp}`, 120, 0.1);
|
|
35
|
+
}, `Wait until L1 timestamp ${timestamp}`, timeout ?? 120, 0.1);
|
|
35
36
|
}
|
|
36
37
|
class DelayerImpl {
|
|
37
|
-
|
|
38
|
+
dateProvider;
|
|
39
|
+
logger;
|
|
40
|
+
constructor(dateProvider, opts){
|
|
41
|
+
this.dateProvider = dateProvider;
|
|
42
|
+
this.logger = createLogger('ethereum:tx_delayer');
|
|
43
|
+
this.maxInclusionTimeIntoSlot = undefined;
|
|
44
|
+
this.nextWait = undefined;
|
|
45
|
+
this.sentTxHashes = [];
|
|
46
|
+
this.cancelledTxs = [];
|
|
38
47
|
this.ethereumSlotDuration = BigInt(opts.ethereumSlotDuration);
|
|
39
48
|
}
|
|
49
|
+
maxInclusionTimeIntoSlot;
|
|
40
50
|
ethereumSlotDuration;
|
|
41
|
-
nextWait
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
51
|
+
nextWait;
|
|
52
|
+
sentTxHashes;
|
|
53
|
+
cancelledTxs;
|
|
54
|
+
getSentTxHashes() {
|
|
55
|
+
return this.sentTxHashes;
|
|
56
|
+
}
|
|
57
|
+
getCancelledTxs() {
|
|
58
|
+
return this.cancelledTxs;
|
|
45
59
|
}
|
|
46
60
|
pauseNextTxUntilBlock(l1BlockNumber) {
|
|
47
61
|
this.nextWait = {
|
|
@@ -53,32 +67,77 @@ class DelayerImpl {
|
|
|
53
67
|
l1Timestamp: BigInt(l1Timestamp)
|
|
54
68
|
};
|
|
55
69
|
}
|
|
70
|
+
cancelNextTx() {
|
|
71
|
+
this.nextWait = {
|
|
72
|
+
indefinitely: true
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
setMaxInclusionTimeIntoSlot(seconds) {
|
|
76
|
+
this.maxInclusionTimeIntoSlot = seconds;
|
|
77
|
+
}
|
|
56
78
|
}
|
|
57
79
|
/**
|
|
58
80
|
* Returns a new client (without modifying the one passed in) with an injected tx delayer.
|
|
59
81
|
* The delayer can be used to hold off the next tx to be sent until a given block number.
|
|
60
82
|
* TODO(#10824): This doesn't play along well with blob txs for some reason.
|
|
61
|
-
*/ export function withDelayer(client, opts) {
|
|
83
|
+
*/ export function withDelayer(client, dateProvider, opts) {
|
|
84
|
+
if (!isExtendedClient(client)) {
|
|
85
|
+
throw new Error('withDelayer has to be instantiated with a wallet viem client.');
|
|
86
|
+
}
|
|
62
87
|
const logger = createLogger('ethereum:tx_delayer');
|
|
63
|
-
const delayer = new DelayerImpl(opts);
|
|
88
|
+
const delayer = new DelayerImpl(dateProvider, opts);
|
|
64
89
|
const extended = client// Tweak sendRawTransaction so it uses the delay defined in the delayer.
|
|
65
90
|
// Note that this will only work with local accounts (ie accounts for which we have the private key).
|
|
66
91
|
// Transactions signed by the node will not be delayed since they use sendTransaction directly,
|
|
67
92
|
// but we do not use them in our codebase at all.
|
|
68
93
|
.extend((client)=>({
|
|
69
94
|
async sendRawTransaction (...args) {
|
|
95
|
+
let wait;
|
|
96
|
+
let txHash;
|
|
97
|
+
const { serializedTransaction } = args[0];
|
|
98
|
+
const publicClient = client;
|
|
70
99
|
if (delayer.nextWait !== undefined) {
|
|
100
|
+
// Check if we have been instructed to delay the next tx.
|
|
71
101
|
const waitUntil = delayer.nextWait;
|
|
72
102
|
delayer.nextWait = undefined;
|
|
73
|
-
const publicClient = client;
|
|
74
|
-
const wait = 'l1BlockNumber' in waitUntil ? waitUntilBlock(publicClient, waitUntil.l1BlockNumber - 1n, logger) : waitUntilL1Timestamp(publicClient, waitUntil.l1Timestamp - delayer.ethereumSlotDuration, logger);
|
|
75
103
|
// Compute the tx hash manually so we emulate sendRawTransaction response
|
|
76
|
-
|
|
77
|
-
|
|
104
|
+
txHash = computeTxHash(serializedTransaction);
|
|
105
|
+
// Cancel tx outright if instructed
|
|
106
|
+
if ('indefinitely' in waitUntil && waitUntil.indefinitely) {
|
|
107
|
+
logger.info(`Cancelling tx ${txHash}`);
|
|
108
|
+
delayer.cancelledTxs.push(serializedTransaction);
|
|
109
|
+
return Promise.resolve(txHash);
|
|
110
|
+
}
|
|
111
|
+
// Or wait until the desired block number or timestamp
|
|
112
|
+
wait = 'l1BlockNumber' in waitUntil ? waitUntilBlock(publicClient, waitUntil.l1BlockNumber - 1n, logger) : 'l1Timestamp' in waitUntil ? waitUntilL1Timestamp(publicClient, waitUntil.l1Timestamp - delayer.ethereumSlotDuration, logger) : undefined;
|
|
78
113
|
logger.info(`Delaying tx ${txHash} until ${inspect(waitUntil)}`, {
|
|
79
114
|
argsLen: args.length,
|
|
80
115
|
...omit(parseTransaction(serializedTransaction), 'data', 'sidecars')
|
|
81
116
|
});
|
|
117
|
+
} else if (delayer.maxInclusionTimeIntoSlot !== undefined) {
|
|
118
|
+
// Check if we need to delay txs sent too close to the end of the slot.
|
|
119
|
+
const currentBlock = await publicClient.getBlock({
|
|
120
|
+
includeTransactions: false
|
|
121
|
+
});
|
|
122
|
+
const { timestamp: lastBlockTimestamp, number } = currentBlock;
|
|
123
|
+
const now = delayer.dateProvider.now();
|
|
124
|
+
txHash = computeTxHash(serializedTransaction);
|
|
125
|
+
const logData = {
|
|
126
|
+
...omit(parseTransaction(serializedTransaction), 'data', 'sidecars'),
|
|
127
|
+
lastBlockTimestamp,
|
|
128
|
+
now,
|
|
129
|
+
maxInclusionTimeIntoSlot: delayer.maxInclusionTimeIntoSlot
|
|
130
|
+
};
|
|
131
|
+
if (now / 1000 - Number(lastBlockTimestamp) > delayer.maxInclusionTimeIntoSlot) {
|
|
132
|
+
// If the last block was mined more than `maxInclusionTimeIntoSlot` seconds ago, then we cannot include
|
|
133
|
+
// any txs in the current slot, so we delay the tx until the next slot.
|
|
134
|
+
logger.info(`Delaying inclusion of tx ${txHash} until the next slot since it was sent too late`, logData);
|
|
135
|
+
wait = waitUntilBlock(publicClient, number + 1n, logger);
|
|
136
|
+
} else {
|
|
137
|
+
logger.debug(`Immediately sending tx ${txHash} as it was received early enough in the slot`, logData);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (wait !== undefined) {
|
|
82
141
|
// Do not await here so we can return the tx hash immediately as if it had been sent on the spot.
|
|
83
142
|
// Instead, delay it so it lands on the desired block number or timestamp, assuming anvil will
|
|
84
143
|
// mine it immediately.
|
|
@@ -90,14 +149,14 @@ class DelayerImpl {
|
|
|
90
149
|
computedTxHash: txHash
|
|
91
150
|
});
|
|
92
151
|
}
|
|
93
|
-
logger.info(`Sent previously delayed tx ${clientTxHash}
|
|
94
|
-
delayer.
|
|
152
|
+
logger.info(`Sent previously delayed tx ${clientTxHash}`);
|
|
153
|
+
delayer.sentTxHashes.push(clientTxHash);
|
|
95
154
|
}).catch((err)=>logger.error(`Error sending tx after delay`, err));
|
|
96
155
|
return Promise.resolve(txHash);
|
|
97
156
|
} else {
|
|
98
157
|
const txHash = await client.sendRawTransaction(...args);
|
|
99
158
|
logger.verbose(`Sent tx immediately ${txHash}`);
|
|
100
|
-
delayer.
|
|
159
|
+
delayer.sentTxHashes.push(txHash);
|
|
101
160
|
return txHash;
|
|
102
161
|
}
|
|
103
162
|
}
|
|
@@ -114,3 +173,20 @@ class DelayerImpl {
|
|
|
114
173
|
delayer
|
|
115
174
|
};
|
|
116
175
|
}
|
|
176
|
+
/**
|
|
177
|
+
* Compute the tx hash given the serialized tx. Note that if this is a blob tx, we need to
|
|
178
|
+
* exclude the blobs, commitments, and proofs from the hash.
|
|
179
|
+
*/ function computeTxHash(serializedTransaction) {
|
|
180
|
+
if (serializedTransaction.startsWith('0x03')) {
|
|
181
|
+
const parsed = parseTransaction(serializedTransaction);
|
|
182
|
+
if (parsed.blobs || parsed.sidecars) {
|
|
183
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
184
|
+
const { blobs, sidecars, ...rest } = parsed;
|
|
185
|
+
return keccak256(serializeTransaction({
|
|
186
|
+
type: 'eip4844',
|
|
187
|
+
...rest
|
|
188
|
+
}));
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return keccak256(serializedTransaction);
|
|
192
|
+
}
|
|
@@ -2,10 +2,11 @@ import type { Logger } from '@aztec/foundation/log';
|
|
|
2
2
|
import { GovernanceAbi } from '@aztec/l1-artifacts/GovernanceAbi';
|
|
3
3
|
import { type GetContractReturnType, type PrivateKeyAccount } from 'viem';
|
|
4
4
|
import type { L1ContractAddresses } from '../l1_contract_addresses.js';
|
|
5
|
-
import type {
|
|
6
|
-
export declare function executeGovernanceProposal(proposalId: bigint, governance: GetContractReturnType<typeof GovernanceAbi,
|
|
7
|
-
export declare function createGovernanceProposal(payloadAddress: `0x${string}`, addresses: L1ContractAddresses, privateKey: PrivateKeyAccount, publicClient:
|
|
8
|
-
governance: GetContractReturnType<typeof GovernanceAbi,
|
|
5
|
+
import type { ExtendedViemWalletClient, ViemPublicClient } from '../types.js';
|
|
6
|
+
export declare function executeGovernanceProposal(proposalId: bigint, governance: GetContractReturnType<typeof GovernanceAbi, ViemPublicClient>, voteAmount: bigint, privateKey: PrivateKeyAccount, l1Client: ExtendedViemWalletClient, rpcUrls: string[], logger: Logger): Promise<void>;
|
|
7
|
+
export declare function createGovernanceProposal(payloadAddress: `0x${string}`, addresses: L1ContractAddresses, privateKey: PrivateKeyAccount, publicClient: ViemPublicClient, logger: Logger): Promise<{
|
|
8
|
+
governance: GetContractReturnType<typeof GovernanceAbi, ViemPublicClient>;
|
|
9
9
|
voteAmount: bigint;
|
|
10
|
+
proposalId: bigint;
|
|
10
11
|
}>;
|
|
11
12
|
//# sourceMappingURL=upgrade_utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upgrade_utils.d.ts","sourceRoot":"","sources":["../../src/test/upgrade_utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAEpD,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"upgrade_utils.d.ts","sourceRoot":"","sources":["../../src/test/upgrade_utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAEpD,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAGlE,OAAO,EAAE,KAAK,qBAAqB,EAAE,KAAK,iBAAiB,EAAe,MAAM,MAAM,CAAC;AAGvF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAEvE,OAAO,KAAK,EAAE,wBAAwB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAG9E,wBAAsB,yBAAyB,CAC7C,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,qBAAqB,CAAC,OAAO,aAAa,EAAE,gBAAgB,CAAC,EACzE,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,iBAAiB,EAC7B,QAAQ,EAAE,wBAAwB,EAClC,OAAO,EAAE,MAAM,EAAE,EACjB,MAAM,EAAE,MAAM,iBAmCf;AAED,wBAAsB,wBAAwB,CAC5C,cAAc,EAAE,KAAK,MAAM,EAAE,EAC7B,SAAS,EAAE,mBAAmB,EAC9B,UAAU,EAAE,iBAAiB,EAC7B,YAAY,EAAE,gBAAgB,EAC9B,MAAM,EAAE,MAAM,GACb,OAAO,CAAC;IACT,UAAU,EAAE,qBAAqB,CAAC,OAAO,aAAa,EAAE,gBAAgB,CAAC,CAAC;IAC1E,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC,CAyCD"}
|