-
Notifications
You must be signed in to change notification settings - Fork 49
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
Changes from 7 commits
ce591d8
5a07296
aaedf3e
fbec6fa
c070716
4864fcd
4d95969
7109e4b
b8e69c7
9216e82
ca4f9ad
8de6d48
0d68d99
518fce9
d97b159
00c8574
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
syntax = "proto3"; | ||
package greenfield.virtualgroup; | ||
|
||
import "gogoproto/gogo.proto"; | ||
|
||
option go_package = "github.com/bnb-chain/greenfield/x/virtualgroup/types"; | ||
|
||
// PickVGFStrategy represents the method for selecting the best global virtual group family based on the strategy | ||
enum PickVGFStrategy { | ||
option (gogoproto.goproto_enum_prefix) = false; | ||
|
||
StrategyMaximizeFreeStoreSize = 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,14 +6,6 @@ import ( | |
|
||
"cosmossdk.io/errors" | ||
sdkmath "cosmossdk.io/math" | ||
"github.com/cometbft/cometbft/libs/log" | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
"github.com/cosmos/cosmos-sdk/store/prefix" | ||
storetypes "github.com/cosmos/cosmos-sdk/store/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" | ||
"github.com/cosmos/gogoproto/proto" | ||
|
||
"github.com/bnb-chain/greenfield/internal/sequence" | ||
gnfdtypes "github.com/bnb-chain/greenfield/types" | ||
types2 "github.com/bnb-chain/greenfield/types" | ||
|
@@ -26,6 +18,13 @@ import ( | |
sptypes "github.com/bnb-chain/greenfield/x/sp/types" | ||
"github.com/bnb-chain/greenfield/x/storage/types" | ||
virtualgroupmoduletypes "github.com/bnb-chain/greenfield/x/virtualgroup/types" | ||
"github.com/cometbft/cometbft/libs/log" | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
"github.com/cosmos/cosmos-sdk/store/prefix" | ||
storetypes "github.com/cosmos/cosmos-sdk/store/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" | ||
"github.com/cosmos/gogoproto/proto" | ||
) | ||
|
||
type ( | ||
|
@@ -118,13 +117,24 @@ func (k Keeper) CreateBucket( | |
} | ||
|
||
// check primary sp approval | ||
if opts.PrimarySpApproval.ExpiredHeight < uint64(ctx.BlockHeight()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed with IsUpgraded(upgradetypes.Pawnee) |
||
// TODO: Select the correct hard fork version to update vgf | ||
if !ctx.IsUpgraded(upgradetypes.Pawnee) && opts.PrimarySpApproval.ExpiredHeight < uint64(ctx.BlockHeight()) { | ||
return sdkmath.ZeroUint(), errors.Wrapf(types.ErrInvalidApproval, "The approval of sp is expired.") | ||
} | ||
err = k.VerifySPAndSignature(ctx, sp, opts.ApprovalMsgBytes, opts.PrimarySpApproval.Sig, ownerAcc) | ||
if err != nil { | ||
return sdkmath.ZeroUint(), err | ||
|
||
// TODO: Select the correct hard fork version to update vgf | ||
if !ctx.IsUpgraded(upgradetypes.Pawnee) { | ||
err = k.VerifySPAndSignature(ctx, sp, opts.ApprovalMsgBytes, opts.PrimarySpApproval.Sig, ownerAcc) | ||
if err != nil { | ||
return sdkmath.ZeroUint(), err | ||
} | ||
} else { | ||
err = k.VerifySP(ctx, sp, ownerAcc) | ||
if err != nil { | ||
return sdkmath.ZeroUint(), err | ||
} | ||
} | ||
|
||
gvgFamily, err := k.virtualGroupKeeper.GetAndCheckGVGFamilyAvailableForNewBucket(ctx, opts.PrimarySpApproval.GlobalVirtualGroupFamilyId) | ||
if err != nil { | ||
return sdkmath.ZeroUint(), err | ||
|
@@ -567,6 +577,12 @@ func (k Keeper) CreateObject( | |
return sdkmath.ZeroUint(), err | ||
} | ||
|
||
// check object | ||
//_, found = k.GetObjectInfo(ctx, bucketName, objectName) | ||
//if found { | ||
// return sdkmath.ZeroUint(), types.ErrObjectAlreadyExists | ||
//} | ||
|
||
// primary sp | ||
sp := k.MustGetPrimarySPForBucket(ctx, bucketInfo) | ||
|
||
|
@@ -585,14 +601,22 @@ func (k Keeper) CreateObject( | |
creator = operator | ||
} | ||
|
||
// check approval | ||
if opts.PrimarySpApproval.ExpiredHeight < uint64(ctx.BlockHeight()) { | ||
// TODO: Select the correct hard fork version to update vgf | ||
if !ctx.IsUpgraded(upgradetypes.Pawnee) && opts.PrimarySpApproval.ExpiredHeight < uint64(ctx.BlockHeight()) { | ||
return sdkmath.ZeroUint(), errors.Wrapf(types.ErrInvalidApproval, "The approval of sp is expired.") | ||
} | ||
|
||
err = k.VerifySPAndSignature(ctx, sp, opts.ApprovalMsgBytes, opts.PrimarySpApproval.Sig, operator) | ||
if err != nil { | ||
return sdkmath.ZeroUint(), err | ||
// TODO: Select the correct hard fork version to update vgf | ||
if !ctx.IsUpgraded(upgradetypes.Pawnee) { | ||
keefel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
err = k.VerifySPAndSignature(ctx, sp, opts.ApprovalMsgBytes, opts.PrimarySpApproval.Sig, operator) | ||
if err != nil { | ||
return sdkmath.ZeroUint(), err | ||
} | ||
} else { | ||
err = k.VerifySP(ctx, sp, operator) | ||
if err != nil { | ||
return sdkmath.ZeroUint(), err | ||
} | ||
} | ||
|
||
objectKey := types.GetObjectKey(bucketName, objectName) | ||
|
@@ -1618,6 +1642,13 @@ func (k Keeper) VerifySPAndSignature(_ sdk.Context, sp *sptypes.StorageProvider, | |
return nil | ||
} | ||
|
||
func (k Keeper) VerifySP(_ sdk.Context, sp *sptypes.StorageProvider, operator sdk.AccAddress) error { | ||
if sp.Status != sptypes.STATUS_IN_SERVICE && !k.fromSpMaintenanceAcct(sp, operator) { | ||
return sptypes.ErrStorageProviderNotInService | ||
} | ||
return nil | ||
} | ||
|
||
func (k Keeper) GenNextBucketId(ctx sdk.Context) sdkmath.Uint { | ||
store := ctx.KVStore(k.storeKey) | ||
|
||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be all CAP