From 31b5d5aa3af9bbaa7e35ee10b9e00cf8959e75d2 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Sat, 28 Feb 2026 00:07:56 +0100 Subject: [PATCH] eth/protocols/eth: bring back Derivable method --- eth/protocols/eth/handlers.go | 15 +-------------- eth/protocols/eth/receipt.go | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/eth/protocols/eth/handlers.go b/eth/protocols/eth/handlers.go index 56b4a4cd7f..f9014ab74a 100644 --- a/eth/protocols/eth/handlers.go +++ b/eth/protocols/eth/handlers.go @@ -435,16 +435,6 @@ func writeTxForHash(tx []byte, buf *bytes.Buffer) { } } -// writeReceiptForHash returns a write function that encode receipts for hash derivation. -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) - } - } -} - func handleReceipts(backend Backend, msg Decoder, peer *Peer) error { // A batch of receipts arrived to one of our previous requests res := new(ReceiptsPacket) @@ -462,14 +452,11 @@ func handleReceipts(backend Backend, msg Decoder, peer *Peer) error { return fmt.Errorf("Receipts: %w", err) } - var bloomBuf [6]byte - writeReceipt := writeReceiptForHash(&bloomBuf) metadata := func() interface{} { hasher := trie.NewStackTrie(nil) hashes := make([]common.Hash, len(receiptLists)) for i := range receiptLists { - receipts := newDerivableRawList(&receiptLists[i].items, writeReceipt) - hashes[i] = types.DeriveSha(receipts, hasher) + hashes[i] = types.DeriveSha(receiptLists[i].Derivable(), hasher) } return hashes } diff --git a/eth/protocols/eth/receipt.go b/eth/protocols/eth/receipt.go index e812b43913..580cbc7b59 100644 --- a/eth/protocols/eth/receipt.go +++ b/eth/protocols/eth/receipt.go @@ -146,6 +146,22 @@ func (rl *ReceiptList) EncodeRLP(w io.Writer) error { return rl.items.EncodeRLP(w) } +func (rl *ReceiptList) Derivable() types.DerivableList { + var bloomBuf [6]byte + write := writeReceiptForHash(&bloomBuf) + return newDerivableRawList(&rl.items, write) +} + +// writeReceiptForHash returns a write function that encodes receipts for hash derivation. +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) + } + } +} + // encodeTypes takes a slice of rlp-encoded receipts, and transactions, // and applies the type-encoding on the receipts (for non-legacy receipts). // e.g. for non-legacy receipts: receipt-data -> {tx-type || receipt-data}