From 6f2bab52f1b5ffa1a4652a067bbf19636b589b65 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Tue, 7 Jan 2025 00:43:44 +0800 Subject: [PATCH] fix(x/auth/tx): add missing CacheWithValue for ExtensionOptions (#23144) --- CHANGELOG.md | 1 + x/auth/tx/builder.go | 2 +- x/auth/tx/gogotx.go | 20 ++++++++++++++------ 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0816734bfcf0..84211e5ed58e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,6 +53,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i ### Bug Fixes * (query) [23002](https://github.com/cosmos/cosmos-sdk/pull/23002) Fix collection filtered pagination. +* (x/auth/tx) [23144](https://github.com/cosmos/cosmos-sdk/pull/23144) Add missing CacheWithValue for ExtensionOptions. * (x/auth/tx) [#23148](https://github.com/cosmos/cosmos-sdk/pull/23148) Avoid panic from intoAnyV2 when v1.PublicKey is optional. ### API Breaking Changes diff --git a/x/auth/tx/builder.go b/x/auth/tx/builder.go index 17b23f8b645b..e786ff08bdb7 100644 --- a/x/auth/tx/builder.go +++ b/x/auth/tx/builder.go @@ -46,7 +46,7 @@ func newBuilderFromDecodedTx( modeInfoV1 := new(tx.ModeInfo) fromV2ModeInfo(sigInfo.ModeInfo, modeInfoV1) sigInfos[i] = &tx.SignerInfo{ - PublicKey: intoAnyV1([]*anypb.Any{sigInfo.PublicKey})[0], + PublicKey: intoAnyV1(codec, []*anypb.Any{sigInfo.PublicKey})[0], ModeInfo: modeInfoV1, Sequence: sigInfo.Sequence, } diff --git a/x/auth/tx/gogotx.go b/x/auth/tx/gogotx.go index 196b6a6827c7..49533934a54f 100644 --- a/x/auth/tx/gogotx.go +++ b/x/auth/tx/gogotx.go @@ -7,6 +7,7 @@ import ( "time" "github.com/cosmos/gogoproto/proto" + gogoproto "github.com/cosmos/gogoproto/types/any" "google.golang.org/protobuf/reflect/protoreflect" "google.golang.org/protobuf/types/known/anypb" @@ -236,11 +237,11 @@ func (w *gogoTxWrapper) GetSigningTxData() txsigning.TxData { } func (w *gogoTxWrapper) GetExtensionOptions() []*codectypes.Any { - return intoAnyV1(w.Tx.Body.ExtensionOptions) + return intoAnyV1(w.cdc, w.Tx.Body.ExtensionOptions) } func (w *gogoTxWrapper) GetNonCriticalExtensionOptions() []*codectypes.Any { - return intoAnyV1(w.Tx.Body.NonCriticalExtensionOptions) + return intoAnyV1(w.cdc, w.Tx.Body.NonCriticalExtensionOptions) } func (w *gogoTxWrapper) AsTx() (*txtypes.Tx, error) { @@ -270,13 +271,20 @@ func (w *gogoTxWrapper) AsTxRaw() (*txtypes.TxRaw, error) { }, nil } -func intoAnyV1(v2s []*anypb.Any) []*codectypes.Any { +func intoAnyV1(cdc codec.BinaryCodec, v2s []*anypb.Any) []*codectypes.Any { v1s := make([]*codectypes.Any, len(v2s)) for i, v2 := range v2s { - v1s[i] = &codectypes.Any{ - TypeUrl: v2.TypeUrl, - Value: v2.Value, + var value *gogoproto.Any + if msg, err := decodeFromAny(cdc, v2); err == nil { + value, _ = gogoproto.NewAnyWithCacheWithValue(msg) } + if value == nil { + value = &codectypes.Any{ + TypeUrl: v2.TypeUrl, + Value: v2.Value, + } + } + v1s[i] = value } return v1s }