-
Notifications
You must be signed in to change notification settings - Fork 19.5k
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/state: introduce stateupdate structure #29530
base: master
Are you sure you want to change the base?
Conversation
8e190d8
to
ea9d92e
Compare
005bb86
to
60746bb
Compare
354717c
to
bd6b20a
Compare
2fe48c1
to
2089fdb
Compare
2089fdb
to
3d70c5b
Compare
This pull request has been deployed full sync for a few days, since the genesis. It can sync more than 16m blocks with no error. |
3d70c5b
to
d940577
Compare
d940577
to
7b1ff9b
Compare
// boundary; however post the byzantium fork, the commit will only be performed | ||
// at the end of block, this set essentially tracks all the modifications | ||
// made within the block. | ||
needCommit Storage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that the previous 3 items are all XXXStorage
, I'd recommend using uncommittedStorage
for this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though, it's a bit weird, because it contains the "origin" values too, which also somewhat clash with originStorage. Does it make sense to have the origin in 2 different variables? Can't we just use this field as a map[hash]struct{} to track which slots need commit, but otherwise rely on originStorage for the actual value content?
@@ -193,6 +191,7 @@ func (s *stateObject) GetCommittedState(key common.Hash) common.Hash { | |||
// have been handles via pendingStorage above. | |||
// 2) we don't have new values, and can deliver empty response back | |||
if _, destructed := s.db.stateObjectsDestruct[s.address]; destructed { | |||
s.originStorage[key] = common.Hash{} // track the empty slot as origin value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any particular reason for starting to track this here?
} | ||
s.pendingStorage = make(Storage) // reset pending map | ||
s.needCommit = make(Storage) // empties the commit markers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might want to use some map clearing method here to retain the memory and not reallocate for the next tx (pre byzantium).
data: types.SlimAccountRLP(s.data), | ||
} | ||
if s.origin == nil { | ||
op.origin = nil // the account was not present |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a noop, right? Can't we just have a single if branch to set origin if s.origin != nil?
return blob | ||
} | ||
) | ||
for key, slot := range s.pendingStorage { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pls rename slot to value. Slot is really the key itself.
// Overwrite the clean value of storage slots | ||
s.originStorage[key] = slot | ||
} | ||
s.pendingStorage = make(Storage) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use a map clearing method here
This pull request rewrites the statedb by introducing a state update struct.
A state update struct will be constructed once the
statedb.Commit
is invoked. It contains all the statechanges caused by previous state transition, e.g.
Instead of committing the state change into state snapshot and trie database blindly, the state update
will be returned and then can be consumed by different state database implementation in different
ways. It gives more flexibilities to design database abstraction for different purposes.
What's more, the statedb has been simplified significantly, especially in state change construction.