Skip to content

Commit b3b8b17

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

File tree

4 files changed

+159
-19
lines changed

4 files changed

+159
-19
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: 138 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,149 @@ 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(
38+
userAddress: string,
39+
chainId: number
40+
): Promise<boolean> {
41+
const config = getBigBlocksConfig(chainId);
42+
if (!config) {
43+
throw new Error(`Chain with ID ${chainId} is not supported for BigBlocks.`);
44+
}
45+
console.log('Useradd' + userAddress);
46+
console.log(
47+
`Checking BigBlocks status for ${userAddress} on ${config.name}...`
48+
);
49+
console.log(`Making RPC call to: ${config.rpcUrl}`);
50+
try {
51+
const requestBody = {
52+
jsonrpc: '2.0',
53+
id: 0,
54+
method: 'eth_usingBigBlocks',
55+
params: [userAddress]
56+
};
57+
58+
const res = await fetch(config.rpcUrl, {
59+
method: 'POST',
60+
headers: {
61+
'Content-Type': 'application/json'
62+
},
63+
body: JSON.stringify(requestBody)
64+
});
65+
66+
if (!res.ok) {
67+
throw new Error(`HTTP Error: ${res.status} ${await res.text()}`);
68+
}
69+
70+
const result = (await res.json()) as JsonRpcResponse;
71+
72+
console.log(result);
73+
74+
if (result.error) {
75+
throw new Error(
76+
`RPC Error: ${result.error.code} - ${result.error.message}`
77+
);
78+
}
79+
80+
return result.result || false;
81+
} catch (err) {
82+
console.error('Failed to fetch BigBlocks status.');
83+
throw err;
84+
}
85+
}
86+
87+
/**
88+
* Enable BigBlocks with retry mechanism
89+
*/
90+
async function enableBigBlocksWithRetry(
91+
config: any,
92+
chainId: number,
93+
maxRetries: number = 3
94+
): Promise<void> {
95+
for (let attempt = 1; attempt <= maxRetries; attempt++) {
96+
try {
97+
console.log(
98+
` Attempt ${attempt}/${maxRetries}: Enabling BigBlocks on ${config.name}`
99+
);
100+
await enableBigBlocks(config.envKey, true, chainId);
101+
console.log(` BigBlocks enabled on ${config.name} (attempt ${attempt})`);
102+
return;
103+
} catch (error) {
104+
console.log(
105+
`Attempt ${attempt}/${maxRetries} failed:`,
106+
(error as Error).message
107+
);
108+
109+
if (attempt === maxRetries) {
110+
throw new Error(
111+
`Failed to enable BigBlocks on ${
112+
config.name
113+
} after ${maxRetries} attempts: ${(error as Error).message}`
114+
);
115+
}
116+
117+
// Wait 2 seconds before retry
118+
console.log(' Waiting 2 seconds before retry...');
119+
await new Promise((resolve) => setTimeout(resolve, 2000));
120+
}
121+
}
122+
}
123+
124+
/**
125+
* Setup BigBlocks for a specific chain
126+
*/
127+
async function setupBigBlocks(
128+
chainId: number,
129+
deployerAddress: string
130+
): Promise<void> {
27131
const config = getBigBlocksConfig(chainId);
28132
if (!config) return;
29133

30134
if (!config.envKey) {
31135
throw new Error(`Please set the private key for ${config.name}.`);
32136
}
33137

34-
console.log(`Using BigBlocks on ${config.name}`);
35-
try {
36-
await enableBigBlocks(config.envKey, true, chainId);
37-
} catch (error) {
138+
console.log(` Checking BigBlocks status on ${config.name}...`);
139+
140+
// Check if BigBlocks is already enabled
141+
const isEnabled = await checkBigBlocksStatus(deployerAddress, chainId);
142+
143+
if (isEnabled) {
144+
console.log(`BigBlocks already enabled on ${config.name}`);
145+
return;
146+
}
147+
148+
console.log(
149+
` BigBlocks not enabled on ${config.name}, attempting to enable...`
150+
);
151+
152+
// Try to enable BigBlocks with retry mechanism
153+
await enableBigBlocksWithRetry(config, chainId, 3);
154+
155+
// Verify it was enabled successfully
156+
console.log(`Verifying BigBlocks was enabled...`);
157+
const isEnabledAfter = await checkBigBlocksStatus(deployerAddress, chainId);
158+
159+
if (!isEnabledAfter) {
38160
throw new Error(
39-
`Failed to setup BigBlocks on ${config.name}: ${(error as Error).message}`
161+
`BigBlocks enable command succeeded but verification failed on ${config.name}`
40162
);
41163
}
164+
165+
console.log(`BigBlocks successfully verified as enabled on ${config.name}`);
42166
}
43167

44168
async function main() {
@@ -47,15 +171,16 @@ async function main() {
47171
const currentNonce = await ethers.provider.getTransactionCount(
48172
deployerAddress
49173
);
50-
const { chainId } = await ethers.provider.getNetwork(); // More direct way to get chainId
174+
const { chainId } = await ethers.provider.getNetwork();
51175
const chainConfig = await getChainConfig(Number(chainId));
52176
const output: DeploymentAddresses = loadOutput();
53177

54178
const gasOverrides = chainConfig.gasParams;
55179

180+
// Handle BigBlocks setup automatically if supported
56181
if (isBigBlocksSupported(Number(chainId))) {
57-
console.log('🔄 Setting up BigBlocks...');
58-
await setupBigBlocks(Number(chainId));
182+
console.log('🔍 BigBlocks supported on this chain, checking status...');
183+
await setupBigBlocks(Number(chainId), deployerAddress);
59184
}
60185

61186
console.log(
@@ -105,7 +230,7 @@ async function main() {
105230
const WalletFactory = await ethers.getContractFactory(
106231
chainConfig.walletFactoryContractName
107232
);
108-
const contract = await WalletFactory.deploy(walletAddress, gasOverrides); // constructor args + overrides
233+
const contract = await WalletFactory.deploy(walletAddress, gasOverrides);
109234
await contract.waitForDeployment();
110235
console.log(
111236
`✅ ${chainConfig.walletFactoryContractName} deployed at ${contract.target}`
@@ -132,7 +257,7 @@ async function main() {
132257
const Forwarder = await ethers.getContractFactory(
133258
chainConfig.forwarderContractName
134259
);
135-
const contract = await Forwarder.deploy(gasOverrides); // overrides only
260+
const contract = await Forwarder.deploy(gasOverrides);
136261
await contract.waitForDeployment();
137262
console.log(
138263
`✅ ${chainConfig.forwarderContractName} deployed at ${contract.target}`
@@ -157,7 +282,7 @@ async function main() {
157282
const contract = await ForwarderFactory.deploy(
158283
forwarderAddress,
159284
gasOverrides
160-
); // constructor args + overrides
285+
);
161286
await contract.waitForDeployment();
162287
console.log(
163288
`✅ ${chainConfig.forwarderFactoryContractName} deployed at ${contract.target}`

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)