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

fix: add sp exit status check when craete gvg #433

Merged
merged 2 commits into from
Aug 23, 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
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
Loading