Skip to content

Commit

Permalink
lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kocubinski committed May 10, 2024
1 parent d5d3469 commit 612f0fc
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 24 deletions.
31 changes: 21 additions & 10 deletions runtime/v2/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
"fmt"
"sort"

"github.com/golang/protobuf/proto"
gogoproto "github.com/cosmos/gogoproto/proto"
"golang.org/x/exp/maps"
"google.golang.org/grpc"
protobuf "google.golang.org/protobuf/proto"
proto "google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/reflect/protoregistry"

Expand All @@ -22,7 +22,6 @@ import (
"cosmossdk.io/core/transaction"
"cosmossdk.io/log"
"cosmossdk.io/server/v2/stf"
gogoproto "github.com/cosmos/gogoproto/proto"

"github.com/cosmos/cosmos-sdk/codec"
sdkmodule "github.com/cosmos/cosmos-sdk/types/module"
Expand Down Expand Up @@ -160,7 +159,9 @@ func (m *MM) InitGenesisJSON(ctx context.Context, genesisData map[string]json.Ra
return fmt.Errorf("failed to unmarshal %s genesis state: %w", moduleName, err)
}
for _, jsonTx := range genesisState.GenTxs {
txHandler(jsonTx)
if err := txHandler(jsonTx); err != nil {
return fmt.Errorf("failed to handle genesis transaction: %w", err)
}
}
continue
}
Expand Down Expand Up @@ -572,7 +573,7 @@ func (c *configurator) RegisterService(sd *grpc.ServiceDesc, ss interface{}) {
return
}

