Log common.Hash with hex instead of TerminalString/Bytes()

pull/1205/head
Kai Lee 5 years ago committed by Minh Doan
parent 4d41cd79c7
commit 593c881632
  1. 6
      consensus/consensus_v2.go
  2. 46
      core/blockchain.go
  3. 4
      core/chain_indexer.go
  4. 8
      core/headerchain.go
  5. 8
      core/rawdb/accessors_chain.go
  6. 4
      core/rawdb/accessors_indexes.go
  7. 40
      core/tx_pool.go
  8. 2
      core/types/block.go

@ -107,7 +107,7 @@ func (consensus *Consensus) announce(block *types.Block) {
consensus.PbftLog.AddMessage(pbftMsg)
consensus.getLogger().Debug().
Bytes("MsgblockHash", pbftMsg.BlockHash[:]).
Str("MsgblockHash", pbftMsg.BlockHash.Hex()).
Uint64("MsgViewID", pbftMsg.ViewID).
Uint64("MsgBlockNum", pbftMsg.BlockNum).
Msg("[Announce] Added Announce message in pbftLog")
@ -127,7 +127,7 @@ func (consensus *Consensus) announce(block *types.Block) {
Msg("[Announce] Cannot send announce message")
} else {
consensus.getLogger().Info().
Bytes("BlockHash", block.Hash().Bytes()).
Str("BlockHash", block.Hash().Hex()).
Uint64("BlockNum", block.NumberU64()).
Msg("[Announce] Sent Announce Message!!")
}
@ -470,7 +470,7 @@ func (consensus *Consensus) onPrepared(msg *msg_pb.Message) {
consensus.getLogger().Warn().
Uint64("MsgBlockNum", recvMsg.BlockNum).
Bytes("MsgBlockHash", recvMsg.BlockHash[:]).
Bytes("blockObjHash", blockObj.Header().Hash().Bytes()).
Str("blockObjHash", blockObj.Header().Hash().Hex()).
Msg("[OnPrepared] BlockHash not match")
return
}

@ -267,7 +267,7 @@ func (bc *BlockChain) loadLastState() error {
// Dangling block without a state associated, init from scratch
utils.Logger().Warn().
Str("number", currentBlock.Number().String()).
Bytes("hash", currentBlock.Hash().Bytes()).
Str("hash", currentBlock.Hash().Hex()).
Msg("Head state missing, repairing chain")
if err := bc.repair(&currentBlock); err != nil {
return err
@ -302,19 +302,19 @@ func (bc *BlockChain) loadLastState() error {
utils.Logger().Info().
Str("number", currentHeader.Number.String()).
Bytes("hash", currentHeader.Hash().Bytes()).
Str("hash", currentHeader.Hash().Hex()).
Str("td", headerTd.String()).
Str("age", common.PrettyAge(time.Unix(currentHeader.Time.Int64(), 0)).String()).
Msg("Loaded most recent local header")
utils.Logger().Info().
Str("number", currentBlock.Number().String()).
Bytes("hash", currentBlock.Hash().Bytes()).
Str("hash", currentBlock.Hash().Hex()).
Str("td", blockTd.String()).
Str("age", common.PrettyAge(time.Unix(currentBlock.Time().Int64(), 0)).String()).
Msg("Loaded most recent local full block")
utils.Logger().Info().
Str("number", currentFastBlock.Number().String()).
Bytes("hash", currentFastBlock.Hash().Bytes()).
Str("hash", currentFastBlock.Hash().Hex()).
Str("td", fastTd.String()).
Str("age", common.PrettyAge(time.Unix(currentFastBlock.Time().Int64(), 0)).String()).
Msg("Loaded most recent local fast block")
@ -395,7 +395,7 @@ func (bc *BlockChain) FastSyncCommitHead(hash common.Hash) error {
utils.Logger().Info().
Str("number", block.Number().String()).
Bytes("hash", hash.Bytes()).
Str("hash", hash.Hex()).
Msg("Committed new head block")
return nil
}
@ -500,7 +500,7 @@ func (bc *BlockChain) repair(head **types.Block) error {
if _, err := state.New((*head).Root(), bc.stateCache); err == nil {
utils.Logger().Info().
Str("number", (*head).Number().String()).
Bytes("hash", (*head).Hash().Bytes()).
Str("hash", (*head).Hash().Hex()).
Msg("Rewound blockchain to past state")
return nil
}
@ -755,8 +755,8 @@ func (bc *BlockChain) Stop() {
utils.Logger().Info().
Str("block", recent.Number().String()).
Bytes("hash", recent.Hash().Bytes()).
Bytes("root", recent.Root().Bytes()).
Str("hash", recent.Hash().Hex()).
Str("root", recent.Root().Hex()).
Msg("Writing cached state to disk")
if err := triedb.Commit(recent.Root(), true); err != nil {
utils.Logger().Error().Err(err).Msg("Failed to commit recent state trie")
@ -875,10 +875,10 @@ func (bc *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain [
if blockChain[i].NumberU64() != blockChain[i-1].NumberU64()+1 || blockChain[i].ParentHash() != blockChain[i-1].Hash() {
utils.Logger().Error().
Str("number", blockChain[i].Number().String()).
Bytes("hash", blockChain[i].Hash().Bytes()).
Bytes("parent", blockChain[i].ParentHash().Bytes()).
Str("hash", blockChain[i].Hash().Hex()).
Str("parent", blockChain[i].ParentHash().Hex()).
Str("prevnumber", blockChain[i-1].Number().String()).
Bytes("prevhash", blockChain[i-1].Hash().Bytes()).
Str("prevhash", blockChain[i-1].Hash().Hex()).
Msg("Non contiguous receipt insert")
return 0, fmt.Errorf("non contiguous insert: item %d is #%d [%x…], item %d is #%d [%x…] (parent [%x…])", i-1, blockChain[i-1].NumberU64(),
blockChain[i-1].Hash().Bytes()[:4], i, blockChain[i].NumberU64(), blockChain[i].Hash().Bytes()[:4], blockChain[i].ParentHash().Bytes()[:4])
@ -949,7 +949,7 @@ func (bc *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain [
Str("elapsed", common.PrettyDuration(time.Since(start)).String()).
Str("age", common.PrettyAge(time.Unix(head.Time().Int64(), 0)).String()).
Str("head", head.Number().String()).
Bytes("hash", head.Hash().Bytes()).
Str("hash", head.Hash().Hex()).
Str("size", common.StorageSize(bytes).String()).
Int32("ignored", stats.ignored).
Msg("Imported new block receipts")
@ -1095,7 +1095,7 @@ func (bc *BlockChain) InsertChain(chain types.Blocks) (int, error) {
header := block.Header()
header.Logger(utils.Logger()).Info().
Int("segmentIndex", idx).
Bytes("parentHash", header.ParentHash.Bytes()).
Str("parentHash", header.ParentHash.Hex()).
Msg("added block to chain")
if header.ShardStateHash != (common.Hash{}) {
@ -1124,10 +1124,10 @@ func (bc *BlockChain) insertChain(chain types.Blocks) (int, []interface{}, []*ty
// Chain broke ancestry, log a message (programming error) and skip insertion
utils.Logger().Error().
Str("number", chain[i].Number().String()).
Bytes("hash", chain[i].Hash().Bytes()).
Bytes("parent", chain[i].ParentHash().Bytes()).
Str("hash", chain[i].Hash().Hex()).
Str("parent", chain[i].ParentHash().Hex()).
Str("prevnumber", chain[i-1].Number().String()).
Bytes("prevhash", chain[i-1].Hash().Bytes()).
Str("prevhash", chain[i-1].Hash().Hex()).
Msg("Non contiguous block insert")
return 0, nil, nil, fmt.Errorf("non contiguous insert: item %d is #%d [%x…], item %d is #%d [%x…] (parent [%x…])", i-1, chain[i-1].NumberU64(),
@ -1274,7 +1274,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks) (int, []interface{}, []*ty
}
logger := utils.Logger().With().
Str("number", block.Number().String()).
Bytes("hash", block.Hash().Bytes()).
Str("hash", block.Hash().Hex()).
Int("uncles", len(block.Uncles())).
Int("txs", len(block.Transactions())).
Uint64("gas", block.GasUsed()).
@ -1344,7 +1344,7 @@ func (st *insertStats) report(chain []*types.Block, index int, cache common.Stor
Str("elapsed", common.PrettyDuration(elapsed).String()).
Float64("mgasps", float64(st.usedGas)*1000/float64(elapsed)).
Str("number", end.Number().String()).
Bytes("hash", end.Hash().Bytes()).
Str("hash", end.Hash().Hex()).
Str("cache", cache.String())
if timestamp := time.Unix(end.Time().Int64(), 0); time.Since(timestamp) > time.Minute {
@ -1451,18 +1451,18 @@ func (bc *BlockChain) reorg(oldBlock, newBlock *types.Block) error {
}
logEvent.
Str("number", commonBlock.Number().String()).
Bytes("hash", commonBlock.Hash().Bytes()).
Str("hash", commonBlock.Hash().Hex()).
Int("drop", len(oldChain)).
Bytes("dropfrom", oldChain[0].Hash().Bytes()).
Str("dropfrom", oldChain[0].Hash().Hex()).
Int("add", len(newChain)).
Bytes("addfrom", newChain[0].Hash().Bytes()).
Str("addfrom", newChain[0].Hash().Hex()).
Msg("Chain split detected")
} else {
utils.Logger().Error().
Str("oldnum", oldBlock.Number().String()).
Bytes("oldhash", oldBlock.Hash().Bytes()).
Str("oldhash", oldBlock.Hash().Hex()).
Str("newnum", newBlock.Number().String()).
Bytes("newhash", newBlock.Hash().Bytes()).
Str("newhash", newBlock.Hash().Hex()).
Msg("Impossible reorg, please file an issue")
}
// Insert the new chain, taking care of the proper incremental order

@ -286,8 +286,8 @@ func (c *ChainIndexer) newHead(head uint64, reorg bool) {
if syncedHead != c.checkpointHead {
c.log.Error().
Uint64("number", c.checkpointSections*c.sectionSize-1).
Str("expected", c.checkpointHead.TerminalString()).
Str("synced", syncedHead.TerminalString()).
Str("expected", c.checkpointHead.Hex()).
Str("synced", syncedHead.Hex()).
Msg("Synced chain does not match checkpoint")
return
}

@ -209,10 +209,10 @@ func (hc *HeaderChain) ValidateHeaderChain(chain []*types.Header, checkFreq int)
// Chain broke ancestry, log a message (programming error) and skip insertion
utils.Logger().Error().
Str("number", chain[i].Number.String()).
Str("hash", chain[i].Hash().TerminalString()).
Str("parent", chain[i].ParentHash.TerminalString()).
Str("hash", chain[i].Hash().Hex()).
Str("parent", chain[i].ParentHash.Hex()).
Str("prevnumber", chain[i-1].Number.String()).
Str("prevhash", chain[i-1].Hash().TerminalString()).
Str("prevhash", chain[i-1].Hash().Hex()).
Msg("Non contiguous header insert")
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,
@ -286,7 +286,7 @@ func (hc *HeaderChain) InsertHeaderChain(chain []*types.Header, writeHeader WhCa
Int("count", stats.processed).
Str("elapsed", common.PrettyDuration(time.Since(start)).String()).
Str("number", last.Number.String()).
Str("hash", last.Hash().TerminalString())
Str("hash", last.Hash().Hex())
if timestamp := time.Unix(last.Time.Int64(), 0); time.Since(timestamp) > time.Minute {
context = context.Str("age", common.PrettyAge(timestamp).String())

@ -150,7 +150,7 @@ func ReadHeader(db DatabaseReader, hash common.Hash, number uint64) *types.Heade
}
header := new(types.Header)
if err := rlp.Decode(bytes.NewReader(data), header); err != nil {
utils.Logger().Error().Err(err).Bytes("hash", hash.Bytes()).Msg("Invalid block header RLP")
utils.Logger().Error().Err(err).Str("hash", hash.Hex()).Msg("Invalid block header RLP")
return nil
}
return header
@ -219,7 +219,7 @@ func ReadBody(db DatabaseReader, hash common.Hash, number uint64) *types.Body {
}
body := new(types.Body)
if err := rlp.Decode(bytes.NewReader(data), body); err != nil {
utils.Logger().Error().Err(err).Bytes("hash", hash.Bytes()).Msg("Invalid block body RLP")
utils.Logger().Error().Err(err).Str("hash", hash.Hex()).Msg("Invalid block body RLP")
return nil
}
return body
@ -249,7 +249,7 @@ func ReadTd(db DatabaseReader, hash common.Hash, number uint64) *big.Int {
}
td := new(big.Int)
if err := rlp.Decode(bytes.NewReader(data), td); err != nil {
utils.Logger().Error().Err(err).Bytes("hash", hash.Bytes()).Msg("Invalid block total difficulty RLP")
utils.Logger().Error().Err(err).Str("hash", hash.Hex()).Msg("Invalid block total difficulty RLP")
return nil
}
return td
@ -283,7 +283,7 @@ func ReadReceipts(db DatabaseReader, hash common.Hash, number uint64) types.Rece
// Convert the receipts from their storage form to their internal representation
storageReceipts := []*types.ReceiptForStorage{}
if err := rlp.DecodeBytes(data, &storageReceipts); err != nil {
utils.Logger().Error().Err(err).Bytes("hash", hash.Bytes()).Msg("Invalid receipt array RLP")
utils.Logger().Error().Err(err).Str("hash", hash.Hex()).Msg("Invalid receipt array RLP")
return nil
}
receipts := make(types.Receipts, len(storageReceipts))

@ -74,7 +74,7 @@ func ReadTransaction(db DatabaseReader, hash common.Hash) (*types.Transaction, c
if body == nil || len(body.Transactions) <= int(txIndex) {
utils.Logger().Error().
Uint64("number", blockNumber).
Bytes("hash", blockHash.Bytes()).
Str("hash", blockHash.Hex()).
Uint64("index", txIndex).
Msg("Transaction referenced missing")
return nil, common.Hash{}, 0, 0
@ -93,7 +93,7 @@ func ReadReceipt(db DatabaseReader, hash common.Hash) (*types.Receipt, common.Ha
if len(receipts) <= int(receiptIndex) {
utils.Logger().Error().
Uint64("number", blockNumber).
Bytes("hash", blockHash.Bytes()).
Str("hash", blockHash.Hex()).
Uint64("index", receiptIndex).
Msg("Receipt refereced missing")
return nil, common.Hash{}, 0, 0

@ -393,7 +393,7 @@ func (pool *TxPool) reset(oldHead, newHead *types.Header) {
if rem = pool.chain.GetBlock(rem.ParentHash(), rem.NumberU64()-1); rem == nil {
utils.Logger().Error().
Str("block", oldHead.Number.String()).
Str("hash", oldHead.Hash().TerminalString()).
Str("hash", oldHead.Hash().Hex()).
Msg("Unrooted old chain seen by tx pool")
return
}
@ -403,7 +403,7 @@ func (pool *TxPool) reset(oldHead, newHead *types.Header) {
if add = pool.chain.GetBlock(add.ParentHash(), add.NumberU64()-1); add == nil {
utils.Logger().Error().
Str("block", newHead.Number.String()).
Str("hash", newHead.Hash().TerminalString()).
Str("hash", newHead.Hash().Hex()).
Msg("Unrooted new chain seen by tx pool")
return
}
@ -413,7 +413,7 @@ func (pool *TxPool) reset(oldHead, newHead *types.Header) {
if rem = pool.chain.GetBlock(rem.ParentHash(), rem.NumberU64()-1); rem == nil {
utils.Logger().Error().
Str("block", oldHead.Number.String()).
Str("hash", oldHead.Hash().TerminalString()).
Str("hash", oldHead.Hash().Hex()).
Msg("Unrooted old chain seen by tx pool")
return
}
@ -421,7 +421,7 @@ func (pool *TxPool) reset(oldHead, newHead *types.Header) {
if add = pool.chain.GetBlock(add.ParentHash(), add.NumberU64()-1); add == nil {
utils.Logger().Error().
Str("block", newHead.Number.String()).
Str("hash", newHead.Hash().TerminalString()).
Str("hash", newHead.Hash().Hex()).
Msg("Unrooted new chain seen by tx pool")
return
}
@ -649,12 +649,12 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (bool, error) {
// If the transaction is already known, discard it
hash := tx.Hash()
if pool.all.Get(hash) != nil {
logger.Warn().Str("hash", hash.TerminalString()).Msg("Discarding already known transaction")
logger.Warn().Str("hash", hash.Hex()).Msg("Discarding already known transaction")
return false, fmt.Errorf("known transaction: %x", hash)
}
// If the transaction fails basic validation, discard it
if err := pool.validateTx(tx, local); err != nil {
logger.Warn().Err(err).Str("hash", hash.TerminalString()).Msg("Discarding invalid transaction")
logger.Warn().Err(err).Str("hash", hash.Hex()).Msg("Discarding invalid transaction")
invalidTxCounter.Inc(1)
return false, err
}
@ -663,7 +663,7 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (bool, error) {
// If the new transaction is underpriced, don't accept it
if !local && pool.priced.Underpriced(tx, pool.locals) {
logger.Warn().
Str("hash", hash.TerminalString()).
Str("hash", hash.Hex()).
Str("price", tx.GasPrice().String()).
Msg("Discarding underpriced transaction")
underpricedTxCounter.Inc(1)
@ -673,7 +673,7 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (bool, error) {
drop := pool.priced.Discard(pool.all.Count()-int(pool.config.GlobalSlots+pool.config.GlobalQueue-1), pool.locals)
for _, tx := range drop {
logger.Warn().
Str("hash", tx.Hash().TerminalString()).
Str("hash", tx.Hash().Hex()).
Str("price", tx.GasPrice().String()).
Msg("Discarding freshly underpriced transaction")
underpricedTxCounter.Inc(1)
@ -700,7 +700,7 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (bool, error) {
pool.journalTx(from, tx)
logger.Warn().
Str("hash", tx.Hash().TerminalString()).
Str("hash", tx.Hash().Hex()).
Interface("from", from).
Interface("to", tx.To()).
Msg("Pooled new executable transaction")
@ -725,7 +725,7 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (bool, error) {
pool.journalTx(from, tx)
logger.Warn().
Str("hash", hash.TerminalString()).
Str("hash", hash.Hex()).
Interface("from", from).
Interface("to", tx.To()).
Msg("Pooled new future transaction")
@ -991,7 +991,7 @@ func (pool *TxPool) promoteExecutables(accounts []common.Address) {
// Drop all transactions that are deemed too old (low nonce)
for _, tx := range list.Forward(pool.currentState.GetNonce(addr)) {
hash := tx.Hash()
logger.Warn().Str("hash", hash.TerminalString()).Msg("Removed old queued transaction")
logger.Warn().Str("hash", hash.Hex()).Msg("Removed old queued transaction")
pool.all.Remove(hash)
pool.priced.Removed()
}
@ -999,7 +999,7 @@ func (pool *TxPool) promoteExecutables(accounts []common.Address) {
drops, _ := list.Filter(pool.currentState.GetBalance(addr), pool.currentMaxGas)
for _, tx := range drops {
hash := tx.Hash()
logger.Warn().Str("hash", hash.TerminalString()).Msg("Removed unpayable queued transaction")
logger.Warn().Str("hash", hash.Hex()).Msg("Removed unpayable queued transaction")
pool.all.Remove(hash)
pool.priced.Removed()
queuedNofundsCounter.Inc(1)
@ -1008,7 +1008,7 @@ func (pool *TxPool) promoteExecutables(accounts []common.Address) {
for _, tx := range list.Ready(pool.pendingState.GetNonce(addr)) {
hash := tx.Hash()
if pool.promoteTx(addr, hash, tx) {
logger.Warn().Str("hash", hash.TerminalString()).Msg("Promoting queued transaction")
logger.Warn().Str("hash", hash.Hex()).Msg("Promoting queued transaction")
promoted = append(promoted, tx)
}
}
@ -1019,7 +1019,7 @@ func (pool *TxPool) promoteExecutables(accounts []common.Address) {
pool.all.Remove(hash)
pool.priced.Removed()
queuedRateLimitCounter.Inc(1)
logger.Warn().Str("hash", hash.TerminalString()).Msg("Removed cap-exceeding queued transaction")
logger.Warn().Str("hash", hash.Hex()).Msg("Removed cap-exceeding queued transaction")
}
}
// Delete the entire queue entry if it became empty.
@ -1072,7 +1072,7 @@ func (pool *TxPool) promoteExecutables(accounts []common.Address) {
if nonce := tx.Nonce(); pool.pendingState.GetNonce(offenders[i]) > nonce {
pool.pendingState.SetNonce(offenders[i], nonce)
}
logger.Warn().Str("hash", hash.TerminalString()).Msg("Removed fairness-exceeding pending transaction")
logger.Warn().Str("hash", hash.Hex()).Msg("Removed fairness-exceeding pending transaction")
}
pending--
}
@ -1094,7 +1094,7 @@ func (pool *TxPool) promoteExecutables(accounts []common.Address) {
if nonce := tx.Nonce(); pool.pendingState.GetNonce(addr) > nonce {
pool.pendingState.SetNonce(addr, nonce)
}
logger.Warn().Str("hash", hash.TerminalString()).Msg("Removed fairness-exceeding pending transaction")
logger.Warn().Str("hash", hash.Hex()).Msg("Removed fairness-exceeding pending transaction")
}
pending--
}
@ -1157,7 +1157,7 @@ func (pool *TxPool) demoteUnexecutables() {
// Drop all transactions that are deemed too old (low nonce)
for _, tx := range list.Forward(nonce) {
hash := tx.Hash()
logger.Warn().Str("hash", hash.TerminalString()).Msg("Removed old pending transaction")
logger.Warn().Str("hash", hash.Hex()).Msg("Removed old pending transaction")
pool.all.Remove(hash)
pool.priced.Removed()
}
@ -1165,21 +1165,21 @@ func (pool *TxPool) demoteUnexecutables() {
drops, invalids := list.Filter(pool.currentState.GetBalance(addr), pool.currentMaxGas)
for _, tx := range drops {
hash := tx.Hash()
logger.Warn().Str("hash", hash.TerminalString()).Msg("Removed unpayable pending transaction")
logger.Warn().Str("hash", hash.Hex()).Msg("Removed unpayable pending transaction")
pool.all.Remove(hash)
pool.priced.Removed()
pendingNofundsCounter.Inc(1)
}
for _, tx := range invalids {
hash := tx.Hash()
logger.Warn().Str("hash", hash.TerminalString()).Msg("Demoting pending transaction")
logger.Warn().Str("hash", hash.Hex()).Msg("Demoting pending transaction")
pool.enqueueTx(hash, tx)
}
// If there's a gap in front, alert (should never happen) and postpone all transactions
if list.Len() > 0 && list.txs.Get(nonce) == nil {
for _, tx := range list.Cap(0) {
hash := tx.Hash()
logger.Error().Str("hash", hash.TerminalString()).Msg("Demoting invalidated transaction")
logger.Error().Str("hash", hash.Hex()).Msg("Demoting invalidated transaction")
pool.enqueueTx(hash, tx)
}
}

@ -121,7 +121,7 @@ func (h *Header) Size() common.StorageSize {
func (h *Header) Logger(logger *zerolog.Logger) *zerolog.Logger {
nlogger := logger.
With().
Bytes("blockHash", h.Hash().Bytes()).
Str("blockHash", h.Hash().Hex()).
Uint32("blockShard", h.ShardID).
Str("blockEpoch", h.Epoch.String()).
Str("blockNumber", h.Number.String()).

Loading…
Cancel
Save