core/state: fix state iterator#19127
Conversation
| cb(key, common.BytesToHash(it.Value)) | ||
|
|
||
| if len(it.Value) > 0 { | ||
| _, content, _, err := rlp.Split(it.Value) |
There was a problem hiding this comment.
Why do you need to post-process the value returned by the iterator? Shouldn't the underlying iterator do this?
There was a problem hiding this comment.
Yes it is quite weird since before putting the value into the trie, we have an additional rlp encode process https://github.com/ethereum/go-ethereum/blob/master/core/state/state_object.go#L234
And for the normal GetState operation, there is a corresponding rlp decode process https://github.com/ethereum/go-ethereum/blob/master/core/state/state_object.go#L186
While the iterator only iterate the trie node and miss the rlp decode operation.
| if len(it.Value) > 0 { | ||
| _, content, _, err := rlp.Split(it.Value) | ||
| if err != nil { | ||
| continue |
There was a problem hiding this comment.
This seems like a very bad idea. When we iterate a trie, no error should ever happen. Here not only are we expecting an error, but also silently discarding it. This would end up haunting us a lot. What's happening here?
|
@karalabe I return the error explicitly. PTAL |
This PR introduces a fix to
state.ForEachStoragefunction.Since before inserting data into trie, there is an additional RLP encode operation.
While in the
state.ForEachStoragefunction, it relies on the trie iterator to iterate all leaf nodes(aka state data), but the rlp decode operation is missing there.