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

fix(stf): fixes to make init genesis pass #21088

Merged
merged 3 commits into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 4 additions & 2 deletions runtime/v2/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,10 @@ func (a *AppBuilder[T]) Build(opts ...AppBuilderOption[T]) (*App[T], error) {
home := v.GetString(FlagHome)

storeOpts := rootstore.DefaultStoreOptions()
if err := v.Sub("store.options").Unmarshal(&storeOpts); err != nil {
return nil, fmt.Errorf("failed to store options: %w", err)
if s := v.Sub("store.options"); s != nil {
if err := s.Unmarshal(&storeOpts); err != nil {
return nil, fmt.Errorf("failed to store options: %w", err)
}
}

scRawDb, err := db.NewDB(db.DBType(v.GetString("store.app-db-backend")), "application", filepath.Join(home, "data"), nil)
Expand Down
2 changes: 1 addition & 1 deletion runtime/v2/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (m *MM[T]) InitGenesisJSON(
case appmodulev2.HasGenesis:
m.logger.Debug("running initialization for module", "module", moduleName)
if err := module.InitGenesis(ctx, genesisData[moduleName]); err != nil {
return err
return fmt.Errorf("init module %s: %w", moduleName, err)
}
case appmodulev2.HasABCIGenesis:
m.logger.Debug("running initialization for module", "module", moduleName)
Expand Down
2 changes: 1 addition & 1 deletion schema/appdata/async.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type AsyncListenerOptions struct {
BufferSize int

// DoneWaitGroup is an optional wait-group that listener goroutines will notify via Add(1) when they are started
// and Done() after they are cancelled and completed.
// and Done() after they are canceled and completed.
DoneWaitGroup *sync.WaitGroup
}

Expand Down
1 change: 1 addition & 0 deletions schema/appdata/mux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ func callCollector(i int, onCall func(string, int, Packet)) Listener {
}

func checkExpectedCallOrder(t *testing.T, actual, expected []string) {
t.Helper()
if len(actual) != len(expected) {
t.Fatalf("expected %d calls, got %d", len(expected), len(actual))
}
Expand Down
22 changes: 12 additions & 10 deletions schema/module_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,20 @@ func TestModuleSchema_Validate(t *testing.T) {
},
{
name: "same enum",
objectTypes: []ObjectType{{
Name: "object1",
KeyFields: []Field{
{
Name: "k",
Kind: EnumKind,
EnumType: EnumType{
Name: "enum1",
Values: []string{"a", "b"},
objectTypes: []ObjectType{
{
Name: "object1",
KeyFields: []Field{
{
Name: "k",
Kind: EnumKind,
EnumType: EnumType{
Name: "enum1",
Values: []string{"a", "b"},
},
},
},
},
},
{
Name: "object2",
KeyFields: []Field{
Expand Down Expand Up @@ -296,6 +297,7 @@ func TestModuleSchema_LookupType(t *testing.T) {
}

func exampleSchema(t *testing.T) ModuleSchema {
t.Helper()
return requireModuleSchema(t, []ObjectType{
{
Name: "object1",
Expand Down
3 changes: 2 additions & 1 deletion server/v2/cometbft/client/grpc/cmtservice/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"strings"

"cosmossdk.io/server/v2/cometbft/client/rpc"
abci "github.com/cometbft/cometbft/api/cometbft/abci/v1"
coretypes "github.com/cometbft/cometbft/rpc/core/types"
gogogrpc "github.com/cosmos/gogoproto/grpc"
Expand All @@ -13,6 +12,8 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"cosmossdk.io/server/v2/cometbft/client/rpc"

codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
Expand Down
10 changes: 6 additions & 4 deletions server/v2/stf/core_event_service.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package stf

import (
"bytes"
"context"
"encoding/json"
"slices"

"github.com/cosmos/gogoproto/jsonpb"
gogoproto "github.com/cosmos/gogoproto/proto"
"golang.org/x/exp/maps"

Expand Down Expand Up @@ -55,14 +57,14 @@ func (em *eventManager) EmitNonConsensus(event gogoproto.Message) error {
// TypedEventToEvent takes typed event and converts to Event object
func TypedEventToEvent(tev gogoproto.Message) (event.Event, error) {
evtType := gogoproto.MessageName(tev)
evtJSON, err := gogoproto.Marshal(tev)
if err != nil {
buf := new(bytes.Buffer)
jm := &jsonpb.Marshaler{OrigName: true, EmitDefaults: true, AnyResolver: nil}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am using jsonpb now but without the types.UnpackInterfaces to not add codec types.

if err := jm.Marshal(buf, tev); err != nil {
return event.Event{}, err
}

var attrMap map[string]json.RawMessage
err = json.Unmarshal(evtJSON, &attrMap)
if err != nil {
if err := json.Unmarshal(buf.Bytes(), &attrMap); err != nil {
return event.Event{}, err
}

Expand Down
2 changes: 1 addition & 1 deletion server/v2/store/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func createRootStore(cmd *cobra.Command, rootDir string, v *viper.Viper, logger
}

storeOpts := root.DefaultStoreOptions()
if v != nil {
if v != nil && v.Sub("store.options") != nil {
if err := v.Sub("store.options").Unmarshal(&storeOpts); err != nil {
return nil, 0, fmt.Errorf("failed to store options: %w", err)
}
Expand Down
1 change: 1 addition & 0 deletions simapp/v2/app_di.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/std"
_ "github.com/cosmos/cosmos-sdk/x/genutil"
)

// DefaultNodeHome default home directories for the application daemon
Expand Down
Loading