Skip to content

Commit

Permalink
Fix Message Fees with v0.46 changes. (#1060)
Browse files Browse the repository at this point in the history
* [995]: Bump cosmos to v0.46.0-pio-1-rc1 (from v0.45.5-pio-1).

* [995]: Add changelog line.

* [995]: Remove call to authrest.RegisterTxRoutes since it was deprecated and now no longer exists.

* [995]: Replace import of github.com/cosmos/cosmos-sdk/x/auth/legacy/legacytx with github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx since it was moved.

* [995]: Remove imports of github.com/cosmos/cosmos-sdk/client/rest which was deprecated and no longer exists. Also remove all the RegisterRESTRoutes functions and calls.

* [995]: Update the name client's call to govclient.NewProposalHandler and delete the name client's rest.go since nothing in there is used anymore and github.com/cosmos/cosmos-sdk/x/gov/client/rest has been removed.

* [995]: Remove all uses of github.com/cosmos/cosmos-sdk/types/rest which was deprecated, and has now been removed.

* [995]: Update ibc-go to v5.0.0-beta1 since that's the first one that supports cosmos v0.46.

* [995]: Remove google.golang.org/grpc v1.33.2 replace line. It was added when we bumped cosmos to v0.41.0 (from v0.40.1). But now some stuff in the newer version (v1.48.0) is needed by cosmos.

* [995]: Update the cosmos-sdk version in the require section (even though it's being replaced below).

* [995]: Add a replace line for wasmd to use a local verison. There's a draft PR to update wasmd to v0.46: CosmWasm/wasmd#930 That's what I've got locally and will be referencing. Not yet sure what I'll do if I need to push this up before they've got a tagged version.

* [995]: go mod tidy (finally, it works).

* [995]: Add v0.46 to the TODO in go.mod to help identify it as something that needs to be done as part of the v0.46 update.

* [995]: Fix compliation issues in app.go.

* [995]: Fix compilation issues in root.go.

* [995]: Switch to using storetypes.StoreKey (from sdk.StoreKey).

* [995]: Fix uses of coins.SafeSub since it's now vararg.

* [995]: Fix the gov stuff that moved to v1beta1.

* [995]: Add the FeeGasMeter.GasRemaining function that was added to the interface.

* [995]: Update the antewrapper handler to use a couple new functions that changed.

* [995]: Fix a couple more govtypes moves.

* [995]: change a coins.Sub call to use varargs.

* [995]: Provide the expiration time as a reference to authz.NewMsgGrant since they seem to have changed it to a reference.

* [995]: Fix uses of the renamed GenSignedMockTx (was GenTx) and SimDeliver (was Deliver) sim functions.

* [995]: update call to AddressAndDenomFromBalancesStore (used to be AddressFromBalancesStore).

* [995]: Fix call to GetPubKey that now also returns an error (instead of panic).

* [995]: Switch to a local version of cosmos so I can test the authz fix.

* [995]: Switch to GetAuthorization (from GetCleanAuthorization).

* [995]: Replace the rest of the GenTx calls with GenSignedMockTx.

* [995]: Fix uses of simapp.FundAccount and standardize all of them to just use the bank module's testutil.FundAccount.

* [995]: Fix the rest of the uses of SimDeliver (was previously named Deliver).

* [995]: Remove a bunch of test helpers that aren't used but are available from the SDK.

* [995]: Delete our version of EmptyAppOptions which was just a copy of the cosmos version, and switch to using the cosmos version.

* [995]: Standardize the import of github.com/cosmos/cosmos-sdk/simapp to be aliased to sdksim.

* [995]: Fix uses of AccAddressFromHexUnsafe (used to be named AccAddressFromHex).

* [995]: Fix uses of testnet.New.

* [995]: Remove the use of MaxWasmCodeSize and set the MaxWasmSize instead.

* [995]: Fix simulation call to wasm.NewAppModule, which requires some new arguments.

* [995]: Remove use of UpgradeInfo and replace it with Plan.

* [995]: Switch to .Codec (from JSONCodec) since the latter was removed from the context and we're supposed to use .Codec now.

* [995]: Provide a codec to all calls to kerying.New.

* [995]: Update uses of keyring.Record.GetAddress to account for the additional error return value.

* [995]: gov module's GenesisState is now in v1beta1 and the GenerateSaveCoinKey moved to testutil.

* [995]: switch to keyring.Record (used be called Info). Add handling of the error return value from GetAddress (newly added).

* [995]: account for the added error return value from GetPubKey. Call BuildUnsignedTx directly from the factory since it was moved there.

* [995]: gov module's GenesisState was moved to v1beta1.

* [995]: Fix several complaints about the receivers in the dbmigrator migrator tests.

* [995]: Fix several complaints about the ReflectorTestSuit method receivers having a lock but being concrete.

* [995]: Correct uses of the encoding config's Codec (used to be called Marshaller).

* [995]: Update a use of NewDeductFeeDecorator (used to be called NewMempoolFeeDecorator).

* [995]: Fix some complaints about variable names conflicting with import names.

* [995]: Comment out a couple more uses of SetMsgServiceRouter (with a TODO above them). Fix the expiration arg in all calls to SaveGrant and replace the last few uses of GetCleanAuthorization.

* [995]: Switch to pruning/types for the pruning options (was moved from store/types).

* [995]: Make the marker HandlerTestSuite methods have a pointer receiver since it does some lock stuff and Intellij complains.

* [995]: The InitialStake field now requires an sdk Int.

* [995]: The sdksim.Setup function now also takes in the Testing variable.

* [995]: The NewTextProposal function moved to gov types v1beta1.

* [995]: Use the SetMsgServiceRouter again.

* [995]: Fix some errorcheck lint complaints. The functions that it's now complaining about all are hard-coded to return nil. I thought about just putting a nolint comment on them stating such, but eh, this protects us from future changes to those SDK functions.

* [995]: The clientCtx.Codec returns an interface now, so there's no need to type-assert/convert it anymore. This fixes some gocritic linter complaints.

* [995]: Tweak the makefile a bit. Don't output errors from go mod list when getting the TM_VERSION; those will be output later if that value is needed. Echo the commands from several targets that used to have them suppressed; just makes it easier to troubleshoot. Use the GO variable for all go executions. Do a go.sum before running tests.

* [995]: Rip out all the stuff added to facilitate having a kafka dependency.

* [995]: Switch to cosmos version v0.46.0-pio-1-rc2.

* [995]: Update app/test_helpers.go to bring it in line with Cosmos' simapp/test_helpers.go. Also stop using DefaultNodeHome for unit tests.

* [995]: Put the marker authz_test in the types_test package due to circular import cycle with /app.

* [995]: Bring prepForZeroHeightGenesis inline with the updated simapp version and clean up the TestSimAppExportAndBlockedAddrs to be closer to the cosmos version too (and use the new stuff).

* [995]: Remove the config index-events workaround since it was fixed in v0.46.

* [995]: Tweak some fee antewrapper errors to make them match Cosmos' similar ones. Also, the addresses were being converted to hex instead of bech32. So this is better now.

* [995]: Fix the TestEnsureMempoolFees test because Cosmos now checks for fund availability. Also clean up the antewrapper tests so that they only run once (they were running thrice). And update the TestDeductFeesNoDelegation to be more robust and make sure we're getting the expectd errors instead of just any error.

* [995]: Segment TestMsgService since it's failing and need to slog through it. Bump the gas used in there since it's no longer enough again, and remove the check function and all it's uses, replaced with require NoError.

* [995]: Fix unit test that was failing because TextProposal moved to v1beta1 (from types) and is in an error string check.

* [995]: In the metadata cli test, set the suite's config value before generating the keyring stuff so that it can use the config as intended (not sure how it didn't panic before). Also change a couple expected error strings because some errors changed.

* [995]: Fix the marker cli tests. Need more gas for the gov proposals. Need to set the suite's cfg earlier (same as what metadate cli tests did). And now expect a 0x9 instead of 0x5 from the withdraw proposal.

* [995]: Fix the marker handler test, invalid proposal since the package changed for TextProposal (to v1beta1 from types).

* [995]: Correct an incorrectly updated comment (that might be useful when fixing stuff in a bit).

* [995]: Fix the marker operations test that changed due to added use of the random number generator by the SDK. Also added a note about that and a list of valid options that things might change to in the future. But I left it looking for one specific name since that shouldn't change unless making changes to the SDK or operations.

* [995]: Fix the Holding query since the data is stored differently now. key is <prefix><account><denom>, value is <amount>. Used to be key is <prefix><account>, value is <coin>.

* [995]: Refactor the marker Holding query to use the sdk's DenomOwners query (should have better performance).

* [995]: lint fixes.

* [995]: Undo a lot of the formatting/division changes that I had made to TestMsgService since we're going to fix that in a separte PR.

* [995]: Skip several MsgService tests, to be fixed in a separate PR.

* [995]: Switch the TODO comment in msg_fees_decorator to reference that it's required for 1.12.

* [995]: Enhance the changelog with more info about what's being done here.

* [995]: Switch wasm to a version tagged on our own fork so that we can keep moving forward.

* [995]: Add new upgrade handler that runs migrations. Add a couple 1.12.x TODO entries.

* [995]: Remove unused deprecated Conditions field.

* [995]: Replace deprecated use of strings.Title.

* [995]: Replace use of a couple deprecated gov cli flags, and just make local versions of them to use instead.

* [995]: Correct the changelog entry about the DenomOwners query.

* [995]: Undo a comment change that will be handy during a followup.

* [995]: Delete a couple missed references to sims-state-listening.mk.

* [1010]: Replace use of the deprecated sdkResponse.Data field. The documentation says it's still usable, but something changed because it made the sim tests all start failing due to index out of range (asking for 0, but no entries). That indicates that stuff was missing from the Data field, and so we can't use it anymore.

* [995]: Fix the runsim sims. I accidentally got rid of the -tags part that allows the other dbs to be used. Also simplified it further since there doesn't need to be differences between the runsim and go test versions.

* [1010]: Tweak the .Data fix to use the GetCachedValue off the response rather than reunmarshaling it from the bytes.

* [995]: Add unit tests on the ExportAppStateAndValidators function.

* [995]: Fix the casting of the MsgInstantiateContractResponse.

* [995]: Update the TestAppImportExport simulation to bring it in line with it's cosmos-sdk counterpart. Fail if the db can't close. Handle the panic when there are no validators. Provide some keys to the authzkeeper checking.

* [995]: Fix a couple marker tests that started failing because I fixed the account numbers thing.

* [995]: Bump the sdk to v0.46.0-pio-1-rc3 (from v0.46.0-pio-1-rc2).

* [995]: Bump cosmos-sdk to v0.46.0-pio-1-rc4 (from v0.46.0-pio-1-rc3).

* [995]: Add ochre-rc1 upgrade handler.

* [995]: Fix the changelog so that this new stuff isn't listed in the 1.12 section.

* [995]: Update the TODO: Required comments to reference v1.13.x (instead of v1.12.x).

* [995]: Fix the name of the TestHandlerTestSuite (was TestAnteTestSuite, which is a different thing).

* [995]: Undo a change to the msg_fee_invoker that I made at some point, but now don't want since it's in an area to be fixed anyway.

* Updated to remove deprecated sdk.Int. (#1036)

* [995]: Disable the sims for the same reason I needed to disable some of the msg service router tests. Added TODO comments about removing the skips too.

* [995]: Add issue links to the TODOs needed to be todone with issue 1006 (the fees stuff).

* [995]: Add issue links to the other new TODOs.

* [995]: Bump cosmos to v0.46.0-pio-1-rc5 (from v0.46.0-pio-1-rc4).

* Replaced deprecated SetFullFundraiserPath with SetCoinType and SetPurpose (#1037)

* Removed SetFullFundraiserPath and replaced it with SetCoinType and SetPurpose.

* Added prefix_test and updated SetConfig to have a configurable seal param. This was mainly to help with testing.

* [995]: Lint fixes.

* [1006]: Create a public GetFeeTx that converts a tx to a fee tx or returns a standard error (since that was copied all over).

* [1006]: Refactor the TxGasLimitDecorator. Only bypass if ALL msgs are gov (instead of just at least one). Include both old and new governance messages.

* [1006]: Use our own antehandler in SetupTest.

* [1006]: Reorder the ante handlers to more closely match the SDK's default one.

* [1006]: A little cleanup on the MsgFeeDecorator.

* [1006]: Start refactoring the ProvenanceDeductFeeDecorator to more closely match the SDK's DeductFeeDecorator. Still have stuff to work out here though.

* Revert "[1006]: Start refactoring the ProvenanceDeductFeeDecorator to more closely match the SDK's DeductFeeDecorator. Still have stuff to work out here though."

This reverts commit b9a7a3c.

* [1006]: Remove all the test skips.

* [1006]: Get rid of the cosmosante.NewDeductFeeDecorator since we have our own already added (this was the primary source of problems).

* [1006]: Used named attributes in NewMsgFeesDecorator.

* [1006]: Include the MsgFeesKeeper when creating the AnteHandler for tests.

* [1006]: Bump the NewTestGasLimit because the TestDeductFeesNoDelegation didn't have enough.

* [1006]: Add a replacement for the MempoolFeeDecorator since that functionality got moved into the DeductFeeDecorator and we're using our own for that.

* [1006]: Create helper for getting the fee gas meter to standardize on the error.

* [1006]: consume coins instead of just a coin. This makes a lot of parts more robust (e.g. no longer assuming the coins are the same).

* [1006]: Remove some named return variables that don't need to be named.

* [1006]: Move CalculateAdditionalFeesToBePaid to the msgfees keeper since it's all msgfee lookup stuff anyway.

* [1006]: Pull in the cosmossdk.io/errors package.

* [1006]: Add the chainid back into test app setup since some of the fee stuff behaves differently when there's no chain id, and it was breaking tests.

* [1006]: Clean up the msg fee invoker and add the payer to the events.

* [1006]: Overhaul the msg service router. Extract the Provenance-specific stuff into it's own function so that the main function is nearly identical to what the SDK has. Really simplify what it's doing too.

* [1006]: Overhaul the ProvenanceDeductFeeDecorator. Make it closer to the DeductFeesDecorator in the SDK. Emit two events, one for the whole fee and one for the base fee (which is deducted in here). In here, check that the payer account has enough funds to cover the fees.

* [1006]: Overhaul the NewMsgFeesDecorator to only check that enough fees have been provided to cover the base fee plus any message based fees.

* [1006]: Update the antewrapper handler to call the new NewMinGasPricesDecorator and move the NewMsgFeesDecorator to right after that (since they're similar).

* [1006]: Remove the TestCalculateAdditionalFeesToBePaid tests from the antewrapper stuff since it moved elsewhere (along with the tests). Call antewrapper.NewMsgFeesDecorator with the correct new args.

* [1006]: Change the AnteTestSuite receivers to s (from suite).

* [1006]: Fix the prov feegrant tests that started to fail because of a change in the error messages.

* [1006]: Fix where the base fee wasn't being properly defined.

* [1006]: Fix and clean up a bunch of the antewrapper tests. Some were broken, some not doing what they said, and some were redundant. Also, functionality in those changed so they needed updating to reflect those changes.

* [1006]: Delete the TestEnsureMempoolFees test since a) the ProvenanceDeductFeeDecorator doesn't do that anymore and b) it was testing the SDK's NewDeductFeeDecorato.

* [1006]: Delete a bunch of tests that are no longer relevant and functionality is tested where it was moved.

* [1006]: a little cleanup and added robustnest.

* [1006]: small text tweak.

* [1006]: Lint fixes.

* [995]: Add some lookups to the TestRewardsProgramStartPerformQualifyingActions_Vote_InvalidDelegations test for some extra debug info.

* [995]: Fix import order.

* [995]: Refactor TestRewardsProgramStartPerformQualifyingActions_Vote_InvalidDelegations a bit. Make it so that the votes are coming from an account that isn't a validator.

* [995]: Remove the nickel upgrade handler and combine it with my ochre one.

* [995]: Add missing comment about how the tests are initiated.

* [995]: Lint fixes.

* [1006]: Simplify and fix MsgFeesDistribution.Increase. I originally had the logic backwards for adding to recipients. Also, go no longer complains when the map entry is null and you still call .Add on it.

* [1006]: Add some more tests on CalculateAdditionalFeesToBePaid to cover the different splits now.

* [1006]: Fix some test compilation issues from after the merge.

* [1006]: Rename suite to s.

* [1006]: Fix a couple unit tests now looking at the wrong denom.

* [1006]: Fix a unit test.

* [1006]: Re-enable TestRewardsProgramStart and bring it in-line with the other tests.

* [1006]: Re-enable the TestMsgServiceMsgFeeWithRecipient test and simplify all the msg_fees attribut json stuff.

* [1006]: Clean up and re-enable TestRewardsProgramStartPerformQualifyingActions.

* [1006]: Fix a bunch of the asserts and make the tests generally more robust. Add some missing NoError checks. Only access [0] after asserting it's not empty. Make the assert/require messages provide better info about what value is being checked. Include messages in all of the NoError checks.

* [1006]: Restrict lines to 130 charcters (except for the one function name that's super huge.

* [1006]: Update some test failure messages to provide more context (specially in loops).

* [1006]: Remove all the lines that just do ctx.WithBlockTime(time.Now()) since that doesn't actually do anything.

* [1006]: Fix the TestFullBIP44Path test to actually test what we're trying to test.

* [995]: Fix the TestFullBIP44Path test to actually test what we're trying to test.

* [995]: Use the FundModuleAccount function instead of minting and sending.

* [995]: Bump Cosmos-SDK to v0.46.1-pio-1-rc1 (from v0.46.0-pio-1-rc5). It's exactly the same, just named more accurately.

* [995]: lazy-load the govVoteMsgUrls messages, just to be safe.

* [995]: Update the isGovernanceMessage func to account for the new version of governance messages.

* [995]: Fix the gov msg count.

* [995]: Lint fixes. I really hate that the Go convention for acronyms in variable names is to capitalize all or none of them.

* [995]: Switch msgURL setting logic to just look for an empty slice instead of slice of specific length. Makes it a little more future-safe.

* [995]: Switch those checks to a nil check and add a comment about it.

* [1006]: Remove loop over map.

* [1006]: Enhance an error message.

* [1006]: Correct the amount being used by the message fee invoker.

* [1006]: Switch to our feegrant keeper interface and add a log message.

* [1006]: Add some debug logging.

* [1006]: Fix a comment.

* [1006]: Make the simulation gas limits a little more accurate by not bypassing some msg fee lookups.

* [1006]: Make an IsInitGenesis function to use in place of the ctx.BlockHeight() > 0 check. Probably going to need this elsewhere too.

* [1006]: Only check their accounts for the msg-based fees (don't include the base fee in the check). And only deduct the base fee if we're not in InitGenesis.

* [1006]: Send the address to DeductFees since the full account isn't needed. Also, add the account address to the error in there.

* [1006]: Fix a couple tests that broke because I changed which amounts are being checked in accounts and also changed the error message returned in one case.

* [1006]: Update the comment on checkTxFeeWithValidatorMinGasPrices too.

* [1006]: Add the min_fee_charged event/attribute back in and change baseFee back to what it was before (fee - additional fees).

* [1006]: Add a test that makes sure events are emitted for failed Txs wwhere the min fee is charged.

* [1006]: Expand the TestFailedTx to check both with and without msg-based fees.

* [1006]: Add a changelog entry.

* [1006]: Expand the event documentation a bit more.

* [1006]: Grammar fix.

* [1006]: Remove the upgrade test script that got accidentally added a bit ago.

Co-authored-by: Matt Witkowski <[email protected]>
  • Loading branch information
SpicyLemon and Matt Witkowski authored Sep 28, 2022
1 parent e0655fa commit 19fb4c3
Show file tree
Hide file tree
Showing 31 changed files with 2,776 additions and 2,167 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ Ref: https://keepachangelog.com/en/1.0.0/
* Stop using the deprecated Wrap and Wrapf functions in the sdk/types/errors package in favor of those functions off specific errors, or else the cosmossdk.io/errors package. [#1013](https://github.com/provenance-io/provenance/issues/995)
* For newly added reward's module, Voting incentive program, validator votes should count for higher shares, since they vote for all their delegations.
This feature allows the reward creator to introduce the multiplier to achieve the above.
* Refactored the fee handling [#1006](https://github.com/provenance-io/provenance/issues/1006):
* Created a `MinGasPricesDecorator` to replace the `MempoolFeeDecorator` that was removed from the SDK. It makes sure the fee is greater than the validators min-gas fee.
* Refactored the `MsgFeesDecorator` to only make sure there's enough fee provided. It no longer deducts/consumes anything and it no longer checks the payer's account.
* Refactored the `ProvenanceDeductFeeDecorator`. It now makes sure the payer has enough in their account to cover the additional fees. It also now deducts/consumes the `floor gas price * gas`.
* Added the `fee_payer` attribute to events of type `tx` involving fees (i.e. the ones with attributes `fee`, `min_fee_charged`, `additionalfee` and/or `baseFee`).
* Moved the additional fees calculation logic into the msgfees keeper.

### Bug Fixes

Expand Down
6 changes: 0 additions & 6 deletions app/sim_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ import (
// Profile with:
// go test -benchmem -run=^$ github.com/provenance-io/provenance/app -bench ^BenchmarkFullAppSimulation$ -Commit=true -cpuprofile cpu.out
func BenchmarkFullAppSimulation(b *testing.B) {
// TODO: Required for v1.13.x: Remove this b.Skip() line and fix things so these tests pass. https://github.com/provenance-io/provenance/issues/1006
b.Skip("This test is disabled, but must be re-enabled before v1.13 can be ready.")

b.ReportAllocs()
config, db, dir, logger, skip, err := sdksim.SetupSimulation("goleveldb-app-sim", "Simulation")
if err != nil {
Expand Down Expand Up @@ -67,9 +64,6 @@ func BenchmarkFullAppSimulation(b *testing.B) {
}

func BenchmarkInvariants(b *testing.B) {
// TODO: Required for v1.13.x: Remove this b.Skip() line and fix things so these tests pass. https://github.com/provenance-io/provenance/issues/1006
b.Skip("This test is disabled, but must be re-enabled before v1.13 can be ready.")

b.ReportAllocs()
config, db, dir, logger, skip, err := sdksim.SetupSimulation("leveldb-app-invariant-bench", "Simulation")
if err != nil {
Expand Down
15 changes: 0 additions & 15 deletions app/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ type StoreKeysPrefixes struct {
}

func TestFullAppSimulation(t *testing.T) {
// TODO: Required for v1.13.x: Remove this t.Skip() line and fix things so these tests pass. https://github.com/provenance-io/provenance/issues/1006
t.Skip("This test is disabled, but must be re-enabled before v1.13 can be ready.")

config, db, dir, logger, skip, err := sdksim.SetupSimulation("leveldb-app-sim", "Simulation")
if skip {
t.Skip("skipping provenance application simulation")
Expand Down Expand Up @@ -104,9 +101,6 @@ func TestFullAppSimulation(t *testing.T) {
}

func TestSimple(t *testing.T) {
// TODO: Required for v1.13.x: Remove this t.Skip() line and fix things so these tests pass. https://github.com/provenance-io/provenance/issues/1006
t.Skip("This test is disabled, but must be re-enabled before v1.13 can be ready.")

config, db, dir, logger, skip, err := sdksim.SetupSimulation("leveldb-app-sim", "Simulation")
if skip {
t.Skip("skipping provenance application simulation")
Expand Down Expand Up @@ -142,9 +136,6 @@ func TestSimple(t *testing.T) {
// Profile with:
// /usr/local/go/bin/go test -benchmem -run=^$ github.com/provenance-io/provenance -bench ^BenchmarkFullAppSimulation$ -Commit=true -cpuprofile cpu.out
func TestAppImportExport(t *testing.T) {
// TODO: Required for v1.13.x: Remove this t.Skip() line and fix things so these tests pass. https://github.com/provenance-io/provenance/issues/1006
t.Skip("This test is disabled, but must be re-enabled before v1.13 can be ready.")

// uncomment to run in ide without flags.
//sdksim.FlagEnabledValue = true

Expand Down Expand Up @@ -261,9 +252,6 @@ func TestAppImportExport(t *testing.T) {
}

func TestAppSimulationAfterImport(t *testing.T) {
// TODO: Required for v1.13.x: Remove this t.Skip() line and fix things so these tests pass. https://github.com/provenance-io/provenance/issues/1006
t.Skip("This test is disabled, but must be re-enabled before v1.13 can be ready.")

config, db, dir, logger, skip, err := sdksim.SetupSimulation("leveldb-app-sim", "Simulation")
if skip {
t.Skip("skipping application simulation after import")
Expand Down Expand Up @@ -342,9 +330,6 @@ func TestAppSimulationAfterImport(t *testing.T) {
// TODO: Make another test for the fuzzer itself, which just has noOp txs
// and doesn't depend on the application.
func TestAppStateDeterminism(t *testing.T) {
// TODO: Required for v1.13.x: Remove this t.Skip() line and fix things so these tests pass. https://github.com/provenance-io/provenance/issues/1006
t.Skip("This test is disabled, but must be re-enabled before v1.13 can be ready.")

if !sdksim.FlagEnabledValue {
t.Skip("skipping application simulation")
}
Expand Down
12 changes: 8 additions & 4 deletions app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type SetupOptions struct {
SkipUpgradeHeights map[int64]bool
EncConfig params.EncodingConfig
AppOpts servertypes.AppOptions
ChainID string
}

func setup(t *testing.T, withGenesis bool, invCheckPeriod uint) (*App, GenesisState) {
Expand Down Expand Up @@ -114,6 +115,7 @@ func NewAppWithCustomOptions(t *testing.T, isCheckTx bool, options SetupOptions)
Validators: []abci.ValidatorUpdate{},
ConsensusParams: DefaultConsensusParams,
AppStateBytes: stateBytes,
ChainId: options.ChainID,
},
)
}
Expand Down Expand Up @@ -141,7 +143,7 @@ func Setup(t *testing.T) *App {
Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100000000000000))),
}

app := SetupWithGenesisValSet(t, valSet, []authtypes.GenesisAccount{acc}, balance)
app := SetupWithGenesisValSet(t, "", valSet, []authtypes.GenesisAccount{acc}, balance)

return app
}
Expand Down Expand Up @@ -220,7 +222,7 @@ func SetupQuerier(t *testing.T) *App {
// that also act as delegators. For simplicity, each validator is bonded with a delegation
// of one consensus engine unit in the default token of the app from first genesis
// account. A Nop logger is set in App.
func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs []authtypes.GenesisAccount, balances ...banktypes.Balance) *App {
func SetupWithGenesisValSet(t *testing.T, chainID string, valSet *tmtypes.ValidatorSet, genAccs []authtypes.GenesisAccount, balances ...banktypes.Balance) *App {
t.Helper()

app, genesisState := setup(t, true, 5)
Expand All @@ -235,6 +237,7 @@ func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs
Validators: []abci.ValidatorUpdate{},
ConsensusParams: DefaultConsensusParams,
AppStateBytes: stateBytes,
ChainId: chainID,
},
)

Expand All @@ -245,14 +248,15 @@ func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs
AppHash: app.LastCommitID().Hash,
ValidatorsHash: valSet.Hash(),
NextValidatorsHash: valSet.Hash(),
ChainID: chainID,
}})

return app
}

// SetupWithGenesisAccounts initializes a new App with the provided genesis
// accounts and possible balances.
func SetupWithGenesisAccounts(t *testing.T, genAccs []authtypes.GenesisAccount, balances ...banktypes.Balance) *App {
func SetupWithGenesisAccounts(t *testing.T, chainID string, genAccs []authtypes.GenesisAccount, balances ...banktypes.Balance) *App {
t.Helper()

privVal := mock.NewPV()
Expand All @@ -263,7 +267,7 @@ func SetupWithGenesisAccounts(t *testing.T, genAccs []authtypes.GenesisAccount,
validator := tmtypes.NewValidator(pubKey, 1)
valSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{validator})

return SetupWithGenesisValSet(t, valSet, genAccs, balances...)
return SetupWithGenesisValSet(t, chainID, valSet, genAccs, balances...)
}

// GenesisStateWithSingleValidator initializes GenesisState with a single validator and genesis accounts
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ require (
github.com/stretchr/testify v1.8.0
github.com/tendermint/tendermint v0.34.21
github.com/tendermint/tm-db v0.6.7
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e
golang.org/x/text v0.3.7
google.golang.org/genproto v0.0.0-20220725144611-272f38e5d71b
google.golang.org/grpc v1.49.0
Expand Down Expand Up @@ -141,7 +142,6 @@ require (
go.etcd.io/bbolt v1.3.6 // indirect
go.opencensus.io v0.23.0 // indirect
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e // indirect
golang.org/x/net v0.0.0-20220726230323-06994584191e // indirect
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5 // indirect
golang.org/x/sys v0.0.0-20220727055044-e65921a090b8 // indirect
Expand Down
31 changes: 29 additions & 2 deletions internal/antewrapper/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package antewrapper

import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

// FeeMeterContextDecorator is an AnteDecorator that wraps the current
Expand All @@ -20,7 +21,33 @@ func NewFeeMeterContextDecorator() FeeMeterContextDecorator {
var _ sdk.AnteDecorator = FeeMeterContextDecorator{}

// AnteHandle implements the AnteDecorator.AnteHandle method
func (r FeeMeterContextDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
newCtx = ctx.WithGasMeter(NewFeeGasMeterWrapper(ctx.Logger(), ctx.GasMeter(), simulate))
func (r FeeMeterContextDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) {
newCtx := ctx.WithGasMeter(NewFeeGasMeterWrapper(ctx.Logger(), ctx.GasMeter(), simulate))
return next(newCtx, tx, simulate)
}

// GetFeeTx coverts the provided Tx to a FeeTx if possible.
func GetFeeTx(tx sdk.Tx) (sdk.FeeTx, error) {
feeTx, ok := tx.(sdk.FeeTx)
if !ok {
return nil, sdkerrors.ErrTxDecode.Wrap("Tx must be a FeeTx")
}
return feeTx, nil
}

// GetFeeGasMeter gets a FeeGasMeter from the provided context.
func GetFeeGasMeter(ctx sdk.Context) (*FeeGasMeter, error) {
feeGasMeter, ok := ctx.GasMeter().(*FeeGasMeter)
if !ok {
return nil, sdkerrors.ErrLogic.Wrap("gas meter is not a FeeGasMeter")
}
return feeGasMeter, nil
}

// IsInitGenesis returns true if the context indicates we're in InitGenesis.
func IsInitGenesis(ctx sdk.Context) bool {
// Note: This isn't fully accurate since you can initialize a chain at a height other than zero.
// But it should be good enough for our stuff. Ideally we'd want something specifically set in
// the context during InitGenesis to check, but that'd probably involve some SDK work.
return ctx.BlockHeight() <= 0
}
7 changes: 7 additions & 0 deletions internal/antewrapper/export_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package antewrapper

// Expose some private functions so they can be unit tested.
var (
IsGovMessage = isGovMessage
IsOnlyGovMsgs = isOnlyGovMsgs
)
6 changes: 3 additions & 3 deletions internal/antewrapper/fee_gas_meter.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ func (g *FeeGasMeter) String() string {
}

// ConsumeFee increments the amount of msg fee required by a msg type.
func (g *FeeGasMeter) ConsumeFee(amount sdk.Coin, msgType string, recipient string) {
func (g *FeeGasMeter) ConsumeFee(amount sdk.Coins, msgType string, recipient string) {
key := msgfeestypes.GetCompositeKey(msgType, recipient)
cur := g.usedFees[key]
if cur.Empty() {
g.usedFees[key] = sdk.NewCoins(amount)
g.usedFees[key] = sdk.NewCoins(amount...)
} else {
g.usedFees[key] = cur.Add(amount)
g.usedFees[key] = cur.Add(amount...)
}
g.feeCalls[key]++
}
Expand Down
10 changes: 5 additions & 5 deletions internal/antewrapper/fee_gas_meter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestFeeGasMeter(t *testing.T) {
} else {
usedFee = usedFee.Add(usageFee)
}
require.NotPanics(t, func() { meter.ConsumeFee(usageFee, msgType, "") }, "panicked on adding fees")
require.NotPanics(t, func() { meter.ConsumeFee(sdk.NewCoins(usageFee), msgType, "") }, "panicked on adding fees")
}

require.Panics(t, func() { meter.ConsumeGas(1, "") }, "Exceeded but not panicked. tc #%d", tcnum)
Expand All @@ -62,20 +62,20 @@ func TestFeeGasMeter(t *testing.T) {
assert.Equal(t, meter.FeeConsumed().Sort(), usedFee.Sort(), "FeeConsumed does not match all Fees")
meter2 := NewFeeGasMeterWrapper(log.TestingLogger(), sdkgas.NewGasMeter(100), false).(*FeeGasMeter)
meter2.ConsumeGas(sdkgas.Gas(50), "consume half max")
meter2.ConsumeFee(sdk.NewCoin(msgfeestype.NhashDenom, sdk.NewInt(1000000)), "/cosmos.bank.v1beta1.MsgSend", "")
meter2.ConsumeFee(sdk.NewCoins(sdk.NewCoin(msgfeestype.NhashDenom, sdk.NewInt(1000000))), "/cosmos.bank.v1beta1.MsgSend", "")
require.Equalf(t, "feeGasMeter:\n limit: 100\n consumed: 50 fee consumed: 1000000nhash", meter2.String(), "expect string output to match")
meter2.RefundGas(uint64(20), "refund")
require.Equalf(t, "feeGasMeter:\n limit: 100\n consumed: 30 fee consumed: 1000000nhash", meter2.String(), "expect string output to match")
require.Equalf(t, "1000000nhash", meter2.FeeConsumed().String(), "expect string output to match")
require.Panics(t, func() { meter2.ConsumeGas(sdkgas.Gas(70)+2, "panic") })
meter2.ConsumeFee(sdk.NewCoin(msgfeestype.NhashDenom, sdk.NewInt(2000000)), "/cosmos.bank.v1beta1.MsgSend", "")
meter2.ConsumeFee(sdk.NewCoins(sdk.NewCoin(msgfeestype.NhashDenom, sdk.NewInt(2000000))), "/cosmos.bank.v1beta1.MsgSend", "")
require.Equalf(t, "feeGasMeter:\n limit: 100\n consumed: 102 fee consumed: 3000000nhash", meter2.String(), "expect string output to match")
meter2.RefundGas(uint64(20), "refund")
require.Equalf(t, "feeGasMeter:\n limit: 100\n consumed: 82 fee consumed: 3000000nhash", meter2.String(), "expect string output to match")
require.Equalf(t, "3000000nhash", meter2.FeeConsumed().String(), "expect string output to match")
require.Equalf(t, "map[/cosmos.bank.v1beta1.MsgSend:3000000nhash]", fmt.Sprintf("%v", meter2.FeeConsumedByMsg()), "expect string output to match")
meter2.ConsumeFee(sdk.NewCoin("doge", sdk.NewInt(2000000)), "/provenance.marker.v1.MsgAddMarkerRequest", "")
meter2.ConsumeFee(sdk.NewCoin("jackthecat", sdk.NewInt(420)), "/provenance.marker.v1.MsgAddMarkerRequest", "")
meter2.ConsumeFee(sdk.NewCoins(sdk.NewCoin("doge", sdk.NewInt(2000000))), "/provenance.marker.v1.MsgAddMarkerRequest", "")
meter2.ConsumeFee(sdk.NewCoins(sdk.NewCoin("jackthecat", sdk.NewInt(420))), "/provenance.marker.v1.MsgAddMarkerRequest", "")
meter2FeesConsumed := meter2.FeeConsumed()
require.Equalf(t, "2000000doge,420jackthecat,3000000nhash", meter2FeesConsumed.String(), "expect string output to match")
require.Equalf(t, "2000000doge,420jackthecat", meter2.FeeConsumedForType("/provenance.marker.v1.MsgAddMarkerRequest", "").String(), "expect string output to match")
Expand Down
12 changes: 5 additions & 7 deletions internal/antewrapper/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,12 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
}

decorators := []sdk.AnteDecorator{
cosmosante.NewSetUpContextDecorator(),
// outermost AnteDecorator. SetUpContext must be called first
NewFeeMeterContextDecorator(), // NOTE : fee gas meter also has the functionality of GasTracerContextDecorator in previous versions
cosmosante.NewExtensionOptionsDecorator(options.ExtensionOptionChecker),
cosmosante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
NewFeeMeterContextDecorator(), // NOTE : fee gas meter also has the functionality of GasTracerContextDecorator in previous versions
NewTxGasLimitDecorator(),
cosmosante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, nil),
// Fee Decorator works to augment NewDeductFeeDecorator and also check that enough fees are paid
NewMsgFeesDecorator(options.BankKeeper, options.AccountKeeper, options.FeegrantKeeper, options.MsgFeesKeeper),
NewMinGasPricesDecorator(),
NewMsgFeesDecorator(options.MsgFeesKeeper),
cosmosante.NewExtensionOptionsDecorator(options.ExtensionOptionChecker),
cosmosante.NewValidateBasicDecorator(),
cosmosante.NewTxTimeoutHeightDecorator(),
cosmosante.NewValidateMemoDecorator(options.AccountKeeper),
Expand Down
75 changes: 75 additions & 0 deletions internal/antewrapper/min_gas_prices_decorator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package antewrapper

import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

// MinGasPricesDecorator will check if the transaction's fee is at least as large
// as the local validator's minimum gasFee (defined in validator config).
// If fee is too low, decorator returns error and tx is rejected from mempool.
// Note this only applies when ctx.CheckTx = true
// If fee is high enough or not CheckTx, then call next AnteHandler
// CONTRACT: Tx must implement FeeTx to use MinGasPricesDecorator
type MinGasPricesDecorator struct{}

func NewMinGasPricesDecorator() MinGasPricesDecorator {
return MinGasPricesDecorator{}
}

func (mfd MinGasPricesDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) {
if !simulate {
err := checkTxFeeWithValidatorMinGasPrices(ctx, tx)
if err != nil {
return ctx, err
}
}

return next(ctx, tx, simulate)
}

// checkTxFeeWithValidatorMinGasPrices makes sure one or more of the fee coins has enough to cover
// the validator's min gas fee.
func checkTxFeeWithValidatorMinGasPrices(ctx sdk.Context, tx sdk.Tx) error {
// Note: This is copied from Cosmos-SDK:x/auth/ante/validator_tx_fee.go and tweaked as follows:
// 1. The priority return value and call to calculate the priority has been removed because we
// probably don't want the naive approach they have, and we don't know what we want yet.
// Also, the priority mempool isn't fully ready yet.
// 2. The Coins return value has been removed because we use our network's floor gas price instead of
// the validators min gas prices when deciding the fee to deduct.
// 3. Use of deprecated sdkerrors.Wrap and .Wrapf has been fixed.
// 4. The first lines were updated to use GetFeeTx.
// 5. The content of the final error message was updated to hopefully avoid confusion with the floor gas price.
// 6. The comment above the function was fixed.
feeTx, err := GetFeeTx(tx)
if err != nil {
return err
}

feeCoins := feeTx.GetFee()
gas := feeTx.GetGas()

// Ensure that the provided fees meet a minimum threshold for the validator,
// if this is a CheckTx. This is only for local mempool purposes, and thus
// is only ran on check tx.
if ctx.IsCheckTx() {
minGasPrices := ctx.MinGasPrices()
if !minGasPrices.IsZero() {
requiredFees := make(sdk.Coins, len(minGasPrices))

// Determine the required fees by multiplying each required minimum gas
// price by the gas limit, where fee = ceil(minGasPrice * gasLimit).
glDec := sdk.NewDec(int64(gas))
for i, gp := range minGasPrices {
fee := gp.Amount.Mul(glDec)
requiredFees[i] = sdk.NewCoin(gp.Denom, fee.Ceil().RoundInt())
}

if !feeCoins.IsAnyGTE(requiredFees) {
return sdkerrors.ErrInsufficientFee.Wrapf("min-gas-prices not met; got: %s required: %s", feeCoins, requiredFees)
}
}
}

return nil
}
Loading

0 comments on commit 19fb4c3

Please sign in to comment.