Skip to content

Commit dd3d9fe

Browse files
chore: adding check and retry mech for enabling big blocks
Ticket: WIN-6941
1 parent 7b2f709 commit dd3d9fe

File tree

4 files changed

+138
-22
lines changed

4 files changed

+138
-22
lines changed

config/bigBlocksConfig.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { CHAIN_IDS } from './chainIds';
22
const { HYPE_EVM_PRIVATE_KEY } = process.env;
3+
34
/**
45
* Configuration for a chain that supports BigBlocks
56
*/
@@ -10,6 +11,8 @@ export interface BigBlocksChainConfig {
1011
isTestnet: boolean;
1112
/** API URL for BigBlocks service */
1213
apiUrl: string;
14+
/** RPC URL for the network */
15+
rpcUrl: string;
1316
/** Chain ID for BigBlocks service */
1417
bigBlocksChainId: number;
1518
/** Environment variable key for private key */
@@ -26,13 +29,15 @@ export const BIGBLOCKS_SUPPORTED_CHAINS: Record<number, BigBlocksChainConfig> =
2629
name: 'HypeEVM mainnet',
2730
isTestnet: false,
2831
apiUrl: 'https://api.hyperliquid.xyz/exchange',
32+
rpcUrl: 'https://spectrum-01.simplystaking.xyz/hyperliquid-tn-rpc/evm',
2933
bigBlocksChainId: 1337,
3034
envKey: HYPE_EVM_PRIVATE_KEY
3135
},
3236
[CHAIN_IDS.HYPEEVM_TESTNET]: {
3337
name: 'HypeEVM Testnet',
3438
isTestnet: true,
3539
apiUrl: 'https://api.hyperliquid-testnet.xyz/exchange',
40+
rpcUrl: 'https://spectrum-01.simplystaking.xyz/hyperliquid-tn-rpc/evm',
3641
bigBlocksChainId: 1337,
3742
envKey: HYPE_EVM_PRIVATE_KEY
3843
}

