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

Skip initialisation #317

Merged
merged 2 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions cmd/perftest.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func init() {
perfTestCmd.Flags().BoolVarP(&opts.MoveMid, "movemidprice", "M", false, "allow the mid price we place orders around to move randomly")
perfTestCmd.Flags().BoolVarP(&opts.FillPriceLevels, "fillpricelevel", "F", false, "place an order at every available price level")
perfTestCmd.Flags().BoolVarP(&opts.InitialiseOnly, "initialiseonly", "i", false, "initialise everything and then exit")
perfTestCmd.Flags().BoolVarP(&opts.DoNotInitialise, "donotinitialise", "I", false, "skip the initialise steps")
perfTestCmd.Flags().BoolVarP(&opts.UseLPsForOrders, "uselpsfororders", "U", true, "allow lp users to place orders during setup")
perfTestCmd.MarkFlagRequired("address")
perfTestCmd.MarkFlagRequired("wallet")
Expand Down
29 changes: 28 additions & 1 deletion perftest/perftest.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type Opts struct {
StartingMidPrice int64
FillPriceLevels bool
InitialiseOnly bool
DoNotInitialise bool
UseLPsForOrders bool
}

Expand Down Expand Up @@ -106,6 +107,10 @@ func (p *perfLoadTesting) LoadUsers(opts Opts) error {
}

func (p *perfLoadTesting) depositTokens(assets map[string]string, opts Opts) error {
if opts.DoNotInitialise {
return nil
}

if len(opts.GanacheURL) > 0 {
for index, user := range p.users {
if index >= opts.Voters {
Expand Down Expand Up @@ -240,6 +245,18 @@ func (p *perfLoadTesting) checkNetworkLimits(opts Opts) error {

func (p *perfLoadTesting) proposeAndEnactMarket(opts Opts) ([]string, error) {
markets := p.dataNode.getMarkets()

if opts.DoNotInitialise {
marketIds := []string{}
if len(markets) >= opts.MarketCount {
for _, market := range markets {
marketIds = append(marketIds, market.Id)
}
return marketIds, nil
}
return nil, fmt.Errorf("failed to get open market")
}

if len(markets) == 0 {
for i := 0; i < opts.MarketCount; i++ {
err := p.wallet.NewMarket(i, p.users[0])
Expand Down Expand Up @@ -310,6 +327,9 @@ func (p *perfLoadTesting) proposeAndEnactMarket(opts Opts) ([]string, error) {
}

func (p *perfLoadTesting) seedPeggedOrders(marketIDs []string, opts Opts) error {
if opts.DoNotInitialise {
return nil
}
// Loop through every market
for _, marketID := range marketIDs {
for i := 0; i < opts.PeggedOrders; i++ {
Expand Down Expand Up @@ -360,6 +380,9 @@ func (p *perfLoadTesting) seedPeggedOrders(marketIDs []string, opts Opts) error
}

func (p *perfLoadTesting) seedPriceLevels(marketIDs []string, opts Opts) error {
if opts.DoNotInitialise {
return nil
}
for _, marketID := range marketIDs {
// Buys first
for i := opts.StartingMidPrice - 1; i > opts.StartingMidPrice-int64(opts.PriceLevels); i-- {
Expand Down Expand Up @@ -409,6 +432,9 @@ func (p *perfLoadTesting) seedPriceLevels(marketIDs []string, opts Opts) error {
}

func (p *perfLoadTesting) seedStopOrders(marketIDs []string, opts Opts) error {
if opts.DoNotInitialise {
return nil
}
// We need to go through all markets and all users
for _, marketID := range marketIDs {
order := &commandspb.OrderSubmission{
Expand Down Expand Up @@ -856,13 +882,14 @@ func Run(opts Opts) error {

// If we are only initialising, stop now and return
if opts.InitialiseOnly {
fmt.Print("Depositing tokens and assets...")
// Make one more check that assets are topped up
err = plt.depositTokens(assets, opts)
if err != nil {
fmt.Println("FAILED")
return err
}

fmt.Println("Complete")
fmt.Println("Initialisation complete")
return nil
}
Expand Down
Loading