From fc30667f7605bed390a2ffddd037e9297cbc9dc6 Mon Sep 17 00:00:00 2001 From: Artur Troian Date: Sun, 15 Sep 2024 20:31:53 -0500 Subject: [PATCH] fix(testnetify): use from address as operator use correctly derived consensus address Signed-off-by: Artur Troian --- cmd/akash/cmd/testnetify/config.go | 1 + cmd/akash/cmd/testnetify/state.go | 58 ++++++-------------------- cmd/akash/cmd/testnetify/validators.go | 13 ++---- 3 files changed, 16 insertions(+), 56 deletions(-) diff --git a/cmd/akash/cmd/testnetify/config.go b/cmd/akash/cmd/testnetify/config.go index 1662d80635..d82bcb55e2 100644 --- a/cmd/akash/cmd/testnetify/config.go +++ b/cmd/akash/cmd/testnetify/config.go @@ -48,6 +48,7 @@ type Delegator struct { } type ValidatorConfig struct { + Operator AccAddress `json:"operator"` PubKey PubKey `json:"pubkey"` Name string `json:"name"` Bonded bool `json:"bonded"` diff --git a/cmd/akash/cmd/testnetify/state.go b/cmd/akash/cmd/testnetify/state.go index 8d5245ae71..0ae5f846f8 100644 --- a/cmd/akash/cmd/testnetify/state.go +++ b/cmd/akash/cmd/testnetify/state.go @@ -7,7 +7,6 @@ import ( "sync" "time" - ptypes "github.com/akash-network/akash-api/go/node/provider/v1beta3" "github.com/theckman/yacspin" tmtypes "github.com/tendermint/tendermint/types" @@ -31,6 +30,7 @@ import ( dtypes "github.com/akash-network/akash-api/go/node/deployment/v1beta3" etypes "github.com/akash-network/akash-api/go/node/escrow/v1beta3" mtypes "github.com/akash-network/akash-api/go/node/market/v1beta4" + ptypes "github.com/akash-network/akash-api/go/node/provider/v1beta3" "github.com/akash-network/node/x/audit" "github.com/akash-network/node/x/cert" @@ -300,10 +300,6 @@ func (ga *GenesisState) validateBalances() error { return fmt.Errorf("bonded pool balance is different from bonded coins: %s <-> %s", notBondedBalance, notBondedCoins) // nolint: goerr113 } - // if !notBondedBalance.IsEqual(notBondedCoins) { - // return fmt.Errorf("not bonded pool balance is different from not bonded coins: %s <-> %s", notBondedBalance, notBondedCoins) // nolint: goerr113 - // } - return nil } @@ -451,16 +447,10 @@ func (ga *AuthState) pack(cdc codec.Codec) error { } func (ga *BankState) unpack(cdc codec.Codec) error { - var err error - ga.once.Do(func() { ga.state = banktypes.GetGenesisStateFromAppState(cdc, ga.gstate) }) - if err != nil { - return err - } - return nil } @@ -482,16 +472,10 @@ func (ga *BankState) pack(cdc codec.Codec) error { } func (ga *GovState) unpack(cdc codec.Codec) error { - var err error - ga.once.Do(func() { ga.state = GetGovGenesisStateFromAppState(cdc, ga.gstate) }) - if err != nil { - return err - } - return nil } @@ -511,16 +495,10 @@ func (ga *GovState) pack(cdc codec.Codec) error { } func (ga *IBCState) unpack(cdc codec.Codec) error { - var err error - ga.once.Do(func() { ga.state = GetIBCGenesisStateFromAppState(cdc, ga.gstate) }) - if err != nil { - return err - } - return nil } @@ -540,16 +518,10 @@ func (ga *IBCState) pack(cdc codec.Codec) error { } func (ga *StakingState) unpack(cdc codec.Codec) error { - var err error - ga.once.Do(func() { ga.state = stakingtypes.GetGenesisStateFromAppState(cdc, ga.gstate) }) - if err != nil { - return err - } - return nil } @@ -569,16 +541,10 @@ func (ga *StakingState) pack(cdc codec.Codec) error { } func (ga *SlashingState) unpack(cdc codec.Codec) error { - var err error - ga.once.Do(func() { ga.state = GetSlashingGenesisStateFromAppState(cdc, ga.gstate) }) - if err != nil { - return err - } - return nil } @@ -598,16 +564,10 @@ func (ga *SlashingState) pack(cdc codec.Codec) error { } func (ga *DistributionState) unpack(cdc codec.Codec) error { - var err error - ga.once.Do(func() { ga.state = GetDistributionGenesisStateFromAppState(cdc, ga.gstate) }) - if err != nil { - return err - } - return nil } @@ -1034,6 +994,8 @@ func (ga *GenesisState) ensureActiveSet(cdc codec.Codec) error { return err } + ga.app.StakingState.state.Params.MaxValidators = 1 + sVals := ga.app.StakingState.state.Validators vCount := ga.app.StakingState.state.Params.MaxValidators @@ -1063,7 +1025,10 @@ func (ga *GenesisState) ensureActiveSet(cdc codec.Codec) error { } } - pubkey, _ := val.ConsPubKey() + pubkey, err := val.ConsPubKey() + if err != nil { + return err + } tmPk, err := cryptocodec.ToTmPubKeyInterface(pubkey) if err != nil { @@ -1074,7 +1039,7 @@ func (ga *GenesisState) ensureActiveSet(cdc codec.Codec) error { totalPower += power vals = append(vals, tmtypes.GenesisValidator{ - Address: tmPk.Address(), + Address: sdk.ConsAddress(tmPk.Address()).Bytes(), PubKey: tmPk, Power: power, Name: val.Description.Moniker, @@ -1096,7 +1061,6 @@ func (ga *GenesisState) ensureActiveSet(cdc codec.Codec) error { ga.app.StakingState.state.LastTotalPower = sdk.NewInt(totalPower) ga.app.StakingState.state.LastValidatorPowers = sPowers - sort.Sort(sort.Reverse(GenesisValidators(vals))) ga.doc.Validators = vals @@ -1176,6 +1140,8 @@ func (ga *GenesisState) AddNewValidator( return err } + consAddr := sdk.ConsAddress(pk.Address()) + pkAny, err := codectypes.NewAnyWithValue(pk) if err != nil { return err @@ -1219,9 +1185,9 @@ func (ga *GenesisState) AddNewValidator( ga.app.SlashingState.state.SigningInfos = append(ga.app.SlashingState.state.SigningInfos, slashingtypes.SigningInfo{ - Address: sdk.ConsAddress(addr).String(), + Address: consAddr.String(), ValidatorSigningInfo: slashingtypes.ValidatorSigningInfo{ - Address: sdk.ConsAddress(addr).String(), + Address: consAddr.String(), StartHeight: ga.doc.InitialHeight - 3, IndexOffset: 0, JailedUntil: time.Time{}, diff --git a/cmd/akash/cmd/testnetify/validators.go b/cmd/akash/cmd/testnetify/validators.go index ec238bfd90..90bf46d632 100644 --- a/cmd/akash/cmd/testnetify/validators.go +++ b/cmd/akash/cmd/testnetify/validators.go @@ -1,27 +1,20 @@ package testnetify import ( - "encoding/hex" - "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" ) func (ga *GenesisState) modifyValidators(cdc codec.Codec, cfg *ValidatorsConfig) error { for _, val := range cfg.Add { - addr, err := hex.DecodeString(val.PubKey.PubKey.Address().String()) - if err != nil { - return err - } - - operatorAddress := sdk.ValAddress(addr) + operatorAddress := sdk.ValAddress(val.Operator.AccAddress) - if err = ga.AddNewValidator(cdc, operatorAddress, val.PubKey.PubKey, val.Name, val.Rates); err != nil { + if err := ga.AddNewValidator(cdc, operatorAddress, val.PubKey.PubKey, val.Name, val.Rates); err != nil { return err } for _, delegator := range val.Delegators { - err = ga.IncreaseDelegatorStake( + err := ga.IncreaseDelegatorStake( cdc, delegator.Address.AccAddress, operatorAddress,