Skip to content

Commit

Permalink
enhancement storage module
Browse files Browse the repository at this point in the history
  • Loading branch information
fynnss committed Mar 13, 2023
1 parent fdd68f3 commit 2f05c8f
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 59 deletions.
32 changes: 31 additions & 1 deletion x/storage/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

// TODO: Support List bucket/object/group with pagination.
// TODO: Support GetGroup
// TODO: Support HeadGroup

// GetQueryCmd returns the cli query commands for this module
func GetQueryCmd(queryRoute string) *cobra.Command {
Expand Down Expand Up @@ -210,3 +210,33 @@ func CmdGetPolicy() *cobra.Command {

return cmd
}

func CmdVerifyPermission() *cobra.Command {
cmd := &cobra.Command{
Use: "verify-permission",
Short: "Query verify-permission",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) (err error) {

clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)

params := &types.QueryVerifyPermissionRequest{}

res, err := queryClient.VerifyPermission(cmd.Context(), params)
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
43 changes: 0 additions & 43 deletions x/storage/client/cli/query_verify_permission.go

This file was deleted.

4 changes: 1 addition & 3 deletions x/storage/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ func (k Keeper) CreateObject(
Id: k.GenNextObjectID(ctx),
CreateAt: ctx.BlockTime().Unix(),
ObjectStatus: types.OBJECT_STATUS_CREATED,
RedundancyType: opts.RedundancyType, // TODO: base on redundancy policy
RedundancyType: opts.RedundancyType,
SourceType: opts.SourceType,
Checksums: opts.Checksums,
SecondarySpAddresses: secondarySPs,
Expand Down Expand Up @@ -459,7 +459,6 @@ func (k Keeper) SealObject(

objectInfo.ObjectStatus = types.OBJECT_STATUS_SEALED

// TODO(fynn): consider remove the lock fee meta from bucketInfo
store := ctx.KVStore(k.storeKey)
bbz := k.cdc.MustMarshal(bucketInfo)
store.Set(types.GetBucketByIDKey(bucketInfo.Id), bbz)
Expand Down Expand Up @@ -510,7 +509,6 @@ func (k Keeper) CancelCreateObject(
return err
}

// TODO(fynn): consider remove the lock fee meta from bucketInfo
bbz := k.cdc.MustMarshal(bucketInfo)
store.Set(types.GetBucketByIDKey(bucketInfo.Id), bbz)

Expand Down
15 changes: 13 additions & 2 deletions x/storage/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package keeper
import (
"context"

"cosmossdk.io/errors"
gnfderrors "github.com/bnb-chain/greenfield/types/errors"
sdk "github.com/cosmos/cosmos-sdk/types"

types2 "github.com/bnb-chain/greenfield/types"
Expand Down Expand Up @@ -90,7 +92,6 @@ func (k msgServer) UpdateBucketInfo(goCtx context.Context, msg *types.MsgUpdateB

func (k msgServer) CreateObject(goCtx context.Context, msg *types.MsgCreateObject) (*types.MsgCreateObjectResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
// TODO: check bucket and object permission
ownerAcc, err := sdk.AccAddressFromHexUnsafe(msg.Creator)
if err != nil {
return nil, err
Expand Down Expand Up @@ -118,12 +119,22 @@ func (k msgServer) CreateObject(goCtx context.Context, msg *types.MsgCreateObjec
func (k msgServer) SealObject(goCtx context.Context, msg *types.MsgSealObject) (*types.MsgSealObjectResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

// TODO: check permission when permission module ready
spSealAcc, err := sdk.AccAddressFromHexUnsafe(msg.Operator)
if err != nil {
return nil, err
}

expectSecondarySPNum := k.Keeper.RedundantDataChunkNum(ctx) + k.Keeper.RedundantParityChunkNum(ctx)
if len(msg.SecondarySpAddresses) != (int)(expectSecondarySPNum) {
return nil, errors.Wrapf(gnfderrors.ErrInvalidSPAddress, "Missing SP expect (%d), but (%d)", expectSecondarySPNum,
len(msg.SecondarySpAddresses))
}

if len(msg.SecondarySpSignatures) != (int)(expectSecondarySPNum) {
return nil, errors.Wrapf(gnfderrors.ErrInvalidSPSignature, "Missing SP signatures, expect (%d), but (%d)",
expectSecondarySPNum, len(msg.SecondarySpSignatures))
}

err = k.Keeper.SealObject(ctx, spSealAcc, msg.BucketName, msg.ObjectName, SealObjectOptions{
SecondarySpAddresses: msg.SecondarySpAddresses,
SecondarySpSignatures: msg.SecondarySpSignatures,
Expand Down
10 changes: 0 additions & 10 deletions x/storage/types/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,23 +486,13 @@ func (msg *MsgSealObject) ValidateBasic() error {
return err
}

// TODO: 6 hard code here.
if len(msg.SecondarySpAddresses) != 6 {
return errors.Wrapf(gnfderrors.ErrInvalidSPAddress, "Missing SP expect: (%d), but (%d)", 6,
len(msg.SecondarySpAddresses))
}

for _, addr := range msg.SecondarySpAddresses {
_, err := sdk.AccAddressFromHexUnsafe(addr)
if err != nil {
return errors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid secondary sp address (%s)", err)
}
}

if len(msg.SecondarySpSignatures) != 6 {
return errors.Wrapf(gnfderrors.ErrInvalidSPSignature, "Missing SP signatures")
}

for _, sig := range msg.SecondarySpSignatures {
if sig == nil && len(sig) != ethcrypto.SignatureLength {
return errors.Wrapf(gnfderrors.ErrInvalidSPSignature, "invalid SP signatures")
Expand Down

0 comments on commit 2f05c8f

Please sign in to comment.