-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
imp(feemarket): update
BaseFee
based on GasWanted
(#1105)
* add gasWanted transient store keys * add gasWanted transient store keeper functions * add gasWanted transient store tracker * add comment * remove unncesary comment * remove unnecesary function * fix tests * fix bad comment * remove unnecesary comment * update comment * update changelog * Update CHANGELOG.md Co-authored-by: Federico Kunze Küllmer <[email protected]> * add GasWantedDecorator * remove unnecesary comments * gasWanted decorator test * fix tests * fix tests and build * fix lint * updated end block event * Update app/ante/fee_market.go Co-authored-by: Federico Kunze Küllmer <[email protected]> * fix undeclared variable * Update app/ante/fee_market_test.go * remove unnecesary line * migrate MinGasMultiplier to FeeMarket module * set limited gas wanted * remove old newKeeper param * update proto comment * fix test * update comments * Update x/feemarket/keeper/abci.go Co-authored-by: Federico Kunze Küllmer <[email protected]> * address comments from review * tidy * tests Co-authored-by: Federico Kunze Küllmer <[email protected]>
- Loading branch information
Showing
46 changed files
with
570 additions
and
521 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package ante | ||
|
||
import ( | ||
"math/big" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
) | ||
|
||
// GasWantedDecorator keeps track of the gasWanted amount on the current block in transient store | ||
// for BaseFee calculation. | ||
// NOTE: This decorator does not perform any validation | ||
type GasWantedDecorator struct { | ||
evmKeeper EVMKeeper | ||
feeMarketKeeper FeeMarketKeeper | ||
} | ||
|
||
// NewGasWantedDecorator creates a new NewGasWantedDecorator | ||
func NewGasWantedDecorator( | ||
evmKeeper EVMKeeper, | ||
feeMarketKeeper FeeMarketKeeper, | ||
) GasWantedDecorator { | ||
return GasWantedDecorator{ | ||
evmKeeper, | ||
feeMarketKeeper, | ||
} | ||
} | ||
|
||
func (gwd GasWantedDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { | ||
params := gwd.evmKeeper.GetParams(ctx) | ||
ethCfg := params.ChainConfig.EthereumConfig(gwd.evmKeeper.ChainID()) | ||
|
||
blockHeight := big.NewInt(ctx.BlockHeight()) | ||
london := ethCfg.IsLondon(blockHeight) | ||
|
||
feeTx, ok := tx.(sdk.FeeTx) | ||
if ok && london { | ||
gasWanted := feeTx.GetGas() | ||
feeMktParams := gwd.feeMarketKeeper.GetParams(ctx) | ||
// Add total gasWanted to cumulative in block transientStore in FeeMarket module | ||
if feeMktParams.IsBaseFeeEnabled(ctx.BlockHeight()) { | ||
if _, err := gwd.feeMarketKeeper.AddTransientGasWanted(ctx, gasWanted); err != nil { | ||
return ctx, sdkerrors.Wrapf(err, "failed to add gas wanted to transient store") | ||
} | ||
} | ||
} | ||
|
||
return next(ctx, tx, simulate) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package ante_test | ||
|
||
import ( | ||
"math/big" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" | ||
ethtypes "github.com/ethereum/go-ethereum/core/types" | ||
"github.com/tharsis/ethermint/app/ante" | ||
"github.com/tharsis/ethermint/tests" | ||
evmtypes "github.com/tharsis/ethermint/x/evm/types" | ||
) | ||
|
||
func (suite AnteTestSuite) TestGasWantedDecorator() { | ||
suite.enableFeemarket = true | ||
suite.SetupTest() | ||
dec := ante.NewGasWantedDecorator(suite.app.EvmKeeper, suite.app.FeeMarketKeeper) | ||
from, fromPrivKey := tests.NewAddrKey() | ||
to := tests.GenerateAddress() | ||
|
||
testCases := []struct { | ||
name string | ||
expectedGasWanted uint64 | ||
malleate func() sdk.Tx | ||
}{ | ||
{ | ||
"Cosmos Tx", | ||
TestGasLimit, | ||
func() sdk.Tx { | ||
denom := evmtypes.DefaultEVMDenom | ||
testMsg := banktypes.MsgSend{ | ||
FromAddress: "evmos1x8fhpj9nmhqk8z9kpgjt95ck2xwyue0ptzkucp", | ||
ToAddress: "evmos1dx67l23hz9l0k9hcher8xz04uj7wf3yu26l2yn", | ||
Amount: sdk.Coins{sdk.Coin{Amount: sdk.NewInt(10), Denom: denom}}, | ||
} | ||
txBuilder := suite.CreateTestCosmosTxBuilder(sdk.NewInt(10), "stake", &testMsg) | ||
return txBuilder.GetTx() | ||
}, | ||
}, | ||
{ | ||
"Ethereum Legacy Tx", | ||
TestGasLimit, | ||
func() sdk.Tx { | ||
msg := suite.BuildTestEthTx(from, to, nil, make([]byte, 0), big.NewInt(0), nil, nil, nil) | ||
return suite.CreateTestTx(msg, fromPrivKey, 1, false) | ||
}, | ||
}, | ||
{ | ||
"Ethereum Access List Tx", | ||
TestGasLimit, | ||
func() sdk.Tx { | ||
emptyAccessList := ethtypes.AccessList{} | ||
msg := suite.BuildTestEthTx(from, to, nil, make([]byte, 0), big.NewInt(0), nil, nil, &emptyAccessList) | ||
return suite.CreateTestTx(msg, fromPrivKey, 1, false) | ||
}, | ||
}, | ||
{ | ||
"Ethereum Dynamic Fee Tx (EIP1559)", | ||
TestGasLimit, | ||
func() sdk.Tx { | ||
emptyAccessList := ethtypes.AccessList{} | ||
msg := suite.BuildTestEthTx(from, to, nil, make([]byte, 0), big.NewInt(0), big.NewInt(100), big.NewInt(50), &emptyAccessList) | ||
return suite.CreateTestTx(msg, fromPrivKey, 1, false) | ||
}, | ||
}, | ||
{ | ||
"EIP712 message", | ||
200000, | ||
func() sdk.Tx { | ||
amount := sdk.NewCoins(sdk.NewCoin(evmtypes.DefaultEVMDenom, sdk.NewInt(20))) | ||
gas := uint64(200000) | ||
acc := suite.app.AccountKeeper.NewAccountWithAddress(suite.ctx, from.Bytes()) | ||
suite.Require().NoError(acc.SetSequence(1)) | ||
suite.app.AccountKeeper.SetAccount(suite.ctx, acc) | ||
tx := suite.CreateTestEIP712TxBuilderMsgSend(acc.GetAddress(), fromPrivKey, suite.ctx.ChainID(), gas, amount) | ||
return tx.GetTx() | ||
}, | ||
}, | ||
} | ||
|
||
// cumulative gas wanted from all test transactions in the same block | ||
var expectedGasWanted uint64 | ||
|
||
for _, tc := range testCases { | ||
suite.Run(tc.name, func() { | ||
_, err := dec.AnteHandle(suite.ctx, tc.malleate(), false, NextFn) | ||
suite.Require().NoError(err) | ||
|
||
gasWanted := suite.app.FeeMarketKeeper.GetTransientGasWanted(suite.ctx) | ||
expectedGasWanted += tc.expectedGasWanted | ||
suite.Require().Equal(expectedGasWanted, gasWanted) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.