diff --git a/tools/genesis-snapshot/presets/presets_yaml.go b/tools/genesis-snapshot/presets/presets_yaml.go index 0c879c7df..cd38ec268 100644 --- a/tools/genesis-snapshot/presets/presets_yaml.go +++ b/tools/genesis-snapshot/presets/presets_yaml.go @@ -2,6 +2,7 @@ package presets import ( "fmt" + "time" "golang.org/x/crypto/blake2b" @@ -21,18 +22,22 @@ type ValidatorYaml struct { } type BlockIssuerYaml struct { - Name string `yaml:"name"` - PublicKey string `yaml:"publicKey"` + Name string `yaml:"name"` + PublicKey string `yaml:"publicKey"` + BlockIssuanceCredits uint64 `yaml:"blockIssuanceCredits"` } type BasicOutputYaml struct { + Name string `yaml:"name"` Address string `yaml:"address"` Amount uint64 `yaml:"amount"` Mana uint64 `yaml:"mana"` } type ConfigYaml struct { - Name string `yaml:"name"` + NetworkName string `yaml:"networkName"` + Bech32HRP string `yaml:"bech32HRP"` + FilePath string `yaml:"filepath"` Validators []ValidatorYaml `yaml:"validators"` @@ -40,12 +45,32 @@ type ConfigYaml struct { BasicOutputs []BasicOutputYaml `yaml:"basicOutputs"` } +func TestnetProtocolParameters(networkName string, bech32HRP iotago.NetworkPrefix) iotago.ProtocolParameters { + return iotago.NewV3SnapshotProtocolParameters( + iotago.WithNetworkOptions(networkName, bech32HRP), + iotago.WithStorageOptions(100, 1, 100, 1000, 1000, 1000), + iotago.WithWorkScoreOptions(500, 110_000, 7_500, 40_000, 90_000, 50_000, 40_000, 70_000, 5_000, 15_000), + iotago.WithTimeProviderOptions(0, time.Now().Unix(), 10, 13), + iotago.WithLivenessOptions(10, 15, 4, 7, 100), + iotago.WithSupplyOptions(4600000000000000, 63, 1, 17, 32, 21, 70), + iotago.WithCongestionControlOptions(1, 1, 1, 400_000_000, 250_000_000, 50_000_000, 1000, 100), + iotago.WithStakingOptions(3, 10, 10), + iotago.WithVersionSignalingOptions(7, 5, 7), + iotago.WithRewardsOptions(8, 11, 2, 384), + iotago.WithTargetCommitteeSize(16), + iotago.WithChainSwitchingThreshold(3), + ) +} + func GenerateFromYaml(hostsFile string) ([]options.Option[snapshotcreator.Options], error) { var configYaml ConfigYaml if err := ioutils.ReadYAMLFromFile(hostsFile, &configYaml); err != nil { return nil, err } + fmt.Printf("generating protocol parameters for network %s with bech32HRP %s\n", configYaml.NetworkName, configYaml.Bech32HRP) + protocolParams := TestnetProtocolParameters(configYaml.NetworkName, iotago.NetworkPrefix(configYaml.Bech32HRP)) + accounts := make([]snapshotcreator.AccountDetails, 0, len(configYaml.Validators)+len(configYaml.BlockIssuers)) for _, validator := range configYaml.Validators { pubkey := validator.PublicKey @@ -53,39 +78,45 @@ func GenerateFromYaml(hostsFile string) ([]options.Option[snapshotcreator.Option account := snapshotcreator.AccountDetails{ AccountID: blake2b.Sum256(lo.PanicOnErr(hexutil.DecodeHex(pubkey))), Address: iotago.Ed25519AddressFromPubKey(lo.PanicOnErr(hexutil.DecodeHex(pubkey))), - Amount: mock.MinValidatorAccountAmount(ProtocolParamsDocker), + Amount: mock.MinValidatorAccountAmount(protocolParams), IssuerKey: iotago.Ed25519PublicKeyHashBlockIssuerKeyFromPublicKey(ed25519.PublicKey(lo.PanicOnErr(hexutil.DecodeHex(pubkey)))), ExpirySlot: iotago.MaxSlotIndex, - BlockIssuanceCredits: iotago.MaxBlockIssuanceCredits / 4, + BlockIssuanceCredits: 0, StakingEndEpoch: iotago.MaxEpochIndex, FixedCost: 1, - StakedAmount: mock.MinValidatorAccountAmount(ProtocolParamsDocker), - Mana: iotago.Mana(mock.MinValidatorAccountAmount(ProtocolParamsDocker)), + StakedAmount: mock.MinValidatorAccountAmount(protocolParams), + Mana: iotago.Mana(mock.MinValidatorAccountAmount(protocolParams)), } accounts = append(accounts, account) } for _, blockIssuer := range configYaml.BlockIssuers { pubkey := blockIssuer.PublicKey - fmt.Printf("adding blockissueer %s with publicKey %s\n", blockIssuer.Name, pubkey) + fmt.Printf("adding blockissuer %s with publicKey %s\n", blockIssuer.Name, pubkey) account := snapshotcreator.AccountDetails{ AccountID: blake2b.Sum256(lo.PanicOnErr(hexutil.DecodeHex(pubkey))), Address: iotago.Ed25519AddressFromPubKey(lo.PanicOnErr(hexutil.DecodeHex(pubkey))), - Amount: mock.MinValidatorAccountAmount(ProtocolParamsDocker), + Amount: mock.MinValidatorAccountAmount(protocolParams), IssuerKey: iotago.Ed25519PublicKeyHashBlockIssuerKeyFromPublicKey(ed25519.PublicKey(lo.PanicOnErr(hexutil.DecodeHex(pubkey)))), ExpirySlot: iotago.MaxSlotIndex, - BlockIssuanceCredits: iotago.MaxBlockIssuanceCredits / 4, - Mana: iotago.Mana(mock.MinValidatorAccountAmount(ProtocolParamsDocker)), + BlockIssuanceCredits: iotago.BlockIssuanceCredits(blockIssuer.BlockIssuanceCredits), + Mana: iotago.Mana(mock.MinValidatorAccountAmount(protocolParams)), } accounts = append(accounts, account) } basicOutputs := make([]snapshotcreator.BasicOutputDetails, 0, len(configYaml.BasicOutputs)) for _, basicOutput := range configYaml.BasicOutputs { - address := lo.Return2(iotago.ParseBech32(basicOutput.Address)) + hrp, address, err := iotago.ParseBech32(basicOutput.Address) + if err != nil { + panic(err) + } + if protocolParams.Bech32HRP() != hrp { + panic(fmt.Sprintf("address %s has wrong HRP %s, expected %s", address, hrp, protocolParams.Bech32HRP())) + } amount := basicOutput.Amount mana := basicOutput.Mana - fmt.Printf("adding basicOutput for %s with amount %d and mana %d\n", address, amount, mana) + fmt.Printf("adding basicOutput %s for %s with amount %d and mana %d\n", basicOutput.Name, address, amount, mana) basicOutputs = append(basicOutputs, snapshotcreator.BasicOutputDetails{ Address: address, Amount: iotago.BaseToken(amount), @@ -95,7 +126,7 @@ func GenerateFromYaml(hostsFile string) ([]options.Option[snapshotcreator.Option return []options.Option[snapshotcreator.Options]{ snapshotcreator.WithFilePath(configYaml.FilePath), - snapshotcreator.WithProtocolParameters(ProtocolParamsDocker), + snapshotcreator.WithProtocolParameters(protocolParams), snapshotcreator.WithAccounts(accounts...), snapshotcreator.WithBasicOutputs(basicOutputs...), }, nil