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

refactor: simplify sign mode (2/2) (backport #23476) #23477

Merged
merged 2 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i
* [#23470](/~https://github.com/cosmos/cosmos-sdk/pull/23470) Converge to use of one single sign mode type and signer data:
* Use api's signmode throughout the SDK to align with `cosmossdk.io/tx`. This allows developer not to juggle between sign mode types
* Deprecate `authsigning.SignerData` in favor of txsigning.SignerData and replace its usage
* Move helpers to go from one sign mode enum to another to `types/signing` instead of `x/auth/signing` (less dependency on `x`)
* Remove `APISignModeToInternal` from `x/auth` as no conversion is necessary by the user anymore
* (all) [#23445](/~https://github.com/cosmos/cosmos-sdk/pull/23445) Remove `v2` code from codebase.
* (codec) [#22988](/~https://github.com/cosmos/cosmos-sdk/pull/22988) Improve edge case handling for recursion limits.
* (proto) [#23437](/~https://github.com/cosmos/cosmos-sdk/pull/23437) Deprecate `Block` field from `GetBlockByHeightResponse` and return empty comet block for `GetBlockByHeight`.
Expand Down
2 changes: 1 addition & 1 deletion client/tx/aux_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (b *AuxTxBuilder) SetSignMode(mode apisigning.SignMode) error {
apisigning.SignMode_SIGN_MODE_DIRECT_AUX, apisigning.SignMode_SIGN_MODE_LEGACY_AMINO_JSON)
}

b.auxSignerData.Mode, _ = signing.APISignModeToInternal(mode)
b.auxSignerData.Mode = signing.SignMode(mode)
return nil
}

Expand Down
4 changes: 1 addition & 3 deletions client/tx/aux_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
typestx "github.com/cosmos/cosmos-sdk/types/tx"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
)

const (
Expand Down Expand Up @@ -249,7 +248,6 @@ func checkCorrectData(t *testing.T, cdc codec.Codec, auxSignerData typestx.AuxSi
require.Equal(t, chainID, auxSignerData.SignDoc.ChainId)
require.Equal(t, msgAny, body.GetMessages()[0])
require.Equal(t, pkAny, auxSignerData.SignDoc.PublicKey)
m, _ := signing.InternalSignModeToAPI(auxSignerData.Mode)
require.Equal(t, signMode, m)
require.Equal(t, signMode, apisigning.SignMode(auxSignerData.Mode))
require.Equal(t, rawSig, auxSignerData.Sig)
}
3 changes: 3 additions & 0 deletions client/v2/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ Ref: https://keepachangelog.com/en/1.0.0/

## [Unreleased]

## [v2.10.0-beta.2](/~https://github.com/cosmos/cosmos-sdk/releases/tag/client/v2/v2.10.0-beta.2) - 2025-01-22

* [#23325](/~https://github.com/cosmos/cosmos-sdk/pull/23325) Remove `NewAppOptionsFromConfig` that isn't needed in normal wiring.
* [#23470](/~https://github.com/cosmos/cosmos-sdk/pull/23470) Accept sign mode from `cosmossdk.io/api`.

## [v2.10.0-beta.1](/~https://github.com/cosmos/cosmos-sdk/releases/tag/client/v2/v2.10.0-beta.1) - 2024-12-18

Expand Down
2 changes: 1 addition & 1 deletion client/v2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,4 @@ require (
pgregory.net/rapid v1.1.0 // indirect
)

replace github.com/cosmos/cosmos-sdk => github.com/cosmos/cosmos-sdk v0.52.0-rc.1.0.20250122113551-ad692c97166e
replace github.com/cosmos/cosmos-sdk => github.com/cosmos/cosmos-sdk v0.52.0-rc.1.0.20250122120205-bc49a8e7fd2f
4 changes: 2 additions & 2 deletions client/v2/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ github.com/cosmos/cosmos-db v1.1.1 h1:FezFSU37AlBC8S98NlSagL76oqBRWq/prTPvFcEJNC
github.com/cosmos/cosmos-db v1.1.1/go.mod h1:AghjcIPqdhSLP/2Z0yha5xPH3nLnskz81pBx3tcVSAw=
github.com/cosmos/cosmos-proto v1.0.0-beta.5 h1:eNcayDLpip+zVLRLYafhzLvQlSmyab+RC5W7ZfmxJLA=
github.com/cosmos/cosmos-proto v1.0.0-beta.5/go.mod h1:hQGLpiIUloJBMdQMMWb/4wRApmI9hjHH05nefC0Ojec=
github.com/cosmos/cosmos-sdk v0.52.0-rc.1.0.20250122113551-ad692c97166e h1:uD+6+X9yIfcBH13hJZjPqiTnZAuskWWUlLtIrbTQ7K4=
github.com/cosmos/cosmos-sdk v0.52.0-rc.1.0.20250122113551-ad692c97166e/go.mod h1:NBaGSpGuOFFDx7V/FVmbPqm1n0Xu3ihzqCbqj+8PxVs=
github.com/cosmos/cosmos-sdk v0.52.0-rc.1.0.20250122120205-bc49a8e7fd2f h1:la+6zEjMn3+/gG+uHyJYyqkJ6HUAgP1NcoKH21rvBUE=
github.com/cosmos/cosmos-sdk v0.52.0-rc.1.0.20250122120205-bc49a8e7fd2f/go.mod h1:NBaGSpGuOFFDx7V/FVmbPqm1n0Xu3ihzqCbqj+8PxVs=
github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY=
github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw=
github.com/cosmos/gogogateway v1.2.0 h1:Ae/OivNhp8DqBi/sh2A8a1D0y638GpL3tkmLQAiKxTE=
Expand Down
6 changes: 3 additions & 3 deletions types/tx/direct_aux.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package tx
import (
gogoprotoany "github.com/cosmos/gogoproto/types/any"

apisigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1"

cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
Expand Down Expand Up @@ -50,12 +52,10 @@ func (a *AuxSignerData) GetSignatureV2() (signing.SignatureV2, error) {
return signing.SignatureV2{}, sdkerrors.ErrInvalidType.Wrapf("expected %T, got %T", (cryptotypes.PubKey)(nil), pk)
}

signMode, _ := signing.InternalSignModeToAPI(a.Mode)

return signing.SignatureV2{
PubKey: pk,
Data: &signing.SingleSignatureData{
SignMode: signMode,
SignMode: apisigning.SignMode(a.Mode),
Signature: a.Sig,
},
Sequence: a.SignDoc.Sequence,
Expand Down
5 changes: 3 additions & 2 deletions types/tx/direct_aux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (

"github.com/stretchr/testify/require"

apisigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1"

codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
Expand Down Expand Up @@ -76,8 +78,7 @@ func TestAuxSignerData(t *testing.T) {
require.NoError(t, err)
sigV2, err := tc.sd.GetSignatureV2()
require.NoError(t, err)
m, _ := signing.InternalSignModeToAPI(tc.sd.Mode)
require.Equal(t, m, sigV2.Data.(*signing.SingleSignatureData).SignMode)
require.Equal(t, apisigning.SignMode(tc.sd.Mode), sigV2.Data.(*signing.SingleSignatureData).SignMode)
require.Equal(t, tc.sd.Sig, sigV2.Data.(*signing.SingleSignatureData).Signature)
require.Equal(t, tc.sd.SignDoc.Sequence, sigV2.Sequence)
require.True(t, tc.sd.SignDoc.PublicKey.GetCachedValue().(cryptotypes.PubKey).Equals(sigV2.PubKey))
Expand Down
8 changes: 4 additions & 4 deletions types/tx/signing/signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (

gogoprotoany "github.com/cosmos/gogoproto/types/any"

signingv1beta1 "cosmossdk.io/api/cosmos/tx/signing/v1beta1"

cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
)

Expand Down Expand Up @@ -32,11 +34,10 @@ type SignatureV2 struct {
func SignatureDataToProto(data SignatureData) *SignatureDescriptor_Data {
switch data := data.(type) {
case *SingleSignatureData:
signMode, _ := APISignModeToInternal(data.SignMode)
return &SignatureDescriptor_Data{
Sum: &SignatureDescriptor_Data_Single_{
Single: &SignatureDescriptor_Data_Single{
Mode: signMode,
Mode: SignMode(data.SignMode),
Signature: data.Signature,
},
},
Expand Down Expand Up @@ -67,9 +68,8 @@ func SignatureDataToProto(data SignatureData) *SignatureDescriptor_Data {
func SignatureDataFromProto(descData *SignatureDescriptor_Data) SignatureData {
switch descData := descData.Sum.(type) {
case *SignatureDescriptor_Data_Single_:
signMode, _ := InternalSignModeToAPI(descData.Single.Mode)
return &SingleSignatureData{
SignMode: signMode,
SignMode: signingv1beta1.SignMode(descData.Single.Mode),
Signature: descData.Single.Signature,
}
case *SignatureDescriptor_Data_Multi_:
Expand Down
39 changes: 0 additions & 39 deletions types/tx/signing/types.go

This file was deleted.

4 changes: 1 addition & 3 deletions x/auth/tx/sigs.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ func SignatureDataToModeInfoAndSig(data signing.SignatureData) (*tx.ModeInfo, []

switch data := data.(type) {
case *signing.SingleSignatureData:
signMode, _ := signing.APISignModeToInternal(data.SignMode)

return &tx.ModeInfo{
Sum: &tx.ModeInfo_Single_{
Single: &tx.ModeInfo_Single{Mode: signMode},
Single: &tx.ModeInfo_Single{Mode: signing.SignMode(data.SignMode)},
},
}, data.Signature
case *signing.MultiSignatureData:
Expand Down
Loading