mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-17 18:30:45 +00:00
core/types: drop type v4StoredReceiptRLP
This commit is contained in:
parent
089a589a81
commit
e561f2842e
2 changed files with 7 additions and 63 deletions
|
|
@ -90,18 +90,8 @@ type receiptRLP struct {
|
||||||
Logs []*Log
|
Logs []*Log
|
||||||
}
|
}
|
||||||
|
|
||||||
// v4StoredReceiptRLP is the storage encoding of a receipt used in database version 4.
|
// receiptStorageRLP is the original storage encoding of a receipt including some unnecessary fields.
|
||||||
type v4StoredReceiptRLP struct {
|
type receiptStorageRLP 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 {
|
|
||||||
PostStateOrStatus []byte
|
PostStateOrStatus []byte
|
||||||
CumulativeGasUsed uint64
|
CumulativeGasUsed uint64
|
||||||
Bloom Bloom
|
Bloom Bloom
|
||||||
|
|
@ -241,7 +231,7 @@ type ReceiptForStorage Receipt
|
||||||
// EncodeRLP implements rlp.Encoder, and flattens all content fields of a receipt
|
// EncodeRLP implements rlp.Encoder, and flattens all content fields of a receipt
|
||||||
// into an RLP stream.
|
// into an RLP stream.
|
||||||
func (r *ReceiptForStorage) EncodeRLP(w io.Writer) error {
|
func (r *ReceiptForStorage) EncodeRLP(w io.Writer) error {
|
||||||
enc := &v3StoredReceiptRLP{
|
enc := &receiptStorageRLP{
|
||||||
PostStateOrStatus: (*Receipt)(r).statusEncoding(),
|
PostStateOrStatus: (*Receipt)(r).statusEncoding(),
|
||||||
CumulativeGasUsed: r.CumulativeGasUsed,
|
CumulativeGasUsed: r.CumulativeGasUsed,
|
||||||
Bloom: r.Bloom,
|
Bloom: r.Bloom,
|
||||||
|
|
@ -264,17 +254,11 @@ func (r *ReceiptForStorage) DecodeRLP(s *rlp.Stream) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// Try decoding from the newest format for future proofness, then the older one
|
return decodeStoredReceiptRLP(r, blob)
|
||||||
// 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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func decodeV3StoredReceiptRLP(r *ReceiptForStorage, blob []byte) error {
|
func decodeStoredReceiptRLP(r *ReceiptForStorage, blob []byte) error {
|
||||||
var stored v3StoredReceiptRLP
|
var stored receiptStorageRLP
|
||||||
if err := rlp.DecodeBytes(blob, &stored); err != nil {
|
if err := rlp.DecodeBytes(blob, &stored); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -295,27 +279,6 @@ func decodeV3StoredReceiptRLP(r *ReceiptForStorage, blob []byte) error {
|
||||||
return nil
|
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.
|
// Receipts implements DerivableList for receipts.
|
||||||
type Receipts []*Receipt
|
type Receipts []*Receipt
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,10 +43,6 @@ func TestLegacyReceiptDecoding(t *testing.T) {
|
||||||
name string
|
name string
|
||||||
encode func(*Receipt) ([]byte, error)
|
encode func(*Receipt) ([]byte, error)
|
||||||
}{
|
}{
|
||||||
{
|
|
||||||
"V4StoredReceiptRLP",
|
|
||||||
encodeAsV4StoredReceiptRLP,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"V3StoredReceiptRLP",
|
"V3StoredReceiptRLP",
|
||||||
encodeAsV3StoredReceiptRLP,
|
encodeAsV3StoredReceiptRLP,
|
||||||
|
|
@ -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) {
|
func encodeAsV3StoredReceiptRLP(want *Receipt) ([]byte, error) {
|
||||||
stored := &v3StoredReceiptRLP{
|
stored := &receiptStorageRLP{
|
||||||
PostStateOrStatus: want.statusEncoding(),
|
PostStateOrStatus: want.statusEncoding(),
|
||||||
CumulativeGasUsed: want.CumulativeGasUsed,
|
CumulativeGasUsed: want.CumulativeGasUsed,
|
||||||
Bloom: want.Bloom,
|
Bloom: want.Bloom,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue