evm, rpc: disable BaseFee for non London block (#662)

* disable basefee if not london block

* add london block check in state transition

* fix linter

* add unit test

* clean code

* add changelog
This commit is contained in:
Thomas Nguy
2021-10-13 15:39:47 +02:00
committed by GitHub
parent c7a2fb97c7
commit 75d553674c
7 changed files with 96 additions and 17 deletions
+8 -2
View File
@@ -159,7 +159,10 @@ func (k *Keeper) ApplyTransaction(tx *ethtypes.Transaction) (*types.MsgEthereumT
// get the latest signer according to the chain rules from the config
signer := ethtypes.MakeSigner(ethCfg, big.NewInt(ctx.BlockHeight()))
baseFee := k.feeMarketKeeper.GetBaseFee(ctx)
var baseFee *big.Int
if types.IsLondon(ethCfg, ctx.BlockHeight()) {
baseFee = k.feeMarketKeeper.GetBaseFee(ctx)
}
msg, err := tx.AsMessage(signer, baseFee)
if err != nil {
@@ -368,7 +371,10 @@ func (k *Keeper) ApplyNativeMessage(msg core.Message) (*types.MsgEthereumTxRespo
return nil, stacktrace.Propagate(err, "failed to obtain coinbase address")
}
baseFee := k.feeMarketKeeper.GetBaseFee(ctx)
var baseFee *big.Int
if types.IsLondon(ethCfg, ctx.BlockHeight()) {
baseFee = k.feeMarketKeeper.GetBaseFee(ctx)
}
tracer := types.NewTracer(k.tracer, msg, ethCfg, ctx.BlockHeight(), k.debug)
evm := k.NewEVM(msg, ethCfg, params, coinbase, baseFee, tracer)
+8
View File
@@ -2,6 +2,9 @@ package types
import (
"fmt"
"math/big"
"github.com/ethereum/go-ethereum/params"
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
@@ -132,3 +135,8 @@ func validateChainConfig(i interface{}) error {
return cfg.Validate()
}
func IsLondon(ethConfig *params.ChainConfig, height int64) bool {
rules := ethConfig.Rules(big.NewInt(height))
return rules.IsLondon
}
+31
View File
@@ -3,6 +3,8 @@ package types
import (
"testing"
"github.com/ethereum/go-ethereum/params"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/stretchr/testify/require"
)
@@ -104,3 +106,32 @@ func TestValidateChainConfig(t *testing.T) {
}
}
}
func TestIsLondon(t *testing.T) {
testCases := []struct {
name string
height int64
result bool
}{
{
"Before london block",
5,
false,
},
{
"After london block",
12_965_001,
true,
},
{
"london block",
12_965_000,
true,
},
}
for _, tc := range testCases {
ethConfig := params.MainnetChainConfig
require.Equal(t, IsLondon(ethConfig, tc.height), tc.result)
}
}