Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qb1773 minimum sds staking #252

Merged
merged 3 commits into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func SetupWithGenesisNodeSet(t *testing.T,
resourceNodes,
metaNodes,
registertypes.DefaultRemainingNozLimit,
make([]*registertypes.Slashing, 0),
make([]registertypes.Slashing, 0),
registertypes.DefaultStakeNozRate,
)
genesisState[registertypes.ModuleName] = app.AppCodec().MustMarshalJSON(registerGenesis)
Expand Down
31 changes: 23 additions & 8 deletions proto/stratos/register/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,21 @@ option go_package = "github.com/stratosnet/stratos-chain/x/register/types";
// GenesisState defines the register module's genesis state.
message GenesisState {
Params params = 1 [
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "params",
(gogoproto.moretags) = "yaml:\"params\""
];
repeated ResourceNode resource_nodes = 2 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "ResourceNodes",
(gogoproto.moretags) = "yaml:\"resource_nodes\""
(gogoproto.jsontag) = "resource_nodes",
(gogoproto.moretags) = "yaml:\"resource_nodes\"",
(gogoproto.castrepeated) = "ResourceNodes"
];
repeated MetaNode meta_nodes = 3 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "MetaNodes",
(gogoproto.moretags) = "yaml:\"meta_nodes\""
(gogoproto.jsontag) = "meta_nodes",
(gogoproto.moretags) = "yaml:\"meta_nodes\"",
(gogoproto.castrepeated) = "MetaNodes"
];
string remaining_noz_limit = 4 [
(gogoproto.nullable) = false,
Expand All @@ -31,37 +35,48 @@ message GenesisState {
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int"
]; // remaining noz limit
repeated Slashing slashing = 5 [
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "slashing",
(gogoproto.moretags) = "yaml:\"slashing_info\""
];
string stake_noz_rate = 6 [
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "stake_noz_rate",
(gogoproto.moretags) = "yaml:\"stake_noz_rate\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec"
]; //fixed rate of stake over noz
}

message GenesisMetaNode {
string network_address = 1 [
(gogoproto.jsontag) = "network_address",
(gogoproto.moretags) = "yaml:\"network_address\""
]; // network address of the meta node
google.protobuf.Any pubkey = 2 [
(cosmos_proto.accepts_interface) = "cosmos.crypto.PubKey",
(gogoproto.jsontag) = "pubkey",
(gogoproto.moretags) = "yaml:\"pubkey\""
]; // the consensus public key of the meta node; bech encoded in JSON
bool suspend = 3 [
(gogoproto.jsontag) = "suspend",
(gogoproto.moretags) = "yaml:\"suspend\""
]; // has the meta node been suspended from bonded status?
cosmos.staking.v1beta1.BondStatus status = 4 [
(gogoproto.jsontag) = "status",
(gogoproto.moretags) = "yaml:\"status\""
]; // meta node status (Unspecified/Bonded/Unbonding/Unbonded)
string tokens = 5 [
(gogoproto.moretags) = "yaml:\"token\""
(gogoproto.jsontag) = "tokens",
(gogoproto.moretags) = "yaml:\"tokens\""
]; // delegated tokens
string owner_address = 6 [
(gogoproto.jsontag) = "owner_address",
(gogoproto.moretags) = "yaml:\"owner_address\""
]; // owner address of the meta node
Description description = 7 [
(gogoproto.moretags) = "yaml:\"description\",omitempty"
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "description",
(gogoproto.moretags) = "yaml:\"description\""
]; // description terms for the meta node
}

