Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LSM Staking and Slashing #9

Merged
merged 26 commits into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
00e671a
proto-gen
sampocs Jun 20, 2023
319337f
copied over staking protos
sampocs Jun 20, 2023
e81ad50
updated proto package name and fixed lint errors
sampocs Jun 20, 2023
25460ac
generated staking protos
sampocs Jun 20, 2023
01505b7
copied over module level files
sampocs Jun 20, 2023
988802b
removed min self delegation
sampocs Jun 20, 2023
b175c50
copied over staking types
sampocs Jun 20, 2023
c86a47b
copied over staking client
sampocs Jun 20, 2023
29052f5
copied over teststaking
sampocs Jun 20, 2023
b59ecbf
fixed build errors related to teststaking or min-self-delegation
sampocs Jun 20, 2023
cc8b59c
copied over staking simulation
sampocs Jun 20, 2023
0cfb4cb
copied over staking keeper
sampocs Jun 21, 2023
af19f65
removed GetLiquidDelegation
sampocs Jun 21, 2023
aa8b986
removed GetLiquidValidator
sampocs Jun 21, 2023
fd8434f
removed GetLiquidHistoricalInfo
sampocs Jun 21, 2023
b941dc8
removed GetLiquidBondedValidatorsByPower
sampocs Jun 21, 2023
38b5c5d
removed GetAllLiquidDelegations
sampocs Jun 21, 2023
c087b45
resolved batch of build errors in staking
sampocs Jun 21, 2023
7881f29
resolved batch of build errors from staking in other modules
sampocs Jun 21, 2023
c351d6d
fixed simulation tests for non-lsm txs
sampocs Jun 21, 2023
a1b58ed
misc small changes while fixing staking unit tests
sampocs Jun 21, 2023
fba2912
added back delegation_test that was removed
sampocs Jun 21, 2023
da29a2d
copied over slashing files
sampocs Jun 21, 2023
62289c7
removed/fixed tests that reference min_self_delegation
sampocs Jun 21, 2023
5743c84
fixed unit tests related to jailing a validator
sampocs Jun 22, 2023
7a79d16
fixed staking cli tests
sampocs Jun 22, 2023
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
6 changes: 6 additions & 0 deletions simapp/params/weights.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ const (
DefaultWeightMsgDelegate int = 100
DefaultWeightMsgUndelegate int = 100
DefaultWeightMsgBeginRedelegate int = 100
DefaultWeightMsgCancelUnbondingDelegation int = 100
DefaultWeightMsgTokenizeShares int = 100
DefaultWeightMsgRedeemTokensforShares int = 100
DefaultWeightMsgTransferTokenizeShareRecord int = 50
DefaultWeightMsgEnableTokenizeShares int = 100
DefaultWeightMsgDisableTokenizeShares int = 100

DefaultWeightCommunitySpendProposal int = 5
DefaultWeightTextProposal int = 5
Expand Down
202 changes: 147 additions & 55 deletions x/staking/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/staking/types"
)

const (
DefaultWeightMsgTokenizeShares int = 100
DefaultWeightMsgRedeemTokensforShares int = 100
DefaultWeightMsgTransferTokenizeShareRecord int = 50
)
const ()

// Simulation operation weights constants
//
Expand All @@ -33,6 +29,8 @@ const (
OpWeightMsgTokenizeShares = "op_weight_msg_tokenize_shares" //nolint:gosec
OpWeightMsgRedeemTokensforShares = "op_weight_msg_redeem_tokens_for_shares" //nolint:gosec
OpWeightMsgTransferTokenizeShareRecord = "op_weight_msg_transfer_tokenize_share_record" //nolint:gosec
OpWeightMsgDisableTokenizeShares = "op_weight_msg_disable_tokenize_shares" //nolint:gosec
OpWeightMsgEnableTokenizeShares = "op_weight_msg_enable_tokenize_shares" //nolint:gosec
)

