From 34854c2039ee053e9d27acdd344a112a436bec7e Mon Sep 17 00:00:00 2001 From: pengin7384 Date: Thu, 20 Jun 2024 22:04:17 +0900 Subject: [PATCH] rawdb: delete unused return values in ReadReceipt --- core/blockchain_reader.go | 3 +-- core/blockchain_test.go | 6 +++--- core/rawdb/accessors_indexes.go | 20 ++++++++++---------- eth/filters/filter_system_test.go | 2 +- internal/ethapi/api_test.go | 2 +- 5 files changed, 16 insertions(+), 17 deletions(-) diff --git a/core/blockchain_reader.go b/core/blockchain_reader.go index 1995916d81..63e000ada7 100644 --- a/core/blockchain_reader.go +++ b/core/blockchain_reader.go @@ -211,8 +211,7 @@ func (bc *BlockChain) GetBlocksFromHash(hash common.Hash, n int) (blocks []*type // GetReceiptByHash retrieves the receipt by transaction hash func (bc *BlockChain) GetReceiptByHash(txHash common.Hash) *types.Receipt { - receipt, _, _, _ := rawdb.ReadReceipt(bc.db, txHash, bc.chainConfig) - return receipt + return rawdb.ReadReceipt(bc.db, txHash, bc.chainConfig) } // GetReceiptsByHash retrieves the receipts for all transactions in a given block. diff --git a/core/blockchain_test.go b/core/blockchain_test.go index e4bc3e09a6..064a28af9f 100644 --- a/core/blockchain_test.go +++ b/core/blockchain_test.go @@ -1070,7 +1070,7 @@ func testChainTxReorgs(t *testing.T, scheme string) { if txn, _, _, _ := rawdb.ReadTransaction(db, tx.Hash()); txn != nil { t.Errorf("drop %d: tx %v found while shouldn't have been", i, txn) } - if rcpt, _, _, _ := rawdb.ReadReceipt(db, tx.Hash(), blockchain.Config()); rcpt != nil { + if rcpt := rawdb.ReadReceipt(db, tx.Hash(), blockchain.Config()); rcpt != nil { t.Errorf("drop %d: receipt %v found while shouldn't have been", i, rcpt) } } @@ -1079,7 +1079,7 @@ func testChainTxReorgs(t *testing.T, scheme string) { if txn, _, _, _ := rawdb.ReadTransaction(db, tx.Hash()); txn == nil { t.Errorf("add %d: expected tx to be found", i) } - if rcpt, _, _, _ := rawdb.ReadReceipt(db, tx.Hash(), blockchain.Config()); rcpt == nil { + if rcpt := rawdb.ReadReceipt(db, tx.Hash(), blockchain.Config()); rcpt == nil { t.Errorf("add %d: expected receipt to be found", i) } } @@ -1088,7 +1088,7 @@ func testChainTxReorgs(t *testing.T, scheme string) { if txn, _, _, _ := rawdb.ReadTransaction(db, tx.Hash()); txn == nil { t.Errorf("share %d: expected tx to be found", i) } - if rcpt, _, _, _ := rawdb.ReadReceipt(db, tx.Hash(), blockchain.Config()); rcpt == nil { + if rcpt := rawdb.ReadReceipt(db, tx.Hash(), blockchain.Config()); rcpt == nil { t.Errorf("share %d: expected receipt to be found", i) } } diff --git a/core/rawdb/accessors_indexes.go b/core/rawdb/accessors_indexes.go index 60ef25ce73..ad1fc1cb52 100644 --- a/core/rawdb/accessors_indexes.go +++ b/core/rawdb/accessors_indexes.go @@ -121,24 +121,24 @@ func ReadTransaction(db ethdb.Reader, hash common.Hash) (*types.Transaction, com // ReadReceipt retrieves a specific transaction receipt from the database, along with // its added positional metadata. -func ReadReceipt(db ethdb.Reader, txHash common.Hash, config *params.ChainConfig) (*types.Receipt, common.Hash, uint64, uint64) { +func ReadReceipt(db ethdb.Reader, txHash common.Hash, config *params.ChainConfig) *types.Receipt { // Retrieve the context of the receipt based on the transaction hash blockNumber := ReadTxLookupEntry(db, txHash) if blockNumber == nil { - return nil, common.Hash{}, 0, 0 + return nil } blockHash := ReadCanonicalHash(db, *blockNumber) if blockHash == (common.Hash{}) { - return nil, common.Hash{}, 0, 0 + return nil } blockHeader := ReadHeader(db, blockHash, *blockNumber) if blockHeader == nil { - return nil, common.Hash{}, 0, 0 + return nil } blockBody := ReadBody(db, blockHash, *blockNumber) if blockBody == nil { log.Error("Missing body but have receipt", "blockHash", blockHash, "number", blockNumber) - return nil, common.Hash{}, 0, 0 + return nil } // Find a match tx and derive receipt fields @@ -150,11 +150,11 @@ func ReadReceipt(db ethdb.Reader, txHash common.Hash, config *params.ChainConfig // Read raw receipts only if hash matches receipts := ReadRawReceipts(db, blockHash, *blockNumber) if receipts == nil { - return nil, common.Hash{}, 0, 0 + return nil } if len(blockBody.Transactions) != len(receipts) { log.Error("Transaction and receipt count mismatch", "txs", len(blockBody.Transactions), "receipts", len(receipts)) - return nil, common.Hash{}, 0, 0 + return nil } targetReceipt := receipts[txIndex] @@ -181,13 +181,13 @@ func ReadReceipt(db ethdb.Reader, txHash common.Hash, config *params.ChainConfig if err := targetReceipt.DeriveFields(signer, blockHash, *blockNumber, blockHeader.BaseFee, blobGasPrice, uint(txIndex), gasUsed, logIndex, blockBody.Transactions[txIndex]); err != nil { log.Error("Failed to derive the receipt fields", "txHash", txHash, "err", err) - return nil, common.Hash{}, 0, 0 + return nil } - return targetReceipt, blockHash, *blockNumber, uint64(txIndex) + return targetReceipt } log.Error("Receipt not found", "number", *blockNumber, "blockHash", blockHash, "txHash", txHash) - return nil, common.Hash{}, 0, 0 + return nil } // ReadBloomBits retrieves the compressed bloom bit vector belonging to the given diff --git a/eth/filters/filter_system_test.go b/eth/filters/filter_system_test.go index fbca4efc2d..ef72d4e55a 100644 --- a/eth/filters/filter_system_test.go +++ b/eth/filters/filter_system_test.go @@ -108,7 +108,7 @@ func (b *testBackend) GetBody(ctx context.Context, hash common.Hash, number rpc. } func (b *testBackend) GetReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error) { - receipt, _, _, _ := rawdb.ReadReceipt(b.db, txHash, params.TestChainConfig) + receipt := rawdb.ReadReceipt(b.db, txHash, params.TestChainConfig) return receipt, nil } diff --git a/internal/ethapi/api_test.go b/internal/ethapi/api_test.go index 3ea246e864..067913db1a 100644 --- a/internal/ethapi/api_test.go +++ b/internal/ethapi/api_test.go @@ -551,7 +551,7 @@ func (b testBackend) StateAndHeaderByNumberOrHash(ctx context.Context, blockNrOr } func (b testBackend) Pending() (*types.Block, types.Receipts, *state.StateDB) { panic("implement me") } func (b testBackend) GetReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error) { - receipt, _, _, _ := rawdb.ReadReceipt(b.db, txHash, b.chain.Config()) + receipt := rawdb.ReadReceipt(b.db, txHash, b.chain.Config()) return receipt, nil } func (b testBackend) GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error) {