Expand Down
8 changes: 5 additions & 3 deletions proto/stratos/register/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ message StakingInfo {
(gogoproto.jsontag) = "status",
(gogoproto.moretags) = "yaml:\"status\""];
string tokens = 5 [
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "tokens",
(gogoproto.moretags) = "yaml:\"tokens\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int"
Expand All @@ -181,6 +182,7 @@ message StakingInfo {
(gogoproto.moretags) = "yaml:\"owner_address\""
];
Description description = 7 [
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "description",
(gogoproto.moretags) = "yaml:\"description\""
];
Expand All @@ -195,17 +197,17 @@ message StakingInfo {
(gogoproto.moretags) = "yaml:\"node_type\""
];
cosmos.base.v1beta1.Coin bonded_stake = 10 [
(gogoproto.nullable) = true,
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "bonded_stake",
(gogoproto.moretags) = "yaml:\"bonded_stake\""
];
cosmos.base.v1beta1.Coin un_bonding_stake = 11 [
(gogoproto.nullable) = true,
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "un_bonding_stake",
(gogoproto.moretags) = "yaml:\"un_bonding_stake\""
];
cosmos.base.v1beta1.Coin un_bonded_stake = 12 [
(gogoproto.nullable) = true,
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "un_bonded_stake",
(gogoproto.moretags) = "yaml:\"un_bonded_stake\""
];
Expand Down
9 changes: 9 additions & 0 deletions proto/stratos/register/v1/register.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "google/protobuf/any.proto";
import "google/protobuf/timestamp.proto";
import "google/protobuf/duration.proto";
import "cosmos_proto/cosmos.proto";
import "cosmos/base/v1beta1/coin.proto";
import "cosmos/staking/v1beta1/staking.proto";

option go_package = "github.com/stratosnet/stratos-chain/x/register/types";
Expand Down Expand Up @@ -33,8 +34,14 @@ message Params {
(gogoproto.moretags) = "yaml:\"max_entries\",omitempty"
];
bool resource_node_reg_enabled = 5 [
(gogoproto.jsontag) = "resource_node_reg_enabled",
(gogoproto.moretags) = "yaml:\"resource_node_reg_enabled\""
];
cosmos.base.v1beta1.Coin resource_node_min_stake = 6 [
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "resource_node_min_stake",
(gogoproto.moretags) = "yaml:\"resource_node_min_stake\""
];
}

message ResourceNode {
Expand Down Expand Up @@ -68,6 +75,7 @@ message ResourceNode {
(gogoproto.moretags) = "yaml:\"owner_address\""
];
Description description = 7 [
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "description",
(gogoproto.moretags) = "yaml:\"description\""
];
Expand Down Expand Up @@ -120,6 +128,7 @@ message MetaNode {
(gogoproto.moretags) = "yaml:\"owner_address\""
];
Description description = 7 [
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "description",
(gogoproto.moretags) = "yaml:\"description\""
];
Expand Down
6 changes: 2 additions & 4 deletions proto/stratos/register/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ message MsgCreateResourceNode {
(gogoproto.moretags) = "yaml:\"owner_address\""
];
Description description = 5 [
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "description",
(gogoproto.moretags) = "yaml:\"description\""
];
Expand Down Expand Up @@ -103,6 +104,7 @@ message MsgCreateMetaNode {
(gogoproto.moretags) = "yaml:\"owner_address\""
];
Description description = 5 [
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "description",
(gogoproto.moretags) = "yaml:\"description\""
];
Expand Down Expand Up @@ -199,10 +201,6 @@ message MsgUpdateResourceNodeStake {
(gogoproto.jsontag) = "owner_address",
(gogoproto.moretags) = "yaml:\"owner_address\""
];
bool incr_stake = 3 [
(gogoproto.jsontag) = "incr_stake",
(gogoproto.moretags) = "yaml:\"incr_stake\""
];
cosmos.base.v1beta1.Coin stake_delta = 4 [
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "stake_delta",
Expand Down
2 changes: 1 addition & 1 deletion x/pot/keeper/distribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ func (k Keeper) GetTotalConsumedNoz(trafficList []types.SingleWalletVolume) sdk.
totalTraffic := sdk.ZeroInt()
for _, vol := range trafficList {
toAdd := vol.Volume
totalTraffic = totalTraffic.Add(*toAdd)
totalTraffic = totalTraffic.Add(toAdd)
}
return totalTraffic
}
Expand Down
16 changes: 3 additions & 13 deletions x/register/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,6 @@ func UpdateResourceNodeStakeCmd() *cobra.Command {

_ = cmd.MarkFlagRequired(flags.FlagFrom)
_ = cmd.MarkFlagRequired(FlagStakeDelta)
_ = cmd.MarkFlagRequired(FlagIncrStake)
_ = cmd.MarkFlagRequired(FlagNetworkAddress)
return cmd
}
Expand Down Expand Up @@ -496,7 +495,7 @@ func newBuildUpdateResourceNodeMsg(clientCtx client.Context, txf tx.Factory, fs
if t := nodeType.Type(); t == "UNKNOWN" {
return txf, nil, types.ErrNodeType
}
msg := types.NewMsgUpdateResourceNode(*description, nodeTypeVal, networkAddr, ownerAddr)
msg := types.NewMsgUpdateResourceNode(description, nodeTypeVal, networkAddr, ownerAddr)
return txf, msg, nil
}

Expand Down Expand Up @@ -526,7 +525,7 @@ func newBuildUpdateMetaNodeMsg(clientCtx client.Context, txf tx.Factory, fs *fla
details,
)

msg := types.NewMsgUpdateMetaNode(*description, networkAddr, ownerAddr)
msg := types.NewMsgUpdateMetaNode(description, networkAddr, ownerAddr)
return txf, msg, nil
}

