From 9b9d3b5b97313ddd9bc09937dbf233e11d63840e Mon Sep 17 00:00:00 2001 From: sideninja <75445744+sideninja@users.noreply.github.com> Date: Thu, 9 May 2024 17:40:57 +0200 Subject: [PATCH 1/6] support decode single receipt --- storage/pebble/receipts.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/storage/pebble/receipts.go b/storage/pebble/receipts.go index e456423e..8bfb3989 100644 --- a/storage/pebble/receipts.go +++ b/storage/pebble/receipts.go @@ -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{} @@ -138,9 +139,14 @@ 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 { + // try to decode single receipt (breaking change migration) + var storeReceipt *models.StorageReceipt + if err = rlp.DecodeBytes(val, &storeReceipt); err != nil { + return nil, err + } + + storeReceipts = append(storeReceipts, storeReceipt) } receipts := make([]*gethTypes.Receipt, len(storeReceipts)) From 7150a937d8997c5cc3c576d19a357085c8d72c3b Mon Sep 17 00:00:00 2001 From: sideninja <75445744+sideninja@users.noreply.github.com> Date: Thu, 9 May 2024 17:45:20 +0200 Subject: [PATCH 2/6] fix wrong message --- api/api.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/api/api.go b/api/api.go index da5639bd..3d99b645 100644 --- a/api/api.go +++ b/api/api.go @@ -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" @@ -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 { @@ -551,7 +552,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 } From bdbcfa70adc152a37bd09cc8bcbfa08eb5760e4e Mon Sep 17 00:00:00 2001 From: sideninja <75445744+sideninja@users.noreply.github.com> Date: Thu, 9 May 2024 17:59:11 +0200 Subject: [PATCH 3/6] fix error handling --- api/api.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/api/api.go b/api/api.go index 3d99b645..66eebcfb 100644 --- a/api/api.go +++ b/api/api.go @@ -282,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. @@ -312,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. From d45884638eb5d97dc544b6a7f28baf3af2d345c1 Mon Sep 17 00:00:00 2001 From: sideninja <75445744+sideninja@users.noreply.github.com> Date: Thu, 9 May 2024 18:54:32 +0200 Subject: [PATCH 4/6] change decoding of transaction without type --- models/transaction.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/models/transaction.go b/models/transaction.go index d1ac7a14..23bf3fd0 100644 --- a/models/transaction.go +++ b/models/transaction.go @@ -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 + } + return nil, fmt.Errorf("failed to rlp decode transaction: %w", err) } From 8b4b7c78b7594cdd0e44607ac2bcf84c86ac7c9b Mon Sep 17 00:00:00 2001 From: sideninja <75445744+sideninja@users.noreply.github.com> Date: Thu, 9 May 2024 18:54:43 +0200 Subject: [PATCH 5/6] warn for block without tx --- api/api.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/api/api.go b/api/api.go index 66eebcfb..494a8530 100644 --- a/api/api.go +++ b/api/api.go @@ -576,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) } From 98c9f2483a2564f3503a1b2dbbef43ba55cad597 Mon Sep 17 00:00:00 2001 From: sideninja <75445744+sideninja@users.noreply.github.com> Date: Thu, 9 May 2024 18:54:50 +0200 Subject: [PATCH 6/6] decode previous receipts --- storage/pebble/receipts.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/storage/pebble/receipts.go b/storage/pebble/receipts.go index 8bfb3989..a46986fa 100644 --- a/storage/pebble/receipts.go +++ b/storage/pebble/receipts.go @@ -140,13 +140,14 @@ func (r *Receipts) getByBlockHeight(height []byte) ([]*gethTypes.Receipt, error) var storeReceipts []*models.StorageReceipt 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 + var storeReceipt models.StorageReceipt if err = rlp.DecodeBytes(val, &storeReceipt); err != nil { return nil, err } - storeReceipts = append(storeReceipts, storeReceipt) + storeReceipts = []*models.StorageReceipt{&storeReceipt} } receipts := make([]*gethTypes.Receipt, len(storeReceipts))