Skip to content

Commit

Permalink
updatestake to restore sp's ppstore
Browse files Browse the repository at this point in the history
  • Loading branch information
WangLiStratos committed Jan 30, 2023
1 parent e439d8e commit b36d134
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
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

0 comments on commit b36d134

Please sign in to comment.