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

refactor!: require exported app wiring providers #13292

Merged
merged 53 commits into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
e4b5846
refactor(depinject)!: require exported functions
aaronc Aug 2, 2022
555c6fe
unexport ProviderDescriptor
aaronc Aug 2, 2022
88f0935
WIP on tests
aaronc Aug 2, 2022
1f9f6c7
fix tests and check for bound instance methods
aaronc Aug 3, 2022
4fbf97a
Merge branch 'main' of github.com:cosmos/cosmos-sdk into aaronc/depin…
aaronc Aug 3, 2022
b1f0c98
address merge issues
aaronc Aug 3, 2022
6e5ee43
WIP on checking valid types
aaronc Aug 3, 2022
9925907
WIP on checking valid types
aaronc Aug 3, 2022
5f2b439
WIP
aaronc Aug 10, 2022
30ffdb9
tests passing
aaronc Aug 10, 2022
8db2564
Merge branch 'main' of github.com:cosmos/cosmos-sdk into aaronc/depin…
aaronc Aug 10, 2022
ec9e610
revert changes outside module
aaronc Aug 10, 2022
6546067
docs
aaronc Aug 10, 2022
75b4456
docs
aaronc Aug 10, 2022
0459519
docs
aaronc Aug 10, 2022
0c0e801
Merge branch 'main' into aaronc/depinject-codegen-require-export
julienrbrt Aug 10, 2022
6861c58
add comment
aaronc Aug 11, 2022
5975b98
Merge remote-tracking branch 'origin/aaronc/depinject-codegen-require…
aaronc Aug 11, 2022
2788ed0
Merge branch 'main' into aaronc/depinject-codegen-require-export
aaronc Aug 11, 2022
227c7cf
Merge branch 'main' of github.com:cosmos/cosmos-sdk into aaronc/depin…
aaronc Aug 15, 2022
30c67e9
Merge branch 'aaronc/depinject-codegen-require-export' of github.com:…
aaronc Aug 15, 2022
da5a0a1
revert
aaronc Aug 15, 2022
8950c3f
update depinject go.mod versions
aaronc Aug 17, 2022
c83d045
Merge branch 'main' of github.com:cosmos/cosmos-sdk into aaronc/depin…
aaronc Aug 17, 2022
a5c4048
remove go.work
aaronc Aug 17, 2022
811b316
Merge branch 'main' of github.com:cosmos/cosmos-sdk into aaronc/depin…
aaronc Aug 30, 2022
d037fa0
add go.work back
aaronc Aug 30, 2022
cf3bd20
update modules to require exported providers
aaronc Aug 30, 2022
ea328ed
Merge branch 'main' of github.com:cosmos/cosmos-sdk into aaronc/depin…
aaronc Aug 31, 2022
40796f1
revert
aaronc Aug 31, 2022
1f3e2d5
update go mods
aaronc Aug 31, 2022
056dfb2
Merge branch 'main' of github.com:cosmos/cosmos-sdk into aaronc/depin…
aaronc Sep 14, 2022
575f1c9
revert
aaronc Sep 14, 2022
39000a3
revert
aaronc Sep 14, 2022
93f0076
go mod tidy
aaronc Sep 14, 2022
52ff890
Merge branch 'main' into aaronc/depinject-codegen-require-export4
tac0turtle Sep 15, 2022
de58b3f
Merge branch 'main' into aaronc/depinject-codegen-require-export4
tac0turtle Sep 16, 2022
d792f0a
Merge branch 'main' into aaronc/depinject-codegen-require-export4
aaronc Sep 27, 2022
1287aa9
Merge branch 'main' into aaronc/depinject-codegen-require-export4
facundomedica Sep 28, 2022
40a8ed5
Merge branch 'main' into aaronc/depinject-codegen-require-export4
aaronc Sep 28, 2022
10a89d8
Merge branch 'main' into aaronc/depinject-codegen-require-export4
tac0turtle Oct 2, 2022
c09bc44
go mod tidy all
tac0turtle Oct 3, 2022
d03fad4
Merge branch 'main' into aaronc/depinject-codegen-require-export4
tac0turtle Oct 3, 2022
b5893b4
Merge branch 'main' of github.com:cosmos/cosmos-sdk into aaronc/depin…
aaronc Oct 3, 2022
0769f7c
remove appWrapper
aaronc Oct 3, 2022
4328c9b
fixes
aaronc Oct 3, 2022
047f8d6
Merge branch 'main' into aaronc/depinject-codegen-require-export4
julienrbrt Oct 4, 2022
ddf96d6
Merge branch 'main' into aaronc/depinject-codegen-require-export4
tac0turtle Oct 5, 2022
2d3ce02
Merge branch 'main' of github.com:cosmos/cosmos-sdk into aaronc/depin…
aaronc Oct 10, 2022
20ef294
revert
aaronc Oct 10, 2022
ca16042
go mod tidy
aaronc Oct 10, 2022
c1d6c69
Merge branch 'main' of github.com:cosmos/cosmos-sdk into aaronc/depin…
aaronc Oct 10, 2022
f2da4b1
fix sim failures
aaronc Oct 10, 2022
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 baseapp/block_gas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
dbm "github.com/tendermint/tm-db"

