Skip to content

Commit

Permalink
fix(stf): fixes to make init genesis pass (#21088)
Browse files Browse the repository at this point in the history
Co-authored-by: marbar3778 <[email protected]>
  • Loading branch information
alpe and tac0turtle authored Jul 27, 2024
1 parent 2e08845 commit b05bb26
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 9 deletions.
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
1 change: 1 addition & 0 deletions schema/module_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,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
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}
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

0 comments on commit b05bb26

Please sign in to comment.