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: implement paymaster #582

Merged
merged 26 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ func (app *App) registerSerengetiUpgradeHandler() {
app.GashubKeeper.SetMsgGasParams(ctx, *gashubtypes.NewMsgGasParamsWithFixedGas(sdk.MsgTypeURL(&storagemoduletypes.MsgDelegateCreateObject{}), 1.2e3))
app.GashubKeeper.SetMsgGasParams(ctx, *gashubtypes.NewMsgGasParamsWithFixedGas(sdk.MsgTypeURL(&storagemoduletypes.MsgDelegateUpdateObjectContent{}), 1.2e3))
app.GashubKeeper.SetMsgGasParams(ctx, *gashubtypes.NewMsgGasParamsWithFixedGas(sdk.MsgTypeURL(&storagemoduletypes.MsgSealObjectV2{}), 1.2e2))
app.GashubKeeper.SetMsgGasParams(ctx, *gashubtypes.NewMsgGasParamsWithFixedGas(sdk.MsgTypeURL(&storagemoduletypes.MsgSetBucketFlowRateLimit{}), 1.2e3))
return app.mm.RunMigrations(ctx, app.configurator, fromVM)
})

Expand Down
406 changes: 406 additions & 0 deletions e2e/tests/storage_rate_limit_test.go

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions proto/greenfield/storage/common.proto
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,19 @@ message LocalVirtualGroup {
// Notice that the minimum unit of charge is 128K
uint64 total_charge_size = 4;
}

message BucketFlowRateLimit {
Copy link
Contributor

Choose a reason for hiding this comment

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

BucketFlowRateLimit is just Int. Why we need this instead of using Int?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we can add another fields

// flow_rate_limit defines the flow rate limit of the bucket
string flow_rate_limit = 1 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
}

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"];
}
24 changes: 24 additions & 0 deletions proto/greenfield/storage/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -631,3 +631,27 @@ message EventCancelUpdateObjectContent {
(gogoproto.nullable) = false
];
}

message EventSetBucketFlowRateLimit {
yutianwu marked this conversation as resolved.
Show resolved Hide resolved
// operator define the account address of operator who set the bucket flow rate limit
string operator = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// bucket_name define the name of the bucket
string bucket_name = 2;
// payment_address define the payment address for the bucket
string payment_address = 3 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// bucket_owner define the intended owner of the bucket
string bucket_owner = 4 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// flow_rate_limit define the flow rate limit of the bucket
string flow_rate_limit = 5 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
}

message EventBucketFlowRateLimitStatus {
// bucket_name define the name of the bucket
string bucket_name = 1;
// is_limited define the status of the bucket flow rate limit
bool is_limited = 2;
}
21 changes: 21 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,18 @@ message QueryGroupsExistByIdRequest {
message QueryGroupsExistResponse {
map<string, bool> exists = 1;
}

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

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
];
}
23 changes: 23 additions & 0 deletions proto/greenfield/storage/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ service Msg {

// Since: Manchurian upgrade
rpc SetTag(MsgSetTag) returns (MsgSetTagResponse);

rpc SetBucketFlowRateLimit(MsgSetBucketFlowRateLimit) returns (MsgSetBucketFlowRateLimitResponse);
}

message MsgCreateBucket {
Expand Down Expand Up @@ -772,3 +774,24 @@ message MsgToggleSPAsDelegatedAgent {
}

message MsgToggleSPAsDelegatedAgentResponse {}

message MsgSetBucketFlowRateLimit {
option (cosmos.msg.v1.signer) = "operator";

// operator defines the account address of the operator, either the object owner or the updater with granted permission.
string operator = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// bucket_name defines the name of the bucket
string bucket_name = 2;
// bucket_owner defines the account address of the bucket owner
string bucket_owner = 3 [(cosmos_proto.scalar) = "cosmos.AddressString"];
yutianwu marked this conversation as resolved.
Show resolved Hide resolved
// payment_address defines an account address to pay the fee for the bucket.
string payment_address = 4 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// flow_rate_limit defines the flow rate limit of the bucket
string flow_rate_limit = 5 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
}

message MsgSetBucketFlowRateLimitResponse {}
14 changes: 14 additions & 0 deletions proto/greenfield/storage/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,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
];
}
94 changes: 94 additions & 0 deletions swagger/static/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2632,6 +2632,15 @@ paths:

when a bucket is created, by default, this is false, means
SP is allowed to create object for delegator
extra_info:
type: object
properties:
is_rate_limited:
type: boolean
flow_rate_limit:
type: string
current_flow_rate:
type: string
default:
description: An unexpected error response.
schema:
Expand Down Expand Up @@ -2764,6 +2773,15 @@ paths:

when a bucket is created, by default, this is false, means
SP is allowed to create object for delegator
extra_info:
type: object
properties:
is_rate_limited:
type: boolean
flow_rate_limit:
type: string
current_flow_rate:
type: string
default:
description: An unexpected error response.
schema:
Expand Down Expand Up @@ -5089,6 +5107,57 @@ paths:
format: int64
tags:
- Query
/greenfield/storage/payment_account_bucket_flow_rate_limit/{payment_account}/{bucket_name}:
get:
summary: Queries the flow rate limit of a bucket for a payment account
operationId: QueryPaymentAccountBucketFlowRateLimit
responses:
'200':
description: A successful response.
schema:
type: object
properties:
is_set:
type: boolean
flow_rate_limit:
type: string
default:
description: An unexpected error response.
schema:
type: object
properties:
error:
type: string
code:
type: integer
format: int32
message:
type: string
details:
type: array
items:
type: object
properties:
type_url:
type: string
value:
type: string
format: byte
parameters:
- name: payment_account
in: path
required: true
type: string
- name: bucket_name
in: path
required: true
type: string
- name: bucket_owner
in: query
required: false
type: string
tags:
- Query
/greenfield/storage/policy_by_id/{policy_id}:
get:
summary: Queries a policy by policy id
Expand Down Expand Up @@ -34813,6 +34882,15 @@ definitions:
- RESOURCE_TYPE_OBJECT
- RESOURCE_TYPE_GROUP
default: RESOURCE_TYPE_UNSPECIFIED
greenfield.storage.BucketExtraInfo:
type: object
properties:
is_rate_limited:
type: boolean
flow_rate_limit:
type: string
current_flow_rate:
type: string
greenfield.storage.BucketInfo:
type: object
properties:
Expand Down Expand Up @@ -35605,6 +35683,15 @@ definitions:

when a bucket is created, by default, this is false, means SP is
allowed to create object for delegator
extra_info:
type: object
properties:
is_rate_limited:
type: boolean
flow_rate_limit:
type: string
current_flow_rate:
type: string
greenfield.storage.QueryHeadGroupMemberResponse:
type: object
properties:
Expand Down Expand Up @@ -36525,6 +36612,13 @@ definitions:
Relayer fee for the ACK or FAIL_ACK package of the mirror object
tx to op chain
description: QueryParamsResponse is response type for the Query/Params RPC method.
greenfield.storage.QueryPaymentAccountBucketFlowRateLimitResponse:
type: object
properties:
is_set:
type: boolean
flow_rate_limit:
type: string
greenfield.storage.QueryPolicyByIdResponse:
type: object
properties:
Expand Down
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: "set flow rate limit for a bucket",
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
}
Loading
Loading