Log progress info

This commit is contained in:
Ashwin Phatak 2022-05-26 15:50:42 +05:30 committed by Roy Crihfield
parent d213644ff4
commit 7129044eae
5 changed files with 32 additions and 3 deletions

2
.gitignore vendored
View File

@ -1,2 +1,4 @@
.idea/ .idea/
.vscode/
ipld-eth-state-snapshot ipld-eth-state-snapshot
mocks/

View File

@ -1,7 +1,7 @@
MOCKS_DIR = $(CURDIR)/mocks MOCKS_DIR = $(CURDIR)/mocks
mockgen_cmd=mockgen mockgen_cmd=mockgen
.PHONY: mocks .PHONY: mocks test
mocks: mocks/snapshot/publisher.go mocks: mocks/snapshot/publisher.go
@ -14,3 +14,6 @@ clean:
build: build:
go fmt ./... go fmt ./...
go build go build
test: mocks
go clean -testcache && go test -v ./...

View File

@ -52,3 +52,8 @@ Config format:
chainID = "1" # $ETH_CHAIN_ID chainID = "1" # $ETH_CHAIN_ID
genesisBlock = "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3" # $ETH_GENESIS_BLOCK genesisBlock = "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3" # $ETH_GENESIS_BLOCK
``` ```
## Tests
* Install [mockgen](https://github.com/golang/mock#installation)
* `make test`

View File

@ -44,7 +44,7 @@ func stateSnapshot() {
mode := snapshot.SnapshotMode(modeStr) mode := snapshot.SnapshotMode(modeStr)
config, err := snapshot.NewConfig(mode) config, err := snapshot.NewConfig(mode)
if err != nil { if err != nil {
logWithCommand.Fatal("unable to initialize config: %v", err) logWithCommand.Fatalf("unable to initialize config: %v", err)
} }
logWithCommand.Infof("opening levelDB and ancient data at %s and %s", logWithCommand.Infof("opening levelDB and ancient data at %s and %s",
config.Eth.LevelDBPath, config.Eth.AncientDBPath) config.Eth.LevelDBPath, config.Eth.AncientDBPath)

View File

@ -81,6 +81,8 @@ type SnapshotParams struct {
} }
func (s *Service) CreateSnapshot(params SnapshotParams) error { func (s *Service) CreateSnapshot(params SnapshotParams) error {
log.Infof("createSnapshot BEGIN %v", params)
// extract header from lvldb and publish to PG-IPFS // extract header from lvldb and publish to PG-IPFS
// hold onto the headerID so that we can link the state nodes to this header // hold onto the headerID so that we can link the state nodes to this header
log.Infof("Creating snapshot at height %d", params.Height) log.Infof("Creating snapshot at height %d", params.Height)
@ -92,12 +94,16 @@ func (s *Service) CreateSnapshot(params SnapshotParams) error {
log.Infof("head hash: %s head height: %d", hash.Hex(), params.Height) log.Infof("head hash: %s head height: %d", hash.Hex(), params.Height)
log.Infof("publish header")
err := s.ipfsPublisher.PublishHeader(header) err := s.ipfsPublisher.PublishHeader(header)
if err != nil { if err != nil {
return err return err
} }
log.Infof("opening trie...")
tree, err := s.stateDB.OpenTrie(header.Root) tree, err := s.stateDB.OpenTrie(header.Root)
log.Infof("opened trie")
if err != nil { if err != nil {
return err return err
} }
@ -106,13 +112,19 @@ func (s *Service) CreateSnapshot(params SnapshotParams) error {
go s.tracker.run() go s.tracker.run()
go s.tracker.captureSignal() go s.tracker.captureSignal()
log.Infof("after goroutines start")
var iters []trie.NodeIterator var iters []trie.NodeIterator
// attempt to restore from recovery file if it exists // attempt to restore from recovery file if it exists
log.Infof("restoring iterators from recovery file...")
iters, err = s.tracker.restore(tree) iters, err = s.tracker.restore(tree)
if err != nil { if err != nil {
log.Errorf("restore error: %s", err.Error())
return err return err
} }
if iters != nil { if iters != nil {
log.Infof("restored iterators; count: %d", len(iters))
if params.Workers < uint(len(iters)) { if params.Workers < uint(len(iters)) {
return fmt.Errorf( return fmt.Errorf(
"number of recovered workers (%d) is greater than number configured (%d)", "number of recovered workers (%d) is greater than number configured (%d)",
@ -120,12 +132,17 @@ func (s *Service) CreateSnapshot(params SnapshotParams) error {
) )
} }
} else { // nothing to restore } else { // nothing to restore
log.Infof("no iterators to restore")
if params.Workers > 1 { if params.Workers > 1 {
log.Infof("creating %d subtrie iterators...", params.Workers)
iters = iter.SubtrieIterators(tree, params.Workers) iters = iter.SubtrieIterators(tree, params.Workers)
log.Infof("created %d subtrie iterators", params.Workers)
} else { } else {
log.Infof("creating node iterators")
iters = []trie.NodeIterator{tree.NodeIterator(nil)} iters = []trie.NodeIterator{tree.NodeIterator(nil)}
} }
for i, it := range iters { for i, it := range iters {
log.Infof("tracked iterator %d", i)
iters[i] = s.tracker.tracked(it) iters[i] = s.tracker.tracked(it)
} }
} }
@ -133,10 +150,12 @@ func (s *Service) CreateSnapshot(params SnapshotParams) error {
defer func() { defer func() {
err := s.tracker.haltAndDump() err := s.tracker.haltAndDump()
if err != nil { if err != nil {
log.Error("failed to write recovery file: ", err) log.Errorf("failed to write recovery file: %v", err)
} }
}() }()
log.Infof("num iters %d", len(iters))
if len(iters) > 0 { if len(iters) > 0 {
return s.createSnapshotAsync(iters, headerID) return s.createSnapshotAsync(iters, headerID)
} else { } else {