Skip to content

Commit

Permalink
Add the Sanction Module (#1922)
Browse files Browse the repository at this point in the history
* [1901]: Copy the sanction protos from our SDK fork.

* [1901]: Change the go_package in the sanction protos to this repo.

* [1901]: Copy the x/sanction stuff from our SDK fork.

* [1901]: Remove imports of the old simapp stuff.

* [1901]: Fix all the imports of the sanction module.

* [1901]: Clean up the codec and make the AppModule satisfy the interface again.

* [1901]: Fix comment in no-now-lint.sh referencing old tendermint library.

* [1901]: Swap in cometbft imports for the tendermint ones.

* [1901]: Delete some old module methods that aren't needed or used anymore and fix some types that moved.

* [1901]: Update the expected keepers.

* [1901]: Update getLastProposal in the msg service router test to get stuff directly instead of using .Walk on all props.

* [1901]: Create the wrapped gov keeper and use that in the sanction keeper so that I can still mock proposals.

* [1901]: Fix the send restriction to use a context.Context.

* [1901]: Fix last usage of sdk.NewInt.

* [1901]: Fix a couple imports in previously generated code (will just regenerate later, but this is a quick fix).

* [1901]: Replace the test_helpers stuff with our standard assertions stuff.

* [1901]: Make GenerateOrBroadcastTxCLIAsGovProp and use that for the sanction stuff (will do the rest later after this gets in, I guess). Also make generic funcs for the --authority flag. Fix uses of simState.AppParams.GetOrGenerate.

* [1901]: Fix calls to FundAccount.

* [1901]: Reorder module interface assertions to match others.

* [1901]: Remove internal tools since it's not needed anymore.

* [1901]: make proto-regen.

* [1901]: Remove duplicate ; from name.proto.

* [1901]: Add the sanction module back into the app.

* [1901]: Fix a marker unit test that's getting the next proposal id instead of the most recent one.

* [1901]: Fix most of the problems in the operations tests.

* [1901]: Fix nextBlock() maybe.

* [1901]: Clean up the names of things in export_test and fix several lint issues.

* [1901]: Add cosmossdk.io/collections to go.mod.

* [1901]: Remove github.com/regen-network/cosmos-proto v0.3.1 from go.mod since its not needed anymore.

* [1901]: Fix the simulation tests.

* [1901]: Rename a test file that wasn't quite right.

* [1901]: Add some helpers to use for cli query tests. Make the sanction cli tests compile (using the new helpers).

* [1901]: Make the codec in app.New instead of having it provided, and make some helpers for getting the codec stuff.

* [1901]: Add a TODO to the MakeTestEncodingConfig function to get rid of it.

* [1901]: Delete all the NAVs from the migrations in order to make build times much, much better.

* [1901]: Add some missing codec-setup lines to app.New.

* [1901]: Remove unneeded import.

* [1901]: Set the chain-id when creating the app in the CLI tests.

* [1901]: Change the CLI query helpers be specific to unit tests so that I can log more stuff and make it easier to debug problems.

* [1901]: Fix the sanction cli tests.

* [1901]: Add changelog entry.

* [1901]: Add the sanction key back into the import-export sim test.

* [1901]: Delete some more navs.

* [1901]: Add the sanction stuff to the swagger config and regenerate it.

* [1901]: Update spec docs: Add link in main readme to the sanction docs. Add TOCs to the sanction docs, fix the proto links, and do a little cleanup.
  • Loading branch information
SpicyLemon authored Apr 10, 2024
1 parent c1db1a7 commit ee6b992
Show file tree
Hide file tree
Showing 98 changed files with 68,300 additions and 27,329 deletions.
4 changes: 3 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,10 @@ linters-settings:

- github.com/armon/go-metrics

- cosmossdk.io/math
- cosmossdk.io/core
- cosmossdk.io/errors
- cosmossdk.io/math
- cosmossdk.io/store
- github.com/cosmos/go-bip39
- github.com/cosmos/cosmos-sdk
- github.com/cosmos/ibc-go/v6
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* Bump cosmos-SDK to `v0.50.2` (from `v0.46.13-pio-2`) [#1772](https://github.com/provenance-io/provenance/issues/1772).
* Add store for crisis module for sdk v0.50 [#1760](https://github.com/provenance-io/provenance/issues/1760).
* Add PreBlocker support for sdk v0.50 [#1760](https://github.com/provenance-io/provenance/issues/1760).
* Add the Sanction module back in [#1922](https://github.com/provenance-io/provenance/pull/1922).

### Improvements

Expand Down
93 changes: 57 additions & 36 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"cosmossdk.io/log"
sdkmath "cosmossdk.io/math"
"cosmossdk.io/x/tx/signing"

storetypes "cosmossdk.io/store/types"
"cosmossdk.io/x/evidence"
Expand All @@ -32,6 +33,9 @@ import (
"cosmossdk.io/x/upgrade"
upgradekeeper "cosmossdk.io/x/upgrade/keeper"
upgradetypes "cosmossdk.io/x/upgrade/types"
"github.com/cosmos/cosmos-sdk/codec/address"
"github.com/cosmos/cosmos-sdk/std"
"github.com/cosmos/gogoproto/proto"

icq "github.com/cosmos/ibc-apps/modules/async-icq/v8"
icqkeeper "github.com/cosmos/ibc-apps/modules/async-icq/v8/keeper"
Expand All @@ -40,9 +44,6 @@ import (
// "github.com/cosmos/cosmos-sdk/x/quarantine" // TODO[1760]: quarantine
// quarantinekeeper "github.com/cosmos/cosmos-sdk/x/quarantine/keeper" // TODO[1760]: quarantine
// quarantinemodule "github.com/cosmos/cosmos-sdk/x/quarantine/module" // TODO[1760]: quarantine
// "github.com/cosmos/cosmos-sdk/x/sanction" // TODO[1760]: sanction
// sanctionkeeper "github.com/cosmos/cosmos-sdk/x/sanction/keeper" // TODO[1760]: sanction
// sanctionmodule "github.com/cosmos/cosmos-sdk/x/sanction/module" // TODO[1760]: sanction

dbm "github.com/cosmos/cosmos-db"
"github.com/cosmos/cosmos-sdk/baseapp"
Expand Down Expand Up @@ -131,7 +132,7 @@ import (
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"
ibctestingtypes "github.com/cosmos/ibc-go/v8/testing/types"

appparams "github.com/provenance-io/provenance/app/params"
simappparams "github.com/provenance-io/provenance/app/params"
"github.com/provenance-io/provenance/internal/antewrapper"
piohandlers "github.com/provenance-io/provenance/internal/handlers"
"github.com/provenance-io/provenance/internal/pioconfig"
Expand Down Expand Up @@ -177,6 +178,9 @@ import (
rewardkeeper "github.com/provenance-io/provenance/x/reward/keeper"
rewardmodule "github.com/provenance-io/provenance/x/reward/module"
rewardtypes "github.com/provenance-io/provenance/x/reward/types"
"github.com/provenance-io/provenance/x/sanction"
sanctionkeeper "github.com/provenance-io/provenance/x/sanction/keeper"
sanctionmodule "github.com/provenance-io/provenance/x/sanction/module"
triggerkeeper "github.com/provenance-io/provenance/x/trigger/keeper"
triggermodule "github.com/provenance-io/provenance/x/trigger/module"
triggertypes "github.com/provenance-io/provenance/x/trigger/types"
Expand Down Expand Up @@ -266,7 +270,7 @@ type App struct {
MsgFeesKeeper msgfeeskeeper.Keeper
RewardKeeper rewardkeeper.Keeper
// QuarantineKeeper quarantinekeeper.Keeper // TODO[1760]: quarantine
// SanctionKeeper sanctionkeeper.Keeper // TODO[1760]: sanction
SanctionKeeper sanctionkeeper.Keeper
TriggerKeeper triggerkeeper.Keeper
OracleKeeper oraclekeeper.Keeper
ConsensusParamsKeeper consensusparamkeeper.Keeper
Expand Down Expand Up @@ -329,15 +333,29 @@ func init() {
// New returns a reference to an initialized Provenance Blockchain App.
func New(
logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool, skipUpgradeHeights map[int64]bool,
homePath string, invCheckPeriod uint, encodingConfig appparams.EncodingConfig,
homePath string, invCheckPeriod uint,
appOpts servertypes.AppOptions, baseAppOptions ...func(*baseapp.BaseApp),
) *App {
appCodec := encodingConfig.Marshaler
legacyAmino := encodingConfig.Amino
interfaceRegistry := encodingConfig.InterfaceRegistry
interfaceRegistry, _ := types.NewInterfaceRegistryWithOptions(types.InterfaceRegistryOptions{
ProtoFiles: proto.HybridResolver,
SigningOptions: signing.Options{
AddressCodec: address.Bech32Codec{
Bech32Prefix: sdk.GetConfig().GetBech32AccountAddrPrefix(),
},
ValidatorAddressCodec: address.Bech32Codec{
Bech32Prefix: sdk.GetConfig().GetBech32ValidatorAddrPrefix(),
},
},
})
appCodec := codec.NewProtoCodec(interfaceRegistry)
legacyAmino := codec.NewLegacyAmino()
txConfig := tx.NewTxConfig(appCodec, tx.DefaultSignModes)

std.RegisterLegacyAminoCodec(legacyAmino)
std.RegisterInterfaces(interfaceRegistry)

bApp := baseapp.NewBaseApp("provenanced", logger, db, encodingConfig.TxConfig.TxDecoder(), baseAppOptions...)
bApp.SetMsgServiceRouter(piohandlers.NewPioMsgServiceRouter(encodingConfig.TxConfig.TxDecoder()))
bApp := baseapp.NewBaseApp("provenanced", logger, db, txConfig.TxDecoder(), baseAppOptions...)
bApp.SetMsgServiceRouter(piohandlers.NewPioMsgServiceRouter(txConfig.TxDecoder()))
bApp.SetCommitMultiStoreTracer(traceStore)
bApp.SetVersion(version.Version)
bApp.SetInterfaceRegistry(interfaceRegistry)
Expand Down Expand Up @@ -365,7 +383,7 @@ func New(
wasmtypes.StoreKey,
rewardtypes.StoreKey,
// quarantine.StoreKey, // TODO[1760]: quarantine
// sanction.StoreKey, // TODO[1760]: sanction
sanction.StoreKey,
triggertypes.StoreKey,
oracletypes.StoreKey,
hold.StoreKey,
Expand Down Expand Up @@ -445,10 +463,8 @@ func New(
EnabledSignModes: enabledSignModes,
TextualCoinMetadataQueryFn: txmodule.NewBankKeeperCoinMetadataQueryFn(app.BankKeeper),
}
txConfig, err := tx.NewTxConfigWithOptions(
appCodec,
txConfigOpts,
)
var err error
txConfig, err = tx.NewTxConfigWithOptions(appCodec, txConfigOpts)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -679,15 +695,14 @@ func New(
)
oracleModule := oraclemodule.NewAppModule(appCodec, app.OracleKeeper, app.AccountKeeper, app.BankKeeper, app.IBCKeeper.ChannelKeeper)

// TODO[1760]: sanction
// unsanctionableAddrs := make([]sdk.AccAddress, 0, len(maccPerms)+1)
// for mName := range maccPerms {
// unsanctionableAddrs = append(unsanctionableAddrs, authtypes.NewModuleAddress(mName))
// }
// unsanctionableAddrs = append(unsanctionableAddrs, authtypes.NewModuleAddress(quarantine.ModuleName))
// app.SanctionKeeper = sanctionkeeper.NewKeeper(appCodec, keys[sanction.StoreKey],
// app.BankKeeper, &app.GovKeeper,
// govAuthority, unsanctionableAddrs)
unsanctionableAddrs := make([]sdk.AccAddress, 0, len(maccPerms)+1)
for mName := range maccPerms {
unsanctionableAddrs = append(unsanctionableAddrs, authtypes.NewModuleAddress(mName))
}
// unsanctionableAddrs = append(unsanctionableAddrs, authtypes.NewModuleAddress(quarantine.ModuleName)) // TODO[1760]: quarantine
app.SanctionKeeper = sanctionkeeper.NewKeeper(appCodec, keys[sanction.StoreKey],
app.BankKeeper, &app.GovKeeper,
govAuthority, unsanctionableAddrs)

// register the proposal types
govRouter := govtypesv1beta1.NewRouter()
Expand All @@ -706,11 +721,7 @@ func New(
// Set legacy router for backwards compatibility with gov v1beta1
govKeeper.SetLegacyRouter(govRouter)

app.GovKeeper = *govKeeper.SetHooks(
govtypes.NewMultiGovHooks(
// app.SanctionKeeper // TODO[1760]: sanction
),
)
app.GovKeeper = *govKeeper.SetHooks(govtypes.NewMultiGovHooks(app.SanctionKeeper))

// Create static IBC router, add transfer route, then set and seal it
ibcRouter := porttypes.NewRouter()
Expand Down Expand Up @@ -764,7 +775,7 @@ func New(
groupmodule.NewAppModule(appCodec, app.GroupKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper),
// quarantinemodule.NewAppModule(appCodec, app.QuarantineKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), // TODO[1760]: quarantine
// sanctionmodule.NewAppModule(appCodec, app.SanctionKeeper, app.AccountKeeper, app.BankKeeper, app.GovKeeper, app.interfaceRegistry), // TODO[1760]: sanction
sanctionmodule.NewAppModule(appCodec, app.SanctionKeeper, app.AccountKeeper, app.BankKeeper, app.GovKeeper, app.interfaceRegistry),

// PROVENANCE
metadata.NewAppModule(appCodec, app.MetadataKeeper, app.AccountKeeper),
Expand Down Expand Up @@ -851,7 +862,7 @@ func New(
nametypes.ModuleName,
vestingtypes.ModuleName,
// quarantine.ModuleName, // TODO[1760]: quarantine
// sanction.ModuleName, // TODO[1760]: sanction
sanction.ModuleName,
hold.ModuleName,
exchange.ModuleName,
consensusparamtypes.ModuleName,
Expand Down Expand Up @@ -893,7 +904,7 @@ func New(
feegrant.ModuleName,
paramstypes.ModuleName,
// quarantine.ModuleName, // TODO[1760]: quarantine
// sanction.ModuleName, // TODO[1760]: sanction
sanction.ModuleName,
hold.ModuleName,
exchange.ModuleName,
consensusparamtypes.ModuleName,
Expand Down Expand Up @@ -921,7 +932,7 @@ func New(
group.ModuleName,
feegrant.ModuleName,
// quarantine.ModuleName, // TODO[1760]: quarantine
// sanction.ModuleName, // TODO[1760]: sanction
sanction.ModuleName,

nametypes.ModuleName,
attributetypes.ModuleName,
Expand Down Expand Up @@ -969,7 +980,7 @@ func New(
upgradetypes.ModuleName,
vestingtypes.ModuleName,
// quarantine.ModuleName, // TODO[1760]: quarantine
// sanction.ModuleName, // TODO[1760]: sanction
sanction.ModuleName,
hold.ModuleName,
exchange.ModuleName,
consensusparamtypes.ModuleName, // TODO[1760]: Is this the correct placement?
Expand Down Expand Up @@ -1012,7 +1023,7 @@ func New(
authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
groupmodule.NewAppModule(appCodec, app.GroupKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
// quarantinemodule.NewAppModule(appCodec, app.QuarantineKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), // TODO[1760]: quarantine
// sanctionmodule.NewAppModule(appCodec, app.SanctionKeeper, app.AccountKeeper, app.BankKeeper, app.GovKeeper, app.interfaceRegistry), // TODO[1760]: sanction
sanctionmodule.NewAppModule(appCodec, app.SanctionKeeper, app.AccountKeeper, app.BankKeeper, app.GovKeeper, app.interfaceRegistry),

metadata.NewAppModule(appCodec, app.MetadataKeeper, app.AccountKeeper),
marker.NewAppModule(appCodec, app.MarkerKeeper, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.GovKeeper, app.AttributeKeeper, app.interfaceRegistry),
Expand Down Expand Up @@ -1247,6 +1258,16 @@ func (app *App) InterfaceRegistry() types.InterfaceRegistry {
return app.interfaceRegistry
}

// GetEncodingConfig returns the various encoding configurations used in this app.
func (app *App) GetEncodingConfig() simappparams.EncodingConfig {
return simappparams.EncodingConfig{
InterfaceRegistry: app.InterfaceRegistry(),
Marshaler: app.AppCodec(),
TxConfig: app.GetTxConfig(),
Amino: app.LegacyAmino(),
}
}

// DefaultGenesis returns a default genesis from the registered AppModuleBasic's.
func (app *App) DefaultGenesis() map[string]json.RawMessage {
return app.BasicModuleManager.DefaultGenesis(app.appCodec)
Expand Down
4 changes: 1 addition & 3 deletions app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ func TestSimAppExportAndBlockedAddrs(t *testing.T) {
InvCheckPeriod: 0,
HomePath: t.TempDir(),
SkipUpgradeHeights: map[int64]bool{},
EncConfig: MakeEncodingConfig(),
AppOpts: simtestutil.EmptyAppOptions{},
}
app := NewAppWithCustomOptions(t, false, opts)
Expand All @@ -57,7 +56,7 @@ func TestSimAppExportAndBlockedAddrs(t *testing.T) {

// Making a new app object with the db, so that initchain hasn't been called
app2 := New(log.NewTestLogger(t), opts.DB, nil, true,
map[int64]bool{}, opts.HomePath, 0, MakeEncodingConfig(), simtestutil.EmptyAppOptions{})
map[int64]bool{}, opts.HomePath, 0, simtestutil.EmptyAppOptions{})
require.NotPanics(t, func() {
_, err = app2.ExportAppStateAndValidators(false, nil, nil)
}, "exporting app state at current height")
Expand All @@ -81,7 +80,6 @@ func TestExportAppStateAndValidators(t *testing.T) {
InvCheckPeriod: 0,
HomePath: t.TempDir(),
SkipUpgradeHeights: map[int64]bool{},
EncConfig: MakeEncodingConfig(),
AppOpts: simtestutil.EmptyAppOptions{},
}
app := NewAppWithCustomOptions(t, false, opts)
Expand Down
17 changes: 0 additions & 17 deletions app/encoding.go

This file was deleted.

8 changes: 7 additions & 1 deletion app/params/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ import (
// MakeTestEncodingConfig creates an EncodingConfig for a non-amino based test configuration.
// This function should be used only internally (in the SDK).
// App user shouldn't create new codecs - use the app.AppCodec instead.
// [DEPRECATED]
//
// TODO[1760]: Update all the simulation stuff that uses this to instead get what's needed from the SimState.
// That will involve passing the SimSate into many places where we used to provide a codec.
// Then delete this file and amino.go, and clean up stuff in the Makefile that uses the test_amino tag.
//
// Deprecated: Either get this from the app (app.GetEncodingConfig()) or use MakeTestEncodingConfig (from the app package),
// or get what's needed from the SimSate.
func MakeTestEncodingConfig() EncodingConfig {
cdc := amino.NewLegacyAmino()
signingOptions := signing.Options{
Expand Down
4 changes: 2 additions & 2 deletions app/sim_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func BenchmarkFullAppSimulation(b *testing.B) {
}
}()

app := New(logger, db, nil, true, map[int64]bool{}, b.TempDir(), simcli.FlagPeriodValue, MakeEncodingConfig(), simtestutil.EmptyAppOptions{}, interBlockCacheOpt())
app := New(logger, db, nil, true, map[int64]bool{}, b.TempDir(), simcli.FlagPeriodValue, simtestutil.EmptyAppOptions{}, interBlockCacheOpt())

// run randomized simulation
_, simParams, simErr := simulation.SimulateFromSeed(
Expand Down Expand Up @@ -86,7 +86,7 @@ func BenchmarkInvariants(b *testing.B) {
}
}()

app := New(logger, db, nil, true, map[int64]bool{}, b.TempDir(), simcli.FlagPeriodValue, MakeEncodingConfig(), simtestutil.EmptyAppOptions{}, interBlockCacheOpt())
app := New(logger, db, nil, true, map[int64]bool{}, b.TempDir(), simcli.FlagPeriodValue, simtestutil.EmptyAppOptions{}, interBlockCacheOpt())

// run randomized simulation
_, lastBlockTime, simParams, simErr := simulation.SimulateFromSeedProv(
Expand Down
Loading

0 comments on commit ee6b992

Please sign in to comment.