summaryrefslogtreecommitdiff
path: root/cmd/netgoal/generate.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/netgoal/generate.go')
-rw-r--r--cmd/netgoal/generate.go61
1 files changed, 43 insertions, 18 deletions
diff --git a/cmd/netgoal/generate.go b/cmd/netgoal/generate.go
index 015fb4207..7cd417621 100644
--- a/cmd/netgoal/generate.go
+++ b/cmd/netgoal/generate.go
@@ -50,6 +50,7 @@ var roundTxnCount uint64
var accountsCount uint64
var assetsCount uint64
var applicationCount uint64
+var balRange []string
func init() {
rootCmd.AddCommand(generateCmd)
@@ -73,6 +74,7 @@ func init() {
generateCmd.Flags().Uint64VarP(&accountsCount, "naccounts", "", 31, "Account count")
generateCmd.Flags().Uint64VarP(&assetsCount, "nassets", "", 5, "Asset count")
generateCmd.Flags().Uint64VarP(&applicationCount, "napps", "", 7, "Application Count")
+ generateCmd.Flags().StringArrayVar(&balRange, "bal", []string{}, "Application Count")
longParts := make([]string, len(generateTemplateLines)+1)
longParts[0] = generateCmd.Long
@@ -174,8 +176,10 @@ template modes for -t:`,
if sourceWallet == "" {
reportErrorf("must specify source wallet name with -wname.")
}
-
- err = generateAccountsLoadingFileTemplate(outputFilename, sourceWallet, rounds, roundTxnCount, accountsCount, assetsCount, applicationCount)
+ if len(balRange) < 2 {
+ reportErrorf("must specify account balance range with --bal.")
+ }
+ err = generateAccountsLoadingFileTemplate(outputFilename, sourceWallet, rounds, roundTxnCount, accountsCount, assetsCount, applicationCount, balRange)
default:
reportInfoln("Please specify a valid template name.\nSupported templates are:")
for _, line := range generateTemplateLines {
@@ -281,7 +285,7 @@ func generateNetworkGoalTemplate(templateFilename string, wallets, relays, nodes
}
if npnHosts > 0 {
- for walletIndex < wallets {
+ for walletIndex < npnHosts {
for nodei, node := range template.Nodes {
if node.Name[0:4] != "nonP" {
continue
@@ -292,11 +296,11 @@ func generateNetworkGoalTemplate(templateFilename string, wallets, relays, nodes
}
template.Nodes[nodei].Wallets = append(template.Nodes[nodei].Wallets, wallet)
walletIndex++
- if walletIndex >= wallets {
+ if walletIndex >= npnHosts {
break
}
}
- if walletIndex >= wallets {
+ if walletIndex >= npnHosts {
break
}
}
@@ -395,9 +399,10 @@ func generateNetworkTemplate(templateFilename string, wallets, relays, nodeHosts
}
}
+ // one wallet per NPN host to concentrate stake
if npnHosts > 0 {
walletIndex := 0
- for walletIndex < wallets {
+ for walletIndex < npnHosts {
for hosti := range network.Hosts {
for nodei, node := range network.Hosts[hosti].Nodes {
if node.Name[0:4] != "nonP" {
@@ -409,11 +414,11 @@ func generateNetworkTemplate(templateFilename string, wallets, relays, nodeHosts
}
network.Hosts[hosti].Nodes[nodei].Wallets = append(network.Hosts[hosti].Nodes[nodei].Wallets, wallet)
walletIndex++
- if walletIndex >= wallets {
+ if walletIndex >= npnHosts {
break
}
}
- if walletIndex >= wallets {
+ if walletIndex >= npnHosts {
break
}
}
@@ -461,19 +466,29 @@ func saveGoalTemplateToDisk(template netdeploy.NetworkTemplate, filename string)
}
func generateWalletGenesisData(wallets, npnHosts int) gen.GenesisData {
+ ratZero := big.NewRat(int64(0), int64(1))
+ ratHundred := big.NewRat(int64(100), int64(1))
data := gen.DefaultGenesis
+ totalWallets := wallets + npnHosts
+ data.Wallets = make([]gen.WalletData, totalWallets)
+ participatingNodeStake := big.NewRat(int64(100), int64(wallets))
+ nonParticipatingNodeStake := ratZero
if npnHosts > 0 {
- wallets = 2 * wallets
+ // split participating an non participating stake evenly
+ participatingNodeStake = big.NewRat(int64(50), int64(wallets))
+ nonParticipatingNodeStake = big.NewRat(int64(50), int64(npnHosts))
}
- data.Wallets = make([]gen.WalletData, wallets)
- stake := big.NewRat(int64(100), int64(wallets))
-
- ratZero := big.NewRat(int64(0), int64(1))
- ratHundred := big.NewRat(int64(100), int64(1))
+ stake := ratZero
stakeSum := new(big.Rat).Set(ratZero)
- for i := 0; i < wallets; i++ {
- if i == (wallets - 1) {
+ for i := 0; i < totalWallets; i++ {
+
+ if i < wallets {
+ stake = participatingNodeStake
+ } else {
+ stake = nonParticipatingNodeStake
+ }
+ if i == (totalWallets - 1) {
// use the last wallet to workaround roundoff and get back to 1.0
stake = stake.Sub(new(big.Rat).Set(ratHundred), stakeSum)
}
@@ -482,7 +497,7 @@ func generateWalletGenesisData(wallets, npnHosts int) gen.GenesisData {
Name: "Wallet" + strconv.Itoa(i+1), // Wallet names are 1-based for this template
Stake: floatStake,
}
- if (i < (wallets / 2)) || (npnHosts == 0) {
+ if i < wallets {
w.Online = true
}
stakeSum = stakeSum.Add(stakeSum, stake)
@@ -507,7 +522,16 @@ func saveGenesisDataToDisk(genesisData gen.GenesisData, filename string) error {
return err
}
-func generateAccountsLoadingFileTemplate(templateFilename, sourceWallet string, rounds, roundTxnCount, accountsCount, assetsCount, applicationCount uint64) error {
+func generateAccountsLoadingFileTemplate(templateFilename, sourceWallet string, rounds, roundTxnCount, accountsCount, assetsCount, applicationCount uint64, balRange []string) error {
+
+ min, err := strconv.ParseInt(balRange[0], 0, 64)
+ if err != nil {
+ return err
+ }
+ max, err := strconv.ParseInt(balRange[1], 0, 64)
+ if err != nil {
+ return err
+ }
var data = remote.BootstrappedNetwork{
NumRounds: rounds,
@@ -516,6 +540,7 @@ func generateAccountsLoadingFileTemplate(templateFilename, sourceWallet string,
GeneratedAssetsCount: assetsCount,
GeneratedApplicationCount: applicationCount,
SourceWalletName: sourceWallet,
+ BalanceRange: []int64{min, max},
}
return saveLoadingFileDataToDisk(data, templateFilename)
}