Skip to content

Commit

Permalink
Added script for sharding table cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
u-hubar committed Mar 8, 2024
1 parent 7d0db0b commit c2b593a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { lazyObject } from 'hardhat/plugins';
import { HardhatRuntimeEnvironment } from 'hardhat/types';

import './tasks/address_converter';
import './tasks/clear_sharding_table';
import './tasks/deploy_test_token';
import './tasks/low_level_call_data_encoder';
import './tasks/mint_test_tokens';
Expand Down
42 changes: 42 additions & 0 deletions tasks/clear_sharding_table.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import fs from 'fs/promises';

import { task } from 'hardhat/config';
import { HardhatRuntimeEnvironment } from 'hardhat/types';

type ConverterParameters = {
filePath: string;
};

task('clear_sharding_table', 'Removed nodes from sharding table by node IDs from the CSV file')
.addParam<string>('filePath', 'Path to CSV file with Node IDs')
.setAction(async (taskArgs: ConverterParameters, hre: HardhatRuntimeEnvironment) => {
const { filePath } = taskArgs;

let nodeIdsToDelete: string[];
try {
const data = await fs.readFile(filePath, 'utf8');
nodeIdsToDelete = data
.trim()
.split('\n')
.map((row) => row.split(',')[0]);
} catch (err) {
console.error(err);
nodeIdsToDelete = [];
}

const ShardingTableABI = hre.helpers.getAbi('ShardingTable');
const shardingTableAddress = hre.helpers.contractDeployments.contracts['ShardingTable'].evmAddress;
const ShardingTable = await hre.ethers.getContractAt(ShardingTableABI, shardingTableAddress);

const table = await ShardingTable['getShardingTable()']();

for (const node of table) {
const nodeIdString = hre.ethers.utils.toUtf8String(node.nodeId);

if (nodeIdsToDelete.includes(nodeIdString)) {
console.log(`Deleting node with identityId: ${node.identityId}`);

await ShardingTable.removeNode(node.identityId);
}
}
});

0 comments on commit c2b593a

Please sign in to comment.