From c7838ad91fc3c8082dab1ad8aa25cc6784f13a00 Mon Sep 17 00:00:00 2001 From: Peter Barrow Date: Wed, 19 Oct 2022 13:00:33 +0100 Subject: [PATCH 1/3] feat: Configure number of LP orders per side --- CHANGELOG.md | 1 + cmd/perftest.go | 1 + go.mod | 2 +- go.sum | 4 ++-- perftest/datanode.go | 17 ++++++++++++++ perftest/perftest.go | 19 ++++++++++++--- perftest/wallet.go | 56 +++++++++++++++++--------------------------- 7 files changed, 59 insertions(+), 41 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 19614fd..14da05f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,6 +55,7 @@ - [218](https://github.com/vegaprotocol/vegatools/issue/218) - perftest allows multiple LPs and moving of mid price for random orders - [222](https://github.com/vegaprotocol/vegatools/issue/222) - Updated market proposal text with renamed fields - [225](https://github.com/vegaprotocol/vegatools/issue/225) - Add option to dump total event counts +- [227](https://github.com/vegaprotocol/vegatools/issue/227) - Allow configuration of the LP shape ### 🐛 Fixes - [78](https://github.com/vegaprotocol/vegatools/pull/78) - Fix build with missing dependency diff --git a/cmd/perftest.go b/cmd/perftest.go index f63fdf4..8643c26 100644 --- a/cmd/perftest.go +++ b/cmd/perftest.go @@ -26,6 +26,7 @@ func init() { perfTestCmd.Flags().IntVarP(&opts.UserCount, "users", "u", 10, "number of users to send commands with") perfTestCmd.Flags().IntVarP(&opts.MarketCount, "markets", "m", 1, "number of markets to create and use") perfTestCmd.Flags().IntVarP(&opts.Voters, "voters", "v", 3, "number of accounts to assign voting power") + perfTestCmd.Flags().IntVarP(&opts.LPOrdersPerSide, "lporders", "l", 3, "number of orders per side in the LP shape") perfTestCmd.Flags().BoolVarP(&opts.MoveMid, "movemidprice", "p", false, "allow the mid price we place orders around to move randomly") perfTestCmd.MarkFlagRequired("address") perfTestCmd.MarkFlagRequired("wallet") diff --git a/go.mod b/go.mod index 80b1031..19d17c5 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.19 require ( code.vegaprotocol.io/shared v0.0.0-20220704150014-7c22d12ccb72 - code.vegaprotocol.io/vega v0.57.1-0.20221007134620-54ab707ac14d + code.vegaprotocol.io/vega v0.58.1-0.20221018160916-e5debe36ecb1 github.com/cosmos/iavl v0.19.1 github.com/ethereum/go-ethereum v1.10.21 github.com/gdamore/tcell/v2 v2.5.2 diff --git a/go.sum b/go.sum index a2a4ec6..02960f8 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= code.vegaprotocol.io/shared v0.0.0-20220704150014-7c22d12ccb72 h1:BJwmbEbC+ujqLSA1dSyUwDOc4+aRoZcndj/RM210CtE= code.vegaprotocol.io/shared v0.0.0-20220704150014-7c22d12ccb72/go.mod h1:P9MfU2GyzI4Vc7OrKx9+qN9JV0bNGFB/aYe0++e7158= -code.vegaprotocol.io/vega v0.57.1-0.20221007134620-54ab707ac14d h1:9CJJLpF/oldVly33eZi1lQKTGwkVEgNnMx3XxV+yipU= -code.vegaprotocol.io/vega v0.57.1-0.20221007134620-54ab707ac14d/go.mod h1:FQ3Q23aHsBNIzNL4YyTab2w/cleZQlr/vPfhQym04v4= +code.vegaprotocol.io/vega v0.58.1-0.20221018160916-e5debe36ecb1 h1:zqPMCOusWpPDPsm8f25fLIxv9cU95nFsIfdvYWTv0KQ= +code.vegaprotocol.io/vega v0.58.1-0.20221018160916-e5debe36ecb1/go.mod h1:G9A0haG9Qf0GNd6oza8UeDxF9hDVHRwM+1OkUcZnfac= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/DataDog/zstd v1.4.1 h1:3oxKN3wbHibqx897utPC2LTQU4J+IHWWJO+glkAkpFM= github.com/DataDog/zstd v1.4.1/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo= diff --git a/perftest/datanode.go b/perftest/datanode.go index 058e9d1..8aea7de 100644 --- a/perftest/datanode.go +++ b/perftest/datanode.go @@ -17,6 +17,23 @@ type dnWrapper struct { wallet walletWrapper } +func (d *dnWrapper) getNetworkParam(param string) (string, error) { + request := &datanode.NetworkParametersRequest{} + + response, err := d.dataNode.NetworkParameters(context.Background(), request) + if err != nil { + return "", err + } + + for _, value := range response.NetworkParameters { + if value.Key == "market.liquidityProvision.shapes.maxSize" { + return value.Value, nil + } + } + // We didn't find it + return "", fmt.Errorf("failed to get network parameter for maximum LP shape size") +} + func (d *dnWrapper) getAssets() (map[string]string, error) { request := &datanode.AssetsRequest{} diff --git a/perftest/perftest.go b/perftest/perftest.go index 3cbad16..f5a0e06 100644 --- a/perftest/perftest.go +++ b/perftest/perftest.go @@ -5,6 +5,7 @@ import ( "fmt" "log" "math/rand" + "strconv" "time" "google.golang.org/grpc" @@ -27,6 +28,7 @@ type Opts struct { MarketCount int Voters int MoveMid bool + LPOrdersPerSide int } type perfLoadTesting struct { @@ -103,7 +105,7 @@ func (p *perfLoadTesting) depositTokens(assets map[string]string, faucetURL, gan return nil } -func (p *perfLoadTesting) proposeAndEnactMarket(numberOfMarkets, voters int) ([]string, error) { +func (p *perfLoadTesting) proposeAndEnactMarket(numberOfMarkets, voters, maxLPShape int) ([]string, error) { markets := p.dataNode.getMarkets() if len(markets) == 0 { for i := 0; i < numberOfMarkets; i++ { @@ -132,7 +134,7 @@ func (p *perfLoadTesting) proposeAndEnactMarket(numberOfMarkets, voters int) ([] for i := 0; i < len(markets); i++ { // Send in a liquidity provision so we can get the market out of auction for j := 0; j < voters; j++ { - p.wallet.SendLiquidityProvision(p.users[j], markets[i]) + p.wallet.SendLiquidityProvision(p.users[j], markets[i], maxLPShape) } p.wallet.SendOrder(p.users[0], &commandspb.OrderSubmission{MarketId: markets[i], @@ -317,9 +319,20 @@ func Run(opts Opts) error { } fmt.Println("Complete") + networkParam, err := plt.dataNode.getNetworkParam("market.liquidityProvision.shapes.maxSize") + if err != nil { + fmt.Println("Failed to get LP maximum shape size") + return err + } + maxLPShape, _ := strconv.ParseInt(networkParam, 0, 32) + + if opts.LPOrdersPerSide > int(maxLPShape) { + return fmt.Errorf("supplied lp size greater than network param (%d>%d)", opts.LPOrdersPerSide, maxLPShape) + } + // Send in a proposal to create a new market and vote to get it through fmt.Print("Proposing and voting in new market...") - marketIDs, err := plt.proposeAndEnactMarket(opts.MarketCount, opts.Voters) + marketIDs, err := plt.proposeAndEnactMarket(opts.MarketCount, opts.Voters, opts.LPOrdersPerSide) if err != nil { fmt.Println("FAILED") return err diff --git a/perftest/wallet.go b/perftest/wallet.go index c85d665..76e74b7 100644 --- a/perftest/wallet.go +++ b/perftest/wallet.go @@ -7,6 +7,7 @@ import ( "io" "log" "net/http" + "strconv" "strings" "time" @@ -360,48 +361,33 @@ func (w *walletWrapper) SendNewMarketProposal(marketIndex int, user UserDetails) return w.SignSubmitTx(user.token, cmd) } -func (w *walletWrapper) SendLiquidityProvision(user UserDetails, marketID string) error { +func (w *walletWrapper) SendLiquidityProvision(user UserDetails, marketID string, orderCount int) error { lp := commandspb.LiquidityProvisionSubmission{ MarketId: marketID, Reference: "MarketLiquidity", Fee: "0.01", CommitmentAmount: "50000000", - Buys: []*proto.LiquidityOrder{ - { - Reference: proto.PeggedReference_PEGGED_REFERENCE_BEST_BID, - Proportion: 10, - Offset: "1000", - }, - { - Reference: proto.PeggedReference_PEGGED_REFERENCE_BEST_BID, - Proportion: 10, - Offset: "1500", - }, - { - Reference: proto.PeggedReference_PEGGED_REFERENCE_MID, - Proportion: 10, - Offset: "2000", - }, - }, - Sells: []*proto.LiquidityOrder{ - { - Reference: proto.PeggedReference_PEGGED_REFERENCE_BEST_ASK, - Proportion: 10, - Offset: "2000", - }, - { - Reference: proto.PeggedReference_PEGGED_REFERENCE_BEST_ASK, - Proportion: 10, - Offset: "1500", - }, - { - Reference: proto.PeggedReference_PEGGED_REFERENCE_MID, - Proportion: 10, - Offset: "1000", - }, - }, } + // Generate the buy and sell side LP orders + buys := make([]*proto.LiquidityOrder, orderCount) + sells := make([]*proto.LiquidityOrder, orderCount) + for i := 0; i < orderCount; i++ { + buys[i] = &proto.LiquidityOrder{ + Reference: proto.PeggedReference_PEGGED_REFERENCE_BEST_BID, + Proportion: 10, + Offset: strconv.FormatInt(int64(1000+(i*10)), 10), + } + sells[i] = &proto.LiquidityOrder{ + Reference: proto.PeggedReference_PEGGED_REFERENCE_BEST_ASK, + Proportion: 10, + Offset: strconv.FormatInt(int64(1000+(i*10)), 10), + } + } + + lp.Buys = buys + lp.Sells = sells + m := jsonpb.Marshaler{} submitTxReq := &walletpb.SubmitTransactionRequest{ From 155796f9f4c612bbaca0a0848dd25dc6aa7d39b8 Mon Sep 17 00:00:00 2001 From: Peter Barrow Date: Wed, 19 Oct 2022 15:10:17 +0100 Subject: [PATCH 2/3] feat: made network param configurable --- perftest/datanode.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/perftest/datanode.go b/perftest/datanode.go index 8aea7de..82d3e02 100644 --- a/perftest/datanode.go +++ b/perftest/datanode.go @@ -26,12 +26,12 @@ func (d *dnWrapper) getNetworkParam(param string) (string, error) { } for _, value := range response.NetworkParameters { - if value.Key == "market.liquidityProvision.shapes.maxSize" { + if value.Key == param { return value.Value, nil } } // We didn't find it - return "", fmt.Errorf("failed to get network parameter for maximum LP shape size") + return "", fmt.Errorf("failed to get network parameter %s", param) } func (d *dnWrapper) getAssets() (map[string]string, error) { From 8ace24c30bd6d7c6987c8af3d071b8901c4b6dad Mon Sep 17 00:00:00 2001 From: Peter Barrow Date: Thu, 20 Oct 2022 12:01:16 +0100 Subject: [PATCH 3/3] feat: updated datanode access to v2 --- perftest/datanode.go | 73 ++++++++++++++++++++++---------------------- perftest/perftest.go | 2 +- 2 files changed, 38 insertions(+), 37 deletions(-) diff --git a/perftest/datanode.go b/perftest/datanode.go index 82d3e02..f0a04ba 100644 --- a/perftest/datanode.go +++ b/perftest/datanode.go @@ -7,7 +7,7 @@ import ( "strconv" "time" - datanode "code.vegaprotocol.io/vega/protos/data-node/api/v1" + datanode "code.vegaprotocol.io/vega/protos/data-node/api/v2" proto "code.vegaprotocol.io/vega/protos/vega" v1 "code.vegaprotocol.io/vega/protos/vega/commands/v1" ) @@ -18,98 +18,99 @@ type dnWrapper struct { } func (d *dnWrapper) getNetworkParam(param string) (string, error) { - request := &datanode.NetworkParametersRequest{} + request := &datanode.GetNetworkParameterRequest{ + Key: param, + } - response, err := d.dataNode.NetworkParameters(context.Background(), request) + response, err := d.dataNode.GetNetworkParameter(context.Background(), request) if err != nil { return "", err } - for _, value := range response.NetworkParameters { - if value.Key == param { - return value.Value, nil - } - } - // We didn't find it - return "", fmt.Errorf("failed to get network parameter %s", param) + return response.NetworkParameter.Value, nil } func (d *dnWrapper) getAssets() (map[string]string, error) { - request := &datanode.AssetsRequest{} + request := &datanode.ListAssetsRequest{} - response, err := d.dataNode.Assets(context.Background(), request) + response, err := d.dataNode.ListAssets(context.Background(), request) if err != nil { return nil, err } assets := map[string]string{} - for _, asset := range response.Assets { - assets[asset.Details.Symbol] = asset.Id + for _, asset := range response.GetAssets().GetEdges() { + assets[asset.Node.Details.Symbol] = asset.Node.Id } return assets, nil } func (d *dnWrapper) getAssetsPerUser(pubKey, asset string) (int64, error) { - request := &datanode.PartyAccountsRequest{ - PartyId: pubKey, - Asset: asset, + request := &datanode.ListAccountsRequest{ + Filter: &datanode.AccountFilter{ + AssetId: asset, + PartyIds: []string{pubKey}, + AccountTypes: []proto.AccountType{ + proto.AccountType_ACCOUNT_TYPE_GENERAL, + }, + }, } - response, err := d.dataNode.PartyAccounts(context.Background(), request) + response, err := d.dataNode.ListAccounts(context.Background(), request) if err != nil { return 0, err } - for _, account := range response.Accounts { - if account.Type == proto.AccountType_ACCOUNT_TYPE_GENERAL { - return strconv.ParseInt(account.Balance, 10, 64) - } + for _, account := range response.Accounts.Edges { + return strconv.ParseInt(account.Account.Balance, 10, 64) } return 0, nil } func (d *dnWrapper) getMarkets() []string { - marketsReq := &datanode.MarketsRequest{} + marketsReq := &datanode.ListMarketsRequest{} - response, err := d.dataNode.Markets(context.Background(), marketsReq) + response, err := d.dataNode.ListMarkets(context.Background(), marketsReq) if err != nil { log.Println(err) return nil } marketIDs := []string{} - for _, market := range response.Markets { - if market.State != proto.Market_STATE_REJECTED { - marketIDs = append(marketIDs, market.Id) + for _, market := range response.Markets.Edges { + if market.Node.State != proto.Market_STATE_REJECTED { + marketIDs = append(marketIDs, market.Node.Id) } } return marketIDs } func (d *dnWrapper) getPendingProposalID() (string, error) { - request := &datanode.GetProposalsRequest{} + request := &datanode.ListGovernanceDataRequest{} - response, err := d.dataNode.GetProposals(context.Background(), request) + response, err := d.dataNode.ListGovernanceData(context.Background(), request) if err != nil { log.Println(err) } - for _, proposal := range response.GetData() { - if proposal.Proposal.State == proto.Proposal_STATE_OPEN { - return proposal.Proposal.Id, nil + for _, proposal := range response.Connection.Edges { + if proposal.Node.Proposal.State == proto.Proposal_STATE_OPEN { + return proposal.Node.Proposal.Id, nil } } return "", fmt.Errorf("no pending proposals found") } func (d *dnWrapper) waitForMarketEnactment(marketID string, maxWaitSeconds int) error { - request := &datanode.GetProposalsRequest{} + request := &datanode.ListGovernanceDataRequest{ + ProposalReference: &marketID, + } for i := 0; i < maxWaitSeconds; i++ { - response, err := d.dataNode.GetProposals(context.Background(), request) + response, err := d.dataNode.ListGovernanceData(context.Background(), request) if err != nil { return err } - for _, proposal := range response.GetData() { - if proposal.Proposal.State == proto.Proposal_STATE_ENACTED { + for _, proposal := range response.Connection.Edges { + if proposal.Node.Proposal.State == proto.Proposal_STATE_ENACTED { return nil } } diff --git a/perftest/perftest.go b/perftest/perftest.go index f5a0e06..abedb96 100644 --- a/perftest/perftest.go +++ b/perftest/perftest.go @@ -11,7 +11,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" - datanode "code.vegaprotocol.io/vega/protos/data-node/api/v1" + datanode "code.vegaprotocol.io/vega/protos/data-node/api/v2" proto "code.vegaprotocol.io/vega/protos/vega" commandspb "code.vegaprotocol.io/vega/protos/vega/commands/v1" )