Skip to content

Commit

Permalink
fix review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
fynnss committed Mar 17, 2023
1 parent 0a8123f commit 6bb40c6
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
7 changes: 5 additions & 2 deletions proto/greenfield/permission/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,17 @@ message Policy {
repeated permission.Statement statements = 5;
// expiration_time defines the whole expiration time of all the statements.
// Notices: Its priority is higher than the expiration time inside the Statement
google.protobuf.Timestamp expiration_time = 7 [
google.protobuf.Timestamp expiration_time = 6 [
(gogoproto.stdtime) = true,
(gogoproto.nullable) = true
];
// member_statement define a special policy which indicates that the principal is a member of the group
permission.Statement member_statement = 6;
permission.Statement member_statement = 7;
}

// PolicyGroup refers to a group of policies which grant permission to Group, which is limited to MaxGroupNum (default 10).
// This means that a single resource can only grant permission to 10 groups. The reason for
// this is to enable on-chain determination of whether an operator has permission within a limited time.
message PolicyGroup {
message Item {
string policy_id = 1 [
Expand Down
4 changes: 2 additions & 2 deletions x/permission/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ func (k Keeper) PutPolicy(ctx sdk.Context, policy *types.Policy) (math.Uint, err
if bz != nil {
policyGroup := types.PolicyGroup{}
k.cdc.MustUnmarshal(bz, &policyGroup)
if (uint64)(len(policyGroup.Items)) >= k.MaximumGroupNum(ctx) {
if (uint64)(len(policyGroup.Items)) >= k.MaximumPolicyGroupSize(ctx) {
return math.ZeroUint(), types.ErrLimitExceeded.Wrapf("group number limit to %d, actual %d",
k.MaximumGroupNum(ctx),
k.MaximumPolicyGroupSize(ctx),
len(policyGroup.Items))
}
isFound := false
Expand Down
6 changes: 3 additions & 3 deletions x/permission/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
func (k Keeper) GetParams(ctx sdk.Context) types.Params {
return types.NewParams(
k.MaximumStatementsNum(ctx),
k.MaximumGroupNum(ctx))
k.MaximumPolicyGroupSize(ctx))
}

// SetParams set the params
Expand All @@ -23,7 +23,7 @@ func (k Keeper) MaximumStatementsNum(ctx sdk.Context) (res uint64) {
return
}

func (k Keeper) MaximumGroupNum(ctx sdk.Context) (res uint64) {
k.paramstore.Get(ctx, types.KeyMaxPolicyGroupNum, &res)
func (k Keeper) MaximumPolicyGroupSize(ctx sdk.Context) (res uint64) {
k.paramstore.Get(ctx, types.KeyMaxPolicyGroupSIze, &res)
return
}
6 changes: 3 additions & 3 deletions x/permission/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const (
)

var (
KeyMaxStatementsNum = []byte("MaxStatementsNum")
KeyMaxPolicyGroupNum = []byte("MaxPolicyGroupNum")
KeyMaxStatementsNum = []byte("MaxStatementsNum")
KeyMaxPolicyGroupSIze = []byte("MaxPolicyGroupSize")
)

var _ paramtypes.ParamSet = (*Params)(nil)
Expand All @@ -41,7 +41,7 @@ func DefaultParams() Params {
func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
return paramtypes.ParamSetPairs{
paramtypes.NewParamSetPair(KeyMaxStatementsNum, &p.MaximumStatementsNum, validateMaximumStatementsNum),
paramtypes.NewParamSetPair(KeyMaxPolicyGroupNum, &p.MaximumGroupNum, validateMaximumGroupNum),
paramtypes.NewParamSetPair(KeyMaxPolicyGroupSIze, &p.MaximumGroupNum, validateMaximumGroupNum),
}
}

Expand Down
2 changes: 1 addition & 1 deletion x/permission/types/params.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6bb40c6

Please sign in to comment.