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: remove create object & bucket approval #580

Merged
merged 16 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
2 changes: 2 additions & 0 deletions app/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ func (app *App) registerPawneeUpgradeHandler() {
app.UpgradeKeeper.SetUpgradeHandler(upgradetypes.Pawnee,
func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
app.Logger().Info("upgrade to ", plan.Name)
// TODO: Select the correct hard fork version to update vgf
app.VirtualgroupKeeper.MigrateGlobalVirtualGroupFamiliesForSP(ctx)
app.GashubKeeper.SetMsgGasParams(ctx, *gashubtypes.NewMsgGasParamsWithFixedGas(sdk.MsgTypeURL(&storagemoduletypes.MsgUpdateObjectContent{}), 1.2e3))
app.GashubKeeper.SetMsgGasParams(ctx, *gashubtypes.NewMsgGasParamsWithFixedGas(sdk.MsgTypeURL(&storagemoduletypes.MsgCancelUpdateObjectContent{}), 1.2e3))
return app.mm.RunMigrations(ctx, app.configurator, fromVM)
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.StrategyMaximizeFreeStoreSize)
s.Require().Equal(spOptimalGvgFamilyId, gvg.FamilyId)

srcGVGs := s.queryGlobalVirtualGroupsByFamily(gvg.FamilyId)

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;

StrategyMaximizeFreeStoreSize = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check for the style to define enum. It should be like XX_XX_XX

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to Strategy_Maximize_Free_Store_Size

Copy link
Collaborator

@alexgao001 alexgao001 Mar 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be all CAP

}
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:
- StrategyMaximizeFreeStoreSize
default: StrategyMaximizeFreeStoreSize
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:
- StrategyMaximizeFreeStoreSize
default: StrategyMaximizeFreeStoreSize
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
65 changes: 48 additions & 17 deletions x/storage/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@ import (

"cosmossdk.io/errors"
sdkmath "cosmossdk.io/math"
"github.com/cometbft/cometbft/libs/log"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/store/prefix"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
"github.com/cosmos/gogoproto/proto"

"github.com/bnb-chain/greenfield/internal/sequence"
gnfdtypes "github.com/bnb-chain/greenfield/types"
types2 "github.com/bnb-chain/greenfield/types"
Expand All @@ -26,6 +18,13 @@ import (
sptypes "github.com/bnb-chain/greenfield/x/sp/types"
"github.com/bnb-chain/greenfield/x/storage/types"
virtualgroupmoduletypes "github.com/bnb-chain/greenfield/x/virtualgroup/types"
"github.com/cometbft/cometbft/libs/log"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/store/prefix"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
"github.com/cosmos/gogoproto/proto"
)

type (
Expand Down Expand Up @@ -118,13 +117,24 @@ func (k Keeper) CreateBucket(
}

// check primary sp approval
if opts.PrimarySpApproval.ExpiredHeight < uint64(ctx.BlockHeight()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these code cant be deleted directly. Need to modify after new hardfork is introduced.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't be deleted directly. With the new Go-SDK, verification no longer goes through SP to obtain, thus there is no expiredHeight.
In the old Go-SDK, creating a bucket would go through SP to get approval, but this is no longer necessary for ExpiredHeight verification.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed with IsUpgraded(upgradetypes.Pawnee)
the correct hard fork version will be updated before release

// TODO: Select the correct hard fork version to update vgf
if !ctx.IsUpgraded(upgradetypes.Pawnee) && opts.PrimarySpApproval.ExpiredHeight < uint64(ctx.BlockHeight()) {
return sdkmath.ZeroUint(), errors.Wrapf(types.ErrInvalidApproval, "The approval of sp is expired.")
}
err = k.VerifySPAndSignature(ctx, sp, opts.ApprovalMsgBytes, opts.PrimarySpApproval.Sig, ownerAcc)
if err != nil {
return sdkmath.ZeroUint(), err

// TODO: Select the correct hard fork version to update vgf
if !ctx.IsUpgraded(upgradetypes.Pawnee) {
err = k.VerifySPAndSignature(ctx, sp, opts.ApprovalMsgBytes, opts.PrimarySpApproval.Sig, ownerAcc)
if err != nil {
return sdkmath.ZeroUint(), err
}
} else {
err = k.VerifySP(ctx, sp, ownerAcc)
if err != nil {
return sdkmath.ZeroUint(), err
}
}

gvgFamily, err := k.virtualGroupKeeper.GetAndCheckGVGFamilyAvailableForNewBucket(ctx, opts.PrimarySpApproval.GlobalVirtualGroupFamilyId)
if err != nil {
return sdkmath.ZeroUint(), err
Expand Down Expand Up @@ -567,6 +577,12 @@ func (k Keeper) CreateObject(
return sdkmath.ZeroUint(), err
}

// check object
//_, found = k.GetObjectInfo(ctx, bucketName, objectName)
//if found {
// return sdkmath.ZeroUint(), types.ErrObjectAlreadyExists
//}

// primary sp
sp := k.MustGetPrimarySPForBucket(ctx, bucketInfo)

Expand All @@ -585,14 +601,22 @@ func (k Keeper) CreateObject(
creator = operator
}

// check approval
if opts.PrimarySpApproval.ExpiredHeight < uint64(ctx.BlockHeight()) {
// TODO: Select the correct hard fork version to update vgf
if !ctx.IsUpgraded(upgradetypes.Pawnee) && opts.PrimarySpApproval.ExpiredHeight < uint64(ctx.BlockHeight()) {
return sdkmath.ZeroUint(), errors.Wrapf(types.ErrInvalidApproval, "The approval of sp is expired.")
}

err = k.VerifySPAndSignature(ctx, sp, opts.ApprovalMsgBytes, opts.PrimarySpApproval.Sig, operator)
if err != nil {
return sdkmath.ZeroUint(), err
// TODO: Select the correct hard fork version to update vgf
if !ctx.IsUpgraded(upgradetypes.Pawnee) {
keefel marked this conversation as resolved.
Show resolved Hide resolved
err = k.VerifySPAndSignature(ctx, sp, opts.ApprovalMsgBytes, opts.PrimarySpApproval.Sig, operator)
if err != nil {
return sdkmath.ZeroUint(), err
}
} else {
err = k.VerifySP(ctx, sp, operator)
if err != nil {
return sdkmath.ZeroUint(), err
}
}

objectKey := types.GetObjectKey(bucketName, objectName)
Expand Down Expand Up @@ -1618,6 +1642,13 @@ func (k Keeper) VerifySPAndSignature(_ sdk.Context, sp *sptypes.StorageProvider,
return nil
}

func (k Keeper) VerifySP(_ sdk.Context, sp *sptypes.StorageProvider, operator sdk.AccAddress) error {
if sp.Status != sptypes.STATUS_IN_SERVICE && !k.fromSpMaintenanceAcct(sp, operator) {
return sptypes.ErrStorageProviderNotInService
}
return nil
}

func (k Keeper) GenNextBucketId(ctx sdk.Context) sdkmath.Uint {
store := ctx.KVStore(k.storeKey)

Expand Down
Loading
Loading