diff --git a/.vscode/launch.json b/.vscode/launch.json index d188c4ae2a5f..a5e7a729457b 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -20,6 +20,15 @@ "program": "${workspaceFolder}/simapp/v2/simdv2", "args": ["start"], "buildFlags": "" + }, + { + "name": "Start: simapp/v1", + "type": "go", + "request": "launch", + "mode": "debug", + "program": "${workspaceFolder}/simapp/simd", + "args": ["start"], + "buildFlags": "" } ] } diff --git a/testutil/testdata/testpb/tx.proto b/testutil/testdata/testpb/tx.proto index d3b97193acf7..f49900205e3a 100644 --- a/testutil/testdata/testpb/tx.proto +++ b/testutil/testdata/testpb/tx.proto @@ -5,6 +5,7 @@ import "amino/amino.proto"; import "gogoproto/gogo.proto"; import "testpb/testdata.proto"; import "cosmos/msg/v1/msg.proto"; +import "cosmos_proto/cosmos.proto"; option go_package = "github.com/cosmos/cosmos-sdk/testutil/testdata"; @@ -35,4 +36,11 @@ message TestMsg { option (amino.name) = "testpb/TestMsg"; repeated string signers = 1; + + string decField = 2 [ + (cosmos_proto.scalar) = "cosmos.Dec", + (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", + (amino.dont_omitempty) = true, + (gogoproto.nullable) = false + ]; } diff --git a/testutil/testdata/testpb/tx.pulsar.go b/testutil/testdata/testpb/tx.pulsar.go index 5e4213c4802a..14b44049e00d 100644 --- a/testutil/testdata/testpb/tx.pulsar.go +++ b/testutil/testdata/testpb/tx.pulsar.go @@ -5,6 +5,7 @@ import ( _ "cosmossdk.io/api/amino" _ "cosmossdk.io/api/cosmos/msg/v1" fmt "fmt" + _ "github.com/cosmos/cosmos-proto" runtime "github.com/cosmos/cosmos-proto/runtime" _ "github.com/cosmos/gogoproto/gogoproto" protoreflect "google.golang.org/protobuf/reflect/protoreflect" @@ -981,14 +982,16 @@ func (x *_TestMsg_1_list) IsValid() bool { } var ( - md_TestMsg protoreflect.MessageDescriptor - fd_TestMsg_signers protoreflect.FieldDescriptor + md_TestMsg protoreflect.MessageDescriptor + fd_TestMsg_signers protoreflect.FieldDescriptor + fd_TestMsg_decField protoreflect.FieldDescriptor ) func init() { file_testpb_tx_proto_init() md_TestMsg = File_testpb_tx_proto.Messages().ByName("TestMsg") fd_TestMsg_signers = md_TestMsg.Fields().ByName("signers") + fd_TestMsg_decField = md_TestMsg.Fields().ByName("decField") } var _ protoreflect.Message = (*fastReflection_TestMsg)(nil) @@ -1062,6 +1065,12 @@ func (x *fastReflection_TestMsg) Range(f func(protoreflect.FieldDescriptor, prot return } } + if x.DecField != "" { + value := protoreflect.ValueOfString(x.DecField) + if !f(fd_TestMsg_decField, value) { + return + } + } } // Has reports whether a field is populated. @@ -1079,6 +1088,8 @@ func (x *fastReflection_TestMsg) Has(fd protoreflect.FieldDescriptor) bool { switch fd.FullName() { case "testpb.TestMsg.signers": return len(x.Signers) != 0 + case "testpb.TestMsg.decField": + return x.DecField != "" default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.TestMsg")) @@ -1097,6 +1108,8 @@ func (x *fastReflection_TestMsg) Clear(fd protoreflect.FieldDescriptor) { switch fd.FullName() { case "testpb.TestMsg.signers": x.Signers = nil + case "testpb.TestMsg.decField": + x.DecField = "" default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.TestMsg")) @@ -1119,6 +1132,9 @@ func (x *fastReflection_TestMsg) Get(descriptor protoreflect.FieldDescriptor) pr } listValue := &_TestMsg_1_list{list: &x.Signers} return protoreflect.ValueOfList(listValue) + case "testpb.TestMsg.decField": + value := x.DecField + return protoreflect.ValueOfString(value) default: if descriptor.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.TestMsg")) @@ -1143,6 +1159,8 @@ func (x *fastReflection_TestMsg) Set(fd protoreflect.FieldDescriptor, value prot lv := value.List() clv := lv.(*_TestMsg_1_list) x.Signers = *clv.list + case "testpb.TestMsg.decField": + x.DecField = value.Interface().(string) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.TestMsg")) @@ -1169,6 +1187,8 @@ func (x *fastReflection_TestMsg) Mutable(fd protoreflect.FieldDescriptor) protor } value := &_TestMsg_1_list{list: &x.Signers} return protoreflect.ValueOfList(value) + case "testpb.TestMsg.decField": + panic(fmt.Errorf("field decField of message testpb.TestMsg is not mutable")) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.TestMsg")) @@ -1185,6 +1205,8 @@ func (x *fastReflection_TestMsg) NewField(fd protoreflect.FieldDescriptor) proto case "testpb.TestMsg.signers": list := []string{} return protoreflect.ValueOfList(&_TestMsg_1_list{list: &list}) + case "testpb.TestMsg.decField": + return protoreflect.ValueOfString("") default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.TestMsg")) @@ -1260,6 +1282,10 @@ func (x *fastReflection_TestMsg) ProtoMethods() *protoiface.Methods { n += 1 + l + runtime.Sov(uint64(l)) } } + l = len(x.DecField) + if l > 0 { + n += 1 + l + runtime.Sov(uint64(l)) + } if x.unknownFields != nil { n += len(x.unknownFields) } @@ -1289,6 +1315,13 @@ func (x *fastReflection_TestMsg) ProtoMethods() *protoiface.Methods { i -= len(x.unknownFields) copy(dAtA[i:], x.unknownFields) } + if len(x.DecField) > 0 { + i -= len(x.DecField) + copy(dAtA[i:], x.DecField) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.DecField))) + i-- + dAtA[i] = 0x12 + } if len(x.Signers) > 0 { for iNdEx := len(x.Signers) - 1; iNdEx >= 0; iNdEx-- { i -= len(x.Signers[iNdEx]) @@ -1379,6 +1412,38 @@ func (x *fastReflection_TestMsg) ProtoMethods() *protoiface.Methods { } x.Signers = append(x.Signers, string(dAtA[iNdEx:postIndex])) iNdEx = postIndex + case 2: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field DecField", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.DecField = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := runtime.Skip(dAtA[iNdEx:]) @@ -1512,7 +1577,8 @@ type TestMsg struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Signers []string `protobuf:"bytes,1,rep,name=signers,proto3" json:"signers,omitempty"` + Signers []string `protobuf:"bytes,1,rep,name=signers,proto3" json:"signers,omitempty"` + DecField string `protobuf:"bytes,2,opt,name=decField,proto3" json:"decField,omitempty"` } func (x *TestMsg) Reset() { @@ -1542,6 +1608,13 @@ func (x *TestMsg) GetSigners() []string { return nil } +func (x *TestMsg) GetDecField() string { + if x != nil { + return x.DecField + } + return "" +} + var File_testpb_tx_proto protoreflect.FileDescriptor var file_testpb_tx_proto_rawDesc = []byte{ @@ -1552,17 +1625,24 @@ var file_testpb_tx_proto_rawDesc = []byte{ 0x74, 0x6f, 0x1a, 0x15, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x64, 0x61, 0x74, 0x61, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x17, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x6d, 0x73, 0x67, 0x2f, 0x76, 0x31, 0x2f, 0x6d, 0x73, 0x67, 0x2e, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x22, 0x4f, 0x0a, 0x0c, 0x4d, 0x73, 0x67, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x44, - 0x6f, 0x67, 0x12, 0x1d, 0x0a, 0x03, 0x64, 0x6f, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, - 0x0b, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x44, 0x6f, 0x67, 0x52, 0x03, 0x64, 0x6f, - 0x67, 0x12, 0x14, 0x0a, 0x05, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x05, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x3a, 0x0a, 0x82, 0xe7, 0xb0, 0x2a, 0x05, 0x6f, 0x77, - 0x6e, 0x65, 0x72, 0x22, 0x2a, 0x0a, 0x14, 0x4d, 0x73, 0x67, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, - 0x44, 0x6f, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6e, - 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, - 0x48, 0x0a, 0x07, 0x54, 0x65, 0x73, 0x74, 0x4d, 0x73, 0x67, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x69, - 0x67, 0x6e, 0x65, 0x72, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x07, 0x73, 0x69, 0x67, - 0x6e, 0x65, 0x72, 0x73, 0x3a, 0x23, 0x88, 0xa0, 0x1f, 0x00, 0x82, 0xe7, 0xb0, 0x2a, 0x07, 0x73, + 0x74, 0x6f, 0x1a, 0x19, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5f, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x4f, 0x0a, + 0x0c, 0x4d, 0x73, 0x67, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x44, 0x6f, 0x67, 0x12, 0x1d, 0x0a, + 0x03, 0x64, 0x6f, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x74, 0x65, 0x73, + 0x74, 0x70, 0x62, 0x2e, 0x44, 0x6f, 0x67, 0x52, 0x03, 0x64, 0x6f, 0x67, 0x12, 0x14, 0x0a, 0x05, + 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x6f, 0x77, 0x6e, + 0x65, 0x72, 0x3a, 0x0a, 0x82, 0xe7, 0xb0, 0x2a, 0x05, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x22, 0x2a, + 0x0a, 0x14, 0x4d, 0x73, 0x67, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x44, 0x6f, 0x67, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x9c, 0x01, 0x0a, 0x07, 0x54, + 0x65, 0x73, 0x74, 0x4d, 0x73, 0x67, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, + 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x07, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x73, + 0x12, 0x52, 0x0a, 0x08, 0x64, 0x65, 0x63, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x09, 0x42, 0x36, 0xc8, 0xde, 0x1f, 0x00, 0xda, 0xde, 0x1f, 0x1b, 0x63, 0x6f, 0x73, 0x6d, + 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x6d, 0x61, 0x74, 0x68, 0x2e, 0x4c, 0x65, + 0x67, 0x61, 0x63, 0x79, 0x44, 0x65, 0x63, 0xd2, 0xb4, 0x2d, 0x0a, 0x63, 0x6f, 0x73, 0x6d, 0x6f, + 0x73, 0x2e, 0x44, 0x65, 0x63, 0xa8, 0xe7, 0xb0, 0x2a, 0x01, 0x52, 0x08, 0x64, 0x65, 0x63, 0x46, + 0x69, 0x65, 0x6c, 0x64, 0x3a, 0x23, 0x88, 0xa0, 0x1f, 0x00, 0x82, 0xe7, 0xb0, 0x2a, 0x07, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x72, 0x73, 0x8a, 0xe7, 0xb0, 0x2a, 0x0e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2f, 0x54, 0x65, 0x73, 0x74, 0x4d, 0x73, 0x67, 0x32, 0x4d, 0x0a, 0x03, 0x4d, 0x73, 0x67, 0x12, 0x3f, 0x0a, 0x09, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x44, 0x6f, 0x67, 0x12, 0x14, 0x2e, diff --git a/testutil/testdata/tx.go b/testutil/testdata/tx.go index 3abc02d61c6a..6de23c818b42 100644 --- a/testutil/testdata/tx.go +++ b/testutil/testdata/tx.go @@ -1,6 +1,7 @@ package testdata import ( + "cosmossdk.io/math" "testing" "gotest.tools/v3/assert" @@ -81,7 +82,8 @@ func NewTestMsg(addrs ...sdk.AccAddress) *TestMsg { } return &TestMsg{ - Signers: accAddresses, + Signers: accAddresses, + DecField: math.LegacyZeroDec(), } } diff --git a/testutil/testdata/tx.pb.go b/testutil/testdata/tx.pb.go index e2d416faa41e..17cefcb39269 100644 --- a/testutil/testdata/tx.pb.go +++ b/testutil/testdata/tx.pb.go @@ -5,7 +5,9 @@ package testdata import ( context "context" + cosmossdk_io_math "cosmossdk.io/math" fmt "fmt" + _ "github.com/cosmos/cosmos-proto" _ "github.com/cosmos/cosmos-sdk/types/msgservice" _ "github.com/cosmos/cosmos-sdk/types/tx/amino" _ "github.com/cosmos/gogoproto/gogoproto" @@ -129,7 +131,8 @@ func (m *MsgCreateDogResponse) GetName() string { // TestMsg is msg type for testing protobuf message using any, as defined in // https://github.com/cosmos/cosmos-sdk/issues/6213. type TestMsg struct { - Signers []string `protobuf:"bytes,1,rep,name=signers,proto3" json:"signers,omitempty"` + Signers []string `protobuf:"bytes,1,rep,name=signers,proto3" json:"signers,omitempty"` + DecField cosmossdk_io_math.LegacyDec `protobuf:"bytes,2,opt,name=decField,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"decField"` } func (m *TestMsg) Reset() { *m = TestMsg{} } @@ -174,29 +177,33 @@ func init() { func init() { proto.RegisterFile("testpb/tx.proto", fileDescriptor_1c54006dba274b2e) } var fileDescriptor_1c54006dba274b2e = []byte{ - // 337 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x90, 0x31, 0x4b, 0xc3, 0x40, - 0x14, 0xc7, 0x73, 0xd6, 0xb6, 0xe4, 0x2a, 0x8a, 0x21, 0x62, 0x08, 0x1a, 0x4b, 0x5d, 0x4a, 0xc0, - 0x1c, 0xd6, 0xad, 0x8b, 0xa0, 0x1d, 0xba, 0x14, 0x21, 0x38, 0xb9, 0xa5, 0xed, 0x71, 0x06, 0x4d, - 0x5e, 0xc9, 0xbb, 0xaa, 0xa3, 0x38, 0x89, 0x93, 0x1f, 0xc1, 0x8f, 0xd0, 0x8f, 0xe1, 0xd8, 0xd1, - 0x51, 0xda, 0xa1, 0x5f, 0x43, 0x72, 0x97, 0x68, 0x07, 0x97, 0xbc, 0xff, 0xfb, 0x3d, 0xf2, 0xbf, - 0xf7, 0xfe, 0x74, 0x47, 0x72, 0x94, 0x93, 0x21, 0x93, 0x4f, 0xc1, 0x24, 0x03, 0x09, 0x56, 0x4d, - 0x03, 0x77, 0x37, 0x4a, 0xe2, 0x14, 0x98, 0xfa, 0xea, 0x91, 0x6b, 0x0b, 0x10, 0xa0, 0x24, 0xcb, - 0x55, 0x41, 0xf7, 0x4a, 0x07, 0x8e, 0x72, 0x1c, 0xc9, 0xa8, 0xc0, 0xfb, 0x23, 0xc0, 0x04, 0x90, - 0x25, 0x28, 0xd8, 0xc3, 0x69, 0x5e, 0xf4, 0xa0, 0x75, 0x45, 0xb7, 0x06, 0x28, 0x2e, 0x33, 0x1e, - 0x49, 0xde, 0x03, 0x61, 0x1d, 0xd2, 0xca, 0x18, 0x84, 0x43, 0x9a, 0xa4, 0xdd, 0xe8, 0x34, 0x02, - 0xed, 0x16, 0xf4, 0x40, 0x84, 0x39, 0xb7, 0x6c, 0x5a, 0x85, 0xc7, 0x94, 0x67, 0xce, 0x46, 0x93, - 0xb4, 0xcd, 0x50, 0x37, 0x5d, 0xfa, 0xb2, 0x9a, 0xf9, 0x5a, 0xb7, 0x7c, 0x6a, 0xaf, 0x1b, 0x86, - 0x1c, 0x27, 0x90, 0x22, 0xb7, 0x2c, 0xba, 0x99, 0x46, 0x09, 0x57, 0xce, 0x66, 0xa8, 0x74, 0xab, - 0x4f, 0xeb, 0xd7, 0x1c, 0xe5, 0x00, 0x85, 0xe5, 0xd0, 0x3a, 0xc6, 0x22, 0xe5, 0x19, 0x3a, 0xa4, - 0x59, 0x69, 0x9b, 0x61, 0xd9, 0x76, 0x8f, 0x5f, 0x3f, 0x8e, 0x8c, 0xfc, 0x81, 0x92, 0xbc, 0xad, - 0x66, 0xfe, 0x76, 0x71, 0x66, 0xf1, 0x7b, 0x67, 0x40, 0x2b, 0xb9, 0xcb, 0x39, 0x35, 0xff, 0x4e, - 0xb1, 0xcb, 0xed, 0xd7, 0xf7, 0x71, 0x0f, 0xfe, 0xa3, 0xe5, 0x96, 0x6e, 0xf5, 0x79, 0x35, 0xf3, - 0xc9, 0x45, 0xff, 0x73, 0xe1, 0x91, 0xf9, 0xc2, 0x23, 0xdf, 0x0b, 0x8f, 0xbc, 0x2f, 0x3d, 0x63, - 0xbe, 0xf4, 0x8c, 0xaf, 0xa5, 0x67, 0xdc, 0x04, 0x22, 0x96, 0xb7, 0xd3, 0x61, 0x30, 0x82, 0x84, - 0x15, 0x99, 0xea, 0x72, 0x82, 0xe3, 0x3b, 0x95, 0xfa, 0x54, 0xc6, 0xf7, 0xbf, 0xf1, 0x0f, 0x6b, - 0x2a, 0xe6, 0xb3, 0x9f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x89, 0xf1, 0xc8, 0x3c, 0xda, 0x01, 0x00, - 0x00, + // 411 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x2f, 0x49, 0x2d, 0x2e, + 0x29, 0x48, 0xd2, 0x2f, 0xa9, 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x83, 0x08, 0x48, + 0x09, 0x26, 0xe6, 0x66, 0xe6, 0xe5, 0xeb, 0x83, 0x49, 0x88, 0x94, 0x94, 0x48, 0x7a, 0x7e, 0x7a, + 0x3e, 0x98, 0xa9, 0x0f, 0x62, 0x41, 0x45, 0x45, 0x61, 0x26, 0xa4, 0x16, 0x97, 0xa4, 0x24, 0x96, + 0x24, 0x42, 0x85, 0xc5, 0x93, 0xf3, 0x8b, 0x73, 0xf3, 0x8b, 0xf5, 0x73, 0x8b, 0xd3, 0xf5, 0xcb, + 0x0c, 0x41, 0x14, 0x54, 0x42, 0x12, 0x22, 0x11, 0x0f, 0x31, 0x08, 0xc2, 0x81, 0x48, 0x29, 0xf9, + 0x73, 0xf1, 0xf8, 0x16, 0xa7, 0x3b, 0x17, 0xa5, 0x26, 0x96, 0xa4, 0xba, 0xe4, 0xa7, 0x0b, 0xc9, + 0x72, 0x31, 0xa7, 0xe4, 0xa7, 0x4b, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x1b, 0x71, 0xeb, 0x41, 0x2c, + 0xd2, 0x73, 0xc9, 0x4f, 0x0f, 0x02, 0x89, 0x0b, 0x89, 0x70, 0xb1, 0xe6, 0x97, 0xe7, 0xa5, 0x16, + 0x49, 0x30, 0x29, 0x30, 0x6a, 0x70, 0x06, 0x41, 0x38, 0x56, 0x5c, 0x4d, 0xcf, 0x37, 0x68, 0x41, + 0xd8, 0x4a, 0x5a, 0x5c, 0x22, 0xc8, 0x06, 0x06, 0xa5, 0x16, 0x17, 0xe4, 0xe7, 0x15, 0xa7, 0x0a, + 0x09, 0x71, 0xb1, 0xe4, 0x25, 0xe6, 0xa6, 0x82, 0x4d, 0xe6, 0x0c, 0x02, 0xb3, 0x95, 0xe6, 0x30, + 0x72, 0xb1, 0x87, 0xa4, 0x16, 0x97, 0xf8, 0x16, 0xa7, 0x0b, 0x49, 0x70, 0xb1, 0x17, 0x67, 0xa6, + 0xe7, 0xa5, 0x16, 0x15, 0x4b, 0x30, 0x2a, 0x30, 0x6b, 0x70, 0x06, 0xc1, 0xb8, 0x42, 0x41, 0x5c, + 0x1c, 0x29, 0xa9, 0xc9, 0x6e, 0x99, 0xa9, 0x39, 0x29, 0x10, 0x6b, 0x9d, 0xcc, 0x4e, 0xdc, 0x93, + 0x67, 0xb8, 0x75, 0x4f, 0x5e, 0x1a, 0xe2, 0x95, 0xe2, 0x94, 0x6c, 0xbd, 0xcc, 0x7c, 0xfd, 0xdc, + 0xc4, 0x92, 0x0c, 0x3d, 0x9f, 0xd4, 0xf4, 0xc4, 0xe4, 0x4a, 0x97, 0xd4, 0xe4, 0x4b, 0x5b, 0x74, + 0xb9, 0xa0, 0x3e, 0x75, 0x49, 0x4d, 0x5e, 0xf1, 0x7c, 0x83, 0x16, 0x63, 0x10, 0xdc, 0x1c, 0x2b, + 0xe5, 0x8e, 0x05, 0xf2, 0x0c, 0x20, 0x57, 0xc3, 0x6c, 0xe9, 0x7a, 0xbe, 0x41, 0x8b, 0x0f, 0x1a, + 0xac, 0x50, 0x27, 0x19, 0xf9, 0x72, 0x31, 0x83, 0x5c, 0x66, 0xcf, 0xc5, 0x89, 0x08, 0x1f, 0x11, + 0x58, 0x90, 0x20, 0x7b, 0x52, 0x4a, 0x06, 0x9b, 0x28, 0xcc, 0xeb, 0x52, 0xac, 0x0d, 0x20, 0xdb, + 0x9d, 0x3c, 0x4e, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, 0x09, + 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0x4a, 0x2f, 0x3d, 0xb3, + 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f, 0x17, 0x1a, 0x3b, 0x50, 0x4a, 0xb7, 0x38, 0x25, 0x1b, + 0x1c, 0xcb, 0xa5, 0x25, 0x99, 0x39, 0xf0, 0xe8, 0x4e, 0x62, 0x03, 0xc7, 0x9d, 0x31, 0x20, 0x00, + 0x00, 0xff, 0xff, 0x82, 0x43, 0x1a, 0xed, 0x4a, 0x02, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -371,6 +378,16 @@ func (m *TestMsg) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + { + size := m.DecField.Size() + i -= size + if _, err := m.DecField.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 if len(m.Signers) > 0 { for iNdEx := len(m.Signers) - 1; iNdEx >= 0; iNdEx-- { i -= len(m.Signers[iNdEx]) @@ -436,6 +453,8 @@ func (m *TestMsg) Size() (n int) { n += 1 + l + sovTx(uint64(l)) } } + l = m.DecField.Size() + n += 1 + l + sovTx(uint64(l)) return n } @@ -706,6 +725,40 @@ func (m *TestMsg) Unmarshal(dAtA []byte) error { } m.Signers = append(m.Signers, string(dAtA[iNdEx:postIndex])) iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DecField", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.DecField.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipTx(dAtA[iNdEx:]) diff --git a/types/tx_msg_test.go b/types/tx_msg_test.go index 31ca01f5df6e..13c795c7ba9a 100644 --- a/types/tx_msg_test.go +++ b/types/tx_msg_test.go @@ -6,6 +6,8 @@ import ( "github.com/stretchr/testify/suite" "google.golang.org/protobuf/types/known/anypb" + "cosmossdk.io/math" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" @@ -35,7 +37,8 @@ func (s *testMsgSuite) TestMsgTypeURL() { } func (s *testMsgSuite) TestGetMsgFromTypeURL() { - msg := new(testdata.TestMsg) + msg := testdata.NewTestMsg() + msg.DecField = math.LegacyZeroDec() cdc := codec.NewProtoCodec(testdata.NewTestInterfaceRegistry()) result, err := sdk.GetMsgFromTypeURL(cdc, "/testpb.TestMsg") diff --git a/x/auth/ante/unordered.go b/x/auth/ante/unordered.go index 3441ef442787..b97774ef6118 100644 --- a/x/auth/ante/unordered.go +++ b/x/auth/ante/unordered.go @@ -7,7 +7,7 @@ import ( "sync" "time" - "github.com/golang/protobuf/proto" // nolint: staticcheck // for proto.Message + "github.com/cosmos/gogoproto/proto" "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/core/transaction" @@ -49,7 +49,12 @@ type UnorderedTxDecorator struct { sha256Cost uint64 } -func NewUnorderedTxDecorator(maxDuration time.Duration, m *unorderedtx.Manager, env appmodule.Environment, gasCost uint64) *UnorderedTxDecorator { +func NewUnorderedTxDecorator( + maxDuration time.Duration, + m *unorderedtx.Manager, + env appmodule.Environment, + gasCost uint64, +) *UnorderedTxDecorator { return &UnorderedTxDecorator{ maxTimeoutDuration: maxDuration, txManager: m, @@ -58,7 +63,12 @@ func NewUnorderedTxDecorator(maxDuration time.Duration, m *unorderedtx.Manager, } } -func (d *UnorderedTxDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, _ bool, next sdk.AnteHandler) (sdk.Context, error) { +func (d *UnorderedTxDecorator) AnteHandle( + ctx sdk.Context, + tx sdk.Tx, + _ bool, + next sdk.AnteHandler, +) (sdk.Context, error) { unorderedTx, ok := tx.(sdk.TxWithUnordered) if !ok || !unorderedTx.GetUnordered() { // If the transaction does not implement unordered capabilities or has the @@ -69,13 +79,23 @@ func (d *UnorderedTxDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, _ bool, ne headerInfo := d.env.HeaderService.HeaderInfo(ctx) timeoutTimestamp := unorderedTx.GetTimeoutTimeStamp() if timeoutTimestamp.IsZero() || timeoutTimestamp.Unix() == 0 { - return ctx, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "unordered transaction must have timeout_timestamp set") + return ctx, errorsmod.Wrap( + sdkerrors.ErrInvalidRequest, + "unordered transaction must have timeout_timestamp set", + ) } if timeoutTimestamp.Before(headerInfo.Time) { - return ctx, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "unordered transaction has a timeout_timestamp that has already passed") + return ctx, errorsmod.Wrap( + sdkerrors.ErrInvalidRequest, + "unordered transaction has a timeout_timestamp that has already passed", + ) } if timeoutTimestamp.After(headerInfo.Time.Add(d.maxTimeoutDuration)) { - return ctx, errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "unordered tx ttl exceeds %s", d.maxTimeoutDuration.String()) + return ctx, errorsmod.Wrapf( + sdkerrors.ErrInvalidRequest, + "unordered tx ttl exceeds %s", + d.maxTimeoutDuration.String(), + ) } // consume gas in all exec modes to avoid gas estimation discrepancies @@ -97,7 +117,10 @@ func (d *UnorderedTxDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, _ bool, ne // check for duplicates if d.txManager.Contains(txHash) { - return ctx, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "tx %X is duplicated") + return ctx, errorsmod.Wrap( + sdkerrors.ErrInvalidRequest, + "tx %X is duplicated", + ) } if d.env.TransactionService.ExecMode(ctx) == transaction.ExecModeFinalize { // a new tx included in the block, add the hash to the unordered tx manager @@ -111,7 +134,10 @@ func (d *UnorderedTxDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, _ bool, ne func TxIdentifier(timeout uint64, tx sdk.Tx) ([32]byte, error) { feetx := tx.(sdk.FeeTx) if feetx.GetFee().IsZero() { - return [32]byte{}, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "unordered transaction must have a fee") + return [32]byte{}, errorsmod.Wrap( + sdkerrors.ErrInvalidRequest, + "unordered transaction must have a fee", + ) } buf := bufPool.Get().(*bytes.Buffer) @@ -126,22 +152,34 @@ func TxIdentifier(timeout uint64, tx sdk.Tx) ([32]byte, error) { // Malleability is not a concern here because the state machine will encode the transaction deterministically. bz, err := proto.Marshal(msg) if err != nil { - return [32]byte{}, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "failed to marshal message") + return [32]byte{}, errorsmod.Wrap( + sdkerrors.ErrInvalidRequest, + "failed to marshal message", + ) } if _, err := buf.Write(bz); err != nil { - return [32]byte{}, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "failed to write message to buffer") + return [32]byte{}, errorsmod.Wrap( + sdkerrors.ErrInvalidRequest, + "failed to write message to buffer", + ) } } // write the timeout height to the buffer if err := binary.Write(buf, binary.LittleEndian, timeout); err != nil { - return [32]byte{}, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "failed to write timeout_height to buffer") + return [32]byte{}, errorsmod.Wrap( + sdkerrors.ErrInvalidRequest, + "failed to write timeout_height to buffer", + ) } // write gas to the buffer if err := binary.Write(buf, binary.LittleEndian, feetx.GetGas()); err != nil { - return [32]byte{}, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "failed to write unordered to buffer") + return [32]byte{}, errorsmod.Wrap( + sdkerrors.ErrInvalidRequest, + "failed to write unordered to buffer", + ) } txHash := sha256.Sum256(buf.Bytes()) diff --git a/x/auth/migrations/legacytx/stdtx_test.go b/x/auth/migrations/legacytx/stdtx_test.go index f49357ca6398..cdb28e978b2b 100644 --- a/x/auth/migrations/legacytx/stdtx_test.go +++ b/x/auth/migrations/legacytx/stdtx_test.go @@ -44,7 +44,7 @@ func TestStdSignBytes(t *testing.T) { Amount: []*basev1beta1.Coin{{Denom: "atom", Amount: "150"}}, GasLimit: 100000, } - msgStr := fmt.Sprintf(`{"type":"testpb/TestMsg","value":{"signers":["%s"]}}`, addr) + msgStr := fmt.Sprintf(`{"type":"testpb/TestMsg","value":{"decField":"0","signers":["%s"]}}`, addr) tests := []struct { name string args args diff --git a/x/auth/tx/decoder.go b/x/auth/tx/decoder.go index ed576ddf68c2..74b20621690b 100644 --- a/x/auth/tx/decoder.go +++ b/x/auth/tx/decoder.go @@ -1,36 +1,35 @@ package tx import ( - "google.golang.org/protobuf/encoding/protojson" + gogoproto "github.com/cosmos/gogoproto/proto" txv1beta1 "cosmossdk.io/api/cosmos/tx/v1beta1" "cosmossdk.io/core/address" + errorsmod "cosmossdk.io/errors" "cosmossdk.io/x/tx/decode" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/types/tx" ) // DefaultJSONTxDecoder returns a default protobuf JSON TxDecoder using the provided Marshaler. -func DefaultJSONTxDecoder(addrCodec address.Codec, cdc codec.BinaryCodec, decoder *decode.Decoder) sdk.TxDecoder { - jsonUnmarshaller := protojson.UnmarshalOptions{ - AllowPartial: false, - DiscardUnknown: false, - } +func DefaultJSONTxDecoder(addrCodec address.Codec, cdc codec.Codec, decoder *decode.Decoder) sdk.TxDecoder { return func(txBytes []byte) (sdk.Tx, error) { - jsonTx := new(txv1beta1.Tx) - err := jsonUnmarshaller.Unmarshal(txBytes, jsonTx) + var jsonTx tx.Tx + err := cdc.UnmarshalJSON(txBytes, &jsonTx) if err != nil { - return nil, err + return nil, errorsmod.Wrap(sdkerrors.ErrTxDecode, err.Error()) } // need to convert jsonTx into raw tx. - bodyBytes, err := marshalOption.Marshal(jsonTx.Body) + bodyBytes, err := gogoproto.Marshal(jsonTx.Body) if err != nil { return nil, err } - authInfoBytes, err := marshalOption.Marshal(jsonTx.AuthInfo) + authInfoBytes, err := gogoproto.Marshal(jsonTx.AuthInfo) if err != nil { return nil, err } diff --git a/x/auth/tx/encoder.go b/x/auth/tx/encoder.go index df15da9fca8e..f40e75962686 100644 --- a/x/auth/tx/encoder.go +++ b/x/auth/tx/encoder.go @@ -3,10 +3,12 @@ package tx import ( "fmt" - "google.golang.org/protobuf/encoding/protojson" + gogoproto "github.com/cosmos/gogoproto/proto" + "google.golang.org/protobuf/proto" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" + sdktx "github.com/cosmos/cosmos-sdk/types/tx" ) // DefaultTxEncoder returns a default protobuf TxEncoder using the provided Marshaler @@ -22,16 +24,28 @@ func DefaultTxEncoder() sdk.TxEncoder { // DefaultJSONTxEncoder returns a default protobuf JSON TxEncoder using the provided Marshaler. func DefaultJSONTxEncoder(cdc codec.Codec) sdk.TxEncoder { - jsonMarshaler := protojson.MarshalOptions{ - Indent: "", - UseProtoNames: true, - UseEnumNumbers: false, - } return func(tx sdk.Tx) ([]byte, error) { + // 1) Unwrap the tx gogoWrapper, ok := tx.(*gogoTxWrapper) if !ok { return nil, fmt.Errorf("unexpected tx type: %T", tx) } - return jsonMarshaler.Marshal(gogoWrapper.Tx) + // The unwrapped tx is a pulsar message, but SDK spec for marshaling JSON is AminoJSON. + // AminoJSON only operates on gogoproto structures, so we need to convert the pulsar message to a "v1" (gogoproto) Tx. + // see: https://github.com/cosmos/cosmos-sdk/issues/20431 and associated PRs for an eventual fix. + // + // 2) Marshal the pulsar message to bytes + bz, err := proto.Marshal(gogoWrapper.Tx) + if err != nil { + return nil, err + } + // 3) Umarshal the bytes to a "v1" (gogoproto) Tx + v1Tx := &sdktx.Tx{} + err = gogoproto.Unmarshal(bz, v1Tx) + if err != nil { + return nil, err + } + // 4) Marshal the "v1" (gogoproto) to Amino ProtoJSON + return cdc.MarshalJSON(v1Tx) } } diff --git a/x/auth/tx/testutil/suite.go b/x/auth/tx/testutil/suite.go index 1689fca40161..6ac4b25608c6 100644 --- a/x/auth/tx/testutil/suite.go +++ b/x/auth/tx/testutil/suite.go @@ -3,10 +3,12 @@ package testutil import ( "bytes" "context" + "strings" "github.com/stretchr/testify/suite" signingv1beta1 "cosmossdk.io/api/cosmos/tx/signing/v1beta1" + "cosmossdk.io/math" "cosmossdk.io/x/auth/signing" "github.com/cosmos/cosmos-sdk/client" @@ -74,7 +76,8 @@ func (s *TxConfigTestSuite) TestTxBuilderSetMsgs() { err := txBuilder.SetMsgs(msgs...) s.Require().NoError(err) tx := txBuilder.GetTx() - s.Require().Equal(msgs, tx.GetMsgs()) + unbuiltMsgs := tx.GetMsgs() + s.Require().Equal(msgs, unbuiltMsgs) signers, err := tx.GetSigners() s.Require().NoError(err) s.Require().Equal([][]byte{addr1, addr2}, signers) @@ -242,6 +245,8 @@ func (s *TxConfigTestSuite) TestTxEncodeDecode() { gasLimit := uint64(50000) memo := "foomemo" msg := testdata.NewTestMsg(addr) + pi := "3.141590000000000000" + msg.DecField = math.LegacyMustNewDecFromStr(pi) dummySig := []byte("dummySig") sig := signingtypes.SignatureV2{ PubKey: pubkey, @@ -286,6 +291,9 @@ func (s *TxConfigTestSuite) TestTxEncodeDecode() { jsonTxBytes, err := s.TxConfig.TxJSONEncoder()(tx) s.Require().NoError(err) s.Require().NotNil(jsonTxBytes) + // ensure the JSON representation contains the human read-able decimal value + s.Require().True(strings.Contains(string(jsonTxBytes), pi), + "expected %s to contain %s", string(jsonTxBytes), pi) log("JSON decode transaction") tx2, err = s.TxConfig.TxJSONDecoder()(jsonTxBytes) @@ -302,6 +310,8 @@ func (s *TxConfigTestSuite) TestTxEncodeDecode() { pks, err = tx3.GetPubKeys() s.Require().NoError(err) s.Require().Equal([]cryptotypes.PubKey{pubkey}, pks) + msg2 := tx2.GetMsgs()[0].(*testdata.TestMsg) + s.Require().Equal(pi, msg2.DecField.String()) } func (s *TxConfigTestSuite) TestWrapTxBuilder() {