diff --git a/pkg/snapshot/file/publisher.go b/pkg/snapshot/file/publisher.go index 1d70a81..fcb5255 100644 --- a/pkg/snapshot/file/publisher.go +++ b/pkg/snapshot/file/publisher.go @@ -281,13 +281,15 @@ func (p *publisher) PrepareTxForBatch(tx snapt.Tx, maxBatchSize uint) (snapt.Tx, func (p *publisher) logNodeCounters() { t := time.NewTicker(logInterval) for range t.C { - p.printNodeCounters() + p.printNodeCounters("progress") } } -func (p *publisher) printNodeCounters() { - logrus.Infof("runtime: %s", time.Now().Sub(p.startTime).String()) - logrus.Infof("processed state nodes: %d", atomic.LoadUint64(&p.stateNodeCounter)) - logrus.Infof("processed storage nodes: %d", atomic.LoadUint64(&p.storageNodeCounter)) - logrus.Infof("processed code nodes: %d", atomic.LoadUint64(&p.codeNodeCounter)) +func (p *publisher) printNodeCounters(msg string) { + log.WithFields(log.Fields{ + "runtime": time.Now().Sub(p.startTime).String(), + "state nodes": atomic.LoadUint64(&p.stateNodeCounter), + "storage nodes": atomic.LoadUint64(&p.storageNodeCounter), + "code nodes": atomic.LoadUint64(&p.codeNodeCounter), + }).Info(msg) } diff --git a/pkg/snapshot/pg/publisher.go b/pkg/snapshot/pg/publisher.go index a32d626..4f014a3 100644 --- a/pkg/snapshot/pg/publisher.go +++ b/pkg/snapshot/pg/publisher.go @@ -27,7 +27,7 @@ import ( blockstore "github.com/ipfs/go-ipfs-blockstore" dshelp "github.com/ipfs/go-ipfs-ds-help" "github.com/multiformats/go-multihash" - "github.com/sirupsen/logrus" + log "github.com/sirupsen/logrus" "github.com/ethereum/go-ethereum/statediff/indexer/database/sql" "github.com/ethereum/go-ethereum/statediff/indexer/database/sql/postgres" @@ -81,8 +81,7 @@ func (p *publisher) BeginTx() (snapt.Tx, error) { } go p.logNodeCounters() return pubTx{tx, func() { - logrus.Info("----- final counts -----") - p.printNodeCounters() + p.printNodeCounters("final stats") }}, nil } @@ -227,13 +226,15 @@ func (p *publisher) PrepareTxForBatch(tx snapt.Tx, maxBatchSize uint) (snapt.Tx, func (p *publisher) logNodeCounters() { t := time.NewTicker(logInterval) for range t.C { - p.printNodeCounters() + p.printNodeCounters("progress") } } -func (p *publisher) printNodeCounters() { - logrus.Infof("runtime: %s", time.Now().Sub(p.startTime).String()) - logrus.Infof("processed state nodes: %d", atomic.LoadUint64(&p.stateNodeCounter)) - logrus.Infof("processed storage nodes: %d", atomic.LoadUint64(&p.storageNodeCounter)) - logrus.Infof("processed code nodes: %d", atomic.LoadUint64(&p.codeNodeCounter)) +func (p *publisher) printNodeCounters(msg string) { + log.WithFields(log.Fields{ + "runtime": time.Now().Sub(p.startTime).String(), + "state nodes": atomic.LoadUint64(&p.stateNodeCounter), + "storage nodes": atomic.LoadUint64(&p.storageNodeCounter), + "code nodes": atomic.LoadUint64(&p.codeNodeCounter), + }).Info(msg) } diff --git a/pkg/snapshot/service.go b/pkg/snapshot/service.go index e93ccf1..4efe153 100644 --- a/pkg/snapshot/service.go +++ b/pkg/snapshot/service.go @@ -29,7 +29,7 @@ import ( "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/trie" - "github.com/sirupsen/logrus" + log "github.com/sirupsen/logrus" . "github.com/vulcanize/eth-pg-ipfs-state-snapshot/pkg/types" iter "github.com/vulcanize/go-eth-state-node-iterator" @@ -79,14 +79,14 @@ type SnapshotParams struct { func (s *Service) CreateSnapshot(params SnapshotParams) error { // extract header from lvldb and publish to PG-IPFS // hold onto the headerID so that we can link the state nodes to this header - logrus.Infof("Creating snapshot at height %d", params.Height) + log.Infof("Creating snapshot at height %d", params.Height) hash := rawdb.ReadCanonicalHash(s.ethDB, params.Height) header := rawdb.ReadHeader(s.ethDB, hash, params.Height) if header == nil { return fmt.Errorf("unable to read canonical header at height %d", params.Height) } - logrus.Infof("head hash: %s head height: %d", hash.Hex(), params.Height) + log.Infof("head hash: %s head height: %d", hash.Hex(), params.Height) err := s.ipfsPublisher.PublishHeader(header) if err != nil { @@ -128,7 +128,7 @@ func (s *Service) CreateSnapshot(params SnapshotParams) error { defer func() { err := s.tracker.haltAndDump(s.recoveryFile) if err != nil { - logrus.Error("failed to write recovery file: ", err) + log.Error("failed to write recovery file: ", err) } }() @@ -142,7 +142,7 @@ func (s *Service) CreateSnapshot(params SnapshotParams) error { // Create snapshot up to head (ignores height param) func (s *Service) CreateLatestSnapshot(workers uint) error { - logrus.Info("Creating snapshot at head") + log.Info("Creating snapshot at head") hash := rawdb.ReadHeadHeaderHash(s.ethDB) height := rawdb.ReadHeaderNumber(s.ethDB, hash) if height == nil { @@ -234,7 +234,7 @@ func (s *Service) createSnapshot(it trie.NodeIterator, headerID string) error { codeHash := common.BytesToHash(account.CodeHash) codeBytes := rawdb.ReadCode(s.ethDB, codeHash) if len(codeBytes) == 0 { - logrus.Error("Code is missing", "account", common.BytesToHash(it.LeafKey())) + log.Error("Code is missing", "account", common.BytesToHash(it.LeafKey())) return errors.New("missing code") }