2018-07-18 18:14:14 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"path"
|
|
|
|
"runtime/pprof"
|
|
|
|
"syscall"
|
|
|
|
|
|
|
|
"github.com/cosmos/ethermint/state"
|
|
|
|
"github.com/cosmos/ethermint/test/importer"
|
|
|
|
|
|
|
|
dbm "github.com/tendermint/tendermint/libs/db"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
cpuprofile = flag.String("cpu-profile", "", "write cpu profile `file`")
|
|
|
|
blockchain = flag.String("blockchain", "data/blockchain", "file containing blocks to load")
|
|
|
|
datadir = flag.String("datadir", path.Join(os.Getenv("HOME"), ".ethermint"), "directory for ethermint data")
|
2018-08-09 19:49:40 +00:00
|
|
|
cachesize = flag.Int("cachesize", 1024*1024, "number of key-value pairs for the state stored in memory")
|
2018-07-18 18:14:14 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
if *cpuprofile != "" {
|
|
|
|
f, err := os.Create(*cpuprofile)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("could not create CPU profile: %v\n", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := pprof.StartCPUProfile(f); err != nil {
|
|
|
|
fmt.Printf("could not start CPU profile: %v\n", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
defer pprof.StopCPUProfile()
|
|
|
|
}
|
|
|
|
|
|
|
|
sigs := make(chan os.Signal, 1)
|
|
|
|
interruptCh := make(chan bool, 1)
|
|
|
|
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
<-sigs
|
|
|
|
interruptCh <- true
|
|
|
|
}()
|
|
|
|
|
|
|
|
stateDB := dbm.NewDB("state", dbm.LevelDBBackend, *datadir)
|
|
|
|
codeDB := dbm.NewDB("code", dbm.LevelDBBackend, *datadir)
|
|
|
|
|
2018-08-09 19:49:40 +00:00
|
|
|
ethermintDB, err := state.NewDatabase(stateDB, codeDB, *cachesize)
|
2018-07-18 18:14:14 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(fmt.Sprintf("failed to initialize geth Database: %v", err))
|
|
|
|
}
|
|
|
|
|
|
|
|
importer := importer.Importer{
|
|
|
|
EthermintDB: ethermintDB,
|
|
|
|
BlockchainFile: *blockchain,
|
|
|
|
Datadir: *datadir,
|
|
|
|
InterruptCh: interruptCh,
|
|
|
|
}
|
|
|
|
|
|
|
|
importer.Import()
|
|
|
|
}
|