From ced5965ef798e1975064123377289b7004f89567 Mon Sep 17 00:00:00 2001
From: Andrew Ashikhmin <34320705+yperbasis@users.noreply.github.com>
Date: Mon, 13 Sep 2021 15:59:18 +0200
Subject: [PATCH] Remove ReceiptsKey in favour of EncodeBlockNumber (#2681)

---
 common/dbutils/composite_keys.go |  7 -------
 core/rawdb/accessors_chain.go    | 12 ++++++------
 2 files changed, 6 insertions(+), 13 deletions(-)

diff --git a/common/dbutils/composite_keys.go b/common/dbutils/composite_keys.go
index 19df9c2f6c..c96592c871 100644
--- a/common/dbutils/composite_keys.go
+++ b/common/dbutils/composite_keys.go
@@ -42,13 +42,6 @@ func BlockBodyKey(number uint64, hash common.Hash) []byte {
 	return k
 }
 
-// ReceiptsKey = blockN (uint64 big endian)
-func ReceiptsKey(blockNumber uint64) []byte {
-	newK := make([]byte, 8)
-	binary.BigEndian.PutUint64(newK, blockNumber)
-	return newK
-}
-
 // LogKey = blockN (uint64 big endian) + txId (uint32 big endian)
 func LogKey(blockNumber uint64, txId uint32) []byte {
 	newK := make([]byte, 8+4)
diff --git a/core/rawdb/accessors_chain.go b/core/rawdb/accessors_chain.go
index ef6ad7c0dd..71db385d8d 100644
--- a/core/rawdb/accessors_chain.go
+++ b/core/rawdb/accessors_chain.go
@@ -549,7 +549,7 @@ func DeleteTd(db kv.Deleter, hash common.Hash, number uint64) error {
 // HasReceipts verifies the existence of all the transaction receipts belonging
 // to a block.
 func HasReceipts(db kv.Has, hash common.Hash, number uint64) bool {
-	if has, err := db.Has(kv.Receipts, dbutils.ReceiptsKey(number)); !has || err != nil {
+	if has, err := db.Has(kv.Receipts, dbutils.EncodeBlockNumber(number)); !has || err != nil {
 		return false
 	}
 	return true
@@ -560,7 +560,7 @@ func HasReceipts(db kv.Has, hash common.Hash, number uint64) bool {
 // should not be used. Use ReadReceipts instead if the metadata is needed.
 func ReadRawReceipts(db kv.Tx, blockNum uint64) types.Receipts {
 	// Retrieve the flattened receipt slice
-	data, err := db.GetOne(kv.Receipts, dbutils.ReceiptsKey(blockNum))
+	data, err := db.GetOne(kv.Receipts, dbutils.EncodeBlockNumber(blockNum))
 	if err != nil {
 		log.Error("ReadRawReceipts failed", "err", err)
 	}
@@ -655,7 +655,7 @@ func WriteReceipts(tx kv.Putter, number uint64, receipts types.Receipts) error {
 		return fmt.Errorf("encode block receipts for block %d: %v", number, err)
 	}
 
-	if err = tx.Put(kv.Receipts, dbutils.ReceiptsKey(number), buf.Bytes()); err != nil {
+	if err = tx.Put(kv.Receipts, dbutils.EncodeBlockNumber(number), buf.Bytes()); err != nil {
 		return fmt.Errorf("writing receipts for block %d: %v", number, err)
 	}
 	return nil
@@ -687,7 +687,7 @@ func AppendReceipts(tx kv.RwTx, blockNumber uint64, receipts types.Receipts) err
 		return fmt.Errorf("encode block receipts for block %d: %v", blockNumber, err)
 	}
 
-	if err = tx.Append(kv.Receipts, dbutils.ReceiptsKey(blockNumber), buf.Bytes()); err != nil {
+	if err = tx.Append(kv.Receipts, dbutils.EncodeBlockNumber(blockNumber), buf.Bytes()); err != nil {
 		return fmt.Errorf("writing receipts for block %d: %v", blockNumber, err)
 	}
 	return nil
@@ -695,7 +695,7 @@ func AppendReceipts(tx kv.RwTx, blockNumber uint64, receipts types.Receipts) err
 
 // DeleteReceipts removes all receipt data associated with a block hash.
 func DeleteReceipts(db kv.RwTx, number uint64) error {
-	if err := db.Delete(kv.Receipts, dbutils.ReceiptsKey(number), nil); err != nil {
+	if err := db.Delete(kv.Receipts, dbutils.EncodeBlockNumber(number), nil); err != nil {
 		return fmt.Errorf("receipts delete failed: %d, %w", number, err)
 	}
 
@@ -711,7 +711,7 @@ func DeleteReceipts(db kv.RwTx, number uint64) error {
 
 // DeleteNewerReceipts removes all receipt for given block number or newer
 func DeleteNewerReceipts(db kv.RwTx, number uint64) error {
-	if err := db.ForEach(kv.Receipts, dbutils.ReceiptsKey(number), func(k, v []byte) error {
+	if err := db.ForEach(kv.Receipts, dbutils.EncodeBlockNumber(number), func(k, v []byte) error {
 		return db.Delete(kv.Receipts, k, nil)
 	}); err != nil {
 		return err
-- 
GitLab