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

block-generator: Improve payment algorithm to allow sending many more transactions. #864

Merged
merged 9 commits into from
Feb 9, 2022
43 changes: 29 additions & 14 deletions cmd/block-generator/generator/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,21 @@ const (
assetDestroy TxTypeID = "asset_destroy"

assetTotal = uint64(100000000000000000)
fee = uint64(1000)
)

const (
consensusTimeMilli int64 = 4500
)

// consensus parameters.
var (
minBal uint64
fee uint64
)

func init() {
minBal = config.Consensus[protocol.ConsensusFuture].MinBalance
winder marked this conversation as resolved.
Show resolved Hide resolved
fee = config.Consensus[protocol.ConsensusFuture].MinTxnFee
}

// GenerationConfig defines the tunable parameters for block generation.
type GenerationConfig struct {
Name string `mapstructure:"name"`
Expand Down Expand Up @@ -453,30 +461,37 @@ func (g *generator) generatePaymentTxn(round uint64, intra uint64) (transactions
func (g *generator) generatePaymentTxnInternal(selection TxTypeID, round uint64, intra uint64) (transactions.SignedTxn, transactions.ApplyData, error) {
defer g.recordData(track(selection))

// amounts
amount := uint64(1)

// Select a receiver
var receiveIndex uint64
switch selection {
case paymentTx:
receiveIndex = rand.Uint64() % g.numAccounts
case paymentAcctCreateTx:
// give new accounts extra algos for sending other transactions (optin/optout)
amount = minBal * 100
g.balances = append(g.balances, 0)
g.numAccounts++
receiveIndex = g.numAccounts - 1
receiveIndex = g.numAccounts
// increment at the end in case it needs to be referenced later.
defer func() {
g.numAccounts++
}()
}
total := amount + fee

// Always send from a genesis account.
// Select a sender from genesis account
sendIndex := g.numPayments % g.config.NumGenesisAccounts
// if the genesis account has insufficient balance... start checking others
winder marked this conversation as resolved.
Show resolved Hide resolved
for g.balances[sendIndex] < (total + minBal) {
winder marked this conversation as resolved.
Show resolved Hide resolved
fmt.Printf("\n\ngeneratePaymentTxnInternal(): the sender account does not have enough algos for the transfer. idx %d, payment number %d\n\n", sendIndex, g.numPayments)
os.Exit(1)
}

sender := indexToAccount(sendIndex)
receiver := indexToAccount(receiveIndex)

amount := uint64(1000000)
fee := uint64(1000)
total := amount + fee
if g.balances[sendIndex] < total {
fmt.Printf("\n\nthe sender account does not have enough algos for the transfer. idx %d, payment number %d\n\n", sendIndex, g.numPayments)
os.Exit(1)
}

g.balances[sendIndex] -= total
g.balances[receiveIndex] += amount

Expand Down