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

fix: increase range for the random value of request id in prover #6115

Merged
merged 1 commit into from
Jan 8, 2024

Conversation

rdvorkin
Copy link
Contributor

Request id is currently generated by choosing random number 0-10000.
This range is too small, and in some scenarios causes duplicate ids in batch.
Example:
call eth_call to multicall contract, aggregating balanceOf calls of many tokens.
If enough tokens are queried, then many eth_getProof requests will be submitted in a batch. for a large amount of tokens there is a large chance of request id collision, failing the check in https://github.com/ChainSafe/lodestar/blob/unstable/packages/prover/src/utils/json_rpc.ts#L84

Request id is currently generated by choosing random number 0-10000.
This range is too small, and in some scenarios causes duplicate ids in batch.
Example:
call eth_call to multicall contract, aggregating balanceOf calls of many tokens. If enough tokens are queried, then many eth_getProof requests will be submitted in a batch. for a large amount of tokens there is a large chance of request id collision, failing the check in https://github.com/ChainSafe/lodestar/blob/unstable/packages/prover/src/utils/json_rpc.ts#L84
@rdvorkin rdvorkin requested a review from a team as a code owner November 20, 2023 13:22
@rdvorkin rdvorkin changed the title fix: increase range for the random value of request id fix: increase range for the random value of request id in prover Nov 20, 2023
@@ -100,6 +100,6 @@ export class ELRpc {

getRequestId(): string {
// TODO: Find better way to generate random id
return (Math.random() * 10000).toFixed(0);
return (Math.random() * 100000000000000000).toFixed(0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for noticing this! Indeed the range of 10000 is improper for this application.

Math.random is a bad generator regardless. Why not have an incrementing counter @nazarhussain ?

Copy link
Member

@wemeetagain wemeetagain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is better than what we had before.

Created an issue to investigate this further.

@wemeetagain wemeetagain merged commit 2aeb0f1 into ChainSafe:unstable Jan 8, 2024
@wemeetagain
Copy link
Member

🎉 This PR is included in v1.14.0 🎉

ensi321 pushed a commit to ensi321/lodestar that referenced this pull request Jan 22, 2024
…inSafe#6115)

fix: increase range for the random value of request id

Request id is currently generated by choosing random number 0-10000.
This range is too small, and in some scenarios causes duplicate ids in batch.
Example:
call eth_call to multicall contract, aggregating balanceOf calls of many tokens. If enough tokens are queried, then many eth_getProof requests will be submitted in a batch. for a large amount of tokens there is a large chance of request id collision, failing the check in https://github.com/ChainSafe/lodestar/blob/unstable/packages/prover/src/utils/json_rpc.ts#L84
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

Successfully merging this pull request may close these issues.

4 participants