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: Validate Msg proto annotations #13793

Merged
merged 65 commits into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
e867834
wip
amaury1093 Nov 8, 2022
88cb125
feat: Validate Msg proto annotations
amaury1093 Nov 8, 2022
4e88fe6
Regenerate
amaury1093 Nov 8, 2022
419418a
Update
amaury1093 Nov 8, 2022
40b3958
Add comments
amaury1093 Nov 8, 2022
fe94644
Merge branch 'main' of ssh://github.com/cosmos/cosmos-sdk into am/134…
amaury1093 Nov 21, 2022
1ac9468
go mod tidy
amaury1093 Nov 21, 2022
db4cafe
wip merge fd sets
amaury1093 Nov 22, 2022
3b5d07d
fix gomods
amaury1093 Nov 28, 2022
168d125
wip
amaury1093 Nov 28, 2022
9981a0b
Fix nil any
amaury1093 Dec 1, 2022
59d9a83
Merge branch 'main' of ssh://github.com/cosmos/cosmos-sdk into am/134…
amaury1093 Dec 1, 2022
0dad494
Revert
amaury1093 Dec 1, 2022
2ae4914
Small cleanup
amaury1093 Dec 1, 2022
3b59f38
Move registration fix to types
amaury1093 Dec 1, 2022
e48ded0
revert some stuff
amaury1093 Dec 1, 2022
f0f2fd8
comments
amaury1093 Dec 1, 2022
0458789
Return err
amaury1093 Dec 1, 2022
6aea9ee
Merge branch 'main' of ssh://github.com/cosmos/cosmos-sdk into am/134…
amaury1093 Dec 5, 2022
708c5e9
Merge branch 'main' of ssh://github.com/cosmos/cosmos-sdk into am/134…
amaury1093 Dec 15, 2022
b2a0414
go mod tidy
amaury1093 Dec 15, 2022
22c6718
Merge branch 'main' of ssh://github.com/cosmos/cosmos-sdk into am/134…
amaury1093 Jan 16, 2023
3fcd4c0
Revert some stuff
amaury1093 Jan 18, 2023
43b0a04
Revert
amaury1093 Jan 18, 2023
61e9b54
revert
amaury1093 Jan 18, 2023
bd9dd66
Make it cleaner
amaury1093 Jan 18, 2023
39eaea5
Add tests
amaury1093 Jan 18, 2023
33f09ed
Add comments
amaury1093 Jan 19, 2023
64be084
Support MultiMsgsend
amaury1093 Jan 19, 2023
7152c27
Add comments
amaury1093 Jan 19, 2023
ab20001
Revert
amaury1093 Jan 19, 2023
dd1d67f
revert
amaury1093 Jan 19, 2023
e6e6a98
revert
amaury1093 Jan 19, 2023
cbeddfb
Don't panic
amaury1093 Jan 19, 2023
f0d7560
Merge branch 'main' of ssh://github.com/cosmos/cosmos-sdk into am/134…
amaury1093 Jan 31, 2023
489b2f3
go-mod-tidy-all
amaury1093 Jan 31, 2023
862cbec
Revert
amaury1093 Jan 31, 2023
a7823a0
Merge branch 'main' of ssh://github.com/cosmos/cosmos-sdk into am/134…
amaury1093 Feb 20, 2023
e5d877b
make proto-gen
amaury1093 Feb 20, 2023
a229a64
Use merged registry
amaury1093 Feb 20, 2023
767c236
Use os.StdErr
amaury1093 Feb 20, 2023
b02329e
Merge branch 'main' into am/13405-valid-annotations
amaury1093 Feb 20, 2023
4f84a83
Merge branch 'main' of ssh://github.com/cosmos/cosmos-sdk into am/134…
amaury1093 Mar 8, 2023
fbd9a35
Merge branch 'am/13405-valid-annotations' of ssh://github.com/cosmos/…
amaury1093 Mar 8, 2023
69a6ed4
Use MergedRegistry
amaury1093 Mar 8, 2023
b8e7bee
Use standalone validation
amaury1093 Mar 8, 2023
0ea3bd2
Merge branch 'main' into am/13405-valid-annotations
amaury1093 Mar 8, 2023
d226a51
Log instead of panic
amaury1093 Mar 8, 2023
719da5a
Merge branch 'am/13405-valid-annotations' of ssh://github.com/cosmos/…
amaury1093 Mar 8, 2023
aa62be7
revert
amaury1093 Mar 8, 2023
7fa3497
Move msg validation to GetSignersContext
amaury1093 Mar 13, 2023
55bf5d4
Merge branch 'main' of ssh://github.com/cosmos/cosmos-sdk into am/134…
amaury1093 Mar 13, 2023
b8435e2
Use commit hash for api
amaury1093 Mar 13, 2023
34fa561
Put in ProvideApp
amaury1093 Mar 13, 2023
b39b168
Fix build
amaury1093 Mar 13, 2023
0e20595
Remove replace
amaury1093 Mar 13, 2023
a302c5d
Fix test
amaury1093 Mar 13, 2023
e1042a1
Merge branch 'main' into am/13405-valid-annotations
amaury1093 Mar 13, 2023
c596277
Update x/tx/signing/get_signers.go
amaury1093 Mar 14, 2023
b6d287c
Merge branch 'main' into am/13405-valid-annotations
amaury1093 Mar 14, 2023
7c8b8b9
Merge branch 'main' of ssh://github.com/cosmos/cosmos-sdk into am/134…
amaury1093 Mar 20, 2023
90bdbe8
Fix build
amaury1093 Mar 20, 2023
2cb4fab
Return err
amaury1093 Mar 20, 2023
449d98c
Fix PR number in CL
amaury1093 Mar 20, 2023
cdfe4a9
Merge branch 'main' into am/13405-valid-annotations
amaury1093 Mar 20, 2023
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
Prev Previous commit
Next Next commit
Put in ProvideApp
  • Loading branch information
