Skip to content
Merged
41 changes: 26 additions & 15 deletions cmd/netgoal/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,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
Expand All @@ -296,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
}
}
Expand Down Expand Up @@ -399,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" {
Expand All @@ -413,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
}
}
Expand Down Expand Up @@ -465,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
Copy link
Contributor

Choose a reason for hiding this comment

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

Have we always been assuming an even split between participating and non participating nodes? I wonder if that should be configurable. It looks like that would be a new feature though so probably out of scope

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was evenly split before. I will create a ticket to make it configurable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created this ticket to allow configuration of stake ratio: https://github.com/algorand/go-algorand-internal/issues/1566

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)
}
Expand All @@ -486,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)
Expand Down
Loading