Skip to content
Merged
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
71 changes: 54 additions & 17 deletions shared/pingpong/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -667,28 +667,39 @@ 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)
var newAppAddrs []string
appsPerAddr := make(map[string]int)
totalAppCnt := len(pps.cinfo.AppParams)
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]
newAppAddrs = append(newAppAddrs, addr)
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)
if err != nil {
return
}
txgroup = txgroup[:0]
senders = senders[:0]
}

appsPerAddr[addr]++
totalAppCnt++
}
}
if len(txgroup) > 0 {
Expand All @@ -701,6 +712,32 @@ 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 newAppAddrs {
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