Skip to content

Commit

Permalink
Fix receipt decoding for calls to eth_getLogs (#242)
Browse files Browse the repository at this point in the history
* Fix receipt decoding for calls to eth_getLogs

We added a special receipt type for celo dynamic fee transactions that
stores the base fee in the fee currency in the receipt, this makes it
possible to calculate the gasPrice without needing state access, but we
missed the flow for eth_getLogs because they use a different type to
decode the receipts to avoid makeing the bloom filter.

So this adds support for decoding our added receipts in that flow.
  • Loading branch information
piersy authored Sep 27, 2024
1 parent 26785e0 commit db278f4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
18 changes: 17 additions & 1 deletion core/rawdb/accessors_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -694,8 +694,24 @@ type receiptLogs struct {

// DecodeRLP implements rlp.Decoder.
func (r *receiptLogs) DecodeRLP(s *rlp.Stream) error {
// Retrieve the entire receipt blob as we need to try multiple decoders
blob, err := s.Raw()
if err != nil {
return err
}
// Check to see if this is a celo dynamic fee receipt.
if types.IsCeloDynamicFeeReceipt(blob) {
var stored types.CeloDynamicFeeStoredReceiptRLP
err := rlp.DecodeBytes(blob, &stored)
if err != nil {
return err
}
r.Logs = stored.Logs
return nil
}

var stored storedReceiptRLP
if err := s.Decode(&stored); err != nil {
if err := rlp.DecodeBytes(blob, &stored); err != nil {
return err
}
r.Logs = stored.Logs
Expand Down
8 changes: 4 additions & 4 deletions core/types/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ type storedReceiptRLP struct {
DepositReceiptVersion *uint64 `rlp:"optional"`
}

type celoDynamicFeeStoredReceiptRLP struct {
type CeloDynamicFeeStoredReceiptRLP struct {
CeloDynamicReceiptMarker []interface{} // Marker to distinguish this from storedReceiptRLP
PostStateOrStatus []byte
CumulativeGasUsed uint64
Expand Down Expand Up @@ -465,7 +465,7 @@ func (r *ReceiptForStorage) EncodeRLP(_w io.Writer) error {
// Detect CeloDynamicFee receipts by looking at the first list element
// To distinguish these receipts from the very similar normal receipts, an
// empty list is added as the first element of the RLP-serialized struct.
func isCeloDynamicFeeReceipt(blob []byte) bool {
func IsCeloDynamicFeeReceipt(blob []byte) bool {
listHeaderSize := 1 // Length of the list header representing the struct in bytes
if blob[0] > 0xf7 {
listHeaderSize += int(blob[0]) - 0xf7
Expand All @@ -483,7 +483,7 @@ func (r *ReceiptForStorage) DecodeRLP(s *rlp.Stream) error {
return err
}
// First try to decode the latest receipt database format, try the pre-bedrock Optimism legacy format otherwise.
if isCeloDynamicFeeReceipt(blob) {
if IsCeloDynamicFeeReceipt(blob) {
return decodeStoredCeloDynamicFeeReceiptRLP(r, blob)
}
if err := decodeStoredReceiptRLP(r, blob); err == nil {
Expand Down Expand Up @@ -523,7 +523,7 @@ func decodeLegacyOptimismReceiptRLP(r *ReceiptForStorage, blob []byte) error {
}

func decodeStoredCeloDynamicFeeReceiptRLP(r *ReceiptForStorage, blob []byte) error {
var stored celoDynamicFeeStoredReceiptRLP
var stored CeloDynamicFeeStoredReceiptRLP
if err := rlp.DecodeBytes(blob, &stored); err != nil {
return err
}
Expand Down

0 comments on commit db278f4

Please sign in to comment.