From 26012fc6f174b6ecf7d9ecad723eadf18697581b Mon Sep 17 00:00:00 2001 From: Peter Barrow Date: Fri, 6 Jan 2023 14:57:56 +0000 Subject: [PATCH 1/6] fix: Moving over to wallet v2 api --- checkpoint/type.go | 2 +- cmd/perftest.go | 2 + go.mod | 6 +- go.sum | 14 +- perftest/datanode.go | 3 +- perftest/perftest.go | 45 +++- perftest/wallet.go | 513 +++++++++++--------------------------- snapshotdb/snapshotdb.go | 2 +- withdraw/pull_withdraw.go | 1 - 9 files changed, 202 insertions(+), 386 deletions(-) diff --git a/checkpoint/type.go b/checkpoint/type.go index 36ccf09..4e7f32e 100644 --- a/checkpoint/type.go +++ b/checkpoint/type.go @@ -413,7 +413,7 @@ func dummy() *all { TimeWindow: 10, ScalingFactor: 0.7, }, - TriggeringRatio: 0.5, + TriggeringRatio: "0.5", AuctionExtension: 10, }, RiskParameters: &vega.NewMarketConfiguration_LogNormal{ diff --git a/cmd/perftest.go b/cmd/perftest.go index 69023a9..355d468 100644 --- a/cmd/perftest.go +++ b/cmd/perftest.go @@ -21,6 +21,7 @@ func init() { perfTestCmd.Flags().StringVarP(&opts.WalletURL, "wallet", "w", "", "address of the wallet server") perfTestCmd.Flags().StringVarP(&opts.FaucetURL, "faucet", "f", "", "address of the faucet server") perfTestCmd.Flags().StringVarP(&opts.GanacheURL, "ganache", "g", "", "address of the ganache server") + perfTestCmd.Flags().StringVarP(&opts.TokenKeysFile, "tokenkeys", "t", "", "path to api token keys file") perfTestCmd.Flags().IntVarP(&opts.CommandsPerSecond, "cps", "c", 100, "commands per second") perfTestCmd.Flags().IntVarP(&opts.RuntimeSeconds, "runtime", "r", 60, "runtime in seconds") perfTestCmd.Flags().IntVarP(&opts.UserCount, "users", "u", 10, "number of users to send commands with") @@ -36,6 +37,7 @@ func init() { perfTestCmd.MarkFlagRequired("address") perfTestCmd.MarkFlagRequired("wallet") perfTestCmd.MarkFlagRequired("faucet") + perfTestCmd.MarkFlagRequired("tokenkeys") } func runPerfTest(cmd *cobra.Command, args []string) error { diff --git a/go.mod b/go.mod index 7272b6d..6aeccff 100644 --- a/go.mod +++ b/go.mod @@ -4,8 +4,8 @@ go 1.19 require ( code.vegaprotocol.io/shared v0.0.0-20221010085458-55c50711135f - code.vegaprotocol.io/vega v0.62.2-0.20221118155204-060bc3b13f56 - github.com/cosmos/iavl v0.19.1 + code.vegaprotocol.io/vega v0.66.0 + github.com/cosmos/iavl v0.19.4 github.com/ethereum/go-ethereum v1.10.21 github.com/gdamore/tcell/v2 v2.5.2 github.com/gogo/protobuf v1.3.2 @@ -54,7 +54,7 @@ require ( github.com/rjeczalik/notify v0.9.1 // indirect github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect github.com/spf13/pflag v1.0.5 // indirect - github.com/tendermint/tendermint v0.34.23 // indirect + github.com/tendermint/tendermint v0.34.24 // indirect github.com/tklauser/go-sysconf v0.3.10 // indirect github.com/tklauser/numcpus v0.4.0 // indirect go.etcd.io/bbolt v1.3.6 // indirect diff --git a/go.sum b/go.sum index c8f9f9c..81e413c 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,7 @@ code.vegaprotocol.io/shared v0.0.0-20221010085458-55c50711135f h1:ivaWSXN7XKESShqYw/QFuT6b2mvThWPQLO7lW5sadHs= code.vegaprotocol.io/shared v0.0.0-20221010085458-55c50711135f/go.mod h1:XzX67GsyOHzvytMr0QOHX4CCTdCZDYKUUi88rx40Nt0= -code.vegaprotocol.io/vega v0.62.2-0.20221118155204-060bc3b13f56 h1:4Yqk9HyAvv+whbzUGuulvIR85UxNhyxl9RqMv4BMnII= -code.vegaprotocol.io/vega v0.62.2-0.20221118155204-060bc3b13f56/go.mod h1:kferwPYB97SNdznVdU2Ao3AoNlao5NH+C68ityenuVk= +code.vegaprotocol.io/vega v0.66.0 h1:6IYqaQn+INPpMzz795N6oLuXBfLtRIC3I1C47Bs9EZ4= +code.vegaprotocol.io/vega v0.66.0/go.mod h1:hnqQGTSfFafoDICM8IeOcr/+rfXANT9v8NpwIRue0SA= 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= @@ -12,7 +12,7 @@ github.com/StackExchange/wmi v1.2.1 h1:VIkavFPXSjcnS+O8yTq7NI32k0R5Aj+v39y29VYDO github.com/StackExchange/wmi v1.2.1/go.mod h1:rcmrprowKIVzvc+NUiLncP2uuArMWLCbu9SBzvHz7e8= github.com/VictoriaMetrics/fastcache v1.6.0 h1:C/3Oi3EiBCqufydp1neRZkqcwmEiuRT9c3fqvvgKm5o= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= -github.com/btcsuite/btcd v0.22.1 h1:CnwP9LM/M9xuRrGSCGeMVs9iv09uMqwsVX7EeIpgV2c= +github.com/btcsuite/btcd v0.22.2 h1:vBZ+lGGd1XubpOWO67ITJpAEsICWhA0YzqkcpkgNBfo= github.com/btcsuite/btcd/btcec/v2 v2.2.0 h1:fzn1qaOt32TuLjFlkzYSsBC35Q3KUjT1SwPxiMSCF5k= github.com/btcsuite/btcd/btcec/v2 v2.2.0/go.mod h1:U7MHm051Al6XmscBQ0BoNydpOTsFAn707034b5nY8zU= github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U= @@ -30,8 +30,8 @@ github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8Nz github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/cosmos/gorocksdb v1.2.0 h1:d0l3jJG8M4hBouIZq0mDUHZ+zjOx044J3nGRskwTb4Y= github.com/cosmos/gorocksdb v1.2.0/go.mod h1:aaKvKItm514hKfNJpUJXnnOWeBnk2GL4+Qw9NHizILw= -github.com/cosmos/iavl v0.19.1 h1:3gaq9b6SjiB0KBTygRnAvEGml2pQlu1TH8uma5g63Ys= -github.com/cosmos/iavl v0.19.1/go.mod h1:X9PKD3J0iFxdmgNLa7b2LYWdsGd90ToV5cAONApkEPw= +github.com/cosmos/iavl v0.19.4 h1:t82sN+Y0WeqxDLJRSpNd8YFX5URIrT+p8n6oJbJ2Dok= +github.com/cosmos/iavl v0.19.4/go.mod h1:X9PKD3J0iFxdmgNLa7b2LYWdsGd90ToV5cAONApkEPw= github.com/cpuguy83/go-md2man v1.0.10 h1:BSKMNlYxDvnunlTymqtgONjNnaRV1sTpcovwwjF22jk= github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= @@ -205,8 +205,8 @@ github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PK github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a h1:1ur3QoCqvE5fl+nylMaIr9PVV1w343YRDtsy+Rwu7XI= github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a/go.mod h1:RRCYJbIwD5jmqPI9XoAFR0OcDxqUctll6zUj/+B4S48= -github.com/tendermint/tendermint v0.34.23 h1:JZYsdc59aOiT5efou+BHILJv8x6FlRyvlor84Xq9Tb0= -github.com/tendermint/tendermint v0.34.23/go.mod h1:rXVrl4OYzmIa1I91av3iLv2HS0fGSiucyW9J4aMTpKI= +github.com/tendermint/tendermint v0.34.24 h1:879MKKJWYYPJEMMKME+DWUTY4V9f/FBpnZDI82ky+4k= +github.com/tendermint/tendermint v0.34.24/go.mod h1:rXVrl4OYzmIa1I91av3iLv2HS0fGSiucyW9J4aMTpKI= github.com/tendermint/tm-db v0.6.7 h1:fE00Cbl0jayAoqlExN6oyQJ7fR/ZtoVOmvPJ//+shu8= github.com/tendermint/tm-db v0.6.7/go.mod h1:byQDzFkZV1syXr/ReXS808NxA2xvyuuVgXOJ/088L6I= github.com/tklauser/go-sysconf v0.3.10 h1:IJ1AZGZRWbY8T5Vfk04D9WOA5WSejdflXxP03OUqALw= diff --git a/perftest/datanode.go b/perftest/datanode.go index 7671cda..b8e52c5 100644 --- a/perftest/datanode.go +++ b/perftest/datanode.go @@ -9,7 +9,6 @@ import ( 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" ) type dnWrapper struct { @@ -121,7 +120,7 @@ func (d *dnWrapper) waitForMarketEnactment(marketID string, maxWaitSeconds int) func (d *dnWrapper) voteOnProposal(users []UserDetails, propID string, voters int) error { for i := 0; i < voters; i++ { - err := d.wallet.SendVote(users[i], &v1.VoteSubmission{ProposalId: propID, Value: proto.Vote_VALUE_YES}) + err := d.wallet.SendVote(users[i], propID) if err != nil { return err } diff --git a/perftest/perftest.go b/perftest/perftest.go index be20a65..691e792 100644 --- a/perftest/perftest.go +++ b/perftest/perftest.go @@ -1,11 +1,14 @@ package perftest import ( + "bufio" "flag" "fmt" "log" "math/rand" + "os" "strconv" + "strings" "time" "google.golang.org/grpc" @@ -22,6 +25,7 @@ type Opts struct { WalletURL string FaucetURL string GanacheURL string + TokenKeysFile string CommandsPerSecond int RuntimeSeconds int UserCount int @@ -70,10 +74,28 @@ func (p *perfLoadTesting) connectToDataNode(dataNodeAddr string) (map[string]str } } -func (p *perfLoadTesting) CreateUsers(userCount int) error { - var err error - p.users, err = p.wallet.CreateOrLoadWallets(userCount) - return err +func (p *perfLoadTesting) LoadUsers(tokenFilePath string, userCount int) error { + // See if we have a token file defined and if so load all the wallet names and api-keys + p.users = []UserDetails{} + tokenFile, err := os.Open(tokenFilePath) + if err != nil { + return err + } + fileScanner := bufio.NewScanner(tokenFile) + fileScanner.Split(bufio.ScanLines) + + for fileScanner.Scan() { + lineParts := strings.Split(fileScanner.Text(), " ") + if len(lineParts) == 2 { + pubKey, _ := p.wallet.GetFirstKey(lineParts[1]) + + p.users = append(p.users, UserDetails{userName: lineParts[0], token: lineParts[1], pubKey: pubKey}) + } + if len(p.users) == userCount { + break + } + } + return nil } func (p *perfLoadTesting) depositTokens(assets map[string]string, faucetURL, ganacheURL string, voters int) error { @@ -168,7 +190,7 @@ func (p *perfLoadTesting) proposeAndEnactMarket(numberOfMarkets, voters, maxLPSh markets := p.dataNode.getMarkets() if len(markets) == 0 { for i := 0; i < numberOfMarkets; i++ { - err := p.wallet.SendNewMarketProposal(i, p.users[0]) + err := p.wallet.NewMarket(i, p.users[0]) if err != nil { return nil, err } @@ -568,11 +590,16 @@ func Run(opts Opts) error { fmt.Println("Complete") // Create a set of users - fmt.Print("Creating users...") - err = plt.CreateUsers(opts.UserCount) - if err != nil { + fmt.Print("Loading users from token API file...") + if len(opts.TokenKeysFile) > 0 { + err = plt.LoadUsers(opts.TokenKeysFile, opts.UserCount) + if err != nil { + fmt.Println("FAILED") + return err + } + } else { fmt.Println("FAILED") - return err + return fmt.Errorf("error: unable to open token file") } fmt.Println("Complete") diff --git a/perftest/wallet.go b/perftest/wallet.go index 67f08a2..d02b338 100644 --- a/perftest/wallet.go +++ b/perftest/wallet.go @@ -5,17 +5,12 @@ import ( "encoding/json" "fmt" "io" - "log" "net/http" "strconv" - "strings" "time" - "github.com/gogo/protobuf/jsonpb" - proto "code.vegaprotocol.io/vega/protos/vega" commandspb "code.vegaprotocol.io/vega/protos/vega/commands/v1" - v1 "code.vegaprotocol.io/vega/protos/vega/data/v1" walletpb "code.vegaprotocol.io/vega/protos/vega/wallet/v1" ) @@ -36,227 +31,172 @@ func (w walletWrapper) SecondsFromNowInSecs(seconds int64) int64 { return time.Now().Unix() + seconds } -// LoginWallet opens a wallet and logs into it using the supplied username and password -func (w walletWrapper) LoginWallet(username, password string) (string, error) { - postBody, _ := json.Marshal(map[string]string{ - "wallet": username, - "passphrase": password, - }) - responseBody := bytes.NewBuffer(postBody) - - URL := "http://" + w.walletURL + "/api/v1/auth/token" - - resp, err := http.Post(URL, "application/json", responseBody) - if err != nil { - return "", err - } - defer resp.Body.Close() - body, err := io.ReadAll(resp.Body) - if err != nil { - return "", err - } - sb := string(body) - if strings.Contains(sb, "error") { - return "", fmt.Errorf(sb) - } - - // Get the token value out from the JSON - var result map[string]interface{} - json.Unmarshal([]byte(sb), &result) - - return result["token"].(string), nil +type Keys struct { + Keys []Key } - -// CreateWallet will create a new wallet if one does not already exist -func (w walletWrapper) CreateWallet(username, password string) (string, error) { - postBody, _ := json.Marshal(map[string]string{ - "wallet": username, - "passphrase": password, - }) - responseBody := bytes.NewBuffer(postBody) - - URL := "http://" + w.walletURL + "/api/v1/wallets" - - resp, err := http.Post(URL, "application/json", responseBody) - if err != nil { - return "", err - } - defer resp.Body.Close() - body, err := io.ReadAll(resp.Body) - if err != nil { - return "", err - } - sb := string(body) - if strings.Contains(sb, "\"error\"") { - return "", fmt.Errorf(sb) - } - - // Get the token value out from the JSON - var result map[string]interface{} - json.Unmarshal([]byte(sb), &result) - - return result["token"].(string), nil +type Key struct { + Name string + PublicKey string +} +type ListKeysResult struct { + Jsonrpc string + Result Keys + Id string } -// CreateKey will create a new key pair in the open wallet -func (w walletWrapper) CreateKey(password, token string) (string, error) { - postBody, _ := json.Marshal(map[string]string{ - "passphrase": password, +func (w walletWrapper) sendTransaction(user UserDetails, subType string, subData interface{}) ([]byte, error) { + transaction, _ := json.Marshal(map[string]interface{}{ + "jsonrpc": "2.0", + "method": "client.send_transaction", + "id": "1", + "params": map[string]interface{}{ + "token": user.token, + "publicKey": user.pubKey, + "sendingMode": "TYPE_SYNC", + "transaction": map[string]interface{}{ + subType: subData, + }, + }, }) - postBuffer := bytes.NewBuffer(postBody) - - URL := "http://" + w.walletURL + "/api/v1/keys" - - client := &http.Client{} - req, err := http.NewRequest(http.MethodPost, URL, postBuffer) - if err != nil { - log.Fatal(err) - } - - bearer := "Bearer " + token - - req.Header.Add("Authorization", bearer) - - resp, err := client.Do(req) - if err != nil { - log.Println(err) - } - - defer resp.Body.Close() - body, err := io.ReadAll(resp.Body) - if err != nil { - return "", err - } - sb := string(body) - if strings.Contains(sb, "error") { - return "", fmt.Errorf(sb) - } - // Get the token value out from the JSON - var result map[string]interface{} - json.Unmarshal([]byte(sb), &result) - keys := result["key"].(map[string]interface{}) - return keys["pub"].(string), nil + return w.sendRequest(transaction) } -// ListKeys shows all the keys associated with the open wallet. -func (w walletWrapper) ListKeys(token string) ([]string, error) { - URL := "http://" + w.walletURL + "/api/v1/keys" - - client := &http.Client{} - req, err := http.NewRequest(http.MethodGet, URL, nil) - if err != nil { - return nil, err - } +func (w walletWrapper) sendRequest(request []byte) ([]byte, error) { + postBody := bytes.NewBuffer(request) - bearer := "Bearer " + token + URL := "http://" + w.walletURL + "/api/v2/requests" - req.Header.Add("Authorization", bearer) - - resp, err := client.Do(req) + req, err := http.NewRequest(http.MethodPost, URL, postBody) if err != nil { return nil, err } + req.Header.Add("origin", "perfbot") + client := &http.Client{} + resp, err := client.Do(req) defer resp.Body.Close() - body, err := io.ReadAll(resp.Body) + reply, err := io.ReadAll(resp.Body) + fmt.Println(string(reply)) if err != nil { return nil, err } - sb := string(body) - if strings.Contains(sb, "error") { - return nil, fmt.Errorf(sb) - } - - // Get the token value out from the JSON - var result map[string]interface{} - json.Unmarshal([]byte(sb), &result) - keys := result["keys"].([]interface{}) - if len(keys) == 0 { - return nil, fmt.Errorf("no keys found") - } - - pubKeys := []string{} - for i := 0; i < len(keys); i++ { - key := keys[i].(map[string]interface{}) - pubKeys = append(pubKeys, key["pub"].(string)) - } - return pubKeys, nil + return reply, nil } -// CreateOrLoadWallets will first attempt to open a wallet but if that does not -// exist it will create one and create a key ready for use -func (w walletWrapper) CreateOrLoadWallets(number int) ([]UserDetails, error) { - // We want to make or load a set of wallets, do it in a loop here - var key string - var newKeys = 0 - var users []UserDetails = []UserDetails{} - for i := 0; i < number; i++ { - userName := fmt.Sprintf("User%04d", i) - - // Attempt to log in with that username - token, err := w.LoginWallet(userName, "p3rfb0t") - if err != nil { - token, err = w.CreateWallet(userName, "p3rfb0t") - if err != nil { - return nil, fmt.Errorf("unable to create a new wallet: %w", err) - } - } - keys, _ := w.ListKeys(token) - if len(keys) == 0 { - key, _ = w.CreateKey("p3rfb0t", token) - newKeys++ - } else { - key = keys[0] - } - - users = append(users, UserDetails{ - userName: userName, - token: token, - pubKey: key, - }) +func (w walletWrapper) NewMarket(offset int, user UserDetails) error { + newMarket := map[string]interface{}{ + "rationale": map[string]interface{}{ + "description": "desc", + "title": "title", + }, + "terms": map[string]interface{}{ + "closingTimestamp": w.SecondsFromNowInSecs(15), + "enactmentTimestamp": w.SecondsFromNowInSecs(30), + "newMarket": map[string]interface{}{ + "changes": map[string]interface{}{ + "lpPriceRange": "10", + "decimalPlaces": "5", + "positionDecimalPlaces": "5", + "instrument": map[string]interface{}{ + "code": "CRYPTO:BTCUSD/NOV22", + "name": "NOV 2022 BTC vs USD future", + "future": map[string]interface{}{ + "settlementAsset": "fUSDC", + "quoteName": "BTCUSD", + "dataSourceSpecForSettlementData": map[string]interface{}{ + "external": map[string]interface{}{ + "oracle": map[string]interface{}{ + "signers": []interface{}{ + map[string]interface{}{ + "ethAddress": map[string]interface{}{ + "address": "0xfCEAdAFab14d46e20144F48824d0C09B1a03F2BC", + }, + }, + }, + "filters": []interface{}{ + map[string]interface{}{ + "key": map[string]interface{}{ + "name": "trading.settled", + "type": "TYPE_INTEGER", + }, + "conditions": []interface{}{ + map[string]interface{}{ + "operator": "OPERATOR_GREATER_THAN", + "value": "0", + }, + }, + }, + }, + }, + }, + }, + "dataSourceSpecForTradingTermination": map[string]interface{}{ + "external": map[string]interface{}{ + "oracle": map[string]interface{}{ + "signers": []interface{}{ + map[string]interface{}{ + "ethAddress": map[string]interface{}{ + "address": "0xfCEAdAFab14d46e20144F48824d0C09B1a03F2BC", + }, + }, + }, + "filters": []interface{}{ + map[string]interface{}{ + "key": map[string]interface{}{ + "name": "trading.terminated", + "type": "TYPE_BOOLEAN", + }, + }, + }, + }, + }, + }, + "dataSourceSpecBinding": map[string]interface{}{ + "settlementDataProperty": "trading.settled", + "tradingTerminationProperty": "trading.terminated", + }, + }, + }, + "simple": map[string]interface{}{ + "factorLong": "0.15", + "factorShort": "0.25", + "maxMoveUp": "10", + "minMoveDown": "-5", + "probabilityOfTrading": "0.1", + }, + }, + }, + }, } - return users, nil -} -// SignSubmitTx will sign and then submit a transaction -func (w *walletWrapper) SignSubmitTx(userToken string, command string) error { - err := w.SendCommand([]byte(command), userToken) + _, err := w.sendTransaction(user, "proposalSubmission", newMarket) return err } -// SendCommand will send a signed command to the wallet -func (w *walletWrapper) SendCommand(submission []byte, token string) error { - postBuffer := bytes.NewBuffer(submission) - - URL := "http://" + w.walletURL + "/api/v1/command" - - client := &http.Client{} - req, err := http.NewRequest(http.MethodPost, URL, postBuffer) - if err != nil { - return err - } - - bearer := "Bearer " + token - req.Header.Add("Authorization", bearer) +// GetFirstKey gives us the first public key linked to our wallet +func (w walletWrapper) GetFirstKey(longLivenToken string) (string, error) { + post, _ := json.Marshal(map[string]interface{}{ + "id": "1", + "jsonrpc": "2.0", + "method": "client.list_keys", + "params": map[string]string{ + "token": longLivenToken, + }, + }) + body, err := w.sendRequest(post) - resp, err := client.Do(req) + var values ListKeysResult = ListKeysResult{} + err = json.Unmarshal(body, &values) if err != nil { - return err + fmt.Println(err) } - defer resp.Body.Close() - body, err := io.ReadAll(resp.Body) - if err != nil { - return err - } - sb := string(body) - if strings.Contains(sb, "error") { - log.Println(sb) - return fmt.Errorf(sb) + if len(values.Result.Keys) > 0 { + return values.Result.Keys[0].PublicKey, nil } - return nil + return "", nil } // SendBatchOrders sends a set of new order commands to the wallet @@ -264,13 +204,6 @@ func (w *walletWrapper) SendBatchOrders(user UserDetails, cancels []*commandspb.OrderCancellation, amends []*commandspb.OrderAmendment, orders []*commandspb.OrderSubmission) error { - m := jsonpb.Marshaler{} - - // Create the request - submitTxReq := &walletpb.SubmitTransactionRequest{ - PubKey: user.pubKey, - Propagate: true, - } command := &walletpb.SubmitTransactionRequest_BatchMarketInstructions{ BatchMarketInstructions: &commandspb.BatchMarketInstructions{}, @@ -279,131 +212,14 @@ func (w *walletWrapper) SendBatchOrders(user UserDetails, command.BatchMarketInstructions.Amendments = amends command.BatchMarketInstructions.Submissions = orders - submitTxReq.Command = command - - cmd, err := m.MarshalToString(submitTxReq) - if err != nil { - return err - } - return w.SignSubmitTx(user.token, cmd) + _, err := w.sendTransaction(user, "orderSubmission", command) + return err } // SendOrder sends a new order command to the wallet func (w *walletWrapper) SendOrder(user UserDetails, os *commandspb.OrderSubmission) error { - m := jsonpb.Marshaler{} - - submitTxReq := &walletpb.SubmitTransactionRequest{ - PubKey: user.pubKey, - Propagate: true, - Command: &walletpb.SubmitTransactionRequest_OrderSubmission{ - OrderSubmission: os, - }, - } - - cmd, err := m.MarshalToString(submitTxReq) - if err != nil { - return err - } - return w.SignSubmitTx(user.token, cmd) -} - -// SendNewMarketProposal will build and send a new market proposal to the wallet -func (w *walletWrapper) SendNewMarketProposal(marketIndex int, user UserDetails) error { - - m := jsonpb.Marshaler{} - - ref := fmt.Sprintf("PerfBotProposalRef%d", marketIndex) - desc := fmt.Sprintf("PerfBotDesc%d", marketIndex) - title := fmt.Sprintf("PerfBotProposalTitle%d", marketIndex) - - submitTxReq := &walletpb.SubmitTransactionRequest{ - PubKey: user.pubKey, - Propagate: true, - Command: &walletpb.SubmitTransactionRequest_ProposalSubmission{ - ProposalSubmission: &commandspb.ProposalSubmission{ - Reference: ref, - Rationale: &proto.ProposalRationale{ - Description: desc, - Title: title, - }, - Terms: &proto.ProposalTerms{ - ClosingTimestamp: w.SecondsFromNowInSecs(15), - EnactmentTimestamp: w.SecondsFromNowInSecs(30), - Change: &proto.ProposalTerms_NewMarket{ - NewMarket: &proto.NewMarket{ - Changes: &proto.NewMarketConfiguration{ - DecimalPlaces: 5, - Instrument: &proto.InstrumentConfiguration{ - Code: "CRYPTO:BTCUSD/NOV22", - Name: "NOV 2022 BTC vs USD future", - Product: &proto.InstrumentConfiguration_Future{ - Future: &proto.FutureProduct{ - SettlementAsset: "fUSDC", - QuoteName: "BTCUSD", - DataSourceSpecBinding: &proto.DataSourceSpecToFutureBinding{ - SettlementDataProperty: "trading.settled", - TradingTerminationProperty: "trading.termination", - }, - DataSourceSpecForTradingTermination: proto.NewDataSourceDefinition( - proto.DataSourceDefinitionTypeExt, - ).SetOracleConfig(&proto.DataSourceSpecConfiguration{ - Signers: []*v1.Signer{ - { - Signer: &v1.Signer_PubKey{ - PubKey: &v1.PubKey{Key: "0xDEADBEEF"}, - }, - }, - }, - Filters: []*v1.Filter{ - {Key: &v1.PropertyKey{ - Name: "trading.termination", - Type: v1.PropertyKey_TYPE_BOOLEAN, - }}, - }, - }), - DataSourceSpecForSettlementData: proto.NewDataSourceDefinition( - proto.DataSourceDefinitionTypeExt, - ).SetOracleConfig(&proto.DataSourceSpecConfiguration{ - Signers: []*v1.Signer{ - { - Signer: &v1.Signer_PubKey{ - PubKey: &v1.PubKey{Key: "0xDEADBEEF"}, - }, - }, - }, - Filters: []*v1.Filter{ - {Key: &v1.PropertyKey{ - Name: "trading.settled", - Type: v1.PropertyKey_TYPE_INTEGER, - }}, - }, - }), - }, - }, - }, - RiskParameters: &proto.NewMarketConfiguration_Simple{ - Simple: &proto.SimpleModelParams{ - FactorLong: 0.15, - FactorShort: 0.25, - MaxMoveUp: 10, - MinMoveDown: -5, - ProbabilityOfTrading: 0.1, - }, - }, - }, - }, - }, - }, - }, - }, - } - - cmd, err := m.MarshalToString(submitTxReq) - if err != nil { - return err - } - - return w.SignSubmitTx(user.token, cmd) + _, err := w.sendTransaction(user, "orderSubmission", os) + return err } func (w *walletWrapper) SendLiquidityProvision(user UserDetails, marketID string, orderCount int) error { @@ -433,20 +249,9 @@ func (w *walletWrapper) SendLiquidityProvision(user UserDetails, marketID string lp.Buys = buys lp.Sells = sells - m := jsonpb.Marshaler{} + _, err := w.sendTransaction(user, "liquidityProvisionSubmission", lp) - submitTxReq := &walletpb.SubmitTransactionRequest{ - PubKey: user.pubKey, - Propagate: true, - Command: &walletpb.SubmitTransactionRequest_LiquidityProvisionSubmission{ - LiquidityProvisionSubmission: &lp, - }, - } - cmd, err := m.MarshalToString(submitTxReq) - if err != nil { - return err - } - return w.SignSubmitTx(user.token, cmd) + return err } // SendCancelAll will build and send a cancel all command to the wallet @@ -455,36 +260,20 @@ func (w *walletWrapper) SendCancelAll(user UserDetails, marketID string) error { MarketId: marketID, } - m := jsonpb.Marshaler{} - - submitTxReq := &walletpb.SubmitTransactionRequest{ - PubKey: user.pubKey, - Propagate: true, - Command: &walletpb.SubmitTransactionRequest_OrderCancellation{ - OrderCancellation: &cancel, - }, - } - cmd, err := m.MarshalToString(submitTxReq) + _, err := w.sendTransaction(user, "orderCancellation", cancel) if err != nil { return err } - return w.SignSubmitTx(user.token, cmd) + return err } // SendVote will build and send a vote command to the wallet -func (w walletWrapper) SendVote(user UserDetails, vote *commandspb.VoteSubmission) error { - m := jsonpb.Marshaler{} - - submitTxReq := &walletpb.SubmitTransactionRequest{ - PubKey: user.pubKey, - Propagate: true, - Command: &walletpb.SubmitTransactionRequest_VoteSubmission{ - VoteSubmission: vote, - }, +func (w walletWrapper) SendVote(user UserDetails, propId string) error { + vote := commandspb.VoteSubmission{ + ProposalId: propId, + Value: proto.Vote_VALUE_YES, } - cmd, err := m.MarshalToString(submitTxReq) - if err != nil { - return err - } - return w.SignSubmitTx(user.token, cmd) + + _, err := w.sendTransaction(user, "voteSubmission", vote) + return err } diff --git a/snapshotdb/snapshotdb.go b/snapshotdb/snapshotdb.go index d68fc45..a5e8b3e 100644 --- a/snapshotdb/snapshotdb.go +++ b/snapshotdb/snapshotdb.go @@ -151,7 +151,7 @@ func Run(dbpath string, versionsOnly bool, outputPath string, heightToOutput int return fmt.Errorf("failed to open database located at %s : %w", dbpath, err) } - tree, err := iavl.NewMutableTree(db, 0) + tree, err := iavl.NewMutableTree(db, 0, false) if err != nil { return err } diff --git a/withdraw/pull_withdraw.go b/withdraw/pull_withdraw.go index 002cdff..0e8fa18 100644 --- a/withdraw/pull_withdraw.go +++ b/withdraw/pull_withdraw.go @@ -106,7 +106,6 @@ func getBundle(clt api.TradingDataServiceClient, w *vega.Withdrawal) (*withdrawa return &withdrawalBundle{ AssetSource: resp.AssetSource, Amount: resp.Amount, - Expiry: resp.Expiry, Nonce: resp.Nonce, Signatures: resp.Signatures, TargetAddress: w.GetExt().GetErc20().GetReceiverAddress(), From b5015c69ea0663d56b62e4a29ab8cc5787fd52b1 Mon Sep 17 00:00:00 2001 From: Peter Barrow Date: Mon, 9 Jan 2023 11:52:27 +0000 Subject: [PATCH 2/6] fix: Added references --- perftest/perftest.go | 12 ++++++++---- perftest/wallet.go | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/perftest/perftest.go b/perftest/perftest.go index 691e792..c6dc7fb 100644 --- a/perftest/perftest.go +++ b/perftest/perftest.go @@ -383,7 +383,8 @@ func (p *perfLoadTesting) sendTradingLoad(marketIDs []string, users, ops, runTim Size: 3, Side: proto.Side_SIDE_BUY, Type: proto.Order_TYPE_MARKET, - TimeInForce: proto.Order_TIME_IN_FORCE_IOC}) + TimeInForce: proto.Order_TIME_IN_FORCE_IOC, + Reference: "MarketBuy"}) if err != nil { log.Println("Failed to send market buy order", err) } @@ -392,7 +393,8 @@ func (p *perfLoadTesting) sendTradingLoad(marketIDs []string, users, ops, runTim Size: 3, Side: proto.Side_SIDE_SELL, Type: proto.Order_TYPE_MARKET, - TimeInForce: proto.Order_TIME_IN_FORCE_IOC}) + TimeInForce: proto.Order_TIME_IN_FORCE_IOC, + Reference: "MarketSell"}) if err != nil { log.Println("Failed to send market sell order", err) } @@ -407,7 +409,8 @@ func (p *perfLoadTesting) sendTradingLoad(marketIDs []string, users, ops, runTim Size: 1, Side: proto.Side_SIDE_SELL, Type: proto.Order_TYPE_LIMIT, - TimeInForce: proto.Order_TIME_IN_FORCE_GTC}) + TimeInForce: proto.Order_TIME_IN_FORCE_GTC, + Reference: "NonTouchingLimitSell"}) if err != nil { log.Println("Failed to send non crossing random limit sell order", err) } @@ -418,7 +421,8 @@ func (p *perfLoadTesting) sendTradingLoad(marketIDs []string, users, ops, runTim Size: 1, Side: proto.Side_SIDE_BUY, Type: proto.Order_TYPE_LIMIT, - TimeInForce: proto.Order_TIME_IN_FORCE_GTC}) + TimeInForce: proto.Order_TIME_IN_FORCE_GTC, + Reference: "NonTouchingLimitBuy"}) if err != nil { log.Println("Failed to send non crossing random limit buy order", err) } diff --git a/perftest/wallet.go b/perftest/wallet.go index d02b338..7279d22 100644 --- a/perftest/wallet.go +++ b/perftest/wallet.go @@ -78,7 +78,7 @@ func (w walletWrapper) sendRequest(request []byte) ([]byte, error) { defer resp.Body.Close() reply, err := io.ReadAll(resp.Body) - fmt.Println(string(reply)) + if err != nil { return nil, err } From d75384e5431e7abc324e9fc395604ff372d166e0 Mon Sep 17 00:00:00 2001 From: Peter Barrow Date: Tue, 10 Jan 2023 11:52:03 +0000 Subject: [PATCH 3/6] fix: Fail if error code returned --- perftest/wallet.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/perftest/wallet.go b/perftest/wallet.go index 7279d22..fda2149 100644 --- a/perftest/wallet.go +++ b/perftest/wallet.go @@ -77,6 +77,10 @@ func (w walletWrapper) sendRequest(request []byte) ([]byte, error) { resp, err := client.Do(req) defer resp.Body.Close() + if resp.StatusCode != 200 { + return nil, fmt.Errorf(resp.Status) + } + reply, err := io.ReadAll(resp.Body) if err != nil { From f3a112c0d6b43aaf92f4317c330017be017d3004 Mon Sep 17 00:00:00 2001 From: Peter Barrow Date: Tue, 10 Jan 2023 13:19:53 +0000 Subject: [PATCH 4/6] fix: Linter --- perftest/wallet.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/perftest/wallet.go b/perftest/wallet.go index fda2149..b4517ce 100644 --- a/perftest/wallet.go +++ b/perftest/wallet.go @@ -31,17 +31,17 @@ func (w walletWrapper) SecondsFromNowInSecs(seconds int64) int64 { return time.Now().Unix() + seconds } -type Keys struct { - Keys []Key +type keys struct { + Keys []key } -type Key struct { +type key struct { Name string PublicKey string } -type ListKeysResult struct { +type listKeysResult struct { Jsonrpc string - Result Keys - Id string + Result keys + ID string } func (w walletWrapper) sendTransaction(user UserDetails, subType string, subData interface{}) ([]byte, error) { @@ -75,6 +75,9 @@ func (w walletWrapper) sendRequest(request []byte) ([]byte, error) { client := &http.Client{} resp, err := client.Do(req) + if err != nil { + return nil, err + } defer resp.Body.Close() if resp.StatusCode != 200 { @@ -191,7 +194,7 @@ func (w walletWrapper) GetFirstKey(longLivenToken string) (string, error) { }) body, err := w.sendRequest(post) - var values ListKeysResult = ListKeysResult{} + var values listKeysResult = listKeysResult{} err = json.Unmarshal(body, &values) if err != nil { fmt.Println(err) @@ -272,9 +275,9 @@ func (w *walletWrapper) SendCancelAll(user UserDetails, marketID string) error { } // SendVote will build and send a vote command to the wallet -func (w walletWrapper) SendVote(user UserDetails, propId string) error { +func (w walletWrapper) SendVote(user UserDetails, propID string) error { vote := commandspb.VoteSubmission{ - ProposalId: propId, + ProposalId: propID, Value: proto.Vote_VALUE_YES, } From 2858ac6aac638f366737562994ba154bbe41706a Mon Sep 17 00:00:00 2001 From: Peter Barrow Date: Tue, 10 Jan 2023 13:54:21 +0000 Subject: [PATCH 5/6] fix: Updated protobuf import --- checkpoint/parse.go | 2 +- checkpoint/type.go | 4 ++-- eventpersister/eventpersister.go | 2 +- eventsource/eventsource.go | 2 +- eventsource/socketclient.go | 2 +- go.mod | 2 +- perftest/wallet.go | 6 +++--- pullvotes/main.go | 2 +- stream/stream.go | 2 +- 9 files changed, 12 insertions(+), 12 deletions(-) diff --git a/checkpoint/parse.go b/checkpoint/parse.go index 0cfed90..fea8b26 100644 --- a/checkpoint/parse.go +++ b/checkpoint/parse.go @@ -10,7 +10,7 @@ import ( checkpoint "code.vegaprotocol.io/vega/protos/vega/checkpoint/v1" events "code.vegaprotocol.io/vega/protos/vega/events/v1" - "github.com/golang/protobuf/proto" + "google.golang.org/protobuf/proto" ) var ( diff --git a/checkpoint/type.go b/checkpoint/type.go index 4e7f32e..788ac7c 100644 --- a/checkpoint/type.go +++ b/checkpoint/type.go @@ -11,9 +11,9 @@ import ( checkpoint "code.vegaprotocol.io/vega/protos/vega/checkpoint/v1" events "code.vegaprotocol.io/vega/protos/vega/events/v1" - "github.com/golang/protobuf/jsonpb" - "github.com/golang/protobuf/proto" + "github.com/gogo/protobuf/jsonpb" "golang.org/x/crypto/sha3" + "google.golang.org/protobuf/proto" ) type all struct { diff --git a/eventpersister/eventpersister.go b/eventpersister/eventpersister.go index aa331a7..3d14881 100644 --- a/eventpersister/eventpersister.go +++ b/eventpersister/eventpersister.go @@ -12,7 +12,7 @@ import ( eventspb "code.vegaprotocol.io/vega/protos/vega/events/v1" "code.vegaprotocol.io/vegatools/stream" - "github.com/golang/protobuf/proto" + "google.golang.org/protobuf/proto" ) // Run is the main function of `eventpersister` package diff --git a/eventsource/eventsource.go b/eventsource/eventsource.go index e776451..6f82c76 100644 --- a/eventsource/eventsource.go +++ b/eventsource/eventsource.go @@ -9,7 +9,7 @@ import ( eventspb "code.vegaprotocol.io/vega/protos/vega/events/v1" - "github.com/golang/protobuf/proto" + "google.golang.org/protobuf/proto" ) func sendAllEvents(sendEvents func([]*eventspb.BusEvent) error, evtFile *os.File, diff --git a/eventsource/socketclient.go b/eventsource/socketclient.go index fd904fe..03b7832 100644 --- a/eventsource/socketclient.go +++ b/eventsource/socketclient.go @@ -5,10 +5,10 @@ import ( eventspb "code.vegaprotocol.io/vega/protos/vega/events/v1" - "github.com/golang/protobuf/proto" mangos "go.nanomsg.org/mangos/v3" "go.nanomsg.org/mangos/v3/protocol" "go.nanomsg.org/mangos/v3/protocol/push" + "google.golang.org/protobuf/proto" // Required for socket client _ "go.nanomsg.org/mangos/v3/transport/inproc" diff --git a/go.mod b/go.mod index 6aeccff..31cd219 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,6 @@ require ( github.com/ethereum/go-ethereum v1.10.21 github.com/gdamore/tcell/v2 v2.5.2 github.com/gogo/protobuf v1.3.2 - github.com/golang/protobuf v1.5.2 github.com/shopspring/decimal v1.3.1 github.com/spf13/cobra v1.6.0 github.com/stretchr/testify v1.8.0 @@ -38,6 +37,7 @@ require ( github.com/gdamore/encoding v1.0.0 // indirect github.com/go-ole/go-ole v1.2.6 // indirect github.com/go-stack/stack v1.8.0 // indirect + github.com/golang/protobuf v1.5.2 // indirect github.com/golang/snappy v0.0.4 // indirect github.com/google/btree v1.0.0 // indirect github.com/google/uuid v1.3.0 // indirect diff --git a/perftest/wallet.go b/perftest/wallet.go index b4517ce..968549a 100644 --- a/perftest/wallet.go +++ b/perftest/wallet.go @@ -256,7 +256,7 @@ func (w *walletWrapper) SendLiquidityProvision(user UserDetails, marketID string lp.Buys = buys lp.Sells = sells - _, err := w.sendTransaction(user, "liquidityProvisionSubmission", lp) + _, err := w.sendTransaction(user, "liquidityProvisionSubmission", &lp) return err } @@ -267,7 +267,7 @@ func (w *walletWrapper) SendCancelAll(user UserDetails, marketID string) error { MarketId: marketID, } - _, err := w.sendTransaction(user, "orderCancellation", cancel) + _, err := w.sendTransaction(user, "orderCancellation", &cancel) if err != nil { return err } @@ -281,6 +281,6 @@ func (w walletWrapper) SendVote(user UserDetails, propID string) error { Value: proto.Vote_VALUE_YES, } - _, err := w.sendTransaction(user, "voteSubmission", vote) + _, err := w.sendTransaction(user, "voteSubmission", &vote) return err } diff --git a/pullvotes/main.go b/pullvotes/main.go index cd64818..82839a1 100644 --- a/pullvotes/main.go +++ b/pullvotes/main.go @@ -8,7 +8,7 @@ import ( "path" commandspb "code.vegaprotocol.io/vega/protos/vega/commands/v1" - "github.com/golang/protobuf/proto" + "google.golang.org/protobuf/proto" ) var ( diff --git a/stream/stream.go b/stream/stream.go index b243228..f97c013 100644 --- a/stream/stream.go +++ b/stream/stream.go @@ -15,7 +15,7 @@ import ( api "code.vegaprotocol.io/vega/protos/vega/api/v1" eventspb "code.vegaprotocol.io/vega/protos/vega/events/v1" - "github.com/golang/protobuf/jsonpb" + "github.com/gogo/protobuf/jsonpb" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" ) From 7bfd1ad7e8c3523dea224de8b5cae7e3a08aa7a6 Mon Sep 17 00:00:00 2001 From: Peter Barrow Date: Tue, 10 Jan 2023 14:52:03 +0000 Subject: [PATCH 6/6] fix: Changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 75f1322..96fd5f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -63,6 +63,7 @@ - [237](https://github.com/vegaprotocol/vegatools/issues/237) - Rename of Oracles to Data Sources - [240](https://github.com/vegaprotocol/vegatools/issues/240) - Add support for filling price levels before perf testing begins - [247](https://github.com/vegaprotocol/vegatools/issues/247) - Made ganache value optional for perftool +- [251](https://github.com/vegaprotocol/vegatools/issues/251) - Changed code to use wallet V2 and updated protobuf mod to correct version ### 🐛 Fixes - [78](https://github.com/vegaprotocol/vegatools/pull/78) - Fix build with missing dependency