Skip to content

Commit

Permalink
fix: add sp exit status check when craete gvg (#433)
Browse files Browse the repository at this point in the history
* add sp exit status check when create gvg and swapout

* allow sp in maintenance can create gvg
  • Loading branch information
fynnss committed Aug 24, 2023
1 parent 1f4af44 commit 912f056
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions x/sp/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ func (sp *StorageProvider) IsInService() bool {
return sp.GetStatus() == STATUS_IN_SERVICE
}

func (sp *StorageProvider) IsInMaintenance() bool {
return sp.GetStatus() == STATUS_IN_MAINTENANCE
}

func (sp *StorageProvider) GetTotalDeposit() math.Int { return sp.TotalDeposit }

// constant used in flags to indicate that description field should not be updated
Expand Down
7 changes: 7 additions & 0 deletions x/virtualgroup/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ func (k msgServer) CreateGlobalVirtualGroup(goCtx context.Context, req *types.Ms
return nil, sptypes.ErrStorageProviderNotFound.Wrapf("The address must be operator address of sp.")
}

if !sp.IsInService() && !sp.IsInMaintenance() {
return nil, sptypes.ErrStorageProviderNotInService.Wrapf("sp is not in service or in maintenance, status: %s", sp.Status.String())
}

stat := k.GetOrCreateGVGStatisticsWithinSP(ctx, sp.Id)
stat.PrimaryCount++
gvgStatisticsWithinSPs = append(gvgStatisticsWithinSPs, stat)
Expand Down Expand Up @@ -272,6 +276,9 @@ func (k msgServer) SwapOut(goCtx context.Context, msg *types.MsgSwapOut) (*types
return nil, sptypes.ErrStorageProviderNotFound.Wrapf("successor sp not found.")
}

if !successorSP.IsInService() {
return nil, sptypes.ErrStorageProviderNotInService.Wrapf("successor sp is not in service, status: %s", sp.Status.String())
}
// verify the approval
err := gnfdtypes.VerifySignature(sdk.MustAccAddressFromHex(successorSP.ApprovalAddress), sdk.Keccak256(msg.GetApprovalBytes()), msg.SuccessorSpApproval.Sig)
if err != nil {
Expand Down

0 comments on commit 912f056

Please sign in to comment.