From 268f33ac95981a5587028a69669027fd18e09948 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Wed, 16 Apr 2025 10:02:19 +0200 Subject: [PATCH] eth/protocols/eth: simplify --- eth/protocols/eth/receipt.go | 16 ++-------------- eth/protocols/eth/receipt_test.go | 8 ++------ 2 files changed, 4 insertions(+), 20 deletions(-) diff --git a/eth/protocols/eth/receipt.go b/eth/protocols/eth/receipt.go index f833ddd66d..eb26b7c5bf 100644 --- a/eth/protocols/eth/receipt.go +++ b/eth/protocols/eth/receipt.go @@ -19,7 +19,6 @@ package eth import ( "bytes" "fmt" - "io" "iter" "github.com/ethereum/go-ethereum/core/types" @@ -63,19 +62,8 @@ func (r *Receipt) DecodeRLP(s *rlp.Stream) error { return s.ListEnd() } -// EncodeRLP writes the network encoding of receipts. -func (r *Receipt) EncodeRLP(_w io.Writer) error { - w := rlp.NewEncoderBuffer(_w) - list := w.List() - w.WriteUint64(uint64(r.TxType)) - w.WriteBytes(r.PostStateOrStatus) - w.WriteUint64(r.GasUsed) - w.Write(r.Logs) - w.ListEnd(list) - return w.Flush() -} - -// encodeStorage writes the network encoding of receipts. +// encodeStorage writes the storage encoding, i.e. the result matches +// types.ReceiptForStorage. func (r *Receipt) encodeStorage(w *rlp.EncoderBuffer) { list := w.List() w.WriteBytes(r.PostStateOrStatus) diff --git a/eth/protocols/eth/receipt_test.go b/eth/protocols/eth/receipt_test.go index 5017ec4d9a..78676c66c0 100644 --- a/eth/protocols/eth/receipt_test.go +++ b/eth/protocols/eth/receipt_test.go @@ -66,18 +66,14 @@ func TestTransformReceipts(t *testing.T) { encBlockBody, _ := rlp.EncodeToBytes(blockBody) // convert from storage encoding to network encoding - have, err := blockReceiptsToNetwork(in, encBlockBody) + network, err := blockReceiptsToNetwork(in, encBlockBody) if err != nil { t.Fatalf("test[%d]: blockReceiptsToNetwork error: %v", i, err) } - out, _ := rlp.EncodeToBytes(test.output) - if !bytes.Equal(have, out) { - t.Fatalf("test[%d]: blockReceiptsToNetwork mismatch\nhave: %x\nwant: %x\n in: %x", i, out, have, in) - } // parse as Receipts response list from network encoding var rl ReceiptList69 - if err := rlp.DecodeBytes(out, &rl); err != nil { + if err := rlp.DecodeBytes(network, &rl); err != nil { t.Fatalf("test[%d]: can't decode network receipts: %v", i, err) } storageEnc := rl.toStorageReceiptsRLP()