refactor(x/staking,genutil)!: use validatorUpdates (#19754)
Co-authored-by: chixiaoxiao <chixiaoxiao@gmail.com>
This commit is contained in:
co-authored by
chixiaoxiao
parent
a1bfe5d285
commit
bfa734ce8f
@@ -3,11 +3,10 @@ package genutil
|
||||
import (
|
||||
"context"
|
||||
|
||||
abci "github.com/cometbft/cometbft/abci/types"
|
||||
|
||||
"cosmossdk.io/core/genesis"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/types/module"
|
||||
"github.com/cosmos/cosmos-sdk/x/genutil/types"
|
||||
)
|
||||
|
||||
@@ -16,9 +15,13 @@ 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)
|
||||
moduleValidatorUpdates, err := DeliverGenTxs(ctx, genesisState.GenTxs, stakingKeeper, deliverTx, txEncodingConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return moduleValidatorUpdates, nil
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
+2
-3
@@ -6,8 +6,6 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
abci "github.com/cometbft/cometbft/abci/types"
|
||||
|
||||
"cosmossdk.io/core/genesis"
|
||||
bankexported "cosmossdk.io/x/bank/exported"
|
||||
stakingtypes "cosmossdk.io/x/staking/types"
|
||||
@@ -15,6 +13,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/module"
|
||||
"github.com/cosmos/cosmos-sdk/x/genutil/types"
|
||||
)
|
||||
|
||||
@@ -94,7 +93,7 @@ func DeliverGenTxs(
|
||||
ctx context.Context, genTxs []json.RawMessage,
|
||||
stakingKeeper types.StakingKeeper, deliverTx genesis.TxHandler,
|
||||
txEncodingConfig client.TxEncodingConfig,
|
||||
) ([]abci.ValidatorUpdate, error) {
|
||||
) ([]module.ValidatorUpdate, error) {
|
||||
for _, genTx := range genTxs {
|
||||
tx, err := txEncodingConfig.TxJSONDecoder()(genTx)
|
||||
if err != nil {
|
||||
|
||||
+1
-25
@@ -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.
|
||||
|
||||
@@ -10,9 +10,9 @@ import (
|
||||
reflect "reflect"
|
||||
|
||||
exported "cosmossdk.io/x/bank/exported"
|
||||
types "github.com/cometbft/cometbft/abci/types"
|
||||
codec "github.com/cosmos/cosmos-sdk/codec"
|
||||
types0 "github.com/cosmos/cosmos-sdk/types"
|
||||
types "github.com/cosmos/cosmos-sdk/types"
|
||||
module "github.com/cosmos/cosmos-sdk/types/module"
|
||||
gomock "github.com/golang/mock/gomock"
|
||||
)
|
||||
|
||||
@@ -40,10 +40,10 @@ func (m *MockStakingKeeper) EXPECT() *MockStakingKeeperMockRecorder {
|
||||
}
|
||||
|
||||
// ApplyAndReturnValidatorSetUpdates mocks base method.
|
||||
func (m *MockStakingKeeper) ApplyAndReturnValidatorSetUpdates(arg0 context.Context) ([]types.ValidatorUpdate, error) {
|
||||
func (m *MockStakingKeeper) ApplyAndReturnValidatorSetUpdates(arg0 context.Context) ([]module.ValidatorUpdate, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "ApplyAndReturnValidatorSetUpdates", arg0)
|
||||
ret0, _ := ret[0].([]types.ValidatorUpdate)
|
||||
ret0, _ := ret[0].([]module.ValidatorUpdate)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
@@ -78,10 +78,10 @@ func (m *MockAccountKeeper) EXPECT() *MockAccountKeeperMockRecorder {
|
||||
}
|
||||
|
||||
// NewAccount mocks base method.
|
||||
func (m *MockAccountKeeper) NewAccount(arg0 context.Context, arg1 types0.AccountI) types0.AccountI {
|
||||
func (m *MockAccountKeeper) NewAccount(arg0 context.Context, arg1 types.AccountI) types.AccountI {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "NewAccount", arg0, arg1)
|
||||
ret0, _ := ret[0].(types0.AccountI)
|
||||
ret0, _ := ret[0].(types.AccountI)
|
||||
return ret0
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ func (mr *MockAccountKeeperMockRecorder) NewAccount(arg0, arg1 interface{}) *gom
|
||||
}
|
||||
|
||||
// SetAccount mocks base method.
|
||||
func (m *MockAccountKeeper) SetAccount(arg0 context.Context, arg1 types0.AccountI) {
|
||||
func (m *MockAccountKeeper) SetAccount(arg0 context.Context, arg1 types.AccountI) {
|
||||
m.ctrl.T.Helper()
|
||||
m.ctrl.Call(m, "SetAccount", arg0, arg1)
|
||||
}
|
||||
@@ -127,7 +127,7 @@ func (m *MockGenesisAccountsIterator) EXPECT() *MockGenesisAccountsIteratorMockR
|
||||
}
|
||||
|
||||
// IterateGenesisAccounts mocks base method.
|
||||
func (m *MockGenesisAccountsIterator) IterateGenesisAccounts(cdc *codec.LegacyAmino, appGenesis map[string]json.RawMessage, cb func(types0.AccountI) bool) {
|
||||
func (m *MockGenesisAccountsIterator) IterateGenesisAccounts(cdc *codec.LegacyAmino, appGenesis map[string]json.RawMessage, cb func(types.AccountI) bool) {
|
||||
m.ctrl.T.Helper()
|
||||
m.ctrl.Call(m, "IterateGenesisAccounts", cdc, appGenesis, cb)
|
||||
}
|
||||
|
||||
@@ -4,17 +4,16 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
abci "github.com/cometbft/cometbft/abci/types"
|
||||
|
||||
bankexported "cosmossdk.io/x/bank/exported"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/module"
|
||||
)
|
||||
|
||||
// StakingKeeper defines the expected staking keeper (noalias)
|
||||
type StakingKeeper interface {
|
||||
ApplyAndReturnValidatorSetUpdates(context.Context) (updates []abci.ValidatorUpdate, err error)
|
||||
ApplyAndReturnValidatorSetUpdates(context.Context) (updates []module.ValidatorUpdate, err error)
|
||||
}
|
||||
|
||||
// AccountKeeper defines the expected account keeper (noalias)
|
||||
|
||||
Reference in New Issue
Block a user