Expand All @@ -541,15 +540,6 @@ func newBuildUpdateResourceNodeStakeMsg(clientCtx client.Context, txf tx.Factory
return txf, nil, err
}

incrStakeStr, err := fs.GetString(FlagIncrStake)
if err != nil {
return txf, nil, err
}
incrStake, err := strconv.ParseBool(incrStakeStr)
if err != nil {
return txf, nil, err
}

networkAddrStr, _ := fs.GetString(FlagNetworkAddress)
networkAddr, err := stratos.SdsAddressFromBech32(networkAddrStr)
if err != nil {
Expand All @@ -558,7 +548,7 @@ func newBuildUpdateResourceNodeStakeMsg(clientCtx client.Context, txf tx.Factory

ownerAddr := clientCtx.GetFromAddress()

msg := types.NewMsgUpdateResourceNodeStake(networkAddr, ownerAddr, stakeDelta, incrStake)
msg := types.NewMsgUpdateResourceNodeStake(networkAddr, ownerAddr, stakeDelta)
return txf, msg, nil
}

Expand Down
12 changes: 3 additions & 9 deletions x/register/client/rest/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ type (
BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"`
NetworkAddress string `json:"network_address" yaml:"network_address"`
StakeDelta sdk.Coin `json:"stake_delta" yaml:"stake_delta"`
IncrStake string `json:"incr_stake" yaml:"incr_stake"`
}

UpdateEffectiveStakeRequest struct {
Expand Down Expand Up @@ -166,7 +165,7 @@ func postCreateResourceNodeHandlerFn(cliCtx client.Context) http.HandlerFunc {
return
}

msg, err := types.NewMsgCreateResourceNode(networkAddr, pubKey, req.Amount, ownerAddr, &req.Description,
msg, err := types.NewMsgCreateResourceNode(networkAddr, pubKey, req.Amount, ownerAddr, req.Description,
req.NodeType)
if err := msg.ValidateBasic(); err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
Expand Down Expand Up @@ -206,7 +205,7 @@ func postCreateMetaNodeHandlerFn(cliCtx client.Context) http.HandlerFunc {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}
msg, err := types.NewMsgCreateMetaNode(networkAddr, pubKey, req.Amount, ownerAddr, &req.Description)
msg, err := types.NewMsgCreateMetaNode(networkAddr, pubKey, req.Amount, ownerAddr, req.Description)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
Expand Down Expand Up @@ -354,12 +353,7 @@ func postUpdateResourceNodeStakeHandlerFn(cliCtx client.Context) http.HandlerFun
return
}

incrStake, err := strconv.ParseBool(req.IncrStake)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}
msg := types.NewMsgUpdateResourceNodeStake(networkAddr, ownerAddr, req.StakeDelta, incrStake)
msg := types.NewMsgUpdateResourceNodeStake(networkAddr, ownerAddr, req.StakeDelta)
if err := msg.ValidateBasic(); err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
Expand Down
13 changes: 3 additions & 10 deletions x/register/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
// InitGenesis initialize default parameters
// and the keeper's address to pubkey map
func InitGenesis(ctx sdk.Context, keeper keeper.Keeper, data *types.GenesisState) {
keeper.SetParams(ctx, *data.Params)
keeper.SetParams(ctx, data.Params)

freshStart := keeper.GetResourceNodeNotBondedToken(ctx).IsZero() &&
keeper.GetResourceNodeBondedToken(ctx).IsZero() &&
Expand Down Expand Up @@ -134,7 +134,7 @@ func ExportGenesis(ctx sdk.Context, keeper keeper.Keeper) (data *types.GenesisSt
remainingNozLimit := keeper.GetRemainingOzoneLimit(ctx)
stakeNozRate := keeper.GetStakeNozRate(ctx)

var slashingInfo []*types.Slashing
var slashingInfo []types.Slashing
keeper.IteratorSlashingInfo(ctx, func(walletAddress sdk.AccAddress, val sdk.Int) (stop bool) {
if val.GT(sdk.ZeroInt()) {
slashing := types.NewSlashing(walletAddress, val)
Expand All @@ -143,12 +143,5 @@ func ExportGenesis(ctx sdk.Context, keeper keeper.Keeper) (data *types.GenesisSt
return false
})

return &types.GenesisState{
Params: &params,
ResourceNodes: resourceNodes,
MetaNodes: metaNodes,
RemainingNozLimit: remainingNozLimit,
Slashing: slashingInfo,
StakeNozRate: stakeNozRate,
}
return types.NewGenesisState(params, resourceNodes, metaNodes, remainingNozLimit, slashingInfo, stakeNozRate)
}
Loading