From 7be6104114a2b482b5a2367b76e663e9eb9adb84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Thu, 25 Apr 2019 09:48:33 +0300 Subject: [PATCH] core/rawdb: tiny review nit fixes --- core/rawdb/accessors_indexes.go | 12 +++++------- core/rawdb/accessors_indexes_test.go | 3 +-- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/core/rawdb/accessors_indexes.go b/core/rawdb/accessors_indexes.go index b5dde74fe6..423145a760 100644 --- a/core/rawdb/accessors_indexes.go +++ b/core/rawdb/accessors_indexes.go @@ -34,18 +34,16 @@ func ReadTxLookupEntry(db ethdb.Reader, hash common.Hash) *uint64 { if len(data) == 0 { return nil } - // + // Database v6 tx lookup just stores the block number if len(data) < common.HashLength { - var number big.Int - number.SetBytes(data) - numberU64 := number.Uint64() - return &numberU64 + number := new(big.Int).SetBytes(data).Uint64() + return &number } - // Database v4 tx lookup format just stores the hash. + // Database v4-v5 tx lookup format just stores the hash if len(data) == common.HashLength { return ReadHeaderNumber(db, common.BytesToHash(data)) } - // Finally try database v3 tx lookup format. + // Finally try database v3 tx lookup format var entry LegacyTxLookupEntry if err := rlp.DecodeBytes(data, &entry); err != nil { log.Error("Invalid transaction lookup entry RLP", "hash", hash, "blob", data, "err", err) diff --git a/core/rawdb/accessors_indexes_test.go b/core/rawdb/accessors_indexes_test.go index 4a5bd2e1f6..c09bff0101 100644 --- a/core/rawdb/accessors_indexes_test.go +++ b/core/rawdb/accessors_indexes_test.go @@ -39,7 +39,7 @@ func TestLookupStorage(t *testing.T) { }, }, { - "DatabaseV4", + "DatabaseV4-V5", func(db ethdb.Writer, block *types.Block) { for _, tx := range block.Transactions() { db.Put(txLookupKey(tx.Hash()), block.Hash().Bytes()) @@ -64,7 +64,6 @@ func TestLookupStorage(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { - db := NewMemoryDatabase() tx1 := types.NewTransaction(1, common.BytesToAddress([]byte{0x11}), big.NewInt(111), 1111, big.NewInt(11111), []byte{0x11, 0x11, 0x11})