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

internal/ethapi: prevent unnecessary resource usage in eth_getProof implementation #27310

Merged
merged 3 commits into from May 31, 2023

Conversation

prestwich
Copy link
Contributor

closes #27308

  • deserializes hex keys early to shortcut on invalid input
  • re-use the account storageTrie for each proof for each proof in the account, preventing repeated deep-copying of the trie

Code smell:
I duplicated the proofList type rather than making it public. Making it public seemed like the wrong choice, as it would result in panics on misuse. There is probably a better way to do this but I'm not sufficiently familiar with the codebase

@vinioleg2015zem vinioleg2015zem linked an issue May 21, 2023 that may be closed by this pull request
@holiman holiman changed the title opt: prevent unnecessary resource usage in eth_getProof implementation internal/ethapi: prevent unnecessary resource usage in eth_getProof implementation May 21, 2023
// GetProof returns the Merkle-proof for a given account and optionally some storage keys.
func (s *BlockChainAPI) GetProof(ctx context.Context, address common.Address, storageKeys []string, blockNrOrHash rpc.BlockNumberOrHash) (*AccountResult, error) {
var (
keys = make([]common.Hash, len(storageKeys))
storageProof = make([]StorageResult, len(storageKeys))
Copy link
Member

Choose a reason for hiding this comment

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

Maybe storageProofs?

Copy link
Member

@MariusVanDerWijden MariusVanDerWijden left a comment

Choose a reason for hiding this comment

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

SGTM

Co-authored-by: Marius van der Wijden <m.vanderwijden@live.de>
Copy link
Contributor

@holiman holiman left a comment

Choose a reason for hiding this comment

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

LGTM

@holiman holiman added this to the 1.12.1 milestone May 31, 2023
@holiman holiman merged commit 61dcf76 into ethereum:master May 31, 2023
2 checks passed
@prestwich
Copy link
Contributor Author

Thanks for the cleanup 🙏

antonydenyer pushed a commit to antonydenyer/go-ethereum that referenced this pull request Jul 28, 2023
…mplementation (ethereum#27310)

Deserialize hex keys early to shortcut on invalid input, and re-use the account storageTrie for each proof for each proof in the account, preventing repeated deep-copying of the trie.

Closes ethereum#27308

 --------

Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Marius van der Wijden <m.vanderwijden@live.de>
MoonShiesty pushed a commit to MoonShiesty/go-ethereum that referenced this pull request Aug 30, 2023
…mplementation (ethereum#27310)

Deserialize hex keys early to shortcut on invalid input, and re-use the account storageTrie for each proof for each proof in the account, preventing repeated deep-copying of the trie.

Closes ethereum#27308

 --------

Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Marius van der Wijden <m.vanderwijden@live.de>
devopsbo3 pushed a commit to HorizenOfficial/go-ethereum that referenced this pull request Nov 10, 2023
…mplementation (ethereum#27310)

Deserialize hex keys early to shortcut on invalid input, and re-use the account storageTrie for each proof for each proof in the account, preventing repeated deep-copying of the trie.

Closes ethereum#27308

 --------

Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Marius van der Wijden <m.vanderwijden@live.de>
devopsbo3 added a commit to HorizenOfficial/go-ethereum that referenced this pull request Nov 10, 2023
devopsbo3 added a commit to HorizenOfficial/go-ethereum that referenced this pull request Nov 10, 2023
devopsbo3 added a commit to HorizenOfficial/go-ethereum that referenced this pull request Nov 10, 2023
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.

Optimizations for eth_getProof > content://media/external/downloads/1000000694
3 participants