Skip to content

Commit 8c93dc3

Browse files
committed
clean up
1 parent 9d5f03f commit 8c93dc3

File tree

2 files changed

+12
-20
lines changed

2 files changed

+12
-20
lines changed

src/decorators/rollupAdminLogicPublicActions.integration.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ it('successfully set validators', async () => {
3131
rollup: l3Rollup,
3232
},
3333
);
34-
expect(initialValidators).toHaveLength(10);
34+
// By default, chains from nitro testnode has 11 validators
35+
// https://github.com/OffchainLabs/nitro-testnode/blob/de8cf4edec0d12e5ef1b7623e54e35ddb579ff0b/test-node.bash#L634
36+
// https://github.com/OffchainLabs/nitro-contracts/blob/47a9c034bc082256d498f8031fab1a37c37a123c/scripts/rollupCreation.ts#L250-L257
37+
expect(initialValidators).toHaveLength(11);
3538
expect(isAccurateInitially).toBeTruthy();
3639

3740
const tx = await client.rollupAdminLogicPrepareTransactionRequest({

src/getValidators.ts

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
getFunctionSelector,
1010
} from 'viem';
1111

12-
import { rollupCreatorABI as rollupCreatorV3Dot1ABI } from './contracts/RollupCreator';
1312
import { rollupCreatorABI as rollupCreatorV2Dot1ABI } from './contracts/RollupCreator/v2.1';
1413
import { rollupCreatorABI as rollupCreatorV1Dot1ABI } from './contracts/RollupCreator/v1.1';
1514
import { upgradeExecutorABI } from './contracts/UpgradeExecutor';
@@ -20,17 +19,12 @@ import { rollupABI as rollupV2Dot1ABI } from './contracts/Rollup/v2.1';
2019
import { createRollupFetchTransactionHash } from './createRollupFetchTransactionHash';
2120
import { getLogsWithBatching } from './utils/getLogsWithBatching';
2221

23-
const createRollupV3Dot1ABI = getAbiItem({ abi: rollupCreatorV3Dot1ABI, name: 'createRollup' });
24-
const createRollupV3Dot1FunctionSelector = getFunctionSelector(createRollupV3Dot1ABI);
25-
2622
const createRollupV2Dot1ABI = getAbiItem({ abi: rollupCreatorV2Dot1ABI, name: 'createRollup' });
2723
const createRollupV2Dot1FunctionSelector = getFunctionSelector(createRollupV2Dot1ABI);
2824

2925
const createRollupV1Dot1ABI = getAbiItem({ abi: rollupCreatorV1Dot1ABI, name: 'createRollup' });
3026
const createRollupV1Dot1FunctionSelector = getFunctionSelector(createRollupV1Dot1ABI);
3127

32-
const setValidatorV3Dot1ABI = getAbiItem({ abi: rollupV3Dot1ABI, name: 'setValidator' });
33-
3428
const setValidatorPreV3Dot1ABI = getAbiItem({ abi: rollupV2Dot1ABI, name: 'setValidator' });
3529
const setValidatorPreV3Dot1FunctionSelector = getFunctionSelector(setValidatorPreV3Dot1ABI);
3630

@@ -49,10 +43,9 @@ const validatorsSetEventAbi = getAbiItem({ abi: rollupV3Dot1ABI, name: 'Validato
4943

5044
function getValidatorsFromFunctionData<
5145
TAbi extends
52-
| (typeof createRollupV3Dot1ABI)[]
5346
| (typeof createRollupV2Dot1ABI)[]
5447
| (typeof createRollupV1Dot1ABI)[]
55-
| (typeof setValidatorV3Dot1ABI)[],
48+
| (typeof setValidatorPreV3Dot1ABI)[],
5649
>({ abi, data }: { abi: TAbi; data: Hex }) {
5750
const { args } = decodeFunctionData({
5851
abi,
@@ -86,7 +79,7 @@ function iterateThroughValidatorsList(
8679

8780
function updateAccumulator(acc: Set<Address>, input: Hex) {
8881
const [validators, enabled] = getValidatorsFromFunctionData({
89-
abi: [setValidatorV3Dot1ABI],
82+
abi: [setValidatorPreV3Dot1ABI],
9083
data: input,
9184
});
9285

@@ -166,7 +159,11 @@ export async function getValidators<TChain extends Chain>(
166159
return iterateThroughValidatorsList(acc, _validators, _enabled);
167160
}, new Set<Address>());
168161

169-
const txs = await Promise.all(
162+
/** For pre v3.1, the OwnerFunctionCalled event is emitted when the validators list is updated
163+
* the event is emitted without the validators list and the new states in the event args
164+
* so we have to grab the tx and decode the calldata to get the validators list
165+
*/
166+
const preV3Dot1Txs = await Promise.all(
170167
preV3Dot1Events.map((event) =>
171168
publicClient.getTransaction({
172169
hash: event.transactionHash,
@@ -175,18 +172,10 @@ export async function getValidators<TChain extends Chain>(
175172
);
176173

177174
let isAccurate = true;
178-
const validators = txs.reduce((acc, tx) => {
175+
const validators = preV3Dot1Txs.reduce((acc, tx) => {
179176
const txSelectedFunction = tx.input.slice(0, 10);
180177

181178
switch (txSelectedFunction) {
182-
case createRollupV3Dot1FunctionSelector: {
183-
const [{ validators }] = getValidatorsFromFunctionData({
184-
abi: [createRollupV3Dot1ABI],
185-
data: tx.input,
186-
});
187-
188-
return new Set([...acc, ...validators]);
189-
}
190179
case createRollupV2Dot1FunctionSelector: {
191180
const [{ validators }] = getValidatorsFromFunctionData({
192181
abi: [createRollupV2Dot1ABI],

0 commit comments

Comments
 (0)