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

tools: Allow specification of Reward Pool Account Balance in Genesis #4643

Merged
merged 23 commits into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
2acacdb
tmp
barnjamin Oct 14, 2022
1eaef62
set balance to 0
barnjamin Oct 14, 2022
d79453e
set alloc
barnjamin Oct 14, 2022
9f18a01
Try min bal
barnjamin Oct 14, 2022
21508a1
set reward pool to min allocation when in dev mode
barnjamin Oct 14, 2022
345c99d
dont define reward pool as zero address
barnjamin Oct 14, 2022
305e1e1
adding another flag to the gen.GenesisData struct to allow more exact…
barnjamin Oct 19, 2022
917f547
Merge branch 'master' into devmode-no-rewards
barnjamin Oct 19, 2022
6441788
Merge branch 'master' into devmode-genesis-no-reward
barnjamin Oct 19, 2022
5b428a8
fix part key assignement
barnjamin Oct 19, 2022
d4d1cfe
rename flag to make it clear this is just an initial condition
barnjamin Oct 25, 2022
80f3ce0
remove flag from create, add field to genesis template for rewards po…
barnjamin Oct 27, 2022
2812d89
fix possible bug with balance between 0 and min bal
barnjamin Oct 27, 2022
1bae82b
Update gen/generate.go
barnjamin Oct 27, 2022
ceff9e5
Add tests confirming genesis.json generation
michaeldiamant Oct 28, 2022
075711f
Fix comment
michaeldiamant Oct 28, 2022
7cea01f
Fix reviewdog errors
michaeldiamant Oct 28, 2022
99c7c8c
Merge pull request #1 from michaeldiamant/TestGenesisJsonCreation
barnjamin Oct 31, 2022
cd39c5e
Update netdeploy/network.go
barnjamin Oct 31, 2022
019df3e
Update gen/generate.go
michaeldiamant Nov 1, 2022
5193c93
group imports
barnjamin Nov 1, 2022
0c3ec98
Merge branch 'devmode-no-rewards' into devmode-genesis-no-reward
barnjamin Nov 1, 2022
d4db850
remove unintended merge changes
barnjamin Nov 1, 2022
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
4 changes: 3 additions & 1 deletion cmd/goal/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ var startNode string
var noImportKeys bool
var noClean bool
var devModeOverride bool
var noRewardOverride bool

