From e588e0ca2b3b615af0ecfd5679c42df8f1cc4272 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Tue, 28 Feb 2017 13:35:17 +0200 Subject: all: next batch of log polishes to contextual versions --- core/headerchain.go | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) (limited to 'core/headerchain.go') diff --git a/core/headerchain.go b/core/headerchain.go index a0550a428..775321bc6 100644 --- a/core/headerchain.go +++ b/core/headerchain.go @@ -101,7 +101,7 @@ func NewHeaderChain(chainDb ethdb.Database, config *params.ChainConfig, getValid if err != nil { return nil, err } - log.Info(fmt.Sprint("WARNING: Wrote default ethereum genesis block")) + log.Warn("Wrote default Ethereum genesis block") hc.genesisHeader = genesisBlock.Header() } @@ -154,12 +154,11 @@ func (hc *HeaderChain) WriteHeader(header *types.Header) (status WriteStatus, er // Irrelevant of the canonical status, write the td and header to the database if err := hc.WriteTd(hash, number, externTd); err != nil { - log.Crit(fmt.Sprintf("failed to write header total difficulty: %v", err)) + log.Crit("Failed to write header total difficulty", "err", err) } if err := WriteHeader(hc.chainDb, header); err != nil { - log.Crit(fmt.Sprintf("failed to write header contents: %v", err)) + log.Crit("Failed to write header content", "err", err) } - // If the total difficulty is higher than our known, add it to the canonical chain // Second clause in the if statement reduces the vulnerability to selfish mining. // Please refer to http://www.cs.cornell.edu/~ie53/publications/btcProcFC.pdf @@ -185,15 +184,13 @@ func (hc *HeaderChain) WriteHeader(header *types.Header) (status WriteStatus, er headNumber = headHeader.Number.Uint64() - 1 headHeader = hc.GetHeader(headHash, headNumber) } - // Extend the canonical chain with the new header if err := WriteCanonicalHash(hc.chainDb, hash, number); err != nil { - log.Crit(fmt.Sprintf("failed to insert header number: %v", err)) + log.Crit("Failed to insert header number", "err", err) } if err := WriteHeadHeaderHash(hc.chainDb, hash); err != nil { - log.Crit(fmt.Sprintf("failed to insert head header hash: %v", err)) + log.Crit("Failed to insert head header hash", "err", err) } - hc.currentHeaderHash, hc.currentHeader = hash, types.CopyHeader(header) status = CanonStatTy @@ -227,11 +224,11 @@ func (hc *HeaderChain) InsertHeaderChain(chain []*types.Header, checkFreq int, w for i := 1; i < len(chain); i++ { if chain[i].Number.Uint64() != chain[i-1].Number.Uint64()+1 || chain[i].ParentHash != chain[i-1].Hash() { // Chain broke ancestry, log a messge (programming error) and skip insertion - failure := fmt.Errorf("non contiguous insert: item %d is #%d [%x…], item %d is #%d [%x…] (parent [%x…])", - i-1, chain[i-1].Number.Uint64(), chain[i-1].Hash().Bytes()[:4], i, chain[i].Number.Uint64(), chain[i].Hash().Bytes()[:4], chain[i].ParentHash.Bytes()[:4]) + log.Error("Non contiguous header insert", "number", chain[i].Number, "hash", chain[i].Hash(), + "parent", chain[i].ParentHash, "prevnumber", chain[i-1].Number, "prevhash", chain[i-1].Hash()) - log.Error(fmt.Sprint(failure.Error())) - return 0, failure + return 0, fmt.Errorf("non contiguous insert: item %d is #%d [%x…], item %d is #%d [%x…] (parent [%x…])", i-1, chain[i-1].Number, + chain[i-1].Hash().Bytes()[:4], i, chain[i].Number, chain[i].Hash().Bytes()[:4], chain[i].ParentHash[:4]) } } // Collect some import statistics to report on @@ -316,7 +313,7 @@ func (hc *HeaderChain) InsertHeaderChain(chain []*types.Header, checkFreq int, w for i, header := range chain { // Short circuit insertion if shutting down if hc.procInterrupt() { - log.Debug(fmt.Sprint("premature abort during header chain processing")) + log.Debug("Premature abort during headers processing") break } hash := header.Hash() @@ -332,13 +329,9 @@ func (hc *HeaderChain) InsertHeaderChain(chain []*types.Header, checkFreq int, w stats.processed++ } // Report some public statistics so the user has a clue what's going on - first, last := chain[0], chain[len(chain)-1] - - ignored := "" - if stats.ignored > 0 { - ignored = fmt.Sprintf(" (%d ignored)", stats.ignored) - } - log.Info(fmt.Sprintf("imported %4d headers%s in %9v. #%v [%x… / %x…]", stats.processed, ignored, common.PrettyDuration(time.Since(start)), last.Number, first.Hash().Bytes()[:4], last.Hash().Bytes()[:4])) + last := chain[len(chain)-1] + log.Info("Imported new block headers", "count", stats.processed, "number", last.Number, "hash", last.Hash(), + "elapsed", common.PrettyDuration(time.Since(start)), "ignored", stats.ignored) return 0, nil } @@ -445,7 +438,7 @@ func (hc *HeaderChain) CurrentHeader() *types.Header { // SetCurrentHeader sets the current head header of the canonical chain. func (hc *HeaderChain) SetCurrentHeader(head *types.Header) { if err := WriteHeadHeaderHash(hc.chainDb, head.Hash()); err != nil { - log.Crit(fmt.Sprintf("failed to insert head header hash: %v", err)) + log.Crit("Failed to insert head header hash", "err", err) } hc.currentHeader = head hc.currentHeaderHash = head.Hash() @@ -488,7 +481,7 @@ func (hc *HeaderChain) SetHead(head uint64, delFn DeleteCallback) { hc.currentHeaderHash = hc.currentHeader.Hash() if err := WriteHeadHeaderHash(hc.chainDb, hc.currentHeaderHash); err != nil { - log.Crit(fmt.Sprintf("failed to reset head header hash: %v", err)) + log.Crit("Failed to reset head header hash", "err", err) } } -- cgit v1.2.3