diff options
author | Péter Szilágyi <peterke@gmail.com> | 2017-02-28 19:35:17 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2017-02-28 21:03:20 +0800 |
commit | e588e0ca2b3b615af0ecfd5679c42df8f1cc4272 (patch) | |
tree | c37e95792ed9f17209b7de26a5d6047ac915db2a /core/headerchain.go | |
parent | d4f60d362b8fcf82db1accf89c146a2a71375841 (diff) | |
download | go-tangerine-e588e0ca2b3b615af0ecfd5679c42df8f1cc4272.tar.gz go-tangerine-e588e0ca2b3b615af0ecfd5679c42df8f1cc4272.tar.zst go-tangerine-e588e0ca2b3b615af0ecfd5679c42df8f1cc4272.zip |
all: next batch of log polishes to contextual versions
Diffstat (limited to 'core/headerchain.go')
-rw-r--r-- | core/headerchain.go | 37 |
1 files changed, 15 insertions, 22 deletions
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) } } |