Skip to content

Commit 737dcfd

Browse files
authored
refactor!: rm GetSignBytes (#16062)
1 parent d1a337e commit 737dcfd

95 files changed

Lines changed: 968 additions & 1827 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ Ref: https://keepachangelog.com/en/1.0.0/
245245
* Removed: keeper `GetConstantFee`, `SetConstantFee`
246246
* (x/mint) [#16329](https://github.com/cosmos/cosmos-sdk/pull/16329) Use collections for state management:
247247
* Removed: keeper `GetParams`, `SetParams`, `GetMinter`, `SetMinter`.
248+
* (x/*all*) [#16052](https://github.com/cosmos/cosmos-sdk/pull/16062) `GetSignBytes` implementations on messages and global legacy amino codec definitions have been removed from all modules.
249+
* (sims) [#16052](https://github.com/cosmos/cosmos-sdk/pull/16062) `GetOrGenerate` no longer requires a codec argument is now 4-arity instead of 5-arity.
248250

249251
### Client Breaking Changes
250252

UPGRADING.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ ClevelDB, BoltDB and BadgerDB are not supported anymore. To migrate from a unsup
5353

5454
### Protobuf
5555

56-
The SDK is in the process of removing all `gogoproto` annotations.
56+
With the deprecation of the amino JSON codec defined in [cosmos/gogoproto](https://github.com/cosmos/gogoproto) in favor of the protoreflect powered x/tx/aminojson codec, module developers are encouraged verify that their messages have the correct protobuf annotations to deterministically produce identical output from both codecs.
57+
58+
For core SDK types equivalence is asserted by generative testing of [SignableTypes](https://github.com/cosmos/cosmos-sdk/blob/76f0d101530ed78befc95506ab473c771d0d8a8c/tests/integration/rapidgen/rapidgen.go#L106) in [TestAminoJSON_Equivalence](https://github.com/cosmos/cosmos-sdk/blob/76f0d101530ed78befc95506ab473c771d0d8a8c/tests/integration/aminojson/aminojson_test.go#L90).
59+
60+
TODO: summarize proto annotation requirements.
5761

5862
#### Stringer
5963

@@ -181,6 +185,8 @@ The return type of the interface method `TxConfig.SignModeHandler()` has been ch
181185
The `sdk.Msg` interface has been updated to not require the implementation of the `ValidateBasic` method.
182186
It is now recommended to validate message directly in the message server. When the validation is performed in the message server, the `ValidateBasic` method on a message is no longer required and can be removed.
183187

188+
Messages no longer need to implement the `LegacyMsg` interface and implementations of `GetSignBytes` can be deleted. Because of this change, global legacy Amino codec definitions and their registration in `init()` can safely be removed as well.
189+
184190
#### `x/auth`
185191

186192
For ante handler construction via `ante.NewAnteHandler`, the field `ante.HandlerOptions.SignModeHandler` has been updated to `x/tx/signing/HandlerMap` from `x/auth/signing/SignModeHandler`. Callers typically fetch this value from `client.TxConfig.SignModeHandler()` (which is also changed) so this change should be transparent to most users.

api/cosmos/gov/v1/tx.pulsar.go

Lines changed: 169 additions & 165 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/cosmos/tx/v1beta1/tx.pulsar.go

Lines changed: 161 additions & 156 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

codec/proto_codec.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package codec
22

33
import (
44
"encoding/binary"
5+
"encoding/json"
56
"errors"
67
"fmt"
78
"strings"
@@ -17,6 +18,7 @@ import (
1718
"google.golang.org/protobuf/types/known/anypb"
1819

1920
"cosmossdk.io/x/tx/signing/aminojson"
21+
2022
"github.com/cosmos/cosmos-sdk/codec/types"
2123
)
2224

@@ -196,7 +198,23 @@ func (pc *ProtoCodec) MarshalAminoJSON(msg gogoproto.Message) ([]byte, error) {
196198
if err != nil {
197199
return nil, err
198200
}
199-
return jsonBytes, nil
201+
// TODO: remove this sort once https://github.com/cosmos/cosmos-sdk/issues/2350#issuecomment-1542715157 lands
202+
// the encoder should be rendering in lexical order
203+
return sortJSON(jsonBytes)
204+
}
205+
206+
// sortJSON sorts the JSON keys of the given JSON encoded byte slice.
207+
func sortJSON(toSortJSON []byte) ([]byte, error) {
208+
var c interface{}
209+
err := json.Unmarshal(toSortJSON, &c)
210+
if err != nil {
211+
return nil, err
212+
}
213+
js, err := json.Marshal(c)
214+
if err != nil {
215+
return nil, err
216+
}
217+
return js, nil
200218
}
201219

202220
// UnmarshalJSON implements JSONCodec.UnmarshalJSON method,

core/coins/format.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func formatCoin(coin *basev1beta1.Coin, metadata *bankv1beta1.Metadata) (string,
6767
return vr + " " + dispDenom, err
6868
}
6969

70-
// formatCoins formats Coins into a value-rendered string, which uses
70+
// FormatCoins formats Coins into a value-rendered string, which uses
7171
// `formatCoin` separated by ", " (a comma and a space), and sorted
7272
// alphabetically by value-rendered denoms. It expects an array of metadata
7373
// (optionally nil), where each metadata at index `i` MUST match the coin denom

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ require (
159159

160160
// Below are the short-lived replace of the Cosmos SDK
161161
replace (
162+
// TODO remove after cosmossdk.io/api release
163+
cosmossdk.io/api => ./api
162164
// TODO: remove me after collections 0.2. is released.
163165
cosmossdk.io/collections => ./collections
164166
cosmossdk.io/core => ./core

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl
3535
cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs=
3636
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
3737
cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo=
38-
cosmossdk.io/api v0.4.1 h1:0ikaYM6GyxTYYcfBiyR8YnLCfhNnhKpEFnaSepCTmqg=
39-
cosmossdk.io/api v0.4.1/go.mod h1:jR7k5ok90LxW2lFUXvd8Vpo/dr4PpiyVegxdm7b1ZdE=
4038
cosmossdk.io/depinject v1.0.0-alpha.3 h1:6evFIgj//Y3w09bqOUOzEpFj5tsxBqdc5CfkO7z+zfw=
4139
cosmossdk.io/depinject v1.0.0-alpha.3/go.mod h1:eRbcdQ7MRpIPEM5YUJh8k97nxHpYbc3sMUnEtt8HPWU=
4240
cosmossdk.io/errors v1.0.0-beta.7.0.20230524212735-6cabb6aa5741 h1:BCRz06fvddw7cKGiEGDiSox3qMsjQ97f92K+PDZDHdc=

proto/cosmos/gov/v1/tx.proto

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,12 @@ message MsgSubmitProposal {
5555
repeated google.protobuf.Any messages = 1;
5656

5757
// initial_deposit is the deposit value that must be paid at proposal submission.
58-
repeated cosmos.base.v1beta1.Coin initial_deposit = 2 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
58+
repeated cosmos.base.v1beta1.Coin initial_deposit = 2 [
59+
(gogoproto.nullable) = false,
60+
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins",
61+
(amino.dont_omitempty) = true,
62+
(amino.encoding) = "legacy_coins"
63+
];
5964

6065
// proposer is the account address of the proposer.
6166
string proposer = 3 [(cosmos_proto.scalar) = "cosmos.AddressString"];

proto/cosmos/tx/v1beta1/tx.proto

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
syntax = "proto3";
22
package cosmos.tx.v1beta1;
33

4+
import "amino/amino.proto";
45
import "gogoproto/gogo.proto";
56
import "cosmos/crypto/multisig/v1beta1/multisig.proto";
67
import "cosmos/base/v1beta1/coin.proto";
@@ -205,8 +206,12 @@ message ModeInfo {
205206
// which must be above some miminum to be accepted into the mempool.
206207
message Fee {
207208
// amount is the amount of coins to be paid as a fee
208-
repeated cosmos.base.v1beta1.Coin amount = 1
209-
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"];
209+
repeated cosmos.base.v1beta1.Coin amount = 1 [
210+
(gogoproto.nullable) = false,
211+
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins",
212+
(amino.dont_omitempty) = true,
213+
(amino.encoding) = "legacy_coins"
214+
];
210215

211216
// gas_limit is the maximum gas that can be used in transaction processing
212217
// before an out of gas error occurs
@@ -228,8 +233,12 @@ message Fee {
228233
// Since: cosmos-sdk 0.46
229234
message Tip {
230235
// amount is the amount of the tip
231-
repeated cosmos.base.v1beta1.Coin amount = 1
232-
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"];
236+
repeated cosmos.base.v1beta1.Coin amount = 1 [
237+
(gogoproto.nullable) = false,
238+
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins",
239+
(amino.dont_omitempty) = true,
240+
(amino.encoding) = "legacy_coins"
241+
];
233242
// tipper is the address of the account paying for the tip
234243
string tipper = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
235244
}

0 commit comments

Comments
 (0)