Skip to content

Commit

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

* add sp exit status check when create gvg and swapout

* allow sp in maintenance can create gvg

* check secondary sp in gvg
  • Loading branch information
fynnss authored Aug 24, 2023
1 parent 1f4af44 commit 235b7b7
Show file tree
Hide file tree
Showing 2 changed files with 15 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
11 changes: 11 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 All @@ -66,6 +70,10 @@ func (k msgServer) CreateGlobalVirtualGroup(goCtx context.Context, req *types.Ms
if !found {
return nil, sdkerrors.Wrapf(sptypes.ErrStorageProviderNotFound, "secondary sp not found, ID: %d", id)
}
if !ssp.IsInService() && !ssp.IsInMaintenance() {
return nil, sptypes.ErrStorageProviderNotInService.Wrapf("sp in GVG is not in service or in maintenance, status: %s", sp.Status.String())
}

secondarySpIds = append(secondarySpIds, ssp.Id)
gvgStatisticsWithinSP := k.GetOrCreateGVGStatisticsWithinSP(ctx, ssp.Id)
gvgStatisticsWithinSP.SecondaryCount++
Expand Down Expand Up @@ -272,6 +280,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 235b7b7

Please sign in to comment.