From a538497e23a720e13567ffe1ba2a9f98a825c89b Mon Sep 17 00:00:00 2001 From: Eric Zhu Date: Mon, 24 Oct 2022 23:58:35 -0400 Subject: [PATCH 1/7] staking dynamic dependency generation mapping --- aclmapping/staking/mappings.go | 260 +++++++++++++++++++++++ aclmapping/utils/identifier_templates.go | 1 + go.mod | 2 +- go.sum | 4 +- loadtest/config.json | 5 +- loadtest/loadtest_client.go | 3 +- loadtest/main.go | 31 ++- loadtest/sign.go | 24 +++ loadtest/types.go | 22 +- 9 files changed, 342 insertions(+), 10 deletions(-) create mode 100644 aclmapping/staking/mappings.go diff --git a/aclmapping/staking/mappings.go b/aclmapping/staking/mappings.go new file mode 100644 index 0000000000..18e8d68223 --- /dev/null +++ b/aclmapping/staking/mappings.go @@ -0,0 +1,260 @@ +package aclstakingmapping + +import ( + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" + sdkacltypes "github.com/cosmos/cosmos-sdk/types/accesscontrol" + aclkeeper "github.com/cosmos/cosmos-sdk/x/accesscontrol/keeper" + acltypes "github.com/cosmos/cosmos-sdk/x/accesscontrol/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + utils "github.com/sei-protocol/sei-chain/aclmapping/utils" +) + +var ErrorInvalidMsgType = fmt.Errorf("invalid message received for staking module") + +func GetStakingDependencyGenerator() aclkeeper.DependencyGeneratorMap { + dependencyGeneratorMap := make(aclkeeper.DependencyGeneratorMap) + + delegateKey := acltypes.GenerateMessageKey(&stakingtypes.MsgDelegate{}) + undelegateKey := acltypes.GenerateMessageKey(&stakingtypes.MsgUndelegate{}) + beginRedelegateKey := acltypes.GenerateMessageKey(&stakingtypes.MsgBeginRedelegate{}) + dependencyGeneratorMap[delegateKey] = MsgDelegateDependencyGenerator + dependencyGeneratorMap[undelegateKey] = MsgUndelegateDependencyGenerator + dependencyGeneratorMap[beginRedelegateKey] = MsgBeginRedelegateDependencyGenerator + + return dependencyGeneratorMap +} + +func MsgDelegateDependencyGenerator(keeper aclkeeper.Keeper, ctx sdk.Context, msg sdk.Msg) ([]sdkacltypes.AccessOperation, error) { + msgDelegate, ok := msg.(*stakingtypes.MsgDelegate) + if !ok { + return []sdkacltypes.AccessOperation{}, ErrorInvalidMsgType + } + + accessOperations := []sdkacltypes.AccessOperation{ + // Checks if the delegator exists + // Checks if there is a delegation object that already exists for (delegatorAddr, validatorAddr) + { + AccessType: sdkacltypes.AccessType_READ, + ResourceType: sdkacltypes.ResourceType_KV, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgDelegate.DelegatorAddress+msgDelegate.ValidatorAddress), + }, + // Store new delegator for (delegator, validator) + { + AccessType: sdkacltypes.AccessType_WRITE, + ResourceType: sdkacltypes.ResourceType_KV, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgDelegate.DelegatorAddress+msgDelegate.ValidatorAddress), + }, + + // delegate coins from account validator account + { + AccessType: sdkacltypes.AccessType_READ, + ResourceType: sdkacltypes.ResourceType_KV, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgDelegate.DelegatorAddress), + }, + { + AccessType: sdkacltypes.AccessType_WRITE, + ResourceType: sdkacltypes.ResourceType_KV, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgDelegate.DelegatorAddress), + }, + { + AccessType: sdkacltypes.AccessType_READ, + ResourceType: sdkacltypes.ResourceType_KV, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgDelegate.ValidatorAddress), + }, + { + AccessType: sdkacltypes.AccessType_WRITE, + ResourceType: sdkacltypes.ResourceType_KV, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgDelegate.ValidatorAddress), + }, + + // Checks if the validators exchange rate is valid + { + AccessType: sdkacltypes.AccessType_READ, + ResourceType: sdkacltypes.ResourceType_KV, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgDelegate.ValidatorAddress), + }, + // Update validator shares and power index + { + AccessType: sdkacltypes.AccessType_WRITE, + ResourceType: sdkacltypes.ResourceType_KV, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgDelegate.ValidatorAddress), + }, + + // Last Operation should always be a commit + { + ResourceType: sdkacltypes.ResourceType_ANY, + AccessType: sdkacltypes.AccessType_COMMIT, + IdentifierTemplate: utils.DefaultIDTemplate, + }, + } + + return accessOperations, nil +} + +func MsgUndelegateDependencyGenerator(keeper aclkeeper.Keeper, ctx sdk.Context, msg sdk.Msg) ([]sdkacltypes.AccessOperation, error) { + msgUndelegate, ok := msg.(*stakingtypes.MsgUndelegate) + if !ok { + return []sdkacltypes.AccessOperation{}, ErrorInvalidMsgType + } + + accessOperations := []sdkacltypes.AccessOperation{ + // Treat Delegations and Undelegations to have the same ACL since they are highly coupled, no point in finer granularization + + // Get delegation/redelegations and error checking + { + AccessType: sdkacltypes.AccessType_READ, + ResourceType: sdkacltypes.ResourceType_KV, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgUndelegate.DelegatorAddress+msgUndelegate.ValidatorAddress), + }, + // Update/delete delegation and update redelegation + { + AccessType: sdkacltypes.AccessType_WRITE, + ResourceType: sdkacltypes.ResourceType_KV, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgUndelegate.DelegatorAddress+msgUndelegate.ValidatorAddress), + }, + + // Update the delegator and validator account balances + { + AccessType: sdkacltypes.AccessType_READ, + ResourceType: sdkacltypes.ResourceType_KV, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgUndelegate.DelegatorAddress), + }, + { + AccessType: sdkacltypes.AccessType_WRITE, + ResourceType: sdkacltypes.ResourceType_KV, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgUndelegate.DelegatorAddress), + }, + { + AccessType: sdkacltypes.AccessType_READ, + ResourceType: sdkacltypes.ResourceType_KV, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgUndelegate.ValidatorAddress), + }, + { + AccessType: sdkacltypes.AccessType_WRITE, + ResourceType: sdkacltypes.ResourceType_KV, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgUndelegate.ValidatorAddress), + }, + + // Checks if the validators exchange rate is valid + { + AccessType: sdkacltypes.AccessType_READ, + ResourceType: sdkacltypes.ResourceType_KV, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgUndelegate.ValidatorAddress), + }, + // Update validator shares and power index + { + AccessType: sdkacltypes.AccessType_WRITE, + ResourceType: sdkacltypes.ResourceType_KV, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgUndelegate.ValidatorAddress), + }, + + // Last Operation should always be a commit + { + ResourceType: sdkacltypes.ResourceType_ANY, + AccessType: sdkacltypes.AccessType_COMMIT, + IdentifierTemplate: utils.DefaultIDTemplate, + }, + } + + return accessOperations, nil +} + +func MsgBeginRedelegateDependencyGenerator(keeper aclkeeper.Keeper, ctx sdk.Context, msg sdk.Msg) ([]sdkacltypes.AccessOperation, error) { + msgBeingRedelegate, ok := msg.(*stakingtypes.MsgBeginRedelegate) + if !ok { + return []sdkacltypes.AccessOperation{}, ErrorInvalidMsgType + } + + accessOperations := []sdkacltypes.AccessOperation{ + // Treat Delegations and Redelegations to have the same ACL since they are highly coupled, no point in finer granularization + + // Get src delegation to verify it has sufficient funds to undelegate + // Get dest delegation to see if it already exists + { + AccessType: sdkacltypes.AccessType_READ, + ResourceType: sdkacltypes.ResourceType_KV, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgBeingRedelegate.DelegatorAddress+msgBeingRedelegate.ValidatorSrcAddress), + }, + { + AccessType: sdkacltypes.AccessType_READ, + ResourceType: sdkacltypes.ResourceType_KV, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgBeingRedelegate.DelegatorAddress+msgBeingRedelegate.ValidatorDstAddress), + }, + // Update/delete src and destination delegation after tokens have been unbonded + { + AccessType: sdkacltypes.AccessType_WRITE, + ResourceType: sdkacltypes.ResourceType_KV, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgBeingRedelegate.DelegatorAddress+msgBeingRedelegate.ValidatorSrcAddress), + }, + { + AccessType: sdkacltypes.AccessType_WRITE, + ResourceType: sdkacltypes.ResourceType_KV, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgBeingRedelegate.DelegatorAddress+msgBeingRedelegate.ValidatorDstAddress), + }, + + // Update the delegator, src validator and dest validator account balances + { + AccessType: sdkacltypes.AccessType_READ, + ResourceType: sdkacltypes.ResourceType_KV, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgBeingRedelegate.DelegatorAddress), + }, + { + AccessType: sdkacltypes.AccessType_WRITE, + ResourceType: sdkacltypes.ResourceType_KV, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgBeingRedelegate.DelegatorAddress), + }, + { + AccessType: sdkacltypes.AccessType_READ, + ResourceType: sdkacltypes.ResourceType_KV, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgBeingRedelegate.ValidatorSrcAddress), + }, + { + AccessType: sdkacltypes.AccessType_WRITE, + ResourceType: sdkacltypes.ResourceType_KV, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgBeingRedelegate.ValidatorSrcAddress), + }, + { + AccessType: sdkacltypes.AccessType_READ, + ResourceType: sdkacltypes.ResourceType_KV, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgBeingRedelegate.ValidatorDstAddress), + }, + { + AccessType: sdkacltypes.AccessType_WRITE, + ResourceType: sdkacltypes.ResourceType_KV, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgBeingRedelegate.ValidatorDstAddress), + }, + + // Update validators staking shares and power index + { + AccessType: sdkacltypes.AccessType_READ, + ResourceType: sdkacltypes.ResourceType_KV, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgBeingRedelegate.ValidatorSrcAddress), + }, + { + AccessType: sdkacltypes.AccessType_WRITE, + ResourceType: sdkacltypes.ResourceType_KV, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgBeingRedelegate.ValidatorSrcAddress), + }, + { + AccessType: sdkacltypes.AccessType_READ, + ResourceType: sdkacltypes.ResourceType_KV, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgBeingRedelegate.ValidatorDstAddress), + }, + { + AccessType: sdkacltypes.AccessType_WRITE, + ResourceType: sdkacltypes.ResourceType_KV, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgBeingRedelegate.ValidatorDstAddress), + }, + + // Last Operation should always be a commit + { + ResourceType: sdkacltypes.ResourceType_ANY, + AccessType: sdkacltypes.AccessType_COMMIT, + IdentifierTemplate: utils.DefaultIDTemplate, + }, + } + + return accessOperations, nil +} diff --git a/aclmapping/utils/identifier_templates.go b/aclmapping/utils/identifier_templates.go index ac28dad9ff..3098e33742 100644 --- a/aclmapping/utils/identifier_templates.go +++ b/aclmapping/utils/identifier_templates.go @@ -11,6 +11,7 @@ const ( ACCOUNT = "acc" BANK = "bank" AUTH = "auth" + STAKING = "staking" DefaultIDTemplate = "*" ) diff --git a/go.mod b/go.mod index eeb77f3c14..72b2d3097b 100644 --- a/go.mod +++ b/go.mod @@ -131,7 +131,7 @@ require ( ) replace ( - github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.1.176 + github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.1.192 github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 github.com/keybase/go-keychain => github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 github.com/tendermint/tendermint => github.com/sei-protocol/sei-tendermint v0.1.59 diff --git a/go.sum b/go.sum index fd2cf03824..ff4bb4d040 100644 --- a/go.sum +++ b/go.sum @@ -1098,8 +1098,8 @@ github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg github.com/seccomp/libseccomp-golang v0.9.1/go.mod h1:GbW5+tmTXfcxTToHLXlScSlAvWlF4P2Ca7zGrPiEpWo= github.com/securego/gosec/v2 v2.11.0/go.mod h1:SX8bptShuG8reGC0XS09+a4H2BoWSJi+fscA+Pulbpo= github.com/segmentio/fasthash v1.0.3/go.mod h1:waKX8l2N8yckOgmSsXJi7x1ZfdKZ4x7KRMzBtS3oedY= -github.com/sei-protocol/sei-cosmos v0.1.176 h1:6UgAcryRx6C+UlouHDjxuY7T7hj3nck91QoeppyPdLc= -github.com/sei-protocol/sei-cosmos v0.1.176/go.mod h1:8ccWQxpBkWbpvBos/T4QO9K9gQxFs0duTqKRnagKo+0= +github.com/sei-protocol/sei-cosmos v0.1.192 h1:qrrzr2qHrj7zMDmU7KizOjlXm2uLROUtz8ogEYSxfSE= +github.com/sei-protocol/sei-cosmos v0.1.192/go.mod h1:8ccWQxpBkWbpvBos/T4QO9K9gQxFs0duTqKRnagKo+0= github.com/sei-protocol/sei-tendermint v0.1.59 h1:POGL60PumMQHF4EzAHzvkGfDnodQJLHpl65LuiwSO/Y= github.com/sei-protocol/sei-tendermint v0.1.59/go.mod h1:Olwbjyagrpoxj5DAUhHxMTWDVEfQ3FYdpypaJ3+6Hs8= github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= diff --git a/loadtest/config.json b/loadtest/config.json index 32f171af10..0dcdf24a5d 100644 --- a/loadtest/config.json +++ b/loadtest/config.json @@ -15,7 +15,10 @@ }, "message_type_distribution": { "limit_order_percentage": "0.2", - "market_order_percentage": "0.8" + "market_order_percentage": "0.8", + "delegate_percentage": "0.5", + "undelegate_percentage": "0.25", + "begin_redelegate_percentage": "0.25" }, "message_type": "basic", "contract_distribution": [ diff --git a/loadtest/loadtest_client.go b/loadtest/loadtest_client.go index 9bf8b0740f..0d4891aa2d 100644 --- a/loadtest/loadtest_client.go +++ b/loadtest/loadtest_client.go @@ -79,6 +79,7 @@ func (c *LoadTestClient) BuildTxs() (workgroups []*sync.WaitGroup, sendersList [ numberOfAccounts := config.TxsPerBlock / config.MsgsPerTx * 2 // * 2 because we need two sets of accounts activeAccounts := []int{} inactiveAccounts := []int{} + qv := GetValidators() for i := 0; i < int(numberOfAccounts); i++ { if i%2 == 0 { @@ -98,7 +99,7 @@ func (c *LoadTestClient) BuildTxs() (workgroups []*sync.WaitGroup, sendersList [ for _, account := range activeAccounts { key := c.SignerClient.GetKey(uint64(account)) - msg := generateMessage(config, key, config.MsgsPerTx) + msg := generateMessage(config, key, config.MsgsPerTx, qv.Validators) txBuilder := TestConfig.TxConfig.NewTxBuilder() _ = txBuilder.SetMsgs(msg) seqDelta := uint64(i / 2) diff --git a/loadtest/main.go b/loadtest/main.go index bef80e7c51..2a8774e037 100644 --- a/loadtest/main.go +++ b/loadtest/main.go @@ -17,6 +17,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/sei-protocol/sei-chain/app" dextypes "github.com/sei-protocol/sei-chain/x/dex/types" ) @@ -69,7 +70,7 @@ func run() { fmt.Printf("%s - Finished\n", time.Now().Format("2006-01-02T15:04:05")) } -func generateMessage(config Config, key cryptotypes.PrivKey, msgPerTx uint64) sdk.Msg { +func generateMessage(config Config, key cryptotypes.PrivKey, batchSize uint64, validators []Validator) sdk.Msg { var msg sdk.Msg switch config.MessageType { case "basic": @@ -81,8 +82,34 @@ func generateMessage(config Config, key cryptotypes.PrivKey, msgPerTx uint64) sd Amount: sdk.NewInt(1), }), } + case "staking": + msgType := config.MsgTypeDistr.SampleStakingMsgs() + + switch msgType { + case "delegate": + msg = &stakingtypes.MsgDelegate{ + DelegatorAddress: sdk.AccAddress(key.PubKey().Address()).String(), + ValidatorAddress: validators[rand.Intn(len(validators))].OpperatorAddr, + Amount: sdk.Coin{Denom: "usei", Amount: sdk.NewInt(5)}, + } + case "undelegate": + msg = &stakingtypes.MsgUndelegate{ + DelegatorAddress: sdk.AccAddress(key.PubKey().Address()).String(), + ValidatorAddress: validators[rand.Intn(len(validators))].OpperatorAddr, + Amount: sdk.Coin{Denom: "usei", Amount: sdk.NewInt(1)}, + } + case "begin_redelegate": + msg = &stakingtypes.MsgBeginRedelegate{ + DelegatorAddress: sdk.AccAddress(key.PubKey().Address()).String(), + ValidatorSrcAddress: validators[rand.Intn(len(validators))].OpperatorAddr, + ValidatorDstAddress: validators[rand.Intn(len(validators))].OpperatorAddr, + Amount: sdk.Coin{Denom: "usei", Amount: sdk.NewInt(1)}, + } + default: + panic("Unknown message type") + } case "dex": - msgType := config.MsgTypeDistr.Sample() + msgType := config.MsgTypeDistr.SampleDexMsgs() orderPlacements := []*dextypes.Order{} var orderType dextypes.OrderType if msgType == "limit" { diff --git a/loadtest/sign.go b/loadtest/sign.go index b27bf53d26..9651507852 100644 --- a/loadtest/sign.go +++ b/loadtest/sign.go @@ -5,6 +5,7 @@ import ( "fmt" "io" "os" + "os/exec" "path/filepath" "sync" "time" @@ -59,6 +60,29 @@ func NewSignerClient() *SignerClient { } } +type Validator struct { + OpperatorAddr string `json:"operator_address"` +} + +type QueryValidators struct { + Validators []Validator `json:"validators"` +} + +func GetValidators() QueryValidators { + seid_query, err := exec.Command("seid", "query", "staking", "validators", "--output", "json").Output() + + if err != nil { + panic(err) + } + + qv := QueryValidators{} + if err := json.Unmarshal(seid_query, &qv); err != nil { + panic(err) + } + + return qv +} + func (sc *SignerClient) GetKey(accountIdx uint64) cryptotypes.PrivKey { if val, ok := sc.CachedAccountKey.Load(accountIdx); ok { privKey := val.(cryptotypes.PrivKey) diff --git a/loadtest/types.go b/loadtest/types.go index 76ac460828..72874586ef 100644 --- a/loadtest/types.go +++ b/loadtest/types.go @@ -43,11 +43,14 @@ func (d *NumericDistribution) Sample() sdk.Dec { } type MsgTypeDistribution struct { - LimitOrderPct sdk.Dec `json:"limit_order_percentage"` - MarketOrderPct sdk.Dec `json:"market_order_percentage"` + LimitOrderPct sdk.Dec `json:"limit_order_percentage"` + MarketOrderPct sdk.Dec `json:"market_order_percentage"` + DelegatePct sdk.Dec `json:"delegate_percentage"` + UndelegatePct sdk.Dec `json:"undelegate_percentage"` + BeginRedelegatePct sdk.Dec `json:"begin_redelegate_percentage"` } -func (d *MsgTypeDistribution) Sample() string { +func (d *MsgTypeDistribution) SampleDexMsgs() string { if !d.LimitOrderPct.Add(d.MarketOrderPct).Equal(sdk.OneDec()) { panic("Distribution percentages must add up to 1") } @@ -58,6 +61,19 @@ func (d *MsgTypeDistribution) Sample() string { return "market" } +func (d *MsgTypeDistribution) SampleStakingMsgs() string { + if !d.DelegatePct.Add(d.UndelegatePct).Add(d.BeginRedelegatePct).Equal(sdk.OneDec()) { + panic("Distribution percentages must add up to 1") + } + randNum := sdk.MustNewDecFromStr(fmt.Sprintf("%f", rand.Float64())) + if randNum.LT(d.DelegatePct) { + return "delegate" + } else if randNum.LT(d.DelegatePct.Add(d.UndelegatePct)) { + return "undelegate" + } + return "begin_redelegate" +} + type ContractDistributions []ContractDistribution func (d *ContractDistributions) Sample() string { From 14cebc5cc494a47748d9e9c14f6d8dcf8c1d0c0e Mon Sep 17 00:00:00 2001 From: Eric Zhu Date: Tue, 25 Oct 2022 00:04:42 -0400 Subject: [PATCH 2/7] try staking messages --- loadtest/config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/loadtest/config.json b/loadtest/config.json index 0dcdf24a5d..d22f1b8343 100644 --- a/loadtest/config.json +++ b/loadtest/config.json @@ -20,7 +20,7 @@ "undelegate_percentage": "0.25", "begin_redelegate_percentage": "0.25" }, - "message_type": "basic", + "message_type": "staking", "contract_distribution": [ { "contract_address": "sei1yw4xvtc43me9scqfr2jr2gzvcxd3a9y4eq7gaukreugw2yd2f8tsy4qgdm", From 1d2a4c6869ee00ea74de1066cfc678864dd27e10 Mon Sep 17 00:00:00 2001 From: Eric Zhu Date: Tue, 25 Oct 2022 00:25:15 -0400 Subject: [PATCH 3/7] update param name --- loadtest/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/loadtest/main.go b/loadtest/main.go index 2a8774e037..c57a1a9390 100644 --- a/loadtest/main.go +++ b/loadtest/main.go @@ -70,7 +70,7 @@ func run() { fmt.Printf("%s - Finished\n", time.Now().Format("2006-01-02T15:04:05")) } -func generateMessage(config Config, key cryptotypes.PrivKey, batchSize uint64, validators []Validator) sdk.Msg { +func generateMessage(config Config, key cryptotypes.PrivKey, msgPerTx uint64, validators []Validator) sdk.Msg { var msg sdk.Msg switch config.MessageType { case "basic": From d1b1759046fcfeddf157ad690311f04757da2910 Mon Sep 17 00:00:00 2001 From: Eric Zhu Date: Tue, 25 Oct 2022 00:41:08 -0400 Subject: [PATCH 4/7] update config --- loadtest/config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/loadtest/config.json b/loadtest/config.json index d22f1b8343..9185eb38be 100644 --- a/loadtest/config.json +++ b/loadtest/config.json @@ -1,7 +1,7 @@ { "msgs_per_tx": 10, "chain_id": "sei-loadtest-testnet", - "txs_per_block": 6000, + "txs_per_block": 400, "rounds": 5, "price_distribution": { "min": "45", From e62803211474f26c10033862bc2827356daadb11 Mon Sep 17 00:00:00 2001 From: Eric Zhu Date: Tue, 25 Oct 2022 00:49:51 -0400 Subject: [PATCH 5/7] update msg distribution json in config --- loadtest/config.json | 14 +++++++++----- loadtest/types.go | 23 +++++++++++++++-------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/loadtest/config.json b/loadtest/config.json index 9185eb38be..580568577f 100644 --- a/loadtest/config.json +++ b/loadtest/config.json @@ -14,11 +14,15 @@ "number_of_distinct_values": 20 }, "message_type_distribution": { - "limit_order_percentage": "0.2", - "market_order_percentage": "0.8", - "delegate_percentage": "0.5", - "undelegate_percentage": "0.25", - "begin_redelegate_percentage": "0.25" + "dex": { + "limit_order_percentage": "0.2", + "market_order_percentage": "0.8" + }, + "staking": { + "delegate_percentage": "0.5", + "undelegate_percentage": "0.25", + "begin_redelegate_percentage": "0.25" + } }, "message_type": "staking", "contract_distribution": [ diff --git a/loadtest/types.go b/loadtest/types.go index 72874586ef..1e65ae8ea5 100644 --- a/loadtest/types.go +++ b/loadtest/types.go @@ -42,33 +42,40 @@ func (d *NumericDistribution) Sample() sdk.Dec { return d.Min.Add(d.Max.Sub(d.Min).QuoInt64(d.NumDistinct).Mul(steps)) } -type MsgTypeDistribution struct { - LimitOrderPct sdk.Dec `json:"limit_order_percentage"` - MarketOrderPct sdk.Dec `json:"market_order_percentage"` +type DexMsgTypeDistribution struct { + LimitOrderPct sdk.Dec `json:"limit_order_percentage"` + MarketOrderPct sdk.Dec `json:"market_order_percentage"` +} + +type StakingMsgTypeDistribution struct { DelegatePct sdk.Dec `json:"delegate_percentage"` UndelegatePct sdk.Dec `json:"undelegate_percentage"` BeginRedelegatePct sdk.Dec `json:"begin_redelegate_percentage"` } +type MsgTypeDistribution struct { + Dex DexMsgTypeDistribution `json:"dex"` + Staking StakingMsgTypeDistribution `json:"staking"` +} func (d *MsgTypeDistribution) SampleDexMsgs() string { - if !d.LimitOrderPct.Add(d.MarketOrderPct).Equal(sdk.OneDec()) { + if !d.Dex.LimitOrderPct.Add(d.Dex.MarketOrderPct).Equal(sdk.OneDec()) { panic("Distribution percentages must add up to 1") } randNum := sdk.MustNewDecFromStr(fmt.Sprintf("%f", rand.Float64())) - if randNum.LT(d.LimitOrderPct) { + if randNum.LT(d.Dex.LimitOrderPct) { return "limit" } return "market" } func (d *MsgTypeDistribution) SampleStakingMsgs() string { - if !d.DelegatePct.Add(d.UndelegatePct).Add(d.BeginRedelegatePct).Equal(sdk.OneDec()) { + if !d.Staking.DelegatePct.Add(d.Staking.UndelegatePct).Add(d.Staking.BeginRedelegatePct).Equal(sdk.OneDec()) { panic("Distribution percentages must add up to 1") } randNum := sdk.MustNewDecFromStr(fmt.Sprintf("%f", rand.Float64())) - if randNum.LT(d.DelegatePct) { + if randNum.LT(d.Staking.DelegatePct) { return "delegate" - } else if randNum.LT(d.DelegatePct.Add(d.UndelegatePct)) { + } else if randNum.LT(d.Staking.DelegatePct.Add(d.Staking.UndelegatePct)) { return "undelegate" } return "begin_redelegate" From 5e91dbd0bdae5e890adf0f5e1b8beb64a07e7ad6 Mon Sep 17 00:00:00 2001 From: Eric Zhu Date: Tue, 25 Oct 2022 01:17:50 -0400 Subject: [PATCH 6/7] fix linting error --- loadtest/sign.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/loadtest/sign.go b/loadtest/sign.go index 9651507852..19e8fcdda0 100644 --- a/loadtest/sign.go +++ b/loadtest/sign.go @@ -69,14 +69,13 @@ type QueryValidators struct { } func GetValidators() QueryValidators { - seid_query, err := exec.Command("seid", "query", "staking", "validators", "--output", "json").Output() - + seidQuery, err := exec.Command("seid", "query", "staking", "validators", "--output", "json").Output() if err != nil { panic(err) } qv := QueryValidators{} - if err := json.Unmarshal(seid_query, &qv); err != nil { + if err := json.Unmarshal(seidQuery, &qv); err != nil { panic(err) } From 3cf8541cf06f255fc4a8a3d0e29a5f66990d38ca Mon Sep 17 00:00:00 2001 From: Eric Zhu Date: Tue, 25 Oct 2022 01:29:48 -0400 Subject: [PATCH 7/7] revert to basic msg type --- loadtest/config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/loadtest/config.json b/loadtest/config.json index 580568577f..71dfde2c71 100644 --- a/loadtest/config.json +++ b/loadtest/config.json @@ -24,7 +24,7 @@ "begin_redelegate_percentage": "0.25" } }, - "message_type": "staking", + "message_type": "basic", "contract_distribution": [ { "contract_address": "sei1yw4xvtc43me9scqfr2jr2gzvcxd3a9y4eq7gaukreugw2yd2f8tsy4qgdm",