Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

eth_getBlockByNumber fix on batch transactions #1050

Merged
merged 7 commits into from
Apr 18, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ Ref: https://keepachangelog.com/en/1.0.0/

* (deps) [tharsis#1046](https://github.com/tharsis/ethermint/pull/1046) Bump Cosmos SDK version to [`v0.45.3`](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.45.3)

### Bug Fixes
crypto-facs marked this conversation as resolved.
Show resolved Hide resolved
* (rpc) [tharsis#1050](https://github.com/tharsis/ethermint/pull/1050) `eth_getBlockByNumber` fix on batch transactions

## [v0.13.0] - 2022-04-05

### API Breaking
Expand Down
4 changes: 3 additions & 1 deletion rpc/ethereum/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ func (e *EVMBackend) EthBlockFromTendermint(
}

txResults := resBlockResult.TxsResults
txIndex := uint64(0)

for i, txBz := range block.Txs {
tx, err := e.clientCtx.TxConfig.TxDecoder()(txBz)
Expand Down Expand Up @@ -394,14 +395,15 @@ func (e *EVMBackend) EthBlockFromTendermint(
tx,
common.BytesToHash(block.Hash()),
uint64(block.Height),
uint64(i),
txIndex,
baseFee,
)
if err != nil {
e.logger.Debug("NewTransactionFromData for receipt failed", "hash", tx.Hash().Hex(), "error", err.Error())
continue
}
ethRPCTxs = append(ethRPCTxs, rpcTx)
txIndex++
}
}

Expand Down
86 changes: 86 additions & 0 deletions tests/e2e/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import (
"bytes"
"context"
"fmt"
"github.com/cosmos/cosmos-sdk/client/flags"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
"github.com/tharsis/ethermint/rpc/ethereum/types"
"math/big"
"testing"

Expand Down Expand Up @@ -747,3 +751,85 @@ func (s *IntegrationTestSuite) TestPendingTransactionFilter() {
s.Require().NoError(err)
s.Require().Equal([]common.Hash{signedTx.Hash()}, filterResult)
}

//TODO add transactionIndex tests once we have OpenRPC interfaces
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
func (s *IntegrationTestSuite) TestBatchETHTransactions() {
const ethTxs = 2
txBuilder := s.network.Validators[0].ClientCtx.TxConfig.NewTxBuilder()
builder, ok := txBuilder.(authtx.ExtensionOptionsTxBuilder)
s.Require().True(ok)

recipient := common.HexToAddress("0x378c50D9264C63F3F92B806d4ee56E9D86FfB3Ec")
accountNonce := s.getAccountNonce(recipient)
feeAmount := sdk.ZeroInt()

var gasLimit uint64
var msgs []sdk.Msg

for i := 0; i < ethTxs; i++ {
chainId, err := s.network.Validators[0].JSONRPCClient.ChainID(s.ctx)
s.Require().NoError(err)

gasPrice := s.getGasPrice()
from := common.BytesToAddress(s.network.Validators[0].Address)
nonce := accountNonce + uint64(i) + 1

msgTx := evmtypes.NewTx(
chainId,
nonce,
&recipient,
big.NewInt(10),
100000,
gasPrice,
big.NewInt(200),
nil,
nil,
nil,
)
msgTx.From = from.Hex()
err = msgTx.Sign(s.ethSigner, s.network.Validators[0].ClientCtx.Keyring)
s.Require().NoError(err)

msgs = append(msgs, msgTx.GetMsgs()...)
txData, err := evmtypes.UnpackTxData(msgTx.Data)
s.Require().NoError(err)
feeAmount = feeAmount.Add(sdk.NewIntFromBigInt(txData.Fee()))
gasLimit = gasLimit + txData.GetGas()
}

option, err := codectypes.NewAnyWithValue(&evmtypes.ExtensionOptionsEthereumTx{})
s.Require().NoError(err)

queryClient := types.NewQueryClient(s.network.Validators[0].ClientCtx)
res, err := queryClient.Params(s.ctx, &evmtypes.QueryParamsRequest{})

fees := make(sdk.Coins, 0)
if feeAmount.Sign() > 0 {
fees = append(fees, sdk.NewCoin(res.GetParams().EvmDenom, feeAmount))
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
}

builder.SetExtensionOptions(option)
err = builder.SetMsgs(msgs...)
s.Require().NoError(err)
builder.SetFeeAmount(fees)
builder.SetGasLimit(gasLimit)

tx := builder.GetTx()
txEncoder := s.network.Validators[0].ClientCtx.TxConfig.TxEncoder()
txBytes, err := txEncoder(tx)
s.Require().NoError(err)

syncCtx := s.network.Validators[0].ClientCtx.WithBroadcastMode(flags.BroadcastBlock)
txResponse, err := syncCtx.BroadcastTx(txBytes)
s.Require().NoError(err)
s.Require().Equal(uint32(0), txResponse.Code)

block, err := s.network.Validators[0].JSONRPCClient.BlockByNumber(s.ctx, big.NewInt(txResponse.Height))
s.Require().NoError(err)

txs := block.Transactions()
s.Require().Len(txs, ethTxs)
for i, tx := range txs {
s.Require().Equal(accountNonce+uint64(i)+1, tx.Nonce())
}
}