Skip to content

Commit

Permalink
fix(testnetify): use from address as operator (#1957)
Browse files Browse the repository at this point in the history
use correctly derived consensus address

Signed-off-by: Artur Troian <[email protected]>
  • Loading branch information
troian authored Sep 16, 2024
1 parent 5b08c70 commit d16d266
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 56 deletions.
1 change: 1 addition & 0 deletions cmd/akash/cmd/testnetify/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
56 changes: 10 additions & 46 deletions cmd/akash/cmd/testnetify/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}

Expand Down Expand Up @@ -1063,7 +1023,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 {
Expand All @@ -1074,7 +1037,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,
Expand All @@ -1096,7 +1059,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
Expand Down Expand Up @@ -1176,6 +1138,8 @@ func (ga *GenesisState) AddNewValidator(
return err
}

consAddr := sdk.ConsAddress(pk.Address())

pkAny, err := codectypes.NewAnyWithValue(pk)
if err != nil {
return err
Expand Down Expand Up @@ -1219,9 +1183,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{},
Expand Down
13 changes: 3 additions & 10 deletions cmd/akash/cmd/testnetify/validators.go
Original file line number Diff line number Diff line change
@@ -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,
Expand Down

0 comments on commit d16d266

Please sign in to comment.