"cosmossdk.io/depinject"

baseapptestutil "github.com/cosmos/cosmos-sdk/baseapp/testutil"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/tx"
Expand Down
59 changes: 28 additions & 31 deletions runtime/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
runtimev1alpha1 "cosmossdk.io/api/cosmos/app/runtime/v1alpha1"
"cosmossdk.io/core/appmodule"
"cosmossdk.io/depinject"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
Expand All @@ -23,29 +24,24 @@ type BaseAppOption func(*baseapp.BaseApp)
// IsManyPerContainerType indicates that this is a depinject.ManyPerContainerType.
func (b BaseAppOption) IsManyPerContainerType() {}

// appWrapper is used to pass around an instance of *App internally between
// runtime dependency inject providers that is partially constructed (no
// baseapp yet).
type appWrapper *App

func init() {
appmodule.Register(&runtimev1alpha1.Module{},
appmodule.Provide(
provideCodecs,
provideAppBuilder,
provideKVStoreKey,
provideTransientStoreKey,
provideMemoryStoreKey,
provideDeliverTx,
ProvideCodecs,
ProvideKVStoreKey,
ProvideTransientStoreKey,
ProvideMemoryStoreKey,
ProvideDeliverTx,
),
appmodule.Invoke(SetupAppBuilder),
)
}

