fix error

This commit is contained in:
healthykim 2026-02-18 23:07:20 -07:00
parent 2fa04e10f7
commit ef7258ed99
3 changed files with 21 additions and 8 deletions

View file

@ -17,6 +17,7 @@
package downloader
import (
"bytes"
"fmt"
"math/big"
"sync"
@ -40,6 +41,16 @@ import (
"github.com/ethereum/go-ethereum/trie"
)
type receiptHashList struct {
items []eth.Receipt
bloomBuf [6]byte
}
func (l *receiptHashList) Len() int { return len(l.items) }
func (l *receiptHashList) EncodeIndex(i int, buf *bytes.Buffer) {
l.items[i].EncodeForHash(&l.bloomBuf, buf)
}
// downloadTester is a test simulator for mocking out local block chain.
type downloadTester struct {
chain *core.BlockChain
@ -264,13 +275,15 @@ func (dlp *downloadTesterPeer) RequestReceipts(hashes []common.Hash, sink chan *
blobs := eth.ServiceGetReceiptsQuery(dlp.chain, hashes)
receipts := make([]types.Receipts, len(blobs))
hashes = make([]common.Hash, len(blobs))
hasher := trie.NewStackTrie(nil)
for i, blob := range blobs {
rlp.DecodeBytes(blob, &receipts[i])
}
hasher := trie.NewStackTrie(nil)
hashes = make([]common.Hash, len(receipts))
for i, receipt := range receipts {
hashes[i] = types.DeriveSha(receipt, hasher)
var items []eth.Receipt
rlp.DecodeBytes(blob, &items)
hashes[i] = types.DeriveSha(&receiptHashList{items: items}, hasher)
}
req := &eth.Request{
Peer: dlp.id,

View file

@ -440,7 +440,7 @@ func writeReceiptForHash(bloomBuf *[6]byte) func([]byte, *bytes.Buffer) {
return func(data []byte, outbuf *bytes.Buffer) {
var r Receipt
if rlp.DecodeBytes(data, &r) == nil {
r.encodeForHash(bloomBuf, outbuf)
r.EncodeForHash(bloomBuf, outbuf)
}
}
}

View file

@ -46,8 +46,8 @@ func newReceipt(tr *types.Receipt) Receipt {
return r
}
// encodeForHash encodes a receipt for the block receiptsRoot derivation.
func (r *Receipt) encodeForHash(bloomBuf *[6]byte, out *bytes.Buffer) {
// EncodeForHash encodes a receipt for the block receiptsRoot derivation.
func (r *Receipt) EncodeForHash(bloomBuf *[6]byte, out *bytes.Buffer) {
// For typed receipts, add the tx type.
if r.TxType != 0 {
out.WriteByte(r.TxType)