func init() {
networkCmd.AddCommand(networkCreateCmd)
Expand All @@ -47,6 +48,7 @@ func init() {
networkCreateCmd.Flags().BoolVarP(&noImportKeys, "noimportkeys", "K", false, "Do not import root keys when creating the network (by default will import)")
networkCreateCmd.Flags().BoolVar(&noClean, "noclean", false, "Prevents auto-cleanup on error - for diagnosing problems")
networkCreateCmd.Flags().BoolVar(&devModeOverride, "devMode", false, "Forces the configuration to enable DevMode, returns an error if the template is not compatible with DevMode.")
networkCreateCmd.Flags().BoolVar(&noRewardOverride, "noReward", false, "Forces the configuration to disable Rewards")
michaeldiamant marked this conversation as resolved.
Show resolved Hide resolved

networkStartCmd.Flags().StringVarP(&startNode, "node", "n", "", "Specify the name of a specific node to start")

Expand Down Expand Up @@ -101,7 +103,7 @@ var networkCreateCmd = &cobra.Command{
consensus, _ = config.PreloadConfigurableConsensusProtocols(dataDir)
}

network, err := netdeploy.CreateNetworkFromTemplate(networkName, networkRootDir, networkTemplateFile, binDir, !noImportKeys, nil, consensus, devModeOverride)
network, err := netdeploy.CreateNetworkFromTemplate(networkName, networkRootDir, networkTemplateFile, binDir, !noImportKeys, nil, consensus, devModeOverride, noRewardOverride)
if err != nil {
if noClean {
reportInfof(" ** failed ** - Preserving network rootdir '%s'", networkRootDir)
Expand Down
33 changes: 26 additions & 7 deletions gen/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,28 @@ func GenerateGenesisFiles(genesisData GenesisData, consensus config.ConsensusPro
return fmt.Errorf("couldn't make output directory '%s': %v", outDir, err.Error())
}

return generateGenesisFiles(outDir, proto, consensusParams, genesisData.NetworkName, genesisData.VersionModifier, allocation, genesisData.FirstPartKeyRound, genesisData.LastPartKeyRound, genesisData.PartKeyDilution, genesisData.FeeSink, genesisData.RewardsPool, genesisData.Comment, genesisData.DevMode, verboseOut)
return generateGenesisFiles(
proto, consensusParams, allocation, genesisData, outDir, verboseOut,
)
}

func generateGenesisFiles(outDir string, protoVersion protocol.ConsensusVersion, protoParams config.ConsensusParams, netName string, schemaVersionModifier string,
allocation []genesisAllocation, firstWalletValid uint64, lastWalletValid uint64, partKeyDilution uint64, feeSink, rewardsPool basics.Address, comment string, devmode bool, verboseOut io.Writer) (err error) {
func generateGenesisFiles(protoVersion protocol.ConsensusVersion, protoParams config.ConsensusParams, allocation []genesisAllocation, genData GenesisData, outDir string, verboseOut io.Writer) (err error) {

genesisAddrs := make(map[string]basics.Address)
records := make(map[string]basics.AccountData)
var (
netName = genData.NetworkName
schemaVersionModifier = genData.VersionModifier
firstWalletValid = genData.FirstPartKeyRound
lastWalletValid = genData.LastPartKeyRound
partKeyDilution = genData.PartKeyDilution
feeSink = genData.FeeSink
rewardsPool = genData.RewardsPool
devmode = genData.DevMode
noRewards = genData.NoRewards
comment = genData.Comment

genesisAddrs = make(map[string]basics.Address)
records = make(map[string]basics.AccountData)
)

if partKeyDilution == 0 {
partKeyDilution = protoParams.DefaultKeyDilution
Expand Down Expand Up @@ -326,13 +340,18 @@ func generateGenesisFiles(outDir string, protoVersion protocol.ConsensusVersion,
fmt.Fprintln(verboseOut, protoVersion, protoParams.MinBalance)
}

rewardBalance := defaultIncentivePoolBalanceAtInception
if noRewards {
rewardBalance = protoParams.MinBalance
}

records["FeeSink"] = basics.AccountData{
Status: basics.NotParticipating,
MicroAlgos: basics.MicroAlgos{Raw: protoParams.MinBalance},
}
records["RewardsPool"] = basics.AccountData{
Status: basics.NotParticipating,
MicroAlgos: basics.MicroAlgos{Raw: defaultIncentivePoolBalanceAtInception},
MicroAlgos: basics.MicroAlgos{Raw: rewardBalance},
}

sinkAcct := genesisAllocation{
michaeldiamant marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -342,7 +361,7 @@ func generateGenesisFiles(outDir string, protoVersion protocol.ConsensusVersion,
}
poolAcct := genesisAllocation{
Name: "RewardsPool",
Stake: defaultIncentivePoolBalanceAtInception,
Stake: rewardBalance,
Online: basics.NotParticipating,
}

Expand Down
1 change: 1 addition & 0 deletions gen/walletData.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type GenesisData struct {
Wallets []WalletData
FeeSink basics.Address
RewardsPool basics.Address
NoRewards bool
DevMode bool
Comment string
}
Expand Down
6 changes: 5 additions & 1 deletion netdeploy/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type Network struct {

// CreateNetworkFromTemplate uses the specified template to deploy a new private network
// under the specified root directory.
func CreateNetworkFromTemplate(name, rootDir, templateFile, binDir string, importKeys bool, nodeExitCallback nodecontrol.AlgodExitErrorCallback, consensus config.ConsensusProtocols, overrideDevMode bool) (Network, error) {
func CreateNetworkFromTemplate(name, rootDir, templateFile, binDir string, importKeys bool, nodeExitCallback nodecontrol.AlgodExitErrorCallback, consensus config.ConsensusProtocols, overrideDevMode, overrideNoRewards bool) (Network, error) {
n := Network{
rootDir: rootDir,
nodeExitCallback: nodeExitCallback,
Expand All @@ -74,6 +74,10 @@ func CreateNetworkFromTemplate(name, rootDir, templateFile, binDir string, impor
template.Nodes[0].IsRelay = false
}
}
if overrideNoRewards {
template.Genesis.NoRewards = true
}

barnjamin marked this conversation as resolved.
Show resolved Hide resolved
err = template.Validate()
}
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion test/framework/fixtures/libgoalFixture.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (f *LibGoalFixture) setup(test TestingTB, testName string, templateFile str
os.RemoveAll(f.rootDir)
templateFile = filepath.Join(f.testDataDir, templateFile)
importKeys := false // Don't automatically import root keys when creating folders, we'll import on-demand
network, err := netdeploy.CreateNetworkFromTemplate("test", f.rootDir, templateFile, f.binDir, importKeys, f.nodeExitWithError, f.consensus, false)
network, err := netdeploy.CreateNetworkFromTemplate("test", f.rootDir, templateFile, f.binDir, importKeys, f.nodeExitWithError, f.consensus, false, false)
f.failOnError(err, "CreateNetworkFromTemplate failed: %v")
f.network = network

Expand Down