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: add pick vgf strategy #611

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions proto/greenfield/virtualgroup/common.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
6 changes: 6 additions & 0 deletions swagger/static/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
29 changes: 27 additions & 2 deletions x/virtualgroup/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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")
}
Expand Down
41 changes: 27 additions & 14 deletions x/virtualgroup/types/common.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading