Skip to content

Commit

Permalink
Update go-eth-state-node-iterator version
Browse files Browse the repository at this point in the history
  • Loading branch information
nikugogoi committed May 13, 2022
1 parent 0f8a138 commit bbdc836
Show file tree
Hide file tree
Showing 9 changed files with 258 additions and 15 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ make build

```toml
[leveldb]
mode = "local"
# Path to geth leveldb data
path = "/path-to-local-geth-data/chaindata"
ancient = "/path-to-local-geth-data/chaindata/ancient"
Expand Down Expand Up @@ -53,6 +54,13 @@ make build
]
```

* To use remote leveldb RPC endpoint change the following in [config file](./environments/config.toml)
```toml
[leveldb]
mode = "remote"
url = "http://127.0.0.1:8082/" # Remote leveldb RPC url
```

## Usage

### `serve`
Expand Down
2 changes: 2 additions & 0 deletions cmd/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const (

DB_CACHE_SIZE_MB = "DB_CACHE_SIZE_MB"
TRIE_CACHE_SIZE_MB = "TRIE_CACHE_SIZE_MB"
LVLDB_MODE = "LVLDB_MODE"
LVLDB_PATH = "LVLDB_PATH"
LVLDB_ANCIENT = "LVLDB_ANCIENT"
LVLDB_URL = "LVLDB_URL"
Expand Down Expand Up @@ -113,6 +114,7 @@ func init() {
viper.BindEnv("cache.database", DB_CACHE_SIZE_MB)
viper.BindEnv("cache.trie", TRIE_CACHE_SIZE_MB)

viper.BindEnv("leveldb.mode", LVLDB_MODE)
viper.BindEnv("leveldb.path", LVLDB_PATH)
viper.BindEnv("leveldb.ancient", LVLDB_ANCIENT)
viper.BindEnv("leveldb.url", LVLDB_URL)
Expand Down
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ func init() {
rootCmd.PersistentFlags().String("log-level", log.InfoLevel.String(),
"log level (trace, debug, info, warn, error, fatal, panic")

rootCmd.PersistentFlags().String("leveldb-mode", "", "leveldb access mode")
rootCmd.PersistentFlags().String("leveldb-path", "", "path to primary datastore")
rootCmd.PersistentFlags().String("ancient-path", "", "path to ancient datastore")
rootCmd.PersistentFlags().String("leveldb-url", "", "url to primary leveldb-ethdb-rpc server")
Expand Down Expand Up @@ -178,6 +179,7 @@ func init() {
viper.BindPFlag("statediff.trieWorkers", rootCmd.PersistentFlags().Lookup("trie-workers"))
viper.BindPFlag("statediff.workerQueueSize", rootCmd.PersistentFlags().Lookup("worker-queue-size"))

viper.BindPFlag("leveldb.mode", rootCmd.PersistentFlags().Lookup("leveldb-mode"))
viper.BindPFlag("leveldb.path", rootCmd.PersistentFlags().Lookup("leveldb-path"))
viper.BindPFlag("leveldb.ancient", rootCmd.PersistentFlags().Lookup("ancient-path"))
viper.BindPFlag("leveldb.url", rootCmd.PersistentFlags().Lookup("leveldb-url"))
Expand Down
13 changes: 11 additions & 2 deletions cmd/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,19 @@ type blockRange [2]uint64
func createStateDiffService() (sd.StateDiffService, error) {
// load some necessary params
logWithCommand.Info("Loading statediff service parameters")
mode := viper.GetString("leveldb.mode")
path := viper.GetString("leveldb.path")
ancientPath := viper.GetString("leveldb.ancient")
url := viper.GetString("leveldb.url")
if path == "" || ancientPath == "" {
logWithCommand.Fatal("require a valid eth leveldb primary datastore path and ancient datastore path")

if mode == "remote" {
if url == "" {
logWithCommand.Fatal("require a valid RPC url for accessing leveldb")
}
} else {
if path == "" || ancientPath == "" {
logWithCommand.Fatal("require a valid eth leveldb primary datastore path and ancient datastore path")
}
}

nodeInfo := getEthNodeInfo()
Expand Down Expand Up @@ -53,6 +61,7 @@ func createStateDiffService() (sd.StateDiffService, error) {
Preimages: false,
},
ChainConfig: chainConf,
Mode: mode,
Path: path,
AncientPath: ancientPath,
Url: url,
Expand Down
2 changes: 2 additions & 0 deletions environments/config.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[leveldb]
mode = "local"
path = "/app/geth-rw/chaindata"
ancient = "/app/geth-rw/chaindata/ancient"
url = "http://127.0.0.1:8082/"

[server]
ipcPath = ""
Expand Down
2 changes: 2 additions & 0 deletions environments/example.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[leveldb]
mode = "local"
path = "/Users/user/Library/Ethereum/geth/chaindata"
ancient = "/Users/user/Library/Ethereum/geth/chaindata/ancient"
url = "http://127.0.0.1:8082/"

[server]
ipcPath = ".ipc"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ module github.com/vulcanize/eth-statediff-service
go 1.16

require (
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 // indirect
github.com/ethereum/go-ethereum v1.10.17
github.com/jmoiron/sqlx v1.2.0
github.com/prometheus/client_golang v1.4.0
github.com/sirupsen/logrus v1.7.0
github.com/spf13/cobra v1.3.0
github.com/spf13/viper v1.10.1
github.com/vulcanize/go-eth-state-node-iterator v1.0.1
github.com/vulcanize/leveldb-ethdb-rpc v0.0.0-20220509104510-09fcf2aa603d
)

replace github.com/ethereum/go-ethereum v1.10.17 => github.com/vulcanize/go-ethereum v1.10.17-statediff-3.2.0
231 changes: 220 additions & 11 deletions go.sum

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion pkg/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,22 @@ type LvlDBReader struct {
type LvLDBReaderConfig struct {
TrieConfig *trie.Config
ChainConfig *params.ChainConfig
Mode string
Path, AncientPath, Url string
DBCacheSize int
}

// NewLvlDBReader creates a new Read using LevelDB
func NewLvlDBReader(conf LvLDBReaderConfig) (*LvlDBReader, error) {
edb, err := NewDatabase(conf.Url)
var edb ethdb.Database
var err error

if conf.Mode == "remote" {
edb, err = NewDatabase(conf.Url)
} else {
edb, err = rawdb.NewLevelDBDatabaseWithFreezer(conf.Path, conf.DBCacheSize, 256, conf.AncientPath, "eth-statediff-service", true)
}

if err != nil {
return nil, err
}
Expand Down

0 comments on commit bbdc836

Please sign in to comment.