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

Conversation

BarryTong65
Copy link
Contributor

@BarryTong65 BarryTong65 commented Feb 28, 2024

Description

Remove the create object approval & create bucket approval, and during the process of creating objects & buckets, the calls to the SP side are eliminated through the Go-sdk.

For CreateObject, validation for the object's existence has been added on chain, and the corresponding verify signature has been removed.

For CreateBucket, two gRPC queries have been added and used during the creation process in the Go-sdk to replace the previous logic of Pick VGF on the SP side:
image

  • QuerySpAvailableGlobalVirtualGroupFamilies
  • QuerySpOptimalGlobalVirtualGroupFamily

And the limitation on creating buckets under a user has been removed.

Rationale

Before

SP Pick VGF & Create GVG process
image

Current

image Replace the process on the SP side of checking for available VGF & GVG during the create bucket approval. Virtual Group Manager will automatically check the available status of each SP's GVG & VGF and create GVG when the storage is full or the SP does not have any available GVG.

Example

N/A

Changes

Notable changes:

  • Remove the create object approval & create bucket approval, and during the process of creating objects & buckets, the calls to the SP side are eliminated through the Go-sdk.

Potential Impacts

  • Go-SDK
  • Storage Provider

@BarryTong65 BarryTong65 force-pushed the feat-remove-approval branch 2 times, most recently from 7c7277e to 3815ffd Compare February 29, 2024 03:25
@@ -567,6 +559,12 @@ func (k Keeper) CreateObject(
return sdkmath.ZeroUint(), err
}

// check object
_, found = k.GetObjectInfo(ctx, bucketName, objectName)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This check is already implemented below.

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

@@ -117,14 +117,6 @@ func (k Keeper) CreateBucket(
return sdkmath.ZeroUint(), errors.Wrap(types.ErrNoSuchStorageProvider, "the storage provider is not in service")
}

// 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

}, nil
}

func (k Keeper) QuerySpOptimalGlobalVirtualGroupFamily(goCtx context.Context, req *types.QuerySpOptimalGlobalVirtualGroupFamilyRequest) (*types.QuerySpOptimalGlobalVirtualGroupFamilyResponse, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we make this API more flexible? Might define the strategy as enum.

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, an enum was created to select the strategy.

@@ -167,6 +167,7 @@ func (k Keeper) DeleteGVG(ctx sdk.Context, primarySp *sptypes.StorageProvider, g
k.paymentKeeper.IsEmptyNetFlow(ctx, sdk.MustAccAddressFromHex(gvgFamily.VirtualPaymentAddress)) &&
!ctx.IsUpgraded(upgradetypes.Manchurian) {
store.Delete(types.GetGVGFamilyKey(gvg.FamilyId))
k.DeleteGVGFamilyWithinSP(ctx, primarySp.Id, gvg.FamilyId)
Copy link
Collaborator

Choose a reason for hiding this comment

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

not needed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The above GetGVGFamilyKey deletes this VGF. Logically, the list of VGFs under this SP should also have the corresponding VGF removed. Why is this not necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

deleted

break
}
}
if index != -1 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this can be put into the for loop, once meet the desired element, do the manipulation immediately.

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

store.Set(types.GetGVGFamilyStatisticsWithinSPKey(vgfStatisticsWithinSP.StorageProviderId), bz)
}

func (k Keeper) BatchSetGVGFamilyStatisticsWithinSP(ctx sdk.Context, vgfStatisticsWithinSP []*types.GVGFamilyStatisticsWithinSP) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

need to populate data into store as new key is used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The BatchSetGVGFamilyStatisticsWithinSP calls SetGVGFamilyStatisticsWithinSP to store it in the store, so there should be no need to add additional logic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

update the logic to set all GVGFamilyStatisticsWithinSP when executing the hardfork

@@ -73,6 +73,13 @@ message GVGStatisticsWithinSP {
uint32 break_redundancy_reqmt_gvg_count = 4;
}

