Clean up error logging

This commit is contained in:
Elizabeth Engelman 2019-01-02 17:23:03 -06:00
parent ecd34978d3
commit 99a29191b1
2 changed files with 25 additions and 15 deletions

View File

@ -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

View File

@ -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
}