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

feat: disable sp exit and bucket migration msg #521

Merged
merged 2 commits into from
Nov 9, 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
14 changes: 11 additions & 3 deletions app/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
serverconfig "github.com/cosmos/cosmos-sdk/server/config"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/gashub/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

bridgemoduletypes "github.com/bnb-chain/greenfield/x/bridge/types"
Expand Down Expand Up @@ -80,8 +79,17 @@ func (app *App) registerPampasUpgradeHandler() {
app.CrossChainKeeper.SetChannelSendPermission(ctx, sdk.ChainID(app.appConfig.CrossChain.DestOpChainId), storagemoduletypes.ObjectChannelId, sdk.ChannelAllow)
app.CrossChainKeeper.SetChannelSendPermission(ctx, sdk.ChainID(app.appConfig.CrossChain.DestOpChainId), storagemoduletypes.GroupChannelId, sdk.ChannelAllow)

// register MsgRejectMigrateBucket Gas param
app.GashubKeeper.SetMsgGasParams(ctx, *types.NewMsgGasParamsWithFixedGas("/greenfield.storage.MsgRejectMigrateBucket", 1.2e3))
// disable sp exit
app.GashubKeeper.DeleteMsgGasParams(ctx, "/greenfield.virtualgroup.MsgSwapOut")
app.GashubKeeper.DeleteMsgGasParams(ctx, "/greenfield.virtualgroup.MsgCompleteSwapOut")
app.GashubKeeper.DeleteMsgGasParams(ctx, "/greenfield.virtualgroup.MsgCancelSwapOut")
app.GashubKeeper.DeleteMsgGasParams(ctx, "/greenfield.virtualgroup.MsgStorageProviderExit")
app.GashubKeeper.DeleteMsgGasParams(ctx, "/greenfield.virtualgroup.MsgCompleteStorageProviderExit")

// disable bucket migration.
app.GashubKeeper.DeleteMsgGasParams(ctx, "/greenfield.storage.MsgMigrateBucket")
app.GashubKeeper.DeleteMsgGasParams(ctx, "/greenfield.storage.MsgCancelMigrateBucket")
app.GashubKeeper.DeleteMsgGasParams(ctx, "/greenfield.storage.MsgCompleteMigrateBucket")

return app.mm.RunMigrations(ctx, app.configurator, fromVM)
})
Expand Down
200 changes: 100 additions & 100 deletions e2e/tests/payment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1169,106 +1169,106 @@ func (s *PaymentTestSuite) TestVirtualGroup_Settle() {
s.Require().Equal(streamRecordsAfter.Tax.NetflowRate.Sub(streamRecordsBefore.Tax.NetflowRate).Int64(), int64(0))
}