message GVGFamilyStatisticsWithinSP {
// storage_provider_id defines the id of the sp which the statistics associated to
uint32 storage_provider_id = 1;
Copy link
Collaborator

Choose a reason for hiding this comment

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

the storage_provider_id is not needed as the key is the sp_id already.

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

x/storage/keeper/keeper.go Outdated Show resolved Hide resolved
@@ -289,6 +294,8 @@ func (k Keeper) SwapAsPrimarySP(ctx sdk.Context, primarySP, successorSP *sptypes

srcStat := k.MustGetGVGStatisticsWithinSP(ctx, primarySP.Id)
dstStat := k.GetOrCreateGVGStatisticsWithinSP(ctx, successorSP.Id)
srcVGFStat := k.MustGetGVGFamilyStatisticsWithinSP(ctx, primarySP.Id)
Copy link
Collaborator

Choose a reason for hiding this comment

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

if this is executed before the hardfork, there is no stats yet.

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

@@ -358,6 +365,9 @@ func (k Keeper) SwapAsPrimarySP(ctx sdk.Context, primarySP, successorSP *sptypes
}
k.SetGVGStatisticsWithSP(ctx, srcStat)
k.SetGVGStatisticsWithSP(ctx, dstStat)
k.DeleteGVGFamilyWithinSP(ctx, srcVGFStat.SpId, family.Id)
Copy link
Collaborator

Choose a reason for hiding this comment

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

if this is executed before the hardfork, there is no stats yet.

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

var gvgFamily types.GlobalVirtualGroupFamily
k.cdc.MustUnmarshal(iterator.Value(), &gvgFamily)
gvgFamilyStatistics := k.GetOrCreateGVGFamilyStatisticsWithinSP(ctx, gvgFamily.PrimarySpId)
if !slices.Contains(gvgFamilyStatistics.GlobalVirtualGroupFamilyIds, gvgFamily.Id) {
Copy link
Collaborator

@alexgao001 alexgao001 Mar 5, 2024

Choose a reason for hiding this comment

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

should't be any family identical to another

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

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

keefel
keefel previously approved these changes Mar 7, 2024
@@ -358,6 +369,11 @@ func (k Keeper) SwapAsPrimarySP(ctx sdk.Context, primarySP, successorSP *sptypes
}
k.SetGVGStatisticsWithSP(ctx, srcStat)
k.SetGVGStatisticsWithSP(ctx, dstStat)
if ctx.IsUpgraded(upgradetypes.Serengeti) {
k.DeleteGVGFamilyWithinSP(ctx, srcVGFStat.SpId, family.Id)
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you rename this, a little confused..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

rename to DeleteSpecificGVGFamilyStatisticsFromSP. If it is not appropriate, i will think about another one

store.Set(types.GetGVGFamilyStatisticsWithinSPKey(vgfStatisticsWithinSP.SpId), bz)
}

func (k Keeper) BatchSetGVGFamilyStatisticsWithinSP(ctx sdk.Context, vgfStatisticsWithinSP []*types.GVGFamilyStatisticsWithinSP) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is not being called

Copy link
Contributor Author

Choose a reason for hiding this comment

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

deleted

gvgFamilyStatistics := k.GetOrCreateGVGFamilyStatisticsWithinSP(ctx, gvgFamily.PrimarySpId)
k.Logger(ctx).Info(fmt.Sprintf("gvgFamilyStatistics1 gvgFamily id %v, sp id: %d", gvgFamilyStatistics.GlobalVirtualGroupFamilyIds, gvgFamilyStatistics.SpId))
gvgFamilyStatistics.GlobalVirtualGroupFamilyIds = append(gvgFamilyStatistics.GlobalVirtualGroupFamilyIds, gvgFamily.Id)
k.Logger(ctx).Info(fmt.Sprintf("gvgFamilyStatistics2 gvgFamily id %v, sp id: %d", gvgFamilyStatistics.GlobalVirtualGroupFamilyIds, gvgFamilyStatistics.SpId))
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you refine the log

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is only for debug log,deleted

ErrSwapInFailed = errors.Register(ModuleName, 1127, "swap in failed.")
ErrSwapInInfoNotExist = errors.Register(ModuleName, 1128, "swap in info not exist.")
ErrGVGStatisticsNotExist = errors.Register(ModuleName, 1129, "gvg statistics not exist.")
ErrGVGFamilyStatisticsNotExist = errors.Register(ModuleName, 1130, "vgf statistics not exist.")
Copy link
Collaborator

Choose a reason for hiding this comment

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

might want the naming consistent like "global virtual group family..." as it is exposed to users..

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

@BarryTong65 BarryTong65 added this pull request to the merge queue Mar 7, 2024
Merged via the queue into develop with commit 6067133 Mar 7, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants