rpc: fix panic (#630)

This commit is contained in:
Federico Kunze Küllmer
2021-10-06 17:20:34 +02:00
committed by GitHub
parent e79a6ed6b2
commit 19b6c03f37
2 changed files with 8 additions and 7 deletions
+3 -4
View File
@@ -238,9 +238,8 @@ func (e *EVMBackend) EthBlockFromTendermint(
ctx := types.ContextWithHeight(block.Height)
bfRes, err := e.queryClient.FeeMarket.BaseFee(ctx, &feemarkettypes.QueryBaseFeeRequest{})
baseFee, err := e.BaseFee()
if err != nil {
e.logger.Debug("failed to base fee", "height", block.Height, "error", err.Error())
return nil, err
}
@@ -270,7 +269,7 @@ func (e *EVMBackend) EthBlockFromTendermint(
common.BytesToHash(block.Hash()),
uint64(block.Height),
uint64(i),
bfRes.BaseFee.BigInt(),
baseFee,
)
if err != nil {
e.logger.Debug("NewTransactionFromData for receipt failed", "hash", tx.Hash().Hex(), "error", err.Error())
@@ -327,7 +326,7 @@ func (e *EVMBackend) EthBlockFromTendermint(
formattedBlock := types.FormatBlock(
block.Header, block.Size(),
gasLimit, new(big.Int).SetUint64(gasUsed),
ethRPCTxs, bloom, validatorAddr, bfRes.BaseFee.BigInt(),
ethRPCTxs, bloom, validatorAddr, baseFee,
)
return formattedBlock, nil
}
+5 -3
View File
@@ -5,8 +5,10 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/tharsis/ethermint/types"
)
@@ -228,12 +230,12 @@ func (tx DynamicFeeTx) Validate() error {
return nil
}
// Fee panics as it requires the base fee amount to calculate
// Fee returns gasprice * gaslimit.
func (tx DynamicFeeTx) Fee() *big.Int {
panic("fee can only be called manually by providing the base fee")
return fee(tx.GetGasPrice(), tx.GasLimit)
}
// Cost returns amount + gasprice * gaslimit.
func (tx DynamicFeeTx) Cost() *big.Int {
panic("cost can only be called manually by providing the base fee")
return cost(tx.Fee(), tx.GetValue())
}