Skip to content

Commit

Permalink
use preimages in conversion (#44)
Browse files Browse the repository at this point in the history
Co-authored-by: ubuntu <ubuntu@geth-verkle1.ethdevops.io>
  • Loading branch information
gballet and ubuntu authored Jun 14, 2022
1 parent e1cc3aa commit 6639ef7
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions cmd/geth/converkle.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/state/snapshot"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/trie"
Expand Down Expand Up @@ -138,13 +139,17 @@ type slotHash struct {
hash common.Hash
}

func iterateSlots(slotCh chan *slotHash, storageIt snapshot.StorageIterator) {
func iterateSlots(slotCh chan *slotHash, storageIt snapshot.StorageIterator, chaindb ethdb.Database) {
defer storageIt.Release()
for storageIt.Next() {
var slot [32]byte
slotNum := rawdb.ReadPreimage(chaindb, storageIt.Hash())
if len(slotNum) == 0 {
panic(fmt.Sprintf("no preimage for %x", storageIt.Hash().Bytes()))
}
copy(slot[:], storageIt.Slot())
slotCh <- &slotHash{
hash: storageIt.Hash(),
hash: common.BytesToHash(slotNum),
slot: slot[:],
}
}
Expand Down Expand Up @@ -231,6 +236,10 @@ func convertToVerkle(ctx *cli.Context) error {
if !bytes.Equal(acc.CodeHash, emptyCode) {
code = rawdb.ReadCode(chaindb, common.BytesToHash(acc.CodeHash))
}
addr := rawdb.ReadPreimage(chaindb, accIt.Hash())
if len(addr) == 0 {
panic(fmt.Sprintf("no preimage for %x", accIt.Hash().Bytes()))
}
accountCh <- &accHash{
account: acc,
hash: accIt.Hash(),
Expand Down Expand Up @@ -265,7 +274,7 @@ func convertToVerkle(ctx *cli.Context) error {
// TODO these aren't properly stopped in case of errors / aborts
// TODO instead of firing up a new goroutine each time, just pass
// the iterator to a persistent routine (which also handles aborts properly)
go iterateSlots(slotCh, storageIt)
go iterateSlots(slotCh, storageIt, chaindb)
}

// Store the basic account data
Expand Down

0 comments on commit 6639ef7

Please sign in to comment.