amaury1093 committed Mar 13, 2023
commit 34fa561ae93dfbf700fafe738c8e528920649bd0
15 changes: 0 additions & 15 deletions runtime/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package runtime
import (
"encoding/json"
"fmt"
"os"

abci "github.com/cometbft/cometbft/abci/types"
"golang.org/x/exp/slices"
Expand All @@ -24,9 +23,7 @@ import (
servertypes "github.com/cosmos/cosmos-sdk/server/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/types/msgservice"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
"github.com/cosmos/gogoproto/proto"
)

// App is a wrapper around BaseApp and ModuleManager that can be used in hybrid
Expand Down Expand Up @@ -115,18 +112,6 @@ func (a *App) Load(loadLatest bool) error {
}
}

// At startup, check that all proto annotations are correct.
protoFiles, err := proto.MergedRegistry()
if err != nil {
return err
}
err = msgservice.ValidateProtoAnnotations(protoFiles)
if err != nil {
// Once we switch to using protoreflect-based antehandlers, we might
// want to panic here instead of logging a warning.
fmt.Fprintln(os.Stderr, err.Error())
}

return nil
}

Expand Down
23 changes: 22 additions & 1 deletion runtime/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package runtime

import (
"fmt"
"os"

"cosmossdk.io/core/store"
"google.golang.org/protobuf/reflect/protodesc"
"google.golang.org/protobuf/reflect/protoregistry"

abci "github.com/cometbft/cometbft/abci/types"

Expand All @@ -19,6 +22,8 @@ import (
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/std"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/types/msgservice"
"github.com/cosmos/gogoproto/proto"
)

type appModule struct {
Expand Down Expand Up @@ -71,6 +76,8 @@ func ProvideApp() (
codec.ProtoCodecMarshaler,
*baseapp.MsgServiceRouter,
appmodule.AppModule,
protodesc.Resolver,
protoregistry.MessageTypeResolver,
) {
interfaceRegistry := codectypes.NewInterfaceRegistry()
amino := codec.NewLegacyAmino()
Expand All @@ -90,7 +97,21 @@ func ProvideApp() (
}
appBuilder := &AppBuilder{app}

return interfaceRegistry, cdc, amino, appBuilder, cdc, msgServiceRouter, appModule{app}
protoFiles, err := proto.MergedRegistry()
if err != nil {
panic(err)
}
protoTypes := protoregistry.GlobalTypes

// At startup, check that all proto annotations are correct.
err = msgservice.ValidateProtoAnnotations(protoFiles)
if err != nil {
// Once we switch to using protoreflect-based antehandlers, we might
// want to panic here instead of logging a warning.
fmt.Fprintln(os.Stderr, err.Error())
}

return interfaceRegistry, cdc, amino, appBuilder, cdc, msgServiceRouter, appModule{app}, protoFiles, protoTypes
}

type AppInputs struct {
Expand Down
14 changes: 14 additions & 0 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,20 @@ func NewSimApp(
// upgrade.
app.setPostHandler()

// At startup, after all modules have been registered, check that all prot
// annotations are correct.
protoFiles, err := proto.MergedRegistry()
if err != nil {
panic(err)
}
protoTypes := protoregistry.GlobalTypes
err = msgservice.ValidateProtoAnnotations(protoFiles)
if err != nil {
// Once we switch to using protoreflect-based antehandlers, we might
// want to panic here instead of logging a warning.
fmt.Fprintln(os.Stderr, err.Error())
}

if loadLatest {
if err := app.LoadLatestVersion(); err != nil {
panic(fmt.Errorf("error loading last version: %w", err))
Expand Down