diff --git a/proto/greenfield/virtualgroup/common.proto b/proto/greenfield/virtualgroup/common.proto index 68114bd50..9a0b6c309 100644 --- a/proto/greenfield/virtualgroup/common.proto +++ b/proto/greenfield/virtualgroup/common.proto @@ -10,4 +10,7 @@ enum PickVGFStrategy { option (gogoproto.goproto_enum_prefix) = false; Strategy_Maximize_Free_Store_Size = 0; + Strategy_Minimal_Free_Store_Size = 1; + Strategy_Oldest_Create_Time = 2; + Strategy_Recentest_Create_Time = 3; } diff --git a/swagger/static/swagger.yaml b/swagger/static/swagger.yaml index 6c48b5d32..f7eca5f0e 100644 --- a/swagger/static/swagger.yaml +++ b/swagger/static/swagger.yaml @@ -6585,6 +6585,9 @@ paths: type: string enum: - Strategy_Maximize_Free_Store_Size + - Strategy_Minimal_Free_Store_Size + - Strategy_Oldest_Create_Time + - Strategy_Recentest_Create_Time default: Strategy_Maximize_Free_Store_Size tags: - Query @@ -37383,6 +37386,9 @@ definitions: type: string enum: - Strategy_Maximize_Free_Store_Size + - Strategy_Minimal_Free_Store_Size + - Strategy_Oldest_Create_Time + - Strategy_Recentest_Create_Time default: Strategy_Maximize_Free_Store_Size title: >- PickVGFStrategy represents the method for selecting the best global diff --git a/x/virtualgroup/keeper/grpc_query.go b/x/virtualgroup/keeper/grpc_query.go index 75b02481a..985d91dc2 100644 --- a/x/virtualgroup/keeper/grpc_query.go +++ b/x/virtualgroup/keeper/grpc_query.go @@ -4,11 +4,12 @@ import ( "context" "math" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" "github.com/bnb-chain/greenfield/x/virtualgroup/types" ) @@ -230,6 +231,30 @@ func (k Keeper) QuerySpOptimalGlobalVirtualGroupFamily(goCtx context.Context, re } } } + case types.Strategy_Minimal_Free_Store_Size: + for _, gvgfID := range stats.GlobalVirtualGroupFamilyIds { + gvgFamily, found := k.GetGVGFamily(ctx, gvgfID) + if !found { + return nil, types.ErrGVGFamilyNotExist + } + totalStakingSize, stored, err := k.GetGlobalVirtualFamilyTotalStakingAndStoredSize(ctx, gvgFamily) + if err != nil { + return nil, err + } + currentFreeStoreSize = math.Min(float64(totalStakingSize), float64(k.MaxStoreSizePerFamily(ctx))) - float64(stored) + if currentFreeStoreSize < freeStoreSize { + familyID = gvgFamily.Id + freeStoreSize = currentFreeStoreSize + } + } + case types.Strategy_Oldest_Create_Time: + if len(stats.GlobalVirtualGroupFamilyIds) != 0 { + familyID = stats.GlobalVirtualGroupFamilyIds[0] + } + case types.Strategy_Recentest_Create_Time: + if len(stats.GlobalVirtualGroupFamilyIds) != 0 { + familyID = stats.GlobalVirtualGroupFamilyIds[len(stats.GlobalVirtualGroupFamilyIds)-1] + } default: return nil, status.Error(codes.InvalidArgument, "invalid pick vgf strategy") } diff --git a/x/virtualgroup/types/common.pb.go b/x/virtualgroup/types/common.pb.go index 0940dc794..d2aa66f1e 100644 --- a/x/virtualgroup/types/common.pb.go +++ b/x/virtualgroup/types/common.pb.go @@ -26,14 +26,23 @@ type PickVGFStrategy int32 const ( Strategy_Maximize_Free_Store_Size PickVGFStrategy = 0 + Strategy_Minimal_Free_Store_Size PickVGFStrategy = 1 + Strategy_Oldest_Create_Time PickVGFStrategy = 2 + Strategy_Recentest_Create_Time PickVGFStrategy = 3 ) var PickVGFStrategy_name = map[int32]string{ 0: "Strategy_Maximize_Free_Store_Size", + 1: "Strategy_Minimal_Free_Store_Size", + 2: "Strategy_Oldest_Create_Time", + 3: "Strategy_Recentest_Create_Time", } var PickVGFStrategy_value = map[string]int32{ "Strategy_Maximize_Free_Store_Size": 0, + "Strategy_Minimal_Free_Store_Size": 1, + "Strategy_Oldest_Create_Time": 2, + "Strategy_Recentest_Create_Time": 3, } func (x PickVGFStrategy) String() string { @@ -53,18 +62,22 @@ func init() { } var fileDescriptor_95d96763aeb17687 = []byte{ - // 206 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x49, 0x2f, 0x4a, 0x4d, - 0xcd, 0x4b, 0xcb, 0x4c, 0xcd, 0x49, 0xd1, 0x2f, 0xcb, 0x2c, 0x2a, 0x29, 0x4d, 0xcc, 0x49, 0x2f, - 0xca, 0x2f, 0x2d, 0xd0, 0x4f, 0xce, 0xcf, 0xcd, 0xcd, 0xcf, 0xd3, 0x2b, 0x28, 0xca, 0x2f, 0xc9, - 0x17, 0x12, 0x47, 0xa8, 0xd2, 0x43, 0x56, 0x25, 0x25, 0x92, 0x9e, 0x9f, 0x9e, 0x0f, 0x56, 0xa3, - 0x0f, 0x62, 0x41, 0x94, 0x6b, 0xd9, 0x71, 0xf1, 0x07, 0x64, 0x26, 0x67, 0x87, 0xb9, 0xbb, 0x05, - 0x97, 0x14, 0x25, 0x96, 0xa4, 0xa6, 0x57, 0x0a, 0xa9, 0x72, 0x29, 0xc2, 0xd8, 0xf1, 0xbe, 0x89, - 0x15, 0x99, 0xb9, 0x99, 0x55, 0xa9, 0xf1, 0x6e, 0x45, 0xa9, 0xa9, 0xf1, 0xc1, 0x25, 0xf9, 0x45, - 0xa9, 0xf1, 0xc1, 0x99, 0x55, 0xa9, 0x02, 0x0c, 0x52, 0x2c, 0x1d, 0x8b, 0xe5, 0x18, 0x9c, 0xfc, - 0x4e, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, 0x09, 0x8f, 0xe5, - 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0xca, 0x24, 0x3d, 0xb3, 0x24, 0xa3, - 0x34, 0x49, 0x2f, 0x39, 0x3f, 0x57, 0x3f, 0x29, 0x2f, 0x49, 0x37, 0x39, 0x23, 0x31, 0x33, 0x4f, - 0x1f, 0xc9, 0x0f, 0x15, 0xa8, 0xbe, 0x28, 0xa9, 0x2c, 0x48, 0x2d, 0x4e, 0x62, 0x03, 0x3b, 0xcb, - 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0xe8, 0xdf, 0xb8, 0xf0, 0xed, 0x00, 0x00, 0x00, + // 264 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x64, 0xd0, 0x3d, 0x4a, 0x03, 0x41, + 0x14, 0xc0, 0xf1, 0x5d, 0x15, 0x8b, 0x69, 0x0c, 0x8b, 0x20, 0x44, 0x18, 0x3f, 0x88, 0x8d, 0xe0, + 0x4e, 0xa1, 0x27, 0x50, 0x88, 0x95, 0x1f, 0xb8, 0x62, 0x61, 0x33, 0xcc, 0x4e, 0x9e, 0x93, 0x87, + 0x3b, 0x33, 0xcb, 0xe4, 0xad, 0x24, 0x39, 0x81, 0xa5, 0x77, 0xb0, 0xf2, 0x26, 0x96, 0x29, 0x2d, + 0x65, 0xf7, 0x22, 0x62, 0xc4, 0x24, 0x9a, 0xee, 0x5f, 0xfc, 0xaa, 0x3f, 0xeb, 0x98, 0x00, 0xe0, + 0x1e, 0x10, 0x8a, 0x9e, 0x78, 0xc2, 0x40, 0x95, 0x2a, 0x4c, 0xf0, 0x55, 0x29, 0xb4, 0xb7, 0xd6, + 0xbb, 0xb4, 0x0c, 0x9e, 0x7c, 0xb2, 0x35, 0x57, 0xe9, 0xa2, 0x6a, 0x6f, 0x1a, 0x6f, 0xfc, 0xd4, + 0x88, 0xef, 0xfa, 0xe1, 0x87, 0x6f, 0x31, 0xdb, 0xb8, 0x46, 0xfd, 0x78, 0x77, 0xde, 0xcd, 0x28, + 0x28, 0x02, 0x33, 0x4a, 0x0e, 0xd8, 0xde, 0x6f, 0xcb, 0x0b, 0x35, 0x44, 0x8b, 0x63, 0x90, 0xdd, + 0x00, 0x20, 0x33, 0xf2, 0x01, 0x64, 0x86, 0x63, 0x68, 0x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