func provideCodecs(moduleBasics map[string]AppModuleBasicWrapper) (
func ProvideCodecs(moduleBasics map[string]AppModuleBasicWrapper) (
codectypes.InterfaceRegistry,
codec.Codec,
*codec.LegacyAmino,
appWrapper,
*AppBuilder,
codec.ProtoCodecMarshaler,
*baseapp.MsgServiceRouter,
) {
Expand All @@ -64,13 +60,15 @@ func provideCodecs(moduleBasics map[string]AppModuleBasicWrapper) (

cdc := codec.NewProtoCodec(interfaceRegistry)
msgServiceRouter := baseapp.NewMsgServiceRouter()
app := &App{
storeKeys: nil,
interfaceRegistry: interfaceRegistry,
cdc: cdc,
amino: amino,
basicManager: basicManager,
msgServiceRouter: msgServiceRouter,
app := &AppBuilder{
&App{
storeKeys: nil,
interfaceRegistry: interfaceRegistry,
cdc: cdc,
amino: amino,
basicManager: basicManager,
msgServiceRouter: msgServiceRouter,
},
}

return interfaceRegistry, cdc, amino, app, cdc, msgServiceRouter
Expand All @@ -80,25 +78,24 @@ type appInputs struct {
depinject.In

Config *runtimev1alpha1.Module
App appWrapper
AppBuilder *AppBuilder
Modules map[string]AppModuleWrapper
BaseAppOptions []BaseAppOption
}

func provideAppBuilder(inputs appInputs) *AppBuilder {
func SetupAppBuilder(inputs appInputs) {
mm := &module.Manager{Modules: map[string]module.AppModule{}}
for name, wrapper := range inputs.Modules {
mm.Modules[name] = wrapper.AppModule
}
app := inputs.App
app := inputs.AppBuilder.app
app.baseAppOptions = inputs.BaseAppOptions
app.config = inputs.Config
app.ModuleManager = mm
return &AppBuilder{app: app}
}

func registerStoreKey(wrapper appWrapper, key storetypes.StoreKey) {
wrapper.storeKeys = append(wrapper.storeKeys, key)
func registerStoreKey(wrapper *AppBuilder, key storetypes.StoreKey) {
wrapper.app.storeKeys = append(wrapper.app.storeKeys, key)
}

func storeKeyOverride(config *runtimev1alpha1.Module, moduleName string) *runtimev1alpha1.StoreKeyConfig {
Expand All @@ -110,7 +107,7 @@ func storeKeyOverride(config *runtimev1alpha1.Module, moduleName string) *runtim
return nil
}

func provideKVStoreKey(config *runtimev1alpha1.Module, key depinject.ModuleKey, app appWrapper) *storetypes.KVStoreKey {
func ProvideKVStoreKey(config *runtimev1alpha1.Module, key depinject.ModuleKey, app *AppBuilder) *storetypes.KVStoreKey {
override := storeKeyOverride(config, key.Name())

var storeKeyName string
Expand All @@ -125,20 +122,20 @@ func provideKVStoreKey(config *runtimev1alpha1.Module, key depinject.ModuleKey,
return storeKey
}

func provideTransientStoreKey(key depinject.ModuleKey, app appWrapper) *storetypes.TransientStoreKey {
func ProvideTransientStoreKey(key depinject.ModuleKey, app *AppBuilder) *storetypes.TransientStoreKey {
storeKey := storetypes.NewTransientStoreKey(fmt.Sprintf("transient:%s", key.Name()))
registerStoreKey(app, storeKey)
return storeKey
}

func provideMemoryStoreKey(key depinject.ModuleKey, app appWrapper) *storetypes.MemoryStoreKey {
func ProvideMemoryStoreKey(key depinject.ModuleKey, app *AppBuilder) *storetypes.MemoryStoreKey {
storeKey := storetypes.NewMemoryStoreKey(fmt.Sprintf("memory:%s", key.Name()))
registerStoreKey(app, storeKey)
return storeKey
}

func provideDeliverTx(app appWrapper) func(abci.RequestDeliverTx) abci.ResponseDeliverTx {
func ProvideDeliverTx(appBuilder *AppBuilder) func(abci.RequestDeliverTx) abci.ResponseDeliverTx {
return func(tx abci.RequestDeliverTx) abci.ResponseDeliverTx {
return app.BaseApp.DeliverTx(tx)
return appBuilder.app.BaseApp.DeliverTx(tx)
}
}
12 changes: 6 additions & 6 deletions x/auth/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,15 @@ func (AppModule) WeightedOperations(_ module.SimulationState) []simtypes.Weighte

func init() {
appmodule.Register(&modulev1.Module{},
appmodule.Provide(provideModuleBasic, provideModule),
appmodule.Provide(ProvideModuleBasic, ProvideModule),
)
}

func provideModuleBasic() runtime.AppModuleBasicWrapper {
func ProvideModuleBasic() runtime.AppModuleBasicWrapper {
return runtime.WrapAppModuleBasic(AppModuleBasic{})
}

type authInputs struct {
type AuthInputs struct {
depinject.In

Config *modulev1.Module
Expand All @@ -203,14 +203,14 @@ type authInputs struct {
LegacySubspace exported.Subspace `optional:"true"`
}

type authOutputs struct {
type AuthOutputs struct {
depinject.Out

AccountKeeper keeper.AccountKeeper
Module runtime.AppModuleWrapper
}

func provideModule(in authInputs) authOutputs {
func ProvideModule(in AuthInputs) AuthOutputs {
maccPerms := map[string][]string{}
for _, permission := range in.Config.ModuleAccountPermissions {
maccPerms[permission.Account] = permission.Permissions
Expand All @@ -219,5 +219,5 @@ func provideModule(in authInputs) authOutputs {
k := keeper.NewAccountKeeper(in.Cdc, in.Key, types.ProtoBaseAccount, maccPerms, in.Config.Bech32Prefix, types.NewModuleAddress(govtypes.ModuleName).String())
m := NewAppModule(in.Cdc, k, simulation.RandomGenesisAccounts, in.LegacySubspace)

return authOutputs{AccountKeeper: k, Module: runtime.WrapAppModule(m)}
return AuthOutputs{AccountKeeper: k, Module: runtime.WrapAppModule(m)}
}
12 changes: 6 additions & 6 deletions x/auth/tx/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import (

func init() {
appmodule.Register(&modulev1.Module{},
appmodule.Provide(provideModule),
appmodule.Provide(ProvideModule),
)
}

type txInputs struct {
type TxInputs struct {
depinject.In

Config *modulev1.Module
Expand All @@ -35,14 +35,14 @@ type txInputs struct {
FeeGrantKeeper feegrantkeeper.Keeper `optional:"true"`
}

type txOutputs struct {
type TxOutputs struct {
depinject.Out

TxConfig client.TxConfig
BaseAppOption runtime.BaseAppOption
}

func provideModule(in txInputs) txOutputs {
func ProvideModule(in TxInputs) TxOutputs {
txConfig := tx.NewTxConfig(in.ProtoCodecMarshaler, tx.DefaultSignModes)

baseAppOption := func(app *baseapp.BaseApp) {
Expand Down Expand Up @@ -83,10 +83,10 @@ func provideModule(in txInputs) txOutputs {
app.SetTxDecoder(txConfig.TxDecoder())
}

return txOutputs{TxConfig: txConfig, BaseAppOption: baseAppOption}
return TxOutputs{TxConfig: txConfig, BaseAppOption: baseAppOption}
}

func newAnteHandler(txConfig client.TxConfig, in txInputs) (sdk.AnteHandler, error) {
func newAnteHandler(txConfig client.TxConfig, in TxInputs) (sdk.AnteHandler, error) {
if in.BankKeeper == nil {
return nil, fmt.Errorf("both AccountKeeper and BankKeeper are required")
}
Expand Down
12 changes: 6 additions & 6 deletions x/auth/vesting/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,29 +116,29 @@ func (AppModule) ConsensusVersion() uint64 { return 1 }

func init() {
appmodule.Register(&modulev1.Module{},
appmodule.Provide(provideModuleBasic, provideModule),
appmodule.Provide(ProvideModuleBasic, ProvideModule),
)
}

func provideModuleBasic() runtime.AppModuleBasicWrapper {
func ProvideModuleBasic() runtime.AppModuleBasicWrapper {
return runtime.WrapAppModuleBasic(AppModuleBasic{})
}

type vestingInputs struct {
type VestingInputs struct {
depinject.In

AccountKeeper keeper.AccountKeeper
BankKeeper types.BankKeeper
}

type vestingOutputs struct {
type VestingOutputs struct {
depinject.Out

Module runtime.AppModuleWrapper
}

func provideModule(in vestingInputs) vestingOutputs {
func ProvideModule(in VestingInputs) VestingOutputs {
m := NewAppModule(in.AccountKeeper, in.BankKeeper)

return vestingOutputs{Module: runtime.WrapAppModule(m)}
return VestingOutputs{Module: runtime.WrapAppModule(m)}
}
14 changes: 7 additions & 7 deletions x/authz/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,17 +159,17 @@ func init() {
appmodule.Register(
&modulev1.Module{},
appmodule.Provide(
provideModuleBasic,
provideModule,
ProvideModuleBasic,
ProvideModule,
),
)
}

func provideModuleBasic() runtime.AppModuleBasicWrapper {
func ProvideModuleBasic() runtime.AppModuleBasicWrapper {
return runtime.WrapAppModuleBasic(AppModuleBasic{})
}

type authzInputs struct {
type AuthzInputs struct {
depinject.In

Key *store.KVStoreKey
Expand All @@ -180,17 +180,17 @@ type authzInputs struct {
MsgServiceRouter *baseapp.MsgServiceRouter
}

type authzOutputs struct {
type AuthzOutputs struct {
depinject.Out

AuthzKeeper keeper.Keeper
Module runtime.AppModuleWrapper
}

func provideModule(in authzInputs) authzOutputs {
func ProvideModule(in AuthzInputs) AuthzOutputs {
k := keeper.NewKeeper(in.Key, in.Cdc, in.MsgServiceRouter, in.AccountKeeper)
m := NewAppModule(in.Cdc, k, in.AccountKeeper, in.BankKeeper, in.Registry)
return authzOutputs{AuthzKeeper: k, Module: runtime.WrapAppModule(m)}
return AuthzOutputs{AuthzKeeper: k, Module: runtime.WrapAppModule(m)}
}

// ____________________________________________________________________________
Expand Down
21 changes: 11 additions & 10 deletions x/bank/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import (
"fmt"
"time"

modulev1 "cosmossdk.io/api/cosmos/bank/module/v1"
"cosmossdk.io/core/appmodule"
"cosmossdk.io/depinject"
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/spf13/cobra"
abci "github.com/tendermint/tendermint/abci/types"
"golang.org/x/exp/maps"

modulev1 "cosmossdk.io/api/cosmos/bank/module/v1"
"cosmossdk.io/core/appmodule"
"cosmossdk.io/depinject"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
Expand Down Expand Up @@ -196,15 +197,15 @@ func (am AppModule) WeightedOperations(simState module.SimulationState) []simtyp
func init() {
appmodule.Register(&modulev1.Module{},
appmodule.Provide(
provideModuleBasic,
provideModule))
ProvideModuleBasic,
ProvideModule))
}

func provideModuleBasic() runtime.AppModuleBasicWrapper {
func ProvideModuleBasic() runtime.AppModuleBasicWrapper {
return runtime.WrapAppModuleBasic(AppModuleBasic{})
}

type bankInputs struct {
type BankInputs struct {
depinject.In

ModuleKey depinject.OwnModuleKey
Expand All @@ -219,14 +220,14 @@ type bankInputs struct {
LegacySubspace exported.Subspace `optional:"true"`
}

type bankOutputs struct {
type BankOutputs struct {
depinject.Out

BankKeeper keeper.BaseKeeper
Module runtime.AppModuleWrapper
}

func provideModule(in bankInputs) bankOutputs {
func ProvideModule(in BankInputs) BankOutputs {
// Configure blocked module accounts.
//
// Default behavior for blockedAddresses is to regard any module mentioned in
Expand Down Expand Up @@ -258,5 +259,5 @@ func provideModule(in bankInputs) bankOutputs {
)
m := NewAppModule(in.Cdc, bankKeeper, in.AccountKeeper, in.LegacySubspace)

return bankOutputs{BankKeeper: bankKeeper, Module: runtime.WrapAppModule(m)}
return BankOutputs{BankKeeper: bankKeeper, Module: runtime.WrapAppModule(m)}
}
Loading