@aztec/ethereum 0.0.1-commit.b655e406 → 0.0.1-commit.fce3e4f
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 +13 -7
- 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 +70 -65
- 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 +7 -6
- package/dest/contracts/tally_slashing_proposer.d.ts.map +1 -1
- package/dest/contracts/tally_slashing_proposer.js +3 -3
- package/dest/contracts/utils.d.ts +1 -1
- package/dest/deploy_l1_contracts.d.ts +455 -8
- package/dest/deploy_l1_contracts.d.ts.map +1 -1
- package/dest/deploy_l1_contracts.js +51 -33
- package/dest/eth-signer/eth-signer.d.ts +1 -1
- package/dest/eth-signer/index.d.ts +1 -1
- package/dest/index.d.ts +1 -1
- package/dest/l1_artifacts.d.ts +2020 -860
- package/dest/l1_artifacts.d.ts.map +1 -1
- package/dest/l1_contract_addresses.d.ts +3 -3
- package/dest/l1_reader.d.ts +1 -1
- package/dest/l1_tx_utils/config.d.ts +3 -3
- package/dest/l1_tx_utils/config.d.ts.map +1 -1
- package/dest/l1_tx_utils/config.js +13 -4
- 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/index.d.ts +1 -1
- package/dest/l1_tx_utils/interfaces.d.ts +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_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 +16 -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 +3 -4
- 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 +21 -20
- package/dest/test/chain_monitor.d.ts.map +1 -1
- package/dest/test/chain_monitor.js +33 -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 +8 -2
- 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 +11 -10
- package/dest/test/rollup_cheat_codes.d.ts.map +1 -1
- package/dest/test/rollup_cheat_codes.js +36 -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/upgrade_utils.d.ts +1 -1
- package/dest/types.d.ts +1 -1
- package/dest/utils.d.ts +1 -1
- package/dest/utils.d.ts.map +1 -1
- package/dest/zkPassportVerifierAddress.d.ts +1 -1
- package/package.json +10 -9
- package/src/config.ts +16 -8
- 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 +71 -78
- package/src/contracts/tally_slashing_proposer.ts +8 -7
- package/src/deploy_l1_contracts.ts +55 -35
- package/src/l1_tx_utils/config.ts +9 -6
- package/src/l1_tx_utils/readonly_l1_tx_utils.ts +3 -4
- package/src/queries.ts +6 -3
- package/src/test/chain_monitor.ts +47 -47
- package/src/test/eth_cheat_codes.ts +7 -1
- package/src/test/rollup_cheat_codes.ts +37 -40
- package/src/test/start_anvil.ts +2 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { InboxContract, type RollupContract } from '@aztec/ethereum/contracts';
|
|
2
|
+
import { EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
3
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
4
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
5
|
import { promiseWithResolvers } from '@aztec/foundation/promise';
|
|
@@ -10,11 +11,11 @@ import type { ViemClient } from '../types.js';
|
|
|
10
11
|
|
|
11
12
|
export type ChainMonitorEventMap = {
|
|
12
13
|
'l1-block': [{ l1BlockNumber: number; timestamp: bigint }];
|
|
13
|
-
|
|
14
|
-
'
|
|
14
|
+
checkpoint: [{ checkpointNumber: number; l1BlockNumber: number; l2SlotNumber: SlotNumber; timestamp: bigint }];
|
|
15
|
+
'checkpoint-proven': [{ provenCheckpointNumber: number; l1BlockNumber: number; timestamp: bigint }];
|
|
15
16
|
'l2-messages': [{ totalL2Messages: number; l1BlockNumber: number }];
|
|
16
|
-
'l2-epoch': [{ l2EpochNumber:
|
|
17
|
-
'l2-slot': [{ l2SlotNumber:
|
|
17
|
+
'l2-epoch': [{ l2EpochNumber: EpochNumber; timestamp: bigint; committee: EthAddress[] | undefined }];
|
|
18
|
+
'l2-slot': [{ l2SlotNumber: SlotNumber; timestamp: bigint }];
|
|
18
19
|
};
|
|
19
20
|
|
|
20
21
|
/** Utility class that polls the chain on quick intervals and logs new L1 blocks, L2 blocks, and L2 proofs. */
|
|
@@ -27,20 +28,20 @@ export class ChainMonitor extends EventEmitter<ChainMonitorEventMap> {
|
|
|
27
28
|
|
|
28
29
|
/** Current L1 block number */
|
|
29
30
|
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
|
|
31
|
+
/** Current checkpoint number */
|
|
32
|
+
public checkpointNumber!: number;
|
|
33
|
+
/** Current proven checkpoint number */
|
|
34
|
+
public provenCheckpointNumber!: number;
|
|
35
|
+
/** L1 timestamp for the current checkpoint */
|
|
36
|
+
public checkpointTimestamp!: bigint;
|
|
37
|
+
/** L1 timestamp for the proven checkpoint */
|
|
38
|
+
public provenCheckpointTimestamp!: bigint;
|
|
38
39
|
/** Total number of L2 messages pushed into the Inbox */
|
|
39
40
|
public totalL2Messages: number = 0;
|
|
40
41
|
/** Current L2 epoch number */
|
|
41
|
-
public l2EpochNumber!:
|
|
42
|
+
public l2EpochNumber!: EpochNumber;
|
|
42
43
|
/** Current L2 slot number */
|
|
43
|
-
public l2SlotNumber!:
|
|
44
|
+
public l2SlotNumber!: SlotNumber;
|
|
44
45
|
|
|
45
46
|
constructor(
|
|
46
47
|
private readonly rollup: RollupContract,
|
|
@@ -114,28 +115,28 @@ export class ChainMonitor extends EventEmitter<ChainMonitorEventMap> {
|
|
|
114
115
|
this.emit('l1-block', { l1BlockNumber: newL1BlockNumber, timestamp });
|
|
115
116
|
let msg = `L1 block ${newL1BlockNumber} mined at ${timestampString}`;
|
|
116
117
|
|
|
117
|
-
const
|
|
118
|
-
if (this.
|
|
119
|
-
const epochNumber = await this.rollup.
|
|
120
|
-
msg += ` with new
|
|
121
|
-
this.
|
|
122
|
-
this.
|
|
123
|
-
this.emit('
|
|
124
|
-
|
|
118
|
+
const newCheckpointNumber = Number(await this.rollup.getCheckpointNumber());
|
|
119
|
+
if (this.checkpointNumber !== newCheckpointNumber) {
|
|
120
|
+
const epochNumber = await this.rollup.getEpochNumberForCheckpoint(BigInt(newCheckpointNumber));
|
|
121
|
+
msg += ` with new checkpoint ${newCheckpointNumber} for epoch ${epochNumber}`;
|
|
122
|
+
this.checkpointNumber = newCheckpointNumber;
|
|
123
|
+
this.checkpointTimestamp = timestamp;
|
|
124
|
+
this.emit('checkpoint', {
|
|
125
|
+
checkpointNumber: newCheckpointNumber,
|
|
125
126
|
l1BlockNumber: newL1BlockNumber,
|
|
126
|
-
l2SlotNumber
|
|
127
|
+
l2SlotNumber,
|
|
127
128
|
timestamp,
|
|
128
129
|
});
|
|
129
130
|
}
|
|
130
131
|
|
|
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
|
-
|
|
132
|
+
const newProvenCheckpointNumber = Number(await this.rollup.getProvenCheckpointNumber());
|
|
133
|
+
if (this.provenCheckpointNumber !== newProvenCheckpointNumber) {
|
|
134
|
+
const epochNumber = await this.rollup.getEpochNumberForCheckpoint(BigInt(newProvenCheckpointNumber));
|
|
135
|
+
msg += ` with proof up to checkpoint ${newProvenCheckpointNumber} for epoch ${epochNumber}`;
|
|
136
|
+
this.provenCheckpointNumber = newProvenCheckpointNumber;
|
|
137
|
+
this.provenCheckpointTimestamp = timestamp;
|
|
138
|
+
this.emit('checkpoint-proven', {
|
|
139
|
+
provenCheckpointNumber: newProvenCheckpointNumber,
|
|
139
140
|
l1BlockNumber: newL1BlockNumber,
|
|
140
141
|
timestamp,
|
|
141
142
|
});
|
|
@@ -153,13 +154,13 @@ export class ChainMonitor extends EventEmitter<ChainMonitorEventMap> {
|
|
|
153
154
|
if (l2Epoch !== this.l2EpochNumber) {
|
|
154
155
|
this.l2EpochNumber = l2Epoch;
|
|
155
156
|
committee = (await this.rollup.getCurrentEpochCommittee())?.map(addr => EthAddress.fromString(addr));
|
|
156
|
-
this.emit('l2-epoch', { l2EpochNumber:
|
|
157
|
+
this.emit('l2-epoch', { l2EpochNumber: l2Epoch, timestamp, committee });
|
|
157
158
|
msg += ` starting new epoch ${this.l2EpochNumber} `;
|
|
158
159
|
}
|
|
159
160
|
|
|
160
161
|
if (l2SlotNumber !== this.l2SlotNumber) {
|
|
161
162
|
this.l2SlotNumber = l2SlotNumber;
|
|
162
|
-
this.emit('l2-slot', { l2SlotNumber
|
|
163
|
+
this.emit('l2-slot', { l2SlotNumber, timestamp });
|
|
163
164
|
}
|
|
164
165
|
|
|
165
166
|
this.logger.info(msg, {
|
|
@@ -168,8 +169,8 @@ export class ChainMonitor extends EventEmitter<ChainMonitorEventMap> {
|
|
|
168
169
|
l1BlockNumber: this.l1BlockNumber,
|
|
169
170
|
l2SlotNumber,
|
|
170
171
|
l2Epoch,
|
|
171
|
-
|
|
172
|
-
|
|
172
|
+
checkpointNumber: this.checkpointNumber,
|
|
173
|
+
provenCheckpointNumber: this.provenCheckpointNumber,
|
|
173
174
|
totalL2Messages: this.totalL2Messages,
|
|
174
175
|
committee,
|
|
175
176
|
});
|
|
@@ -177,14 +178,13 @@ export class ChainMonitor extends EventEmitter<ChainMonitorEventMap> {
|
|
|
177
178
|
return this;
|
|
178
179
|
}
|
|
179
180
|
|
|
180
|
-
public waitUntilL2Slot(slot:
|
|
181
|
-
|
|
182
|
-
if (this.l2SlotNumber >= targetSlot) {
|
|
181
|
+
public waitUntilL2Slot(slot: SlotNumber): Promise<void> {
|
|
182
|
+
if (this.l2SlotNumber >= slot) {
|
|
183
183
|
return Promise.resolve();
|
|
184
184
|
}
|
|
185
185
|
return new Promise(resolve => {
|
|
186
|
-
const listener = (data: { l2SlotNumber:
|
|
187
|
-
if (data.l2SlotNumber >=
|
|
186
|
+
const listener = (data: { l2SlotNumber: SlotNumber; timestamp: bigint }) => {
|
|
187
|
+
if (data.l2SlotNumber >= slot) {
|
|
188
188
|
this.off('l2-slot', listener);
|
|
189
189
|
resolve();
|
|
190
190
|
}
|
|
@@ -225,19 +225,19 @@ export class ChainMonitor extends EventEmitter<ChainMonitorEventMap> {
|
|
|
225
225
|
});
|
|
226
226
|
}
|
|
227
227
|
|
|
228
|
-
public
|
|
229
|
-
const targetBlock = typeof
|
|
230
|
-
if (this.
|
|
228
|
+
public waitUntilCheckpoint(checkpointNumber: number | bigint): Promise<void> {
|
|
229
|
+
const targetBlock = typeof checkpointNumber === 'bigint' ? checkpointNumber.valueOf() : checkpointNumber;
|
|
230
|
+
if (this.checkpointNumber >= targetBlock) {
|
|
231
231
|
return Promise.resolve();
|
|
232
232
|
}
|
|
233
233
|
return new Promise(resolve => {
|
|
234
|
-
const listener = (data: {
|
|
235
|
-
if (data.
|
|
236
|
-
this.off('
|
|
234
|
+
const listener = (data: { checkpointNumber: number; timestamp: bigint }) => {
|
|
235
|
+
if (data.checkpointNumber >= targetBlock) {
|
|
236
|
+
this.off('checkpoint', listener);
|
|
237
237
|
resolve();
|
|
238
238
|
}
|
|
239
239
|
};
|
|
240
|
-
this.on('
|
|
240
|
+
this.on('checkpoint', listener);
|
|
241
241
|
});
|
|
242
242
|
}
|
|
243
243
|
}
|
|
@@ -6,7 +6,8 @@ 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
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { RollupContract, type ViemPublicClient } from '@aztec/ethereum';
|
|
2
2
|
import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
|
|
3
|
+
import { EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
3
4
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
4
5
|
import { createLogger } from '@aztec/foundation/log';
|
|
5
6
|
import type { DateProvider } from '@aztec/foundation/timer';
|
|
@@ -14,7 +15,6 @@ import {
|
|
|
14
15
|
hexToBigInt,
|
|
15
16
|
http,
|
|
16
17
|
} from 'viem';
|
|
17
|
-
import { foundry } from 'viem/chains';
|
|
18
18
|
|
|
19
19
|
import { EthCheatCodes } from './eth_cheat_codes.js';
|
|
20
20
|
|
|
@@ -30,7 +30,7 @@ export class RollupCheatCodes {
|
|
|
30
30
|
addresses: Pick<L1ContractAddresses, 'rollupAddress'>,
|
|
31
31
|
) {
|
|
32
32
|
this.client = createPublicClient({
|
|
33
|
-
chain:
|
|
33
|
+
chain: ethCheatCodes.chain,
|
|
34
34
|
transport: fallback(ethCheatCodes.rpcUrls.map(url => http(url))),
|
|
35
35
|
});
|
|
36
36
|
this.rollup = getContract({
|
|
@@ -50,15 +50,15 @@ export class RollupCheatCodes {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
/** Returns the current slot */
|
|
53
|
-
public async getSlot() {
|
|
53
|
+
public async getSlot(): Promise<SlotNumber> {
|
|
54
54
|
const ts = BigInt((await this.client.getBlock()).timestamp);
|
|
55
|
-
return await this.rollup.read.getSlotAt([ts]);
|
|
55
|
+
return SlotNumber.fromBigInt(await this.rollup.read.getSlotAt([ts]));
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
/** Returns the current epoch */
|
|
59
|
-
public async getEpoch() {
|
|
59
|
+
public async getEpoch(): Promise<EpochNumber> {
|
|
60
60
|
const slotNumber = await this.getSlot();
|
|
61
|
-
return await this.rollup.read.getEpochAtSlot([slotNumber]);
|
|
61
|
+
return EpochNumber.fromBigInt(await this.rollup.read.getEpochAtSlot([BigInt(slotNumber)]));
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
/**
|
|
@@ -69,11 +69,7 @@ export class RollupCheatCodes {
|
|
|
69
69
|
/** The pending chain tip */ pending: bigint;
|
|
70
70
|
/** The proven chain tip */ proven: bigint;
|
|
71
71
|
}> {
|
|
72
|
-
|
|
73
|
-
return {
|
|
74
|
-
pending: res.pendingBlockNumber,
|
|
75
|
-
proven: res.provenBlockNumber,
|
|
76
|
-
};
|
|
72
|
+
return await this.rollup.read.getTips();
|
|
77
73
|
}
|
|
78
74
|
|
|
79
75
|
/**
|
|
@@ -81,16 +77,16 @@ export class RollupCheatCodes {
|
|
|
81
77
|
*/
|
|
82
78
|
public async debugRollup() {
|
|
83
79
|
const rollup = new RollupContract(this.client, this.rollup.address);
|
|
84
|
-
const pendingNum = await rollup.
|
|
85
|
-
const provenNum = await rollup.
|
|
80
|
+
const pendingNum = await rollup.getCheckpointNumber();
|
|
81
|
+
const provenNum = await rollup.getProvenCheckpointNumber();
|
|
86
82
|
const validators = await rollup.getAttesters();
|
|
87
83
|
const committee = await rollup.getCurrentEpochCommittee();
|
|
88
84
|
const archive = await rollup.archive();
|
|
89
85
|
const slot = await this.getSlot();
|
|
90
86
|
const epochNum = await rollup.getEpochNumberForSlotNumber(slot);
|
|
91
87
|
|
|
92
|
-
this.logger.info(`Pending
|
|
93
|
-
this.logger.info(`Proven
|
|
88
|
+
this.logger.info(`Pending checkpoint num: ${pendingNum}`);
|
|
89
|
+
this.logger.info(`Proven checkpoint num: ${provenNum}`);
|
|
94
90
|
this.logger.info(`Validators: ${validators.map(v => v.toString()).join(', ')}`);
|
|
95
91
|
this.logger.info(`Committee: ${committee?.map(v => v.toString()).join(', ')}`);
|
|
96
92
|
this.logger.info(`Archive: ${archive}`);
|
|
@@ -101,13 +97,13 @@ export class RollupCheatCodes {
|
|
|
101
97
|
/** Fetches the epoch and slot duration config from the rollup contract */
|
|
102
98
|
public async getConfig(): Promise<{
|
|
103
99
|
/** Epoch duration */ epochDuration: bigint;
|
|
104
|
-
/** Slot duration */ slotDuration:
|
|
100
|
+
/** Slot duration */ slotDuration: number;
|
|
105
101
|
}> {
|
|
106
102
|
const [epochDuration, slotDuration] = await Promise.all([
|
|
107
103
|
this.rollup.read.getEpochDuration(),
|
|
108
104
|
this.rollup.read.getSlotDuration(),
|
|
109
105
|
]);
|
|
110
|
-
return { epochDuration, slotDuration };
|
|
106
|
+
return { epochDuration, slotDuration: Number(slotDuration) };
|
|
111
107
|
}
|
|
112
108
|
|
|
113
109
|
/**
|
|
@@ -116,15 +112,15 @@ export class RollupCheatCodes {
|
|
|
116
112
|
* @param opts - Options
|
|
117
113
|
*/
|
|
118
114
|
public async advanceToEpoch(
|
|
119
|
-
epoch:
|
|
115
|
+
epoch: EpochNumber,
|
|
120
116
|
opts: {
|
|
121
117
|
/** Offset in seconds */
|
|
122
118
|
offset?: number;
|
|
123
119
|
} = {},
|
|
124
120
|
) {
|
|
125
121
|
const { epochDuration: slotsInEpoch } = await this.getConfig();
|
|
126
|
-
const
|
|
127
|
-
|
|
122
|
+
const slotNumber = SlotNumber(epoch * Number(slotsInEpoch));
|
|
123
|
+
const timestamp = (await this.rollup.read.getTimestampForSlot([BigInt(slotNumber)])) + BigInt(opts.offset ?? 0);
|
|
128
124
|
try {
|
|
129
125
|
await this.ethCheatCodes.warp(Number(timestamp), { ...opts, silent: true, resetBlockInterval: true });
|
|
130
126
|
this.logger.warn(`Warped to epoch ${epoch}`);
|
|
@@ -138,8 +134,8 @@ export class RollupCheatCodes {
|
|
|
138
134
|
public async advanceToNextEpoch() {
|
|
139
135
|
const slot = await this.getSlot();
|
|
140
136
|
const { epochDuration, slotDuration } = await this.getConfig();
|
|
141
|
-
const slotsUntilNextEpoch = epochDuration - (slot % epochDuration) + 1n;
|
|
142
|
-
const timeToNextEpoch = slotsUntilNextEpoch * slotDuration;
|
|
137
|
+
const slotsUntilNextEpoch = epochDuration - (BigInt(slot) % epochDuration) + 1n;
|
|
138
|
+
const timeToNextEpoch = slotsUntilNextEpoch * BigInt(slotDuration);
|
|
143
139
|
const l1Timestamp = BigInt((await this.client.getBlock()).timestamp);
|
|
144
140
|
await this.ethCheatCodes.warp(Number(l1Timestamp + timeToNextEpoch), {
|
|
145
141
|
silent: true,
|
|
@@ -151,10 +147,11 @@ export class RollupCheatCodes {
|
|
|
151
147
|
/** Warps time in L1 until the beginning of the next slot. */
|
|
152
148
|
public async advanceToNextSlot() {
|
|
153
149
|
const currentSlot = await this.getSlot();
|
|
154
|
-
const
|
|
150
|
+
const nextSlot = SlotNumber(currentSlot + 1);
|
|
151
|
+
const timestamp = await this.rollup.read.getTimestampForSlot([BigInt(nextSlot)]);
|
|
155
152
|
await this.ethCheatCodes.warp(Number(timestamp), { silent: true, resetBlockInterval: true });
|
|
156
|
-
this.logger.warn(`Advanced to slot ${
|
|
157
|
-
return [timestamp,
|
|
153
|
+
this.logger.warn(`Advanced to slot ${nextSlot}`);
|
|
154
|
+
return [timestamp, nextSlot];
|
|
158
155
|
}
|
|
159
156
|
|
|
160
157
|
/**
|
|
@@ -163,42 +160,42 @@ export class RollupCheatCodes {
|
|
|
163
160
|
*/
|
|
164
161
|
public async advanceSlots(howMany: number) {
|
|
165
162
|
const l1Timestamp = (await this.client.getBlock()).timestamp;
|
|
166
|
-
const slotDuration = await this.rollup.read.getSlotDuration();
|
|
167
|
-
const timeToWarp = BigInt(howMany) * slotDuration;
|
|
163
|
+
const slotDuration = Number(await this.rollup.read.getSlotDuration());
|
|
164
|
+
const timeToWarp = BigInt(howMany) * BigInt(slotDuration);
|
|
168
165
|
await this.ethCheatCodes.warp(l1Timestamp + timeToWarp, { silent: true, resetBlockInterval: true });
|
|
169
166
|
const [slot, epoch] = await Promise.all([this.getSlot(), this.getEpoch()]);
|
|
170
167
|
this.logger.warn(`Advanced ${howMany} slots up to slot ${slot} in epoch ${epoch}`);
|
|
171
168
|
}
|
|
172
169
|
|
|
173
170
|
/**
|
|
174
|
-
* Marks the specified
|
|
175
|
-
* @param
|
|
171
|
+
* Marks the specified checkpoint (or latest if none) as proven
|
|
172
|
+
* @param maybeCheckpointNumber - The checkpoint number to mark as proven (defaults to latest pending)
|
|
176
173
|
*/
|
|
177
|
-
public markAsProven(
|
|
174
|
+
public markAsProven(maybeCheckpointNumber?: number | bigint) {
|
|
178
175
|
return this.ethCheatCodes.execWithPausedAnvil(async () => {
|
|
179
176
|
const tipsBefore = await this.getTips();
|
|
180
177
|
const { pending, proven } = tipsBefore;
|
|
181
178
|
|
|
182
|
-
let
|
|
183
|
-
if (
|
|
184
|
-
|
|
179
|
+
let checkpointNumber = maybeCheckpointNumber;
|
|
180
|
+
if (checkpointNumber === undefined || checkpointNumber > pending) {
|
|
181
|
+
checkpointNumber = pending;
|
|
185
182
|
}
|
|
186
|
-
if (
|
|
187
|
-
this.logger.debug(`
|
|
183
|
+
if (checkpointNumber <= proven) {
|
|
184
|
+
this.logger.debug(`Checkpoint ${checkpointNumber} is already proven`);
|
|
188
185
|
return;
|
|
189
186
|
}
|
|
190
187
|
|
|
191
188
|
// @note @LHerskind this is heavily dependent on the storage layout and size of values
|
|
192
189
|
// The rollupStore is a struct and if the size of elements or the struct changes, this can break
|
|
193
|
-
const
|
|
190
|
+
const provenCheckpointNumberSlot = hexToBigInt(RollupContract.stfStorageSlot);
|
|
194
191
|
|
|
195
192
|
// Need to pack it as a single 32 byte word
|
|
196
|
-
const newValue = (BigInt(tipsBefore.pending) << 128n) | BigInt(
|
|
197
|
-
await this.ethCheatCodes.store(EthAddress.fromString(this.rollup.address),
|
|
193
|
+
const newValue = (BigInt(tipsBefore.pending) << 128n) | BigInt(checkpointNumber);
|
|
194
|
+
await this.ethCheatCodes.store(EthAddress.fromString(this.rollup.address), provenCheckpointNumberSlot, newValue);
|
|
198
195
|
|
|
199
196
|
const tipsAfter = await this.getTips();
|
|
200
197
|
if (tipsAfter.pending < tipsAfter.proven) {
|
|
201
|
-
throw new Error('Overwrote pending tip to a
|
|
198
|
+
throw new Error('Overwrote pending tip to a checkpoint in the past');
|
|
202
199
|
}
|
|
203
200
|
|
|
204
201
|
this.logger.info(
|
|
@@ -209,7 +206,7 @@ export class RollupCheatCodes {
|
|
|
209
206
|
|
|
210
207
|
/**
|
|
211
208
|
* Overrides the inProgress field of the Inbox contract state
|
|
212
|
-
* @param howMuch - How many
|
|
209
|
+
* @param howMuch - How many checkpoints to move it forward
|
|
213
210
|
*/
|
|
214
211
|
public advanceInboxInProgress(howMuch: number | bigint): Promise<bigint> {
|
|
215
212
|
return this.ethCheatCodes.execWithPausedAnvil(async () => {
|
package/src/test/start_anvil.ts
CHANGED
|
@@ -15,6 +15,7 @@ export async function startAnvil(
|
|
|
15
15
|
log?: boolean;
|
|
16
16
|
captureMethodCalls?: boolean;
|
|
17
17
|
accounts?: number;
|
|
18
|
+
chainId?: number;
|
|
18
19
|
} = {},
|
|
19
20
|
): Promise<{ anvil: Anvil; methodCalls?: string[]; rpcUrl: string; stop: () => Promise<void> }> {
|
|
20
21
|
const anvilBinary = resolve(dirname(fileURLToPath(import.meta.url)), '../../', 'scripts/anvil_kill_wrapper.sh');
|
|
@@ -35,6 +36,7 @@ export async function startAnvil(
|
|
|
35
36
|
stopTimeout: 1000,
|
|
36
37
|
accounts: opts.accounts ?? 20,
|
|
37
38
|
gasLimit: 45_000_000n,
|
|
39
|
+
chainId: opts.chainId ?? 31337,
|
|
38
40
|
});
|
|
39
41
|
|
|
40
42
|
// Listen to the anvil output to get the port.
|