From d37dcbff49428994ede265f944029df1ee28fbf8 Mon Sep 17 00:00:00 2001 From: Lockwarr Date: Tue, 15 Aug 2023 11:37:56 +0300 Subject: [PATCH] wip: restructure proto files --- Makefile | 29 +++++++++++ app/app.go | 15 ++++++ app/keepers/keepers.go | 6 +-- buf.gen.yaml | 8 --- go.mod | 50 +++++++++---------- proto/buf.gen.yaml | 8 +++ proto/buf.yaml | 9 +++- .../{tax => nolus/tax/v1beta1}/genesis.proto | 4 +- proto/{tax => nolus/tax/v1beta1}/params.proto | 2 +- proto/{tax => nolus/tax/v1beta1}/query.proto | 4 +- .../vestings/v1beta1}/genesis.proto | 4 +- .../vestings/v1beta1}/params.proto | 2 +- .../vestings/v1beta1}/query.proto | 4 +- .../vestings/v1beta1}/tx.proto | 2 +- {scripts => proto/scripts}/protocgen.sh | 1 + x/mint/client/rest/grpc_query_test.go | 2 +- x/mint/simulation/proposal.go | 39 --------------- 17 files changed, 100 insertions(+), 89 deletions(-) delete mode 100644 buf.gen.yaml create mode 100644 proto/buf.gen.yaml rename proto/{tax => nolus/tax/v1beta1}/genesis.proto (79%) rename proto/{tax => nolus/tax/v1beta1}/params.proto (92%) rename proto/{tax => nolus/tax/v1beta1}/query.proto (91%) rename proto/{vestings => nolus/vestings/v1beta1}/genesis.proto (77%) rename proto/{vestings => nolus/vestings/v1beta1}/params.proto (88%) rename proto/{vestings => nolus/vestings/v1beta1}/query.proto (90%) rename proto/{vestings => nolus/vestings/v1beta1}/tx.proto (97%) rename {scripts => proto/scripts}/protocgen.sh (97%) delete mode 100644 x/mint/simulation/proposal.go diff --git a/Makefile b/Makefile index 9836d2a4..5d3e6c53 100644 --- a/Makefile +++ b/Makefile @@ -201,3 +201,32 @@ proto-format: docker run --rm -v $(CURDIR):/workspace \ --workdir /workspace $(PROTO_FORMATTER_IMAGE) \ find ./ -name *.proto -exec clang-format -i {} \; + +# refactor: regenerate proto files with this image cosmos/proto-buidler + +# protoVer=0.13.0 +# protoImageName=ghcr.io/cosmos/proto-builder:$(protoVer) +# protoImage=docker run --rm -v $(CURDIR):/workspace --workdir /workspace $(protoImageName) + +# proto-all: proto-format proto-lint proto-gen + +# proto-gen: +# @echo "Generating Protobuf files" +# @$(protoImage) sh ./proto/scripts/protocgen.sh + +# proto-swagger-gen: +# @echo "Generating Protobuf Swagger" +# @$(protoImage) sh ./proto/scripts/protoc-swagger-gen.sh + +# proto-format: +# @$(protoImage) find ./ -name "*.proto" -exec clang-format -i {} \; + +# proto-lint: +# @$(protoImage) buf lint --error-format=json + +# proto-check-breaking: +# @$(protoImage) buf breaking --against $(HTTPS_GIT)#branch=main + +# proto-update-deps: +# @echo "Updating Protobuf dependencies" +# docker run --rm -v $(CURDIR)/proto:/workspace --workdir /workspace $(protoImageName) buf mod update diff --git a/app/app.go b/app/app.go index 8e276f77..b4b46dc1 100644 --- a/app/app.go +++ b/app/app.go @@ -9,6 +9,11 @@ import ( "github.com/spf13/cast" + autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" + reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1" + + runtimeservices "github.com/cosmos/cosmos-sdk/runtime/services" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node" @@ -171,6 +176,16 @@ func New( app.configurator = module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter()) app.mm.RegisterServices(app.configurator) + // https://github.com/cosmos/cosmos-sdk/blob/main/UPGRADING.md#app-wiring + // For app.go without dependency injection(valid for nolus), add the following lines to your app.go in order to provide newer gRPC services: + autocliv1.RegisterQueryServer(app.GRPCQueryRouter(), runtimeservices.NewAutoCLIQueryService(app.mm.Modules)) + + reflectionSvc, err := runtimeservices.NewReflectionService() + if err != nil { + panic(err) + } + reflectionv1.RegisterReflectionServiceServer(app.GRPCQueryRouter(), reflectionSvc) + // create the simulation manager and define the order of the modules for deterministic simulations // // NOTE: this is not required apps that don't use the simulator for fuzz testing diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index ecee224d..af9fc35c 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -473,10 +473,8 @@ func (appKeepers *AppKeepers) NewAppKeepers( } govConfig := govtypes.DefaultConfig() - /* - Example of setting gov params: - govConfig.MaxMetadataLen = 10000 - */ + // MaxMetadataLen defines the maximum proposal metadata length. + govConfig.MaxMetadataLen = 20000 appKeepers.GovKeeper = govkeeper.NewKeeper( appCodec, diff --git a/buf.gen.yaml b/buf.gen.yaml deleted file mode 100644 index cd492c25..00000000 --- a/buf.gen.yaml +++ /dev/null @@ -1,8 +0,0 @@ -version: v1 -plugins: - - name: gocosmos - out: . - opt: plugins=interfacetype+grpc,Mgoogle/protobuf/any.proto=github.com/cosmos/cosmos-sdk/codec/types - - name: grpc-gateway - out: . - opt: logtostderr=true,allow_colon_final_segments=true diff --git a/go.mod b/go.mod index 2a8170ba..1d90f011 100644 --- a/go.mod +++ b/go.mod @@ -3,44 +3,43 @@ module github.com/Nolus-Protocol/nolus-core go 1.21 require ( - github.com/CosmWasm/wasmd v0.40.0 - github.com/CosmWasm/wasmvm v1.2.4 + github.com/CosmWasm/wasmd v0.41.0 + github.com/CosmWasm/wasmvm v1.3.0 github.com/armon/go-metrics v0.4.1 github.com/cometbft/cometbft v0.37.2 github.com/cometbft/cometbft-db v0.8.0 - github.com/cosmos/cosmos-sdk v0.47.3 + github.com/cosmos/cosmos-sdk v0.47.4 github.com/cosmos/gogoproto v1.4.10 github.com/cosmos/ibc-go/v7 v7.2.0 - github.com/gogo/protobuf v1.3.3 github.com/golang/protobuf v1.5.3 github.com/gorilla/mux v1.8.0 github.com/grpc-ecosystem/grpc-gateway v1.16.0 - github.com/neutron-org/neutron v1.0.5-0.20230801085019-61cd4725cd30 + github.com/neutron-org/neutron v1.0.5-0.20230811072250-536191206e6f github.com/spf13/cast v1.5.1 github.com/spf13/cobra v1.7.0 github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.8.4 - google.golang.org/genproto v0.0.0-20230530153820-e85fd2cbaebc // indirect - google.golang.org/grpc v1.55.0 + google.golang.org/grpc v1.56.2 gopkg.in/yaml.v2 v2.4.0 ) require ( - cosmossdk.io/errors v1.0.0-beta.7 + cosmossdk.io/errors v1.0.0 cosmossdk.io/math v1.0.1 - google.golang.org/genproto/googleapis/api v0.0.0-20230530153820-e85fd2cbaebc + github.com/gogo/protobuf v1.3.3 + google.golang.org/genproto/googleapis/api v0.0.0-20230629202037-9506855d4529 ) require ( - cloud.google.com/go v0.110.0 // indirect - cloud.google.com/go/compute v1.19.0 // indirect + cloud.google.com/go v0.110.4 // indirect + cloud.google.com/go/compute v1.20.1 // indirect cloud.google.com/go/compute/metadata v0.2.3 // indirect - cloud.google.com/go/iam v0.13.0 // indirect - cloud.google.com/go/storage v1.29.0 // indirect + cloud.google.com/go/iam v1.1.0 // indirect + cloud.google.com/go/storage v1.30.1 // indirect cosmossdk.io/api v0.3.1 // indirect cosmossdk.io/core v0.5.1 // indirect cosmossdk.io/depinject v1.0.0-alpha.3 // indirect - cosmossdk.io/log v1.1.0 // indirect + cosmossdk.io/log v1.1.1-0.20230704160919-88f2c830b0ca // indirect cosmossdk.io/tools/rosetta v0.2.1 // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect @@ -96,10 +95,10 @@ require ( github.com/google/go-cmp v0.5.9 // indirect github.com/google/gofuzz v1.2.0 // indirect github.com/google/orderedcode v0.0.1 // indirect - github.com/google/s2a-go v0.1.3 // indirect + github.com/google/s2a-go v0.1.4 // indirect github.com/google/uuid v1.3.0 // indirect github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect - github.com/googleapis/gax-go/v2 v2.8.0 // indirect + github.com/googleapis/gax-go/v2 v2.11.0 // indirect github.com/gorilla/handlers v1.5.1 // indirect github.com/gorilla/websocket v1.5.0 // indirect github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect @@ -141,7 +140,7 @@ require ( github.com/petermattis/goid v0.0.0-20230518223814-80aa455d8761 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/prometheus/client_golang v1.15.1 // indirect + github.com/prometheus/client_golang v1.16.0 // indirect github.com/prometheus/client_model v0.4.0 // indirect github.com/prometheus/common v0.44.0 // indirect github.com/prometheus/procfs v0.10.1 // indirect @@ -163,18 +162,19 @@ require ( github.com/zondax/ledger-go v0.14.3 // indirect go.etcd.io/bbolt v1.3.7 // indirect go.opencensus.io v0.24.0 // indirect - golang.org/x/crypto v0.10.0 // indirect + golang.org/x/crypto v0.11.0 // indirect golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 // indirect - golang.org/x/net v0.11.0 // indirect + golang.org/x/net v0.12.0 // indirect golang.org/x/oauth2 v0.8.0 // indirect - golang.org/x/sys v0.9.0 // indirect - golang.org/x/term v0.9.0 // indirect - golang.org/x/text v0.10.0 // indirect + golang.org/x/sys v0.10.0 // indirect + golang.org/x/term v0.10.0 // indirect + golang.org/x/text v0.11.0 // indirect golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect - google.golang.org/api v0.122.0 // indirect + google.golang.org/api v0.126.0 // indirect google.golang.org/appengine v1.6.7 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc // indirect - google.golang.org/protobuf v1.30.0 // indirect + google.golang.org/genproto v0.0.0-20230706204954-ccb25ca9f130 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect + google.golang.org/protobuf v1.31.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect nhooyr.io/websocket v1.8.7 // indirect diff --git a/proto/buf.gen.yaml b/proto/buf.gen.yaml new file mode 100644 index 00000000..855ea251 --- /dev/null +++ b/proto/buf.gen.yaml @@ -0,0 +1,8 @@ +version: v1 +plugins: + - name: gocosmos + out: .. + opt: plugins=grpc,Mgoogle/protobuf/any.proto=github.com/cosmos/cosmos-sdk/codec/types + - name: grpc-gateway + out: .. + opt: logtostderr=true,allow_colon_final_segments=true \ No newline at end of file diff --git a/proto/buf.yaml b/proto/buf.yaml index 2adc3de9..7ef2b2b0 100644 --- a/proto/buf.yaml +++ b/proto/buf.yaml @@ -1,7 +1,12 @@ +# cosmos-sdk pinned to v0.47.0 required for cosmos/gogoproto - https://github.com/cosmos/cosmos-sdk/blob/main/proto/README.md version: v1 name: buf.build/nomo/nolus-core deps: - - buf.build/cosmos/cosmos-sdk + - buf.build/cosmos/cosmos-proto + - buf.build/cosmos/gogo-proto + - buf.build/cosmos/cosmos-sdk:v0.47.0 + - buf.build/googleapis/googleapis + - buf.build/cosmos/ibc breaking: use: - FILE @@ -16,4 +21,6 @@ lint: - SERVICE_SUFFIX - PACKAGE_VERSION_SUFFIX - RPC_REQUEST_STANDARD_NAME + ignore: + - tendermint diff --git a/proto/tax/genesis.proto b/proto/nolus/tax/v1beta1/genesis.proto similarity index 79% rename from proto/tax/genesis.proto rename to proto/nolus/tax/v1beta1/genesis.proto index 6180d4a3..26936ecd 100644 --- a/proto/tax/genesis.proto +++ b/proto/nolus/tax/v1beta1/genesis.proto @@ -1,8 +1,8 @@ syntax = "proto3"; -package tax; +package nolus.tax.v1beta1; import "gogoproto/gogo.proto"; -import "tax/params.proto"; +import "nolus/tax/v1beta1/params.proto"; option go_package = "github.com/Nolus-Protocol/nolus-core/x/tax/types"; diff --git a/proto/tax/params.proto b/proto/nolus/tax/v1beta1/params.proto similarity index 92% rename from proto/tax/params.proto rename to proto/nolus/tax/v1beta1/params.proto index 82e2b653..24ef77f4 100644 --- a/proto/tax/params.proto +++ b/proto/nolus/tax/v1beta1/params.proto @@ -1,5 +1,5 @@ syntax = "proto3"; -package tax; +package nolus.tax.v1beta1; import "gogoproto/gogo.proto"; diff --git a/proto/tax/query.proto b/proto/nolus/tax/v1beta1/query.proto similarity index 91% rename from proto/tax/query.proto rename to proto/nolus/tax/v1beta1/query.proto index 68e9bd4c..719978f3 100644 --- a/proto/tax/query.proto +++ b/proto/nolus/tax/v1beta1/query.proto @@ -1,9 +1,9 @@ syntax = "proto3"; -package tax; +package nolus.tax.v1beta1; import "gogoproto/gogo.proto"; import "google/api/annotations.proto"; -import "tax/params.proto"; +import "nolus/tax/v1beta1/params.proto"; option go_package = "github.com/Nolus-Protocol/nolus-core/x/tax/types"; diff --git a/proto/vestings/genesis.proto b/proto/nolus/vestings/v1beta1/genesis.proto similarity index 77% rename from proto/vestings/genesis.proto rename to proto/nolus/vestings/v1beta1/genesis.proto index 3af7eaf6..c20b0a11 100644 --- a/proto/vestings/genesis.proto +++ b/proto/nolus/vestings/v1beta1/genesis.proto @@ -1,8 +1,8 @@ syntax = "proto3"; -package vestings; +package nolus.vestings.v1beta1; import "gogoproto/gogo.proto"; -import "vestings/params.proto"; +import "nolus/vestings/v1beta1/params.proto"; option go_package = "github.com/Nolus-Protocol/nolus-core/x/vestings/types"; diff --git a/proto/vestings/params.proto b/proto/nolus/vestings/v1beta1/params.proto similarity index 88% rename from proto/vestings/params.proto rename to proto/nolus/vestings/v1beta1/params.proto index 9b7e63d1..1c7d0a3e 100644 --- a/proto/vestings/params.proto +++ b/proto/nolus/vestings/v1beta1/params.proto @@ -1,5 +1,5 @@ syntax = "proto3"; -package vestings; +package nolus.vestings.v1beta1; import "gogoproto/gogo.proto"; diff --git a/proto/vestings/query.proto b/proto/nolus/vestings/v1beta1/query.proto similarity index 90% rename from proto/vestings/query.proto rename to proto/nolus/vestings/v1beta1/query.proto index 24b018b0..2658f26e 100644 --- a/proto/vestings/query.proto +++ b/proto/nolus/vestings/v1beta1/query.proto @@ -1,9 +1,9 @@ syntax = "proto3"; -package vestings; +package nolus.vestings.v1beta1; import "gogoproto/gogo.proto"; import "google/api/annotations.proto"; -import "vestings/params.proto"; +import "nolus/vestings/v1beta1/params.proto"; option go_package = "github.com/Nolus-Protocol/nolus-core/x/vestings/types"; diff --git a/proto/vestings/tx.proto b/proto/nolus/vestings/v1beta1/tx.proto similarity index 97% rename from proto/vestings/tx.proto rename to proto/nolus/vestings/v1beta1/tx.proto index c059a93c..398f9b8b 100644 --- a/proto/vestings/tx.proto +++ b/proto/nolus/vestings/v1beta1/tx.proto @@ -1,5 +1,5 @@ syntax = "proto3"; -package vestings; +package nolus.vestings.v1beta1; import "gogoproto/gogo.proto"; import "cosmos/base/v1beta1/coin.proto"; diff --git a/scripts/protocgen.sh b/proto/scripts/protocgen.sh similarity index 97% rename from scripts/protocgen.sh rename to proto/scripts/protocgen.sh index 3e35c240..a3d886b9 100644 --- a/scripts/protocgen.sh +++ b/proto/scripts/protocgen.sh @@ -21,6 +21,7 @@ set -eo pipefail echo "Generating gogo proto code" cd proto +#buf export buf.build/cosmos/cosmos-sdk:v0.47.0 --output . buf mod update cd .. buf generate diff --git a/x/mint/client/rest/grpc_query_test.go b/x/mint/client/rest/grpc_query_test.go index 746eb9aa..9d482bb7 100644 --- a/x/mint/client/rest/grpc_query_test.go +++ b/x/mint/client/rest/grpc_query_test.go @@ -10,7 +10,7 @@ import ( sdkmath "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/gogo/protobuf/proto" + "github.com/cosmos/gogoproto/proto" "github.com/stretchr/testify/suite" minttypes "github.com/Nolus-Protocol/nolus-core/x/mint/types" diff --git a/x/mint/simulation/proposal.go b/x/mint/simulation/proposal.go deleted file mode 100644 index 93ecaebf..00000000 --- a/x/mint/simulation/proposal.go +++ /dev/null @@ -1,39 +0,0 @@ -package simulation - -// DONTCOVER - -// refactor: decide if we want to run such simulations - -// Simulation operation weights constants -// const ( -// DefaultWeightMsgUpdateParams int = 100 - -// OpWeightMsgUpdateParams = "op_weight_msg_update_params" //nolint:gosec -// ) - -// // ProposalMsgs defines the module weighted proposals' contents -// func ProposalMsgs() []simtypes.WeightedProposalMsg { -// return []simtypes.WeightedProposalMsg{ -// simulation.NewWeightedProposalMsg( -// OpWeightMsgUpdateParams, -// DefaultWeightMsgUpdateParams, -// SimulateMsgUpdateParams, -// ), -// } -// } - -// SimulateMsgUpdateParams returns a random MsgUpdateParams -// func SimulateMsgUpdateParams(r *rand.Rand, _ sdk.Context, _ []simtypes.Account) sdk.Msg { -// // use the default gov module account address as authority -// var authority sdk.AccAddress = address.Module("gov") - -// // refactor: align upper and lower ranges when we start running simulationss -// params := types.NewParams( -// types.DefaultParams().MintDenom, -// RandomMaxMintableNanoSeconds(r, 1, 6000000), -// ) - -// return types.NewMsgUpdateParams( -// params, authority.String(), -// ) -// }