From ef7258ed99f8ae924088bbf341f5fc5a1df198a0 Mon Sep 17 00:00:00 2001 From: healthykim Date: Wed, 18 Feb 2026 23:07:20 -0700 Subject: [PATCH] fix error --- eth/downloader/downloader_test.go | 23 ++++++++++++++++++----- eth/protocols/eth/handlers.go | 2 +- eth/protocols/eth/receipt.go | 4 ++-- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/eth/downloader/downloader_test.go b/eth/downloader/downloader_test.go index c05421c408..42bb15f8f7 100644 --- a/eth/downloader/downloader_test.go +++ b/eth/downloader/downloader_test.go @@ -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 := ð.Request{ Peer: dlp.id, diff --git a/eth/protocols/eth/handlers.go b/eth/protocols/eth/handlers.go index 61da6ba0ae..56b4a4cd7f 100644 --- a/eth/protocols/eth/handlers.go +++ b/eth/protocols/eth/handlers.go @@ -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) } } } diff --git a/eth/protocols/eth/receipt.go b/eth/protocols/eth/receipt.go index 6ea793b99f..e812b43913 100644 --- a/eth/protocols/eth/receipt.go +++ b/eth/protocols/eth/receipt.go @@ -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)