-
Notifications
You must be signed in to change notification settings - Fork 199
/
module_simulation.go
191 lines (166 loc) · 7.19 KB
/
module_simulation.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
package pairing
import (
"math/rand"
"github.com/cosmos/cosmos-sdk/baseapp"
simappparams "github.com/cosmos/cosmos-sdk/simapp/params"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/cosmos/cosmos-sdk/x/simulation"
"github.com/lavanet/lava/testutil/sample"
pairingsimulation "github.com/lavanet/lava/x/pairing/simulation"
"github.com/lavanet/lava/x/pairing/types"
)
// avoid unused import issue
var (
_ = sample.AccAddress
_ = pairingsimulation.FindAccount
_ = simappparams.StakePerAccount
_ = simulation.MsgEntryKind
_ = baseapp.Paramspace
)
const (
opWeightMsgStakeProvider = "op_weight_msg_stake_provider"
// TODO: Determine the simulation weight value
defaultWeightMsgStakeProvider int = 100
opWeightMsgStakeClient = "op_weight_msg_stake_client"
// TODO: Determine the simulation weight value
defaultWeightMsgStakeClient int = 100
opWeightMsgUnstakeProvider = "op_weight_msg_unstake_provider"
// TODO: Determine the simulation weight value
defaultWeightMsgUnstakeProvider int = 100
opWeightMsgUnstakeClient = "op_weight_msg_unstake_client"
// TODO: Determine the simulation weight value
defaultWeightMsgUnstakeClient int = 100
opWeightMsgRelayPayment = "op_weight_msg_relay_payment"
// TODO: Determine the simulation weight value
defaultWeightMsgRelayPayment int = 100
opWeightMsgFreeze = "op_weight_msg_freeze"
// TODO: Determine the simulation weight value
defaultWeightMsgFreeze int = 100
opWeightMsgUnfreeze = "op_weight_msg_unfreeze"
// TODO: Determine the simulation weight value
defaultWeightMsgUnfreeze int = 100
// this line is used by starport scaffolding # simapp/module/const
)
// GenerateGenesisState creates a randomized GenState of the module
func (AppModule) GenerateGenesisState(simState *module.SimulationState) {
accs := make([]string, len(simState.Accounts))
for i, acc := range simState.Accounts {
accs[i] = acc.Address.String()
}
pairingGenesis := types.GenesisState{
Params: types.DefaultParams(),
// this line is used by starport scaffolding # simapp/module/genesisState
}
simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(&pairingGenesis)
}
// ProposalContents doesn't return any content functions for governance proposals
func (AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedProposalContent {
return nil
}
// RandomizedParams creates randomized param changes for the simulator
func (am AppModule) RandomizedParams(_ *rand.Rand) []simtypes.ParamChange {
pairingParams := types.DefaultParams()
return []simtypes.ParamChange{
simulation.NewSimParamChange(types.ModuleName, string(types.KeyMintCoinsPerCU), func(r *rand.Rand) string {
return string(types.Amino.MustMarshalJSON(pairingParams.MintCoinsPerCU))
}),
simulation.NewSimParamChange(types.ModuleName, string(types.KeyBurnCoinsPerCU), func(r *rand.Rand) string {
return string(types.Amino.MustMarshalJSON(pairingParams.BurnCoinsPerCU))
}),
simulation.NewSimParamChange(types.ModuleName, string(types.KeyFraudStakeSlashingFactor), func(r *rand.Rand) string {
return string(types.Amino.MustMarshalJSON(pairingParams.FraudStakeSlashingFactor))
}),
simulation.NewSimParamChange(types.ModuleName, string(types.KeyFraudSlashingAmount), func(r *rand.Rand) string {
return string(types.Amino.MustMarshalJSON(pairingParams.FraudSlashingAmount))
}),
simulation.NewSimParamChange(types.ModuleName, string(types.KeyServicersToPairCount), func(r *rand.Rand) string {
return string(types.Amino.MustMarshalJSON(pairingParams.ServicersToPairCount))
}),
simulation.NewSimParamChange(types.ModuleName, string(types.KeyEpochBlocksOverlap), func(r *rand.Rand) string {
return string(types.Amino.MustMarshalJSON(pairingParams.EpochBlocksOverlap))
}),
simulation.NewSimParamChange(types.ModuleName, string(types.KeyRecommendedEpochNumToCollectPayment), func(r *rand.Rand) string {
return string(types.Amino.MustMarshalJSON(pairingParams.RecommendedEpochNumToCollectPayment))
}),
}
}
// RegisterStoreDecoder registers a decoder
func (am AppModule) RegisterStoreDecoder(_ sdk.StoreDecoderRegistry) {}
// WeightedOperations returns the all the gov module operations with their respective weights.
func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation {
operations := make([]simtypes.WeightedOperation, 0)
var weightMsgStakeProvider int
simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgStakeProvider, &weightMsgStakeProvider, nil,
func(_ *rand.Rand) {
weightMsgStakeProvider = defaultWeightMsgStakeProvider
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgStakeProvider,
pairingsimulation.SimulateMsgStakeProvider(am.accountKeeper, am.bankKeeper, am.keeper),
))
var weightMsgStakeClient int
simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgStakeClient, &weightMsgStakeClient, nil,
func(_ *rand.Rand) {
weightMsgStakeClient = defaultWeightMsgStakeClient
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgStakeClient,
pairingsimulation.SimulateMsgStakeClient(am.accountKeeper, am.bankKeeper, am.keeper),
))
var weightMsgUnstakeProvider int
simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgUnstakeProvider, &weightMsgUnstakeProvider, nil,
func(_ *rand.Rand) {
weightMsgUnstakeProvider = defaultWeightMsgUnstakeProvider
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgUnstakeProvider,
pairingsimulation.SimulateMsgUnstakeProvider(am.accountKeeper, am.bankKeeper, am.keeper),
))
var weightMsgUnstakeClient int
simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgUnstakeClient, &weightMsgUnstakeClient, nil,
func(_ *rand.Rand) {
weightMsgUnstakeClient = defaultWeightMsgUnstakeClient
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgUnstakeClient,
pairingsimulation.SimulateMsgUnstakeClient(am.accountKeeper, am.bankKeeper, am.keeper),
))
var weightMsgRelayPayment int
simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgRelayPayment, &weightMsgRelayPayment, nil,
func(_ *rand.Rand) {
weightMsgRelayPayment = defaultWeightMsgRelayPayment
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgRelayPayment,
pairingsimulation.SimulateMsgRelayPayment(am.accountKeeper, am.bankKeeper, am.keeper),
))
var weightMsgFreeze int
simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgFreeze, &weightMsgFreeze, nil,
func(_ *rand.Rand) {
weightMsgFreeze = defaultWeightMsgFreeze
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgFreeze,
pairingsimulation.SimulateMsgFreeze(am.accountKeeper, am.bankKeeper, am.keeper),
))
var weightMsgUnfreeze int
simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgUnfreeze, &weightMsgUnfreeze, nil,
func(_ *rand.Rand) {
weightMsgUnfreeze = defaultWeightMsgUnfreeze
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgUnfreeze,
pairingsimulation.SimulateMsgUnfreeze(am.accountKeeper, am.bankKeeper, am.keeper),
))
// this line is used by starport scaffolding # simapp/module/operation
return operations
}