// WeightedOperations returns all the operations from the module with their respective weights
Expand All @@ -41,15 +39,17 @@ func WeightedOperations(
bk types.BankKeeper, k keeper.Keeper,
) simulation.WeightedOperations {
var (
weightMsgCreateValidator int
weightMsgEditValidator int
weightMsgDelegate int
weightMsgUndelegate int
weightMsgBeginRedelegate int
weightMsgCancelUnbondingDelegation int
weightMsgTokenizeShares int
weightMsgRedeemTokensforShares int
weightMsgTransferTokenizeShareRecord int
weightMsgCreateValidator int
weightMsgEditValidator int
weightMsgDelegate int
weightMsgUndelegate int
weightMsgBeginRedelegate int
// weightMsgCancelUnbondingDelegation int
sampocs marked this conversation as resolved.
Show resolved Hide resolved
// weightMsgTokenizeShares int
// weightMsgRedeemTokensforShares int
// weightMsgTransferTokenizeShareRecord int
// weightMsgDisableTokenizeShares int
// weightMsgEnableTokenizeShares int
)

appParams.GetOrGenerate(cdc, OpWeightMsgCreateValidator, &weightMsgCreateValidator, nil,
Expand Down Expand Up @@ -82,29 +82,41 @@ func WeightedOperations(
},
)

appParams.GetOrGenerate(cdc, OpWeightMsgCancelUnbondingDelegation, &weightMsgCancelUnbondingDelegation, nil,
func(_ *rand.Rand) {
weightMsgCancelUnbondingDelegation = simappparams.DefaultWeightMsgDelegate
},
)

appParams.GetOrGenerate(cdc, OpWeightMsgTokenizeShares, &weightMsgTokenizeShares, nil,
func(_ *rand.Rand) {
weightMsgTokenizeShares = DefaultWeightMsgTokenizeShares
},
)

appParams.GetOrGenerate(cdc, OpWeightMsgRedeemTokensforShares, &weightMsgRedeemTokensforShares, nil,
func(_ *rand.Rand) {
weightMsgRedeemTokensforShares = DefaultWeightMsgRedeemTokensforShares
},
)

appParams.GetOrGenerate(cdc, OpWeightMsgTransferTokenizeShareRecord, &weightMsgTransferTokenizeShareRecord, nil,
func(_ *rand.Rand) {
weightMsgTransferTokenizeShareRecord = DefaultWeightMsgTransferTokenizeShareRecord
},
)
// appParams.GetOrGenerate(cdc, OpWeightMsgCancelUnbondingDelegation, &weightMsgCancelUnbondingDelegation, nil,
sampocs marked this conversation as resolved.
Show resolved Hide resolved
// func(_ *rand.Rand) {
// weightMsgCancelUnbondingDelegation = simappparams.DefaultWeightMsgCancelUnbondingDelegation
// },
// )

// appParams.GetOrGenerate(cdc, OpWeightMsgTokenizeShares, &weightMsgTokenizeShares, nil,
// func(_ *rand.Rand) {
// weightMsgTokenizeShares = simappparams.DefaultWeightMsgTokenizeShares
// },
// )

// appParams.GetOrGenerate(cdc, OpWeightMsgRedeemTokensforShares, &weightMsgRedeemTokensforShares, nil,
// func(_ *rand.Rand) {
// weightMsgRedeemTokensforShares = simappparams.DefaultWeightMsgRedeemTokensforShares
// },
// )

// appParams.GetOrGenerate(cdc, OpWeightMsgTransferTokenizeShareRecord, &weightMsgTransferTokenizeShareRecord, nil,
// func(_ *rand.Rand) {
// weightMsgTransferTokenizeShareRecord = simappparams.DefaultWeightMsgTransferTokenizeShareRecord
// },
// )

// appParams.GetOrGenerate(cdc, OpWeightMsgDisableTokenizeShares, &weightMsgDisableTokenizeShares, nil,
// func(_ *rand.Rand) {
// weightMsgDisableTokenizeShares = simappparams.DefaultWeightMsgDisableTokenizeShares
// },
// )

// appParams.GetOrGenerate(cdc, OpWeightMsgEnableTokenizeShares, &weightMsgEnableTokenizeShares, nil,
// func(_ *rand.Rand) {
// weightMsgEnableTokenizeShares = simappparams.DefaultWeightMsgEnableTokenizeShares
// },
// )

return simulation.WeightedOperations{
simulation.NewWeightedOperation(
Expand All @@ -127,22 +139,30 @@ func WeightedOperations(
weightMsgBeginRedelegate,
SimulateMsgBeginRedelegate(ak, bk, k),
),
simulation.NewWeightedOperation(
weightMsgCancelUnbondingDelegation,
SimulateMsgCancelUnbondingDelegate(ak, bk, k),
),
simulation.NewWeightedOperation(
weightMsgTokenizeShares,
SimulateMsgTokenizeShares(ak, bk, k),
),
simulation.NewWeightedOperation(
weightMsgRedeemTokensforShares,
SimulateMsgRedeemTokensforShares(ak, bk, k),
),
simulation.NewWeightedOperation(
weightMsgTransferTokenizeShareRecord,
SimulateMsgTransferTokenizeShareRecord(ak, bk, k),
),
// simulation.NewWeightedOperation(
// weightMsgCancelUnbondingDelegation,
// SimulateMsgCancelUnbondingDelegate(ak, bk, k),
// ),
// simulation.NewWeightedOperation(
// weightMsgTokenizeShares,
// SimulateMsgTokenizeShares(ak, bk, k),
// ),
// simulation.NewWeightedOperation(
// weightMsgRedeemTokensforShares,
// SimulateMsgRedeemTokensforShares(ak, bk, k),
// ),
// simulation.NewWeightedOperation(
// weightMsgTransferTokenizeShareRecord,
// SimulateMsgTransferTokenizeShareRecord(ak, bk, k),
// ),
// simulation.NewWeightedOperation(
// weightMsgDisableTokenizeShares,
// SimulateMsgDisableTokenizeShares(ak, bk, k),
// ),
// simulation.NewWeightedOperation(
// weightMsgEnableTokenizeShares,
// SimulateMsgEnableTokenizeShares(ak, bk, k),
// ),
}
}

Expand Down Expand Up @@ -471,8 +491,8 @@ func SimulateMsgCancelUnbondingDelegate(ak types.AccountKeeper, bk types.BankKee
return simtypes.NoOpMsg(types.ModuleName, "cancel_unbond", "cancelBondAmt amount is zero"), nil, nil
}

msg := types.NewMsgUndelegate(
simAccount.Address, valAddr, sdk.NewCoin(k.BondDenom(ctx), cancelBondAmt),
msg := types.NewMsgCancelUnbondingDelegation(
simAccount.Address, valAddr, ctx.BlockHeight(), sdk.NewCoin(k.BondDenom(ctx), cancelBondAmt),
)

spendable := bk.SpendableCoins(ctx, simAccount.Address)
Expand Down Expand Up @@ -806,3 +826,75 @@ func SimulateMsgTransferTokenizeShareRecord(ak types.AccountKeeper, bk types.Ban
return simulation.GenAndDeliverTxWithRandFees(txCtx)
}
}

func SimulateMsgDisableTokenizeShares(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper) simtypes.Operation {
return func(
r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string,
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
// TODO
simAccount, _ := simtypes.RandomAcc(r, accs)

account := ak.GetAccount(ctx, simAccount.Address)
spendable := bk.SpendableCoins(ctx, account.GetAddress())

if simAccount.PrivKey == nil {
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgTransferTokenizeShareRecord, "account private key is nil"), nil, nil
}

msg := &types.MsgDisableTokenizeShares{
DelegatorAddress: simAccount.Address.String(),
}

txCtx := simulation.OperationInput{
R: r,
App: app,
TxGen: simappparams.MakeTestEncodingConfig().TxConfig,
Cdc: nil,
Msg: msg,
MsgType: msg.Type(),
Context: ctx,
SimAccount: simAccount,
AccountKeeper: ak,
Bankkeeper: bk,
ModuleName: types.ModuleName,
CoinsSpentInMsg: spendable,
}
return simulation.GenAndDeliverTxWithRandFees(txCtx)
}
}

