Skip to content

Commit

Permalink
fix: fix the comments
Browse files Browse the repository at this point in the history
  • Loading branch information
yutianwu committed Mar 6, 2024
1 parent 49e7162 commit 82d81ef
Show file tree
Hide file tree
Showing 18 changed files with 1,917 additions and 394 deletions.
43 changes: 43 additions & 0 deletions e2e/tests/storage_rate_limit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,3 +340,46 @@ func (s *StorageTestSuite) TestNotOwnerSetBucketRateLimit_BucketPaymentAccount()
s.SendTxBlock(user, msgUpdateBucketInfo)
s.Require().NoError(err)
}

func (s *StorageTestSuite) TestQueryBucketRateLimit() {
var err error
sp := s.BaseSuite.PickStorageProvider()
gvg, found := sp.GetFirstGlobalVirtualGroup()
s.Require().True(found)
user := s.User
paymentAcc := s.GenAndChargeAccounts(1, 1000000)[0]

// CreateBucket
bucketName := storageutils.GenRandomBucketName()

msgCreateBucket := storagetypes.NewMsgCreateBucket(
user.GetAddr(), bucketName, storagetypes.VISIBILITY_TYPE_PUBLIC_READ, sp.OperatorKey.GetAddr(),
paymentAcc.GetAddr(), math.MaxUint, nil, 0)
msgCreateBucket.PrimarySpApproval.GlobalVirtualGroupFamilyId = gvg.FamilyId
msgCreateBucket.PrimarySpApproval.Sig, err = sp.ApprovalKey.Sign(msgCreateBucket.GetApprovalBytes())
s.Require().NoError(err)
s.SendTxBlock(user, msgCreateBucket)

// SetBucketRateLimit
msgSetBucketRateLimit := storagetypes.NewMsgSetBucketFlowRateLimit(paymentAcc.GetAddr(), s.User.GetAddr(), paymentAcc.GetAddr(), bucketName, sdkmath.NewInt(100000000000000))
s.SendTxBlock(paymentAcc, msgSetBucketRateLimit)

// update bucket
var readQuota uint64 = 100
msgUpdateBucketInfo := storagetypes.NewMsgUpdateBucketInfo(
user.GetAddr(), bucketName, &readQuota, nil, storagetypes.VISIBILITY_TYPE_PUBLIC_READ)
s.SendTxBlock(user, msgUpdateBucketInfo)

s.Require().NoError(err)

// QueryBucketRateLimit
ctx := context.Background()
queryBucketRateLimitRequest := storagetypes.QueryPaymentAccountBucketFlowRateLimitRequest{
PaymentAccount: paymentAcc.GetAddr().String(),
BucketName: bucketName,
}
queryBucketRateLimitResponse, err := s.Client.QueryPaymentAccountBucketFlowRateLimit(ctx, &queryBucketRateLimitRequest)
s.Require().NoError(err)
s.Require().Equal(queryBucketRateLimitResponse.IsSet, true)
s.Require().Equal(queryBucketRateLimitResponse.FlowRateLimit, sdkmath.NewInt(100000000000000))
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ replace (
github.com/cometbft/cometbft => github.com/bnb-chain/greenfield-cometbft v1.2.0
github.com/cometbft/cometbft-db => github.com/bnb-chain/greenfield-cometbft-db v0.8.1-alpha.1
github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23/go v0.8.0
github.com/cosmos/cosmos-sdk => github.com/bnb-chain/greenfield-cosmos-sdk v1.4.1-0.20240221065455-ef1f7f0d2659
github.com/cosmos/cosmos-sdk => github.com/bnb-chain/greenfield-cosmos-sdk v1.4.1-0.20240305064839-3cb07f5a365c
github.com/cosmos/iavl => github.com/bnb-chain/greenfield-iavl v0.20.1
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
github.com/wercker/journalhook => github.com/wercker/journalhook v0.0.0-20230927020745-64542ffa4117
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ github.com/bnb-chain/greenfield-cometbft v1.2.0 h1:LTStppZS9WkVj0TfEYKkk5OAQDGfY
github.com/bnb-chain/greenfield-cometbft v1.2.0/go.mod h1:WVOEZ59UYM2XePQH47/IQfcInspDn8wbRXhFSJrbU1c=
github.com/bnb-chain/greenfield-cometbft-db v0.8.1-alpha.1 h1:XcWulGacHVRiSCx90Q8Y//ajOrLNBQWR/KDB89dy3cU=
github.com/bnb-chain/greenfield-cometbft-db v0.8.1-alpha.1/go.mod h1:ey1CiK4bYo1RBNJLRiVbYr5CMdSxci9S/AZRINLtppI=
github.com/bnb-chain/greenfield-cosmos-sdk v1.4.1-0.20240221065455-ef1f7f0d2659 h1:ytOD5CuSsmV9pe9HXXJEsxiDKxHzOYShSG8s21Yw5Xw=
github.com/bnb-chain/greenfield-cosmos-sdk v1.4.1-0.20240221065455-ef1f7f0d2659/go.mod h1:XF8U3VN1euzLkIR5xiSNyQSnBabvnD86oz6fgdrpteQ=
github.com/bnb-chain/greenfield-cosmos-sdk v1.4.1-0.20240305064839-3cb07f5a365c h1:H0Rvx1FTVNgmXnUYvG0z3oFVvixPzlUHGN2JOPoNszM=
github.com/bnb-chain/greenfield-cosmos-sdk v1.4.1-0.20240305064839-3cb07f5a365c/go.mod h1:XF8U3VN1euzLkIR5xiSNyQSnBabvnD86oz6fgdrpteQ=
github.com/bnb-chain/greenfield-cosmos-sdk/api v0.0.0-20230816082903-b48770f5e210 h1:GHPbV2bC+gmuO6/sG0Tm8oGal3KKSRlyE+zPscDjlA8=
github.com/bnb-chain/greenfield-cosmos-sdk/api v0.0.0-20230816082903-b48770f5e210/go.mod h1:vhsZxXE9tYJeYB5JR4hPhd6Pc/uPf7j1T8IJ7p9FdeM=
github.com/bnb-chain/greenfield-cosmos-sdk/math v0.0.0-20230816082903-b48770f5e210 h1:FLVOn4+OVbsKi2+YJX5kmD27/4dRu4FW7xCXFhzDO5s=
Expand Down
9 changes: 9 additions & 0 deletions proto/greenfield/storage/common.proto
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,13 @@ message BucketFlowRateLimit {
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
// bucket_owner is the owner of the bucket
string bucket_owner = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}

message BucketFlowRateLimitStatus {
// is_bucket_limited defines the flow rate limit status of the bucket, true means limited and the bucket is uncharged
bool is_bucket_limited = 1;
// payment_address is the payment address of the bucket which limited the flow rate
string payment_address = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}
20 changes: 20 additions & 0 deletions proto/greenfield/storage/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ service Query {
rpc QueryGroupsExistById(QueryGroupsExistByIdRequest) returns (QueryGroupsExistResponse) {
option (google.api.http).get = "/greenfield/storage/groups_exist_by_id/{group_ids}";
}

// Queries the flow rate limit of a bucket for a payment account
rpc QueryPaymentAccountBucketFlowRateLimit(QueryPaymentAccountBucketFlowRateLimitRequest) returns (QueryPaymentAccountBucketFlowRateLimitResponse) {
option (google.api.http).get = "/greenfield/storage/payment_account_bucket_flow_rate_limit/{payment_account}/{bucket_name}";
}
}

// QueryParamsRequest is request type for the Query/Params RPC method.
Expand Down Expand Up @@ -183,6 +188,7 @@ message QueryHeadBucketByIdRequest {

message QueryHeadBucketResponse {
BucketInfo bucket_info = 1;
BucketExtraInfo extra_info = 2;
}

message QueryHeadObjectRequest {
Expand Down Expand Up @@ -416,3 +422,17 @@ message QueryGroupsExistByIdRequest {
message QueryGroupsExistResponse {
map<string, bool> exists = 1;
}

message QueryPaymentAccountBucketFlowRateLimitRequest {
string payment_account = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string bucket_name = 2;
}

message QueryPaymentAccountBucketFlowRateLimitResponse {
bool is_set = 1;
string flow_rate_limit = 2 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
}
14 changes: 14 additions & 0 deletions proto/greenfield/storage/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,17 @@ message ShadowObjectInfo {
// version define the version of object
int64 version = 7;
}

message BucketExtraInfo {
bool is_rate_limited = 1;
string flow_rate_limit = 2 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
string current_flow_rate = 3 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
}
1 change: 1 addition & 0 deletions x/storage/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func GetTxCmd() *cobra.Command {
CmdDiscontinueBucket(),
CmdMigrateBucket(),
CmdCancelMigrateBucket(),
CmdSetBucketFlowRateLimit(),
)

cmd.AddCommand(
Expand Down
63 changes: 63 additions & 0 deletions x/storage/client/cli/tx_set_bucket_flow_rate_limit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package cli

import (
"fmt"
"strconv"

sdkmath "cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/spf13/cobra"

"github.com/bnb-chain/greenfield/x/storage/types"
)

var _ = strconv.Itoa(0)

func CmdSetBucketFlowRateLimit() *cobra.Command {
cmd := &cobra.Command{
Use: "set-bucket-flow-rate-limit [bucket-name] [payment-account] [bucket-owner] [flow-rate-limit]",
Short: "cancel a existing bucket migration",
Args: cobra.ExactArgs(4),
RunE: func(cmd *cobra.Command, args []string) (err error) {
argBucketName := args[0]
argPaymentAcc := args[1]
paymentAcc, err := sdk.AccAddressFromHexUnsafe(argPaymentAcc)
if err != nil {
return err
}
argBucketOwner := args[2]
bucketOwner, err := sdk.AccAddressFromHexUnsafe(argBucketOwner)
if err != nil {
return err
}
argFlowRateLimit, ok := sdkmath.NewIntFromString(args[3])
if !ok {
return fmt.Errorf("invalid flow-rate-limit: %s", args[3])
}

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

msg := types.NewMsgSetBucketFlowRateLimit(
clientCtx.GetFromAddress(),
bucketOwner,
paymentAcc,
argBucketName,
argFlowRateLimit,
)
if err = msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}

flags.AddTxFlagsToCmd(cmd)

return cmd
}
35 changes: 35 additions & 0 deletions x/storage/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,13 @@ func (k Keeper) HeadBucket(goCtx context.Context, req *types.QueryHeadBucketRequ

bucketInfo, found := k.GetBucketInfo(ctx, req.BucketName)
if found {
extraInfo, err := k.GetBucketExtraInfo(ctx, req.BucketName)
if err != nil {
return nil, err
}
return &types.QueryHeadBucketResponse{
BucketInfo: bucketInfo,
ExtraInfo: extraInfo,
}, nil
}
return nil, types.ErrNoSuchBucket
Expand Down Expand Up @@ -674,3 +679,33 @@ func (k Keeper) QueryGroupsExistById(goCtx context.Context, req *types.QueryGrou
}
return &types.QueryGroupsExistResponse{Exists: exists}, nil
}

func (k Keeper) QueryPaymentAccountBucketFlowRateLimit(goCtx context.Context, req *types.QueryPaymentAccountBucketFlowRateLimitRequest) (*types.QueryPaymentAccountBucketFlowRateLimitResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}

ctx := sdk.UnwrapSDKContext(goCtx)

acc, err := sdk.AccAddressFromHexUnsafe(req.PaymentAccount)
if err != nil {
return nil, status.Error(codes.InvalidArgument, "invalid payment account address")
}

bucketInfo, found := k.GetBucketInfo(ctx, req.BucketName)
if !found {
return nil, types.ErrNoSuchBucket
}

flowRateLimit, found := k.getBucketFlowRateLimit(ctx, acc, bucketInfo.BucketName)
if !found {
return &types.QueryPaymentAccountBucketFlowRateLimitResponse{
IsSet: false,
}, nil
}

return &types.QueryPaymentAccountBucketFlowRateLimitResponse{
IsSet: true,
FlowRateLimit: flowRateLimit.FlowRateLimit,
}, nil
}
Loading

0 comments on commit 82d81ef

Please sign in to comment.