From 912f056164425ba45b44b5f0b3b4101188bae6ad Mon Sep 17 00:00:00 2001 From: Fynn Date: Wed, 23 Aug 2023 13:58:26 +0800 Subject: [PATCH] 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 --- x/sp/types/types.go | 4 ++++ x/virtualgroup/keeper/msg_server.go | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/x/sp/types/types.go b/x/sp/types/types.go index 76bad99f9..b23bee951 100644 --- a/x/sp/types/types.go +++ b/x/sp/types/types.go @@ -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 diff --git a/x/virtualgroup/keeper/msg_server.go b/x/virtualgroup/keeper/msg_server.go index 4ee5e956f..727e8613a 100644 --- a/x/virtualgroup/keeper/msg_server.go +++ b/x/virtualgroup/keeper/msg_server.go @@ -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) @@ -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 {