Skip to content
Merged
Changes from 4 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
73 changes: 56 additions & 17 deletions shared/pingpong/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -667,28 +667,37 @@ func (pps *WorkerState) prepareApps(client *libgoal.Client) (err error) {
}

// generate new apps
// cycle through accts and create apps until the desired quantity is reached
var txgroup []transactions.Transaction
var senders []string
for addr, acct := range pps.accounts {
if len(pps.cinfo.AppParams) >= int(pps.cfg.NumApp) {
break
}
var tx transactions.Transaction
tx, err = pps.newApp(addr, client)
if err != nil {
return
}
acct.addBalance(-int64(pps.cfg.MaxFee))
txgroup = append(txgroup, tx)
senders = append(senders, addr)
if len(txgroup) == int(pps.cfg.GroupSize) {
pps.schedule(len(txgroup))
err = pps.sendAsGroup(txgroup, client, senders)
appsPerAddr := make(map[string]int)
totalAppCnt := 0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This loses the possibility that accounts with apps already exist. One of the big changes in my recent pingpong hacking was that we can now have stable accounts and apps and assets that exist over multiple invocations of pingpong. Maybe existingAppCnt := len(pps.cinfo.AppParams) and then loop while newAppCnt + existingAppCnt < pps.cfg.NumApp

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah got it. That explains a few things I was confused about, like why some failing pingpong invocations worked on subsequent runs. Your suggestion makes sense.

for totalAppCnt < int(pps.cfg.NumApp) {
for addr, acct := range pps.accounts {
if totalAppCnt >= int(pps.cfg.NumApp) {
break
}

var tx transactions.Transaction
tx, err = pps.newApp(addr, client)
if err != nil {
return
}
txgroup = txgroup[:0]
senders = senders[:0]
acct.addBalance(-int64(pps.cfg.MaxFee))
Comment thread
algoidurovic marked this conversation as resolved.
txgroup = append(txgroup, tx)
senders = append(senders, addr)
if len(txgroup) == int(pps.cfg.GroupSize) {
pps.schedule(len(txgroup))
err = pps.sendAsGroup(txgroup, client, senders)
if err != nil {
return
}
txgroup = txgroup[:0]
senders = senders[:0]
}

appsPerAddr[addr]++
totalAppCnt++
}
}
if len(txgroup) > 0 {
Expand All @@ -701,6 +710,36 @@ func (pps *WorkerState) prepareApps(client *libgoal.Client) (err error) {
senders = senders[:0]
}

// update pps.cinfo.AppParams to ensure newly created apps are present
for addr := range pps.accounts {
if appsPerAddr[addr] == 0 {
continue
}

var ai v1.Account
for {
ai, err = client.AccountInformation(addr)
if err != nil {
fmt.Printf("Warning, cannot lookup source account")
return
}
if len(ai.AppParams) >= appsPerAddr[addr] {
break
}
waitForNextRoundOrSleep(client, 500*time.Millisecond)
// TODO : if we fail here for too long, we should re-create new accounts, etc.
}
ai, err = client.AccountInformation(addr)
if err != nil {
return
}

for appID, ap := range ai.AppParams {
pps.cinfo.OptIns[appID] = uniqueAppend(pps.cinfo.OptIns[appID], addr)
pps.cinfo.AppParams[appID] = ap
}
}

// opt-in more accounts to apps
acctPerApp := (pps.cfg.NumAppOptIn * pps.cfg.NumPartAccounts) / pps.cfg.NumApp
for appid := range pps.cinfo.AppParams {
Expand Down