Limit the number of requests in a batch call (<500)
Hey mate, Hope you're well.
Is it easy to limit the number of requests in a batch call for instance, less than 500.
For example, analyseBlock-> getBlockSyncEvents->getReceiptsBatch(transactions) is returning error due to the batch size being greater than 500.
Transaction hashes are 1200 and the node provider is limiting to 500 in a batch call.
Can we update getReceiptsBatch(hashes) function in this file ./workers/lib/scrape.block.past.js to split the hashes array into multiple as per the set size like 500 in each array.
Any thoughts please?
Ehi, thanks for the report, going to check this days and once done i'll update you :+1: :smile:
Getblock limit it
Hey @Linch1
Just wondering if the below works, I am not sure if I am doing correct combining the receipts data from the node provider.
New function to slice hashes array into multiple arrays.
function sliceIntoChunks(arr, chunkSize) {
const res = [];
for (let i = 0; i < arr.length; i += chunkSize) {
const chunk = arr.slice(i, i + chunkSize);
res.push(chunk);
}
return res;
}
async function getReceiptsBatch( hashes ){
if(!hashes.length) return [];
let start = Date.now();
let body = [];
let batchSize = hashes.length/500;
let recResult= [];
if (batchSize>1){
const chunkSize = 500;
const chunkArr = sliceIntoChunks(hashes,500);
console.log("chunkArray Length " + chunkArr.length);
for (let j=0; j < chunkArr.length; j++){
console.log("Chunk Array length: " + chunkArr[j].length)
for(let i = 0; i < chunkArr[j].length; i++ ){
let hash = chunkArr[j][i];
body.push({"jsonrpc":"2.0","method":"eth_getTransactionReceipt","params":[hash], "id": i })
};
const receipts = await axios.post(
scraperConfig[process.env.CHAIN_ID].http_provider,
body,
{ headers: { 'Content-Type': 'application/json' } }
);
body = [];
recResult.concat(receipts.data);
}
}else {
let start = Date.now();
let body = [];
for(let i = 0; i < hashes.length; i++ ){
let hash = hashes[i];
body.push({"jsonrpc":"2.0","method":"eth_getTransactionReceipt","params":[hash], "id": i })
};
const receipts = await axios.post(
scraperConfig[process.env.CHAIN_ID].http_provider,
body,
{ headers: { 'Content-Type': 'application/json' } }
);
return receipts.data;
}
return recResult;
}