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

core, trie: fix state log deep copy #17489

Merged
merged 1 commit into from
Aug 23, 2018

Conversation

rjl493456442
Copy link
Member

@rjl493456442 rjl493456442 commented Aug 23, 2018

This PR mainly fixes two things: state deep copy and secure trie deep copy.
Regarding the secure trie, the secure cache content (trie key's preimages) will be discarded for the copied trie in the current codebase, it will definitely introduce some trouble when we want to dump state.

}
for hash, preimage := range self.preimages {
state.preimages[hash] = preimage
state.preimages[hash] = common.CopyBytes(preimage)
Copy link
Member

Choose a reason for hiding this comment

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

I'm unsure about the changes here. Whilst you are in theory correct that this copy is a bit deeper than the old one, it's important to know that logs and preimages won't really be ever modified in any part of the code (the containing slices yes, hence the copy, but the contents AFAIK not). Thus copying them is just an expensive memory duplication that doesn't really add any value. Please correct me if I'm wrong though.

Copy link
Member Author

Choose a reason for hiding this comment

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

I am not sure about the preimage, but for the logs, yes it will be modified. https://github.com/ethereum/go-ethereum/blob/master/miner/worker.go#L540
In my eyes, since the function give out a description of independent copy, i think we should deep copy all the field to prevent misuse in the future

Copy link
Member

Choose a reason for hiding this comment

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

Good catch!

trie Trie
hashKeyBuf [common.HashLength]byte
secKeyCache map[string][]byte
secKeyCacheOwner *SecureTrie // Pointer to self, replace the key cache on mismatch
Copy link
Member

Choose a reason for hiding this comment

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

This change is dangerous. Most of our code assumes that a trie and a secure trie are immutable data structures. Many parts of the code relies on this and copies them freely, knowing that the result is an independent copy. The reason I added this convoluted hack is to retain that immutability guarantee. You are breaking it by requiring explicit copies from now on. I don't think we can guarantee that this won't break existing code and invariants.

@karalabe
Copy link
Member

Please split this PR into the log deep copy and the preimage deep copy. The logs can be merged imho, the preimage I have to think about a bit more.

@rjl493456442 rjl493456442 changed the title core, trie: fix state, secure trie deep copy core, trie: fix state log deep copy Aug 23, 2018
Copy link
Member

@karalabe karalabe left a comment

Choose a reason for hiding this comment

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

LGTM

@karalabe karalabe added this to the 1.8.15 milestone Aug 23, 2018
@karalabe karalabe merged commit c3f7e3b into ethereum:master Aug 23, 2018
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.

2 participants