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

feat/QB-1573_QB-1610 updatestake to restore sp's ppstore #208

Merged
merged 1 commit into from
Jan 31, 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
3 changes: 2 additions & 1 deletion x/register/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ func (k msgServer) HandleMsgUpdateResourceNodeStake(goCtx context.Context, msg *
return &types.MsgUpdateResourceNodeStakeResponse{}, errors.New("invalid stake delta")
}

ozoneLimitChange, completionTime, err := k.UpdateResourceNodeStake(ctx, networkAddr, ownerAddress, *msg.StakeDelta, msg.IncrStake)
ozoneLimitChange, completionTime, node, err := k.UpdateResourceNodeStake(ctx, networkAddr, ownerAddress, *msg.StakeDelta, msg.IncrStake)
if err != nil {
return nil, sdkerrors.Wrap(types.ErrUpdateResourceNodeStake, err.Error())
}
Expand All @@ -333,6 +333,7 @@ func (k msgServer) HandleMsgUpdateResourceNodeStake(goCtx context.Context, msg *
sdk.NewAttribute(types.AttributeKeyNetworkAddress, msg.NetworkAddress),
sdk.NewAttribute(types.AttributeKeyIncrStakeBool, strconv.FormatBool(msg.IncrStake)),
sdk.NewAttribute(types.AttributeKeyStakeDelta, msg.StakeDelta.String()),
sdk.NewAttribute(types.AttributeKeyCurrentStake, sdk.NewCoin(k.BondDenom(ctx), node.Tokens).String()),
sdk.NewAttribute(types.AttributeKeyOZoneLimitChanges, ozoneLimitChange.String()),
sdk.NewAttribute(types.AttributeKeyUnbondingMatureTime, completionTime.Format(time.RFC3339)),
),
Expand Down
16 changes: 8 additions & 8 deletions x/register/keeper/resource_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,36 +317,36 @@ func (k Keeper) UpdateResourceNode(ctx sdk.Context, description types.Descriptio
}

func (k Keeper) UpdateResourceNodeStake(ctx sdk.Context, networkAddr stratos.SdsAddress, ownerAddr sdk.AccAddress,
stakeDelta sdk.Coin, incrStake bool) (ozoneLimitChange sdk.Int, unbondingMatureTime time.Time, err error) {
stakeDelta sdk.Coin, incrStake bool) (ozoneLimitChange sdk.Int, unbondingMatureTime time.Time, resourcenode types.ResourceNode, err error) {

blockTime := ctx.BlockHeader().Time
node, found := k.GetResourceNode(ctx, networkAddr)
if !found {
return sdk.ZeroInt(), blockTime, types.ErrNoResourceNodeFound
return sdk.ZeroInt(), blockTime, node, types.ErrNoResourceNodeFound
}

ownerAddrNode, _ := sdk.AccAddressFromBech32(node.GetOwnerAddress())
if !bytes.Equal(ownerAddrNode, ownerAddr) {
return sdk.ZeroInt(), blockTime, types.ErrInvalidOwnerAddr
return sdk.ZeroInt(), blockTime, node, types.ErrInvalidOwnerAddr
}

if incrStake {
ozoneLimitChange, err := k.AddResourceNodeStake(ctx, node, stakeDelta)
if err != nil {
return sdk.ZeroInt(), blockTime, err
return sdk.ZeroInt(), blockTime, node, err
}
return ozoneLimitChange, blockTime, nil
return ozoneLimitChange, blockTime, node, nil
} else {
// if !incrStake
if node.GetStatus() == stakingtypes.Unbonding {
return sdk.ZeroInt(), blockTime, types.ErrUnbondingNode
return sdk.ZeroInt(), blockTime, node, types.ErrUnbondingNode
}

ozoneLimitChange, completionTime, err := k.UnbondResourceNode(ctx, node, stakeDelta.Amount)
if err != nil {
return sdk.ZeroInt(), blockTime, err
return sdk.ZeroInt(), blockTime, node, err
}
return ozoneLimitChange, completionTime, nil
return ozoneLimitChange, completionTime, node, nil
}
}

Expand Down
1 change: 1 addition & 0 deletions x/register/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const (

AttributeKeyOZoneLimitChanges = "ozone_limit_changes"
AttributeKeyInitialStake = "initial_stake"
AttributeKeyCurrentStake = "current_stake"
AttributeKeyStakeDelta = "stake_delta"
AttributeKeyStakeToRemove = "stake_to_remove"
AttributeKeyIncrStakeBool = "incr_stake"
Expand Down