Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add merged registry for gogo and protov2 #14886

Merged
merged 21 commits into from
Feb 20, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions baseapp/a/a_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package a_test

import (
"fmt"
"testing"

"github.com/cosmos/gogoproto/proto"
"github.com/stretchr/testify/require"

_ "github.com/cosmos/cosmos-sdk/x/bank/types"
)

// TestA is a temporary test to test file descriptors mismatch by importing
// them 1 by 1.
func TestA(t *testing.T) {
r, err := proto.MergedRegistry()
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved

fmt.Println(r.NumFiles())
require.NoError(t, err)
}
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ require (
github.com/cosmos/cosmos-sdk/db v1.0.0-beta.1.0.20220726092710-f848e4300a8a
github.com/cosmos/go-bip39 v1.0.0
github.com/cosmos/gogogateway v1.2.0
github.com/cosmos/gogoproto v1.4.4
github.com/cosmos/gogoproto v1.4.5-0.20230213172703-83dec24dea1d
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved
github.com/cosmos/ledger-cosmos-go v0.13.0
github.com/golang/mock v1.6.0
github.com/golang/protobuf v1.5.2
Expand Down Expand Up @@ -156,10 +156,12 @@ require (
// Here are the short-lived replace from the Cosmos SDK
// Replace here are pending PRs, or version to be tagged
replace (
cosmossdk.io/api => ./api
// TODO update after cosmos-sdk/log tagged
cosmossdk.io/log => ./log
// TODO update/remove after v0.37.x tag of CometBFT
github.com/cometbft/cometbft => github.com/cometbft/cometbft v0.0.0-20230203130311-387422ac220d
github.com/cosmos/gogoproto => ../gogoproto
)

// Below are the long-lived replace of the Cosmos SDK
Expand Down
624 changes: 615 additions & 9 deletions go.sum

Large diffs are not rendered by default.

47 changes: 3 additions & 44 deletions runtime/services/reflection.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
package services

import (
"bytes"
"compress/gzip"
"context"
"io"

reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"
"github.com/cosmos/gogoproto/proto"
"golang.org/x/exp/slices"
protov2 "google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protodesc"
"google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/reflect/protoregistry"
"google.golang.org/protobuf/types/descriptorpb"
)

Expand All @@ -23,44 +15,11 @@ type ReflectionService struct {
}

func NewReflectionService() (*ReflectionService, error) {
fds := &descriptorpb.FileDescriptorSet{}

// load gogo proto file descriptors
allFds := proto.AllFileDescriptors()
haveFileDescriptor := map[string]bool{}
for _, compressedBz := range allFds {
rdr, err := gzip.NewReader(bytes.NewReader(compressedBz))
if err != nil {
return nil, err
}

bz, err := io.ReadAll(rdr)
if err != nil {
return nil, err
}

fd := &descriptorpb.FileDescriptorProto{}
err = protov2.Unmarshal(bz, fd)
if err != nil {
return nil, err
}

fds.File = append(fds.File, fd)
haveFileDescriptor[*fd.Name] = true
fds, err := proto.MergedFileDescriptors()
if err != nil {
return nil, err
}

// load any protoregistry file descriptors not in gogo
protoregistry.GlobalFiles.RangeFiles(func(fileDescriptor protoreflect.FileDescriptor) bool {
if !haveFileDescriptor[fileDescriptor.Path()] {
fds.File = append(fds.File, protodesc.ToFileDescriptorProto(fileDescriptor))
}
return true
})

slices.SortFunc(fds.File, func(x, y *descriptorpb.FileDescriptorProto) bool {
return *x.Name < *y.Name
})

return &ReflectionService{files: fds}, nil
}

Expand Down
6 changes: 6 additions & 0 deletions simapp/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/cometbft/cometbft/libs/log"
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
dbm "github.com/cosmos/cosmos-db"
"github.com/cosmos/gogoproto/proto"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -269,3 +270,8 @@ func TestUpgradeStateOnGenesis(t *testing.T) {

require.NotNil(t, app.UpgradeKeeper.GetVersionSetter())
}

func TestMergedRegistry(t *testing.T) {
_, err := proto.MergedRegistry()
require.NoError(t, err)
}
3 changes: 2 additions & 1 deletion simapp/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ require (
github.com/cosmos/cosmos-db v1.0.0-rc.1
// this version is not used as it is always replaced by the latest Cosmos SDK version
github.com/cosmos/cosmos-sdk v0.48.0
github.com/cosmos/gogoproto v1.4.5-0.20230213172703-83dec24dea1d
github.com/golang/mock v1.6.0
github.com/spf13/cast v1.5.0
github.com/spf13/cobra v1.6.1
Expand Down Expand Up @@ -65,7 +66,6 @@ require (
github.com/cosmos/cosmos-proto v1.0.0-beta.1 // indirect
github.com/cosmos/go-bip39 v1.0.0 // indirect
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/gogoproto v1.4.4 // indirect
github.com/cosmos/iavl v0.20.0-alpha3 // indirect
github.com/cosmos/ledger-cosmos-go v0.13.0 // indirect
github.com/cosmos/rosetta-sdk-go v0.10.0 // indirect
Expand Down Expand Up @@ -200,6 +200,7 @@ replace (
cosmossdk.io/x/upgrade => ../x/upgrade
// TODO update/remove after v0.37.x tag of CometBFT
github.com/cometbft/cometbft => github.com/cometbft/cometbft v0.0.0-20230203130311-387422ac220d
github.com/cosmos/gogoproto => ../../gogoproto
)

// Below are the long-lived replace of the SimApp
Expand Down
Loading