Skip to content

Commit

Permalink
Create a Sanction module (#401)
Browse files Browse the repository at this point in the history
* [1046]: Update the bank module to allow for a sanction keeper.

* [1046]: Create sanction protos and make proto-gen.

* [1046]: In the BlockGas unit test, set the sanction keeper to nil to keep costs the same as when the test was written.

* [1046]: Get the updated ReadPageRequest stuff from the quarantine branch.

* [1046]: make proto-gen on the bank module to get the updated comments.

* [1046]: Fix the package of the query proto.

* [1046]: Change the IsSanctioned keeper method into IsSanctionedAddr to avoid a conflict with the name of the query server method.

* [1046] Create the sanction module and stub out everything it needs.

* [1046]: Start fleshing out the keeper functions.

* [1046]: Update protos. Remove the immediate messages. Add endpoints for querying and updating params.

* [1046]: make proto-format to fix some pre-existing formatting.

* [1046]: Make proto-gen.

* [1046]: Rename SanctionImmediateParams to just ImmediateParams.

* [1046]: Implement all the ValidateBasic msg funcs. Update the genesis type stuff to account for the params and provide stuff for default params.

* [1046]: Rename a couple keeper funcs to hopefully make them more accurate and clearer.

* [1046]: Update the msg server and grpc query keepers to reflect removal of immediate endpoints and addition of params stuff.

* [1046]: Implement the store decoder (for simulation).

* [1046]: Rename the params stuff.

* [1046]: More renaming of some params-related stuff and addition of keeper stuff for params in state.

* [1046]: Fix the name of the addresses field in the query response.

* [1046]: Add a query for temporary entries.

* [1046]: Implement the grpc queries.

* [1046]: init and export genesis.

* [1046]: Implement the msg server stuff.

* [1046]: Emit the events.

* [1046]: Change the IsSanctioned REST endoint to 'check' (from 'active') because I think that's a better name for it.

* [1046]: Implement the cli query commands.

* [1046]: Remove the tx command stuff since it's all gov props.

* [1046]: Do the governance hooks for the most part.

* [1046]: Refactor some keys stuff and add a proposal->temp index. Made the params prefix 0x00 and bumped the rest up one. Moved the params-related functions to the top. Fixed variables named Id because gofmt says (incorrectly IMO) that it should be ID.

* [1046]: Update the keeper. When creating/deleting temp entries, also do the gov prop index entries. When sanctioning or unsanctioning addresses, also delete their temp entries (and those indexes). Add some msgTypeURLs to the keeper so that they're defined once and after everything's registered (hopefully), and usable by the gov_hooks stuff.

* [1046]: Update the gov hooks to account for the temp stuff being cleaned up when a proposal passes and also account for the proposal in question not being found. Also, make sure the min immediate deposit isn't zero before making the temp entries.

* [1046]: Handle the proposal message being a MsgExecLegacyContent wrapping what we really want.

* [1046]: Turns out the Coins proto fields need to have nullable = false. Bah.

* [1046]: Enhance the genesis state validation invalid address message to include the bad addr and error.

* [1046]: Unit tests on the genesis types funcs.

* [1046]: Enhance the msg ValidateBasic error messages to include more info.

* [1046]: Fix a var name.

* [1046]: Unit tests on the Msg functions.

* [1046]: Lint fix.

* [1046]: Unit tests on the sanction params simple stuff.

* [1046]: Start in on keys unit tests.

* [1046]: Some more keys tests and bedtime.

* [1046]: Update the key prefix creators to return a copy of the prefix bytes if the provided thing isn't provided. That way, the thing returned doesn't have extra capacity if we're not expecting to need it.

* [1046]: Finish the keys tests.

* [1046]: Add the sanction keeper to the app.

* [1046]: Remove the bank keeper from the sanction keeper since it's not needed anywhere but the constructor (to tell the bank keeper about itself). Change IsSanctionableAddr to take in an AccAddress and use the stringified addresses in the map instead of the bech32s; the place where I wanted to call it already has them as AccAddresses. When adding either a sanction or temp sanction, make sure the address is sanctionable first.

* [1046]: Start in on the keeper tests.

* [1046]: In IsSanctionedAddr, return false if no addr is provided. Same in IsSanctionableAddr.

* [1046]: Make isSanctionableAddr private because it's so closely named with IsSanctionedAddr and probably isn't that helpful outside the module. If I decide to make it public again, I'll need to come up with a different name.

* [1046]: Some more progress on the keeper unit tests.

* [1046]: Rename isSanctionableAddr to IsAddrThatCannotBeSanctioned and refactor its use. For temp sanctions, move the check into addTempEntries. In IsSanctionedAddr, check IsAddrThatCannotBeSanctioned first, just to be safe. When looking up the latest temp addr, make sure an addr is provided (otherwise it just gets the first temp entry in the store for any addr). Add some comments.

* [1046]: Finish up the keeper tests.

* [1046]: Add temp entries to the genesis proto.

* [1046]: Add temp entries to init/export genesis.

* [1046]: Fix bank unit tests so they compile. Remove the AppModule.Name function since AppModuleBasic requires it too, so it's just being double defined.

* [1046]: Update the sanction simulation store decoder to include the proposal index prefixed keys.

* [1046]: Add the sanction module to the migration tests since the store key is needed due to the restriction.

* [1046]: When creating the simapp, give the correct gov keeper to the sanction keeper constructor. Also, provide it as a reference so that it's later updated appropriately.

* [1046]: Unpack the MsgExecLegacyContent into a reference to it, since that's what the any has and what the codec can decode.

* [1046]: Rename the keeper test funcs to be more in line with standards.

* [1046]: Allow the genState to be nil to InitGenesis. Fix the addr error check in there. Add more context to several of the panic messages in InitGenesis.

* [1046]: Tweak AssertErrorContents to read a bit better. Tweak AssertPanicsWithMessage to have better failure messages. Create AssertPanicContents and AssertNotPanicsNoError and their Require partners.

* [1046]: Prepend OnlyTests to the exported test-only functions.

* [1046]: Add unit tests on genesis keeper funcs.

* [1046]: Tweak the keys tests that check for duplicate values to only have one sub-test per entry and do the duplicate checking under that. Also give them better error messages. Add similar tests on the msg urls in the keeper.

* [1046]: Rename the TestSuite to KeeperTestSuite since I decided not to just put all keeper tests on that struct.

* [1046]: Get rid of unwrapLegacyGovPropMsg. Our new stuff doesn't implement the Content interface, so it can't be in a legacy exec message. Also make things play nicer with nils; probably not needed, but whatever, it makes tests happier.

* [1046]: Create a BaseTestSuite with the stuff needed in the keeper tests, and have the keeper and genesis tests just expand off that object. The BaseTestSuite is a nice place to put commonly needed functions like ClearState. Also, I made all those funcs public since it's for unit testing and there's no good reason to try to keep any of it private.

* [1046]: Move ExportAndCheck out of the genesis test suite into the base one and create a GetStore func since that's a commmonly needed thing in here.

* [1046]: Most of the gov hooks tests, at least on the smaller pieces. Starting in on the proposalGovHook tests.

* [1046]: Tweak the keeper a bit. When creating a temp entry, emit the event after writing both keys just to group logic together. Refactor DeleteGovPropTempEntries to built the keys-to-delete list in the iterator and get the store if there's something to delete. In DeleteAddrTempEntries, only create the store if there's something to delete. Now those two are designed the same way.

* [1046]: Fix the proposalGovHook. As it was, it would do nothing if the proposal wasn't found since there wouldn't be any messages to loop through. Basically, put the status switch at the top level and only loop through the messages when in deposit or voting period since those are the only cases where we care about what the proposal had.

* [1046]: change the unknown gov prop panic message to invalid.

* [1046]: Finish up the proposalGovHook tests.

* [1046]: grpc query tests.

* [1046]: Tweak some error messages from the msg server.

* [1046]: Unit test on the msg server endpoints.

* [1046]: Add some bank module tests.

* [1046]: Unit tests on the CLI queries.

* [1046]: Simulation decoder test.

* [1046]: Implement that simulation random genesis state.

* [1046]: Tweak the RandomParams function to a) have much lower values (more in line with what accounts might have), and b) have a 20% chance of being nil. Add function comments to the simulation genesis funcs.