if !protobuf.HasExtension(prefSd.(protoreflect.ServiceDescriptor).Options(), cosmosmsg.E_Service) {
if !proto.HasExtension(prefSd.(protoreflect.ServiceDescriptor).Options(), cosmosmsg.E_Service) {
err = c.registerQueryHandlers(sd, ss)
if err != nil {
c.err = err
Expand Down Expand Up @@ -606,7 +607,7 @@ func (c *configurator) registerMsgHandlers(sd *grpc.ServiceDesc, ss interface{})
return nil
}

// RequestFullNameFromMethodDesc returns the fully-qualified name of the request message of the provided service's method.
// requestFullNameFromMethodDesc returns the fully-qualified name of the request message of the provided service's method.
func requestFullNameFromMethodDesc(sd *grpc.ServiceDesc, method grpc.MethodDesc) (protoreflect.FullName, error) {
methodFullName := protoreflect.FullName(fmt.Sprintf("%s.%s", sd.ServiceName, method.MethodName))
desc, err := gogoproto.HybridResolver.FindDescriptorByName(methodFullName)
Expand Down Expand Up @@ -635,13 +636,23 @@ func registerMethod(
ctx context.Context,
msg appmodulev2.Message,
) (resp appmodulev2.Message, err error) {
res, err := md.Handler(ss, ctx, func(dstMsg any) error {
proto.Merge(dstMsg.(proto.Message), msg)
return nil
}, nil)
res, err := md.Handler(ss, ctx, noopDecoder, messagePassingInterceptor(msg))
if err != nil {
return nil, err
}
return res.(appmodulev2.Message), nil
})
}

func noopDecoder(_ interface{}) error { return nil }

func messagePassingInterceptor(msg appmodulev2.Message) grpc.UnaryServerInterceptor {
return func(
ctx context.Context,
req interface{},
_ *grpc.UnaryServerInfo,
handler grpc.UnaryHandler,
) (interface{}, error) {
return handler(ctx, msg)
}
}
2 changes: 1 addition & 1 deletion server/v2/appmanager/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package appmanager
// Config represents the configuration options for the app manager.
// TODO: implement comments for toml
type Config struct {
ValidateTxGasLimit uint64 `mapstructure:"validate-tx-gas-limit"` //TODO: check how this works on app mempool
ValidateTxGasLimit uint64 `mapstructure:"validate-tx-gas-limit"` // TODO: check how this works on app mempool
QueryGasLimit uint64 `mapstructure:"query-gas-limit"`
SimulationGasLimit uint64 `mapstructure:"simulation-gas-limit"`
}
21 changes: 15 additions & 6 deletions server/v2/stf/core_router_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

// NewRouterService creates a router.Service which allows to invoke messages and queries using the msg router.
func NewRouterService(queryRouterBuilder *MsgRouterBuilder, msgRouterBuilder *MsgRouterBuilder) router.Service {
func NewRouterService(queryRouterBuilder, msgRouterBuilder *MsgRouterBuilder) router.Service {
queryRouter, err := queryRouterBuilder.Build()
if err != nil {
panic("cannot create queryRouter")
Expand Down Expand Up @@ -77,9 +77,12 @@ func (m *msgRouterService) CanInvoke(ctx context.Context, typeURL string) error
// InvokeTyped execute a message and fill-in a response.
// The response must be known and passed as a parameter.
// Use InvokeUntyped if the response type is not known.
func (m *msgRouterService) InvokeTyped(ctx context.Context, msg, resp protoiface.MessageV1) error {
func (m *msgRouterService) InvokeTyped(
ctx context.Context,
msg, resp protoiface.MessageV1, // nolint:staticcheck // interface types implicitly store a pointer
) error {
var err error
resp, err = m.handler(ctx, msg)
resp, err = m.handler(ctx, msg) // nolint:ineffassign,staticcheck // interface types implicitly store a pointer
return err
}

Expand Down Expand Up @@ -112,13 +115,19 @@ func (m *queryRouterService) CanInvoke(ctx context.Context, typeURL string) erro
// InvokeTyped execute a message and fill-in a response.
// The response must be known and passed as a parameter.
// Use InvokeUntyped if the response type is not known.
func (m *queryRouterService) InvokeTyped(ctx context.Context, req, resp protoiface.MessageV1) error {
func (m *queryRouterService) InvokeTyped(
ctx context.Context,
req, resp protoiface.MessageV1, // nolint:staticcheck // interface types implicitly store a pointer
) error {
var err error
resp, err = m.handler(ctx, req)
resp, err = m.handler(ctx, req) // nolint:ineffassign,staticcheck // interface types implicitly store a pointer
return err
}

// InvokeUntyped execute a message and returns a response.
func (m *queryRouterService) InvokeUntyped(ctx context.Context, req protoiface.MessageV1) (protoiface.MessageV1, error) {
func (m *queryRouterService) InvokeUntyped(
ctx context.Context,
req protoiface.MessageV1,
) (protoiface.MessageV1, error) {
return m.handler(ctx, req)
}
3 changes: 2 additions & 1 deletion server/v2/stf/stf_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (
"errors"
"fmt"

appmodulev2 "cosmossdk.io/core/appmodule/v2"
gogoproto "github.com/cosmos/gogoproto/proto"
"google.golang.org/protobuf/proto"

appmodulev2 "cosmossdk.io/core/appmodule/v2"
)

var ErrNoHandler = errors.New("no handler")
Expand Down
3 changes: 0 additions & 3 deletions store/v2/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ func NewRawDB(dbType RawDBType, name, dataDir string, opts store.DBOptions) (sto
case DBTypeGoLevelDB:
return NewGoLevelDB(name, dataDir, opts)

//case DBTypeRocksDB:
// return NewRocksDB(name, dataDir)

case DBTypePebbleDB:
return NewPebbleDB(name, dataDir)
}
Expand Down
8 changes: 5 additions & 3 deletions store/v2/root/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ import (
"cosmossdk.io/store/v2/storage/sqlite"
)

type SSType int
type SCType int
type (
SSType int
SCType int
)

const (
SSTypeSQLite SSType = 0
Expand Down Expand Up @@ -49,7 +51,7 @@ func CreateRootStore(opts *FactoryOptions) (store.RootStore, error) {
sc store.Committer
err error
ensureDir = func(dir string) error {
if err := os.MkdirAll(dir, 0755); err != nil {
if err := os.MkdirAll(dir, 0x0755); err != nil {
return fmt.Errorf("failed to create directory %s: %w", dir, err)
}
return nil
Expand Down

0 comments on commit 612f0fc

Please sign in to comment.