Skip to content

Commit

Permalink
Merge pull request #343 from onflow/patch-storage-receipt-decoding-v2
Browse files Browse the repository at this point in the history
Patch `models.StorageReceipt` to accommodate the old format
  • Loading branch information
sideninja authored Jul 11, 2024
2 parents 56c5fcb + 9341598 commit 90de2f5
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 8 deletions.
40 changes: 40 additions & 0 deletions models/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,46 @@ import (
"github.com/onflow/go-ethereum/rlp"
)

// TEMP: Remove this type after PreviewNet is reset
type StorageReceiptV0 struct {
Type uint8
PostState []byte
Status uint64
CumulativeGasUsed uint64
Bloom gethTypes.Bloom
Logs []*gethTypes.Log
TxHash common.Hash
ContractAddress common.Address
GasUsed uint64
EffectiveGasPrice *big.Int
BlobGasUsed uint64
BlobGasPrice *big.Int
BlockHash common.Hash
BlockNumber *big.Int
TransactionIndex uint
}

func (sr *StorageReceiptV0) ToNewReceipt() *StorageReceipt {
return &StorageReceipt{
Type: sr.Type,
PostState: sr.PostState,
Status: sr.Status,
CumulativeGasUsed: sr.CumulativeGasUsed,
Bloom: sr.Bloom,
Logs: sr.Logs,
TxHash: sr.TxHash,
ContractAddress: sr.ContractAddress,
GasUsed: sr.GasUsed,
EffectiveGasPrice: sr.EffectiveGasPrice,
BlobGasUsed: sr.BlobGasUsed,
BlobGasPrice: sr.BlobGasPrice,
BlockHash: sr.BlockHash,
BlockNumber: sr.BlockNumber,
TransactionIndex: sr.TransactionIndex,
RevertReason: []byte{},
}
}

// StorageReceipt is a receipt representation for storage.
//
// This struct copies the geth.Receipt type found here: https://github.com/ethereum/go-ethereum/blob/9bbb9df18549d6f81c3d1f4fc6c65f71bc92490d/core/types/receipt.go#L52
Expand Down
30 changes: 22 additions & 8 deletions storage/pebble/receipts.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,20 +133,34 @@ func (r *Receipts) getByBlockHeight(height []byte, batch *pebble.Batch) ([]*mode
}

var receipts []*models.StorageReceipt
if err = rlp.DecodeBytes(val, &receipts); err != nil {

var oldReceipts []*models.StorageReceiptV0
if err = rlp.DecodeBytes(val, &oldReceipts); err != nil {
// todo remove this after previewnet is reset
// try to decode single receipt (breaking change migration)
var storeReceipt models.StorageReceipt
if err = rlp.DecodeBytes(val, &storeReceipt); err != nil {
gethReceipt := gethTypes.Receipt{}
if err = rlp.DecodeBytes(val, &gethReceipt); err != nil {
var storeReceipt models.StorageReceiptV0
if err = rlp.DecodeBytes(val, &storeReceipt); err == nil {
oldReceipts = []*models.StorageReceiptV0{&storeReceipt}
} else {
oldReceipts = []*models.StorageReceiptV0{}
}
}

for _, rcp := range oldReceipts {
receipts = append(receipts, rcp.ToNewReceipt())
}

if len(oldReceipts) == 0 {
if err = rlp.DecodeBytes(val, &receipts); err != nil {
// todo remove this after previewnet is reset
// try to decode single receipt (breaking change migration)
var storeReceipt models.StorageReceipt
if err = rlp.DecodeBytes(val, &storeReceipt); err != nil {
return nil, err
}

storeReceipt = *models.NewStorageReceipt(&gethReceipt)
receipts = []*models.StorageReceipt{&storeReceipt}
}

receipts = []*models.StorageReceipt{&storeReceipt}
}

for _, rcp := range receipts {
Expand Down

0 comments on commit 90de2f5

Please sign in to comment.