From b1862e14959894f1d9808c050b5a8bfd0b0804c6 Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Tue, 17 Mar 2020 20:55:56 +0100 Subject: [PATCH] core/rawdb, cmd/utils: fix review concerns --- cmd/utils/flags.go | 2 +- core/rawdb/accessors_chain.go | 4 ++-- core/rawdb/accessors_indexes.go | 7 ++++--- core/rawdb/chain_iterator.go | 4 +--- core/rlp_test.go | 1 + 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 74f141c89f..eb65ee1a70 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -231,7 +231,7 @@ var ( } TxLookupLimitFlag = cli.Int64Flag{ Name: "txlookuplimit", - Usage: "Number of recent blocks to index transactions-by-hash in (default = index all blocks)", + Usage: "Number of recent blocks to maintain transactions index by-hash for (default = index all blocks)", Value: 0, } LightKDFFlag = cli.BoolFlag{ diff --git a/core/rawdb/accessors_chain.go b/core/rawdb/accessors_chain.go index 5173809687..aa0a8c2827 100644 --- a/core/rawdb/accessors_chain.go +++ b/core/rawdb/accessors_chain.go @@ -328,9 +328,9 @@ func ReadBodyRLP(db ethdb.Reader, hash common.Hash, number uint64) rlp.RawValue } // ReadCanonicalBodyRLP retrieves the block body (transactions and uncles) for the canonical -// bloc at number, in RLP encoding. +// block at number, in RLP encoding. func ReadCanonicalBodyRLP(db ethdb.Reader, number uint64) rlp.RawValue { - // if it's an ancient one, we don't need the canonical hash + // If it's an ancient one, we don't need the canonical hash data, _ := db.Ancient(freezerBodiesTable, number) if len(data) == 0 { // Need to get the hash diff --git a/core/rawdb/accessors_indexes.go b/core/rawdb/accessors_indexes.go index a58e6a63d9..c7f3df2ad7 100644 --- a/core/rawdb/accessors_indexes.go +++ b/core/rawdb/accessors_indexes.go @@ -64,10 +64,11 @@ func WriteTxLookupEntries(db ethdb.KeyValueWriter, block *types.Block) { } // WriteTxLookupEntriesByHash is identical to WriteTxLookupEntries, but does not -// require a full types.Block as input -func WriteTxLookupEntriesByHash(db ethdb.KeyValueWriter, number []byte, hashes []common.Hash) { +// require a full types.Block as input. +func WriteTxLookupEntriesByHash(db ethdb.KeyValueWriter, number uint64, hashes []common.Hash) { + numberBytes := new(big.Int).SetUint64(number).Bytes() for _, hash := range hashes { - if err := db.Put(txLookupKey(hash), number); err != nil { + if err := db.Put(txLookupKey(hash), numberBytes); err != nil { log.Crit("Failed to store transaction lookup entry", "err", err) } } diff --git a/core/rawdb/chain_iterator.go b/core/rawdb/chain_iterator.go index 10039a1fb0..69c07a8ced 100644 --- a/core/rawdb/chain_iterator.go +++ b/core/rawdb/chain_iterator.go @@ -18,7 +18,6 @@ package rawdb import ( "math" - "math/big" "runtime" "sync/atomic" "time" @@ -220,8 +219,7 @@ func IndexTransactions(db ethdb.Database, from uint64, to uint64) { // Next block available, pop it off and index it delivery := queue.PopItem().(*blockTxHashes) lastNum = delivery.number - number := new(big.Int).SetUint64(lastNum).Bytes() - WriteTxLookupEntriesByHash(batch, number, delivery.hashes) + WriteTxLookupEntriesByHash(batch, delivery.number, delivery.hashes) blockCount++ txCount += len(delivery.hashes) // If enough data was accumulated in memory or we're at the last block, dump to disk diff --git a/core/rlp_test.go b/core/rlp_test.go index 2f3c447c22..04daf2fc67 100644 --- a/core/rlp_test.go +++ b/core/rlp_test.go @@ -13,6 +13,7 @@ // // You should have received a copy of the GNU Lesser General Public License // along with the go-ethereum library. If not, see . + package core import (