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

fixes from trying to get the devnet to work #267

Merged
merged 1 commit into from
Sep 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions consensus/beacon/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/consensus/misc/eip1559"
"github.com/ethereum/go-ethereum/consensus/misc/eip4844"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/params"
Expand Down Expand Up @@ -341,10 +342,7 @@ func (beacon *Beacon) Prepare(chain consensus.ChainHeaderReader, header *types.H

// Trigger the start of the verkle conversion if we're at the right block
if chain.Config().IsPrague(header.Number, header.Time) {
parent := chain.GetHeaderByNumber(header.Number.Uint64() - 1)
if !chain.Config().IsPrague(parent.Number, parent.Time) {
statedb.Database().StartVerkleTransition(common.Hash{}, common.Hash{}, chain.Config(), nil)
}
core.VerkleTransition(statedb)
}

return nil
Expand Down Expand Up @@ -409,8 +407,21 @@ func (beacon *Beacon) FinalizeAndAssemble(chain consensus.ChainHeaderReader, hea
return nil, fmt.Errorf("error opening pre-state tree root: %w", err)
}

vtrpre, okpre := preTrie.(*trie.VerkleTrie)
vtrpost, okpost := state.GetTrie().(*trie.VerkleTrie)
var okpre, okpost bool
var vtrpre, vtrpost *trie.VerkleTrie
switch pre := preTrie.(type) {
case *trie.VerkleTrie:
vtrpre, okpre = preTrie.(*trie.VerkleTrie)
vtrpost, okpost = state.GetTrie().(*trie.VerkleTrie)
case *trie.TransitionTrie:
vtrpre = pre.Overlay()
okpre = true
post, _ := state.GetTrie().(*trie.TransitionTrie)
vtrpost = post.Overlay()
okpost = true
default:
panic("invalid tree type")
}
if okpre && okpost {
// Resolve values from the pre state, the post
// state should already have the values in memory.
Expand Down
29 changes: 2 additions & 27 deletions core/state/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func (db *cachingDB) StartVerkleTransition(originalRoot, translatedRoot common.H
|____| |___| /\___ \___ |____/\___ | __/|___| (____ |___| |__| |___| (____ /_____/ \/\_/ |__|___| /_____//_____/
|__|`)
db.started = true
db.AddTranslation(originalRoot, translatedRoot)
// db.AddTranslation(originalRoot, translatedRoot)
db.baseRoot = originalRoot
// initialize so that the first storage-less accounts are processed
db.StorageProcessed = true
Expand All @@ -243,25 +243,6 @@ func (db *cachingDB) EndVerkleTransition() {
db.ended = true
}

func (db *cachingDB) AddTranslation(orig, trans common.Hash) {
// TODO make this persistent
db.translatedRootsLock.Lock()
defer db.translatedRootsLock.Unlock()
db.translatedRoots[db.translationIndex] = trans
db.origRoots[db.translationIndex] = orig
db.translationIndex = (db.translationIndex + 1) % len(db.translatedRoots)
}

func (db *cachingDB) getTranslation(orig common.Hash) common.Hash {
db.translatedRootsLock.RLock()
defer db.translatedRootsLock.RUnlock()
for i, o := range db.origRoots {
if o == orig {
return db.translatedRoots[i]
}
}
return common.Hash{}
}

type cachingDB struct {
disk ethdb.KeyValueStore
Expand Down Expand Up @@ -322,14 +303,8 @@ func (db *cachingDB) OpenTrie(root common.Hash) (Trie, error) {
// TODO separate both cases when I can be certain that it won't
// find a Verkle trie where is expects a Transitoion trie.
if db.started || db.ended {
var r common.Hash
// NOTE this is a kaustinen-only change, it will break replay
// if db.ended {
r = root
// } else {
// r = db.getTranslation(root)
// }
vkt, err := db.openVKTrie(r)
vkt, err := db.openVKTrie(root)
if err != nil {
return nil, err
}
Expand Down
6 changes: 0 additions & 6 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,6 @@ func New(root common.Hash, db Database, snaps *snapshot.Tree) (*StateDB, error)
}
if sdb.snaps != nil {
if sdb.snap = sdb.snaps.Snapshot(root); sdb.snap == nil {
if db, ok := db.(*cachingDB); ok {
trans := db.getTranslation(root)
if trans != (common.Hash{}) {
sdb.snap = sdb.snaps.Snapshot(trans)
}
}
}
}
return sdb, nil
Expand Down
Loading