Skip to content

Commit

Permalink
add pick vgf strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgao001 committed Apr 18, 2024
1 parent a0f1232 commit 7894056
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 12 deletions.
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_Store_Size = 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_Store_Size
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_Store_Size
default: Strategy_Maximize_Free_Store_Size
title: >-
PickVGFStrategy represents the method for selecting the best global
Expand Down
27 changes: 25 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,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")
}
Expand Down
33 changes: 23 additions & 10 deletions x/virtualgroup/types/common.pb.go

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

0 comments on commit 7894056

Please sign in to comment.