Skip to content

Commit

Permalink
add params to disable script (#254)
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 authored Aug 23, 2024
1 parent 6e1f68e commit cfafc11
Show file tree
Hide file tree
Showing 11 changed files with 1,549 additions and 465 deletions.
1,295 changes: 1,007 additions & 288 deletions api/initia/gov/v1/gov.pulsar.go

Large diffs are not rendered by default.

361 changes: 246 additions & 115 deletions api/initia/move/v1/types.pulsar.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/docs/statik/statik.go

Large diffs are not rendered by default.

113 changes: 113 additions & 0 deletions client/docs/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49604,6 +49604,21 @@ paths:
applied

for Move execute messages.
vesting:
description: Vesting is the vesting contract info for tally.
type: object
properties:
module_addr:
type: string
description: module_addr is the address of the vesting module.
module_name:
type: string
description: module_name is the name of the vesting module.
creator_addr:
type: string
description: >-
creator_addr is the address of the creator of the
vesting contract.
description: >-
QueryParamsResponse is the response type for the Query/Params RPC
method.
Expand Down Expand Up @@ -51611,6 +51626,9 @@ paths:
contract_shared_revenue_ratio:
type: string
title: 'CSR: Percentage of fees distributed to developers'
script_enabled:
type: boolean
title: flag whether to enable script execution
allowed_publishers:
type: array
items:
Expand Down Expand Up @@ -52888,6 +52906,12 @@ paths:
type: string
format: byte
description: Hash of the l2 output.
l1_block_number:
type: string
format: uint64
description: >-
The l1 block number that the output root was
submitted in.
l1_block_time:
type: string
format: date-time
Expand Down Expand Up @@ -53032,6 +53056,10 @@ paths:
type: string
format: byte
description: Hash of the l2 output.
l1_block_number:
type: string
format: uint64
description: The l1 block number that the output root was submitted in.
l1_block_time:
type: string
format: date-time
Expand Down Expand Up @@ -53150,6 +53178,12 @@ paths:
type: string
format: byte
description: Hash of the l2 output.
l1_block_number:
type: string
format: uint64
description: >-
The l1 block number that the output root was
submitted in.
l1_block_time:
type: string
format: date-time
Expand Down Expand Up @@ -53297,6 +53331,10 @@ paths:
type: string
format: byte
description: Hash of the l2 output.
l1_block_number:
type: string
format: uint64
description: The l1 block number that the output root was submitted in.
l1_block_time:
type: string
format: date-time
Expand Down Expand Up @@ -85581,6 +85619,21 @@ definitions:
Low threshold functions for emergency and expedited proposal.
These are Move function identifiers and can only be applied
for Move execute messages.
vesting:
description: Vesting is the vesting contract info for tally.
type: object
properties:
module_addr:
type: string
description: module_addr is the address of the vesting module.
module_name:
type: string
description: module_name is the name of the vesting module.
creator_addr:
type: string
description: >-
creator_addr is the address of the creator of the vesting
contract.
description: Params defines the parameters for the x/gov module.
initia.gov.v1.Proposal:
type: object
Expand Down Expand Up @@ -86338,6 +86391,21 @@ definitions:
Low threshold functions for emergency and expedited proposal.
These are Move function identifiers and can only be applied
for Move execute messages.
vesting:
description: Vesting is the vesting contract info for tally.
type: object
properties:
module_addr:
type: string
description: module_addr is the address of the vesting module.
module_name:
type: string
description: module_name is the name of the vesting module.
creator_addr:
type: string
description: >-
creator_addr is the address of the creator of the vesting
contract.
description: QueryParamsResponse is the response type for the Query/Params RPC method.
initia.gov.v1.QueryProposalResponse:
type: object
Expand Down Expand Up @@ -86956,6 +87024,21 @@ definitions:
description: |-
QueryProposalsResponse is the response type for the Query/Proposals RPC
method.
initia.gov.v1.Vesting:
type: object
properties:
module_addr:
type: string
description: module_addr is the address of the vesting module.
module_name:
type: string
description: module_name is the name of the vesting module.
creator_addr:
type: string
description: creator_addr is the address of the creator of the vesting contract.
description: |-
Vesting defines the vesting contract info for MsgVestingVote.
At tally time, gov module would check vesting token amount.
initia.move.v1.Module:
type: object
properties:
Expand Down Expand Up @@ -86996,6 +87079,9 @@ definitions:
contract_shared_revenue_ratio:
type: string
title: 'CSR: Percentage of fees distributed to developers'
script_enabled:
type: boolean
title: flag whether to enable script execution
allowed_publishers:
type: array
items:
Expand Down Expand Up @@ -87177,6 +87263,9 @@ definitions:
contract_shared_revenue_ratio:
type: string
title: 'CSR: Percentage of fees distributed to developers'
script_enabled:
type: boolean
title: flag whether to enable script execution
allowed_publishers:
type: array
items:
Expand Down Expand Up @@ -87788,6 +87877,10 @@ definitions:
type: string
format: byte
description: Hash of the l2 output.
l1_block_number:
type: string
format: uint64
description: The l1 block number that the output root was submitted in.
l1_block_time:
type: string
format: date-time
Expand Down Expand Up @@ -87852,6 +87945,10 @@ definitions:
type: string
format: byte
description: Hash of the l2 output.
l1_block_number:
type: string
format: uint64
description: The l1 block number that the output root was submitted in.
l1_block_time:
type: string
format: date-time
Expand Down Expand Up @@ -87910,6 +88007,10 @@ definitions:
type: string
format: byte
description: Hash of the l2 output.
l1_block_number:
type: string
format: uint64
description: The l1 block number that the output root was submitted in.
l1_block_time:
type: string
format: date-time
Expand Down Expand Up @@ -88098,6 +88199,10 @@ definitions:
type: string
format: byte
description: Hash of the l2 output.
l1_block_number:
type: string
format: uint64
description: The l1 block number that the output root was submitted in.
l1_block_time:
type: string
format: date-time
Expand Down Expand Up @@ -88135,6 +88240,10 @@ definitions:
type: string
format: byte
description: Hash of the l2 output.
l1_block_number:
type: string
format: uint64
description: The l1 block number that the output root was submitted in.
l1_block_time:
type: string
format: date-time
Expand Down Expand Up @@ -88168,6 +88277,10 @@ definitions:
type: string
format: byte
description: Hash of the l2 output.
l1_block_number:
type: string
format: uint64
description: The l1 block number that the output root was submitted in.
l1_block_time:
type: string
format: date-time
Expand Down
8 changes: 7 additions & 1 deletion proto/initia/move/v1/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ message Params {
(amino.dont_omitempty) = true
];

// flag whether to enable script execution
bool script_enabled = 4;

// It is a list of addresses with permission to distribute contracts,
// and an empty list is interpreted as allowing anyone to distribute.
repeated string allowed_publishers = 4
repeated string allowed_publishers = 5
[(gogoproto.moretags) = "yaml:\"allowed_publishers\"", (amino.dont_omitempty) = true];
}

