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

feat(statedb): Add initial module setup with base StateDB #1806

Closed
wants to merge 8 commits into from

Conversation

drklee3
Copy link
Member

@drklee3 drklee3 commented Jan 5, 2024

Description

Adds:

  • New statedb go module, under a new eth directory - if we also want to add custom precompiles under there
  • License
  • Basic README
  • Basic Makefile just with test for now
  • 1:1 copy of pre-existing StateDB from Ethermint v0.21.0-kava-v23-1

Checklist

  • Changelog has been updated as necessary.

@drklee3 drklee3 marked this pull request as ready for review January 5, 2024 23:49
eth/statedb/go.mod Outdated Show resolved Hide resolved
eth/statedb/config.go Outdated Show resolved Hide resolved
Copy link
Member Author

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

Copy link
Contributor

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
Copy link
Contributor

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)?

Copy link
Member Author

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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)
Copy link
Contributor

@galxy25 galxy25 Feb 1, 2024

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

Copy link
Member Author

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
Copy link
Contributor

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)
}
Copy link
Contributor

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?

@drklee3 drklee3 closed this Feb 9, 2024
@drklee3 drklee3 deleted the dl-statedb-module branch February 14, 2024 20:24
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.

3 participants