func SimulateMsgEnableTokenizeShares(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper) simtypes.Operation {
return func(
r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string,
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
// TODO
simAccount, _ := simtypes.RandomAcc(r, accs)

account := ak.GetAccount(ctx, simAccount.Address)
spendable := bk.SpendableCoins(ctx, account.GetAddress())

if simAccount.PrivKey == nil {
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgTransferTokenizeShareRecord, "account private key is nil"), nil, nil
}

msg := &types.MsgEnableTokenizeShares{
DelegatorAddress: simAccount.Address.String(),
}

txCtx := simulation.OperationInput{
R: r,
App: app,
TxGen: simappparams.MakeTestEncodingConfig().TxConfig,
Cdc: nil,
Msg: msg,
MsgType: msg.Type(),
Context: ctx,
SimAccount: simAccount,
AccountKeeper: ak,
Bankkeeper: bk,
ModuleName: types.ModuleName,
CoinsSpentInMsg: spendable,
}
return simulation.GenAndDeliverTxWithRandFees(txCtx)
}
}
6 changes: 6 additions & 0 deletions x/staking/simulation/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ func TestWeightedOperations(t *testing.T) {
{simappparams.DefaultWeightMsgDelegate, types.ModuleName, types.TypeMsgDelegate},
{simappparams.DefaultWeightMsgUndelegate, types.ModuleName, types.TypeMsgUndelegate},
{simappparams.DefaultWeightMsgBeginRedelegate, types.ModuleName, types.TypeMsgBeginRedelegate},
// {simappparams.DefaultWeightMsgCancelUnbondingDelegation, types.ModuleName, types.TypeMsgCancelUnbondingDelegation},
// {simappparams.DefaultWeightMsgTokenizeShares, types.ModuleName, types.TypeMsgTokenizeShares},
// {simappparams.DefaultWeightMsgRedeemTokensforShares, types.ModuleName, types.TypeMsgRedeemTokensForShares},
// {simappparams.DefaultWeightMsgTransferTokenizeShareRecord, types.ModuleName, types.TypeMsgTransferTokenizeShareRecord},
// {simappparams.DefaultWeightMsgDisableTokenizeShares, types.ModuleName, types.TypeMsgDisableTokenizeShares},
// {simappparams.DefaultWeightMsgEnableTokenizeShares, types.ModuleName, types.TypeMsgEnableTokenizeShares},
}

for i, w := range weightesOps {
Expand Down