Skip to content

Commit 8bfae77

Browse files
authored
Merge pull request #916 from CortexFoundation/dev
chain index fix
2 parents ea4df0c + aed6d61 commit 8bfae77

File tree

1 file changed

+6
-23
lines changed

1 file changed

+6
-23
lines changed

core/rawdb/chain_iterator.go

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ import (
2323

2424
"github.com/CortexFoundation/CortexTheseus/common"
2525
"github.com/CortexFoundation/CortexTheseus/common/prque"
26+
"github.com/CortexFoundation/CortexTheseus/core/types"
2627
"github.com/CortexFoundation/CortexTheseus/ctxcdb"
2728
"github.com/CortexFoundation/CortexTheseus/log"
2829
"github.com/CortexFoundation/CortexTheseus/rlp"
29-
"golang.org/x/crypto/sha3"
3030
)
3131

3232
// InitDatabaseFromFreezer reinitializes an empty database from a previous batch
@@ -135,32 +135,15 @@ func iterateTransactions(db ctxcdb.Database, from uint64, to uint64, reverse boo
135135
close(hashesCh)
136136
}
137137
}()
138-
139-
var hasher = sha3.NewLegacyKeccak256()
140138
for data := range rlpCh {
141-
it, err := rlp.NewListIterator(data.rlp)
142-
if err != nil {
143-
log.Warn("tx iteration error", "error", err)
144-
return
145-
}
146-
it.Next()
147-
txs := it.Value()
148-
txIt, err := rlp.NewListIterator(txs)
149-
if err != nil {
150-
log.Warn("tx iteration error", "error", err)
139+
var body types.Body
140+
if err := rlp.DecodeBytes(data.rlp, &body); err != nil {
141+
log.Warn("Failed to decode block body", "block", data.number, "error", err)
151142
return
152143
}
153144
var hashes []common.Hash
154-
for txIt.Next() {
155-
if err := txIt.Err(); err != nil {
156-
log.Warn("tx iteration error", "error", err)
157-
return
158-
}
159-
var txHash common.Hash
160-
hasher.Reset()
161-
hasher.Write(txIt.Value())
162-
hasher.Sum(txHash[:0])
163-
hashes = append(hashes, txHash)
145+
for _, tx := range body.Transactions {
146+
hashes = append(hashes, tx.Hash())
164147
}
165148
result := &blockTxHashes{
166149
hashes: hashes,

0 commit comments

Comments
 (0)