Skip to content

Commit

Permalink
feat: remove create object & bucket approval (#580)
Browse files Browse the repository at this point in the history
* feat: remove bucket get approval

* fix: add e2e tests

* fix: add enum strategy into req and fix e2e tests

* fix: add hardfork logic and remove delete vgf index

* fix: add hardfork logic and remove delete vgf index

* fix: add hardfork logic and remove delete vgf index

* fix: add hardfork logic and remove delete vgf index

* fix: UT

* fix: delete and set GVGFamilyStatistics after hard fork

* fix: strategy enum

* fix: strategy enum

* fix: prepare for Serengeti hardfork

* fix: prepare for Serengeti hardfork

* fix: go imports format

* fix: go imports format

* fix: rename function and change error description
  • Loading branch information
BarryTong65 authored Mar 7, 2024
1 parent a6c913a commit 6067133
Show file tree
Hide file tree
Showing 20 changed files with 1,969 additions and 270 deletions.
18 changes: 18 additions & 0 deletions app/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func (app *App) RegisterUpgradeHandlers(chainID string, serverCfg *serverconfig.
app.registerHulunbeierPatchUpgradeHandler()
app.registerUralUpgradeHandler()
app.registerPawneeUpgradeHandler()
app.registerSerengetiUpgradeHandler()
// app.register...()
// ...
return nil
Expand Down Expand Up @@ -215,3 +216,20 @@ func (app *App) registerPawneeUpgradeHandler() {
return nil
})
}

func (app *App) registerSerengetiUpgradeHandler() {
// Register the upgrade handler
app.UpgradeKeeper.SetUpgradeHandler(upgradetypes.Serengeti,
func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
app.Logger().Info("upgrade to ", plan.Name)
app.VirtualgroupKeeper.MigrateGlobalVirtualGroupFamiliesForSP(ctx)
return app.mm.RunMigrations(ctx, app.configurator, fromVM)
})

