Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

evm: params #458

Merged
merged 32 commits into from
Sep 2, 2020
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
46ae305
evm: params
fedekunze Aug 18, 2020
3bd141b
setup
fedekunze Aug 18, 2020
72fc40e
bump commit
fedekunze Aug 18, 2020
7d041d7
fixes
fedekunze Aug 18, 2020
7b4e423
increase gas usage
fedekunze Aug 18, 2020
6fa8e29
tests
fedekunze Aug 18, 2020
2338725
conflicts
fedekunze Aug 31, 2020
9ffd1e8
evm denom param
fedekunze Sep 1, 2020
452cc78
more config updates
fedekunze Sep 1, 2020
8269746
update genesis
fedekunze Sep 1, 2020
39048af
update ante handler
fedekunze Sep 1, 2020
2289f34
csdb param test
fedekunze Sep 1, 2020
2a364e7
more tests and fixes
fedekunze Sep 1, 2020
fa83504
update statedb.Copy
fedekunze Sep 1, 2020
ab18272
lint
fedekunze Sep 1, 2020
c7c89ab
additional test
fedekunze Sep 1, 2020
d1c1e0a
fix importer tests
fedekunze Sep 1, 2020
d267cc3
fix AnteHandler test
fedekunze Sep 1, 2020
7fe95ba
minor update
fedekunze Sep 1, 2020
94adf0f
revert
fedekunze Sep 1, 2020
86dbdb5
undo gas update
fedekunze Sep 1, 2020
64957ac
stringer test
fedekunze Sep 1, 2020
7c09c23
changelog
fedekunze Sep 1, 2020
8fa07a8
fix csdb index error (#493)
noot Sep 1, 2020
5b9e443
Merge branch 'development' into evm-params
fedekunze Sep 2, 2020
c01ca51
Merge branch 'development' of github.com:ChainSafe/ethermint into evm…
fedekunze Sep 2, 2020
ff3e6b4
Merge branch 'evm-params' of github.com:ChainSafe/ethermint into evm-…
fedekunze Sep 2, 2020
7958be1
update default hash
fedekunze Sep 2, 2020
6fd7af7
update querier
fedekunze Sep 2, 2020
0ec092d
update rpc tests
fedekunze Sep 2, 2020
e5d1736
updates from development
fedekunze Sep 2, 2020
1b8a25b
fix estimate gas test
noot Sep 2, 2020
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 @@ -40,6 +40,9 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Improvements

* (app) [\#471](https://github.com/ChainSafe/ethermint/pull/471) Add `x/upgrade` module for managing software updates.
* (`x/evm`) [\#458](https://github.com/ChainSafe/ethermint/pull/458) Define parameter for token denomination used for the EVM module.
* (`x/evm`) [\#443](https://github.com/ChainSafe/ethermint/issues/443) Support custom Ethereum `ChainConfig` params.
* (types) [\#434](https://github.com/ChainSafe/ethermint/issues/434) Update default denomination to Atto Photon (`aphoton`).

### Bug Fixes

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ test-race:

test-import:
@go test ./importer -v --vet=off --run=TestImportBlocks --datadir tmp \
--blockchain blockchain --timeout=10m
--blockchain blockchain
rm -rf importer/tmp

test-rpc:
Expand Down
9 changes: 4 additions & 5 deletions app/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth"
authante "github.com/cosmos/cosmos-sdk/x/auth/ante"
"github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/bank"

"github.com/cosmos/ethermint/crypto"
evmtypes "github.com/cosmos/ethermint/x/evm/types"
Expand All @@ -29,7 +28,7 @@ const (
// Ethereum or SDK transaction to an internal ante handler for performing
// transaction-level processing (e.g. fee payment, signature verification) before
// being passed onto it's respective handler.
func NewAnteHandler(ak auth.AccountKeeper, bk bank.Keeper, sk types.SupplyKeeper) sdk.AnteHandler {
func NewAnteHandler(ak auth.AccountKeeper, evmKeeper EVMKeeper, sk types.SupplyKeeper) sdk.AnteHandler {
return func(
ctx sdk.Context, tx sdk.Tx, sim bool,
) (newCtx sdk.Context, err error) {
Expand All @@ -53,11 +52,11 @@ func NewAnteHandler(ak auth.AccountKeeper, bk bank.Keeper, sk types.SupplyKeeper
case evmtypes.MsgEthereumTx:
anteHandler = sdk.ChainAnteDecorators(
NewEthSetupContextDecorator(), // outermost AnteDecorator. EthSetUpContext must be called first
NewEthMempoolFeeDecorator(),
NewEthMempoolFeeDecorator(evmKeeper),
NewEthSigVerificationDecorator(),
NewAccountVerificationDecorator(ak, bk),
NewAccountVerificationDecorator(ak, evmKeeper),
NewNonceVerificationDecorator(ak),
NewEthGasConsumeDecorator(ak, sk),
NewEthGasConsumeDecorator(ak, sk, evmKeeper),
NewIncrementSenderSequenceDecorator(ak), // innermost AnteDecorator.
)
default:
Expand Down
3 changes: 2 additions & 1 deletion app/ante/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,9 @@ func (suite *AnteTestSuite) TestEthInvalidMempoolFees() {
// setup app with checkTx = true
suite.app = app.Setup(true)
suite.ctx = suite.app.BaseApp.NewContext(true, abci.Header{Height: 1, ChainID: "3", Time: time.Now().UTC()})
suite.anteHandler = ante.NewAnteHandler(suite.app.AccountKeeper, suite.app.BankKeeper, suite.app.SupplyKeeper)
suite.app.EvmKeeper.SetParams(suite.ctx, evmtypes.DefaultParams())

suite.anteHandler = ante.NewAnteHandler(suite.app.AccountKeeper, suite.app.EvmKeeper, suite.app.SupplyKeeper)
suite.ctx = suite.ctx.WithMinGasPrices(sdk.NewDecCoins(sdk.NewDecCoin(types.DenomDefault, sdk.NewInt(500000))))
addr1, priv1 := newTestAddrKey()
addr2, _ := newTestAddrKey()
Expand Down
56 changes: 36 additions & 20 deletions app/ante/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth"
authante "github.com/cosmos/cosmos-sdk/x/auth/ante"
"github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/bank"

emint "github.com/cosmos/ethermint/types"
evmtypes "github.com/cosmos/ethermint/x/evm/types"
Expand All @@ -18,6 +17,11 @@ import (
ethcore "github.com/ethereum/go-ethereum/core"
)

// EVMKeeper defines the expected keeper interface used on the Eth AnteHandler
type EVMKeeper interface {
GetParams(ctx sdk.Context) evmtypes.Params
}

// EthSetupContextDecorator sets the infinite GasMeter in the Context and wraps
// the next AnteHandler with a defer clause to recover from any downstream
// OutOfGas panics in the AnteHandler chain to return an error with information
Expand Down Expand Up @@ -68,11 +72,15 @@ func (escd EthSetupContextDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simu

// EthMempoolFeeDecorator validates that sufficient fees have been provided that
// meet a minimum threshold defined by the proposer (for mempool purposes during CheckTx).
type EthMempoolFeeDecorator struct{}
type EthMempoolFeeDecorator struct {
evmKeeper EVMKeeper
}

// NewEthMempoolFeeDecorator creates a new EthMempoolFeeDecorator
func NewEthMempoolFeeDecorator() EthMempoolFeeDecorator {
return EthMempoolFeeDecorator{}
func NewEthMempoolFeeDecorator(ek EVMKeeper) EthMempoolFeeDecorator {
return EthMempoolFeeDecorator{
evmKeeper: ek,
}
}

// AnteHandle verifies that enough fees have been provided by the
Expand All @@ -90,16 +98,18 @@ func (emfd EthMempoolFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simula
return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "invalid transaction type: %T", tx)
}

evmDenom := emfd.evmKeeper.GetParams(ctx).EvmDenom

// fee = GP * GL
fee := sdk.NewInt64DecCoin(emint.DenomDefault, msgEthTx.Fee().Int64())
fee := sdk.NewInt64DecCoin(evmDenom, msgEthTx.Fee().Int64())

minGasPrices := ctx.MinGasPrices()

// check that fee provided is greater than the minimum
// NOTE: we only check if aphotons are present in min gas prices. It is up to the
// sender if they want to send additional fees in other denominations.
var hasEnoughFees bool
if fee.Amount.GTE(minGasPrices.AmountOf(emint.DenomDefault)) {
if fee.Amount.GTE(minGasPrices.AmountOf(evmDenom)) {
hasEnoughFees = true
}

Expand Down Expand Up @@ -150,15 +160,15 @@ func (esvd EthSigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, s

// AccountVerificationDecorator validates an account balance checks
type AccountVerificationDecorator struct {
ak auth.AccountKeeper
bk bank.Keeper
ak auth.AccountKeeper
evmKeeper EVMKeeper
}

// NewAccountVerificationDecorator creates a new AccountVerificationDecorator
func NewAccountVerificationDecorator(ak auth.AccountKeeper, bk bank.Keeper) AccountVerificationDecorator {
func NewAccountVerificationDecorator(ak auth.AccountKeeper, ek EVMKeeper) AccountVerificationDecorator {
return AccountVerificationDecorator{
ak: ak,
bk: bk,
ak: ak,
evmKeeper: ek,
}
}

Expand Down Expand Up @@ -192,12 +202,14 @@ func (avd AccountVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, s
)
}

evmDenom := avd.evmKeeper.GetParams(ctx).EvmDenom

// validate sender has enough funds to pay for gas cost
balance := sdk.Coin{Denom: emint.DenomDefault, Amount: acc.GetCoins().AmountOf(emint.DenomDefault)}
if balance.Amount.BigInt().Cmp(msgEthTx.Cost()) < 0 {
balance := acc.GetCoins().AmountOf(evmDenom)
if balance.BigInt().Cmp(msgEthTx.Cost()) < 0 {
return ctx, sdkerrors.Wrapf(
sdkerrors.ErrInsufficientFunds,
"sender balance < tx gas cost (%s < %s%s)", balance.String(), msgEthTx.Cost().String(), emint.DenomDefault,
"sender balance < tx gas cost (%s%s < %s%s)", balance.String(), evmDenom, msgEthTx.Cost().String(), evmDenom,
)
}

Expand Down Expand Up @@ -250,15 +262,17 @@ func (nvd NonceVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim
// EthGasConsumeDecorator validates enough intrinsic gas for the transaction and
// gas consumption.
type EthGasConsumeDecorator struct {
ak auth.AccountKeeper
sk types.SupplyKeeper
ak auth.AccountKeeper
sk types.SupplyKeeper
evmKeeper EVMKeeper
}

// NewEthGasConsumeDecorator creates a new EthGasConsumeDecorator
func NewEthGasConsumeDecorator(ak auth.AccountKeeper, sk types.SupplyKeeper) EthGasConsumeDecorator {
func NewEthGasConsumeDecorator(ak auth.AccountKeeper, sk types.SupplyKeeper, ek EVMKeeper) EthGasConsumeDecorator {
return EthGasConsumeDecorator{
ak: ak,
sk: sk,
ak: ak,
sk: sk,
evmKeeper: ek,
}
}

Expand Down Expand Up @@ -307,8 +321,10 @@ func (egcd EthGasConsumeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simula
// Cost calculates the fees paid to validators based on gas limit and price
cost := new(big.Int).Mul(msgEthTx.Data.Price, new(big.Int).SetUint64(gasLimit))

evmDenom := egcd.evmKeeper.GetParams(ctx).EvmDenom

feeAmt := sdk.NewCoins(
sdk.NewCoin(emint.DenomDefault, sdk.NewIntFromBigInt(cost)),
sdk.NewCoin(evmDenom, sdk.NewIntFromBigInt(cost)),
)

err = auth.DeductFees(egcd.sk, ctx, senderAcc, feeAmt)
Expand Down
4 changes: 3 additions & 1 deletion app/ante/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ func (suite *AnteTestSuite) SetupTest() {
suite.app.Codec().RegisterConcrete(&sdk.TestMsg{}, "test/TestMsg", nil)

suite.ctx = suite.app.BaseApp.NewContext(checkTx, abci.Header{Height: 1, ChainID: "3", Time: time.Now().UTC()})
suite.anteHandler = ante.NewAnteHandler(suite.app.AccountKeeper, suite.app.BankKeeper, suite.app.SupplyKeeper)
suite.app.EvmKeeper.SetParams(suite.ctx, evmtypes.DefaultParams())

suite.anteHandler = ante.NewAnteHandler(suite.app.AccountKeeper, suite.app.EvmKeeper, suite.app.SupplyKeeper)
}

func TestAnteTestSuite(t *testing.T) {
Expand Down
7 changes: 4 additions & 3 deletions app/ethermint.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func NewEthermintApp(

cdc := ethermintcodec.MakeCodec(ModuleBasics)

// use custom Ethermint transaction decoder
// NOTE we use custom Ethermint transaction decoder that supports the sdk.Tx interface instead of sdk.StdTx
bApp := bam.NewBaseApp(appName, logger, db, evm.TxDecoder(cdc), baseAppOptions...)
bApp.SetCommitMultiStoreTracer(traceStore)
bApp.SetAppVersion(version.Version)
Expand Down Expand Up @@ -182,6 +182,7 @@ func NewEthermintApp(
app.subspaces[gov.ModuleName] = app.ParamsKeeper.Subspace(gov.DefaultParamspace).WithKeyTable(gov.ParamKeyTable())
app.subspaces[crisis.ModuleName] = app.ParamsKeeper.Subspace(crisis.DefaultParamspace)
app.subspaces[evidence.ModuleName] = app.ParamsKeeper.Subspace(evidence.DefaultParamspace)
app.subspaces[evm.ModuleName] = app.ParamsKeeper.Subspace(evm.DefaultParamspace)

// use custom Ethermint account for contracts
app.AccountKeeper = auth.NewAccountKeeper(
Expand Down Expand Up @@ -212,7 +213,7 @@ func NewEthermintApp(
)
app.UpgradeKeeper = upgrade.NewKeeper(skipUpgradeHeights, keys[upgrade.StoreKey], app.cdc)
app.EvmKeeper = evm.NewKeeper(
app.cdc, keys[evm.StoreKey], app.AccountKeeper,
app.cdc, keys[evm.StoreKey], app.subspaces[evm.ModuleName], app.AccountKeeper,
)
app.FaucetKeeper = faucet.NewKeeper(
app.cdc, keys[faucet.StoreKey], app.SupplyKeeper,
Expand Down Expand Up @@ -311,7 +312,7 @@ func NewEthermintApp(
// initialize BaseApp
app.SetInitChainer(app.InitChainer)
app.SetBeginBlocker(app.BeginBlocker)
app.SetAnteHandler(ante.NewAnteHandler(app.AccountKeeper, app.BankKeeper, app.SupplyKeeper))
app.SetAnteHandler(ante.NewAnteHandler(app.AccountKeeper, app.EvmKeeper, app.SupplyKeeper))
app.SetEndBlocker(app.EndBlocker)

if loadLatest {
Expand Down
Loading