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: implemente Msgs for SP exit #534

Merged
merged 30 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
312358c
implemente Msgs for SP exit
alexgao001 Dec 1, 2023
c14218a
add tests
alexgao001 Dec 4, 2023
4d62bb6
add tests
alexgao001 Dec 4, 2023
44430c3
fix proto format
alexgao001 Dec 4, 2023
0f55d6d
fix test
alexgao001 Dec 4, 2023
1d61fbd
expose the gvg statistic api for query
alexgao001 Dec 6, 2023
6ae1971
transfer deposit of forced exit SP to payment module when exit completed
alexgao001 Dec 12, 2023
18998e1
fix test
alexgao001 Dec 12, 2023
5f590ad
fix comments
alexgao001 Dec 14, 2023
72fe38f
fix conflict
alexgao001 Dec 14, 2023
22e3b8d
fix comments
alexgao001 Dec 14, 2023
a107f1d
fix comment
alexgao001 Dec 15, 2023
3ad7c09
fix comment
alexgao001 Dec 18, 2023
32cb871
format code
alexgao001 Dec 18, 2023
2828906
fix swagger yaml due to outdated buf version
alexgao001 Dec 18, 2023
260c500
refine the code
alexgao001 Dec 18, 2023
91611a9
fix SetUpgradeInitializer
alexgao001 Dec 18, 2023
142bf7b
fix SetUpgradeInitializer
alexgao001 Dec 18, 2023
629afa3
use queried SP deposit in test
alexgao001 Dec 18, 2023
69af6af
Merge branch 'adapt-sp-exit' of github.com:bnb-chain/greenfield into …
alexgao001 Dec 18, 2023
df63086
enable bucket migration
alexgao001 Dec 18, 2023
1c66afe
fix duplicate gvgs in test
alexgao001 Dec 18, 2023
3443fd4
allow reserved swapin expired SP to continue acquire data if no other…
alexgao001 Dec 19, 2023
b0c9b53
forced exit SP staked BNB transfer to payment module gov stream recor…
alexgao001 Dec 19, 2023
f504e90
add test
alexgao001 Dec 19, 2023
28c6e32
fix test assertion due to duplicate GVG not allowed
alexgao001 Dec 20, 2023
2d4c29d
Merge branch 'develop' of github.com:bnb-chain/greenfield into adapt-…
alexgao001 Dec 21, 2023
ba19800
fix the new params validation failed when init genesis
alexgao001 Dec 21, 2023
0b4d1f0
fix swagger
alexgao001 Dec 21, 2023
510b91c
fix test
alexgao001 Dec 21, 2023
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
33 changes: 33 additions & 0 deletions app/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
paymentmodule "github.com/bnb-chain/greenfield/x/payment"
paymenttypes "github.com/bnb-chain/greenfield/x/payment/types"
storagemoduletypes "github.com/bnb-chain/greenfield/x/storage/types"
virtualgroupmodule "github.com/bnb-chain/greenfield/x/virtualgroup"
virtualgrouptypes "github.com/bnb-chain/greenfield/x/virtualgroup/types"
)

