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!: x/clock v2 - permissionless #893

Merged
merged 39 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
cc9275e
Update Clock Proto
joelsmith-2019 Nov 22, 2023
feeb9ad
Add Keeper Logic
joelsmith-2019 Nov 22, 2023
0e6c505
Update Msg Server, Querier, & Params
joelsmith-2019 Nov 22, 2023
105aec7
Add Tx Cmds
joelsmith-2019 Nov 22, 2023
91e352a
Ensure Sender is Admin
joelsmith-2019 Nov 24, 2023
3c398ce
Add Clock CLI Queries, Update Txs
joelsmith-2019 Nov 24, 2023
4fa4f3f
Update Clock Codec
joelsmith-2019 Nov 24, 2023
8b5d8e4
Fix Get All & Manager Check
joelsmith-2019 Nov 24, 2023
249bfdb
Update Genesis, Fix Genesis Export
joelsmith-2019 Nov 24, 2023
debe734
Jail Contract on Error
joelsmith-2019 Nov 24, 2023
616b214
Pass Clock Interchain Tests (Tests are Incomplete)
joelsmith-2019 Nov 24, 2023
4fd1322
Error Check on Jail Contract
joelsmith-2019 Nov 24, 2023
45fee20
Test Msg Server
joelsmith-2019 Nov 27, 2023
5885783
Test Msg Server with Admin
joelsmith-2019 Nov 27, 2023
bd468a9
Test Querier
joelsmith-2019 Nov 27, 2023
1f2b4c5
Test Params
joelsmith-2019 Nov 27, 2023
a5d52a6
Test Genesis
joelsmith-2019 Nov 27, 2023
868bf75
Update Codec Tests
joelsmith-2019 Nov 27, 2023
22c2102
Fix Msg Tests
joelsmith-2019 Nov 27, 2023
722f3b6
Refactor Stores into Singular Store
joelsmith-2019 Nov 28, 2023
1581533
Lint
joelsmith-2019 Nov 28, 2023
d4982f3
Update Tx CLI Desc, More Lint
joelsmith-2019 Nov 28, 2023
ac083ac
Update Clock SubCmd Descs
joelsmith-2019 Nov 28, 2023
3c3aa11
Remove Contracts from Genesis
joelsmith-2019 Nov 28, 2023
2070db6
Refactor Request Validation
joelsmith-2019 Nov 28, 2023
b301d75
Use Logger in EndBlocker
joelsmith-2019 Nov 28, 2023
5d737ca
Init EndBlocker Tests
joelsmith-2019 Nov 28, 2023
d6c597f
Test Clock End Blocker
joelsmith-2019 Nov 30, 2023
4d02b19
Upload Clock Contract (No Sudo)
joelsmith-2019 Dec 5, 2023
98a4d50
Add Interchain Clock Helper
joelsmith-2019 Dec 5, 2023
3525248
Add Clock Interchain Tests
joelsmith-2019 Dec 6, 2023
51234f7
Test Unregister Clock
joelsmith-2019 Dec 7, 2023
66ed2be
Update Spec Docs
joelsmith-2019 Dec 8, 2023
1f14c90
Merge branch 'main' of https://github.com/CosmosContracts/juno into j…
joelsmith-2019 Dec 12, 2023
782ff97
remove `SetupContractWithAdmin` and instead use extraFlags
Reecepbcups Dec 12, 2023
6b6010a
wait for 2 blocks in the Clock helpers (ictest thing)
Reecepbcups Dec 12, 2023
d37317f
fix: updateParams contractGasLimit
Reecepbcups Dec 12, 2023
366a6f3
patch e2e no admin flag
Reecepbcups Dec 12, 2023
084bf19
Extract Anon Func
joelsmith-2019 Dec 13, 2023
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/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,7 @@ func NewAppKeepers(
appKeepers.ClockKeeper = clockkeeper.NewKeeper(
appKeepers.keys[clocktypes.StoreKey],
appCodec,
appKeepers.WasmKeeper,
appKeepers.ContractKeeper,
govModAddress,
)
Expand Down
12 changes: 7 additions & 5 deletions interchaintest/module_clock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ func TestJunoClock(t *testing.T) {
// Submit the proposal to add it to the allowed contracts list
SubmitParamChangeProp(t, ctx, juno, user, []string{contractAddr})

// TODO: REGISTER CLOCK CONTRACT

// Wait 1 block
_ = testutil.WaitForBlocks(ctx, 1, juno)

// Validate the contract is now auto incrementing from the end blocker
res = helpers.GetClockContractValue(t, ctx, juno, contractAddr)
fmt.Printf("- res: %v\n", res.Data.Val)
require.GreaterOrEqual(t, res.Data.Val, uint32(1))
// res = helpers.GetClockContractValue(t, ctx, juno, contractAddr)
// fmt.Printf("- res: %v\n", res.Data.Val)
// require.GreaterOrEqual(t, res.Data.Val, uint32(1))

t.Cleanup(func() {
_ = ic.Close()
Expand All @@ -62,11 +64,11 @@ func SubmitParamChangeProp(t *testing.T, ctx context.Context, chain *cosmos.Cosm
updateParams := []cosmosproto.Message{
&clocktypes.MsgUpdateParams{
Authority: govAcc,
Params: clocktypes.NewParams(contracts, 1_000_000_000),
Params: clocktypes.NewParams(1_000_000_000),
},
}

proposal, err := chain.BuildProposal(updateParams, "Params Add Contract", "params", "ipfs://CID", fmt.Sprintf(`500000000%s`, chain.Config().Denom))
proposal, err := chain.BuildProposal(updateParams, "Params Update Gas Limit", "params", "ipfs://CID", fmt.Sprintf(`500000000%s`, chain.Config().Denom))
require.NoError(t, err, "error building proposal")

txProp, err := chain.SubmitProposal(ctx, user.KeyName(), proposal)
Expand Down
17 changes: 11 additions & 6 deletions proto/juno/clock/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,22 @@ message GenesisState {
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "params,omitempty"
];
}

// Params defines the set of module parameters.
message Params {
// contract_addresses stores the list of executable contracts to be ticked on every block.
repeated string contract_addresses = 1 [
repeated string contract_addresses = 2 [
joelsmith-2019 marked this conversation as resolved.
Show resolved Hide resolved
(gogoproto.jsontag) = "contract_addresses,omitempty",
(gogoproto.moretags) = "yaml:\"contract_addresses\""
];
// jailed_contract_addresses stores the list of executable contracts that have been jailed.
repeated string jailed_contract_addresses = 3 [
(gogoproto.jsontag) = "jailed_contract_addresses,omitempty",
(gogoproto.moretags) = "yaml:\"jailed_contract_addresses\""
];
}

uint64 contract_gas_limit = 2 [
// Params defines the set of module parameters.
message Params {
// contract_gas_limit defines the maximum amount of gas that can be used by a contract.
uint64 contract_gas_limit = 3 [
(gogoproto.jsontag) = "contract_gas_limit,omitempty",
(gogoproto.moretags) = "yaml:\"contract_gas_limit\""
];
Expand Down
37 changes: 37 additions & 0 deletions proto/juno/clock/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ service Query {
option (google.api.http).get =
"/juno/clock/v1/contracts";
}
// Jailed Clock Contracts
rpc JailedClockContracts(QueryJailedClockContracts)
returns (QueryJailedClockContractsResponse) {
option (google.api.http).get =
"/juno/clock/v1/contracts/jailed";
}
// ClockContract
rpc ClockContract(QueryClockContract)
returns (QueryClockContractResponse) {
option (google.api.http).get =
"/juno/clock/v1/contracts/{contract_address}";
}
// Params
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/juno/clock/v1/params";
Expand All @@ -33,6 +45,31 @@ message QueryClockContractsResponse {
];
}

// QueryJailedClockContracts is the request type to get all jailed contracts.
message QueryJailedClockContracts {}

// QueryJailedClockContractsResponse is the response type for the Query/JailedClockContracts RPC method.
message QueryJailedClockContractsResponse {
repeated string jailed_contract_addresses = 1 [
(gogoproto.jsontag) = "contract_addresses,omitempty",
(gogoproto.moretags) = "yaml:\"contract_addresses\""
];
}

// QueryClockContract is the request type to get a single contract.
message QueryClockContract {
// contract_address is the address of the contract to query.
string contract_address = 1;
}

// QueryClockContractResponse is the response type for the Query/ClockContract RPC method.
message QueryClockContractResponse {
// contract is the contract with the given address.
string contract_address = 1;
// is_jailed is the jailed status of the contract.
bool is_jailed = 2;
}

// QueryParams is the request type to get all module params.
message QueryParamsRequest {}

Expand Down
59 changes: 59 additions & 0 deletions proto/juno/clock/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package juno.clock.v1;

option go_package = "github.com/CosmosContracts/juno/x/clock/types";

import "google/api/annotations.proto";
import "cosmos/msg/v1/msg.proto";
import "juno/clock/v1/genesis.proto";
import "gogoproto/gogo.proto";
Expand All @@ -11,13 +12,71 @@ import "amino/amino.proto";

// Msg defines the Msg service.
service Msg {

// RegisterClockContract defines the endpoint for
// registering a new clock contract.
rpc RegisterClockContract(MsgRegisterClockContract)
returns (MsgRegisterClockContractResponse) {
option (google.api.http).post = "/juno/clock/v1/tx/register";
};

// UnregisterClockContract defines the endpoint for
// unregistering a clock contract.
rpc UnregisterClockContract(MsgUnregisterClockContract)
returns (MsgUnregisterClockContractResponse) {
option (google.api.http).post = "/juno/clock/v1/tx/unregister";
};

// UnjailClockContract defines the endpoint for
// unjailing a clock contract.
rpc UnjailClockContract(MsgUnjailClockContract)
returns (MsgUnjailClockContractResponse) {
option (google.api.http).post = "/juno/clock/v1/tx/unjail";
};

// UpdateParams defines a governance operation for updating the x/clock module
// parameters. The authority is hard-coded to the x/gov module account.
//
// Since: cosmos-sdk 0.47
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);
}

// MsgRegisterClockContract is the Msg/RegisterClockContract request type.
message MsgRegisterClockContract {
// The address of the sender.
string sender_address = 1;
// The address of the contract to register.
string contract_address = 2;
}

// MsgRegisterClockContractResponse defines the response structure for executing a
// MsgRegisterClockContract message.
message MsgRegisterClockContractResponse {}

// MsgUnregisterClockContract is the Msg/UnregisterClockContract request type.
message MsgUnregisterClockContract {
// The address of the sender.
string sender_address = 1;
// The address of the contract to unregister.
string contract_address = 2;
}

// MsgUnregisterClockContractResponse defines the response structure for executing a
// MsgUnregisterClockContract message.
message MsgUnregisterClockContractResponse {}

// MsgUnjailClockContract is the Msg/UnjailClockContract request type.
message MsgUnjailClockContract {
// The address of the sender.
string sender_address = 1;
// The address of the contract to unjail.
string contract_address = 2;
}

// MsgUnjailClockContractResponse defines the response structure for executing a
// MsgUnjailClockContract message.
message MsgUnjailClockContractResponse {}

// MsgUpdateParams is the Msg/UpdateParams request type.
//
// Since: cosmos-sdk 0.47
Expand Down
17 changes: 13 additions & 4 deletions x/clock/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ func EndBlocker(ctx sdk.Context, k keeper.Keeper) {

p := k.GetParams(ctx)

errorExecs := make([]string, len(p.ContractAddresses))
contracts := k.GetAllContracts(ctx, false)
errorExecs := make([]string, len(contracts))
joelsmith-2019 marked this conversation as resolved.
Show resolved Hide resolved
errorExists := false

for idx, addr := range p.ContractAddresses {
for idx, addr := range contracts {
contract, err := sdk.AccAddressFromBech32(addr)
if err != nil {
errorExecs[idx] = addr
Expand All @@ -31,12 +33,19 @@ func EndBlocker(ctx sdk.Context, k keeper.Keeper) {
childCtx := ctx.WithGasMeter(sdk.NewGasMeter(p.ContractGasLimit))
_, err = k.GetContractKeeper().Sudo(childCtx, contract, message)
if err != nil {
errorExists = true
errorExecs[idx] = addr
continue

// Jail contract on error
err = k.JailContract(ctx, addr)
if err != nil {
log.Printf("[x/clock] Failed to Error Contract %s: %v", addr, err)
joelsmith-2019 marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

if len(errorExecs) > 0 {
// Log errors if present
if errorExists {
joelsmith-2019 marked this conversation as resolved.
Show resolved Hide resolved
log.Printf("[x/clock] Execute Errors: %v", errorExecs)
}
}
57 changes: 56 additions & 1 deletion x/clock/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ func GetQueryCmd() *cobra.Command {
}
queryCmd.AddCommand(
GetCmdShowContracts(),
GetCmdShowJailedContracts(),
GetCmdShowContract(),
GetCmdParams(),
)
return queryCmd
Expand All @@ -27,7 +29,7 @@ func GetQueryCmd() *cobra.Command {
func GetCmdShowContracts() *cobra.Command {
cmd := &cobra.Command{
Use: "contracts",
Short: "Show addresses of all current contract modules",
Short: "Show addresses of all current clock contracts",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
Expand All @@ -48,6 +50,59 @@ func GetCmdShowContracts() *cobra.Command {
return cmd
}

func GetCmdShowJailedContracts() *cobra.Command {
cmd := &cobra.Command{
Use: "jailed-contracts",
Short: "Show addresses of all jailed clock contracts",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)
res, err := queryClient.JailedClockContracts(cmd.Context(), &types.QueryJailedClockContracts{})
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
}

func GetCmdShowContract() *cobra.Command {
cmd := &cobra.Command{
Use: "contract [contract_address]",
Short: "Get contract by address",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)

req := &types.QueryClockContract{
ContractAddress: args[0],
}

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

return clientCtx.PrintProto(res)
},
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
}

func GetCmdParams() *cobra.Command {
cmd := &cobra.Command{
Use: "params",
Expand Down
Loading
Loading