From 5ed3e924699da62beae4444c2a2459944fcad099 Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Mon, 3 Aug 2020 10:46:35 -0500 Subject: [PATCH] use freezer db --- cmd/stateSnapshot.go | 4 +++- pkg/snapshot/config.go | 14 +++++++++----- pkg/snapshot/service.go | 6 +++--- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/cmd/stateSnapshot.go b/cmd/stateSnapshot.go index 222ee24..d16df12 100644 --- a/cmd/stateSnapshot.go +++ b/cmd/stateSnapshot.go @@ -60,9 +60,11 @@ func stateSnapshot() { func init() { rootCmd.AddCommand(stateSnapshotCmd) - stateSnapshotCmd.PersistentFlags().String("leveldb-path", "", "path to leveldb") + stateSnapshotCmd.PersistentFlags().String("leveldb-path", "", "path to primary datastore") + stateSnapshotCmd.PersistentFlags().String("ancient-path", "", "path to ancient datastore") stateSnapshotCmd.PersistentFlags().String("block-height", "", "blockheight to extract state at") viper.BindPFlag("leveldb.path", stateSnapshotCmd.PersistentFlags().Lookup("leveldb-path")) + viper.BindPFlag("leveldb.ancient", stateSnapshotCmd.PersistentFlags().Lookup("ancient-path")) viper.BindPFlag("snapshot.blockHeight", stateSnapshotCmd.PersistentFlags().Lookup("block-height")) } diff --git a/pkg/snapshot/config.go b/pkg/snapshot/config.go index fc93977..7c3a90e 100644 --- a/pkg/snapshot/config.go +++ b/pkg/snapshot/config.go @@ -23,17 +23,19 @@ import ( ) const ( - LVL_DB_PATH = "LVL_DB_PATH" - ETH_NODE_ID = "ETH_NODE_ID" + ANCIENT_DB_PATH = "ANCIENT_DB_PATH" ETH_CLIENT_NAME = "ETH_CLIENT_NAME" ETH_GENESIS_BLOCK = "ETH_GENESIS_BLOCK" ETH_NETWORK_ID = "ETH_NETWORK_ID" + ETH_NODE_ID = "ETH_NODE_ID" + LVL_DB_PATH = "LVL_DB_PATH" ) type Config struct { - LevelDBPath string - Node core.Node - DBConfig config.Database + LevelDBPath string + AncientDBPath string + Node core.Node + DBConfig config.Database } func (c *Config) Init() { @@ -43,6 +45,7 @@ func (c *Config) Init() { viper.BindEnv("ethereum.clientName", ETH_CLIENT_NAME) viper.BindEnv("ethereum.genesisBlock", ETH_GENESIS_BLOCK) viper.BindEnv("ethereum.networkID", ETH_NETWORK_ID) + viper.BindEnv("leveldb.ancient", ANCIENT_DB_PATH) c.Node = core.Node{ ID: viper.GetString("ethereum.nodeID"), @@ -51,4 +54,5 @@ func (c *Config) Init() { NetworkID: viper.GetString("ethereum.networkID"), } c.LevelDBPath = viper.GetString("leveldb.path") + c.AncientDBPath = viper.GetString("leveldb.ancient") } diff --git a/pkg/snapshot/service.go b/pkg/snapshot/service.go index 8301b28..40407fb 100644 --- a/pkg/snapshot/service.go +++ b/pkg/snapshot/service.go @@ -50,7 +50,7 @@ func NewSnapshotService(con Config) (*Service, error) { if err != nil { return nil, err } - edb, err := rawdb.NewLevelDBDatabase(con.LevelDBPath, 256, 1024, "eth-pg-ipfs-state-snapshot") + edb, err := rawdb.NewLevelDBDatabaseWithFreezer(con.LevelDBPath, 1024, 256, con.AncientDBPath, "eth-pg-ipfs-state-snapshot") if err != nil { return nil, err } @@ -173,7 +173,7 @@ func (s *Service) createSnapshot(it trie.NodeIterator, trieDB *trie.Database, he return errors.New("unexpected node type") } } - return nil + return it.Error() } func (s *Service) storageSnapshot(sr common.Hash, stateID int64) error { @@ -228,5 +228,5 @@ func (s *Service) storageSnapshot(sr common.Hash, stateID int64) error { return err } } - return nil + return it.Error() }