@@ -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