From 76ffdccb03b63ba6cc9bf43b4dfc6b32f8e5eb2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?colin=20axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Wed, 11 Nov 2020 16:52:11 +0100 Subject: [PATCH] IBC Fraction for trust level changed to uints (#7892) * fraction uses uint now * Update proto/ibc/lightclients/tendermint/v1/tendermint.proto Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> --- .../tendermint/v1/tendermint.proto | 6 +++--- .../07-tendermint/client/cli/tx.go | 4 ++-- .../07-tendermint/types/fraction.go | 8 ++++---- .../07-tendermint/types/tendermint.pb.go | 18 +++++++++--------- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/proto/ibc/lightclients/tendermint/v1/tendermint.proto b/proto/ibc/lightclients/tendermint/v1/tendermint.proto index c592a9b5daea..a6076b6cf64e 100644 --- a/proto/ibc/lightclients/tendermint/v1/tendermint.proto +++ b/proto/ibc/lightclients/tendermint/v1/tendermint.proto @@ -106,8 +106,8 @@ message Header { .tendermint.types.ValidatorSet trusted_validators = 4 [(gogoproto.moretags) = "yaml:\"trusted_validators\""]; } -// Fraction defines the protobuf message type for tmmath.Fraction +// Fraction defines the protobuf message type for tmmath.Fraction that only supports positive values. message Fraction { - int64 numerator = 1; - int64 denominator = 2; + uint64 numerator = 1; + uint64 denominator = 2; } diff --git a/x/ibc/light-clients/07-tendermint/client/cli/tx.go b/x/ibc/light-clients/07-tendermint/client/cli/tx.go index 54c0ac01b03c..4bfe74328dd4 100644 --- a/x/ibc/light-clients/07-tendermint/client/cli/tx.go +++ b/x/ibc/light-clients/07-tendermint/client/cli/tx.go @@ -290,12 +290,12 @@ func parseFraction(fraction string) (types.Fraction, error) { return types.Fraction{}, fmt.Errorf("fraction must have format 'numerator/denominator' got %s", fraction) } - numerator, err := strconv.ParseInt(fr[0], 10, 64) + numerator, err := strconv.ParseUint(fr[0], 10, 64) if err != nil { return types.Fraction{}, fmt.Errorf("invalid trust-level numerator: %w", err) } - denominator, err := strconv.ParseInt(fr[1], 10, 64) + denominator, err := strconv.ParseUint(fr[1], 10, 64) if err != nil { return types.Fraction{}, fmt.Errorf("invalid trust-level denominator: %w", err) } diff --git a/x/ibc/light-clients/07-tendermint/types/fraction.go b/x/ibc/light-clients/07-tendermint/types/fraction.go index e445f19ba6f8..a8d827414617 100644 --- a/x/ibc/light-clients/07-tendermint/types/fraction.go +++ b/x/ibc/light-clients/07-tendermint/types/fraction.go @@ -11,15 +11,15 @@ var DefaultTrustLevel = NewFractionFromTm(light.DefaultTrustLevel) // NewFractionFromTm returns a new Fraction instance from a tmmath.Fraction func NewFractionFromTm(f tmmath.Fraction) Fraction { return Fraction{ - Numerator: f.Numerator, - Denominator: f.Denominator, + Numerator: uint64(f.Numerator), + Denominator: uint64(f.Denominator), } } // ToTendermint converts Fraction to tmmath.Fraction func (f Fraction) ToTendermint() tmmath.Fraction { return tmmath.Fraction{ - Numerator: f.Numerator, - Denominator: f.Denominator, + Numerator: int64(f.Numerator), + Denominator: int64(f.Denominator), } } diff --git a/x/ibc/light-clients/07-tendermint/types/tendermint.pb.go b/x/ibc/light-clients/07-tendermint/types/tendermint.pb.go index f4b26ae3c03b..bd73065032b7 100644 --- a/x/ibc/light-clients/07-tendermint/types/tendermint.pb.go +++ b/x/ibc/light-clients/07-tendermint/types/tendermint.pb.go @@ -256,8 +256,8 @@ func (m *Header) GetTrustedValidators() *types3.ValidatorSet { // Fraction defines the protobuf message type for tmmath.Fraction type Fraction struct { - Numerator int64 `protobuf:"varint,1,opt,name=numerator,proto3" json:"numerator,omitempty"` - Denominator int64 `protobuf:"varint,2,opt,name=denominator,proto3" json:"denominator,omitempty"` + Numerator uint64 `protobuf:"varint,1,opt,name=numerator,proto3" json:"numerator,omitempty"` + Denominator uint64 `protobuf:"varint,2,opt,name=denominator,proto3" json:"denominator,omitempty"` } func (m *Fraction) Reset() { *m = Fraction{} } @@ -293,14 +293,14 @@ func (m *Fraction) XXX_DiscardUnknown() { var xxx_messageInfo_Fraction proto.InternalMessageInfo -func (m *Fraction) GetNumerator() int64 { +func (m *Fraction) GetNumerator() uint64 { if m != nil { return m.Numerator } return 0 } -func (m *Fraction) GetDenominator() int64 { +func (m *Fraction) GetDenominator() uint64 { if m != nil { return m.Denominator } @@ -386,13 +386,13 @@ var fileDescriptor_c6d6cf2b288949be = []byte{ 0x94, 0xd8, 0x07, 0x4a, 0x62, 0xdf, 0xd0, 0x9e, 0xbe, 0x59, 0xbe, 0xe5, 0x6d, 0x28, 0x87, 0x12, 0xd9, 0x18, 0x18, 0x25, 0xa2, 0x1a, 0x70, 0x75, 0x4a, 0x37, 0xed, 0xe2, 0xc1, 0xb4, 0x30, 0x77, 0xe6, 0x59, 0xaa, 0x1a, 0x96, 0xf7, 0x7f, 0xe5, 0xac, 0x46, 0xdd, 0xfa, 0x04, 0xd4, 0xcb, 0xe7, - 0xdf, 0xd8, 0x03, 0xeb, 0xe9, 0x28, 0x41, 0x39, 0x8f, 0x88, 0x93, 0x59, 0xf1, 0x2a, 0x87, 0xd1, + 0xdf, 0xd8, 0x03, 0xeb, 0xe9, 0x28, 0x41, 0x39, 0x8f, 0x88, 0x93, 0x59, 0xf5, 0x2a, 0x87, 0xd1, 0x01, 0x8d, 0x10, 0xa5, 0x24, 0xc1, 0xa9, 0x88, 0x2f, 0x8b, 0xb8, 0xee, 0x72, 0xbf, 0x79, 0x71, 0xd9, 0xae, 0x5d, 0x5c, 0xb6, 0x6b, 0x7f, 0x5d, 0xb6, 0x6b, 0xcf, 0xae, 0xda, 0x4b, 0x17, 0x57, 0xed, 0xa5, 0x3f, 0xae, 0xda, 0x4b, 0x5f, 0x1d, 0x6a, 0xd7, 0x32, 0x20, 0x34, 0x21, 0x54, 0xfd, 0x3d, 0xa2, 0xe1, 0x99, 0x33, 0xa9, 0xbe, 0x22, 0x1f, 0x95, 0x9f, 0x91, 0xef, 0xbe, 0xff, 0x68, - 0xf1, 0x3b, 0xaf, 0x7f, 0x4b, 0xa8, 0xd0, 0xe3, 0x7f, 0x02, 0x00, 0x00, 0xff, 0xff, 0x0e, 0x76, - 0x2d, 0x4a, 0x75, 0x0a, 0x00, 0x00, + 0xf1, 0x3b, 0xaf, 0x7f, 0x4b, 0xa8, 0xd0, 0xe3, 0x7f, 0x02, 0x00, 0x00, 0xff, 0xff, 0xb3, 0x43, + 0xab, 0xfe, 0x75, 0x0a, 0x00, 0x00, } func (m *ClientState) Marshal() (dAtA []byte, err error) { @@ -1889,7 +1889,7 @@ func (m *Fraction) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Numerator |= int64(b&0x7F) << shift + m.Numerator |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -1908,7 +1908,7 @@ func (m *Fraction) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Denominator |= int64(b&0x7F) << shift + m.Denominator |= uint64(b&0x7F) << shift if b < 0x80 { break }