Sitelet https://github.com/Fantom-foundation/go-opera/commit/b387feabcfe2b094a125daf5f4b248c67158d6d4
Skip to content

Commit b387fea

Browse files
committed
add command for exporting EVM keys
1 parent ada20db commit b387fea

2 files changed

Lines changed: 52 additions & 0 deletions

File tree

‎cmd/opera/launcher/chaincmd.go‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,20 @@ Optional second and third arguments control the first and
9191
last epoch to write.
9292
Pass dry-run instead of filename for calculation of hashes without exporting data.
9393
EVM export mode is configured with --export.evm.mode.
94+
`,
95+
},
96+
{
97+
Name: "evm-keys",
98+
Usage: "Export EVM node keys",
99+
ArgsUsage: "<directory>",
100+
Action: utils.MigrateFlags(exportEvmKeys),
101+
Flags: []cli.Flag{
102+
DataDirFlag,
103+
},
104+
Description: `
105+
opera export evm-keys
106+
107+
Requires a first argument of the DB directory to write to.
94108
`,
95109
},
96110
},

‎cmd/opera/launcher/export.go‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@ import (
1010

1111
"github.com/Fantom-foundation/lachesis-base/hash"
1212
"github.com/Fantom-foundation/lachesis-base/inter/idx"
13+
"github.com/Fantom-foundation/lachesis-base/kvdb/batched"
14+
"github.com/Fantom-foundation/lachesis-base/kvdb/pebble"
1315
"github.com/ethereum/go-ethereum/cmd/utils"
1416
"github.com/ethereum/go-ethereum/common"
1517
"github.com/ethereum/go-ethereum/log"
1618
"github.com/ethereum/go-ethereum/rlp"
1719
"github.com/status-im/keycard-go/hexutils"
20+
"github.com/syndtr/goleveldb/leveldb/opt"
1821
"gopkg.in/urfave/cli.v1"
1922

2023
"github.com/Fantom-foundation/go-opera/gossip"
@@ -114,3 +117,38 @@ func exportTo(w io.Writer, gdb *gossip.Store, from, to idx.Epoch) (err error) {
114117

115118
return
116119
}
120+
121+
func exportEvmKeys(ctx *cli.Context) error {
122+
if len(ctx.Args()) < 1 {
123+
utils.Fatalf("This command requires an argument.")
124+
}
125+
126+
cfg := makeAllConfigs(ctx)
127+
128+
rawDbs := makeDirectDBsProducer(cfg)
129+
gdb := makeGossipStore(rawDbs, cfg)
130+
defer gdb.Close()
131+
132+
fn := ctx.Args().First()
133+
134+
keysDB_, err := pebble.New(fn, 1024*opt.MiB, utils.MakeDatabaseHandles()/2, nil, nil)
135+
if err != nil {
136+
return err
137+
}
138+
keysDB := batched.Wrap(keysDB_)
139+
defer keysDB.Close()
140+
141+
it := gdb.EvmStore().EvmDb.NewIterator(nil, nil)
142+
// iterate only over MPT data
143+
it = mptAndPreimageIterator{it}
144+
defer it.Release()
145+
146+
log.Info("Exporting EVM keys", "dir", fn)
147+
for it.Next() {
148+
if err := keysDB.Put(it.Key(), []byte{0}); err != nil {
149+
return err
150+
}
151+
}
152+
log.Info("Exported EVM keys", "dir", fn)
153+
return nil
154+
}

0 commit comments

Comments
 (0)