* [1046]: Unit tests on the simulation genesis funcs.

* [1046]: Stub out the simulation weighted ops stuff. Add the governance keeper to the module so we can look up the gov prop deposit requirements.

* [1046]: Write up all the simulation operations.

* [1046]: Fix maxCoins, make it public, and add unit tests on it.

* [1046]: Make SendGovMsg and OperationMsgVote public so it can be unit tested. Remove the AnyUnpacker since it's not used. Properly set the sanction keeper in the args.

* [1046]: Provide a ProtoCodec to the WeightedOperations function. It's needed because we don't implement LegacyMsg stuff. Provide it when sending things. Clean things up a bit. Set the op msg comment to indicate what's going on since they're all gov props. Send the whole deposit instead of picking a denom since all the denoms are needed anyway.

* [1046]: Write TestWeightedOperations.

* [1046]: For immediate ops, use r to decide yes or no vote before it gets used for anything else.

* [1046]: Add a few test cases to the MaxCoins tests.

* [1046]: Unit tests on SendGovMsg.

* [1046]: Rename a OperationMsgVote argument to voter (from simAccount) for extra clarity.

* [1046]: In TestSendGovMsg, if we expect it to be successful, get the gov prop and make sure it's actually there.

* [1046]: Unit tests on OperationMsgVote.

