mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-20 13:44:31 +00:00
eth/protocols/eth: bring back Derivable method
This commit is contained in:
parent
0d34003a40
commit
31b5d5aa3a
2 changed files with 17 additions and 14 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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}
|
||||
|
|
|
|||
Loading…
Reference in a new issue