Skip to content

Commit

Permalink
core/types: drop type v4StoredReceiptRLP
Browse files Browse the repository at this point in the history
  • Loading branch information
gzliudan committed Sep 9, 2024
1 parent fe999c7 commit 32c390a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 63 deletions.
49 changes: 6 additions & 43 deletions core/types/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,8 @@ type receiptRLP struct {
Logs []*Log
}

// v4StoredReceiptRLP is the storage encoding of a receipt used in database version 4.
type v4StoredReceiptRLP struct {
PostStateOrStatus []byte
CumulativeGasUsed uint64
TxHash common.Hash
ContractAddress common.Address
Logs []*LogForStorage
GasUsed uint64
}

// v3StoredReceiptRLP is the original storage encoding of a receipt including some unnecessary fields.
type v3StoredReceiptRLP struct {
// receiptStorageRLP is the original storage encoding of a receipt including some unnecessary fields.
type receiptStorageRLP struct {
PostStateOrStatus []byte
CumulativeGasUsed uint64
Bloom Bloom
Expand Down Expand Up @@ -241,7 +231,7 @@ type ReceiptForStorage Receipt
// EncodeRLP implements rlp.Encoder, and flattens all content fields of a receipt
// into an RLP stream.
func (r *ReceiptForStorage) EncodeRLP(w io.Writer) error {
enc := &v3StoredReceiptRLP{
enc := &receiptStorageRLP{
PostStateOrStatus: (*Receipt)(r).statusEncoding(),
CumulativeGasUsed: r.CumulativeGasUsed,
Bloom: r.Bloom,
Expand All @@ -264,17 +254,11 @@ func (r *ReceiptForStorage) DecodeRLP(s *rlp.Stream) error {
if err != nil {
return err
}
// Try decoding from the newest format for future proofness, then the older one
// for old nodes that just upgraded. V4 was an intermediate unreleased format so
// we do need to decode it, but it's not common (try last).
if err := decodeV3StoredReceiptRLP(r, blob); err == nil {
return nil
}
return decodeV4StoredReceiptRLP(r, blob)
return decodeStoredReceiptRLP(r, blob)
}

func decodeV3StoredReceiptRLP(r *ReceiptForStorage, blob []byte) error {
var stored v3StoredReceiptRLP
func decodeStoredReceiptRLP(r *ReceiptForStorage, blob []byte) error {
var stored receiptStorageRLP
if err := rlp.DecodeBytes(blob, &stored); err != nil {
return err
}
Expand All @@ -295,27 +279,6 @@ func decodeV3StoredReceiptRLP(r *ReceiptForStorage, blob []byte) error {
return nil
}

func decodeV4StoredReceiptRLP(r *ReceiptForStorage, blob []byte) error {
var stored v4StoredReceiptRLP
if err := rlp.DecodeBytes(blob, &stored); err != nil {
return err
}
if err := (*Receipt)(r).setStatus(stored.PostStateOrStatus); err != nil {
return err
}
r.CumulativeGasUsed = stored.CumulativeGasUsed
r.TxHash = stored.TxHash
r.ContractAddress = stored.ContractAddress
r.GasUsed = stored.GasUsed
r.Logs = make([]*Log, len(stored.Logs))
for i, log := range stored.Logs {
r.Logs[i] = (*Log)(log)
}
r.Bloom = CreateBloom(Receipts{(*Receipt)(r)})

return nil
}

// Receipts implements DerivableList for receipts.
type Receipts []*Receipt

Expand Down
21 changes: 1 addition & 20 deletions core/types/receipt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ func TestLegacyReceiptDecoding(t *testing.T) {
name string
encode func(*Receipt) ([]byte, error)
}{
{
"V4StoredReceiptRLP",
encodeAsV4StoredReceiptRLP,
},
{
"V3StoredReceiptRLP",
encodeAsV3StoredReceiptRLP,
Expand Down Expand Up @@ -113,23 +109,8 @@ func TestLegacyReceiptDecoding(t *testing.T) {
}
}

func encodeAsV4StoredReceiptRLP(want *Receipt) ([]byte, error) {
stored := &v4StoredReceiptRLP{
PostStateOrStatus: want.statusEncoding(),
CumulativeGasUsed: want.CumulativeGasUsed,
TxHash: want.TxHash,
ContractAddress: want.ContractAddress,
Logs: make([]*LogForStorage, len(want.Logs)),
GasUsed: want.GasUsed,
}
for i, log := range want.Logs {
stored.Logs[i] = (*LogForStorage)(log)
}
return rlp.EncodeToBytes(stored)
}

func encodeAsV3StoredReceiptRLP(want *Receipt) ([]byte, error) {
stored := &v3StoredReceiptRLP{
stored := &receiptStorageRLP{
PostStateOrStatus: want.statusEncoding(),
CumulativeGasUsed: want.CumulativeGasUsed,
Bloom: want.Bloom,
Expand Down

0 comments on commit 32c390a

Please sign in to comment.