Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit the number of requests in a batch call (<500) #23

Open
developer9 opened this issue Aug 31, 2022 · 4 comments
Open

Limit the number of requests in a batch call (<500) #23

developer9 opened this issue Aug 31, 2022 · 4 comments

Comments

@developer9
Copy link

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?

@Linch1
Copy link
Owner

Linch1 commented Sep 1, 2022

Ehi, thanks for the report, going to check this days and once done i'll update you 👍 😄

@tanhsnkt1997
Copy link

Getblock limit it

@tanhsnkt1997
Copy link

image

@developer9
Copy link
Author

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;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants