From 63f6778c9648aa01bd2a1c37d8914bdfe66f6cd0 Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Fri, 14 Oct 2022 12:07:42 -0500 Subject: [PATCH] Revert "chore(backport): Simulation is not deterministic due to GenTx (backport #356) (#362)" This reverts commit f075384deb2603cf40740b30dfed678b043c6e58. --- simapp/helpers/test_helpers.go | 9 ++++++--- simapp/test_helpers.go | 3 --- x/authz/simulation/operations.go | 8 +------- x/bank/simulation/operations.go | 10 ---------- x/distribution/simulation/operations.go | 1 - x/genutil/gentx_test.go | 3 --- x/gov/simulation/operations.go | 2 -- x/simulation/util.go | 1 - x/slashing/simulation/operations.go | 1 - x/staking/simulation/operations.go | 2 -- 10 files changed, 7 insertions(+), 33 deletions(-) diff --git a/simapp/helpers/test_helpers.go b/simapp/helpers/test_helpers.go index 6adbc72332c..f9725adfbc0 100644 --- a/simapp/helpers/test_helpers.go +++ b/simapp/helpers/test_helpers.go @@ -2,6 +2,7 @@ package helpers import ( "math/rand" + "time" "github.com/cosmos/cosmos-sdk/client" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" @@ -15,15 +16,17 @@ import ( // TODO: Implement a tool to check for gas growth. For now, // we must increase this across the board for longer runs to work const ( - DefaultGenTxGas uint64 = 2000000 - SimAppChainID = "simulation-app" + DefaultGenTxGas = 2000000 + SimAppChainID = "simulation-app" ) // GenTx generates a signed mock transaction. -func GenTx(r *rand.Rand, gen client.TxConfig, msgs []sdk.Msg, feeAmt sdk.Coins, gas uint64, chainID string, accNums, accSeqs []uint64, priv ...cryptotypes.PrivKey) (sdk.Tx, error) { +func GenTx(gen client.TxConfig, msgs []sdk.Msg, feeAmt sdk.Coins, gas uint64, chainID string, accNums, accSeqs []uint64, priv ...cryptotypes.PrivKey) (sdk.Tx, error) { sigs := make([]signing.SignatureV2, len(priv)) // create a random length memo + r := rand.New(rand.NewSource(time.Now().UnixNano())) + memo := simulation.RandStringOfLength(r, simulation.RandIntBetween(r, 0, 100)) signMode := gen.SignModeHandler().DefaultMode() diff --git a/simapp/test_helpers.go b/simapp/test_helpers.go index 54bd0bfb8d1..860accb45f7 100644 --- a/simapp/test_helpers.go +++ b/simapp/test_helpers.go @@ -5,7 +5,6 @@ import ( "encoding/hex" "encoding/json" "fmt" - "math/rand" "strconv" "testing" "time" @@ -331,7 +330,6 @@ func SignCheckDeliver( ) (sdk.GasInfo, *sdk.Result, error) { tx, err := helpers.GenTx( - rand.New(rand.NewSource(time.Now().UnixNano())), txCfg, msgs, sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 0)}, @@ -382,7 +380,6 @@ func GenSequenceOfTxs(txGen client.TxConfig, msgs []sdk.Msg, accNums []uint64, i var err error for i := 0; i < numToGenerate; i++ { txs[i], err = helpers.GenTx( - rand.New(rand.NewSource(time.Now().UnixNano())), txGen, msgs, sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 0)}, diff --git a/x/authz/simulation/operations.go b/x/authz/simulation/operations.go index 843cb7428a0..2d2f43681b4 100644 --- a/x/authz/simulation/operations.go +++ b/x/authz/simulation/operations.go @@ -116,7 +116,6 @@ func SimulateMsgGrant(ak authz.AccountKeeper, bk authz.BankKeeper, _ keeper.Keep } txCfg := simappparams.MakeTestEncodingConfig().TxConfig tx, err := helpers.GenTx( - r, txCfg, []sdk.Msg{msg}, fees, @@ -184,7 +183,6 @@ func SimulateMsgRevoke(ak authz.AccountKeeper, bk authz.BankKeeper, k keeper.Kee txCfg := simappparams.MakeTestEncodingConfig().TxConfig account := ak.GetAccount(ctx, granterAddr) tx, err := helpers.GenTx( - r, txCfg, []sdk.Msg{&msg}, fees, @@ -239,10 +237,7 @@ func SimulateMsgExec(ak authz.AccountKeeper, bk authz.BankKeeper, k keeper.Keepe granterspendableCoins := bk.SpendableCoins(ctx, granterAddr) coins := simtypes.RandSubsetCoins(r, granterspendableCoins) - // if coins slice is empty, we can not create valid banktype.MsgSend - if len(coins) == 0 { - return simtypes.NoOpMsg(authz.ModuleName, TypeMsgExec, "empty coins slice"), nil, nil - } + // Check send_enabled status of each sent coin denom if err := bk.IsSendEnabledCoins(ctx, coins...); err != nil { return simtypes.NoOpMsg(authz.ModuleName, TypeMsgExec, err.Error()), nil, nil @@ -278,7 +273,6 @@ func SimulateMsgExec(ak authz.AccountKeeper, bk authz.BankKeeper, k keeper.Keepe granteeAcc := ak.GetAccount(ctx, granteeAddr) tx, err := helpers.GenTx( - r, txCfg, []sdk.Msg{&msgExec}, fees, diff --git a/x/bank/simulation/operations.go b/x/bank/simulation/operations.go index 67a46802634..1d09238c3a3 100644 --- a/x/bank/simulation/operations.go +++ b/x/bank/simulation/operations.go @@ -60,10 +60,6 @@ func SimulateMsgSend(ak types.AccountKeeper, bk keeper.Keeper) simtypes.Operatio accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { from, to, coins, skip := randomSendFields(r, ctx, accs, bk, ak) - // if coins slice is empty, we can not create valid types.MsgSend - if len(coins) == 0 { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgSend, "empty coins slice"), nil, nil - } // Check send_enabled status of each coin denom if err := bk.IsSendEnabledCoins(ctx, coins...); err != nil { @@ -98,10 +94,6 @@ func SimulateMsgSendToModuleAccount(ak types.AccountKeeper, bk keeper.Keeper, mo spendable := bk.SpendableCoins(ctx, from.Address) coins := simtypes.RandSubsetCoins(r, spendable) - // if coins slice is empty, we can not create valid types.MsgSend - if len(coins) == 0 { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgSend, "empty coins slice"), nil, nil - } // Check send_enabled status of each coin denom if err := bk.IsSendEnabledCoins(ctx, coins...); err != nil { @@ -148,7 +140,6 @@ func sendMsgSend( } txGen := simappparams.MakeTestEncodingConfig().TxConfig tx, err := helpers.GenTx( - r, txGen, []sdk.Msg{msg}, fees, @@ -372,7 +363,6 @@ func sendMsgMultiSend( txGen := simappparams.MakeTestEncodingConfig().TxConfig tx, err := helpers.GenTx( - r, txGen, []sdk.Msg{msg}, fees, diff --git a/x/distribution/simulation/operations.go b/x/distribution/simulation/operations.go index 6288d4b092a..6bf82ef832a 100644 --- a/x/distribution/simulation/operations.go +++ b/x/distribution/simulation/operations.go @@ -234,7 +234,6 @@ func SimulateMsgFundCommunityPool(ak types.AccountKeeper, bk types.BankKeeper, k msg := types.NewMsgFundCommunityPool(fundAmount, funder.Address) txCtx := simulation.OperationInput{ - R: r, App: app, TxGen: simappparams.MakeTestEncodingConfig().TxConfig, Cdc: nil, diff --git a/x/genutil/gentx_test.go b/x/genutil/gentx_test.go index acf1530baf8..8de5bc4afe4 100644 --- a/x/genutil/gentx_test.go +++ b/x/genutil/gentx_test.go @@ -3,9 +3,7 @@ package genutil_test import ( "encoding/json" "fmt" - "math/rand" "testing" - "time" "github.com/stretchr/testify/suite" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" @@ -236,7 +234,6 @@ func (suite *GenTxTestSuite) TestDeliverGenTxs() { msg := banktypes.NewMsgSend(addr1, addr2, sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 1)}) tx, err := helpers.GenTx( - rand.New(rand.NewSource(time.Now().UnixNano())), suite.encodingConfig.TxConfig, []sdk.Msg{msg}, sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 10)}, diff --git a/x/gov/simulation/operations.go b/x/gov/simulation/operations.go index d07daeb9a82..e5532c7ecdf 100644 --- a/x/gov/simulation/operations.go +++ b/x/gov/simulation/operations.go @@ -159,7 +159,6 @@ func SimulateMsgSubmitProposal( txGen := simappparams.MakeTestEncodingConfig().TxConfig tx, err := helpers.GenTx( - r, txGen, []sdk.Msg{msg}, fees, @@ -247,7 +246,6 @@ func SimulateMsgDeposit(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Ke } txCtx := simulation.OperationInput{ - R: r, App: app, TxGen: simappparams.MakeTestEncodingConfig().TxConfig, Cdc: nil, diff --git a/x/simulation/util.go b/x/simulation/util.go index f9e2c500f93..bb2a6ee62a8 100644 --- a/x/simulation/util.go +++ b/x/simulation/util.go @@ -102,7 +102,6 @@ func GenAndDeliverTxWithRandFees(txCtx OperationInput) (simtypes.OperationMsg, [ func GenAndDeliverTx(txCtx OperationInput, fees sdk.Coins) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { account := txCtx.AccountKeeper.GetAccount(txCtx.Context, txCtx.SimAccount.Address) tx, err := helpers.GenTx( - txCtx.R, txCtx.TxGen, []sdk.Msg{txCtx.Msg}, fees, diff --git a/x/slashing/simulation/operations.go b/x/slashing/simulation/operations.go index 3c087386b33..01d79781e2f 100644 --- a/x/slashing/simulation/operations.go +++ b/x/slashing/simulation/operations.go @@ -91,7 +91,6 @@ func SimulateMsgUnjail(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Kee txGen := simappparams.MakeTestEncodingConfig().TxConfig tx, err := helpers.GenTx( - r, txGen, []sdk.Msg{msg}, fees, diff --git a/x/staking/simulation/operations.go b/x/staking/simulation/operations.go index ca9f3ffdf34..79fa79954ed 100644 --- a/x/staking/simulation/operations.go +++ b/x/staking/simulation/operations.go @@ -153,7 +153,6 @@ func SimulateMsgCreateValidator(ak types.AccountKeeper, bk types.BankKeeper, k k } txCtx := simulation.OperationInput{ - R: r, App: app, TxGen: simappparams.MakeTestEncodingConfig().TxConfig, Cdc: nil, @@ -279,7 +278,6 @@ func SimulateMsgDelegate(ak types.AccountKeeper, bk types.BankKeeper, k keeper.K msg := types.NewMsgDelegate(simAccount.Address, val.GetOperator(), bondAmt) txCtx := simulation.OperationInput{ - R: r, App: app, TxGen: simappparams.MakeTestEncodingConfig().TxConfig, Cdc: nil,