Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix decoding issues with previous formats #237

Merged
merged 7 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 29 additions & 10 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@ import (
"errors"
"fmt"

errs "github.com/onflow/flow-evm-gateway/api/errors"
"github.com/onflow/flow-evm-gateway/config"
"github.com/onflow/flow-evm-gateway/models"
"github.com/onflow/flow-evm-gateway/services/logs"
"github.com/onflow/flow-evm-gateway/services/requester"
"github.com/onflow/flow-evm-gateway/storage"
storageErrs "github.com/onflow/flow-evm-gateway/storage/errors"
evmTypes "github.com/onflow/flow-go/fvm/evm/types"
"github.com/onflow/go-ethereum/common"
"github.com/onflow/go-ethereum/common/hexutil"
Expand All @@ -21,6 +14,14 @@ import (
"github.com/onflow/go-ethereum/eth/filters"
"github.com/onflow/go-ethereum/rpc"
"github.com/rs/zerolog"

errs "github.com/onflow/flow-evm-gateway/api/errors"
"github.com/onflow/flow-evm-gateway/config"
"github.com/onflow/flow-evm-gateway/models"
"github.com/onflow/flow-evm-gateway/services/logs"
"github.com/onflow/flow-evm-gateway/services/requester"
"github.com/onflow/flow-evm-gateway/storage"
storageErrs "github.com/onflow/flow-evm-gateway/storage/errors"
)

func SupportedAPIs(blockChainAPI *BlockChainAPI, streamAPI *StreamAPI, pullAPI *PullAPI) []rpc.API {
Expand Down Expand Up @@ -281,7 +282,12 @@ func (b *BlockChainAPI) GetBlockByHash(
return handleError[*Block](b.logger, err)
}

return b.prepareBlockResponse(ctx, block, fullTx)
apiBlock, err := b.prepareBlockResponse(ctx, block, fullTx)
if err != nil {
return handleError[*Block](b.logger, err)
}

return apiBlock, nil
}

// GetBlockByNumber returns the requested canonical block.
Expand Down Expand Up @@ -311,7 +317,12 @@ func (b *BlockChainAPI) GetBlockByNumber(
return handleError[*Block](b.logger, err)
}

return b.prepareBlockResponse(ctx, block, fullTx)
apiBlock, err := b.prepareBlockResponse(ctx, block, fullTx)
if err != nil {
return handleError[*Block](b.logger, err)
}

return apiBlock, nil
}

// GetBlockReceipts returns the block receipts for the given block hash or number or tag.
Expand Down Expand Up @@ -551,7 +562,7 @@ func handleError[T any](log zerolog.Logger, err error) (T, error) {
return zero, nil
}

log.Error().Err(err).Msg("failed to get latest block height")
log.Error().Err(err).Msg("api error")
return zero, errs.ErrInternal
}

Expand All @@ -565,6 +576,14 @@ func (b *BlockChainAPI) fetchBlockTransactions(
if err != nil {
return nil, err
}
if transaction == nil {
b.logger.Warn().
Str("tx-hash", txHash.String()).
Uint64("evm-height", block.Height).
Msg("not found a transaction the block references")

continue
}
transactions = append(transactions, transaction)
}

Expand Down
6 changes: 6 additions & 0 deletions models/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ func UnmarshalTransaction(value []byte) (Transaction, error) {

tx := &gethTypes.Transaction{}
if err := tx.UnmarshalBinary(value[1:]); err != nil {
// todo remove this after previewnet is reset
// breaking change on transaction data, try without type
if err := tx.UnmarshalBinary(value); err == nil {
return TransactionCall{Transaction: tx}, nil
}

Comment on lines +169 to +174
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

Codebase Verification

The search results confirm that the temporary decoding logic, marked with a "todo" comment about removing it after the previewnet reset, is still present in the models/transaction.go file. This indicates that the intended removal has not yet been executed.


Temporary Decoding Logic Still Present in models/transaction.go

  • The temporary decoding logic that was supposed to be removed after the previewnet reset is still present in the codebase. This needs attention to ensure the code aligns with the intended changes post-reset.
Analysis chain

Temporary decoding logic added to handle breaking changes.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the temporary decoding logic is removed after the previewnet reset.

# Test: Search for the temporary decoding logic. Expect: No occurrences after the reset.
rg --type go $'// todo remove this after previewnet is reset' models/transaction.go

Length of output: 132

return nil, fmt.Errorf("failed to rlp decode transaction: %w", err)
}

Expand Down
19 changes: 13 additions & 6 deletions storage/pebble/receipts.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import (
"sync"

"github.com/cockroachdb/pebble"
"github.com/onflow/flow-evm-gateway/models"
"github.com/onflow/flow-evm-gateway/storage"
errs "github.com/onflow/flow-evm-gateway/storage/errors"
"github.com/onflow/go-ethereum/common"
gethTypes "github.com/onflow/go-ethereum/core/types"
"github.com/onflow/go-ethereum/rlp"

"github.com/onflow/flow-evm-gateway/models"
"github.com/onflow/flow-evm-gateway/storage"
errs "github.com/onflow/flow-evm-gateway/storage/errors"
)

var _ storage.ReceiptIndexer = &Receipts{}
Expand Down Expand Up @@ -138,9 +139,15 @@ func (r *Receipts) getByBlockHeight(height []byte) ([]*gethTypes.Receipt, error)
}

var storeReceipts []*models.StorageReceipt
err = rlp.DecodeBytes(val, &storeReceipts)
if err != nil {
return nil, err
if err = rlp.DecodeBytes(val, &storeReceipts); 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
}

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

receipts := make([]*gethTypes.Receipt, len(storeReceipts))
Expand Down
Loading