Skip to content

core, trie: fix state log deep copy#17489

Merged
karalabe merged 1 commit intoethereum:masterfrom
rjl493456442:fix-state-copy
Aug 23, 2018
Merged

core, trie: fix state log deep copy#17489
karalabe merged 1 commit intoethereum:masterfrom
rjl493456442:fix-state-copy

Conversation

@rjl493456442
Copy link
Copy Markdown
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.

Comment thread core/state/statedb.go Outdated
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Good catch!

Comment thread trie/secure_trie.go Outdated
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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