-
Notifications
You must be signed in to change notification settings - Fork 334
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
feat(statedb): Add initial module setup with base StateDB #1806
Conversation
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.
Standalone workflow for testing statedb since I don't think it needs to be run when non-statedb code is modified
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.
Agreed! Nice optimization
// it's safer to use than using journal index alone. | ||
type revision struct { | ||
id int | ||
journalIndex int |
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.
int64 for more headroom (unless the indices are reset every block then unlikely we run out of them)?
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.
The modified StateDB is in -> Kava-Labs/ethermint#33
This one is just a 1:1 copy of the existing StateDB we are already using via Ethermint without any changes to for the setup
// Snapshot and RevertToSnapshot. | ||
journal *journal | ||
validRevisions []revision | ||
nextRevisionID int |
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.
int64 for more headroom (unless the revisions are reset every block then unlikely we run out of them)?
refund uint64 | ||
|
||
// Per-transaction logs | ||
logs []*ethtypes.Log |
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.
depending how often these are referenced, suggest using a map with the tx hash as the key (and the slice of logs for that tx as the value ofc)
logs []*ethtypes.Log | ||
|
||
// Per-transaction access list | ||
accessList *accessList |
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.
similar comment regarding map indexed by most popular look up key
func (s *StateDB) GetCommittedState(addr common.Address, hash common.Hash) common.Hash { | ||
stateObject := s.getStateObject(addr) | ||
if stateObject != nil { | ||
return stateObject.GetCommittedState(hash) |
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.
all of these Getters
would be more idiomatic golang if they returned an error for when the value wasn't in state (potentially even a typed error to allow callers to decide whether they are okay with the default value for a non-existent key
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.
StateDB needs to implement the StateDB interface from geth so there isn't much flexibility on return values https://github.com/ethereum/go-ethereum/blob/v1.10.26/core/vm/interface.go
// getStateObject retrieves a state object given by the address, returning nil if | ||
// the object is not found. | ||
func (s *StateDB) getStateObject(addr common.Address) *stateObject { | ||
// Prefer live objects if any is available |
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.
assuming live objects are always latest / non-stale version of the state object we care about?
newObj, prev := s.createObject(addr) | ||
if prev != nil { | ||
newObj.setBalance(prev.account.Balance) | ||
} |
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.
wait where is newObj
returned or is this a method that is called only for it's side effects?
Description
Adds:
eth
directory - if we also want to add custom precompiles under therev0.21.0-kava-v23-1
Checklist