Skip to content
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
25 changes: 20 additions & 5 deletions shared/pingpong/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,12 +526,27 @@ func sendAsGroup(txgroup []transactions.Transaction, client libgoal.Client, h []
return
}

func prepareApps(accounts map[string]uint64, client libgoal.Client, cfg PpConfig) (appParams map[uint64]v1.AppParams, optIns map[uint64][]string, err error) {
status, err := client.Status()
if err != nil {
return
var proto *config.ConsensusParams

func getProto(client libgoal.Client) (config.ConsensusParams, error) {
if proto == nil {
var err error
status, err := client.Status()
if err != nil {
return config.ConsensusParams{}, err
}
currentProto, err := client.ConsensusParams(status.LastRound)
if err != nil {
return config.ConsensusParams{}, err
}
proto = &currentProto
}
proto, err := client.ConsensusParams(status.LastRound)

return *proto, nil
}

func prepareApps(accounts map[string]uint64, client libgoal.Client, cfg PpConfig) (appParams map[uint64]v1.AppParams, optIns map[uint64][]string, err error) {
proto, err := getProto(client)
if err != nil {
return
}
Expand Down
29 changes: 26 additions & 3 deletions shared/pingpong/pingpong.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,13 @@ func prepareNewAccounts(client libgoal.Client, cfg PpConfig, wallet []byte, acco
}

// determine the min balance per participant account
func computeAccountMinBalance(cfg PpConfig) (requiredBalance uint64) {
const minActiveAccountBalance uint64 = 100000 // min balance for any active account
func computeAccountMinBalance(client libgoal.Client, cfg PpConfig) (requiredBalance uint64, err error) {
proto, err := getProto(client)
if err != nil {
return
}

minActiveAccountBalance := proto.MinBalance

if cfg.NumApp > 0 {
requiredBalance = (cfg.MinAccountFunds + (cfg.MaxAmt+cfg.MaxFee)*10) * 2
Expand All @@ -141,6 +146,12 @@ func computeAccountMinBalance(cfg PpConfig) (requiredBalance uint64) {
}
if cfg.MaxFee != 0 {
fee = cfg.MaxFee
} else {
// follow the same logic as constructTxn
fee, err = client.SuggestedFee()
Comment thread
tsachiherman marked this conversation as resolved.
if err != nil {
return
}
}
requiredBalance = minActiveAccountBalance

Expand All @@ -152,6 +163,15 @@ func computeAccountMinBalance(cfg PpConfig) (requiredBalance uint64) {
(fee)*uint64(cfg.NumAsset)*uint64(cfg.NumPartAccounts) // asset distributions
requiredBalance += assetCost
}
if cfg.NumApp > 0 {
creationCost := uint64(cfg.NumApp) * proto.AppFlatParamsMinBalance * uint64(proto.MaxAppsCreated)
optInCost := uint64(cfg.NumApp) * proto.AppFlatOptInMinBalance * uint64(proto.MaxAppsOptedIn)
maxGlobalSchema := basics.StateSchema{NumUint: proto.MaxGlobalSchemaEntries, NumByteSlice: proto.MaxGlobalSchemaEntries}
maxLocalSchema := basics.StateSchema{NumUint: proto.MaxLocalSchemaEntries, NumByteSlice: proto.MaxLocalSchemaEntries}
schemaCost := uint64(cfg.NumApp) * (maxGlobalSchema.MinBalance(&proto).Raw*uint64(proto.MaxAppsCreated) +
maxLocalSchema.MinBalance(&proto).Raw*uint64(proto.MaxAppsOptedIn))
requiredBalance += creationCost + optInCost + schemaCost
}
// add cost of transactions
requiredBalance += (cfg.MaxAmt + fee) * 2 * cfg.TxnPerSec * uint64(math.Ceil(cfg.RefreshTime.Seconds()))

Expand All @@ -172,7 +192,10 @@ func fundAccounts(accounts map[string]uint64, client libgoal.Client, cfg PpConfi
// Fee of 0 will make cause the function to use the suggested one by network
fee := uint64(0)

minFund := computeAccountMinBalance(cfg)
minFund, err := computeAccountMinBalance(client, cfg)
if err != nil {
return err
}

fmt.Printf("adjusting account balance to %d\n", minFund)
for addr, balance := range accounts {
Expand Down