diff --git a/proto/greenfield/virtualgroup/common.proto b/proto/greenfield/virtualgroup/common.proto index 68114bd50..ab6e68f62 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_Store_Size = 3; } diff --git a/swagger/static/swagger.yaml b/swagger/static/swagger.yaml index 6c48b5d32..e06e473fe 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_Store_Size 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_Store_Size 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..7036524bf 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,28 @@ 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: + familyID = stats.GlobalVirtualGroupFamilyIds[0] + case types.Strategy_Recentest_Store_Size: + 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..012eb1fde 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_Store_Size 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_Store_Size", } 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_Store_Size": 3, } func (x PickVGFStrategy) String() string { @@ -53,18 +62,22 @@ func init() { } var fileDescriptor_95d96763aeb17687 = []byte{ - // 206 bytes of a gzipped FileDescriptorProto + // 266 bytes of a gzipped FileDescript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28, 0xa9, 0x2c, 0x48, 0x2d, 0x4e, 0x62, 0x03, 0x3b, 0xcb, - 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0xe8, 0xdf, 0xb8, 0xf0, 0xed, 0x00, 0x00, 0x00, + 0x0f, 0x62, 0x41, 0x94, 0x6b, 0xad, 0x60, 0xe4, 0xe2, 0x0f, 0xc8, 0x4c, 0xce, 0x0e, 0x73, 0x77, + 0x0b, 0x2e, 0x29, 0x4a, 0x2c, 0x49, 0x4d, 0xaf, 0x14, 0x52, 0xe5, 0x52, 0x84, 0xb1, 0xe3, 0x7d, + 0x13, 0x2b, 0x32, 0x73, 0x33, 0xab, 0x52, 0xe3, 0xdd, 0x8a, 0x52, 0x53, 0xe3, 0x83, 0x4b, 0xf2, + 0x8b, 0x52, 0xe3, 0x83, 0x33, 0xab, 0x52, 0x05, 0x18, 0x84, 0x54, 0xb8, 0x14, 0x10, 0xca, 0x32, + 0xf3, 0x32, 0x73, 0x13, 0x73, 0x30, 0x54, 0x31, 0x0a, 0xc9, 0x73, 0x49, 0xc3, 0x55, 0xf9, 0xe7, + 0xa4, 0xa4, 0x16, 0x97, 0xc4, 0x3b, 0x17, 0xa5, 0x26, 0x96, 0xa4, 0xc6, 0x87, 0x64, 0xe6, 0xa6, + 0x0a, 0x30, 0x09, 0x29, 0x72, 0xc9, 0xc2, 0x15, 0x04, 0xa5, 0x26, 0xa7, 0xe6, 0x95, 0x80, 0xd4, + 0x20, 0x99, 0xc1, 0x2c, 0xc5, 0xd2, 0xb1, 0x58, 0x8e, 0xc1, 0xc9, 0xef, 0xc4, 0x23, 0x39, 0xc6, + 0x0b, 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc2, 0x63, 0x39, + 0x86, 0x1b, 0x8f, 0xe5, 0x18, 0xa2, 0x4c, 0xd2, 0x33, 0x4b, 0x32, 0x4a, 0x93, 0xf4, 0x92, 0xf3, + 0x73, 0xf5, 0x93, 0xf2, 0x92, 0x74, 0x93, 0x33, 0x12, 0x33, 0xf3, 0xf4, 0x91, 0x82, 0xab, 0x02, + 0x35, 0xc0, 0x4a, 0x2a, 0x0b, 0x52, 0x8b, 0x93, 0xd8, 0xc0, 0x21, 0x60, 0x0c, 0x08, 0x00, 0x00, + 0xff, 0xff, 0xa9, 0xc1, 0x0f, 0x33, 0x58, 0x01, 0x00, 0x00, }