all: bump go-ethereum to v1.10.9 (#231)

* all: bump go-ethereum to v1.10.4

* build

* state transition and rpc

* wip rpc changes

* fix refund

* fixes

* no base fee param

* ante handler

* undo change

* fix test

* bump deps

* calculate base fee

* gRPC base fee query

* update RPC

* fix

* update'

* go.mod

* fix build

* fix panic

* rm changes in third_party

* json rpc changes

* reserved fields

* fixes fixes fixes

* rm no stringer

* fixes 2

* tests wip

* bump geth version

* update

* grpc traceTx

* rm fee market from ante

* fix TransactionArgs

* lint

* update proto

* update tx args

* changelog
This commit is contained in:
Federico Kunze Küllmer
2021-10-05 15:38:20 +00:00
committed by GitHub
parent cda968bddd
commit a8722655bb
44 changed files with 1020 additions and 2584 deletions
+4 -4
View File
@@ -65,7 +65,7 @@ func BenchmarkTokenTransfer(b *testing.B) {
input, err := ContractABI.Pack("transfer", common.HexToAddress("0x378c50D9264C63F3F92B806d4ee56E9D86FfB3Ec"), big.NewInt(1000))
require.NoError(b, err)
nonce := suite.app.EvmKeeper.GetNonce(suite.address)
return types.NewTx(suite.app.EvmKeeper.ChainID(), nonce, &contract, big.NewInt(0), 410000, big.NewInt(1), input, nil)
return types.NewTx(suite.app.EvmKeeper.ChainID(), nonce, &contract, big.NewInt(0), 410000, big.NewInt(1), nil, nil, input, nil)
})
}
@@ -74,7 +74,7 @@ func BenchmarkEmitLogs(b *testing.B) {
input, err := ContractABI.Pack("benchmarkLogs", big.NewInt(1000))
require.NoError(b, err)
nonce := suite.app.EvmKeeper.GetNonce(suite.address)
return types.NewTx(suite.app.EvmKeeper.ChainID(), nonce, &contract, big.NewInt(0), 4100000, big.NewInt(1), input, nil)
return types.NewTx(suite.app.EvmKeeper.ChainID(), nonce, &contract, big.NewInt(0), 4100000, big.NewInt(1), nil, nil, input, nil)
})
}
@@ -83,7 +83,7 @@ func BenchmarkTokenTransferFrom(b *testing.B) {
input, err := ContractABI.Pack("transferFrom", suite.address, common.HexToAddress("0x378c50D9264C63F3F92B806d4ee56E9D86FfB3Ec"), big.NewInt(0))
require.NoError(b, err)
nonce := suite.app.EvmKeeper.GetNonce(suite.address)
return types.NewTx(suite.app.EvmKeeper.ChainID(), nonce, &contract, big.NewInt(0), 410000, big.NewInt(1), input, nil)
return types.NewTx(suite.app.EvmKeeper.ChainID(), nonce, &contract, big.NewInt(0), 410000, big.NewInt(1), nil, nil, input, nil)
})
}
@@ -92,6 +92,6 @@ func BenchmarkTokenMint(b *testing.B) {
input, err := ContractABI.Pack("mint", common.HexToAddress("0x378c50D9264C63F3F92B806d4ee56E9D86FfB3Ec"), big.NewInt(1000))
require.NoError(b, err)
nonce := suite.app.EvmKeeper.GetNonce(suite.address)
return types.NewTx(suite.app.EvmKeeper.ChainID(), nonce, &contract, big.NewInt(0), 410000, big.NewInt(1), input, nil)
return types.NewTx(suite.app.EvmKeeper.ChainID(), nonce, &contract, big.NewInt(0), 410000, big.NewInt(1), nil, nil, input, nil)
})
}
+44 -14
View File
@@ -215,13 +215,20 @@ func (k Keeper) EthCall(c context.Context, req *types.EthCallRequest) (*types.Ms
ctx := sdk.UnwrapSDKContext(c)
k.WithContext(ctx)
var args types.CallArgs
var args types.TransactionArgs
err := json.Unmarshal(req.Args, &args)
if err != nil {
return nil, status.Error(codes.InvalidArgument, err.Error())
}
msg := args.ToMessage(req.GasCap)
if req.BaseFee != nil && req.BaseFee.IsNegative() {
return nil, status.Errorf(codes.InvalidArgument, "base fee cannot be negative %s", req.BaseFee)
}
msg, err := args.ToMessage(req.GasCap, req.GetBaseFee())
if err != nil {
return nil, status.Error(codes.InvalidArgument, err.Error())
}
params := k.GetParams(ctx)
feemktParams := k.feeMarketKeeper.GetParams(ctx)
@@ -266,7 +273,11 @@ func (k Keeper) EstimateGas(c context.Context, req *types.EthCallRequest) (*type
return nil, status.Error(codes.InvalidArgument, "gas cap cannot be lower than 21,000")
}
var args types.CallArgs
if req.BaseFee != nil && req.BaseFee.IsNegative() {
return nil, status.Errorf(codes.InvalidArgument, "base fee cannot be negative %s", req.BaseFee)
}
var args types.TransactionArgs
err := json.Unmarshal(req.Args, &args)
if err != nil {
return nil, status.Error(codes.InvalidArgument, err.Error())
@@ -308,7 +319,7 @@ func (k Keeper) EstimateGas(c context.Context, req *types.EthCallRequest) (*type
return nil, status.Error(codes.Internal, err.Error())
}
baseFee := k.feeMarketKeeper.GetBaseFee(ctx)
baseFee := req.GetBaseFee()
// Create a helper to check if a gas allowance results in an executable transaction
executable := func(gas uint64) (vmerror bool, rsp *types.MsgEthereumTxResponse, err error) {
@@ -317,7 +328,10 @@ func (k Keeper) EstimateGas(c context.Context, req *types.EthCallRequest) (*type
// Reset to the initial context
k.WithContext(ctx)
msg := args.ToMessage(req.GasCap)
msg, err := args.ToMessage(req.GasCap, baseFee)
if err != nil {
return false, nil, err
}
tracer := types.NewTracer(k.tracer, msg, ethCfg, k.Ctx().BlockHeight(), k.debug)
@@ -371,6 +385,10 @@ func (k Keeper) TraceTx(c context.Context, req *types.QueryTraceTxRequest) (*typ
return nil, status.Error(codes.InvalidArgument, "empty request")
}
if req.TraceConfig != nil && req.TraceConfig.Limit < 0 {
return nil, status.Errorf(codes.InvalidArgument, "output limit cannot be negative, got %d", req.TraceConfig.Limit)
}
ctx := sdk.UnwrapSDKContext(c)
k.WithContext(ctx)
@@ -413,17 +431,22 @@ func (k *Keeper) traceTx(
) (*interface{}, error) {
// Assemble the structured logger or the JavaScript tracer
var (
tracer vm.Tracer
err error
tracer vm.Tracer
overrides *ethparams.ChainConfig
err error
)
msg, err := tx.AsMessage(signer)
msg, err := tx.AsMessage(signer, baseFee)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
txHash := tx.Hash()
if traceConfig != nil && traceConfig.Overrides != nil {
overrides = traceConfig.Overrides.EthereumConfig(ethCfg.ChainID)
}
switch {
case traceConfig != nil && traceConfig.Tracer != "":
timeout := defaultTraceTimeout
@@ -436,10 +459,14 @@ func (k *Keeper) traceTx(
}
}
txContext := core.NewEVMTxContext(msg)
tCtx := &tracers.Context{
BlockHash: k.GetHashFn()(uint64(ctx.BlockHeight())),
TxIndex: int(txIndex),
TxHash: txHash,
}
// Construct the JavaScript tracer to execute with
if tracer, err = tracers.New(traceConfig.Tracer, txContext); err != nil {
if tracer, err = tracers.New(traceConfig.Tracer, tCtx); err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
@@ -456,10 +483,13 @@ func (k *Keeper) traceTx(
case traceConfig != nil:
logConfig := vm.LogConfig{
DisableMemory: traceConfig.DisableMemory,
Debug: traceConfig.Debug,
DisableStorage: traceConfig.DisableStorage,
DisableStack: traceConfig.DisableStack,
EnableMemory: traceConfig.EnableMemory,
DisableStorage: traceConfig.DisableStorage,
DisableStack: traceConfig.DisableStack,
EnableReturnData: traceConfig.EnableReturnData,
Debug: traceConfig.Debug,
Limit: int(traceConfig.Limit),
Overrides: overrides,
}
tracer = vm.NewStructLogger(&logConfig)
default:
+8 -8
View File
@@ -481,7 +481,7 @@ func (suite *KeeperTestSuite) TestEstimateGas() {
gasHelper := hexutil.Uint64(20000)
var (
args types.CallArgs
args types.TransactionArgs
gasCap uint64
)
testCases := []struct {
@@ -492,23 +492,23 @@ func (suite *KeeperTestSuite) TestEstimateGas() {
}{
// should success, because transfer value is zero
{"default args", func() {
args = types.CallArgs{To: &common.Address{}}
args = types.TransactionArgs{To: &common.Address{}}
}, true, 21000},
// should fail, because the default From address(zero address) don't have fund
{"not enough balance", func() {
args = types.CallArgs{To: &common.Address{}, Value: (*hexutil.Big)(big.NewInt(100))}
args = types.TransactionArgs{To: &common.Address{}, Value: (*hexutil.Big)(big.NewInt(100))}
}, false, 0},
// should success, enough balance now
{"enough balance", func() {
args = types.CallArgs{To: &common.Address{}, From: &suite.address, Value: (*hexutil.Big)(big.NewInt(100))}
args = types.TransactionArgs{To: &common.Address{}, From: &suite.address, Value: (*hexutil.Big)(big.NewInt(100))}
}, false, 0},
// should success, because gas limit lower than 21000 is ignored
{"gas exceed allowance", func() {
args = types.CallArgs{To: &common.Address{}, Gas: &gasHelper}
args = types.TransactionArgs{To: &common.Address{}, Gas: &gasHelper}
}, true, 21000},
// should fail, invalid gas cap
{"gas exceed global allowance", func() {
args = types.CallArgs{To: &common.Address{}}
args = types.TransactionArgs{To: &common.Address{}}
gasCap = 20000
}, false, 0},
// estimate gas of an erc20 contract deployment, the exact gas number is checked with geth
@@ -516,7 +516,7 @@ func (suite *KeeperTestSuite) TestEstimateGas() {
ctorArgs, err := ContractABI.Pack("", &suite.address, sdk.NewIntWithDecimal(1000, 18).BigInt())
suite.Require().NoError(err)
data := append(ContractBin, ctorArgs...)
args = types.CallArgs{
args = types.TransactionArgs{
From: &suite.address,
Data: (*hexutil.Bytes)(&data),
}
@@ -527,7 +527,7 @@ func (suite *KeeperTestSuite) TestEstimateGas() {
suite.Commit()
transferData, err := ContractABI.Pack("transfer", common.HexToAddress("0x378c50D9264C63F3F92B806d4ee56E9D86FfB3Ec"), big.NewInt(1000))
suite.Require().NoError(err)
args = types.CallArgs{To: &contractAddr, From: &suite.address, Data: (*hexutil.Bytes)(&transferData)}
args = types.TransactionArgs{To: &contractAddr, From: &suite.address, Data: (*hexutil.Bytes)(&transferData)}
}, true, 51880},
}
+6 -4
View File
@@ -184,7 +184,7 @@ func (suite *KeeperTestSuite) DeployTestContract(t require.TestingT, owner commo
require.NoError(t, err)
data := append(ContractBin, ctorArgs...)
args, err := json.Marshal(&types.CallArgs{
args, err := json.Marshal(&types.TransactionArgs{
From: &suite.address,
Data: (*hexutil.Bytes)(&data),
})
@@ -203,8 +203,9 @@ func (suite *KeeperTestSuite) DeployTestContract(t require.TestingT, owner commo
nil, // amount
res.Gas, // gasLimit
nil, // gasPrice
data, // input
nil, // accesses
nil, nil,
data, // input
nil, // accesses
)
erc20DeployTx.From = suite.address.Hex()
err = erc20DeployTx.Sign(ethtypes.LatestSignerForChainID(chainID), suite.signer)
@@ -221,7 +222,7 @@ func (suite *KeeperTestSuite) TransferERC20Token(t require.TestingT, contractAdd
transferData, err := ContractABI.Pack("transfer", to, amount)
require.NoError(t, err)
args, err := json.Marshal(&types.CallArgs{To: &contractAddr, From: &from, Data: (*hexutil.Bytes)(&transferData)})
args, err := json.Marshal(&types.TransactionArgs{To: &contractAddr, From: &from, Data: (*hexutil.Bytes)(&transferData)})
require.NoError(t, err)
res, err := suite.queryClient.EstimateGas(ctx, &types.EthCallRequest{
Args: args,
@@ -237,6 +238,7 @@ func (suite *KeeperTestSuite) TransferERC20Token(t require.TestingT, contractAdd
nil,
res.Gas,
nil,
nil, nil,
transferData,
nil,
)
+11 -13
View File
@@ -42,7 +42,7 @@ func (k *Keeper) NewEVM(
BlockNumber: big.NewInt(k.Ctx().BlockHeight()),
Time: big.NewInt(k.Ctx().BlockHeader().Time.Unix()),
Difficulty: big.NewInt(0), // unused. Only required in PoW context
// BaseFee: baseFee,
BaseFee: baseFee,
}
txCtx := core.NewEVMTxContext(msg)
@@ -54,14 +54,14 @@ func (k *Keeper) NewEVM(
// VMConfig creates an EVM configuration from the debug setting and the extra EIPs enabled on the
// module parameters. The config generated uses the default JumpTable from the EVM.
func (k Keeper) VMConfig(msg core.Message, params types.Params, tracer vm.Tracer) vm.Config {
// fmParams := k.feeMarketKeeper.GetParams(k.Ctx())
fmParams := k.feeMarketKeeper.GetParams(k.Ctx())
return vm.Config{
Debug: k.debug,
Tracer: tracer,
NoRecursion: false, // TODO: consider disabling recursion though params
// NoBaseFee: fmParams.NoBaseFee,
ExtraEips: params.EIPs(),
NoBaseFee: fmParams.NoBaseFee,
ExtraEips: params.EIPs(),
}
}
@@ -161,7 +161,7 @@ func (k *Keeper) ApplyTransaction(tx *ethtypes.Transaction) (*types.MsgEthereumT
baseFee := k.feeMarketKeeper.GetBaseFee(ctx)
msg, err := tx.AsMessage(signer)
msg, err := tx.AsMessage(signer, baseFee)
if err != nil {
return nil, stacktrace.Propagate(err, "failed to return ethereum transaction as core message")
}
@@ -270,7 +270,7 @@ func (k *Keeper) ApplyMessage(evm *vm.EVM, msg core.Message, cfg *params.ChainCo
sender := vm.AccountRef(msg.From())
contractCreation := msg.To() == nil
// isLondon := cfg.IsLondon(evm.Context.BlockNumber)
isLondon := cfg.IsLondon(evm.Context.BlockNumber)
intrinsicGas, err := k.GetEthIntrinsicGas(msg, cfg, contractCreation)
if err != nil {
@@ -296,14 +296,12 @@ func (k *Keeper) ApplyMessage(evm *vm.EVM, msg core.Message, cfg *params.ChainCo
ret, leftoverGas, vmErr = evm.Call(sender, *msg.To(), msg.Data(), leftoverGas, msg.Value())
}
refundQuotient := uint64(2)
refundQuotient := params.RefundQuotient
// refundQuotient := params.RefundQuotient
// // After EIP-3529: refunds are capped to gasUsed / 5
// if isLondon {
// refundQuotient = params.RefundQuotientEIP3529
// }
// After EIP-3529: refunds are capped to gasUsed / 5
if isLondon {
refundQuotient = params.RefundQuotientEIP3529
}
if query {
// gRPC query handlers don't go through the AnteHandler to deduct the gas fee from the sender or have access historical state.
@@ -74,7 +74,10 @@ func newNativeMessage(
) (core.Message, error) {
msgSigner := ethtypes.MakeSigner(cfg, big.NewInt(blockHeight))
var ethTx *ethtypes.Transaction
var (
ethTx *ethtypes.Transaction
baseFee *big.Int
)
if isLegacy {
templateLegacyTx.Nonce = nonce
ethTx = ethtypes.NewTx(templateLegacyTx)
@@ -91,7 +94,7 @@ func newNativeMessage(
return nil, err
}
m, err := msg.AsMessage(msgSigner) // TODO: add DynamicFeeTx
m, err := msg.AsMessage(msgSigner, baseFee) // TODO: add DynamicFeeTx
if err != nil {
return nil, err
}
+2 -2
View File
@@ -549,14 +549,14 @@ func (suite *KeeperTestSuite) CreateTestTx(msg *types.MsgEthereumTx, priv crypto
func (suite *KeeperTestSuite) TestAddLog() {
addr, privKey := tests.NewAddrKey()
msg := types.NewTx(big.NewInt(1), 0, &suite.address, big.NewInt(1), 100000, big.NewInt(1), []byte("test"), nil)
msg := types.NewTx(big.NewInt(1), 0, &suite.address, big.NewInt(1), 100000, big.NewInt(1), nil, nil, []byte("test"), nil)
msg.From = addr.Hex()
tx := suite.CreateTestTx(msg, privKey)
msg, _ = tx.GetMsgs()[0].(*types.MsgEthereumTx)
txHash := msg.AsTransaction().Hash()
msg2 := types.NewTx(big.NewInt(1), 1, &suite.address, big.NewInt(1), 100000, big.NewInt(1), []byte("test"), nil)
msg2 := types.NewTx(big.NewInt(1), 1, &suite.address, big.NewInt(1), 100000, big.NewInt(1), nil, nil, []byte("test"), nil)
msg2.From = addr.Hex()
tx2 := suite.CreateTestTx(msg2, privKey)
+1 -2
View File
@@ -60,8 +60,7 @@ func (k Keeper) DeductTxCostsFromUserBalance(
feeMktParams := k.feeMarketKeeper.GetParams(ctx)
if london && !feeMktParams.NoBaseFee {
// TODO: add to if statement above txData.TxType() == ethtypes.DynamicFeeTxType
if london && !feeMktParams.NoBaseFee && txData.TxType() == ethtypes.DynamicFeeTxType {
baseFee := k.feeMarketKeeper.GetBaseFee(ctx)
effectiveTip = cmath.BigMin(txData.GetGasTipCap(), new(big.Int).Sub(txData.GetGasFeeCap(), baseFee))
}
+2 -2
View File
@@ -126,7 +126,7 @@ func (suite *KeeperTestSuite) TestCheckSenderBalance() {
gasPrice = tc.gasPrice.BigInt()
}
tx := evmtypes.NewTx(zeroInt.BigInt(), 1, &to, amount, tc.gasLimit, gasPrice, nil, tc.accessList)
tx := evmtypes.NewTx(zeroInt.BigInt(), 1, &to, amount, tc.gasLimit, gasPrice, nil, nil, nil, tc.accessList)
tx.From = tc.from
txData, _ := evmtypes.UnpackTxData(tx.Data)
@@ -230,7 +230,7 @@ func (suite *KeeperTestSuite) TestDeductTxCostsFromUserBalance() {
gasPrice = tc.gasPrice.BigInt()
}
tx := evmtypes.NewTx(zeroInt.BigInt(), 1, &suite.address, amount, tc.gasLimit, gasPrice, nil, tc.accessList)
tx := evmtypes.NewTx(zeroInt.BigInt(), 1, &suite.address, amount, tc.gasLimit, gasPrice, nil, nil, nil, tc.accessList)
tx.From = suite.address.String()
txData, _ := evmtypes.UnpackTxData(tx.Data)