core/rawdb: fix transaction indexing/unindexing hashing error (#22457)
* core/rawdb: more verbose error logs + better hashing * core/rawdb: add failing testcase * core/rawdb: properly hash transactions while indexing/unindexing * core/rawdb: exit on error + better log msg
This commit is contained in:
committed by
GitHub
parent
7cbf1d70a7
commit
94ab4ea341
@ -23,10 +23,10 @@ import (
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/prque"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/ethdb"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/rlp"
|
||||
"golang.org/x/crypto/sha3"
|
||||
)
|
||||
|
||||
// InitDatabaseFromFreezer reinitializes an empty database from a previous batch
|
||||
@ -135,32 +135,15 @@ func iterateTransactions(db ethdb.Database, from uint64, to uint64, reverse bool
|
||||
close(hashesCh)
|
||||
}
|
||||
}()
|
||||
|
||||
var hasher = sha3.NewLegacyKeccak256()
|
||||
for data := range rlpCh {
|
||||
it, err := rlp.NewListIterator(data.rlp)
|
||||
if err != nil {
|
||||
log.Warn("tx iteration error", "error", err)
|
||||
return
|
||||
}
|
||||
it.Next()
|
||||
txs := it.Value()
|
||||
txIt, err := rlp.NewListIterator(txs)
|
||||
if err != nil {
|
||||
log.Warn("tx iteration error", "error", err)
|
||||
var body types.Body
|
||||
if err := rlp.DecodeBytes(data.rlp, &body); err != nil {
|
||||
log.Warn("Failed to decode block body", "block", data.number, "error", err)
|
||||
return
|
||||
}
|
||||
var hashes []common.Hash
|
||||
for txIt.Next() {
|
||||
if err := txIt.Err(); err != nil {
|
||||
log.Warn("tx iteration error", "error", err)
|
||||
return
|
||||
}
|
||||
var txHash common.Hash
|
||||
hasher.Reset()
|
||||
hasher.Write(txIt.Value())
|
||||
hasher.Sum(txHash[:0])
|
||||
hashes = append(hashes, txHash)
|
||||
for _, tx := range body.Transactions {
|
||||
hashes = append(hashes, tx.Hash())
|
||||
}
|
||||
result := &blockTxHashes{
|
||||
hashes: hashes,
|
||||
|
Reference in New Issue
Block a user