Expand All @@ -53,6 +56,9 @@ message RawParams {
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true
];

// flag whether to enable script execution
bool script_enabled = 4;
}

// Module is data for the uploaded contract move code
Expand Down
10 changes: 8 additions & 2 deletions x/move/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,15 @@ func (ms MsgServer) ExecuteJSON(context context.Context, req *types.MsgExecuteJS
}

// Script implements script execution
func (ms MsgServer) Script(context context.Context, req *types.MsgScript) (*types.MsgScriptResponse, error) {
func (ms MsgServer) Script(ctx context.Context, req *types.MsgScript) (*types.MsgScriptResponse, error) {
if ok, err := ms.ScriptEnabled(ctx); err != nil {
return nil, err
} else if !ok {
return nil, errors.Wrap(types.ErrScriptDisabled, "script execution is disabled")
}

defer telemetry.MeasureSince(time.Now(), "move", "msg", "script")
ctx := sdk.UnwrapSDKContext(context)

if err := req.Validate(ms.ac); err != nil {
return nil, err
}
Expand Down
15 changes: 15 additions & 0 deletions x/move/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,21 @@ func TestScriptMsg(t *testing.T) {
require.NoError(t, err)
}

func Test_ScriptDisabled(t *testing.T) {
ctx, input := createDefaultTestInput(t)

params, err := input.MoveKeeper.GetParams(ctx)
require.NoError(t, err)

params.ScriptEnabled = false
err = input.MoveKeeper.SetParams(ctx, params)
require.NoError(t, err)

msgServer := keeper.NewMsgServerImpl(&input.MoveKeeper)
_, err = msgServer.Script(ctx, nil)
require.ErrorIs(t, err, types.ErrScriptDisabled)
}

func Test_ExecuteMsg(t *testing.T) {
ctx, input := createDefaultTestInput(t)
ms := keeper.NewMsgServerImpl(&input.MoveKeeper)
Expand Down
10 changes: 10 additions & 0 deletions x/move/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ func (k Keeper) ContractSharedRevenueRatio(ctx context.Context) (math.LegacyDec,
return params.ContractSharedRevenueRatio, nil
}

// ScriptEnabled - script execution enabled
func (k Keeper) ScriptEnabled(ctx context.Context) (bool, error) {
params, err := k.GetParams(ctx)
if err != nil {
return false, err
}

return params.ScriptEnabled, nil
}

// SetParams sets the x/move module parameters.
func (k Keeper) SetParams(ctx context.Context, params types.Params) error {
if err := k.SetRawParams(ctx, params.ToRaw()); err != nil {
Expand Down
3 changes: 3 additions & 0 deletions x/move/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,7 @@ var (

// ErrAddressAlreadyTaken error raised when the address is already taken
ErrAddressAlreadyTaken = errorsmod.Register(ModuleName, 15, "address already taken")

// ErrScriptDisabled error raised when the script execution is disabled
ErrScriptDisabled = errorsmod.Register(ModuleName, 16, "script execution disabled")
)
6 changes: 5 additions & 1 deletion x/move/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import (

// Default parameter values
const (
DefaultBaseDenom = "uinit"
DefaultBaseDenom = "uinit"
DefaultScriptEnabled = true
)

var (
Expand All @@ -35,6 +36,7 @@ func DefaultParams() Params {
BaseDenom: DefaultBaseDenom,
BaseMinGasPrice: DefaultBaseMinGasPrice,
ContractSharedRevenueRatio: DefaultContractSharedRevenueRatio,
ScriptEnabled: DefaultScriptEnabled,
AllowedPublishers: nil,
}
}
Expand Down Expand Up @@ -74,6 +76,7 @@ func (p Params) ToRaw() RawParams {
BaseDenom: p.BaseDenom,
BaseMinGasPrice: p.BaseMinGasPrice,
ContractSharedRevenueRatio: p.ContractSharedRevenueRatio,
ScriptEnabled: p.ScriptEnabled,
}
}

Expand All @@ -84,6 +87,7 @@ func (p RawParams) ToParams(allowedPublishers []string) Params {
BaseMinGasPrice: p.BaseMinGasPrice,
ContractSharedRevenueRatio: p.ContractSharedRevenueRatio,
AllowedPublishers: allowedPublishers,
ScriptEnabled: p.ScriptEnabled,
}
}

Expand Down
Loading

0 comments on commit cfafc11

Please sign in to comment.