* [1046]: If there's an error getting the proposal id (no clue how), don't create the future ops.

* [1046]: Unit tests on SimulateGovMsg Sanction and Unsanction.

* [1046]: Some function comments.

* [1046]: Slight tweak to some variable names (accs instead of accts) and some comment tweaks.

* [1046]: Unit tests on the simulation immediate stuff.

* [1046]: In SimulateGovMsgUpdateParams, generate the random params before picking the sender.

* [1046]: Unit tests on SimulateGovMsgUpdateParams.

* [1046]: Refactor the sims to a) only sanction new addrs because sanctioning known accounts causes other sims to fail, and b) unsanction addresses that are sanctioned instead of just using random addresses.

* [1046]: When creating the random genesis state, use fresh addresses instead of existing ones since using existing ones breaks all the other ops.

* [1046]: Set the gov keeper in the module, just as nature intended.

* [1046]: Provide the maccPerms account addresses as unsanctionable.

* [1046]: First draft of the spec documentation.

* [1046]: Fix some spec doc stuff.

* [1046]: Fix a couple comments copied from the quarantine stuff.

* [1046]: Fix an event comment.

* [1046]: Add some more missing proto comments.

* [1046]: Add a nondeterministic warning to ModuleAccounts.

* [1046]: Add a missing comment on the GovKeeper expected interface.

* [1046]: Add genesis validation on the temporary entries.

* [1046]: Fix a couple test names.

* [1046]: Fix a few comments on the gov hooks.

* [1046]: Some lint fixes.

* [1046]: Fix a couple function comments in the keeper.

* [1046]: Add RequireNotPanicsNoError to the BaseTestSuite and use that in a bunch of places to clean stuff up.

* [1046]: use 0x01 for the sanction state value to match the temp value. Rename the TempSanctionB and TempUnsanctionB stuff to not have Temp so they can be used for permanent if desired.

* [1046]: Some more test cleanup to make better use of some of the setup helper functions used elsewhere.

* [1046]: Slight tweak to a comment.

* [1046]: Get rid of the getSeedValue and replace it with a func that just creates the new rand with that seed value since it's used exactly like that for all calls.

* [1046]: Update state spec docs to reflect the change of sanctioned addr value to 0x01 (from 0x00).

* [1046]: Refactor AssertNotPanicsNoError to make it less confusing. Previously, at first glance, it looked like it wasn't returning the right thing when it all passed because the last line was return false. But the last line was only getting used if there was a panic. So while it was returning correctly, it was confusing to read. So I fixed that (hopefully).

* [1046]: Tweak the concepts a bit for wording and put the complex interactions at the end.

* [1046]: Add an integration test that sanctions a validator.

* [1046]: Add alias c to the is-sanctioned CLI command.

* [1046]: Add changelog entry.

* [1046]: Add the sanction module to the main spec readme list.
  • Loading branch information
