Skip to content

Commit

Permalink
Fixing GRPC
Browse files Browse the repository at this point in the history
  • Loading branch information
cbrit committed Apr 8, 2024
1 parent 478cef6 commit b678ba5
Show file tree
Hide file tree
Showing 146 changed files with 12,319 additions and 165 deletions.
1 change: 1 addition & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,7 @@ golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E=
golang.org/x/tools v0.10.0 h1:tvDr/iQoUqNdohiYm0LmmKcBk+q86lb9EprIUFhHHGg=
golang.org/x/tools v0.10.0/go.mod h1:UJwyiVBsOA2uwvK/e5OY3GTpDUJriEd+/YlqAwLPmyM=
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
gonum.org/v1/gonum v0.11.0 h1:f1IJhK4Km5tBJmaiJXtk/PkL4cdVX6J+tGiM187uT5E=
Expand Down
3 changes: 2 additions & 1 deletion integration_tests/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ func (s *IntegrationTestSuite) initGenesis() {
s.Require().NoError(cdc.UnmarshalJSON(appGenState[gravitytypes.ModuleName], &gravityGenState))
gravityGenState.Params.GravityId = "gravitytest"
gravityGenState.Params.BridgeEthereumAddress = gravityContract.String()
gravityGenState.Params.ConfirmedOutgoingTxWindow = 100
gravityGenState.Params.ConfirmedOutgoingTxWindow = 1000000
gravityGenState.Params.TargetEthTxTimeout = 3600000
gravityGenState.Params.AverageBlockTime = 1000
gravityGenState.Params.AverageEthereumBlockTime = 1000
Expand Down Expand Up @@ -385,6 +385,7 @@ func (s *IntegrationTestSuite) initValidatorConfigs() {
valConfig.P2P.AddrBookStrict = false
valConfig.P2P.ExternalAddress = fmt.Sprintf("%s:%d", val.instanceName(), 26656)
valConfig.RPC.ListenAddress = "tcp://0.0.0.0:26657"
valConfig.RPC.GRPCListenAddress = "tcp://0.0.0.0:9090"
valConfig.StateSync.Enable = false
valConfig.LogLevel = "info"

Expand Down
27 changes: 20 additions & 7 deletions module/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ import (
"github.com/cosmos/cosmos-sdk/x/capability"
capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
"github.com/cosmos/cosmos-sdk/x/consensus"
consensusparamkeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper"
consensusparamtypes "github.com/cosmos/cosmos-sdk/x/consensus/types"
"github.com/cosmos/cosmos-sdk/x/crisis"
crisiskeeper "github.com/cosmos/cosmos-sdk/x/crisis/keeper"
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
Expand Down Expand Up @@ -122,6 +124,7 @@ var (
genutil.AppModuleBasic{},
bank.AppModuleBasic{},
capability.AppModuleBasic{},
consensus.AppModuleBasic{},
staking.AppModuleBasic{},
mint.AppModuleBasic{},
distr.AppModuleBasic{},
Expand Down Expand Up @@ -202,7 +205,7 @@ type Gravity struct {
mintKeeper mintkeeper.Keeper
distrKeeper distrkeeper.Keeper
govKeeper govkeeper.Keeper
consensusParamsKeeper *consensusparamkeeper.Keeper
consensusParamsKeeper consensusparamkeeper.Keeper
crisisKeeper crisiskeeper.Keeper
upgradeKeeper upgradekeeper.Keeper
paramsKeeper paramskeeper.Keeper
Expand Down Expand Up @@ -260,8 +263,8 @@ func NewGravityApp(
authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey,
minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey,
govtypes.StoreKey, paramstypes.StoreKey, icaexported.StoreKey, upgradetypes.StoreKey,
evidencetypes.StoreKey, ibctransfertypes.StoreKey, capabilitytypes.StoreKey,
gravitytypes.StoreKey,
evidencetypes.StoreKey, ibctransfertypes.StoreKey, consensusparamtypes.StoreKey, capabilitytypes.StoreKey,
gravitytypes.StoreKey, crisistypes.StoreKey,
)
tKeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand All @@ -278,7 +281,12 @@ func NewGravityApp(
}

app.paramsKeeper = initParamsKeeper(appCodec, legacyAmino, keys[paramstypes.StoreKey], tKeys[paramstypes.TStoreKey])
bApp.SetParamStore(app.consensusParamsKeeper)

authority := authtypes.NewModuleAddress(govtypes.ModuleName).String()

// set the BaseApp's parameter store
app.consensusParamsKeeper = consensusparamkeeper.NewKeeper(appCodec, keys[consensusparamtypes.StoreKey], authority)
bApp.SetParamStore(&app.consensusParamsKeeper)

app.capabilityKeeper = capabilitykeeper.NewKeeper(
appCodec,
Expand All @@ -293,8 +301,6 @@ func NewGravityApp(
// `ScopeToModule`.
app.capabilityKeeper.Seal()

authority := authtypes.NewModuleAddress(govtypes.ModuleName).String()

app.accountKeeper = authkeeper.NewAccountKeeper(
appCodec,
app.keys[authtypes.StoreKey],
Expand Down Expand Up @@ -532,6 +538,7 @@ func NewGravityApp(
genutiltypes.ModuleName,
paramstypes.ModuleName,
vestingtypes.ModuleName,
consensusparamtypes.ModuleName,
gravitytypes.ModuleName,
)
app.mm.SetOrderEndBlockers(
Expand All @@ -551,6 +558,7 @@ func NewGravityApp(
paramstypes.ModuleName,
upgradetypes.ModuleName,
vestingtypes.ModuleName,
consensusparamtypes.ModuleName,
gravitytypes.ModuleName,
)
app.mm.SetOrderInitGenesis(
Expand All @@ -574,7 +582,6 @@ func NewGravityApp(
)

app.mm.RegisterInvariants(&app.crisisKeeper)
// app.mm.RegisterRoutes(app.Router(), app.QueryRouter(), encodingConfig.Amino)
app.configurator = module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter())
app.mm.RegisterServices(app.configurator)

Expand Down Expand Up @@ -804,6 +811,12 @@ func (app *Gravity) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APICo
authtx.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
ModuleBasics.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)

// Register node gRPC service for grpc-gateway.
nodeservice.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)

// Register new tendermint queries routes from grpc-gateway.
tmservice.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)

// TODO: build the custom gravity swagger files and add here?
if apiConfig.Swagger {
RegisterSwaggerAPI(clientCtx, apiSvr.Router)
Expand Down
16 changes: 15 additions & 1 deletion module/cmd/gravity/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
tmcfg "github.com/cometbft/cometbft/config"
tmcli "github.com/cometbft/cometbft/libs/cli"
"github.com/cometbft/cometbft/libs/log"
tmtypes "github.com/cometbft/cometbft/types"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/debug"
Expand Down Expand Up @@ -188,6 +189,18 @@ func (a appCreator) newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, a
panic(err)
}

homeDir := cast.ToString(appOpts.Get(flags.FlagHome))
chainID := cast.ToString(appOpts.Get(flags.FlagChainID))
if chainID == "" {
// fallback to genesis chain-id
appGenesis, err := tmtypes.GenesisDocFromFile(filepath.Join(homeDir, "config", "genesis.json"))
if err != nil {
panic(err)
}

chainID = appGenesis.ChainID
}

snapshotDir := filepath.Join(cast.ToString(appOpts.Get(flags.FlagHome)), "data", "snapshots")
snapshotDB, err := dbm.NewDB("metadata", server.GetAppDBBackend(appOpts), snapshotDir)
if err != nil {
Expand All @@ -204,7 +217,7 @@ func (a appCreator) newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, a
}
return app.NewGravityApp(
logger, db, traceStore, true, skipUpgradeHeights,
cast.ToString(appOpts.Get(flags.FlagHome)),
homeDir,
cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)),
a.encCfg,
appOpts,
Expand All @@ -217,6 +230,7 @@ func (a appCreator) newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, a
baseapp.SetTrace(cast.ToBool(appOpts.Get(server.FlagTrace))),
baseapp.SetIndexEvents(cast.ToStringSlice(appOpts.Get(server.FlagIndexEvents))),
baseapp.SetSnapshot(snapshotStore, snapshotOpts),
baseapp.SetChainID(chainID),
)
}

Expand Down
2 changes: 1 addition & 1 deletion module/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ require (
github.com/cosmos/gogoproto v1.4.11
github.com/cosmos/ibc-go/v7 v7.3.2
github.com/ethereum/go-ethereum v1.10.22
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/pkg/errors v0.9.1
Expand Down Expand Up @@ -93,7 +94,6 @@ require (
github.com/golang/glog v1.1.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/go-cmp v0.6.0 // indirect
Expand Down
25 changes: 18 additions & 7 deletions module/proto/gravity/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,28 @@ option (gogoproto.messagename_all) = true;
service Query {

// Module parameters query
rpc Params(ParamsRequest) returns (ParamsResponse) {}
rpc Params(ParamsRequest) returns (ParamsResponse) {
option (google.api.http).get = "/gravity/v1/params";
}

// get info on individual outgoing data
rpc SignerSetTx(SignerSetTxRequest) returns (SignerSetTxResponse) {}
rpc LatestSignerSetTx(LatestSignerSetTxRequest)
returns (SignerSetTxResponse) {}
rpc BatchTx(BatchTxRequest) returns (BatchTxResponse) {}
rpc ContractCallTx(ContractCallTxRequest) returns (ContractCallTxResponse) {}
rpc SignerSetTx(SignerSetTxRequest) returns (SignerSetTxResponse) {
option (google.api.http).get = "/gravity/v1/signer_set_txs/{signer_set_nonce}";
}
rpc LatestSignerSetTx(LatestSignerSetTxRequest) returns (SignerSetTxResponse) {
option (google.api.http).get = "/gravity/v1/signer_set_txs/latest";
}
rpc BatchTx(BatchTxRequest) returns (BatchTxResponse) {
option (google.api.http).get = "/gravity/v1/batch_txs/{token_contract}/{batch_nonce}";
}
rpc ContractCallTx(ContractCallTxRequest) returns (ContractCallTxResponse) {
option (google.api.http).get = "/gravity/v1/contract_call_txs/{invalidation_scope}/{invalidation_nonce}";
}

// get collections of outgoing traffic from the bridge
rpc SignerSetTxs(SignerSetTxsRequest) returns (SignerSetTxsResponse) {}
rpc SignerSetTxs(SignerSetTxsRequest) returns (SignerSetTxsResponse) {
option (google.api.http).get = "/gravity/v1/signer_set_txs";
}
rpc BatchTxs(BatchTxsRequest) returns (BatchTxsResponse) {}
rpc ContractCallTxs(ContractCallTxsRequest)
returns (ContractCallTxsResponse) {}
Expand Down
79 changes: 79 additions & 0 deletions module/third_party/proto/amino/amino.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
syntax = "proto3";

package amino;

import "google/protobuf/descriptor.proto";

// TODO(fdymylja): once we fully migrate to protov2 the go_package needs to be updated.
// We need this right now because gogoproto codegen needs to import the extension.
option go_package = "github.com/cosmos/cosmos-sdk/types/tx/amino";

extend google.protobuf.MessageOptions {
// name is the string used when registering a concrete
// type into the Amino type registry, via the Amino codec's
// `RegisterConcrete()` method. This string MUST be at most 39
// characters long, or else the message will be rejected by the
// Ledger hardware device.
string name = 11110001;

// encoding describes the encoding format used by Amino for the given
// message. The field type is chosen to be a string for
// flexibility, but it should ideally be short and expected to be
// machine-readable, for example "base64" or "utf8_json". We
// highly recommend to use underscores for word separation instead of spaces.
//
// If left empty, then the Amino encoding is expected to be the same as the
// Protobuf one.
//
// This annotation should not be confused with the `encoding`
// one which operates on the field level.
string message_encoding = 11110002;
}

extend google.protobuf.FieldOptions {
// encoding describes the encoding format used by Amino for
// the given field. The field type is chosen to be a string for
// flexibility, but it should ideally be short and expected to be
// machine-readable, for example "base64" or "utf8_json". We
// highly recommend to use underscores for word separation instead of spaces.
//
// If left empty, then the Amino encoding is expected to be the same as the
// Protobuf one.
//
// This annotation should not be confused with the
// `message_encoding` one which operates on the message level.
string encoding = 11110003;

// field_name sets a different field name (i.e. key name) in
// the amino JSON object for the given field.
//
// Example:
//
// message Foo {
// string bar = 1 [(amino.field_name) = "baz"];
// }
//
// Then the Amino encoding of Foo will be:
// `{"baz":"some value"}`
string field_name = 11110004;

// dont_omitempty sets the field in the JSON object even if
// its value is empty, i.e. equal to the Golang zero value. To learn what
// the zero values are, see https://go.dev/ref/spec#The_zero_value.
//
// Fields default to `omitempty`, which is the default behavior when this
// annotation is unset. When set to true, then the field value in the
// JSON object will be set, i.e. not `undefined`.
//
// Example:
//
// message Foo {
// string bar = 1;
// string baz = 2 [(amino.dont_omitempty) = true];
// }
//
// f := Foo{};
// out := AminoJSONEncoder(&f);
// out == {"baz":""}
bool dont_omitempty = 11110005;
}
50 changes: 50 additions & 0 deletions module/third_party/proto/cosmos/app/runtime/v1alpha1/module.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
syntax = "proto3";

package cosmos.app.runtime.v1alpha1;

import "cosmos/app/v1alpha1/module.proto";

// Module is the config object for the runtime module.
message Module {
option (cosmos.app.v1alpha1.module) = {
go_import: "github.com/cosmos/cosmos-sdk/runtime"
use_package: {name: "cosmos.app.v1alpha1"}
};

// app_name is the name of the app.
string app_name = 1;

// begin_blockers specifies the module names of begin blockers
// to call in the order in which they should be called. If this is left empty
// no begin blocker will be registered.
repeated string begin_blockers = 2;

// end_blockers specifies the module names of the end blockers
// to call in the order in which they should be called. If this is left empty
// no end blocker will be registered.
repeated string end_blockers = 3;

// init_genesis specifies the module names of init genesis functions
// to call in the order in which they should be called. If this is left empty
// no init genesis function will be registered.
repeated string init_genesis = 4;

// export_genesis specifies the order in which to export module genesis data.
// If this is left empty, the init_genesis order will be used for export genesis
// if it is specified.
repeated string export_genesis = 5;

// override_store_keys is an optional list of overrides for the module store keys
// to be used in keeper construction.
repeated StoreKeyConfig override_store_keys = 6;
}

// StoreKeyConfig may be supplied to override the default module store key, which
// is the module name.
message StoreKeyConfig {
// name of the module to override the store key of
string module_name = 1;

// the kv store key to use instead of the module name.
string kv_store_key = 2;
}
Loading

0 comments on commit b678ba5

Please sign in to comment.