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

SendBatchRequestAsync returns List<> with null-items #1007

Open
migoldfinger opened this issue Feb 1, 2024 · 3 comments
Open

SendBatchRequestAsync returns List<> with null-items #1007

migoldfinger opened this issue Feb 1, 2024 · 3 comments

Comments

@migoldfinger
Copy link

When running this code the application fails with a null reference exception

var blocks = await wch.Client.Eth.Blocks.GetBlockWithTransactionsByNumber.SendBatchRequestAsync(blockNumbers).ConfigureAwait(false);
foreach(var block in blocks.OrderBy(b => b.Number.Value))
{
    if (block.TransactionCount() > 0)
    {
        var receipts = await _wch.Client.Eth.Transactions.GetTransactionReceipt.SendBatchRequestAsync(block.Transactions.Select(t => t.TransactionHash).ToArray()).ConfigureAwait(false);
        foreach (var receipt in receipts.OrderBy(r => r.TransactionIndex.Value)) // <--Fails with null exception
        {
// Some code
        }
    }
};

The reason are that receipts holds some items that are null.

Expected Behavior

No null items in the result. When refactoring the code and get the recepts in a loop everything works as expected.

Current Behavior

Null items in the result. As an extreme. When only one transaction is present it happens that the result is a List only containing null on index 0.

Steps to Reproduce

Just run the code. This does not happen if you debug it and run the commands in single step mode, so it seams like an timing related bug.

@migoldfinger
Copy link
Author

I sorted it out.
It was Alchemy related.
Instead of getting an error based on the response
[{"jsonrpc":"2.0","id":0,"error":{"code":429,"message":"Your app has exceeded its compute units per second capacity. If you have retries enabled, you can safely ignore this message. If not, check out https://docs.alchemy.com/reference/throughput"}}]
The batch returns null instead of an error.
So the only problem left is that I do get null values instead of error messages.
Is that wanted behavior?

@juanfranblanco
Copy link
Member

juanfranblanco commented Feb 12, 2024

The resolution has been to allow for null values to avoid failing the whole request, which is not great, as you are going to need to replay the lot. So I will collect all the results and combining in a list

@juanfranblanco
Copy link
Member

@migoldfinger something for the next release see the commit

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

2 participants