func (s *PaymentTestSuite) TestVirtualGroup_SwapOut() {
ctx := context.Background()
user := s.GenAndChargeAccounts(1, 1000000)[0]
successorSp := s.PickStorageProvider()

// create a new storage provider
sp := s.BaseSuite.CreateNewStorageProvider()
s.T().Logf("new SP Info: %s", sp.Info.String())

// create a new gvg group for this storage provider
var secondarySPIDs []uint32
for _, ssp := range s.StorageProviders {
if ssp.Info.Id != successorSp.Info.Id {
secondarySPIDs = append(secondarySPIDs, ssp.Info.Id)
}
if len(secondarySPIDs) == 6 {
break
}
}

gvgID, familyID := s.BaseSuite.CreateGlobalVirtualGroup(sp, 0, secondarySPIDs, 1)

// create object
s.BaseSuite.CreateObject(user, sp, gvgID, storagetestutils.GenRandomBucketName(), storagetestutils.GenRandomObjectName())

// Create another gvg contains this new sp
anotherSP := s.PickDifferentStorageProvider(successorSp.Info.Id)
var anotherSecondarySPIDs []uint32
for _, ssp := range s.StorageProviders {
if ssp.Info.Id != successorSp.Info.Id && ssp.Info.Id != anotherSP.Info.Id {
anotherSecondarySPIDs = append(anotherSecondarySPIDs, ssp.Info.Id)
}
if len(anotherSecondarySPIDs) == 5 {
break
}
}
anotherSecondarySPIDs = append(anotherSecondarySPIDs, sp.Info.Id)

anotherGVGID, _ := s.BaseSuite.CreateGlobalVirtualGroup(anotherSP, 0, anotherSecondarySPIDs, 1)

familyResp, err := s.Client.GlobalVirtualGroupFamily(ctx, &virtualgrouptypes.QueryGlobalVirtualGroupFamilyRequest{FamilyId: familyID})
s.Require().NoError(err)
gvgResp, err := s.Client.GlobalVirtualGroup(ctx, &virtualgrouptypes.QueryGlobalVirtualGroupRequest{GlobalVirtualGroupId: anotherGVGID})
s.Require().NoError(err)

streamAddresses := []string{
user.GetAddr().String(),
familyResp.GlobalVirtualGroupFamily.VirtualPaymentAddress,
gvgResp.GlobalVirtualGroup.VirtualPaymentAddress,
paymenttypes.ValidatorTaxPoolAddress.String(),
}
streamRecordsBefore := s.getStreamRecords(streamAddresses)

// sp exit
s.SendTxBlock(sp.OperatorKey, &virtualgrouptypes.MsgStorageProviderExit{
StorageProvider: sp.OperatorKey.GetAddr().String(),
})

resp, err := s.Client.StorageProvider(context.Background(), &sptypes.QueryStorageProviderRequest{Id: sp.Info.Id})
s.Require().NoError(err)
s.Require().Equal(resp.StorageProvider.Status, sptypes.STATUS_GRACEFUL_EXITING)

// swap out, as secondary sp
msgSwapOut2 := virtualgrouptypes.NewMsgSwapOut(sp.OperatorKey.GetAddr(), 0, []uint32{anotherGVGID}, successorSp.Info.Id)
msgSwapOut2.SuccessorSpApproval = &common.Approval{ExpiredHeight: math.MaxUint}
msgSwapOut2.SuccessorSpApproval.Sig, err = successorSp.ApprovalKey.Sign(msgSwapOut2.GetApprovalBytes())
s.Require().NoError(err)
s.SendTxBlock(sp.OperatorKey, msgSwapOut2)

// complete swap out
msgCompleteSwapOut2 := virtualgrouptypes.NewMsgCompleteSwapOut(successorSp.OperatorKey.GetAddr(), 0, []uint32{anotherGVGID})
s.Require().NoError(err)
s.SendTxBlock(successorSp.OperatorKey, msgCompleteSwapOut2)

// swap out, as primary sp
msgSwapOut := virtualgrouptypes.NewMsgSwapOut(sp.OperatorKey.GetAddr(), familyID, nil, successorSp.Info.Id)
msgSwapOut.SuccessorSpApproval = &common.Approval{ExpiredHeight: math.MaxUint}
msgSwapOut.SuccessorSpApproval.Sig, err = successorSp.ApprovalKey.Sign(msgSwapOut.GetApprovalBytes())
s.Require().NoError(err)
s.SendTxBlock(sp.OperatorKey, msgSwapOut)

// complete swap out, as primary sp
msgCompleteSwapOut := virtualgrouptypes.NewMsgCompleteSwapOut(successorSp.OperatorKey.GetAddr(), familyID, nil)
s.Require().NoError(err)
s.SendTxBlock(successorSp.OperatorKey, msgCompleteSwapOut)

// sp complete exit success
s.SendTxBlock(
sp.OperatorKey,
&virtualgrouptypes.MsgCompleteStorageProviderExit{StorageProvider: sp.OperatorKey.GetAddr().String()},
)

// assertions
streamRecordsAfter := s.getStreamRecords(streamAddresses)

s.Require().Equal(streamRecordsAfter.User.NetflowRate.Sub(streamRecordsBefore.User.NetflowRate).Int64(), int64(0))
s.Require().Equal(streamRecordsAfter.GVGFamily.NetflowRate.Sub(streamRecordsBefore.GVGFamily.NetflowRate).Int64(), int64(0))
s.Require().Equal(streamRecordsAfter.GVG.NetflowRate.Sub(streamRecordsBefore.GVG.NetflowRate).Int64(), int64(0))
s.Require().Equal(streamRecordsAfter.Tax.NetflowRate.Sub(streamRecordsBefore.Tax.NetflowRate).Int64(), int64(0))
}
//func (s *PaymentTestSuite) TestVirtualGroup_SwapOut() {
// ctx := context.Background()
// user := s.GenAndChargeAccounts(1, 1000000)[0]
// successorSp := s.PickStorageProvider()
//
// // create a new storage provider
// sp := s.BaseSuite.CreateNewStorageProvider()
// s.T().Logf("new SP Info: %s", sp.Info.String())
//
// // create a new gvg group for this storage provider
// var secondarySPIDs []uint32
// for _, ssp := range s.StorageProviders {
// if ssp.Info.Id != successorSp.Info.Id {
// secondarySPIDs = append(secondarySPIDs, ssp.Info.Id)
// }
// if len(secondarySPIDs) == 6 {
// break
// }
// }
//
// gvgID, familyID := s.BaseSuite.CreateGlobalVirtualGroup(sp, 0, secondarySPIDs, 1)
//
// // create object
// s.BaseSuite.CreateObject(user, sp, gvgID, storagetestutils.GenRandomBucketName(), storagetestutils.GenRandomObjectName())
//
// // Create another gvg contains this new sp
// anotherSP := s.PickDifferentStorageProvider(successorSp.Info.Id)
// var anotherSecondarySPIDs []uint32
// for _, ssp := range s.StorageProviders {
// if ssp.Info.Id != successorSp.Info.Id && ssp.Info.Id != anotherSP.Info.Id {
// anotherSecondarySPIDs = append(anotherSecondarySPIDs, ssp.Info.Id)
// }
// if len(anotherSecondarySPIDs) == 5 {
// break
// }
// }
// anotherSecondarySPIDs = append(anotherSecondarySPIDs, sp.Info.Id)
//
// anotherGVGID, _ := s.BaseSuite.CreateGlobalVirtualGroup(anotherSP, 0, anotherSecondarySPIDs, 1)
//
// familyResp, err := s.Client.GlobalVirtualGroupFamily(ctx, &virtualgrouptypes.QueryGlobalVirtualGroupFamilyRequest{FamilyId: familyID})
// s.Require().NoError(err)
// gvgResp, err := s.Client.GlobalVirtualGroup(ctx, &virtualgrouptypes.QueryGlobalVirtualGroupRequest{GlobalVirtualGroupId: anotherGVGID})
// s.Require().NoError(err)
//
// streamAddresses := []string{
// user.GetAddr().String(),
// familyResp.GlobalVirtualGroupFamily.VirtualPaymentAddress,
// gvgResp.GlobalVirtualGroup.VirtualPaymentAddress,
// paymenttypes.ValidatorTaxPoolAddress.String(),
// }
// streamRecordsBefore := s.getStreamRecords(streamAddresses)
//
// // sp exit
// s.SendTxBlock(sp.OperatorKey, &virtualgrouptypes.MsgStorageProviderExit{
// StorageProvider: sp.OperatorKey.GetAddr().String(),
// })
//
// resp, err := s.Client.StorageProvider(context.Background(), &sptypes.QueryStorageProviderRequest{Id: sp.Info.Id})
// s.Require().NoError(err)
// s.Require().Equal(resp.StorageProvider.Status, sptypes.STATUS_GRACEFUL_EXITING)
//
// // swap out, as secondary sp
// msgSwapOut2 := virtualgrouptypes.NewMsgSwapOut(sp.OperatorKey.GetAddr(), 0, []uint32{anotherGVGID}, successorSp.Info.Id)
// msgSwapOut2.SuccessorSpApproval = &common.Approval{ExpiredHeight: math.MaxUint}
// msgSwapOut2.SuccessorSpApproval.Sig, err = successorSp.ApprovalKey.Sign(msgSwapOut2.GetApprovalBytes())
// s.Require().NoError(err)
// s.SendTxBlock(sp.OperatorKey, msgSwapOut2)
//
// // complete swap out
// msgCompleteSwapOut2 := virtualgrouptypes.NewMsgCompleteSwapOut(successorSp.OperatorKey.GetAddr(), 0, []uint32{anotherGVGID})
// s.Require().NoError(err)
// s.SendTxBlock(successorSp.OperatorKey, msgCompleteSwapOut2)
//
// // swap out, as primary sp
// msgSwapOut := virtualgrouptypes.NewMsgSwapOut(sp.OperatorKey.GetAddr(), familyID, nil, successorSp.Info.Id)
// msgSwapOut.SuccessorSpApproval = &common.Approval{ExpiredHeight: math.MaxUint}
// msgSwapOut.SuccessorSpApproval.Sig, err = successorSp.ApprovalKey.Sign(msgSwapOut.GetApprovalBytes())
// s.Require().NoError(err)
// s.SendTxBlock(sp.OperatorKey, msgSwapOut)
//
// // complete swap out, as primary sp
// msgCompleteSwapOut := virtualgrouptypes.NewMsgCompleteSwapOut(successorSp.OperatorKey.GetAddr(), familyID, nil)
// s.Require().NoError(err)
// s.SendTxBlock(successorSp.OperatorKey, msgCompleteSwapOut)
//
// // sp complete exit success
// s.SendTxBlock(
// sp.OperatorKey,
// &virtualgrouptypes.MsgCompleteStorageProviderExit{StorageProvider: sp.OperatorKey.GetAddr().String()},
// )
//
// // assertions
// streamRecordsAfter := s.getStreamRecords(streamAddresses)
//
// s.Require().Equal(streamRecordsAfter.User.NetflowRate.Sub(streamRecordsBefore.User.NetflowRate).Int64(), int64(0))
// s.Require().Equal(streamRecordsAfter.GVGFamily.NetflowRate.Sub(streamRecordsBefore.GVGFamily.NetflowRate).Int64(), int64(0))
// s.Require().Equal(streamRecordsAfter.GVG.NetflowRate.Sub(streamRecordsBefore.GVG.NetflowRate).Int64(), int64(0))
// s.Require().Equal(streamRecordsAfter.Tax.NetflowRate.Sub(streamRecordsBefore.Tax.NetflowRate).Int64(), int64(0))
//}

