aboutsummaryrefslogtreecommitdiffstats
path: root/core/database_util.go
diff options
context:
space:
mode:
Diffstat (limited to 'core/database_util.go')
-rw-r--r--core/database_util.go47
1 files changed, 21 insertions, 26 deletions
diff --git a/core/database_util.go b/core/database_util.go
index 68263f8d8..bcd99be5f 100644
--- a/core/database_util.go
+++ b/core/database_util.go
@@ -106,7 +106,7 @@ func GetBlockNumber(db ethdb.Database, hash common.Hash) uint64 {
}
header := new(types.Header)
if err := rlp.Decode(bytes.NewReader(data), header); err != nil {
- log.Crit(fmt.Sprintf("failed to decode block header: %v", err))
+ log.Crit("Failed to decode block header", "err", err)
}
return header.Number.Uint64()
}
@@ -166,7 +166,7 @@ func GetHeader(db ethdb.Database, hash common.Hash, number uint64) *types.Header
}
header := new(types.Header)
if err := rlp.Decode(bytes.NewReader(data), header); err != nil {
- log.Error(fmt.Sprintf("invalid block header RLP for hash %x: %v", hash, err))
+ log.Error("Invalid block header RLP", "hash", hash, "err", err)
return nil
}
return header
@@ -190,7 +190,7 @@ func GetBody(db ethdb.Database, hash common.Hash, number uint64) *types.Body {
}
body := new(types.Body)
if err := rlp.Decode(bytes.NewReader(data), body); err != nil {
- log.Error(fmt.Sprintf("invalid block body RLP for hash %x: %v", hash, err))
+ log.Error("Invalid block body RLP", "hash", hash, "err", err)
return nil
}
return body
@@ -208,7 +208,7 @@ func GetTd(db ethdb.Database, hash common.Hash, number uint64) *big.Int {
}
td := new(big.Int)
if err := rlp.Decode(bytes.NewReader(data), td); err != nil {
- log.Error(fmt.Sprintf("invalid block total difficulty RLP for hash %x: %v", hash, err))
+ log.Error("Invalid block total difficulty RLP", "hash", hash, "err", err)
return nil
}
return td
@@ -246,7 +246,7 @@ func GetBlockReceipts(db ethdb.Database, hash common.Hash, number uint64) types.
}
storageReceipts := []*types.ReceiptForStorage{}
if err := rlp.DecodeBytes(data, &storageReceipts); err != nil {
- log.Error(fmt.Sprintf("invalid receipt array RLP for hash %x: %v", hash, err))
+ log.Error("Invalid receipt array RLP", "hash", hash, "err", err)
return nil
}
receipts := make(types.Receipts, len(storageReceipts))
@@ -285,15 +285,15 @@ func GetTransaction(db ethdb.Database, hash common.Hash) (*types.Transaction, co
}
// GetReceipt returns a receipt by hash
-func GetReceipt(db ethdb.Database, txHash common.Hash) *types.Receipt {
- data, _ := db.Get(append(receiptsPrefix, txHash[:]...))
+func GetReceipt(db ethdb.Database, hash common.Hash) *types.Receipt {
+ data, _ := db.Get(append(receiptsPrefix, hash[:]...))
if len(data) == 0 {
return nil
}
var receipt types.ReceiptForStorage
err := rlp.DecodeBytes(data, &receipt)
if err != nil {
- log.Debug(fmt.Sprint("GetReceipt err:", err))
+ log.Error("Invalid receipt RLP", "hash", hash, "err", err)
}
return (*types.Receipt)(&receipt)
}
@@ -302,7 +302,7 @@ func GetReceipt(db ethdb.Database, txHash common.Hash) *types.Receipt {
func WriteCanonicalHash(db ethdb.Database, hash common.Hash, number uint64) error {
key := append(append(headerPrefix, encodeBlockNumber(number)...), numSuffix...)
if err := db.Put(key, hash.Bytes()); err != nil {
- log.Crit(fmt.Sprintf("failed to store number to hash mapping into database: %v", err))
+ log.Crit("Failed to store number to hash mapping", "err", err)
}
return nil
}
@@ -310,7 +310,7 @@ func WriteCanonicalHash(db ethdb.Database, hash common.Hash, number uint64) erro
// WriteHeadHeaderHash stores the head header's hash.
func WriteHeadHeaderHash(db ethdb.Database, hash common.Hash) error {
if err := db.Put(headHeaderKey, hash.Bytes()); err != nil {
- log.Crit(fmt.Sprintf("failed to store last header's hash into database: %v", err))
+ log.Crit("Failed to store last header's hash", "err", err)
}
return nil
}
@@ -318,7 +318,7 @@ func WriteHeadHeaderHash(db ethdb.Database, hash common.Hash) error {
// WriteHeadBlockHash stores the head block's hash.
func WriteHeadBlockHash(db ethdb.Database, hash common.Hash) error {
if err := db.Put(headBlockKey, hash.Bytes()); err != nil {
- log.Crit(fmt.Sprintf("failed to store last block's hash into database: %v", err))
+ log.Crit("Failed to store last block's hash", "err", err)
}
return nil
}
@@ -326,7 +326,7 @@ func WriteHeadBlockHash(db ethdb.Database, hash common.Hash) error {
// WriteHeadFastBlockHash stores the fast head block's hash.
func WriteHeadFastBlockHash(db ethdb.Database, hash common.Hash) error {
if err := db.Put(headFastKey, hash.Bytes()); err != nil {
- log.Crit(fmt.Sprintf("failed to store last fast block's hash into database: %v", err))
+ log.Crit("Failed to store last fast block's hash", "err", err)
}
return nil
}
@@ -342,13 +342,12 @@ func WriteHeader(db ethdb.Database, header *types.Header) error {
encNum := encodeBlockNumber(num)
key := append(blockHashPrefix, hash...)
if err := db.Put(key, encNum); err != nil {
- log.Crit(fmt.Sprintf("failed to store hash to number mapping into database: %v", err))
+ log.Crit("Failed to store hash to number mapping", "err", err)
}
key = append(append(headerPrefix, encNum...), hash...)
if err := db.Put(key, data); err != nil {
- log.Crit(fmt.Sprintf("failed to store header into database: %v", err))
+ log.Crit("Failed to store header", "err", err)
}
- log.Debug(fmt.Sprintf("stored header #%v [%x…]", header.Number, hash[:4]))
return nil
}
@@ -365,9 +364,8 @@ func WriteBody(db ethdb.Database, hash common.Hash, number uint64, body *types.B
func WriteBodyRLP(db ethdb.Database, hash common.Hash, number uint64, rlp rlp.RawValue) error {
key := append(append(bodyPrefix, encodeBlockNumber(number)...), hash.Bytes()...)
if err := db.Put(key, rlp); err != nil {
- log.Crit(fmt.Sprintf("failed to store block body into database: %v", err))
+ log.Crit("Failed to store block body", "err", err)
}
- log.Debug(fmt.Sprintf("stored block body [%x…]", hash.Bytes()[:4]))
return nil
}
@@ -379,9 +377,8 @@ func WriteTd(db ethdb.Database, hash common.Hash, number uint64, td *big.Int) er
}
key := append(append(append(headerPrefix, encodeBlockNumber(number)...), hash.Bytes()...), tdSuffix...)
if err := db.Put(key, data); err != nil {
- log.Crit(fmt.Sprintf("failed to store block total difficulty into database: %v", err))
+ log.Crit("Failed to store block total difficulty", "err", err)
}
- log.Debug(fmt.Sprintf("stored block total difficulty [%x…]: %v", hash.Bytes()[:4], td))
return nil
}
@@ -414,9 +411,8 @@ func WriteBlockReceipts(db ethdb.Database, hash common.Hash, number uint64, rece
// Store the flattened receipt slice
key := append(append(blockReceiptsPrefix, encodeBlockNumber(number)...), hash.Bytes()...)
if err := db.Put(key, bytes); err != nil {
- log.Crit(fmt.Sprintf("failed to store block receipts into database: %v", err))
+ log.Crit("Failed to store block receipts", "err", err)
}
- log.Debug(fmt.Sprintf("stored block receipts [%x…]", hash.Bytes()[:4]))
return nil
}
@@ -434,7 +430,7 @@ func WriteTransactions(db ethdb.Database, block *types.Block) error {
if err != nil {
return err
}
- if err := batch.Put(tx.Hash().Bytes(), data); err != nil {
+ if err = batch.Put(tx.Hash().Bytes(), data); err != nil {
return err
}
// Encode and queue up the transaction metadata for storage
@@ -457,7 +453,7 @@ func WriteTransactions(db ethdb.Database, block *types.Block) error {
}
// Write the scheduled data into the database
if err := batch.Write(); err != nil {
- log.Crit(fmt.Sprintf("failed to store transactions into database: %v", err))
+ log.Crit("Failed to store transactions", "err", err)
}
return nil
}
@@ -489,7 +485,7 @@ func WriteReceipts(db ethdb.Database, receipts types.Receipts) error {
}
// Write the scheduled data into the database
if err := batch.Write(); err != nil {
- log.Crit(fmt.Sprintf("failed to store receipts into database: %v", err))
+ log.Crit("Failed to store receipts", "err", err)
}
return nil
}
@@ -595,7 +591,7 @@ func WritePreimages(db ethdb.Database, number uint64, preimages map[common.Hash]
for hash, preimage := range preimages {
if _, err := table.Get(hash.Bytes()); err != nil {
batch.Put(hash.Bytes(), preimage)
- hitCount += 1
+ hitCount++
}
}
preimageCounter.Inc(int64(len(preimages)))
@@ -604,7 +600,6 @@ func WritePreimages(db ethdb.Database, number uint64, preimages map[common.Hash]
if err := batch.Write(); err != nil {
return fmt.Errorf("preimage write fail for block %d: %v", number, err)
}
- log.Debug(fmt.Sprintf("%d preimages in block %d, including %d new", len(preimages), number, hitCount))
}
return nil
}