From 99a29191b1b3127039f9a456cd00126096f6b9b5 Mon Sep 17 00:00:00 2001 From: Elizabeth Engelman Date: Wed, 2 Jan 2019 17:23:03 -0600 Subject: [PATCH] Clean up error logging --- statediff/builder/builder.go | 16 +++++++--------- statediff/service/service.go | 24 ++++++++++++++++++------ 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/statediff/builder/builder.go b/statediff/builder/builder.go index 131c3626f..22178b98f 100644 --- a/statediff/builder/builder.go +++ b/statediff/builder/builder.go @@ -50,12 +50,12 @@ func (sdb *builder) BuildStateDiff(oldStateRoot, newStateRoot common.Hash, block // Generate tries for old and new states oldTrie, err := trie.New(oldStateRoot, sdb.trieDB) if err != nil { - log.Debug("error creating oldTrie", err) + log.Error("Error creating trie for oldStateRoot", "error", err) return nil, err } newTrie, err := trie.New(newStateRoot, sdb.trieDB) if err != nil { - log.Debug("error creating newTrie", err) + log.Error("Error creating trie for newStateRoot", "error", err) return nil, err } @@ -64,7 +64,7 @@ func (sdb *builder) BuildStateDiff(oldStateRoot, newStateRoot common.Hash, block newIt := newTrie.NodeIterator([]byte{}) creations, err := sdb.collectDiffNodes(oldIt, newIt) if err != nil { - log.Debug("error collecting creation diff nodes", err) + log.Error("Error collecting creation diff nodes", "error", err) return nil, err } @@ -73,7 +73,7 @@ func (sdb *builder) BuildStateDiff(oldStateRoot, newStateRoot common.Hash, block newIt = newTrie.NodeIterator(make([]byte, 0)) deletions, err := sdb.collectDiffNodes(newIt, oldIt) if err != nil { - log.Debug("error collecting deletion diff nodes", err) + log.Error("Error collecting deletion diff nodes", "error", err) return nil, err } @@ -85,17 +85,17 @@ func (sdb *builder) BuildStateDiff(oldStateRoot, newStateRoot common.Hash, block // Build and return the statediff updatedAccounts, err := sdb.buildDiffIncremental(creations, deletions, updatedKeys) if err != nil { - log.Debug("error building diff incremental for updated", err) + log.Error("Error building diff for updated accounts", "error", err) return nil, err } createdAccounts, err := sdb.buildDiffEventual(creations, true) if err != nil { - log.Debug("error building diff incremental for created", err) + log.Error("Error building diff for created accounts", "error", err) return nil, err } deletedAccounts, err := sdb.buildDiffEventual(deletions, false) if err != nil { - log.Debug("error building diff incremental for deleted", err) + log.Error("Error building diff for deleted accounts", "error", err) return nil, err } @@ -260,9 +260,7 @@ func (sdb *builder) buildStorageDiffsIncremental(oldSR common.Hash, newSR common } func (sdb *builder) addressByPath(path []byte) (*common.Address, error) { - // db := core.PreimageTable(sdb.chainDb) log.Debug("Looking up address from path", "path", hexutil.Encode(append([]byte("secure-key-"), path...))) - // if addrBytes,err := db.Get(path); err != nil { if addrBytes, err := sdb.chainDB.Get(append([]byte("secure-key-"), hexToKeybytes(path)...)); err != nil { log.Error("Error looking up address via path", "path", hexutil.Encode(append([]byte("secure-key-"), path...)), "error", err) return nil, err diff --git a/statediff/service/service.go b/statediff/service/service.go index 86b74219c..42711339e 100644 --- a/statediff/service/service.go +++ b/statediff/service/service.go @@ -13,6 +13,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/event" + "github.com/ethereum/go-ethereum/log" ) type BlockChain interface { @@ -51,19 +52,30 @@ func (StateDiffService) APIs() []rpc.API { func (sds *StateDiffService) Loop(events chan core.ChainEvent) { for elem := range events { currentBlock := elem.Block - parentHash := currentBlock.ParentHash() parentBlock := sds.BlockChain.GetBlockByHash(parentHash) - sds.Extractor.ExtractStateDiff(*parentBlock, *currentBlock) + stateDiffLocation, err := sds.Extractor.ExtractStateDiff(*parentBlock, *currentBlock) + if err != nil { + log.Error("Error extracting statediff", "block number", currentBlock.Number(), "error", err) + } else { + log.Info("Statediff extracted", "block number", currentBlock.Number(), "location", stateDiffLocation) + } } } +var eventsChannel chan core.ChainEvent func (sds *StateDiffService) Start(server *p2p.Server) error { - events := make(chan core.ChainEvent, 10) - sds.BlockChain.SubscribeChainEvent(events) - go sds.Loop(events) + log.Info("Starting statediff service") + eventsChannel := make(chan core.ChainEvent, 10) + sds.BlockChain.SubscribeChainEvent(eventsChannel) + go sds.Loop(eventsChannel) return nil } -func (StateDiffService) Stop() error { return nil } +func (StateDiffService) Stop() error { + log.Info("Stopping statediff service") + close(eventsChannel) + + return nil +}