Skip to content

Commit

Permalink
chore: bring in core v0.11.x (v0.50 compatible) to v0.50 (#21298)
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt authored Aug 16, 2024
1 parent 624fe4a commit e37404d
Show file tree
Hide file tree
Showing 16 changed files with 151 additions and 3,050 deletions.
21 changes: 21 additions & 0 deletions core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,27 @@ Ref: https://keepachangelog.com/en/1.0.0/

## [Unreleased]

## [v0.11.2](https://github.com/cosmos/cosmos-sdk/releases/tag/core%2Fv0.11.2)

* [#21298](https://github.com/cosmos/cosmos-sdk/pull/21298) Backport [#19265](https://github.com/cosmos/cosmos-sdk/pull/19265) to core.
* [#21298](https://github.com/cosmos/cosmos-sdk/pull/21298) Clean-up after depinject upgrade.

## [v0.11.1](https://github.com/cosmos/cosmos-sdk/releases/tag/core%2Fv0.11.1)

* [#21022](https://github.com/cosmos/cosmos-sdk/pull/21022) Upgrade depinject to v1.0.0.

## [v0.11.0](https://github.com/cosmos/cosmos-sdk/releases/tag/core%2Fv0.11.0)

* [#17468](https://github.com/cosmos/cosmos-sdk/pull/17468) Add `appmodule.HasPreBlocker` interface.

## [v0.10.0](https://github.com/cosmos/cosmos-sdk/releases/tag/core%2Fv0.10.0)

* [#17383](https://github.com/cosmos/cosmos-sdk/pull/17383) Add `appmoduke.UpgradeModule` interface.

## [v0.9.0](https://github.com/cosmos/cosmos-sdk/releases/tag/core%2Fv0.9.0)

* [#16739](https://github.com/cosmos/cosmos-sdk/pull/16739) Add `AppHash` to header.Info.

## [v0.8.0](https://github.com/cosmos/cosmos-sdk/releases/tag/core%2Fv0.8.0)

* [#15519](https://github.com/cosmos/cosmos-sdk/pull/15519) Update `comet.VoteInfo` for CometBFT v0.38.
Expand Down
115 changes: 5 additions & 110 deletions core/appconfig/config.go
Original file line number Diff line number Diff line change
@@ -1,123 +1,18 @@
package appconfig

import (
"fmt"
"strings"

"github.com/cosmos/cosmos-proto/anyutil"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/reflect/protoregistry"
"google.golang.org/protobuf/types/known/anypb"
"sigs.k8s.io/yaml"

appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1"
"cosmossdk.io/core/internal"
"cosmossdk.io/depinject"
depinjectappconfig "cosmossdk.io/depinject/appconfig"
)

// LoadJSON loads an app config in JSON format.
func LoadJSON(bz []byte) depinject.Config {
config := &appv1alpha1.Config{}
err := protojson.Unmarshal(bz, config)
if err != nil {
return depinject.Error(err)
}

return Compose(config)
}
var LoadJSON = depinjectappconfig.LoadJSON

// LoadYAML loads an app config in YAML format.
func LoadYAML(bz []byte) depinject.Config {
j, err := yaml.YAMLToJSON(bz)
if err != nil {
return depinject.Error(err)
}

return LoadJSON(j)
}
var LoadYAML = depinjectappconfig.LoadYAML

// WrapAny marshals a proto message into a proto Any instance
func WrapAny(config protoreflect.ProtoMessage) *anypb.Any {
cfg, err := anyutil.New(config)
if err != nil {
panic(err)
}

return cfg
}
var WrapAny = depinjectappconfig.WrapAny

// Compose composes a v1alpha1 app config into a container option by resolving
// the required modules and composing their options.
func Compose(appConfig *appv1alpha1.Config) depinject.Config {
opts := []depinject.Config{
depinject.Supply(appConfig),
}

for _, module := range appConfig.Modules {
if module.Name == "" {
return depinject.Error(fmt.Errorf("module is missing name"))
}

if module.Config == nil {
return depinject.Error(fmt.Errorf("module %q is missing a config object", module.Name))
}

msgType, err := protoregistry.GlobalTypes.FindMessageByURL(module.Config.TypeUrl)
if err != nil {
return depinject.Error(err)
}

modules, err := internal.ModulesByProtoMessageName()
if err != nil {
return depinject.Error(err)
}

init, ok := modules[msgType.Descriptor().FullName()]
if !ok {
modDesc := proto.GetExtension(msgType.Descriptor().Options(), appv1alpha1.E_Module).(*appv1alpha1.ModuleDescriptor)
if modDesc == nil {
return depinject.Error(fmt.Errorf("no module registered for type URL %s and that protobuf type does not have the option %s\n\n%s",
module.Config.TypeUrl, appv1alpha1.E_Module.TypeDescriptor().FullName(), dumpRegisteredModules(modules)))
}

return depinject.Error(fmt.Errorf("no module registered for type URL %s, did you forget to import %s: find more information on how to make a module ready for app wiring: https://docs.cosmos.network/main/building-modules/depinject\n\n%s",
module.Config.TypeUrl, modDesc.GoImport, dumpRegisteredModules(modules)))
}

config := init.ConfigProtoMessage.ProtoReflect().Type().New().Interface()
err = anypb.UnmarshalTo(module.Config, config, proto.UnmarshalOptions{})
if err != nil {
return depinject.Error(err)
}

opts = append(opts, depinject.Supply(config))

for _, provider := range init.Providers {
opts = append(opts, depinject.ProvideInModule(module.Name, provider))
}

for _, invoker := range init.Invokers {
opts = append(opts, depinject.InvokeInModule(module.Name, invoker))
}

for _, binding := range module.GolangBindings {
opts = append(opts, depinject.BindInterfaceInModule(module.Name, binding.InterfaceType, binding.Implementation))
}
}

for _, binding := range appConfig.GolangBindings {
opts = append(opts, depinject.BindInterface(binding.InterfaceType, binding.Implementation))
}

return depinject.Configs(opts...)
}

func dumpRegisteredModules(modules map[protoreflect.FullName]*internal.ModuleInitializer) string {
var mods []string
for name := range modules {
mods = append(mods, " "+string(name))
}
return fmt.Sprintf("registered modules are:\n%s", strings.Join(mods, "\n"))
}
var Compose = depinjectappconfig.Compose
223 changes: 0 additions & 223 deletions core/appconfig/config_test.go

This file was deleted.

Loading

0 comments on commit e37404d

Please sign in to comment.