func (s *PaymentTestSuite) TestDiscontinue_InOneBlock_WithoutPriceChange() {
ctx := context.Background()
Expand Down
67 changes: 33 additions & 34 deletions e2e/tests/sp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/bnb-chain/greenfield/sdk/types"
"github.com/bnb-chain/greenfield/testutil/sample"
sptypes "github.com/bnb-chain/greenfield/x/sp/types"
virtualgroupmoduletypes "github.com/bnb-chain/greenfield/x/virtualgroup/types"
)

type StorageProviderTestSuite struct {
Expand All @@ -38,39 +37,39 @@ func (s *StorageProviderTestSuite) SetupSuite() {
func (s *StorageProviderTestSuite) SetupTest() {
}

func (s *StorageProviderTestSuite) TestCreateStorageProvider() {
// Create a New SP
sp := s.BaseSuite.CreateNewStorageProvider()

// query sp by id
querySPResp, err := s.Client.StorageProvider(context.Background(), &sptypes.QueryStorageProviderRequest{
Id: sp.Info.Id,
})
s.Require().NoError(err)
s.Require().Equal(querySPResp.StorageProvider, querySPResp.StorageProvider)

// sp exit
msgSPExit := virtualgroupmoduletypes.MsgStorageProviderExit{
StorageProvider: sp.OperatorKey.GetAddr().String(),
}
s.SendTxBlock(sp.OperatorKey, &msgSPExit)

// 9 query sp status
querySPResp2, err := s.Client.StorageProvider(context.Background(), &sptypes.QueryStorageProviderRequest{Id: sp.Info.Id})
s.Require().NoError(err)
s.Require().Equal(querySPResp2.StorageProvider.Status, sptypes.STATUS_GRACEFUL_EXITING)

// 10 complete sp exit
msgCompleteSPExit := virtualgroupmoduletypes.MsgCompleteStorageProviderExit{
StorageProvider: sp.OperatorKey.GetAddr().String(),
}

s.SendTxBlock(sp.OperatorKey, &msgCompleteSPExit)

// 10 query sp
_, err = s.Client.StorageProvider(context.Background(), &sptypes.QueryStorageProviderRequest{Id: sp.Info.Id})
s.Require().Error(err)
}
//func (s *StorageProviderTestSuite) TestCreateStorageProvider() {
// // Create a New SP
// sp := s.BaseSuite.CreateNewStorageProvider()
//
// // query sp by id
// querySPResp, err := s.Client.StorageProvider(context.Background(), &sptypes.QueryStorageProviderRequest{
// Id: sp.Info.Id,
// })
// s.Require().NoError(err)
// s.Require().Equal(querySPResp.StorageProvider, querySPResp.StorageProvider)
//
// // sp exit
// msgSPExit := virtualgroupmoduletypes.MsgStorageProviderExit{
// StorageProvider: sp.OperatorKey.GetAddr().String(),
// }
// s.SendTxBlock(sp.OperatorKey, &msgSPExit)
//
// // 9 query sp status
// querySPResp2, err := s.Client.StorageProvider(context.Background(), &sptypes.QueryStorageProviderRequest{Id: sp.Info.Id})
// s.Require().NoError(err)
// s.Require().Equal(querySPResp2.StorageProvider.Status, sptypes.STATUS_GRACEFUL_EXITING)
//
// // 10 complete sp exit
// msgCompleteSPExit := virtualgroupmoduletypes.MsgCompleteStorageProviderExit{
// StorageProvider: sp.OperatorKey.GetAddr().String(),
// }
//
// s.SendTxBlock(sp.OperatorKey, &msgCompleteSPExit)
//
// // 10 query sp
// _, err = s.Client.StorageProvider(context.Background(), &sptypes.QueryStorageProviderRequest{Id: sp.Info.Id})
// s.Require().Error(err)
//}

func (s *StorageProviderTestSuite) TestEditStorageProvider() {
ctx := context.Background()
Expand Down
Loading
Loading