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

all: track state changes in state db #27349

Merged
merged 5 commits into from Jul 11, 2023
Merged

Conversation

rjl493456442
Copy link
Member

@rjl493456442 rjl493456442 commented May 25, 2023

This PR tracks the state changes in statedb.

The change set can be used to build the state history in path-based storage scheme
for state rollback and archive state serving.

@rjl493456442 rjl493456442 force-pushed the value-diff branch 2 times, most recently from f6da10e to c40c8a0 Compare May 29, 2023 02:50
@rjl493456442 rjl493456442 force-pushed the value-diff branch 7 times, most recently from c1cd59d to bad3103 Compare June 7, 2023 05:56
@rjl493456442 rjl493456442 changed the title Track the state diff in statedb all: track state changes in state db Jun 7, 2023
@rjl493456442 rjl493456442 marked this pull request as ready for review June 7, 2023 05:56
@rjl493456442 rjl493456442 force-pushed the value-diff branch 7 times, most recently from 11b2c40 to 11e25f7 Compare June 8, 2023 14:10
Comment on lines +175 to +177
if ch.prevAccountOriginExist {
s.accountsOrigin[ch.prev.addrHash] = ch.prevAccountOrigin
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We should document, somewhere, what this means. For example, if prevAccountOriginExist is true, can prevAccountOrigin be nil? And what kind of scenario would lead to that?
Simiarly, can prevAccountOriginExist be false and prevAccountOrigin be non-nil? If so, how?

And if they're both 'strongly' tied to eachother, do we really need prevAccountOriginExist?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's possible that prevAccountOriginExist is true and prevAccountOrigin is nil.

nil means the account was not present and it's created in this block. If we want
to reset this block, we need the explicit flag to distinguish:

  • accountOrigin is nil
  • accountOrigin is not existent

Regarding prevAccountOriginExist is false while prevAccountOrigin is non-nil, it's an impossible combo.

if _, ok := s.accounts[addrHash]; ok {
s.accountsOrigin[addrHash] = nil // case (b)
}
continue
Copy link
Member Author

Choose a reason for hiding this comment

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

add comment

@rjl493456442 rjl493456442 force-pushed the value-diff branch 2 times, most recently from d273dc4 to d9926e3 Compare June 26, 2023 06:26
core/state/statedb.go Outdated Show resolved Hide resolved
trie/triestate/state.go Outdated Show resolved Hide resolved
address: s.address,
addrHash: s.addrHash,
origin: s.origin,
data: s.data,
Copy link
Member

Choose a reason for hiding this comment

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

I think this only deep copies the pointer to s.data, I'm not sure if this is what you want

Copy link
Member Author

Choose a reason for hiding this comment

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

s.data is a struct, it's ok to directly copy it.

Re s.origin, seems we will never change the content of origin via pointer, it's also OK to copy the pointer.

Copy link
Member

@MariusVanDerWijden MariusVanDerWijden left a comment

Choose a reason for hiding this comment

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

LGTM

@holiman holiman added this to the 1.12.1 milestone Jul 11, 2023
@fjl fjl merged commit 4b06e4f into ethereum:master Jul 11, 2023
2 checks passed
MoonShiesty pushed a commit to MoonShiesty/go-ethereum that referenced this pull request Aug 30, 2023
This change makes the StateDB track the state key value diff of a block transition.
We already tracked current account and storage values for the purpose of updating
the state snapshot. With this PR, we now also track the original (pre-transition) values
of accounts and storage slots.
devopsbo3 pushed a commit to HorizenOfficial/go-ethereum that referenced this pull request Nov 10, 2023
This change makes the StateDB track the state key value diff of a block transition.
We already tracked current account and storage values for the purpose of updating
the state snapshot. With this PR, we now also track the original (pre-transition) values
of accounts and storage slots.
devopsbo3 added a commit to HorizenOfficial/go-ethereum that referenced this pull request Nov 10, 2023
devopsbo3 added a commit to HorizenOfficial/go-ethereum that referenced this pull request Nov 10, 2023
devopsbo3 added a commit to HorizenOfficial/go-ethereum that referenced this pull request Nov 10, 2023
state.accounts = copyAccounts(s.accounts)
state.storages = copyStorages(s.storages)
state.accountsOrigin = copyAccounts(state.accountsOrigin)
state.storagesOrigin = copyStorages(state.storagesOrigin)
Copy link
Contributor

Choose a reason for hiding this comment

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

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.

None yet

4 participants