handleReceipts68¶
| Source (upstream pre-purge) | Current | |
|---|---|---|
| File | eth/protocols/eth/handlers.go |
handlers_pow.go |
| Symbol | handleReceipts |
handleReceipts68 |
| Ref | 723aae2b4~1 |
etc/v1.17.4-full-node |
Revival of upstream's generic handleReceipts[L ReceiptsList], monomorphized at L=*ReceiptList68 (the only two lines that differ from the source: the signature and
new(ReceiptsPacket68)). Everything else — the tracker.Fulfil call, the shared receiptListBuffers assignment, the DeriveSha metadata closure and the EncodeForStorage loop — is verbatim. This restores the three protections the purge1 revival lacked: the response is matched against its request before the receipts are materialized (rlp.RawList only counts items on decode), the item count is capped at the number requested via tracker's ErrTooManyItems, and an unsolicited or oversized response now returns an error that drops the peer instead of being silently discarded by dispatchResponse. Logs are never decoded into types.Log on the network path.
3-way merge — purge → getc ← upstream¶
core-geth validation — +32 -7
| | | |---|---| | File | [`handlers.go`](https://github.com/etclabscore/core-geth/blob/v1.12.20/eth/protocols/eth/handlers.go) | | Symbol | `handleReceipts` | | Ref | `v1.12.20` |--- a/core-geth/eth/protocols/eth/handlers.go
+++ b/etc/eth/protocols/eth/handlers_pow.go
@@ -1,20 +1,45 @@
-func handleReceipts(backend Backend, msg Decoder, peer *Peer) error {
+func handleReceipts68(backend Backend, msg Decoder, peer *Peer) error {
// A batch of receipts arrived to one of our previous requests
- res := new(ReceiptsPacket)
+ res := new(ReceiptsPacket68)
if err := msg.Decode(res); err != nil {
- return fmt.Errorf("%w: message %v: %v", errDecode, msg, err)
+ return err
}
+
+ tresp := tracker.Response{ID: res.RequestId, MsgCode: ReceiptsMsg, Size: res.List.Len()}
+ if err := peer.tracker.Fulfil(tresp); err != nil {
+ return fmt.Errorf("Receipts: %w", err)
+ }
+
+ // Assign temporary hashing buffer to each list item, the same buffer is shared
+ // between all receipt list instances.
+ receiptLists, err := res.List.Items()
+ if err != nil {
+ return fmt.Errorf("Receipts: %w", err)
+ }
+ buffers := new(receiptListBuffers)
+ for i := range receiptLists {
+ receiptLists[i].setBuffers(buffers)
+ }
+
metadata := func() interface{} {
hasher := trie.NewStackTrie(nil)
- hashes := make([]common.Hash, len(res.ReceiptsResponse))
- for i, receipt := range res.ReceiptsResponse {
- hashes[i] = types.DeriveSha(types.Receipts(receipt), hasher)
+ hashes := make([]common.Hash, len(receiptLists))
+ for i := range receiptLists {
+ hashes[i] = types.DeriveSha(receiptLists[i].Derivable(), hasher)
}
return hashes
}
+ var enc ReceiptsRLPResponse
+ for i := range receiptLists {
+ encReceipts, err := receiptLists[i].EncodeForStorage()
+ if err != nil {
+ return fmt.Errorf("Receipts: invalid list %d: %v", i, err)
+ }
+ enc = append(enc, encReceipts)
+ }
return peer.dispatchResponse(&Response{
id: res.RequestId,
code: ReceiptsMsg,
- Res: &res.ReceiptsResponse,
+ Res: &enc,
}, metadata)
}