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

netgoal: fix large db generation #5445

Merged
merged 6 commits into from
Jun 7, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 10 additions & 2 deletions cmd/netgoal/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ var accountsCount uint64
var assetsCount uint64
var applicationCount uint64
var balRange []string
var lastPartKeyRound uint64
var deterministicKeys bool

func init() {
rootCmd.AddCommand(generateCmd)
Expand All @@ -77,6 +79,8 @@ func init() {
generateCmd.Flags().Uint64VarP(&assetsCount, "nassets", "", 5, "Asset count")
generateCmd.Flags().Uint64VarP(&applicationCount, "napps", "", 7, "Application Count")
generateCmd.Flags().StringArrayVar(&balRange, "bal", []string{}, "Application Count")
generateCmd.Flags().BoolVarP(&deterministicKeys, "deterministic", "", false, "Whether to generate deterministic keys")
generateCmd.Flags().Uint64VarP(&lastPartKeyRound, "last-part-key-round", "", gen.DefaultGenesis.LastPartKeyRound, "LastPartKeyRound in genesis.json")

longParts := make([]string, len(generateTemplateLines)+1)
longParts[0] = generateCmd.Long
Expand Down Expand Up @@ -184,7 +188,7 @@ template modes for -t:`,
if len(balRange) < 2 {
reportErrorf("must specify account balance range with --bal.")
}
err = generateAccountsLoadingFileTemplate(outputFilename, sourceWallet, rounds, roundTxnCount, accountsCount, assetsCount, applicationCount, balRange)
err = generateAccountsLoadingFileTemplate(outputFilename, sourceWallet, rounds, roundTxnCount, accountsCount, assetsCount, applicationCount, balRange, deterministicKeys)
default:
reportInfoln("Please specify a valid template name.\nSupported templates are:")
for _, line := range generateTemplateLines {
Expand Down Expand Up @@ -528,6 +532,9 @@ func generateWalletGenesis(filename string, wallets, npnNodes int) error {
}

func saveGenesisDataToDisk(genesisData gen.GenesisData, filename string) error {
if lastPartKeyRound != 0 {
genesisData.LastPartKeyRound = lastPartKeyRound
}
f, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
if err == nil {
defer f.Close()
Expand All @@ -538,7 +545,7 @@ func saveGenesisDataToDisk(genesisData gen.GenesisData, filename string) error {
return err
}

func generateAccountsLoadingFileTemplate(templateFilename, sourceWallet string, rounds, roundTxnCount, accountsCount, assetsCount, applicationCount uint64, balRange []string) error {
func generateAccountsLoadingFileTemplate(templateFilename, sourceWallet string, rounds, roundTxnCount, accountsCount, assetsCount, applicationCount uint64, balRange []string, deterministicKeys bool) error {

min, err := strconv.ParseInt(balRange[0], 0, 64)
if err != nil {
Expand All @@ -557,6 +564,7 @@ func generateAccountsLoadingFileTemplate(templateFilename, sourceWallet string,
GeneratedApplicationCount: applicationCount,
SourceWalletName: sourceWallet,
BalanceRange: []int64{min, max},
DeterministicKeys: deterministicKeys,
}
return saveLoadingFileDataToDisk(data, templateFilename)
}
Expand Down
3 changes: 2 additions & 1 deletion netdeploy/remote/bootstrappedNetwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"os"
)

//BootstrappedNetwork contains the specs for generating db files
// BootstrappedNetwork contains the specs for generating db files
type BootstrappedNetwork struct {
NumRounds uint64 `json:"numRounds"`
RoundTransactionsCount uint64 `json:"roundTransactionsCount"`
Expand All @@ -30,6 +30,7 @@ type BootstrappedNetwork struct {
GeneratedApplicationCount uint64 `json:"generatedApplicationCount"`
SourceWalletName string `json:"sourceWalletName"`
BalanceRange []int64 `json:"acctBalanceRange"`
DeterministicKeys bool `json:"deterministicKeys"`
}

// LoadBootstrappedData loads a bootstrappedFile structure from a json file
Expand Down
57 changes: 45 additions & 12 deletions netdeploy/remote/deployedNetwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@
assetPerAcct int
appsPerAcct int

deterministicKeys bool
deterministicAccountCount uint64

genesisID string
genesisHash crypto.Digest
poolAddr basics.Address
Expand Down Expand Up @@ -351,7 +354,7 @@
return
}

//GenerateDatabaseFiles generates database files according to the configurations
// GenerateDatabaseFiles generates database files according to the configurations
func (cfg DeployedNetwork) GenerateDatabaseFiles(fileCfgs BootstrappedNetwork, genesisFolder string) error {

accounts := make(map[basics.Address]basics.AccountData)
Expand Down Expand Up @@ -391,16 +394,17 @@
log := logging.NewLogger()

bootstrappedNet := netState{
nAssets: fileCfgs.GeneratedAssetsCount,
nApplications: fileCfgs.GeneratedApplicationCount,
txnState: protocol.PaymentTx,
roundTxnCnt: fileCfgs.RoundTransactionsCount,
round: basics.Round(0),
genesisID: genesis.ID(),
genesisHash: genesis.Hash(),
poolAddr: poolAddr,
sinkAddr: sinkAddr,
log: log,
nAssets: fileCfgs.GeneratedAssetsCount,
nApplications: fileCfgs.GeneratedApplicationCount,
txnState: protocol.PaymentTx,
roundTxnCnt: fileCfgs.RoundTransactionsCount,
round: basics.Round(0),
genesisID: genesis.ID(),
genesisHash: genesis.Hash(),
poolAddr: poolAddr,
sinkAddr: sinkAddr,
log: log,
deterministicKeys: fileCfgs.DeterministicKeys,

Check warning on line 407 in netdeploy/remote/deployedNetwork.go

View check run for this annotation

Codecov / codecov/patch

netdeploy/remote/deployedNetwork.go#L397-L407

Added lines #L397 - L407 were not covered by tests
}

var params config.ConsensusParams
Expand All @@ -422,6 +426,9 @@
rand.Seed(time.Now().UnixNano())
min := fileCfgs.BalanceRange[0]
max := fileCfgs.BalanceRange[1]
// TODO: Randomly assigning target balance in a range may cause tests to behave unpredictably,
// if the randomly selected balance is too low for proper testing.
// consider inserting a hardcoded balance sufficient for your tests.
bal := rand.Int63n(max-min) + min
bootstrappedNet.fundPerAccount = basics.MicroAlgos{Raw: uint64(bal)}
srcAcct := accounts[src]
Expand Down Expand Up @@ -455,6 +462,10 @@
for i := uint64(bootstrappedNet.round); i < fileCfgs.NumRounds; i++ {
bootstrappedNet.round++
blk, _ := createBlock(src, prev, fileCfgs.RoundTransactionsCount, &bootstrappedNet, params, log)
// don't allow the ledger to fall more than 10 rounds behind before adding more
for int(bootstrappedNet.round)-int(l.LatestTrackerCommitted()) > 10 {
algorandskiy marked this conversation as resolved.
Show resolved Hide resolved
time.Sleep(100 * time.Millisecond)

Check warning on line 467 in netdeploy/remote/deployedNetwork.go

View check run for this annotation

Codecov / codecov/patch

netdeploy/remote/deployedNetwork.go#L466-L467

Added lines #L466 - L467 were not covered by tests
}
err = l.AddBlock(blk, agreement.Certificate{Round: bootstrappedNet.round})
if err != nil {
fmt.Printf("Error %v\n", err)
Expand Down Expand Up @@ -486,6 +497,15 @@
return bookkeeping.GenesisAllocation{}
}

// deterministicKeypair returns a key based on the provided index
func deterministicKeypair(i uint64) *crypto.SignatureSecrets {
var seed crypto.Seed
binary.LittleEndian.PutUint64(seed[:], i)
s := crypto.GenerateSignatureSecrets(seed)
return s

Check warning on line 505 in netdeploy/remote/deployedNetwork.go

View check run for this annotation

Codecov / codecov/patch

netdeploy/remote/deployedNetwork.go#L501-L505

Added lines #L501 - L505 were not covered by tests
}

// keypair returns a random key
func keypair() *crypto.SignatureSecrets {
var seed crypto.Seed
crypto.RandBytes(seed[:])
Expand Down Expand Up @@ -576,6 +596,10 @@
//create accounts
bootstrappedNet.round++
blk, _ := createBlock(src, prev, roundTxnCnt, bootstrappedNet, csParams, log)
// don't allow the ledger to fall more than 10 rounds behind before adding more
for int(bootstrappedNet.round)-int(l.LatestTrackerCommitted()) > 10 {
time.Sleep(100 * time.Millisecond)

Check warning on line 601 in netdeploy/remote/deployedNetwork.go

View check run for this annotation

Codecov / codecov/patch

netdeploy/remote/deployedNetwork.go#L600-L601

Added lines #L600 - L601 were not covered by tests
}
err := l.AddBlock(blk, agreement.Certificate{Round: bootstrappedNet.round})
if err != nil {
fmt.Printf("Error %v\n", err)
Expand Down Expand Up @@ -659,7 +683,13 @@

if !bootstrappedNet.accountsCreated {
for i := uint64(0); i < n; i++ {
secretDst := keypair()
var secretDst *crypto.SignatureSecrets
if bootstrappedNet.deterministicKeys {
secretDst = deterministicKeypair(bootstrappedNet.deterministicAccountCount)
bootstrappedNet.deterministicAccountCount++

Check warning on line 689 in netdeploy/remote/deployedNetwork.go

View check run for this annotation

Codecov / codecov/patch

netdeploy/remote/deployedNetwork.go#L688-L689

Added lines #L688 - L689 were not covered by tests
} else {
secretDst = keypair()
}
dst := basics.Address(secretDst.SignatureVerifier)
bootstrappedNet.accounts = append(bootstrappedNet.accounts, dst)

Expand Down Expand Up @@ -1064,6 +1094,9 @@
// 10 per node should be good for a week (add relayCount * 0 so param is used)
minGB := 20 + (nodeCount * 10) + (relayCount * 50)
return minGB
// TODO: this function appears to insufficiently provision EBS nodes in some cases
// if your nodes have insufficient storage, consider using a reasonable hardcoded value like
// return 256
}

func computeSSDStorage(nodeCount, relayCount int) int {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# bootstrappedScenario is scenario1s but with pre-built 30_000_000 accountdb
PARAMS=-w 20 -R 8 -N 20 -n 20 --npn-algod-nodes 10 --node-template node.json --relay-template relay.json --non-participating-node-template nonPartNode.json
FILEPARAMS=--rounds 1600 --ntxns 20000 --naccounts 30000000 --nassets 20000 --napps 20000 --wallet-name "wallet1" --bal 100000 --bal 1000000
PARAMS=-w 20 -R 8 -N 20 -n 20 --npn-algod-nodes 10 --node-template node.json --relay-template relay.json --non-participating-node-template nonPartNode.json --last-part-key-round 50000
FILEPARAMS=--rounds 1600 --ntxns 20000 --naccounts 30000000 --nassets 20000 --napps 20000 --wallet-name "wallet1" --bal 50000000 --bal 50000001 --deterministic

all: net.json genesis.json topology.json boostrappedFile.json

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"generatedApplicationCount": 20000,
"sourceWalletName": "wallet1",
"acctBalanceRange": [
100000,
1000000
]
50000000,
50000001
],
"deterministicKeys": true
}