Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
BigDealCompany committed May 25, 2024
1 parent f6def9f commit 20149c3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type ChainTokenList = {
// Staking Yearly Rate
export const YEARLY_RATE = JSBI.divide(JSBI.BigInt(365), JSBI.BigInt(REWARDS_DURATION_DAYS_180));
// Block time here is slightly higher (~1s) than average in order to avoid ongoing proposals past the displayed time
export const AVERAGE_BLOCK_TIME_IN_SECS = 3;
export const AVERAGE_BLOCK_TIME_IN_SECS = 5;
export const PROPOSAL_LENGTH_IN_BLOCKS = 40_320;
export const PROPOSAL_LENGTH_IN_SECS = AVERAGE_BLOCK_TIME_IN_SECS * PROPOSAL_LENGTH_IN_BLOCKS;
// export const GOVERNANCE_ADDRESS = '0x5e4be8Bc9637f0EAA1A755019e06A68ce081D58F';
Expand Down
25 changes: 8 additions & 17 deletions src/state/multicall/updater.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,10 @@ import {
parseCallKey,
updateMulticallResults,
} from './actions';
import axios from 'axios';
import rateLimit from 'axios-rate-limit';

// chunk calls so we do not exceed the gas limit
const CALL_CHUNK_SIZE = 25;
const BACKOFF_TIMEOUT = 5000;
const http = rateLimit(axios.create(), { maxRequests: 2, perMilliseconds: 1000 });

/**
* Fetches a chunk of calls, enforcing a minimum block number constraint
Expand All @@ -38,25 +35,18 @@ async function fetchChunk(

let resultsBlockNumber, returnData;
try {
// Use rate-limited axios instance here
const response = await http.post(
'https://mainnet.tron.tronql.com/uo5c40py0q8udu7qje2nyo6ti8fue4/wallet/triggerconstantcontract',
{
multicallContract: multicallContract.address,
chunk: chunk.map((obj) => [obj.address, obj.callData]),
},
[resultsBlockNumber, returnData] = await multicallContract.aggregate(
chunk.map((obj) => [obj.address, obj.callData]),
);
resultsBlockNumber = response.data.resultsBlockNumber;
returnData = response.data.returnData;
} catch (error) {
console.debug('Failed to fetch chunk inside retry', error);
throw error;
}
if (resultsBlockNumber < minBlockNumber) {
console.debug(`Fetched results for old block number: ${resultsBlockNumber} vs. ${minBlockNumber}`);
if (resultsBlockNumber.toNumber() < minBlockNumber) {
console.debug(`Fetched results for old block number: ${resultsBlockNumber.toString()} vs. ${minBlockNumber}`);
throw new RetryableError('Fetched for old block number');
}
return { results: returnData, blockNumber: resultsBlockNumber };
return { results: returnData, blockNumber: resultsBlockNumber.toNumber() };
}

/**
Expand Down Expand Up @@ -213,8 +203,9 @@ export default function Updater(): null {
);
});

// Add a delay between chunks to avoid rate limit issues
return () => setTimeout(cancel, BACKOFF_TIMEOUT);
setTimeout(() => {}, BACKOFF_TIMEOUT);

return cancel;
}),
};
}, [chainId, multicallContract, dispatch, serializedOutdatedCallKeys, latestBlockNumber]);
Expand Down

0 comments on commit 20149c3

Please sign in to comment.