docs, tweaks, fixes
This commit is contained in:
parent
bd5d2992fa
commit
7a6b866163
40
README.md
40
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)
|
[![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
|
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
|
[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=<config path>`
|
||||||
|
|
||||||
|
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=<config path>`
|
||||||
|
|
||||||
|
This depends on the `database` settings being properly configured.
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
An example config file:
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
[leveldb]
|
[leveldb]
|
||||||
@ -25,10 +41,24 @@ Config:
|
|||||||
ipcPath = "~/.vulcanize/vulcanize.ipc"
|
ipcPath = "~/.vulcanize/vulcanize.ipc"
|
||||||
httpPath = "127.0.0.1:8545"
|
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]
|
[log]
|
||||||
file = ""
|
file = "~/.vulcanize/statediff.log"
|
||||||
level = "info"
|
level = "info"
|
||||||
|
|
||||||
[eth]
|
[eth]
|
||||||
chainID = 1
|
chainID = 1
|
||||||
|
|
||||||
```
|
```
|
||||||
|
12
cmd/serve.go
12
cmd/serve.go
@ -64,14 +64,14 @@ func serve() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create leveldb reader
|
// create leveldb reader
|
||||||
logWithCommand.Info("creating leveldb reader")
|
logWithCommand.Info("Creating leveldb reader")
|
||||||
lvlDBReader, err := sd.NewLvlDBReader(path, ancientPath, config)
|
lvlDBReader, err := sd.NewLvlDBReader(path, ancientPath, config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logWithCommand.Fatal(err)
|
logWithCommand.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// create statediff service
|
// create statediff service
|
||||||
logWithCommand.Info("creating statediff service")
|
logWithCommand.Info("Creating statediff service")
|
||||||
db, err := postgres.NewDB(postgres.DbConnectionString(GetDBParams()), GetDBConfig(), nodeInfo)
|
db, err := postgres.NewDB(postgres.DbConnectionString(GetDBParams()), GetDBConfig(), nodeInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logWithCommand.Fatal(err)
|
logWithCommand.Fatal(err)
|
||||||
@ -83,20 +83,20 @@ func serve() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// start service and servers
|
// start service and servers
|
||||||
logWithCommand.Info("starting statediff service")
|
logWithCommand.Info("Starting statediff service")
|
||||||
wg := new(sync.WaitGroup)
|
wg := new(sync.WaitGroup)
|
||||||
go statediffService.Loop(wg)
|
go statediffService.Loop(wg)
|
||||||
logWithCommand.Info("starting rpc servers")
|
logWithCommand.Info("Starting RPC servers")
|
||||||
if err := startServers(statediffService); err != nil {
|
if err := startServers(statediffService); err != nil {
|
||||||
logWithCommand.Fatal(err)
|
logWithCommand.Fatal(err)
|
||||||
}
|
}
|
||||||
logWithCommand.Info("rpc servers successfully spun up; awaiting requests")
|
logWithCommand.Info("RPC servers successfully spun up; awaiting requests")
|
||||||
|
|
||||||
// clean shutdown
|
// clean shutdown
|
||||||
shutdown := make(chan os.Signal)
|
shutdown := make(chan os.Signal)
|
||||||
signal.Notify(shutdown, os.Interrupt)
|
signal.Notify(shutdown, os.Interrupt)
|
||||||
<-shutdown
|
<-shutdown
|
||||||
logWithCommand.Info("received interrupt signal, shutting down")
|
logWithCommand.Info("Received interrupt signal, shutting down")
|
||||||
statediffService.Stop()
|
statediffService.Stop()
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
}
|
}
|
||||||
|
10
cmd/write.go
10
cmd/write.go
@ -60,14 +60,14 @@ func write() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create leveldb reader
|
// create leveldb reader
|
||||||
logWithCommand.Info("creating leveldb reader")
|
logWithCommand.Info("Creating leveldb reader")
|
||||||
lvlDBReader, err := sd.NewLvlDBReader(path, ancientPath, config)
|
lvlDBReader, err := sd.NewLvlDBReader(path, ancientPath, config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logWithCommand.Fatal(err)
|
logWithCommand.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// create statediff service
|
// create statediff service
|
||||||
logWithCommand.Info("creating statediff service")
|
logWithCommand.Info("Creating statediff service")
|
||||||
db, err := postgres.NewDB(postgres.DbConnectionString(GetDBParams()), GetDBConfig(), nodeInfo)
|
db, err := postgres.NewDB(postgres.DbConnectionString(GetDBParams()), GetDBConfig(), nodeInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logWithCommand.Fatal(err)
|
logWithCommand.Fatal(err)
|
||||||
@ -89,14 +89,14 @@ func write() {
|
|||||||
IncludeCode: true,
|
IncludeCode: true,
|
||||||
}
|
}
|
||||||
viper.UnmarshalKey("write.ranges", &blockRanges)
|
viper.UnmarshalKey("write.ranges", &blockRanges)
|
||||||
// viper.UnmarshalKey("write.params", &diffParams)
|
viper.UnmarshalKey("write.params", &diffParams)
|
||||||
|
|
||||||
for _, rng := range blockRanges {
|
for _, rng := range blockRanges {
|
||||||
if rng[1] < rng[0] {
|
if rng[1] < rng[0] {
|
||||||
logWithCommand.Fatal("range ending block number needs to be greater than starting block number")
|
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])
|
logrus.Infof("Writing statediffs from block %d to %d", rng[0], rng[1])
|
||||||
for height := uint64(0); height <= rng[1]; height++ {
|
for height := rng[0]; height <= rng[1]; height++ {
|
||||||
statediffService.WriteStateDiffAt(height, diffParams)
|
statediffService.WriteStateDiffAt(height, diffParams)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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)
|
return fmt.Errorf("failed building eventual storage diffs for node %x\r\nerror: %v", val.Path, err)
|
||||||
}
|
}
|
||||||
diff.StorageNodes = storageDiffs
|
diff.StorageNodes = storageDiffs
|
||||||
// emit codehash => code mappings for cod
|
// emit codehash => code mappings for code
|
||||||
codeHash := common.BytesToHash(val.Account.CodeHash)
|
codeHash := common.BytesToHash(val.Account.CodeHash)
|
||||||
code, err := sdb.stateCache.ContractCode(common.Hash{}, codeHash)
|
code, err := sdb.stateCache.ContractCode(common.Hash{}, codeHash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -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
|
// This operation cannot be performed back past the point of db pruning; it requires an archival node
|
||||||
// for historical data
|
// for historical data
|
||||||
func (sds *Service) WriteStateDiffAt(blockNumber uint64, params sd.Params) error {
|
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)
|
currentBlock, err := sds.lvlDBReader.GetBlockByNumber(blockNumber)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user