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: adding x/cwerrors module #546

Merged
merged 33 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
1a43fbf
adding proto types
spoo-bar Mar 5, 2024
9d8c43a
adding module skeleton
spoo-bar Mar 5, 2024
6c67a42
implement state and keeper
spoo-bar Mar 6, 2024
e0033e2
implementing errors grpc query
spoo-bar Mar 6, 2024
78079e5
implementing abci
spoo-bar Mar 6, 2024
2d3142e
adding upgrade handler
spoo-bar Mar 6, 2024
55bf497
implementing app wiring
spoo-bar Mar 6, 2024
47156e4
implementing MsgUpdateParams get signers
spoo-bar Mar 6, 2024
949ba36
adding types tests
spoo-bar Mar 6, 2024
22f021f
adding keeper tests
spoo-bar Mar 6, 2024
4d14287
adding grpc query test
spoo-bar Mar 7, 2024
1bedb68
adding genesis test
spoo-bar Mar 7, 2024
ceb0edc
adding abci test
spoo-bar Mar 7, 2024
bf328f6
updating new params
spoo-bar Mar 7, 2024
eaf5613
implement query server and msg server for subscription
spoo-bar Mar 7, 2024
370a54d
adding transient store for sudo callback
spoo-bar Mar 7, 2024
e45fdec
adding sudo error callbacks
spoo-bar Mar 11, 2024
2f4ec5c
updaet genesis export to include errors
spoo-bar Mar 11, 2024
21beb9f
updating cli to add query and txs
spoo-bar Mar 11, 2024
dba98ac
allow owners and admin to set up subscription
spoo-bar Mar 12, 2024
421cb52
Merge branch 'main' into spoorthi/errors-module
spoo-bar Mar 12, 2024
86363fa
cleanup proto
spoo-bar Mar 12, 2024
7862ea8
adding module spec
spoo-bar Mar 13, 2024
131967e
adding events
spoo-bar Mar 13, 2024
288609f
Update CHANGELOG.md
spoo-bar Mar 13, 2024
4cf3d67
linting
spoo-bar Mar 13, 2024
db5ca51
cleanup
spoo-bar Mar 13, 2024
2de647d
linting 2
spoo-bar Mar 13, 2024
4d56243
typo fix module spec
spoo-bar Mar 14, 2024
fd5a643
adding stargate query for errors fetching
spoo-bar Mar 14, 2024
5fee5d0
using sequence type to store error id which is increment value
spoo-bar Mar 14, 2024
79dd129
linting 3
spoo-bar Mar 14, 2024
310a1a1
fixing the sequence related implementation
spoo-bar Mar 14, 2024
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Contains all the PRs that improved the code without changing the behaviors.
- [#542](https://github.com/archway-network/archway/pull/542) - Adding x/cwica module
- [#543](https://github.com/archway-network/archway/pull/543) - Bumping sdk to v0.47.9
- [#544](https://github.com/archway-network/archway/pull/544) - Bumping sdk to v0.47.10
- [#546](https://github.com/archway-network/archway/pull/546) - Adding x/cwerrors module

### Improvements

Expand Down
33 changes: 31 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ import (
callbackKeeper "github.com/archway-network/archway/x/callback/keeper"
callbackTypes "github.com/archway-network/archway/x/callback/types"

"github.com/archway-network/archway/x/cwerrors"
cwerrorsKeeper "github.com/archway-network/archway/x/cwerrors/keeper"
cwerrorsTypes "github.com/archway-network/archway/x/cwerrors/types"

"github.com/archway-network/archway/x/rewards"
rewardsKeeper "github.com/archway-network/archway/x/rewards/keeper"
"github.com/archway-network/archway/x/rewards/mintbankkeeper"
Expand Down Expand Up @@ -217,6 +221,7 @@ var (
callback.AppModuleBasic{},
cwfees.AppModule{},
cwica.AppModuleBasic{},
cwerrors.AppModuleBasic{},
)

// module account permissions
Expand Down Expand Up @@ -314,9 +319,9 @@ func NewArchwayApp(
feegrant.StoreKey, authzkeeper.StoreKey, wasmdTypes.StoreKey, consensusparamtypes.StoreKey,
icacontrollertypes.StoreKey, icahosttypes.StoreKey, ibcfeetypes.StoreKey, crisistypes.StoreKey, group.StoreKey, nftkeeper.StoreKey, cwicatypes.StoreKey,

trackingTypes.StoreKey, rewardsTypes.StoreKey, callbackTypes.StoreKey, cwfees.ModuleName,
trackingTypes.StoreKey, rewardsTypes.StoreKey, callbackTypes.StoreKey, cwfees.ModuleName, cwerrorsTypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey, cwerrorsTypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)

app := &ArchwayApp{
Expand Down Expand Up @@ -536,6 +541,10 @@ func NewArchwayApp(
trackingWasmVm := wasmdTypes.NewTrackingWasmerEngine(wasmer, &wasmdTypes.NoOpContractGasProcessor{})

wasmOpts = append(wasmOpts, wasmdKeeper.WithWasmEngine(trackingWasmVm), wasmdKeeper.WithGasRegister(defaultGasRegister))
// Include the x/cwerrors query to stargate queries
wasmOpts = append(wasmOpts, wasmdKeeper.WithQueryPlugins(&wasmdKeeper.QueryPlugins{
Stargate: wasmdKeeper.AcceptListStargateQuerier(getAcceptedStargateQueries(), app.GRPCQueryRouter(), appCodec),
}))
// Archway specific options (using a pointer as the keeper is post-initialized below)
wasmOpts = append(wasmOpts, wasmbinding.BuildWasmOptions(&app.Keepers.RewardsKeeper, &app.Keepers.GovKeeper)...)

Expand Down Expand Up @@ -606,6 +615,16 @@ func NewArchwayApp(
govModuleAddr,
)

app.Keepers.CWErrorsKeeper = cwerrorsKeeper.NewKeeper(
appCodec,
keys[cwerrorsTypes.StoreKey],
tkeys[cwerrorsTypes.TStoreKey],
app.Keepers.WASMKeeper,
app.Keepers.BankKeeper,
app.Keepers.RewardsKeeper,
govModuleAddr,
)

var transferStack porttypes.IBCModule
transferStack = transfer.NewIBCModule(app.Keepers.TransferKeeper)
transferStack = ibcfee.NewIBCMiddleware(transferStack, app.Keepers.IBCFeeKeeper)
Expand Down Expand Up @@ -690,6 +709,7 @@ func NewArchwayApp(
genmsg.NewAppModule(app.MsgServiceRouter()),
callback.NewAppModule(app.appCodec, app.Keepers.CallbackKeeper, app.Keepers.WASMKeeper),
cwica.NewAppModule(appCodec, app.Keepers.CWICAKeeper, app.Keepers.AccountKeeper),
cwerrors.NewAppModule(app.appCodec, app.Keepers.CWErrorsKeeper, app.Keepers.WASMKeeper),
crisis.NewAppModule(&app.Keepers.CrisisKeeper, skipGenesisInvariants, app.getSubspace(crisistypes.ModuleName)), // always be last to make sure that it checks for all invariants and not only part of them
)

Expand Down Expand Up @@ -731,6 +751,7 @@ func NewArchwayApp(
callbackTypes.ModuleName,
cwfees.ModuleName, // does not have being blocker.
cwicatypes.ModuleName,
cwerrorsTypes.ModuleName, // does not have begin blocker
)

app.mm.SetOrderEndBlockers(
Expand Down Expand Up @@ -764,6 +785,7 @@ func NewArchwayApp(
trackingTypes.ModuleName,
rewardsTypes.ModuleName,
callbackTypes.ModuleName,
cwerrorsTypes.ModuleName,
// invariants checks are always the last to run
crisistypes.ModuleName,
cwfees.ModuleName, // does not have end blocker
Expand Down Expand Up @@ -809,6 +831,7 @@ func NewArchwayApp(
trackingTypes.ModuleName,
genmsg.ModuleName,
callbackTypes.ModuleName,
cwerrorsTypes.ModuleName,
// invariants checks are always the last to run
crisistypes.ModuleName,
cwicatypes.ModuleName,
Expand Down Expand Up @@ -1081,3 +1104,9 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino

return paramsKeeper
}

func getAcceptedStargateQueries() wasmdKeeper.AcceptedStargateQueries {
return wasmdKeeper.AcceptedStargateQueries{
"/archway.cwerrors.v1.Query/Errors": &cwerrorsTypes.QueryErrorsRequest{},
}
}
2 changes: 2 additions & 0 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"

callbackKeeper "github.com/archway-network/archway/x/callback/keeper"
cwerrorsKeeper "github.com/archway-network/archway/x/cwerrors/keeper"
cwicaKeeper "github.com/archway-network/archway/x/cwica/keeper"
rewardsKeeper "github.com/archway-network/archway/x/rewards/keeper"
trackingKeeper "github.com/archway-network/archway/x/tracking/keeper"
Expand Down Expand Up @@ -64,5 +65,6 @@ type ArchwayKeepers struct {
RewardsKeeper rewardsKeeper.Keeper
CWFeesKeeper cwfees.Keeper
CallbackKeeper callbackKeeper.Keeper
CWErrorsKeeper cwerrorsKeeper.Keeper
CWICAKeeper cwicaKeeper.Keeper
}
2 changes: 2 additions & 0 deletions app/upgrades/latest/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/archway-network/archway/app/keepers"
"github.com/archway-network/archway/app/upgrades"
callbackTypes "github.com/archway-network/archway/x/callback/types"
cwerrorstypes "github.com/archway-network/archway/x/cwerrors/types"
"github.com/archway-network/archway/x/cwfees"
cwicatypes "github.com/archway-network/archway/x/cwica/types"
)
Expand All @@ -37,6 +38,7 @@ var Upgrade = upgrades.Upgrade{
Added: []string{
callbackTypes.ModuleName,
cwfees.ModuleName,
cwerrorstypes.ModuleName,
icacontrollertypes.StoreKey,
cwicatypes.ModuleName,
},
Expand Down
2 changes: 1 addition & 1 deletion docs/static/swagger.min.json

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions proto/archway/cwerrors/v1/cwerrors.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
syntax = "proto3";
package archway.cwerrors.v1;

import "gogoproto/gogo.proto";

option go_package = "github.com/archway-network/archway/x/cwerrors/types";

// SudoError defines the sudo message for the error callback
message SudoError {
// module_name is the name of the module throwing the error
string module_name = 1;
// error_code is the module level error code
uint32 error_code = 2;
// contract_address is the address of the contract which will receive the
// error callback
string contract_address = 3;
// input_payload is any input which caused the error
string input_payload = 4;
// error_message is the error message
string error_message = 5;
}
51 changes: 51 additions & 0 deletions proto/archway/cwerrors/v1/events.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
syntax = "proto3";
package archway.cwerrors.v1;

import "gogoproto/gogo.proto";
import "archway/cwerrors/v1/params.proto";
import "archway/cwerrors/v1/cwerrors.proto";
import "cosmos/base/v1beta1/coin.proto";

option go_package = "github.com/archway-network/archway/x/cwerrors/types";

// ParamsUpdatedEvent defines the event which is thrown when the module
// parameters are updated
message ParamsUpdatedEvent {
// new_params are the new parameters for the module
Params new_params = 1 [ (gogoproto.nullable) = false ];
// authority is the address of the authority that updated the parameters
string authority = 2;
}

// SubscribedToErrorsEvent defines the event which is thrown when a contract
// subscribes to errors
message SubscribedToErrorsEvent {
// sender is the address which initiated the subscription
string sender = 1;
// contract_address is the address of the contract which is subscribed to
// errors
string contract_address = 2;
// fees_paid is the fees paid for the subscription
cosmos.base.v1beta1.Coin fees_paid = 3 [ (gogoproto.nullable) = false ];
// subscription_valid_till is the block height till which the subscription is
// valid
int64 subscription_valid_till = 4;
}

// StoringErrorEvent defines the event which is thrown when an error is stored
message StoringErrorEvent {
// error is the error which is stored
SudoError error = 1 [ (gogoproto.nullable) = false ];
// deletion_block_height is the block height at which the error will be pruned
// from the state
int64 deletion_block_height = 2;
}

// SudoErrorCallbackFailedEvent defines the event which is thrown when a sudo
// error callback fails
message SudoErrorCallbackFailedEvent {
// error is the error for which the callback is executed
SudoError error = 1 [ (gogoproto.nullable) = false ];
// callback_error_message is the error message of why the callback failed
string callback_error_message = 2;
}
16 changes: 16 additions & 0 deletions proto/archway/cwerrors/v1/genesis.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
syntax = "proto3";
package archway.cwerrors.v1;

import "gogoproto/gogo.proto";
import "archway/cwerrors/v1/params.proto";
import "archway/cwerrors/v1/cwerrors.proto";

option go_package = "github.com/archway-network/archway/x/cwerrors/types";

// GenesisState defines the cwerrors module's genesis state.
message GenesisState {
// params defines all the module parameters.
Params params = 1 [ (gogoproto.nullable) = false ];
// errors defines all the sudo errors currently registered.
repeated SudoError errors = 2 [ (gogoproto.nullable) = false ];
}
18 changes: 18 additions & 0 deletions proto/archway/cwerrors/v1/params.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
syntax = "proto3";
package archway.cwerrors.v1;

import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";

option go_package = "github.com/archway-network/archway/x/cwerrors/types";

// Params defines the set of parameters for the cwerrors module.
message Params {
// error_stored_time is the block height until which error is stored
int64 error_stored_time = 1;
// subsciption_fee is the fee required to subscribe to error callbacks
cosmos.base.v1beta1.Coin subscription_fee = 2
[ (gogoproto.nullable) = false ];
// subscription_period is the period for which the subscription is valid
int64 subscription_period = 3;
}
65 changes: 65 additions & 0 deletions proto/archway/cwerrors/v1/query.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
syntax = "proto3";
package archway.cwerrors.v1;

import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "cosmos/base/v1beta1/coin.proto";
import "archway/cwerrors/v1/cwerrors.proto";
import "archway/cwerrors/v1/params.proto";

option go_package = "github.com/archway-network/archway/x/cwerrors/types";

// Query service for the cwerrors module.
service Query {
// Params queries all the module parameters.
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/archway/cwerrors/v1/params";
}

// Errors queries all the errors for a given contract.
rpc Errors(QueryErrorsRequest) returns (QueryErrorsResponse) {
option (google.api.http).get = "/archway/cwerrors/v1/errors";
}

// IsSubscribed queries if a contract is subscribed to sudo error callbacks.
rpc IsSubscribed(QueryIsSubscribedRequest)
returns (QueryIsSubscribedResponse) {
option (google.api.http).get = "/archway/cwerrors/v1/is_subscribed";
}
}

// QueryParamsRequest is the request for Query.Params.
message QueryParamsRequest {}

// QueryParamsResponse is the response for Query.Params.
message QueryParamsResponse {
// params defines all the module parameters.
Params params = 1 [ (gogoproto.nullable) = false ];
}

// QueryErrorsRequest is the request for Query.Errors.
message QueryErrorsRequest {
// contract_address is the address of the contract whose errors to query for
string contract_address = 1;
}

// QueryErrorsResponse is the response for Query.Errors.
message QueryErrorsResponse {
// errors defines all the contract errors which will be returned
repeated SudoError errors = 1 [ (gogoproto.nullable) = false ];
}

// QueryIsSubscribedRequest is the request for Query.IsSubscribed.
message QueryIsSubscribedRequest {
// contract_address is the address of the contract to query if subscribed
string contract_address = 1;
}

// QueryIsSubscribedResponse is the response for Query.IsSubscribed.
message QueryIsSubscribedResponse {
// subscribed defines if the contract is subscribed to sudo error callbacks
bool subscribed = 1;
// subscription_valid_till defines the block height till which the
// subscription is valid
int64 subscription_valid_till = 2;
}
60 changes: 60 additions & 0 deletions proto/archway/cwerrors/v1/tx.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
syntax = "proto3";
package archway.cwerrors.v1;

import "gogoproto/gogo.proto";
import "cosmos/msg/v1/msg.proto";
import "cosmos/base/v1beta1/coin.proto";
import "archway/cwerrors/v1/params.proto";

option go_package = "github.com/archway-network/archway/x/cwerrors/types";

// Msg defines the cwerrors Msg service.
service Msg {
// UpdateParams defines a governance operation for updating the x/cwerrors
// module parameters. The authority is defined in the keeper.
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);
// SubscribeToError defines an operation which will register a contract for a
// sudo callback on errors
rpc SubscribeToError(MsgSubscribeToError)
returns (MsgSubscribeToErrorResponse);
}

// MsgUpdateParams is the Msg/UpdateParams request type.
message MsgUpdateParams {
option (cosmos.msg.v1.signer) = "authority";
// authority is the address that controls the module (defaults to x/gov unless
// overwritten).
string authority = 1;
// params defines the x/cwerrors parameters to update.
//
// NOTE: All parameters must be supplied.
Params params = 2 [
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "params,omitempty"
];
}

// MsgUpdateParamsResponse defines the response structure for executing a
// MsgUpdateParams message.
message MsgUpdateParamsResponse {}

// MsgSubscribeToError is the Msg/SubscribeToError request type.
message MsgSubscribeToError {
option (cosmos.msg.v1.signer) = "sender";
// sender is the address of who is registering the contarcts for callback on
// error
string sender = 1;
// contract is the address of the contract that will be called on error
string contract_address = 2;
// fee is the subscription fee for the feature (current no fee is charged for
// this feature)
cosmos.base.v1beta1.Coin fee = 3 [ (gogoproto.nullable) = false ];
}

// MsgSubscribeToErrorResponse defines the response structure for executing a
// MsgSubscribeToError message.
message MsgSubscribeToErrorResponse {
// subscription_valid_till is the block height till which the subscription is
// valid
int64 subscription_valid_till = 1;
}
Loading
Loading