eth: add debug_storageRangeAt#14350
Conversation
The key was constructed from nibbles, which isn't possible for all nodes. Remove the only use of Key in LightTrie by always retrying with the original key that was looked up.
5fb8474 to
e1678ce
Compare
There was a problem hiding this comment.
Could you define typedefs for hex and compact encoding?
There was a problem hiding this comment.
No, because both types of key can be stored in shortNode.Key.
There was a problem hiding this comment.
We could always use casts there. Typedefs would be helpful to avoid confusion elsewhere - though the function naming accomplishes some of that at least.
There was a problem hiding this comment.
I don't want to change it in this PR. We can do it in another PR.
There was a problem hiding this comment.
What was the motivation behind making this internal?
There was a problem hiding this comment.
The motivation was to have a single constructor for each iterator. Please see the commit message.
There was a problem hiding this comment.
Why isn't this part of the loop initializer any longer?
There was a problem hiding this comment.
Can you add tests for seeking to the empty string, and for seeking to a key past the end?
There was a problem hiding this comment.
No need to test empty string, all other tests use NodeIterator(nil) ;). I've added one that seeks past the end.
69e1404 to
2f13ce1
Compare
There was a problem hiding this comment.
I assume these are the hashes of the keys in the array below? Could you add a note to that effect for anyone coming across this later?
43de846 to
b22dfc8
Compare
karalabe
left a comment
There was a problem hiding this comment.
Minor issues mostly. Please check and consider whether to fix or not.
One potentially bigger issue I saw was in the state object deep copy. Please check hat part out in detail and explain why it works if it works.
There was a problem hiding this comment.
❤️ I hate these labels so much :P
There was a problem hiding this comment.
Why return the previous "item" if peeking at the next one fails?
There was a problem hiding this comment.
It has to return something. The idea was that the iterator wouldn't advance if there was an error fetching the next item.
There was a problem hiding this comment.
Ah sweet, I've never seen this part of the code in 2 years :))
There was a problem hiding this comment.
Could you add a test for encoding/decoding empty keys? The previous code had explicit checks whereas the new code does this implicitly by relying on the calculation returning an empty slice. There's even a slight API change, where the old code returned nil in hexToKeybytes whereas the new returns []byte{}. I'd be happy to see an explicit test that verifies this weird case too.
There was a problem hiding this comment.
Could you add a test for encoding/decoding empty keys?
There was a problem hiding this comment.
Isn't stateObject.trie a trie.SecureTrie? Because that one is a much fancier construct that won't "deep copy" so easily https://github.com/ethereum/go-ethereum/blob/master/trie/secure_trie.go#L44
There was a problem hiding this comment.
Shallow copy support for SecureTrie was added in 710435b51, by yours truly.
There was a problem hiding this comment.
Don't trust that guy.... he looks shady af ;)
There was a problem hiding this comment.
Doesn't look like an iterator to me :P
There was a problem hiding this comment.
Can this ever happen? If the tx is already in our chain, I think it's safe to say this won't ever fail. (Mentioning because you deleted a similar check at tx.AsMessage).
There was a problem hiding this comment.
The around AsMessage is for deriving the sender. I don't want to remove this one because many more things can go wrong (including DB errors, etc.).
'encode' and 'decode' are meaningless because the code deals with three encodings. Document the encodings and give a name to each one.
Make it so each iterator has exactly one public constructor: - NodeIterators can be created through a method. - Iterators can be created through NewIterator on any NodeIterator.
The 'step' method is split into two parts, 'peek' and 'push'. peek returns the next state but doesn't make it current. The end of iteration was previously tracked by setting 'trie' to nil. End of iteration is now tracked using the 'iteratorEnd' error, which is slightly cleaner and requires less code.
b22dfc8 to
207bd7d
Compare
The new RPC method allows downloading storage in chunks.
debug_storageRangeAttakes parametersblockHash,txIndex,account,startKey,limit. ThestartKeyapplies to the hashed key (instead of the preimage as originally suggested in #3407) . The returned storage values contain the preimage if available. The returned object also contains thenextKeyfield, which will be non-null if there are more keys after the range that was returned.Example:
We agreed on a preliminary spec in #3407. This supersedes that PR.
The earlier commits leading up to the new API add support for seeking in the trie iterator.