Skip to content

Commit

Permalink
Add kickMetaNodeVotePool to genesis file
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiong-stratos committed Mar 12, 2024
1 parent a29695c commit e2f3de2
Show file tree
Hide file tree
Showing 6 changed files with 457 additions and 197 deletions.
369 changes: 264 additions & 105 deletions api/stratos/register/v1/genesis.pulsar.go

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions proto/stratos/register/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ message GenesisState {
(gogoproto.jsontag) = "unbonding_nodes",
(gogoproto.moretags) = "yaml:\"unbonding_nodes\""
];
repeated KickMetaNodeVotePool kick_meta_node_vote_pool = 9 [
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true,
(gogoproto.jsontag) = "kick_meta_node_vote_pool",
(gogoproto.moretags) = "yaml:\"kick_meta_node_vote_pool\""
];
}

message GenesisMetaNode {
Expand Down
8 changes: 7 additions & 1 deletion x/register/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ func (k Keeper) InitGenesis(ctx sdk.Context, data *types.GenesisState) {
}
}

for _, kickMetaNodeVoteInfo := range data.GetKickMetaNodeVotePool() {
k.SetKickMetaNodeVotePool(ctx, kickMetaNodeVoteInfo)
}

return
}

Expand All @@ -182,6 +186,8 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) (data *types.GenesisState) {
return false
})

kickMetaNodeVotePool := k.GetAllKickMetaNodeVotePool(ctx)

return types.NewGenesisState(params, resourceNodes, metaNodes, remainingNozLimit, slashingInfo, depositNozRate,
metaNodeRegVotePool, unbondingNodes)
metaNodeRegVotePool, unbondingNodes, kickMetaNodeVotePool)
}
13 changes: 13 additions & 0 deletions x/register/keeper/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,19 @@ func (k Keeper) GetKickMetaNodeVotePool(ctx sdk.Context, targetNetworkAddr strat
return votePool, true
}

func (k Keeper) GetAllKickMetaNodeVotePool(ctx sdk.Context) (votePools []types.KickMetaNodeVotePool) {
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, types.KickMetaNodeVotesKey)
defer iterator.Close()

for ; iterator.Valid(); iterator.Next() {
voteInfo := types.KickMetaNodeVotePool{}
k.cdc.MustUnmarshalLengthPrefixed(iterator.Value(), &voteInfo)
votePools = append(votePools, voteInfo)
}
return
}

func (k Keeper) GetAllExpiredKickMetaNodeVotePool(ctx sdk.Context) (votePools []types.KickMetaNodeVotePool) {
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, types.KickMetaNodeVotesKey)
Expand Down
35 changes: 19 additions & 16 deletions x/register/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,33 @@ func NewGenesisState(params Params,
depositNozRate sdkmath.LegacyDec,
metaNodeRegVotePool []MetaNodeRegistrationVotePool,
unbondingNodes []UnbondingNode,
kickMetaNodeVotePool []KickMetaNodeVotePool,
) *GenesisState {
return &GenesisState{
Params: params,
ResourceNodes: resourceNodes,
MetaNodes: metaNodes,
RemainingNozLimit: remainingNozLimit,
Slashing: slashingInfo,
DepositNozRate: depositNozRate,
MetaNodeRegVotePool: metaNodeRegVotePool,
UnbondingNodes: unbondingNodes,
Params: params,
ResourceNodes: resourceNodes,
MetaNodes: metaNodes,
RemainingNozLimit: remainingNozLimit,
Slashing: slashingInfo,
DepositNozRate: depositNozRate,
MetaNodeRegVotePool: metaNodeRegVotePool,
UnbondingNodes: unbondingNodes,
KickMetaNodeVotePool: kickMetaNodeVotePool,
}
}

// DefaultGenesisState - default GenesisState used by Cosmos Hub
func DefaultGenesisState() *GenesisState {
return &GenesisState{
Params: DefaultParams(),
ResourceNodes: ResourceNodes{},
MetaNodes: MetaNodes{},
RemainingNozLimit: DefaultRemainingNozLimit,
Slashing: make([]Slashing, 0),
DepositNozRate: DefaultDepositNozRate,
MetaNodeRegVotePool: make([]MetaNodeRegistrationVotePool, 0),
UnbondingNodes: make([]UnbondingNode, 0),
Params: DefaultParams(),
ResourceNodes: ResourceNodes{},
MetaNodes: MetaNodes{},
RemainingNozLimit: DefaultRemainingNozLimit,
Slashing: make([]Slashing, 0),
DepositNozRate: DefaultDepositNozRate,
MetaNodeRegVotePool: make([]MetaNodeRegistrationVotePool, 0),
UnbondingNodes: make([]UnbondingNode, 0),
KickMetaNodeVotePool: make([]KickMetaNodeVotePool, 0),
}
}

Expand Down
Loading

0 comments on commit e2f3de2

Please sign in to comment.