Skip to content

Commit

Permalink
simplify implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt committed Jul 21, 2022
1 parent 7ca8844 commit d623377
Show file tree
Hide file tree
Showing 16 changed files with 83 additions and 148 deletions.
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ require (
github.com/tendermint/btcd v0.1.1
github.com/tendermint/crypto v0.0.0-20191022145703-50d29ede1e15
github.com/tendermint/go-amino v0.16.0
github.com/tendermint/tendermint v0.35.8
github.com/tendermint/tendermint v0.35.9
github.com/tendermint/tm-db v0.6.7
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e
golang.org/x/exp v0.0.0-20220428152302-39d4317da171
Expand Down Expand Up @@ -253,13 +253,13 @@ require (
go.etcd.io/bbolt v1.3.6 // indirect
go.opencensus.io v0.23.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.7.0 // indirect
go.uber.org/zap v1.19.1 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.21.0 // indirect
golang.org/x/exp/typeparams v0.0.0-20220613132600-b0d781184e0d // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/net v0.0.0-20220617184016-355a448f1bc9 // indirect
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5 // indirect
golang.org/x/sync v0.0.0-20220513210516-0976fa681c29 // indirect
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f // indirect
golang.org/x/sys v0.0.0-20220702020025-31831981b65f // indirect
golang.org/x/term v0.0.0-20220526004731-065cf7ba2467 // indirect
golang.org/x/text v0.3.7 // indirect
Expand Down
78 changes: 34 additions & 44 deletions go.sum

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion server/tm_cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ func makeKeyMigrateCmd() *cobra.Command {
return fmt.Errorf("constructing database handle: %w", err)
}

if err = keymigrate.Migrate(ctx, db); err != nil {
// Note storeName argument has been added in TM v0.35.9
// I have set it to "" - please verify if correct
if err = keymigrate.Migrate(ctx, "", db); err != nil {
return fmt.Errorf("running migration for context %q: %w",
dbctx, err)
}
Expand Down
5 changes: 4 additions & 1 deletion simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,10 @@ func NewSimApp(
// add here your custom function that implements the minttypes.InflationCalculationFn interface.

// for providing a custom authority to a module simply add it below. By default the governance module is the default authority.
// e.g minttypes.MintAuthority(authtypes.NewModuleAddress(govtypes.ModuleName))
// map[string]sdk.AccAddress{
// minttypes.ModuleName: authtypes.NewModuleAddress(authtypes.ModuleName),
// // ...
// },
),
)
)
Expand Down
15 changes: 8 additions & 7 deletions x/bank/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,13 @@ func provideModuleBasic() runtime.AppModuleBasicWrapper {
type bankInputs struct {
depinject.In

Config *modulev1.Module
Cdc codec.Codec
Key *store.KVStoreKey
ModuleKey depinject.OwnModuleKey
Config *modulev1.Module
Cdc codec.Codec
Key *store.KVStoreKey

AccountKeeper types.AccountKeeper
Authority types.BankAuthority `optional:"true"`
Authority map[string]sdk.AccAddress `optional:"true"`

// LegacySubspace is used solely for migration of x/params managed parameters
LegacySubspace exported.Subspace
Expand Down Expand Up @@ -263,10 +264,10 @@ func provideModule(in bankInputs) bankOutputs {
}
}

authority := in.Authority
if authority == nil || len(authority) == 0 {
authority, ok := in.Authority[depinject.ModuleKey(in.ModuleKey).Name()]
if !ok {
// default to governance authority if not provided
authority = types.BankAuthority(authtypes.NewModuleAddress(govtypes.ModuleName))
authority = authtypes.NewModuleAddress(govtypes.ModuleName)
}

bankKeeper := keeper.NewBaseKeeper(
Expand Down
11 changes: 0 additions & 11 deletions x/bank/types/authority.go

This file was deleted.

11 changes: 6 additions & 5 deletions x/crisis/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,12 @@ func init() {
type crisisInputs struct {
depinject.In

ModuleKey depinject.OwnModuleKey
Config *modulev1.Module
Key *store.KVStoreKey
Cdc codec.Codec
AppOpts servertypes.AppOptions `optional:"true"`
Authority types.CrisisAuthority `optional:"true"`
AppOpts servertypes.AppOptions `optional:"true"`
Authority map[string]sdk.AccAddress `optional:"true"`

BankKeeper types.SupplyKeeper

Expand All @@ -228,10 +229,10 @@ func provideModule(in crisisInputs) crisisOutputs {
feeCollectorName = authtypes.FeeCollectorName
}

authority := in.Authority
if authority == nil || len(authority) == 0 {
authority, ok := in.Authority[depinject.ModuleKey(in.ModuleKey).Name()]
if !ok {
// default to governance authority if not provided
authority = types.CrisisAuthority(authtypes.NewModuleAddress(govtypes.ModuleName))
authority = authtypes.NewModuleAddress(govtypes.ModuleName)
}

k := keeper.NewKeeper(
Expand Down
11 changes: 0 additions & 11 deletions x/crisis/types/authority.go

This file was deleted.

9 changes: 5 additions & 4 deletions x/distribution/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,11 @@ func provideModuleBasic() runtime.AppModuleBasicWrapper {
type distrInputs struct {
depinject.In

ModuleKey depinject.OwnModuleKey
Config *modulev1.Module
Key *store.KVStoreKey
Cdc codec.Codec
Authority types.DistrAuthority `optional:"true"`
Authority map[string]sdk.AccAddress `optional:"true"`

AccountKeeper types.AccountKeeper
BankKeeper types.BankKeeper
Expand All @@ -265,10 +266,10 @@ func provideModule(in distrInputs) distrOutputs {
feeCollectorName = authtypes.FeeCollectorName
}

authority := in.Authority
if authority == nil || len(authority) == 0 {
authority, ok := in.Authority[depinject.ModuleKey(in.ModuleKey).Name()]
if !ok {
// default to governance authority if not provided
authority = types.DistrAuthority(authtypes.NewModuleAddress(govtypes.ModuleName))
authority = authtypes.NewModuleAddress(govtypes.ModuleName)
}

k := keeper.NewKeeper(
Expand Down
11 changes: 0 additions & 11 deletions x/distribution/types/authority.go

This file was deleted.

9 changes: 5 additions & 4 deletions x/mint/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,11 @@ func provideModuleBasic() runtime.AppModuleBasicWrapper {
type mintInputs struct {
depinject.In

ModuleKey depinject.OwnModuleKey
Config *modulev1.Module
Key *store.KVStoreKey
Cdc codec.Codec
Authority types.MintAuthority `optional:"true"`
Authority map[string]sdk.AccAddress `optional:"true"`
InflationCalculationFn types.InflationCalculationFn `optional:"true"`

// LegacySubspace is used solely for migration of x/params managed parameters
Expand All @@ -263,10 +264,10 @@ func provideModule(in mintInputs) mintOutputs {
feeCollectorName = authtypes.FeeCollectorName
}

authority := in.Authority
if authority == nil || len(authority) == 0 {
authority, ok := in.Authority[depinject.ModuleKey(in.ModuleKey).Name()]
if !ok {
// default to governance authority if not provided
authority = types.MintAuthority(authtypes.NewModuleAddress(govtypes.ModuleName))
authority = authtypes.NewModuleAddress(govtypes.ModuleName)
}

k := keeper.NewKeeper(
Expand Down
11 changes: 0 additions & 11 deletions x/mint/types/authority.go

This file was deleted.

9 changes: 5 additions & 4 deletions x/slashing/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,11 @@ func provideModuleBasic() runtime.AppModuleBasicWrapper {
type slashingInputs struct {
depinject.In

ModuleKey depinject.OwnModuleKey
Key *store.KVStoreKey
Cdc codec.Codec
LegacyAmino *codec.LegacyAmino
Authority types.SlashingAuthority `optional:"true"`
Authority map[string]sdk.AccAddress `optional:"true"`

AccountKeeper types.AccountKeeper
BankKeeper types.BankKeeper
Expand All @@ -257,10 +258,10 @@ type slashingOutputs struct {
}

func provideModule(in slashingInputs) slashingOutputs {
authority := in.Authority
if authority == nil || len(authority) == 0 {
authority, ok := in.Authority[depinject.ModuleKey(in.ModuleKey).Name()]
if !ok {
// default to governance authority if not provided
authority = types.SlashingAuthority(authtypes.NewModuleAddress(govtypes.ModuleName))
authority = authtypes.NewModuleAddress(govtypes.ModuleName)
}

k := keeper.NewKeeper(in.Cdc, in.LegacyAmino, in.Key, in.StakingKeeper, authority.String())
Expand Down
11 changes: 0 additions & 11 deletions x/slashing/types/authority.go

This file was deleted.

17 changes: 9 additions & 8 deletions x/upgrade/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,13 @@ func provideModuleBasic() runtime.AppModuleBasicWrapper {
type upgradeInputs struct {
depinject.In

Config *modulev1.Module
Key *store.KVStoreKey
Cdc codec.Codec
ModuleKey depinject.OwnModuleKey
Config *modulev1.Module
Key *store.KVStoreKey
Cdc codec.Codec

AppOpts servertypes.AppOptions `optional:"true"`
Authority types.UpgradeAuthority `optional:"true"`
AppOpts servertypes.AppOptions `optional:"true"`
Authority map[string]sdk.AccAddress `optional:"true"`
}

type upgradeOutputs struct {
Expand All @@ -198,10 +199,10 @@ func provideModule(in upgradeInputs) upgradeOutputs {
homePath = cast.ToString(in.AppOpts.Get(flags.FlagHome))
}

authority := in.Authority
if authority == nil || len(authority) == 0 {
authority, ok := in.Authority[depinject.ModuleKey(in.ModuleKey).Name()]
if !ok {
// default to governance authority if not provided
authority = types.UpgradeAuthority(authtypes.NewModuleAddress(govtypes.ModuleName))
authority = authtypes.NewModuleAddress(govtypes.ModuleName)
}

// set the governance module account as the authority for conducting upgrades
Expand Down
11 changes: 0 additions & 11 deletions x/upgrade/types/authority.go

This file was deleted.

0 comments on commit d623377

Please sign in to comment.