From 7a6b866163c686dfaeeff5ec807e36afac692edb Mon Sep 17 00:00:00 2001 From: Roy Crihfield Date: Thu, 26 Nov 2020 18:31:29 +0800 Subject: [PATCH] docs, tweaks, fixes --- README.md | 40 +++++++++++++++++++++++++++++++++++----- cmd/serve.go | 12 ++++++------ cmd/write.go | 10 +++++----- pkg/builder.go | 2 +- pkg/service.go | 2 +- 5 files changed, 48 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 5b8682c..172ab77 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -## eth-statediff-service +# eth-statediff-service [![Go Report Card](https://goreportcard.com/badge/github.com/vulcanize/eth-statediff-service)](https://goreportcard.com/report/github.com/vulcanize/eth-statediff-service) @@ -10,11 +10,27 @@ Stand up a statediffing service directly on top of a go-ethereum leveldb instanc This service can serve historical state data over the same rpc interface as [statediffing geth](https://github.com/vulcanize/go-ethereum/releases/tag/v1.9.11-statediff-0.0.5) without needing to run a full node -Usage: +## Usage -`./eth-statediff-service serve --config={path to toml config file}` +To serve state diffs over RPC: -Config: +`eth-statediff-service serve --config=` + +Available RPC methods are: + * `statediff_stateTrieAt()` + * `statediff_streamCodeAndCodeHash()` + * `statediff_stateDiffAt()` + * `statediff_writeStateDiffAt()` + +To write state diffs directly to a database: + +`eth-statediff-service write --config=` + +This depends on the `database` settings being properly configured. + +## Configuration + +An example config file: ```toml [leveldb] @@ -25,10 +41,24 @@ Config: ipcPath = "~/.vulcanize/vulcanize.ipc" httpPath = "127.0.0.1:8545" +[write] + ranges = [[1, 2], [3, 4]] +[write.params] + IntermediateStateNodes = true + IntermediateStorageNodes = false + IncludeBlock = true + IncludeReceipts = true + IncludeTD = true + IncludeCode = false + +[statediff] + workers = 4 + [log] - file = "" + file = "~/.vulcanize/statediff.log" level = "info" [eth] chainID = 1 + ``` diff --git a/cmd/serve.go b/cmd/serve.go index 9d84caf..e47f393 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -64,14 +64,14 @@ func serve() { } // create leveldb reader - logWithCommand.Info("creating leveldb reader") + logWithCommand.Info("Creating leveldb reader") lvlDBReader, err := sd.NewLvlDBReader(path, ancientPath, config) if err != nil { logWithCommand.Fatal(err) } // create statediff service - logWithCommand.Info("creating statediff service") + logWithCommand.Info("Creating statediff service") db, err := postgres.NewDB(postgres.DbConnectionString(GetDBParams()), GetDBConfig(), nodeInfo) if err != nil { logWithCommand.Fatal(err) @@ -83,20 +83,20 @@ func serve() { } // start service and servers - logWithCommand.Info("starting statediff service") + logWithCommand.Info("Starting statediff service") wg := new(sync.WaitGroup) go statediffService.Loop(wg) - logWithCommand.Info("starting rpc servers") + logWithCommand.Info("Starting RPC servers") if err := startServers(statediffService); err != nil { logWithCommand.Fatal(err) } - logWithCommand.Info("rpc servers successfully spun up; awaiting requests") + logWithCommand.Info("RPC servers successfully spun up; awaiting requests") // clean shutdown shutdown := make(chan os.Signal) signal.Notify(shutdown, os.Interrupt) <-shutdown - logWithCommand.Info("received interrupt signal, shutting down") + logWithCommand.Info("Received interrupt signal, shutting down") statediffService.Stop() wg.Wait() } diff --git a/cmd/write.go b/cmd/write.go index 7724308..ab07d59 100644 --- a/cmd/write.go +++ b/cmd/write.go @@ -60,14 +60,14 @@ func write() { } // create leveldb reader - logWithCommand.Info("creating leveldb reader") + logWithCommand.Info("Creating leveldb reader") lvlDBReader, err := sd.NewLvlDBReader(path, ancientPath, config) if err != nil { logWithCommand.Fatal(err) } // create statediff service - logWithCommand.Info("creating statediff service") + logWithCommand.Info("Creating statediff service") db, err := postgres.NewDB(postgres.DbConnectionString(GetDBParams()), GetDBConfig(), nodeInfo) if err != nil { logWithCommand.Fatal(err) @@ -89,14 +89,14 @@ func write() { IncludeCode: true, } viper.UnmarshalKey("write.ranges", &blockRanges) - // viper.UnmarshalKey("write.params", &diffParams) + viper.UnmarshalKey("write.params", &diffParams) for _, rng := range blockRanges { if rng[1] < rng[0] { logWithCommand.Fatal("range ending block number needs to be greater than starting block number") } - logrus.Infof("writing statediffs from %d to %d", rng[0], rng[1]) - for height := uint64(0); height <= rng[1]; height++ { + logrus.Infof("Writing statediffs from block %d to %d", rng[0], rng[1]) + for height := rng[0]; height <= rng[1]; height++ { statediffService.WriteStateDiffAt(height, diffParams) } } diff --git a/pkg/builder.go b/pkg/builder.go index 87de785..6f674eb 100644 --- a/pkg/builder.go +++ b/pkg/builder.go @@ -533,7 +533,7 @@ func (sdb *builder) buildAccountCreations(accounts AccountMap, watchedStorageKey return fmt.Errorf("failed building eventual storage diffs for node %x\r\nerror: %v", val.Path, err) } diff.StorageNodes = storageDiffs - // emit codehash => code mappings for cod + // emit codehash => code mappings for code codeHash := common.BytesToHash(val.Account.CodeHash) code, err := sdb.stateCache.ContractCode(common.Hash{}, codeHash) if err != nil { diff --git a/pkg/service.go b/pkg/service.go index 7d2252b..bd6eace 100644 --- a/pkg/service.go +++ b/pkg/service.go @@ -228,7 +228,7 @@ func (sds *Service) Stop() error { // This operation cannot be performed back past the point of db pruning; it requires an archival node // for historical data func (sds *Service) WriteStateDiffAt(blockNumber uint64, params sd.Params) error { - logrus.Info(fmt.Sprintf("writing state diff at block %d", blockNumber)) + logrus.Info(fmt.Sprintf("Writing state diff at block %d", blockNumber)) currentBlock, err := sds.lvlDBReader.GetBlockByNumber(blockNumber) if err != nil { return err