forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: upstream more changes from v2 (cosmos#20387)
Co-authored-by: Matt Kocubinski <[email protected]>
- Loading branch information
1 parent
92dafe6
commit d7cc6de
Showing
39 changed files
with
5,432 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
syntax = "proto3"; | ||
|
||
package cosmos.streaming.v1; | ||
|
||
option go_package = "cosmossdk.io/server/v2/streaming"; | ||
|
||
// ListenDeliverBlockRequest is the request type for the ListenDeliverBlock RPC method | ||
message ListenDeliverBlockRequest { | ||
int64 block_height = 1; | ||
repeated bytes txs = 2; | ||
repeated Event events = 3; | ||
repeated ExecTxResult tx_results = 4; | ||
} | ||
|
||
// ListenDeliverBlockResponse is the response type for the ListenDeliverBlock RPC method | ||
message ListenDeliverBlockResponse {} | ||
|
||
// ListenStateChangesRequest is the request type for the ListenStateChanges RPC method | ||
message ListenStateChangesRequest { | ||
int64 block_height = 1; | ||
repeated StoreKVPair change_set = 2; | ||
bytes app_hash = 3; | ||
} | ||
|
||
// ListenStateChangesResponse is the response type for the ListenStateChanges RPC method | ||
message ListenStateChangesResponse {} | ||
|
||
// ListenerService is the service for the Listener interface | ||
service ListenerService { | ||
// ListenDeliverBlock is the corresponding endpoint for Listener.ListenDeliverBlock | ||
rpc ListenDeliverBlock(ListenDeliverBlockRequest) returns (ListenDeliverBlockResponse); | ||
// ListenStateChanges is the corresponding endpoint for Listener.ListenStateChanges | ||
rpc ListenStateChanges(ListenStateChangesRequest) returns (ListenStateChangesResponse); | ||
} | ||
|
||
// StoreKVPair is a single key-value pair, associated with a store. | ||
message StoreKVPair { | ||
// address defines the address of the account the state changes are coming from. | ||
// In case of modules you can expect a stringified | ||
bytes address = 1; | ||
// key defines the key of the address that changed. | ||
bytes key = 2; | ||
// value defines the value that changed, empty in case of removal. | ||
bytes value = 3; | ||
// delete defines if the key was removed. | ||
bool delete = 4; // true indicates a delete operation, false indicates a set operation | ||
} | ||
|
||
// Event is a single event, associated with a transaction. | ||
message Event { | ||
string type = 1; | ||
repeated EventAttribute attributes = 2; | ||
} | ||
|
||
// EventAttribute is a single key-value pair, associated with an event. | ||
message EventAttribute { | ||
string key = 1; | ||
string value = 2; | ||
} | ||
|
||
// ExecTxResult contains results of executing one individual transaction. | ||
message ExecTxResult { | ||
uint32 code = 1; | ||
bytes data = 2; | ||
string log = 3; | ||
string info = 4; | ||
int64 gas_wanted = 5; | ||
int64 gas_used = 6; | ||
repeated Event events = 7; | ||
string codespace = 8; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package grpc | ||
|
||
import "math" | ||
|
||
func DefaultConfig() *Config { | ||
return &Config{ | ||
Enable: true, | ||
// DefaultGRPCAddress defines the default address to bind the gRPC server to. | ||
Address: "localhost:9090", | ||
// DefaultGRPCMaxRecvMsgSize defines the default gRPC max message size in | ||
// bytes the server can receive. | ||
MaxRecvMsgSize: 1024 * 1024 * 10, | ||
// DefaultGRPCMaxSendMsgSize defines the default gRPC max message size in | ||
// bytes the server can send. | ||
MaxSendMsgSize: math.MaxInt32, | ||
} | ||
} | ||
|
||
// GRPCConfig defines configuration for the gRPC server. | ||
type Config struct { | ||
// Enable defines if the gRPC server should be enabled. | ||
Enable bool `mapstructure:"enable" toml:"enable" comment:"Enable defines if the gRPC server should be enabled."` | ||
|
||
// Address defines the API server to listen on | ||
Address string `mapstructure:"address" toml:"address" comment:"Address defines the gRPC server address to bind to."` | ||
|
||
// MaxRecvMsgSize defines the max message size in bytes the server can receive. | ||
// The default value is 10MB. | ||
MaxRecvMsgSize int `mapstructure:"max-recv-msg-size" toml:"max-recv-msg-size" comment:"MaxRecvMsgSize defines the max message size in bytes the server can receive.\nThe default value is 10MB."` | ||
|
||
// MaxSendMsgSize defines the max message size in bytes the server can send. | ||
// The default value is math.MaxInt32. | ||
MaxSendMsgSize int `mapstructure:"max-send-msg-size" toml:"max-send-msg-size" comment:"MaxSendMsgSize defines the max message size in bytes the server can send.\nThe default value is math.MaxInt32."` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Package gogoreflection implements gRPC reflection for gogoproto consumers | ||
// the normal reflection library does not work as it points to a different | ||
// singleton registry. The API and codebase is taken from the official gRPC | ||
// reflection repository. | ||
package gogoreflection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package gogoreflection | ||
|
||
import ( | ||
"reflect" | ||
|
||
_ "github.com/cosmos/gogoproto/gogoproto" // required so it does register the gogoproto file descriptor | ||
gogoproto "github.com/cosmos/gogoproto/proto" | ||
|
||
_ "github.com/cosmos/cosmos-proto" // look above | ||
"github.com/golang/protobuf/proto" //nolint:staticcheck // migrate in a future pr | ||
) | ||
|
||
func getFileDescriptor(filePath string) []byte { | ||
// Since we got well known descriptors which are not registered into gogoproto | ||
// registry but are instead registered into the proto one, we need to check both. | ||
fd := gogoproto.FileDescriptor(filePath) | ||
if len(fd) != 0 { | ||
return fd | ||
} | ||
|
||
return proto.FileDescriptor(filePath) //nolint:staticcheck // keep for backward compatibility | ||
} | ||
|
||
func getMessageType(name string) reflect.Type { | ||
typ := gogoproto.MessageType(name) | ||
if typ != nil { | ||
return typ | ||
} | ||
|
||
return proto.MessageType(name) //nolint:staticcheck // keep for backward compatibility | ||
} | ||
|
||
func getExtension(extID int32, m proto.Message) *gogoproto.ExtensionDesc { | ||
// check first in gogoproto registry | ||
for id, desc := range gogoproto.RegisteredExtensions(m) { | ||
if id == extID { | ||
return desc | ||
} | ||
} | ||
|
||
// check into proto registry | ||
for id, desc := range proto.RegisteredExtensions(m) { //nolint:staticcheck // keep for backward compatibility | ||
if id == extID { | ||
return &gogoproto.ExtensionDesc{ | ||
ExtendedType: desc.ExtendedType, //nolint:staticcheck // keep for backward compatibility | ||
ExtensionType: desc.ExtensionType, //nolint:staticcheck // keep for backward compatibility | ||
Field: desc.Field, //nolint:staticcheck // keep for backward compatibility | ||
Name: desc.Name, //nolint:staticcheck // keep for backward compatibility | ||
Tag: desc.Tag, //nolint:staticcheck // keep for backward compatibility | ||
Filename: desc.Filename, //nolint:staticcheck // keep for backward compatibility | ||
} | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func getExtensionsNumbers(m proto.Message) []int32 { | ||
gogoProtoExts := gogoproto.RegisteredExtensions(m) | ||
|
||
out := make([]int32, 0, len(gogoProtoExts)) | ||
for id := range gogoProtoExts { | ||
out = append(out, id) | ||
} | ||
if len(out) != 0 { | ||
return out | ||
} | ||
|
||
protoExts := proto.RegisteredExtensions(m) //nolint:staticcheck // kept for backwards compatibility | ||
out = make([]int32, 0, len(protoExts)) | ||
for id := range protoExts { | ||
out = append(out, id) | ||
} | ||
|
||
return out | ||
} |
22 changes: 22 additions & 0 deletions
22
server/v2/api/grpc/gogoreflection/fix_registration_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package gogoreflection | ||
|
||
import ( | ||
"testing" | ||
|
||
"google.golang.org/protobuf/runtime/protoimpl" | ||
) | ||
|
||
func TestRegistrationFix(t *testing.T) { | ||
res := getFileDescriptor("gogoproto/gogo.proto") | ||
rawDesc, err := decompress(res) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
fd := protoimpl.DescBuilder{ | ||
RawDescriptor: rawDesc, | ||
}.Build() | ||
|
||
if fd.File.Extensions().Len() == 0 { | ||
t.Fatal("unexpected parsing") | ||
} | ||
} |
Oops, something went wrong.