scripts/chainConfig.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ export async function getChainConfig(chainId: number): Promise<ChainConfig> {
9999
case CHAIN_IDS.IRYS_TESTNET:
100100
case CHAIN_IDS.PHAROS:
101101
case CHAIN_IDS.PHAROS_TESTNET:
102-
case CHAIN_IDS.HYPEEVM:
103-
case CHAIN_IDS.HYPEEVM_TESTNET:
104102
case CHAIN_IDS.APECHAIN:
105103
case CHAIN_IDS.APECHAIN_TESTNET:
106104
case CHAIN_IDS.CORE_DAO:
@@ -117,7 +115,16 @@ export async function getChainConfig(chainId: number): Promise<ChainConfig> {
117115
forwarderContractName = 'ForwarderV4';
118116
forwarderFactoryContractName = 'ForwarderFactoryV4';
119117
break;
120-
118+
case CHAIN_IDS.HYPEEVM:
119+
case CHAIN_IDS.HYPEEVM_TESTNET:
120+
gasParams = {
121+
maxFeePerGas: 30_000_000_000n,
122+
maxPriorityFeePerGas: 30_000_000_000n,
123+
gasLimit: 3_000_000
124+
};
125+
forwarderContractName = 'ForwarderV4';
126+
forwarderFactoryContractName = 'ForwarderFactoryV4';
127+
break;
121128
case CHAIN_IDS.WORLD:
122129
case CHAIN_IDS.WORLD_TESTNET:
123130
gasParams = {

scripts/deploy.ts

Lines changed: 117 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,125 @@ const NONCE = {
2020
FORWARDER_FACTORY: 3
2121
};
2222

23+
// Add interface for JSON RPC response
24+
interface JsonRpcResponse {
25+
jsonrpc: string;
26+
id: number;
27+
result?: boolean;
28+
error?: {
29+
code: number;
30+
message: string;
31+
};
32+
}
33+
2334
/**
24-
* Configure BigBlocks for HypeEVM network
35+
* Check if BigBlocks is already enabled using RPC call
2536
*/
26-
async function setupBigBlocks(chainId: number): Promise<void> {
37+
async function checkBigBlocksStatus(userAddress: string, chainId: number): Promise<boolean> {
38+
const config = getBigBlocksConfig(chainId);
39+
if (!config) {
40+
throw new Error(`Chain with ID ${chainId} is not supported for BigBlocks.`);
41+
}
42+
console.log("Useradd" + userAddress);
43+
console.log(`Checking BigBlocks status for ${userAddress} on ${config.name}...`);
44+
console.log(`Making RPC call to: ${config.rpcUrl}`);
45+
try {
46+
const requestBody = {
47+
jsonrpc: '2.0',
48+
id: 0,
49+
method: 'eth_usingBigBlocks',
50+
params: [userAddress],
51+
};
52+
53+
const res = await fetch(config.rpcUrl, {
54+
method: 'POST',
55+
headers: {
56+
'Content-Type': 'application/json',
57+
},
58+
body: JSON.stringify(requestBody),
59+
});
60+
61+
if (!res.ok) {
62+
throw new Error(`HTTP Error: ${res.status} ${await res.text()}`);
63+
}
64+
65+
const result = (await res.json()) as JsonRpcResponse;
66+
67+
console.log(result);
68+
69+
if (result.error) {
70+
throw new Error(`RPC Error: ${result.error.code} - ${result.error.message}`);
71+
}
72+
73+
return result.result || false;
74+
75+
} catch (err) {
76+
console.error('Failed to fetch BigBlocks status.');
77+
throw err;
78+
}
79+
}
80+
81+
/**
82+
* Enable BigBlocks with retry mechanism
83+
*/
84+
async function enableBigBlocksWithRetry(config: any, chainId: number, maxRetries: number = 3): Promise<void> {
85+
for (let attempt = 1; attempt <= maxRetries; attempt++) {
86+
try {
87+
console.log(` Attempt ${attempt}/${maxRetries}: Enabling BigBlocks on ${config.name}`);
88+
await enableBigBlocks(config.envKey, true, chainId);
89+
console.log(` BigBlocks enabled on ${config.name} (attempt ${attempt})`);
90+
return;
91+
} catch (error) {
92+
console.log(`Attempt ${attempt}/${maxRetries} failed:`, (error as Error).message);
93+
94+
if (attempt === maxRetries) {
95+
throw new Error(
96+
`Failed to enable BigBlocks on ${config.name} after ${maxRetries} attempts: ${(error as Error).message}`
97+
);
98+
}
99+
100+
// Wait 2 seconds before retry
101+
console.log(' Waiting 2 seconds before retry...');
102+
await new Promise(resolve => setTimeout(resolve, 2000));
103+
}
104+
}
105+
}
106+
107+
/**
108+
* Setup BigBlocks for a specific chain
109+
*/
110+
async function setupBigBlocks(chainId: number, deployerAddress: string): Promise<void> {
27111
const config = getBigBlocksConfig(chainId);
28112
if (!config) return;
29113

30114
if (!config.envKey) {
31115
throw new Error(`Please set the private key for ${config.name}.`);
32116
}
33117

34-
console.log(`Using BigBlocks on ${config.name}`);
35-
try {
36-
await enableBigBlocks(config.envKey, true, chainId);
37-
} catch (error) {
38-
throw new Error(
39-
`Failed to setup BigBlocks on ${config.name}: ${(error as Error).message}`
40-
);
118+
console.log(` Checking BigBlocks status on ${config.name}...`);
119+
120+
// Check if BigBlocks is already enabled
121+
const isEnabled = await checkBigBlocksStatus(deployerAddress, chainId);
122+
123+
if (isEnabled) {
124+
console.log(`BigBlocks already enabled on ${config.name}`);
125+
return;
41126
}
127+
128+
console.log(` BigBlocks not enabled on ${config.name}, attempting to enable...`);
129+
130+
// Try to enable BigBlocks with retry mechanism
131+
await enableBigBlocksWithRetry(config, chainId, 3);
132+
133+
// Verify it was enabled successfully
134+
console.log(`Verifying BigBlocks was enabled...`);
135+
const isEnabledAfter = await checkBigBlocksStatus(deployerAddress, chainId);
136+
137+
if (!isEnabledAfter) {
138+
throw new Error(`BigBlocks enable command succeeded but verification failed on ${config.name}`);
139+
}
140+
141+
console.log(`BigBlocks successfully verified as enabled on ${config.name}`);
42142
}
43143

44144
async function main() {
@@ -47,15 +147,16 @@ async function main() {
47147
const currentNonce = await ethers.provider.getTransactionCount(
48148
deployerAddress
49149
);
50-
const { chainId } = await ethers.provider.getNetwork(); // More direct way to get chainId
150+
const { chainId } = await ethers.provider.getNetwork();
51151
const chainConfig = await getChainConfig(Number(chainId));
52152
const output: DeploymentAddresses = loadOutput();
53153

54154
const gasOverrides = chainConfig.gasParams;
55155

156+
// Handle BigBlocks setup automatically if supported
56157
if (isBigBlocksSupported(Number(chainId))) {
57-
console.log('🔄 Setting up BigBlocks...');
58-
await setupBigBlocks(Number(chainId));
158+
console.log('🔍 BigBlocks supported on this chain, checking status...');
159+
await setupBigBlocks(Number(chainId), deployerAddress);
59160
}
60161

61162
console.log(
@@ -105,7 +206,7 @@ async function main() {
105206
const WalletFactory = await ethers.getContractFactory(
106207
chainConfig.walletFactoryContractName
107208
);
108-
const contract = await WalletFactory.deploy(walletAddress, gasOverrides); // constructor args + overrides
209+
const contract = await WalletFactory.deploy(walletAddress, gasOverrides);
109210
await contract.waitForDeployment();
110211
console.log(
111212
`✅ ${chainConfig.walletFactoryContractName} deployed at ${contract.target}`
@@ -132,7 +233,7 @@ async function main() {
132233
const Forwarder = await ethers.getContractFactory(
133234
chainConfig.forwarderContractName
134235
);
135-
const contract = await Forwarder.deploy(gasOverrides); // overrides only
236+
const contract = await Forwarder.deploy(gasOverrides);
136237
await contract.waitForDeployment();
137238
console.log(
138239
`✅ ${chainConfig.forwarderContractName} deployed at ${contract.target}`
@@ -157,7 +258,7 @@ async function main() {
157258
const contract = await ForwarderFactory.deploy(
158259
forwarderAddress,
159260
gasOverrides
160-
); // constructor args + overrides
261+
);
161262
await contract.waitForDeployment();
162263
console.log(
163264
`✅ ${chainConfig.forwarderFactoryContractName} deployed at ${contract.target}`
@@ -180,4 +281,4 @@ async function main() {
180281
main().catch((error) => {
181282
console.error(error);
182283
process.exitCode = 1;
183-
});
284+
});

scripts/enableBigBlocks.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { Wallet } from 'ethers';
1+
import { getBytes, Wallet } from 'ethers';
22
import { keccak_256 } from '@noble/hashes/sha3';
33
import { encode } from '@msgpack/msgpack';
44
import { hexToBytes, bytesToHex, concatBytes } from './secp256k1Wrapper';
55
import { getBigBlocksConfig } from '../config/bigBlocksConfig';
6+
import { get } from 'http';
67

78
interface Action {
89
type: 'evmUserModify';
@@ -36,6 +37,7 @@ interface SignL1ActionParams {
3637

3738
function getBigBlocksUrl(chainId: number): string {
3839
const config = getBigBlocksConfig(chainId);
40+
console.log(`BigBlocks config for chain ${chainId}:`, config);
3941
if (!config) throw new Error(`Chain ${chainId} does not support BigBlocks`);
4042
return config.apiUrl;
4143
}
@@ -121,10 +123,10 @@ async function signL1Action({
121123

122124
const message = {
123125
source: config.isTestnet ? 'b' : 'a',
124-
connectionId: arrayify(connectionId)
126+
connectionId: getBytes(connectionId)
125127
};
126128

127-
const signature = await wallet._signTypedData(domain, types, message);
129+
const signature = await wallet.signTypedData(domain, types, message);
128130

129131
const r = '0x' + signature.slice(2, 66);
130132
const s = '0x' + signature.slice(66, 130);
@@ -160,6 +162,7 @@ export async function enableBigBlocks(
160162
});
161163

162164
const apiUrl = getBigBlocksUrl(chainId);
165+
console.log(apiUrl);
163166
const res = await fetch(apiUrl, {
164167
method: 'POST',
165168
headers: {

0 commit comments

Comments
 (0)