SpicyLemon committed Jan 24, 2023
1 parent 3aeadb3 commit 7ea989a
Show file tree
Hide file tree
Showing 66 changed files with 21,917 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* [#270](https://github.com/provenance-io/cosmos-sdk/pull/270) Add functionality to update denom metadata via gov proposal.
* (x/gov,cli) [#434](https://github.com/provenance-io/cosmos-sdk/pull/434) Added `AddGovPropFlagsToCmd` and `ReadGovPropFlags` functions.
* (quarantine) [#335](https://github.com/provenance-io/cosmos-sdk/pull/335) Create the `x/quarantine` module.
* (sanction) [#401](https://github.com/provenance-io/cosmos-sdk/pull/401) Create the `x/sanction` module.

### Improvements

Expand Down
5 changes: 3 additions & 2 deletions baseapp/block_gas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,12 @@ func TestBaseApp_BlockGas(t *testing.T) {
&testdata.TestMsg{},
)
app = simapp.NewSimApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, map[int64]bool{}, "", 0, encCfg, simapp.EmptyAppOptions{}, routerOpt)
// Disable the quarantine module so that the sends (executed below) still consume the same amount of gas
// Disable the sanction and quarantine modules so that the sends (executed below) still consume the same amount of gas
// as when this test was written. Without this, the expGasConsumed check fails due to an extra store lookup
// during a transfer (checking for quarantine). I felt doing this was safer than trying to manually verify
// during a transfer (checking for sanction). I felt doing this was safer than trying to manually verify
// that the new gas numbers are correct so that the expected values could be updated with confidence.
app.BankKeeper.SetQuarantineKeeper(nil)
app.BankKeeper.SetSanctionKeeper(nil)
genState := simapp.GenesisStateWithSingleValidator(t, app)
stateBytes, err := tmjson.MarshalIndent(genState, "", " ")
require.NoError(t, err)
Expand Down
29 changes: 29 additions & 0 deletions proto/cosmos/sanction/v1beta1/events.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
syntax = "proto3";
package cosmos.sanction.v1beta1;

import "cosmos_proto/cosmos.proto";

option go_package = "github.com/cosmos/cosmos-sdk/x/sanction";

// EventAddressSanctioned is an event emitted when an address is sanctioned.
message EventAddressSanctioned {
string address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}

// EventAddressUnsanctioned is an event emitted when an address is unsanctioned.
message EventAddressUnsanctioned {
string address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}

// EventTempAddressSanctioned is an event emitted when an address is temporarily sanctioned.
message EventTempAddressSanctioned {
string address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}

// EventTempAddressUnsanctioned is an event emitted when an address is temporarily unsanctioned.
message EventTempAddressUnsanctioned {
string address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}

// EventParamsUpdated is an event emitted when the sanction module params are updated.
message EventParamsUpdated {}
17 changes: 17 additions & 0 deletions proto/cosmos/sanction/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
syntax = "proto3";
package cosmos.sanction.v1beta1;

import "cosmos/sanction/v1beta1/sanction.proto";
import "cosmos_proto/cosmos.proto";

option go_package = "github.com/cosmos/cosmos-sdk/x/sanction";

// GenesisState defines the sanction module's genesis state.
message GenesisState {
// params are the sanction module parameters.
Params params = 1;
// sanctioned_addresses defines account addresses that are sanctioned.
repeated string sanctioned_addresses = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// temporary_entries defines the temporary entries associated with on-going governance proposals.
repeated TemporaryEntry temporary_entries = 3;
}
84 changes: 84 additions & 0 deletions proto/cosmos/sanction/v1beta1/query.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
syntax = "proto3";
package cosmos.sanction.v1beta1;

import "cosmos/base/query/v1beta1/pagination.proto";
import "cosmos/sanction/v1beta1/sanction.proto";
import "cosmos_proto/cosmos.proto";
import "google/api/annotations.proto";

option go_package = "github.com/cosmos/cosmos-sdk/x/sanction";

// Query defines the gRPC querier service.
service Query {
// IsSanctioned checks if an account has been sanctioned.
rpc IsSanctioned(QueryIsSanctionedRequest) returns (QueryIsSanctionedResponse) {
option (google.api.http).get = "/cosmos/sanction/v1beta1/check/{address}";
}

// SanctionedAddresses returns a list of sanctioned addresses.
rpc SanctionedAddresses(QuerySanctionedAddressesRequest) returns (QuerySanctionedAddressesResponse) {
option (google.api.http).get = "/cosmos/sanction/v1beta1/all";
}

// TemporaryEntries returns temporary sanction/unsanction info.
rpc TemporaryEntries(QueryTemporaryEntriesRequest) returns (QueryTemporaryEntriesResponse) {
option (google.api.http).get = "/cosmos/sanction/v1beta1/temp";
}

// Params returns the sanction module's params.
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/cosmos/sanction/v1beta1/params";
}
}

// QueryIsSanctionedRequest defines the RPC request for checking if an account is sanctioned.
message QueryIsSanctionedRequest {
string address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}

// QueryIsSanctionedResponse defines the RPC response of an IsSanctioned query.
message QueryIsSanctionedResponse {
// is_sanctioned is true if the address is sanctioned.
bool is_sanctioned = 1;
}

// QuerySanctionedAddressesRequest defines the RPC request for listing sanctioned accounts.
message QuerySanctionedAddressesRequest {
// pagination defines an optional pagination for the request.
cosmos.base.query.v1beta1.PageRequest pagination = 99;
}

// QuerySanctionedAddressesResponse defines the RPC response of a SanctionedAddresses query.
message QuerySanctionedAddressesResponse {
// addresses is the list of sanctioned account addresses.
repeated string addresses = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// pagination defines the pagination in the response.
cosmos.base.query.v1beta1.PageResponse pagination = 99;
}

// QueryTemporaryEntriesRequest defines the RPC request for listing temporary sanction/unsanction entries.
message QueryTemporaryEntriesRequest {
// address is an optional address to restrict results to.
string address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// pagination defines an optional pagination for the request.
cosmos.base.query.v1beta1.PageRequest pagination = 99;
}

// QueryTemporaryEntriesResponse defines the RPC response of a TemporaryEntries query.
message QueryTemporaryEntriesResponse {
repeated TemporaryEntry entries = 1;

// pagination defines the pagination in the response.
cosmos.base.query.v1beta1.PageResponse pagination = 99;
}

// QueryParamsRequest defines the RPC request for getting the sanction module params.
message QueryParamsRequest {}

// QueryParamsResponse defines the RPC response of a Params query.
message QueryParamsResponse {
// params are the sanction module parameters.
Params params = 1;
}
47 changes: 47 additions & 0 deletions proto/cosmos/sanction/v1beta1/sanction.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
syntax = "proto3";
package cosmos.sanction.v1beta1;

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

option go_package = "github.com/cosmos/cosmos-sdk/x/sanction";

// Params defines the configurable parameters of the sanction module.
message Params {
// immediate_sanction_min_deposit is the minimum deposit for a sanction to happen immediately.
// If this is zero, immediate sanctioning is not available.
// Otherwise, if a sanction governance proposal is issued with a deposit at least this large, a temporary sanction
// will be immediately issued that will expire when voting ends on the governance proposal.
repeated cosmos.base.v1beta1.Coin immediate_sanction_min_deposit = 1
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"];

// immediate_unsanction_min_deposit is the minimum deposit for an unsanction to happen immediately.
// If this is zero, immediate unsanctioning is not available.
// Otherwise, if an unsanction governance proposal is issued with a deposit at least this large, a temporary
// unsanction will be immediately issued that will expire when voting ends on the governance proposal.
repeated cosmos.base.v1beta1.Coin immediate_unsanction_min_deposit = 2
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"];
}

// TemporaryEntry defines the information involved in a temporary sanction or unsanction.
message TemporaryEntry {
// address is the address of this temporary entry.
string address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// proposal_id is the governance proposal id associated with this temporary entry.
uint64 proposal_id = 2;
// status is whether the entry is a sanction or unsanction.
TempStatus status = 3;
}

// TempStatus is whether a temporary entry is a sanction or unsanction.
enum TempStatus {
option (gogoproto.goproto_enum_prefix) = false;

// TEMP_STATUS_UNSPECIFIED represents and unspecified status value.
TEMP_STATUS_UNSPECIFIED = 0;
// TEMP_STATUS_SANCTIONED indicates a sanction is in place.
TEMP_STATUS_SANCTIONED = 1;
// TEMP_STATUS_UNSANCTIONED indicates an unsanctioned is in place.
TEMP_STATUS_UNSANCTIONED = 2;
}
65 changes: 65 additions & 0 deletions proto/cosmos/sanction/v1beta1/tx.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
syntax = "proto3";
package cosmos.sanction.v1beta1;

import "cosmos/msg/v1/msg.proto";
import "cosmos/sanction/v1beta1/sanction.proto";
import "cosmos_proto/cosmos.proto";

option go_package = "github.com/cosmos/cosmos-sdk/x/sanction";

// Msg defines the sanction Msg service.
service Msg {
// Sanction is a governance operation for sanctioning addresses.
rpc Sanction(MsgSanction) returns (MsgSanctionResponse);

// Unsanction is a governance operation for unsanctioning addresses.
rpc Unsanction(MsgUnsanction) returns (MsgUnsanctionResponse);

// UpdateParams is a governance operation for updating the sanction module params.
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);
}

// MsgSanction represents a message for the governance operation of sanctioning addresses.
message MsgSanction {
option (cosmos.msg.v1.signer) = "authority";

// addresses are the addresses to sanction.
repeated string addresses = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// authority is the address of the account with the authority to enact sanctions (most likely the governance module
// account).
string authority = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}

// MsgOptInResponse defines the Msg/Sanction response type.
message MsgSanctionResponse {}

// MsgSanction represents a message for the governance operation of unsanctioning addresses.
message MsgUnsanction {
option (cosmos.msg.v1.signer) = "authority";

// addresses are the addresses to unsanction.
repeated string addresses = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// authority is the address of the account with the authority to retract sanctions (most likely the governance module
// account).
string authority = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}

// MsgOptInResponse defines the Msg/Unsanction response type.
message MsgUnsanctionResponse {}

// MsgUpdateParams represents a message for the governance operation of updating the sanction module params.
message MsgUpdateParams {
option (cosmos.msg.v1.signer) = "authority";

// params are the sanction module parameters.
Params params = 1;

// authority is the address of the account with the authority to update params (most likely the governance module
// account).
string authority = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}

// MsgUpdateParamsResponse defined the Msg/UpdateParams response type.
message MsgUpdateParamsResponse {}
36 changes: 28 additions & 8 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ import (
"github.com/cosmos/cosmos-sdk/x/quarantine"
quarantinekeeper "github.com/cosmos/cosmos-sdk/x/quarantine/keeper"
quarantinemodule "github.com/cosmos/cosmos-sdk/x/quarantine/module"
"github.com/cosmos/cosmos-sdk/x/sanction"
sanctionkeeper "github.com/cosmos/cosmos-sdk/x/sanction/keeper"
sanctionmodule "github.com/cosmos/cosmos-sdk/x/sanction/module"
"github.com/cosmos/cosmos-sdk/x/slashing"
slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
Expand Down Expand Up @@ -134,6 +137,7 @@ var (
vesting.AppModuleBasic{},
nftmodule.AppModuleBasic{},
quarantinemodule.AppModuleBasic{},
sanctionmodule.AppModuleBasic{},
)

// module account permissions
Expand Down Expand Up @@ -187,6 +191,7 @@ type SimApp struct {
GroupKeeper groupkeeper.Keeper
NFTKeeper nftkeeper.Keeper
QuarantineKeeper quarantinekeeper.Keeper
SanctionKeeper sanctionkeeper.Keeper

// the module manager
mm *module.Manager
Expand Down Expand Up @@ -227,7 +232,7 @@ func NewSimApp(
minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey,
govtypes.StoreKey, paramstypes.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey,
evidencetypes.StoreKey, capabilitytypes.StoreKey,
authzkeeper.StoreKey, nftkeeper.StoreKey, group.StoreKey, quarantine.StoreKey,
authzkeeper.StoreKey, nftkeeper.StoreKey, group.StoreKey, quarantine.StoreKey, sanction.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
// NOTE: The testingkey is just mounted for testing purposes. Actual applications should
Expand Down Expand Up @@ -326,9 +331,13 @@ func NewSimApp(
&stakingKeeper, govRouter, app.MsgServiceRouter(), govConfig,
)

app.SanctionKeeper = sanctionkeeper.NewKeeper(appCodec, keys[sanction.StoreKey],
app.BankKeeper, &govKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(), app.ModuleAccounts())

app.GovKeeper = *govKeeper.SetHooks(
govtypes.NewMultiGovHooks(
// register the governance hooks
app.SanctionKeeper,
),
)

Expand Down Expand Up @@ -374,6 +383,7 @@ func NewSimApp(
groupmodule.NewAppModule(appCodec, app.GroupKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
nftmodule.NewAppModule(appCodec, app.NFTKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
quarantinemodule.NewAppModule(appCodec, app.QuarantineKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
sanctionmodule.NewAppModule(appCodec, app.SanctionKeeper, app.AccountKeeper, app.BankKeeper, app.GovKeeper, app.interfaceRegistry),
)

// During begin block slashing happens after distr.BeginBlocker so that
Expand All @@ -386,15 +396,15 @@ func NewSimApp(
evidencetypes.ModuleName, stakingtypes.ModuleName,
authtypes.ModuleName, banktypes.ModuleName, govtypes.ModuleName, crisistypes.ModuleName, genutiltypes.ModuleName,
authz.ModuleName, feegrant.ModuleName, nft.ModuleName, group.ModuleName,
paramstypes.ModuleName, vestingtypes.ModuleName, quarantine.ModuleName,
paramstypes.ModuleName, vestingtypes.ModuleName, quarantine.ModuleName, sanction.ModuleName,
)
app.mm.SetOrderEndBlockers(
crisistypes.ModuleName, govtypes.ModuleName, stakingtypes.ModuleName,
capabilitytypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName, distrtypes.ModuleName,
slashingtypes.ModuleName, minttypes.ModuleName,
genutiltypes.ModuleName, evidencetypes.ModuleName, authz.ModuleName,
feegrant.ModuleName, nft.ModuleName, group.ModuleName,
paramstypes.ModuleName, upgradetypes.ModuleName, vestingtypes.ModuleName, quarantine.ModuleName,
paramstypes.ModuleName, upgradetypes.ModuleName, vestingtypes.ModuleName, quarantine.ModuleName, sanction.ModuleName,
)

// NOTE: The genutils module must occur after staking so that pools are
Expand All @@ -408,7 +418,7 @@ func NewSimApp(
slashingtypes.ModuleName, govtypes.ModuleName, minttypes.ModuleName, crisistypes.ModuleName,
genutiltypes.ModuleName, evidencetypes.ModuleName, authz.ModuleName,
feegrant.ModuleName, nft.ModuleName, group.ModuleName,
paramstypes.ModuleName, upgradetypes.ModuleName, vestingtypes.ModuleName, quarantine.ModuleName,
paramstypes.ModuleName, upgradetypes.ModuleName, vestingtypes.ModuleName, quarantine.ModuleName, sanction.ModuleName,
)

// Uncomment if you want to set a custom migration order here.
Expand Down Expand Up @@ -527,16 +537,26 @@ func (app *SimApp) LoadHeight(height int64) error {
return app.LoadVersion(height)
}

// ModuleAccountAddrs returns all the app's module account addresses.
// ModuleAccountAddrs returns all the app's module account address bech32 strings.
func (app *SimApp) ModuleAccountAddrs() map[string]bool {
modAccAddrs := make(map[string]bool)
for acc := range maccPerms {
modAccAddrs[authtypes.NewModuleAddress(acc).String()] = true
for _, addr := range app.ModuleAccounts() {
modAccAddrs[addr.String()] = true
}

return modAccAddrs
}

// ModuleAccounts returns all the app's module accounts addresses.
// Warning, this result is nondeterministic. It must be sorted (by you) if order has any chance of being important.
func (app *SimApp) ModuleAccounts() []sdk.AccAddress {
rv := make([]sdk.AccAddress, 0, len(maccPerms))
for name := range maccPerms {
rv = append(rv, authtypes.NewModuleAddress(name))
}
return rv
}

// LegacyAmino returns SimApp's amino codec.
//
// NOTE: This is solely to be used for testing purposes as it may be desirable
Expand Down
Loading

0 comments on commit 7ea989a

Please sign in to comment.