Skip to content

Commit

Permalink
allow to exclude selected EVM keys during genesis export
Browse files Browse the repository at this point in the history
  • Loading branch information
uprendis committed Aug 19, 2022
1 parent 89665a6 commit 01d857a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cmd/opera/launcher/chaincmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ var (
Usage: `EVM export mode ("full" or "ext-mpt" or "mpt" or "none")`,
Value: "mpt",
}
EvmExportExclude = cli.StringFlag{
Name: "export.evm.exclude",
Usage: `DB of EVM keys to exclude from genesis`,
}
importCommand = cli.Command{
Name: "import",
Usage: "Import a blockchain file",
Expand Down
28 changes: 28 additions & 0 deletions cmd/opera/launcher/genesiscmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ import (
"github.com/Fantom-foundation/lachesis-base/hash"
"github.com/Fantom-foundation/lachesis-base/inter/idx"
"github.com/Fantom-foundation/lachesis-base/kvdb"
"github.com/Fantom-foundation/lachesis-base/kvdb/pebble"
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rlp"
"github.com/syndtr/goleveldb/leveldb/opt"
"gopkg.in/urfave/cli.v1"

"github.com/Fantom-foundation/go-opera/gossip/evmstore"
Expand Down Expand Up @@ -65,6 +67,20 @@ func (it mptAndPreimageIterator) Next() bool {
return false
}

type excludingIterator struct {
kvdb.Iterator
exclude kvdb.Reader
}

func (it excludingIterator) Next() bool {
for it.Iterator.Next() {
if ok, _ := it.exclude.Has(it.Key()); !ok {
return true
}
}
return false
}

type unitWriter struct {
plain io.WriteSeeker
gziper *gzip.Writer
Expand Down Expand Up @@ -202,6 +218,15 @@ func exportGenesis(ctx *cli.Context) error {
return errors.New("--export.evm.mode must be one of {full, ext-mpt, mpt, none}")
}

var excludeEvmDB kvdb.Store
if excludeEvmDBPath := ctx.String(EvmExportExclude.Name); len(excludeEvmDBPath) > 0 {
db, err := pebble.New(excludeEvmDBPath, 1024*opt.MiB, utils.MakeDatabaseHandles()/2, nil, nil)
if err != nil {
return err
}
excludeEvmDB = db
}

cfg := makeAllConfigs(ctx)
tmpPath := path.Join(cfg.Node.DataDir, "tmp")
_ = os.RemoveAll(tmpPath)
Expand Down Expand Up @@ -331,6 +356,9 @@ func exportGenesis(ctx *cli.Context) error {
// iterate only over MPT data and preimages
it = mptAndPreimageIterator{it}
}
if excludeEvmDB != nil {
it = excludingIterator{it, excludeEvmDB}
}
defer it.Release()
err = iodb.Write(writer, it)
if err != nil {
Expand Down

0 comments on commit 01d857a

Please sign in to comment.