Skip to content

Commit 068105e

Browse files
committed
script: split to chunk to reduce stress con rpc
1 parent 12db563 commit 068105e

File tree

1 file changed

+32
-27
lines changed

1 file changed

+32
-27
lines changed

script/operations/bulk-renew.mjs

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,38 +20,43 @@ console.log(`Current nonce: ${nonce}`);
2020
const account = wallet.address;
2121
const shouldSimulate = true;
2222
// Assert the list is unique
23-
if (new Set(renewList).size !== renewList.length) {
24-
console.error("List is not unique");
25-
process.exit(1);
26-
}
23+
// if (new Set(renewList).size !== renewList.length) {
24+
// console.error("List is not unique");
25+
// process.exit(1);
26+
// }
27+
const contract = new ethers.Contract(ronRegistrarControllerAddr, abi, provider);
28+
const chunkSize = 20;
2729

2830
async function bulkRenew() {
29-
const contract = new ethers.Contract(ronRegistrarControllerAddr, abi, provider);
31+
for (let i = 0; i < renewList.length; i += chunkSize) {
32+
const chunk = renewList.slice(i, i + chunkSize);
33+
console.log(`Processing chunk ${i / chunkSize + 1} - ${chunk.length} labels`);
3034

31-
const promises = renewList.map(async (label) => {
32-
if (shouldSimulate) {
33-
console.log(`nonce: ${nonce++}`);
34-
try {
35-
await contract.renew.staticCall(label, defaultRenewDuration, {
36-
from: account,
37-
});
38-
} catch (error) {
39-
console.error(`Failed to simulate renew for ${label} - ${defaultRenewDuration}`, error);
40-
}
41-
} else {
42-
console.log(`nonce: ${nonce}`);
43-
try {
44-
await contract.connect(wallet).renew(label, defaultRenewDuration, {
45-
nonce: nonce++,
46-
});
47-
console.log(`Renew for label ${label} - duration: ${defaultRenewDuration} success`);
48-
} catch (error) {
49-
console.error(`Failed to renew label ${label} - duration ${defaultRenewDuration}:`, error);
35+
const promises = chunk.map(async (label) => {
36+
if (shouldSimulate) {
37+
console.log(`nonce: ${nonce++}`);
38+
try {
39+
await contract.renew.staticCall(label, defaultRenewDuration, {
40+
from: account,
41+
});
42+
} catch (error) {
43+
console.error(`Failed to simulate renew for ${label} - ${defaultRenewDuration}`, error);
44+
}
45+
} else {
46+
console.log(`nonce: ${nonce}`);
47+
try {
48+
await contract.connect(wallet).renew(label, defaultRenewDuration, {
49+
nonce: nonce++,
50+
});
51+
console.log(`Renew for label ${label} - duration: ${defaultRenewDuration} success`);
52+
} catch (error) {
53+
console.error(`Failed to renew label ${label} - duration ${defaultRenewDuration}:`, error);
54+
}
5055
}
51-
}
52-
});
56+
});
5357

54-
await Promise.all(promises);
58+
await Promise.all(promises);
59+
}
5560
}
5661

5762
bulkRenew();

0 commit comments

Comments
 (0)