fix error

This commit is contained in:
healthykim 2026-02-18 23:07:20 -07:00 committed by Felix Lange
parent b2ac1c8d8c
commit 0d34003a40
3 changed files with 21 additions and 8 deletions

View file

@ -17,6 +17,7 @@
package downloader package downloader
import ( import (
"bytes"
"fmt" "fmt"
"math/big" "math/big"
"sync" "sync"
@ -40,6 +41,16 @@ import (
"github.com/ethereum/go-ethereum/trie" "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. // downloadTester is a test simulator for mocking out local block chain.
type downloadTester struct { type downloadTester struct {
chain *core.BlockChain chain *core.BlockChain
@ -264,13 +275,15 @@ func (dlp *downloadTesterPeer) RequestReceipts(hashes []common.Hash, sink chan *
blobs := eth.ServiceGetReceiptsQuery(dlp.chain, hashes) blobs := eth.ServiceGetReceiptsQuery(dlp.chain, hashes)
receipts := make([]types.Receipts, len(blobs)) receipts := make([]types.Receipts, len(blobs))
hashes = make([]common.Hash, len(blobs))
hasher := trie.NewStackTrie(nil)
for i, blob := range blobs { for i, blob := range blobs {
rlp.DecodeBytes(blob, &receipts[i]) rlp.DecodeBytes(blob, &receipts[i])
}
hasher := trie.NewStackTrie(nil) var items []eth.Receipt
hashes = make([]common.Hash, len(receipts)) rlp.DecodeBytes(blob, &items)
for i, receipt := range receipts { hashes[i] = types.DeriveSha(&receiptHashList{items: items}, hasher)
hashes[i] = types.DeriveSha(receipt, hasher)
} }
req := &eth.Request{ req := &eth.Request{
Peer: dlp.id, 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) { return func(data []byte, outbuf *bytes.Buffer) {
var r Receipt var r Receipt
if rlp.DecodeBytes(data, &r) == nil { 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 return r
} }
// encodeForHash encodes a receipt for the block receiptsRoot derivation. // EncodeForHash encodes a receipt for the block receiptsRoot derivation.
func (r *Receipt) encodeForHash(bloomBuf *[6]byte, out *bytes.Buffer) { func (r *Receipt) EncodeForHash(bloomBuf *[6]byte, out *bytes.Buffer) {
// For typed receipts, add the tx type. // For typed receipts, add the tx type.
if r.TxType != 0 { if r.TxType != 0 {
out.WriteByte(r.TxType) out.WriteByte(r.TxType)