Skip to content

Commit

Permalink
use validatorUpdates in x/genutil
Browse files Browse the repository at this point in the history
  • Loading branch information
chixiaoxiao committed Mar 14, 2024
1 parent 80dfe96 commit 3fe4097
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 29 deletions.
30 changes: 26 additions & 4 deletions x/genutil/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package genutil

import (
"context"

abci "github.com/cometbft/cometbft/abci/types"
"fmt"
"github.com/cosmos/cosmos-sdk/types/module"

"cosmossdk.io/core/genesis"

Expand All @@ -16,9 +16,31 @@ func InitGenesis(
ctx context.Context, stakingKeeper types.StakingKeeper,
deliverTx genesis.TxHandler, genesisState types.GenesisState,
txEncodingConfig client.TxEncodingConfig,
) (validators []abci.ValidatorUpdate, err error) {
) (validatorUpdates []module.ValidatorUpdate, err error) {
if len(genesisState.GenTxs) > 0 {
validators, err = DeliverGenTxs(ctx, genesisState.GenTxs, stakingKeeper, deliverTx, txEncodingConfig)
cometValidatorUpdates, err := DeliverGenTxs(ctx, genesisState.GenTxs, stakingKeeper, deliverTx, txEncodingConfig)
if err != nil {
return nil, err
}
validatorUpdates = make([]module.ValidatorUpdate, len(cometValidatorUpdates))
for i, v := range cometValidatorUpdates {
if ed25519 := v.PubKey.GetEd25519(); len(ed25519) > 0 {
validatorUpdates[i] = module.ValidatorUpdate{
PubKey: ed25519,
PubKeyType: "ed25519",
Power: v.Power,
}
} else if secp256k1 := v.PubKey.GetSecp256K1(); len(secp256k1) > 0 {
validatorUpdates[i] = module.ValidatorUpdate{
PubKey: secp256k1,
PubKeyType: "secp256k1",
Power: v.Power,
}
} else {
return nil, fmt.Errorf("unexpected validator pubkey type: %T", v.PubKey)
}
}
return validatorUpdates, nil
}
return

Check failure on line 45 in x/genutil/genesis.go

View workflow job for this annotation

GitHub Actions / Analyze

naked return in func `InitGenesis` with 31 lines of code (nakedret)

Check failure on line 45 in x/genutil/genesis.go

View workflow job for this annotation

GitHub Actions / Analyze

naked return in func `InitGenesis` with 31 lines of code (nakedret)

Check failure on line 45 in x/genutil/genesis.go

View workflow job for this annotation

GitHub Actions / Analyze

naked return in func `InitGenesis` with 31 lines of code (nakedret)

Check failure on line 45 in x/genutil/genesis.go

View workflow job for this annotation

GitHub Actions / Analyze

naked return in func `InitGenesis` with 31 lines of code (nakedret)

Check failure on line 45 in x/genutil/genesis.go

View workflow job for this annotation

GitHub Actions / Analyze

naked return in func `InitGenesis` with 31 lines of code (nakedret)

Check failure on line 45 in x/genutil/genesis.go

View workflow job for this annotation

GitHub Actions / Analyze

naked return in func `InitGenesis` with 31 lines of code (nakedret)

Check failure on line 45 in x/genutil/genesis.go

View workflow job for this annotation

GitHub Actions / Analyze

naked return in func `InitGenesis` with 31 lines of code (nakedret)

Check failure on line 45 in x/genutil/genesis.go

View workflow job for this annotation

GitHub Actions / Analyze

naked return in func `InitGenesis` with 31 lines of code (nakedret)

Check failure on line 45 in x/genutil/genesis.go

View workflow job for this annotation

GitHub Actions / Analyze

naked return in func `InitGenesis` with 31 lines of code (nakedret)

Check failure on line 45 in x/genutil/genesis.go

View workflow job for this annotation

GitHub Actions / Analyze

naked return in func `InitGenesis` with 31 lines of code (nakedret)
}
26 changes: 1 addition & 25 deletions x/genutil/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,31 +78,7 @@ func (am AppModule) ValidateGenesis(bz json.RawMessage) error {
func (am AppModule) InitGenesis(ctx context.Context, data json.RawMessage) ([]module.ValidatorUpdate, error) {
var genesisState types.GenesisState
am.cdc.MustUnmarshalJSON(data, &genesisState)
cometValidatorUpdates, err := InitGenesis(ctx, am.stakingKeeper, am.deliverTx, genesisState, am.txEncodingConfig)
if err != nil {
return nil, err
}

validatorUpdates := make([]module.ValidatorUpdate, len(cometValidatorUpdates))
for i, v := range cometValidatorUpdates {
if ed25519 := v.PubKey.GetEd25519(); len(ed25519) > 0 {
validatorUpdates[i] = module.ValidatorUpdate{
PubKey: ed25519,
PubKeyType: "ed25519",
Power: v.Power,
}
} else if secp256k1 := v.PubKey.GetSecp256K1(); len(secp256k1) > 0 {
validatorUpdates[i] = module.ValidatorUpdate{
PubKey: secp256k1,
PubKeyType: "secp256k1",
Power: v.Power,
}
} else {
return nil, fmt.Errorf("unexpected validator pubkey type: %T", v.PubKey)
}
}

return validatorUpdates, nil
return InitGenesis(ctx, am.stakingKeeper, am.deliverTx, genesisState, am.txEncodingConfig)
}

// ExportGenesis returns the exported genesis state as raw bytes for the genutil module.
Expand Down

0 comments on commit 3fe4097

Please sign in to comment.