// Register the upgrade initializer
app.UpgradeKeeper.SetUpgradeInitializer(upgradetypes.Serengeti,
func() error {
app.Logger().Info("Init Serengeti upgrade")
return nil
})
}
1 change: 1 addition & 0 deletions deployment/localup/localup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ function generate_genesis() {
echo -e '[[upgrade]]\nname = "HulunbeierPatch"\nheight = 21\ninfo = ""' >> ${workspace}/.local/validator${i}/config/app.toml
echo -e '[[upgrade]]\nname = "Ural"\nheight = 22\ninfo = ""' >> ${workspace}/.local/validator${i}/config/app.toml
echo -e '[[upgrade]]\nname = "Pawnee"\nheight = 23\ninfo = ""' >> ${workspace}/.local/validator${i}/config/app.toml
echo -e '[[upgrade]]\nname = "Serengeti"\nheight = 24\ninfo = ""' >> ${workspace}/.local/validator${i}/config/app.toml
done

# enable swagger API for validator0
Expand Down
26 changes: 26 additions & 0 deletions e2e/tests/virtualgroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,27 @@ func (s *VirtualGroupTestSuite) queryGlobalVirtualGroupsByFamily(familyID uint32
return resp.GlobalVirtualGroups
}

func (s *VirtualGroupTestSuite) querySpAvailableGlobalVirtualGroupFamilies(spId uint32) []uint32 {
resp, err := s.Client.QuerySpAvailableGlobalVirtualGroupFamilies(
context.Background(),
&virtualgroupmoduletypes.QuerySPAvailableGlobalVirtualGroupFamiliesRequest{
SpId: spId,
})
s.Require().NoError(err)
return resp.GlobalVirtualGroupFamilyIds
}

func (s *VirtualGroupTestSuite) querySpOptimalGlobalVirtualGroupFamily(spId uint32, strategy virtualgroupmoduletypes.PickVGFStrategy) uint32 {
resp, err := s.Client.QuerySpOptimalGlobalVirtualGroupFamily(
context.Background(),
&virtualgroupmoduletypes.QuerySpOptimalGlobalVirtualGroupFamilyRequest{
SpId: spId,
PickVgfStrategy: strategy,
})
s.Require().NoError(err)
return resp.GlobalVirtualGroupFamilyId
}

func (s *VirtualGroupTestSuite) queryAvailableGlobalVirtualGroupFamilies(familyIds []uint32) []uint32 {
resp, err := s.Client.AvailableGlobalVirtualGroupFamilies(
context.Background(),
Expand Down Expand Up @@ -111,6 +132,11 @@ func (s *VirtualGroupTestSuite) TestBasic() {

availableGvgFamilyIds := s.queryAvailableGlobalVirtualGroupFamilies([]uint32{gvg.FamilyId})
s.Require().Equal(availableGvgFamilyIds[0], gvg.FamilyId)
spAvailableGvgFamilyIds := s.querySpAvailableGlobalVirtualGroupFamilies(primarySP.Info.Id)
s.Require().Equal(spAvailableGvgFamilyIds[0], gvg.FamilyId)

spOptimalGvgFamilyId := s.querySpOptimalGlobalVirtualGroupFamily(primarySP.Info.Id, virtualgroupmoduletypes.Strategy_Maximize_Free_Store_Size)
s.Require().Equal(spOptimalGvgFamilyId, gvg.FamilyId)

srcGVGs := s.queryGlobalVirtualGroupsByFamily(gvg.FamilyId)

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ replace (
github.com/cometbft/cometbft => github.com/bnb-chain/greenfield-cometbft v1.2.0
github.com/cometbft/cometbft-db => github.com/bnb-chain/greenfield-cometbft-db v0.8.1-alpha.1
github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23/go v0.8.0
github.com/cosmos/cosmos-sdk => github.com/bnb-chain/greenfield-cosmos-sdk v1.4.1-0.20240221065455-ef1f7f0d2659
github.com/cosmos/cosmos-sdk => github.com/bnb-chain/greenfield-cosmos-sdk v1.4.1-0.20240305064839-3cb07f5a365c
github.com/cosmos/iavl => github.com/bnb-chain/greenfield-iavl v0.20.1
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
github.com/wercker/journalhook => github.com/wercker/journalhook v0.0.0-20230927020745-64542ffa4117
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ github.com/bnb-chain/greenfield-cometbft v1.2.0 h1:LTStppZS9WkVj0TfEYKkk5OAQDGfY
github.com/bnb-chain/greenfield-cometbft v1.2.0/go.mod h1:WVOEZ59UYM2XePQH47/IQfcInspDn8wbRXhFSJrbU1c=
github.com/bnb-chain/greenfield-cometbft-db v0.8.1-alpha.1 h1:XcWulGacHVRiSCx90Q8Y//ajOrLNBQWR/KDB89dy3cU=
github.com/bnb-chain/greenfield-cometbft-db v0.8.1-alpha.1/go.mod h1:ey1CiK4bYo1RBNJLRiVbYr5CMdSxci9S/AZRINLtppI=
github.com/bnb-chain/greenfield-cosmos-sdk v1.4.1-0.20240221065455-ef1f7f0d2659 h1:ytOD5CuSsmV9pe9HXXJEsxiDKxHzOYShSG8s21Yw5Xw=
github.com/bnb-chain/greenfield-cosmos-sdk v1.4.1-0.20240221065455-ef1f7f0d2659/go.mod h1:XF8U3VN1euzLkIR5xiSNyQSnBabvnD86oz6fgdrpteQ=
github.com/bnb-chain/greenfield-cosmos-sdk v1.4.1-0.20240305064839-3cb07f5a365c h1:H0Rvx1FTVNgmXnUYvG0z3oFVvixPzlUHGN2JOPoNszM=
github.com/bnb-chain/greenfield-cosmos-sdk v1.4.1-0.20240305064839-3cb07f5a365c/go.mod h1:XF8U3VN1euzLkIR5xiSNyQSnBabvnD86oz6fgdrpteQ=
github.com/bnb-chain/greenfield-cosmos-sdk/api v0.0.0-20230816082903-b48770f5e210 h1:GHPbV2bC+gmuO6/sG0Tm8oGal3KKSRlyE+zPscDjlA8=
github.com/bnb-chain/greenfield-cosmos-sdk/api v0.0.0-20230816082903-b48770f5e210/go.mod h1:vhsZxXE9tYJeYB5JR4hPhd6Pc/uPf7j1T8IJ7p9FdeM=
github.com/bnb-chain/greenfield-cosmos-sdk/math v0.0.0-20230816082903-b48770f5e210 h1:FLVOn4+OVbsKi2+YJX5kmD27/4dRu4FW7xCXFhzDO5s=
Expand Down
13 changes: 13 additions & 0 deletions proto/greenfield/virtualgroup/common.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
syntax = "proto3";
package greenfield.virtualgroup;

import "gogoproto/gogo.proto";

option go_package = "github.com/bnb-chain/greenfield/x/virtualgroup/types";

// PickVGFStrategy represents the method for selecting the best global virtual group family based on the strategy
enum PickVGFStrategy {
option (gogoproto.goproto_enum_prefix) = false;

Strategy_Maximize_Free_Store_Size = 0;
}
28 changes: 28 additions & 0 deletions proto/greenfield/virtualgroup/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package greenfield.virtualgroup;
import "cosmos/base/query/v1beta1/pagination.proto";
import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "greenfield/virtualgroup/common.proto";
import "greenfield/virtualgroup/params.proto";
import "greenfield/virtualgroup/types.proto";

Expand Down Expand Up @@ -51,6 +52,16 @@ service Query {
rpc GVGStatistics(QuerySPGVGStatisticsRequest) returns (QuerySPGVGStatisticsResponse) {
option (google.api.http).get = "/greenfield/virtualgroup/sp_gvg_statistics";
}

// QuerySpAvailableGlobalVirtualGroupFamilies filters a list of GlobalVirtualGroupFamilies IDs under a certain SP that are qualified to create a bucket on
rpc QuerySpAvailableGlobalVirtualGroupFamilies(QuerySPAvailableGlobalVirtualGroupFamiliesRequest) returns (QuerySPAvailableGlobalVirtualGroupFamiliesResponse) {
option (google.api.http).get = "/greenfield/virtualgroup/sp_available_global_virtual_group_families";
}

// QuerySpOptimalGlobalVirtualGroupFamily filters the optimal GlobalVirtualGroupFamily under a certain SP that is qualified to create a bucket on
rpc QuerySpOptimalGlobalVirtualGroupFamily(QuerySpOptimalGlobalVirtualGroupFamilyRequest) returns (QuerySpOptimalGlobalVirtualGroupFamilyResponse) {
option (google.api.http).get = "/greenfield/virtualgroup/sp_optimal_global_virtual_group_family";
}
}

// QueryParamsRequest is request type for the Query/Params RPC method.
Expand Down Expand Up @@ -119,3 +130,20 @@ message QuerySPGVGStatisticsRequest {
message QuerySPGVGStatisticsResponse {
GVGStatisticsWithinSP gvg_stats = 1;
}

message QuerySPAvailableGlobalVirtualGroupFamiliesRequest {
uint32 sp_id = 1;
}

message QuerySPAvailableGlobalVirtualGroupFamiliesResponse {
repeated uint32 global_virtual_group_family_ids = 1;
}

message QuerySpOptimalGlobalVirtualGroupFamilyRequest {
uint32 sp_id = 1;
PickVGFStrategy pick_vgf_strategy = 2;
}

message QuerySpOptimalGlobalVirtualGroupFamilyResponse {
uint32 global_virtual_group_family_id = 1;
}
7 changes: 7 additions & 0 deletions proto/greenfield/virtualgroup/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ message GVGStatisticsWithinSP {
uint32 break_redundancy_reqmt_gvg_count = 4;
}

message GVGFamilyStatisticsWithinSP {
// sp_id defines the id of the sp which the statistics associated to
uint32 sp_id = 1;
// global_virtual_group_family_ids is a list of identifiers of the global virtual group family associated with the SP.
repeated uint32 global_virtual_group_family_ids = 2;
}

message SwapOutInfo {
// sp_id is the unique id of the storage provider who want to swap out.
uint32 sp_id = 1;
Expand Down
123 changes: 123 additions & 0 deletions swagger/static/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6310,6 +6310,54 @@ paths:
format: byte
tags:
- Query
/greenfield/virtualgroup/sp_available_global_virtual_group_families:
get:
summary: >-
QuerySpAvailableGlobalVirtualGroupFamilies filters a list of
GlobalVirtualGroupFamilies IDs under a certain SP that are qualified to
create a bucket on
operationId: QuerySpAvailableGlobalVirtualGroupFamilies
responses:
'200':
description: A successful response.
schema:
type: object
properties:
global_virtual_group_family_ids:
type: array
items:
type: integer
format: int64
default:
description: An unexpected error response.
schema:
type: object
properties:
error:
type: string
code:
type: integer
format: int32
message:
type: string
details:
type: array
items:
type: object
properties:
type_url:
type: string
value:
type: string
format: byte
parameters:
- name: sp_id
in: query
required: false
type: integer
format: int64
tags:
- Query
/greenfield/virtualgroup/sp_gvg_statistics:
get:
summary: GVGStatistics gets gvg statistics for a SP
Expand Down Expand Up @@ -6394,6 +6442,59 @@ paths:
format: int64
tags:
- Query
/greenfield/virtualgroup/sp_optimal_global_virtual_group_family:
get:
summary: >-
QuerySpOptimalGlobalVirtualGroupFamily filters the optimal
GlobalVirtualGroupFamily under a certain SP that is qualified to create
a bucket on
operationId: QuerySpOptimalGlobalVirtualGroupFamily
responses:
'200':
description: A successful response.
schema:
type: object
properties:
global_virtual_group_family_id:
type: integer
format: int64
default:
description: An unexpected error response.
schema:
type: object
properties:
error:
type: string
code:
type: integer
format: int32
message:
type: string
details:
type: array
items:
type: object
properties:
type_url:
type: string
value:
type: string
format: byte
parameters:
- name: sp_id
in: query
required: false
type: integer
format: int64
- name: pick_vgf_strategy
in: query
required: false
type: string
enum:
- Strategy_Maximize_Free_Store_Size
default: Strategy_Maximize_Free_Store_Size
tags:
- Query
/greenfield/virtualgroup/swap_in_info:
get:
summary: >-
Expand Down Expand Up @@ -37136,6 +37237,14 @@ definitions:
type: string
description: the the number of sp allowed to exit concurrently.
description: Params defines the parameters for the module.
greenfield.virtualgroup.PickVGFStrategy:
type: string
enum:
- Strategy_Maximize_Free_Store_Size
default: Strategy_Maximize_Free_Store_Size
title: >-
PickVGFStrategy represents the method for selecting the best global
virtual group family based on the strategy
greenfield.virtualgroup.QueryGlobalVirtualGroupByFamilyIDResponse:
type: object
properties:
Expand Down Expand Up @@ -37376,6 +37485,14 @@ definitions:
type: string
description: the the number of sp allowed to exit concurrently.
description: QueryParamsResponse is response type for the Query/Params RPC method.
greenfield.virtualgroup.QuerySPAvailableGlobalVirtualGroupFamiliesResponse:
type: object
properties:
global_virtual_group_family_ids:
type: array
items:
type: integer
format: int64
greenfield.virtualgroup.QuerySPGVGStatisticsResponse:
type: object
properties:
Expand Down Expand Up @@ -37421,6 +37538,12 @@ definitions:
unique to all other SP. So this will not be used for

swapIn individual GVG as secondary
greenfield.virtualgroup.QuerySpOptimalGlobalVirtualGroupFamilyResponse:
type: object
properties:
global_virtual_group_family_id:
type: integer
format: int64
greenfield.virtualgroup.QuerySwapInInfoResponse:
type: object
properties:
Expand Down
Loading

0 comments on commit 6067133

Please sign in to comment.