diff --git a/app/export.go b/app/export.go index 23763ea8f..0a313e14b 100644 --- a/app/export.go +++ b/app/export.go @@ -187,7 +187,10 @@ func (app *AkashApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs _ = iter.Close() - _, _ = app.Keepers.Cosmos.Staking.ApplyAndReturnValidatorSetUpdates(ctx) + _, err := app.Keepers.Cosmos.Staking.ApplyAndReturnValidatorSetUpdates(ctx) + if err != nil { + panic(err) + } /* Handle slashing state. */ diff --git a/app/testnet.go b/app/testnet.go index a7633b4f7..6956e4c75 100644 --- a/app/testnet.go +++ b/app/testnet.go @@ -23,9 +23,11 @@ type TestnetValidator struct { OperatorAddress sdk.ValAddress ConsensusAddress sdk.ConsAddress ConsensusPubKey *types.Any + Status stakingtypes.BondStatus Moniker string Commission stakingtypes.Commission MinSelfDelegation sdk.Int + Delegations []TestnetDelegation } type TestnetUpgrade struct { @@ -42,8 +44,18 @@ type TestnetGovConfig struct { } `json:"voting_params,omitempty"` } +type TestnetAccount struct { + Address sdk.AccAddress `json:"address"` + Balances []sdk.Coin `json:"balances"` +} + +type TestnetDelegation struct { + Address sdk.AccAddress `json:"address"` + Amount sdk.Coin `json:"amount"` +} + type TestnetConfig struct { - Accounts []sdk.AccAddress + Accounts []TestnetAccount Validators []TestnetValidator Gov TestnetGovConfig Upgrade TestnetUpgrade @@ -131,33 +143,41 @@ func InitAkashAppForTestnet( panic(err) } + // BANK + // + + for _, account := range tcfg.Accounts { + err := app.Keepers.Cosmos.Bank.MintCoins(ctx, minttypes.ModuleName, account.Balances) + if err != nil { + panic(err) + } + err = app.Keepers.Cosmos.Bank.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, account.Address, account.Balances) + if err != nil { + panic(err) + } + } + for _, val := range tcfg.Validators { // Create Validator struct for our new validator. newVal := stakingtypes.Validator{ OperatorAddress: val.OperatorAddress.String(), ConsensusPubkey: val.ConsensusPubKey, Jailed: false, - Status: stakingtypes.Bonded, - Tokens: sdk.NewInt(900000000000000), - DelegatorShares: sdk.MustNewDecFromStr("10000000"), + Status: val.Status, + Tokens: sdk.NewInt(0), + DelegatorShares: sdk.MustNewDecFromStr("0"), Description: stakingtypes.Description{ - Moniker: "Testnet Validator", - }, - Commission: stakingtypes.Commission{ - CommissionRates: stakingtypes.CommissionRates{ - Rate: sdk.MustNewDecFromStr("0.05"), - MaxRate: sdk.MustNewDecFromStr("0.1"), - MaxChangeRate: sdk.MustNewDecFromStr("0.05"), - }, + Moniker: val.Moniker, }, - MinSelfDelegation: sdk.OneInt(), + Commission: val.Commission, + MinSelfDelegation: val.MinSelfDelegation, } // Add our validator to power and last validators store app.Keepers.Cosmos.Staking.SetValidator(ctx, newVal) err = app.Keepers.Cosmos.Staking.SetValidatorByConsAddr(ctx, newVal) if err != nil { - return nil + panic(err) } app.Keepers.Cosmos.Staking.SetValidatorByPowerIndex(ctx, newVal) @@ -189,9 +209,24 @@ func InitAkashAppForTestnet( Tombstoned: false, } - _, _ = app.Keepers.Cosmos.Staking.ApplyAndReturnValidatorSetUpdates(ctx) + _, err = app.Keepers.Cosmos.Staking.ApplyAndReturnValidatorSetUpdates(ctx) + if err != nil { + panic(err) + } app.Keepers.Cosmos.Slashing.SetValidatorSigningInfo(ctx, newConsAddr, newValidatorSigningInfo) + + for _, del := range val.Delegations { + vl, found := app.Keepers.Cosmos.Staking.GetValidator(ctx, valAddr) + if !found { + panic("validator not found") + } + + _, err = app.Keepers.Cosmos.Staking.Delegate(ctx, del.Address, del.Amount.Amount, stakingtypes.Unbonded, vl, true) + if err != nil { + panic(err) + } + } } // @@ -205,25 +240,6 @@ func InitAkashAppForTestnet( voteParams.VotingPeriod = tcfg.Gov.VotingParams.VotingPeriod.Duration app.Keepers.Cosmos.Gov.SetVotingParams(ctx, voteParams) - // BANK - // - - defaultCoins := sdk.NewCoins( - sdk.NewInt64Coin("uakt", 1000000000000), - sdk.NewInt64Coin("ibc/12C6A0C374171B595A0A9E18B83FA09D295FB1F2D8C6DAA3AC28683471752D84", 1000000000000), // axlUSDC - ) - - for _, account := range tcfg.Accounts { - err := app.Keepers.Cosmos.Bank.MintCoins(ctx, minttypes.ModuleName, defaultCoins) - if err != nil { - return nil - } - err = app.Keepers.Cosmos.Bank.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, account, defaultCoins) - if err != nil { - return nil - } - } - // UPGRADE // if tcfg.Upgrade.Name != "" { diff --git a/cmd/akash/cmd/testnetify/config.go b/cmd/akash/cmd/testnetify/config.go index 842bf6354..0f1c44927 100644 --- a/cmd/akash/cmd/testnetify/config.go +++ b/cmd/akash/cmd/testnetify/config.go @@ -41,12 +41,13 @@ type ConsAddress struct { } type TestnetValidator struct { - Moniker string `json:"moniker"` - Operator AccAddress `json:"operator"` - Bonded bool `json:"bonded"` - Commission stakingtypes.Commission `json:"commission"` - MinSelfDelegation sdk.Int `json:"min_self_delegation"` - Home string `json:"home"` + Moniker string `json:"moniker"` + Operator AccAddress `json:"operator"` + Status stakingtypes.BondStatus `json:"status"` + Commission stakingtypes.Commission `json:"commission"` + MinSelfDelegation sdk.Int `json:"min_self_delegation"` + Home string `json:"home"` + Delegations []akash.TestnetDelegation `json:"delegations"` privValidator *pvm.FilePV pubKey crypto.PubKey @@ -59,7 +60,7 @@ type TestnetValidators []TestnetValidator type TestnetConfig struct { ChainID string `json:"chain_id"` Validators TestnetValidators `json:"validators"` - Accounts []sdk.AccAddress `json:"accounts"` + Accounts []akash.TestnetAccount `json:"accounts"` Gov akash.TestnetGovConfig `json:"gov"` upgrade akash.TestnetUpgrade } diff --git a/cmd/akash/cmd/testnetify/testnetify.go b/cmd/akash/cmd/testnetify/testnetify.go index 5941fadd2..62277c5f9 100644 --- a/cmd/akash/cmd/testnetify/testnetify.go +++ b/cmd/akash/cmd/testnetify/testnetify.go @@ -2,6 +2,7 @@ package testnetify import ( "bufio" + "encoding/hex" "encoding/json" "fmt" "io" @@ -13,6 +14,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/spf13/cobra" "github.com/tendermint/tendermint/crypto/tmhash" @@ -29,6 +31,7 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" sdksrv "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/server/types" + sdktypes "github.com/cosmos/cosmos-sdk/types" akash "github.com/akash-network/node/app" ) @@ -114,6 +117,17 @@ you want to test the upgrade handler itself. return err } + for i, acc := range cfg.Accounts { + if len(acc.Balances) > 0 { + cfg.Accounts[i].Balances = sdk.NewCoins(acc.Balances...) + } else { + cfg.Accounts[i].Balances = sdk.NewCoins( + sdk.NewInt64Coin("uakt", 10000000000000), + sdk.NewInt64Coin("ibc/12C6A0C374171B595A0A9E18B83FA09D295FB1F2D8C6DAA3AC28683471752D84", 1000000000000), // axlUSDC + ) + } + } + sctx.Logger.Info(fmt.Sprintf("loaded config from %s", cfgFilePath)) if name, _ := cmd.Flags().GetString(KeyTestnetTriggerUpgrade); name != "" { @@ -296,7 +310,7 @@ func testnetify(sctx *sdksrv.Context, tcfg TestnetConfig, testnetAppCreator type return nil, node.ErrSaveGenesisDocHash{Err: err} } - state, stateStore, _, err := node.LoadStateFromDBOrGenesisDocProvider(stateDB, genDocProvider, "") + state, stateStore, _, err := node.LoadStateFromDBOrGenesisDocProvider(stateDB, genDocProvider, hex.EncodeToString(updatedChecksum)) if err != nil { return nil, err } @@ -346,6 +360,8 @@ func testnetify(sctx *sdksrv.Context, tcfg TestnetConfig, testnetAppCreator type Moniker: val.Moniker, Commission: val.Commission, MinSelfDelegation: val.MinSelfDelegation, + Status: val.Status, + Delegations: val.Delegations, }) tcfg.Validators[i].privValidator = privValidator @@ -447,15 +463,20 @@ func testnetify(sctx *sdksrv.Context, tcfg TestnetConfig, testnetAppCreator type Signature: voteProto.Signature, }) + var vp int64 + + for _, del := range val.Delegations { + vp += del.Amount.Amount.Quo(sdktypes.DefaultPowerReduction).Int64() + } newValidators = append(newValidators, &cmttypes.Validator{ Address: val.validatorAddress, PubKey: val.pubKey, - VotingPower: 900000000000000, + VotingPower: vp, }) } // Replace all valSets in state to be the valSet with just our validator. - // and set the very first validator as proposer + // and set the very first validator as a proposer newValSet := &cmttypes.ValidatorSet{ Validators: newValidators, Proposer: newValidators[0],