func (app *App) RegisterUpgradeHandlers(chainID string, serverCfg *serverconfig.Config) error {
Expand All @@ -24,6 +26,8 @@ func (app *App) RegisterUpgradeHandlers(chainID string, serverCfg *serverconfig.
app.registerNagquUpgradeHandler()
app.registerPampasUpgradeHandler()
app.registerManchurianUpgradeHandler()
app.registerHulunbeierUpgradeHandler()

// app.register...()
// ...
return nil
Expand Down Expand Up @@ -124,7 +128,36 @@ func (app *App) registerManchurianUpgradeHandler() {
app.UpgradeKeeper.SetUpgradeInitializer(upgradetypes.Manchurian,
func() error {
app.Logger().Info("Init Manchurian upgrade")
return nil
})
}

func (app *App) registerHulunbeierUpgradeHandler() {
// Register the upgrade handler
app.UpgradeKeeper.SetUpgradeHandler(upgradetypes.Hulunbeier,
func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
app.Logger().Info("upgrade to ", plan.Name)

// enable SP exit
app.GashubKeeper.SetMsgGasParams(ctx, *gashubtypes.NewMsgGasParamsWithFixedGas(sdk.MsgTypeURL(&virtualgrouptypes.MsgReserveSwapIn{}), 1.2e3))
app.GashubKeeper.SetMsgGasParams(ctx, *gashubtypes.NewMsgGasParamsWithFixedGas(sdk.MsgTypeURL(&virtualgrouptypes.MsgCancelSwapIn{}), 1.2e3))
app.GashubKeeper.SetMsgGasParams(ctx, *gashubtypes.NewMsgGasParamsWithFixedGas(sdk.MsgTypeURL(&virtualgrouptypes.MsgCompleteSwapIn{}), 1.2e3))
app.GashubKeeper.SetMsgGasParams(ctx, *gashubtypes.NewMsgGasParamsWithFixedGas(sdk.MsgTypeURL(&virtualgrouptypes.MsgStorageProviderForcedExit{}), 1.2e3))
app.GashubKeeper.SetMsgGasParams(ctx, *gashubtypes.NewMsgGasParamsWithFixedGas(sdk.MsgTypeURL(&virtualgrouptypes.MsgStorageProviderExit{}), 1.2e3))
app.GashubKeeper.SetMsgGasParams(ctx, *gashubtypes.NewMsgGasParamsWithFixedGas(sdk.MsgTypeURL(&virtualgrouptypes.MsgCompleteStorageProviderExit{}), 1.2e3))

return app.mm.RunMigrations(ctx, app.configurator, fromVM)
})

// Register the upgrade initializer
app.UpgradeKeeper.SetUpgradeInitializer(upgradetypes.Hulunbeier,
func() error {
app.Logger().Info("Init Hulunbeier upgrade")
mm, ok := app.mm.Modules[virtualgrouptypes.ModuleName].(*virtualgroupmodule.AppModule)
if !ok {
panic("*virtualgroupmodule.AppModule not found")
}
mm.SetConsensusVersion(2)
return nil
})
}
1 change: 1 addition & 0 deletions deployment/localup/localup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ function generate_genesis() {
echo -e '[[upgrade]]\nname = "Nagqu"\nheight = 20\ninfo = ""' >> ${workspace}/.local/validator${i}/config/app.toml
echo -e '[[upgrade]]\nname = "Pampas"\nheight = 20\ninfo = ""' >> ${workspace}/.local/validator${i}/config/app.toml
echo -e '[[upgrade]]\nname = "Manchurian"\nheight = 20\ninfo = ""' >> ${workspace}/.local/validator${i}/config/app.toml
echo -e '[[upgrade]]\nname = "Hulunbeier"\nheight = 21\ninfo = ""' >> ${workspace}/.local/validator${i}/config/app.toml
done

# enable swagger API for validator0
Expand Down
21 changes: 21 additions & 0 deletions e2e/core/basesuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/prysmaticlabs/prysm/crypto/bls"
"github.com/spf13/cobra"
"github.com/stretchr/testify/suite"
"golang.org/x/exp/slices"

"github.com/bnb-chain/greenfield/cmd/gnfd/cmd"
"github.com/bnb-chain/greenfield/sdk/client"
Expand Down Expand Up @@ -682,6 +683,17 @@ func (s *BaseSuite) CreateObject(user keys.KeyManager, primarySP *StorageProvide
}

func (s *BaseSuite) CreateGlobalVirtualGroup(sp *StorageProvider, familyID uint32, secondarySPIDs []uint32, depositAmount int64) (uint32, uint32) {

// check if the GVG already exits
if familyID != 0 {
resp, _ := s.Client.GlobalVirtualGroupByFamilyID(context.Background(), &virtualgroupmoduletypes.QueryGlobalVirtualGroupByFamilyIDRequest{GlobalVirtualGroupFamilyId: familyID})
for _, gvg := range resp.GlobalVirtualGroups {
if slices.Equal(secondarySPIDs, gvg.SecondarySpIds) {
return gvg.Id, familyID
}
}
}

// Create a GVG for each sp by default
deposit := sdk.Coin{
Denom: s.Config.Denom,
Expand Down Expand Up @@ -733,6 +745,15 @@ func (s *BaseSuite) PickStorageProvider() *StorageProvider {
return nil
}

func (s *BaseSuite) PickStorageProviderByID(id uint32) *StorageProvider {
for _, sp := range s.StorageProviders {
if sp.Info.Id == id {
return sp
}
}
return nil
}

func (s *BaseSuite) PickDifferentStorageProvider(spId uint32) *StorageProvider {
for _, sp := range s.StorageProviders {
if sp.Info.Id != spId {
Expand Down
68 changes: 35 additions & 33 deletions e2e/tests/sp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ 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 @@ -37,39 +38,40 @@ 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(),
Operator: 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