From f65fe0a4d317c85db2a6701f0ec256cae3c4e79e Mon Sep 17 00:00:00 2001 From: Aditya Sripal Date: Thu, 6 May 2021 17:08:42 -0400 Subject: [PATCH 01/15] progress on blockdelay --- docs/ibc/proto-docs.md | 17 ++ go.mod | 1 - modules/core/02-client/keeper/params.go | 6 +- modules/core/02-client/types/params.go | 8 +- modules/core/03-connection/keeper/keeper.go | 10 +- modules/core/03-connection/keeper/params.go | 23 ++ .../core/03-connection/keeper/params_test.go | 17 ++ modules/core/03-connection/keeper/verify.go | 12 +- .../core/03-connection/types/connection.pb.go | 245 +++++++++++++++--- modules/core/03-connection/types/genesis.go | 4 +- .../core/03-connection/types/genesis.pb.go | 98 +++++-- .../core/03-connection/types/genesis_test.go | 6 + modules/core/03-connection/types/params.go | 52 ++++ .../07-tendermint/types/tendermint.pb.go | 4 +- proto/ibc/core/connection/v1/connection.proto | 6 + proto/ibc/core/connection/v1/genesis.proto | 1 + 16 files changed, 432 insertions(+), 78 deletions(-) create mode 100644 modules/core/03-connection/keeper/params.go create mode 100644 modules/core/03-connection/keeper/params_test.go create mode 100644 modules/core/03-connection/types/params.go diff --git a/docs/ibc/proto-docs.md b/docs/ibc/proto-docs.md index ecacd9f42dc..d52b6be9131 100644 --- a/docs/ibc/proto-docs.md +++ b/docs/ibc/proto-docs.md @@ -155,6 +155,7 @@ - [ConnectionPaths](#ibc.core.connection.v1.ConnectionPaths) - [Counterparty](#ibc.core.connection.v1.Counterparty) - [IdentifiedConnection](#ibc.core.connection.v1.IdentifiedConnection) + - [Params](#ibc.core.connection.v1.Params) - [Version](#ibc.core.connection.v1.Version) - [State](#ibc.core.connection.v1.State) @@ -2399,6 +2400,21 @@ identifier field. + + +### Params +Params defines the set of Connection parameters. + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `max_time_per_block` | [uint64](#uint64) | | maximum time expected per block, used to enforce block delay. | + + + + + + ### Version @@ -2458,6 +2474,7 @@ GenesisState defines the ibc connection submodule's genesis state. | `connections` | [IdentifiedConnection](#ibc.core.connection.v1.IdentifiedConnection) | repeated | | | `client_connection_paths` | [ConnectionPaths](#ibc.core.connection.v1.ConnectionPaths) | repeated | | | `next_connection_sequence` | [uint64](#uint64) | | the sequence for the next generated connection identifier | +| `params` | [Params](#ibc.core.connection.v1.Params) | | | diff --git a/go.mod b/go.mod index f1e91d76a21..b731eb4f2e9 100644 --- a/go.mod +++ b/go.mod @@ -22,5 +22,4 @@ require ( github.com/tendermint/tm-db v0.6.4 google.golang.org/genproto v0.0.0-20210114201628-6edceaf6022f google.golang.org/grpc v1.37.0 - google.golang.org/protobuf v1.26.0 ) diff --git a/modules/core/02-client/keeper/params.go b/modules/core/02-client/keeper/params.go index c9b88acd371..2addf95d0df 100644 --- a/modules/core/02-client/keeper/params.go +++ b/modules/core/02-client/keeper/params.go @@ -5,19 +5,19 @@ import ( "github.com/cosmos/ibc-go/modules/core/02-client/types" ) -// GetAllowedClients retrieves the receive enabled boolean from the paramstore +// GetAllowedClients retrieves the allowed clients from the paramstore func (k Keeper) GetAllowedClients(ctx sdk.Context) []string { var res []string k.paramSpace.Get(ctx, types.KeyAllowedClients, &res) return res } -// GetParams returns the total set of ibc-transfer parameters. +// GetParams returns the total set of ibc-client parameters. func (k Keeper) GetParams(ctx sdk.Context) types.Params { return types.NewParams(k.GetAllowedClients(ctx)...) } -// SetParams sets the total set of ibc-transfer parameters. +// SetParams sets the total set of ibc-client parameters. func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { k.paramSpace.SetParamSet(ctx, ¶ms) } diff --git a/modules/core/02-client/types/params.go b/modules/core/02-client/types/params.go index f9c50f15f1a..6460a3fcde5 100644 --- a/modules/core/02-client/types/params.go +++ b/modules/core/02-client/types/params.go @@ -4,8 +4,8 @@ import ( "fmt" "strings" - "github.com/cosmos/ibc-go/modules/core/exported" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + "github.com/cosmos/ibc-go/modules/core/exported" ) var ( @@ -21,19 +21,19 @@ func ParamKeyTable() paramtypes.KeyTable { return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) } -// NewParams creates a new parameter configuration for the ibc transfer module +// NewParams creates a new parameter configuration for the ibc client module func NewParams(allowedClients ...string) Params { return Params{ AllowedClients: allowedClients, } } -// DefaultParams is the default parameter configuration for the ibc-transfer module +// DefaultParams is the default parameter configuration for the ibc-client module func DefaultParams() Params { return NewParams(DefaultAllowedClients...) } -// Validate all ibc-transfer module parameters +// Validate all ibc-client module parameters func (p Params) Validate() error { return validateClients(p.AllowedClients) } diff --git a/modules/core/03-connection/keeper/keeper.go b/modules/core/03-connection/keeper/keeper.go index 49747b56704..3ce029168ac 100644 --- a/modules/core/03-connection/keeper/keeper.go +++ b/modules/core/03-connection/keeper/keeper.go @@ -6,6 +6,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" clienttypes "github.com/cosmos/ibc-go/modules/core/02-client/types" "github.com/cosmos/ibc-go/modules/core/03-connection/types" commitmenttypes "github.com/cosmos/ibc-go/modules/core/23-commitment/types" @@ -19,15 +20,22 @@ type Keeper struct { types.QueryServer storeKey sdk.StoreKey + paramSpace paramtypes.Subspace cdc codec.BinaryCodec clientKeeper types.ClientKeeper } // NewKeeper creates a new IBC connection Keeper instance -func NewKeeper(cdc codec.BinaryCodec, key sdk.StoreKey, ck types.ClientKeeper) Keeper { +func NewKeeper(cdc codec.BinaryCodec, key sdk.StoreKey, paramSpace paramtypes.Subspace, ck types.ClientKeeper) Keeper { + // set KeyTable if it has not already been set + if !paramSpace.HasKeyTable() { + paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable()) + } + return Keeper{ storeKey: key, cdc: cdc, + paramSpace: paramSpace, clientKeeper: ck, } } diff --git a/modules/core/03-connection/keeper/params.go b/modules/core/03-connection/keeper/params.go new file mode 100644 index 00000000000..63c14bd0e83 --- /dev/null +++ b/modules/core/03-connection/keeper/params.go @@ -0,0 +1,23 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/ibc-go/modules/core/03-connection/types" +) + +// GetMaxTimePerBlock retrieves the maximum time per block from the paramstore +func (k Keeper) GetMaxTimePerBlock(ctx sdk.Context) uint64 { + var res uint64 + k.paramSpace.Get(ctx, types.KeyMaxTimePerBlock, &res) + return res +} + +// GetParams returns the total set of ibc-connection parameters. +func (k Keeper) GetParams(ctx sdk.Context) types.Params { + return types.NewParams(k.GetMaxTimePerBlock(ctx)) +} + +// SetParams sets the total set of ibc-connection parameters. +func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { + k.paramSpace.SetParamSet(ctx, ¶ms) +} diff --git a/modules/core/03-connection/keeper/params_test.go b/modules/core/03-connection/keeper/params_test.go new file mode 100644 index 00000000000..4da8ae8cff9 --- /dev/null +++ b/modules/core/03-connection/keeper/params_test.go @@ -0,0 +1,17 @@ +package keeper_test + +import ( + "github.com/cosmos/ibc-go/modules/core/03-connection/types" +) + +func (suite *KeeperTestSuite) TestParams() { + expParams := types.DefaultParams() + + params := suite.chainA.App.GetIBCKeeper().ConnectionKeeper.GetParams(suite.chainA.GetContext()) + suite.Require().Equal(expParams, params) + + expParams.MaxTimePerBlock = 0 + suite.chainA.App.GetIBCKeeper().ConnectionKeeper.SetParams(suite.chainA.GetContext(), expParams) + params = suite.chainA.App.GetIBCKeeper().ConnectionKeeper.GetParams(suite.chainA.GetContext()) + suite.Require().Equal(0, expParams.MaxTimePerBlock) +} diff --git a/modules/core/03-connection/keeper/verify.go b/modules/core/03-connection/keeper/verify.go index 38722f98958..a6321442254 100644 --- a/modules/core/03-connection/keeper/verify.go +++ b/modules/core/03-connection/keeper/verify.go @@ -1,6 +1,8 @@ package keeper import ( + "math" + sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" clienttypes "github.com/cosmos/ibc-go/modules/core/02-client/types" @@ -159,9 +161,17 @@ func (k Keeper) VerifyPacketCommitment( return sdkerrors.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } + // calculate minimum block delay by dividing time delay period + // by the maximum expected time per block. Round up the block delay. + timeDelay := connection.GetDelayPeriod() + maxTimePerBlock := k.GetMaxTimePerBlock(ctx) + minBlocks := uint64(math.Ceil(float64(timeDelay) / float64(maxTimePerBlock))) + + // verify that block delay has passed + if err := clientState.VerifyPacketCommitment( clientStore, k.cdc, height, - uint64(ctx.BlockTime().UnixNano()), connection.GetDelayPeriod(), + uint64(ctx.BlockTime().UnixNano()), timeDelay, connection.GetCounterparty().GetPrefix(), proof, portID, channelID, sequence, commitmentBytes, ); err != nil { diff --git a/modules/core/03-connection/types/connection.pb.go b/modules/core/03-connection/types/connection.pb.go index 163897783e4..50e74664f50 100644 --- a/modules/core/03-connection/types/connection.pb.go +++ b/modules/core/03-connection/types/connection.pb.go @@ -354,6 +354,52 @@ func (m *Version) XXX_DiscardUnknown() { var xxx_messageInfo_Version proto.InternalMessageInfo +// Params defines the set of Connection parameters. +type Params struct { + // maximum time expected per block, used to enforce block delay. + MaxTimePerBlock uint64 `protobuf:"varint,1,opt,name=max_time_per_block,json=maxTimePerBlock,proto3" json:"max_time_per_block,omitempty" yaml:"max_time_per_block"` +} + +func (m *Params) Reset() { *m = Params{} } +func (m *Params) String() string { return proto.CompactTextString(m) } +func (*Params) ProtoMessage() {} +func (*Params) Descriptor() ([]byte, []int) { + return fileDescriptor_90572467c054e43a, []int{6} +} +func (m *Params) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Params.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Params) XXX_Merge(src proto.Message) { + xxx_messageInfo_Params.Merge(m, src) +} +func (m *Params) XXX_Size() int { + return m.Size() +} +func (m *Params) XXX_DiscardUnknown() { + xxx_messageInfo_Params.DiscardUnknown(m) +} + +var xxx_messageInfo_Params proto.InternalMessageInfo + +func (m *Params) GetMaxTimePerBlock() uint64 { + if m != nil { + return m.MaxTimePerBlock + } + return 0 +} + func init() { proto.RegisterEnum("ibc.core.connection.v1.State", State_name, State_value) proto.RegisterType((*ConnectionEnd)(nil), "ibc.core.connection.v1.ConnectionEnd") @@ -362,6 +408,7 @@ func init() { proto.RegisterType((*ClientPaths)(nil), "ibc.core.connection.v1.ClientPaths") proto.RegisterType((*ConnectionPaths)(nil), "ibc.core.connection.v1.ConnectionPaths") proto.RegisterType((*Version)(nil), "ibc.core.connection.v1.Version") + proto.RegisterType((*Params)(nil), "ibc.core.connection.v1.Params") } func init() { @@ -369,49 +416,52 @@ func init() { } var fileDescriptor_90572467c054e43a = []byte{ - // 658 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x54, 0x41, 0x6b, 0xdb, 0x4c, - 0x14, 0x94, 0x64, 0x39, 0xb1, 0xd7, 0xf1, 0xf7, 0xb9, 0x5b, 0xd3, 0x0a, 0x41, 0x24, 0xa1, 0x16, - 0x6a, 0x0a, 0xb1, 0xea, 0x04, 0x0a, 0x4d, 0xe9, 0x21, 0x76, 0x5c, 0x10, 0x6d, 0x5d, 0x23, 0x3b, - 0x85, 0xe6, 0x62, 0x6c, 0x69, 0xe3, 0x2c, 0xb5, 0xb5, 0x46, 0x5a, 0x9b, 0xfa, 0x1f, 0x84, 0x9c, - 0x7a, 0xed, 0x21, 0x50, 0xe8, 0x7f, 0x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f, 0x24, 0xbe, 0x81, 0x7b, 0xf6, 0x46, 0x9f, 0x18, 0x43, 0xe2, 0x8c, - 0x07, 0xc8, 0x67, 0xcf, 0xe9, 0x93, 0xad, 0x8d, 0xc4, 0x43, 0x4d, 0xa7, 0x23, 0xe4, 0xf7, 0x56, - 0xc2, 0xa7, 0x74, 0xeb, 0x77, 0x00, 0x00, 0x00, 0xff, 0xff, 0x7b, 0x1f, 0x87, 0x8e, 0xcc, 0x05, - 0x00, 0x00, + // 707 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x54, 0xcd, 0x6e, 0xda, 0x4c, + 0x14, 0xc5, 0xc6, 0x10, 0x18, 0xc2, 0x17, 0xbe, 0x29, 0x6a, 0x5d, 0xa4, 0xd8, 0x96, 0x5b, 0xa9, + 0xa8, 0x52, 0xa0, 0x24, 0x52, 0xa5, 0xa6, 0xea, 0x22, 0x10, 0x2a, 0xb9, 0x3f, 0x14, 0x19, 0x52, + 0xa9, 0xd9, 0x20, 0x63, 0x4f, 0xc8, 0x28, 0xd8, 0x83, 0xec, 0x01, 0x85, 0x37, 0x88, 0xb2, 0xea, + 0xb6, 0x8b, 0x48, 0x95, 0xfa, 0x2e, 0x55, 0xd4, 0x55, 0x96, 0x5d, 0xa1, 0x2a, 0xd9, 0x76, 0xc5, + 0x13, 0x54, 0xf6, 0x80, 0x71, 0xd2, 0x66, 0x91, 0xb4, 0xbb, 0x7b, 0xe6, 0x9e, 0x73, 0x98, 0x7b, + 0xb8, 0x1e, 0xf0, 0x08, 0x77, 0xcd, 0xb2, 0x49, 0x5c, 0x54, 0x36, 0x89, 0xe3, 0x20, 0x93, 0x62, + 0xe2, 0x94, 0x47, 0x95, 0x08, 0x2a, 0x0d, 0x5c, 0x42, 0x09, 0xbc, 0x8b, 0xbb, 0x66, 0xc9, 0x27, + 0x96, 0x22, 0xad, 0x51, 0xa5, 0x90, 0xef, 0x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 0x79, 0xfe, 0xe9, 0x78, 0x80, 0xbc, + 0x6e, 0x32, 0x78, 0xa0, 0x37, 0x7e, 0x05, 0x00, 0x00, 0xff, 0xff, 0x9e, 0x3f, 0x99, 0x65, 0x22, + 0x06, 0x00, 0x00, } func (m *ConnectionEnd) Marshal() (dAtA []byte, err error) { @@ -706,6 +756,34 @@ func (m *Version) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *Params) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Params) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.MaxTimePerBlock != 0 { + i = encodeVarintConnection(dAtA, i, uint64(m.MaxTimePerBlock)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + func encodeVarintConnection(dAtA []byte, offset int, v uint64) int { offset -= sovConnection(v) base := offset @@ -847,6 +925,18 @@ func (m *Version) Size() (n int) { return n } +func (m *Params) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.MaxTimePerBlock != 0 { + n += 1 + sovConnection(uint64(m.MaxTimePerBlock)) + } + return n +} + func sovConnection(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -1716,6 +1806,75 @@ func (m *Version) Unmarshal(dAtA []byte) error { } return nil } +func (m *Params) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowConnection + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Params: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MaxTimePerBlock", wireType) + } + m.MaxTimePerBlock = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowConnection + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MaxTimePerBlock |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipConnection(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthConnection + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipConnection(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/modules/core/03-connection/types/genesis.go b/modules/core/03-connection/types/genesis.go index 8eb441c5235..aa6671979c6 100644 --- a/modules/core/03-connection/types/genesis.go +++ b/modules/core/03-connection/types/genesis.go @@ -17,12 +17,13 @@ func NewConnectionPaths(id string, paths []string) ConnectionPaths { // NewGenesisState creates a GenesisState instance. func NewGenesisState( connections []IdentifiedConnection, connPaths []ConnectionPaths, - nextConnectionSequence uint64, + nextConnectionSequence uint64, params Params, ) GenesisState { return GenesisState{ Connections: connections, ClientConnectionPaths: connPaths, NextConnectionSequence: nextConnectionSequence, + Params: params, } } @@ -32,6 +33,7 @@ func DefaultGenesisState() GenesisState { Connections: []IdentifiedConnection{}, ClientConnectionPaths: []ConnectionPaths{}, NextConnectionSequence: 0, + Params: DefaultParams(), } } diff --git a/modules/core/03-connection/types/genesis.pb.go b/modules/core/03-connection/types/genesis.pb.go index c538d3e3536..2efa4395200 100644 --- a/modules/core/03-connection/types/genesis.pb.go +++ b/modules/core/03-connection/types/genesis.pb.go @@ -29,6 +29,7 @@ type GenesisState struct { ClientConnectionPaths []ConnectionPaths `protobuf:"bytes,2,rep,name=client_connection_paths,json=clientConnectionPaths,proto3" json:"client_connection_paths" yaml:"client_connection_paths"` // the sequence for the next generated connection identifier NextConnectionSequence uint64 `protobuf:"varint,3,opt,name=next_connection_sequence,json=nextConnectionSequence,proto3" json:"next_connection_sequence,omitempty" yaml:"next_connection_sequence"` + Params Params `protobuf:"bytes,4,opt,name=params,proto3" json:"params"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -85,6 +86,13 @@ func (m *GenesisState) GetNextConnectionSequence() uint64 { return 0 } +func (m *GenesisState) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + func init() { proto.RegisterType((*GenesisState)(nil), "ibc.core.connection.v1.GenesisState") } @@ -94,28 +102,29 @@ func init() { } var fileDescriptor_1879d34bc6ac3cd7 = []byte{ - // 327 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x91, 0x31, 0x4f, 0xc2, 0x40, - 0x18, 0x86, 0x5b, 0x20, 0x0e, 0xc5, 0xa9, 0x51, 0x6c, 0x18, 0xae, 0xa4, 0x1a, 0x61, 0x90, 0x3b, - 0x91, 0x49, 0xc7, 0x3a, 0x18, 0x37, 0x03, 0x4e, 0x26, 0x86, 0xd0, 0xe3, 0xb3, 0x5c, 0x42, 0xef, - 0x43, 0xee, 0x20, 0xf2, 0x0b, 0x5c, 0xfd, 0x59, 0x2c, 0x26, 0x8c, 0x4e, 0xc4, 0xc0, 0x3f, 0xe0, - 0x17, 0x98, 0xb6, 0xc6, 0xa2, 0xb1, 0xdb, 0xe5, 0xbe, 0xe7, 0x7d, 0xde, 0xe1, 0xb5, 0x4e, 0x44, - 0xc0, 0x19, 0xc7, 0x09,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3, 0x6d, 0x43, 0x8c, 0xe5, 0x86, 0x18, 0x1f, - 0x1b, 0x62, 0x3c, 0x5c, 0x86, 0x42, 0x0f, 0xa7, 0x01, 0xe5, 0x18, 0x31, 0x8e, 0x2a, 0x42, 0xc5, - 0x44, 0xc0, 0x9b, 0x21, 0xb2, 0x08, 0x07, 0xd3, 0x11, 0xa8, 0x74, 0xaf, 0xf3, 0x76, 0x73, 0x67, - 0x32, 0x3d, 0x1f, 0x83, 0x0a, 0xf6, 0x92, 0xad, 0xda, 0x5f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x85, - 0x66, 0x6f, 0x29, 0x2a, 0x02, 0x00, 0x00, + // 352 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x91, 0xb1, 0x4e, 0xc2, 0x40, + 0x18, 0xc7, 0x5b, 0x21, 0x0c, 0xc5, 0xa9, 0x51, 0x6c, 0x18, 0xae, 0xa4, 0x1a, 0x61, 0x90, 0x3b, + 0x81, 0x49, 0xe3, 0x54, 0x07, 0xe3, 0x46, 0xc0, 0xc9, 0xc4, 0x90, 0xf6, 0xf8, 0x2c, 0x97, 0xd0, + 0xbb, 0xca, 0x1d, 0x44, 0x9e, 0xc0, 0xc1, 0xc5, 0xc7, 0x62, 0x64, 0x74, 0x22, 0x06, 0xde, 0x80, + 0x27, 0x30, 0x6d, 0x89, 0x45, 0x63, 0xb7, 0xe6, 0xfb, 0x7e, 0xff, 0xdf, 0x3f, 0xbd, 0xcf, 0x38, + 0x63, 0x3e, 0x25, 0x54, 0x4c, 0x80, 0x50, 0xc1, 0x39, 0x50, 0xc5, 0x04, 0x27, 0xb3, 0x16, 0x09, + 0x80, 0x83, 0x64, 0x12, 0x47, 0x13, 0xa1, 0x84, 0x59, 0x61, 0x3e, 0xc5, 0x31, 0x85, 0x33, 0x0a, + 0xcf, 0x5a, 0xd5, 0xa3, 0x40, 0x04, 0x22, 0x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0, 0xd4, 0x68, + 0xea, 0x63, 0x2a, 0x42, 0x42, 0x85, 0x0c, 0x85, 0x24, 0xcc, 0xa7, 0xcd, 0x40, 0x90, 0x50, 0x0c, + 0xa7, 0x63, 0x90, 0xe9, 0xb5, 0x2f, 0x3b, 0xcd, 0xbd, 0x83, 0xab, 0x79, 0x04, 0xd2, 0x2f, 0x25, + 0x97, 0xee, 0x7c, 0x07, 0x00, 0x00, 0xff, 0xff, 0x5a, 0x52, 0xa6, 0xc4, 0x68, 0x02, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -138,6 +147,16 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 if m.NextConnectionSequence != 0 { i = encodeVarintGenesis(dAtA, i, uint64(m.NextConnectionSequence)) i-- @@ -206,6 +225,8 @@ func (m *GenesisState) Size() (n int) { if m.NextConnectionSequence != 0 { n += 1 + sovGenesis(uint64(m.NextConnectionSequence)) } + l = m.Params.Size() + n += 1 + l + sovGenesis(uint64(l)) return n } @@ -331,6 +352,39 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { break } } + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipGenesis(dAtA[iNdEx:]) diff --git a/modules/core/03-connection/types/genesis_test.go b/modules/core/03-connection/types/genesis_test.go index 562890ddd15..8f38a8324be 100644 --- a/modules/core/03-connection/types/genesis_test.go +++ b/modules/core/03-connection/types/genesis_test.go @@ -32,6 +32,7 @@ func TestValidateGenesis(t *testing.T) { {clientID, []string{connectionID}}, }, 0, + types.DefaultParams(), ), expPass: true, }, @@ -45,6 +46,7 @@ func TestValidateGenesis(t *testing.T) { {clientID, []string{connectionID}}, }, 0, + types.DefaultParams(), ), expPass: false, }, @@ -58,6 +60,7 @@ func TestValidateGenesis(t *testing.T) { {"(CLIENTIDONE)", []string{connectionID}}, }, 0, + types.DefaultParams(), ), expPass: false, }, @@ -71,6 +74,7 @@ func TestValidateGenesis(t *testing.T) { {clientID, []string{invalidConnectionID}}, }, 0, + types.DefaultParams(), ), expPass: false, }, @@ -84,6 +88,7 @@ func TestValidateGenesis(t *testing.T) { {clientID, []string{connectionID}}, }, 0, + types.DefaultParams(), ), expPass: false, }, @@ -97,6 +102,7 @@ func TestValidateGenesis(t *testing.T) { {clientID, []string{connectionID}}, }, 0, + types.DefaultParams(), ), expPass: false, }, diff --git a/modules/core/03-connection/types/params.go b/modules/core/03-connection/types/params.go new file mode 100644 index 00000000000..6716b7590b4 --- /dev/null +++ b/modules/core/03-connection/types/params.go @@ -0,0 +1,52 @@ +package types + +import ( + "fmt" + "time" + + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" +) + +// DefaultTimePerBlock is the default value for maximum time +// expected per block. +const DefaultTimePerBlock = 10 * time.Minute + +// KeyMaxTimePerBlock is store's key for MaxTimePerBlock parameter +var KeyMaxTimePerBlock = []byte("MaxTimePerBlock") + +// ParamKeyTable type declaration for parameters +func ParamKeyTable() paramtypes.KeyTable { + return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) +} + +// NewParams creates a new parameter configuration for the ibc connection module +func NewParams(timePerBlock uint64) Params { + return Params{ + MaxTimePerBlock: timePerBlock, + } +} + +// DefaultParams is the default parameter configuration for the ibc connection module +func DefaultParams() Params { + return NewParams(uint64(DefaultTimePerBlock)) +} + +// Validate is a no-op for connection parameters +func (p Params) Validate() error { + return nil +} + +// ParamSetPairs implements params.ParamSet +func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { + return paramtypes.ParamSetPairs{ + paramtypes.NewParamSetPair(KeyMaxTimePerBlock, p.MaxTimePerBlock, validateParams), + } +} + +func validateParams(i interface{}) error { + _, ok := i.(uint64) + if !ok { + return fmt.Errorf("invalid parameter. expected %T, got type: %T", uint64(1), i) + } + return nil +} diff --git a/modules/light-clients/07-tendermint/types/tendermint.pb.go b/modules/light-clients/07-tendermint/types/tendermint.pb.go index 9a0645a4462..84a79b66668 100644 --- a/modules/light-clients/07-tendermint/types/tendermint.pb.go +++ b/modules/light-clients/07-tendermint/types/tendermint.pb.go @@ -11,10 +11,10 @@ import ( _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" + _ "github.com/golang/protobuf/ptypes/duration" + _ "github.com/golang/protobuf/ptypes/timestamp" github_com_tendermint_tendermint_libs_bytes "github.com/tendermint/tendermint/libs/bytes" types2 "github.com/tendermint/tendermint/proto/tendermint/types" - _ "google.golang.org/protobuf/types/known/durationpb" - _ "google.golang.org/protobuf/types/known/timestamppb" io "io" math "math" math_bits "math/bits" diff --git a/proto/ibc/core/connection/v1/connection.proto b/proto/ibc/core/connection/v1/connection.proto index 5b4e32bf856..300f943e00e 100644 --- a/proto/ibc/core/connection/v1/connection.proto +++ b/proto/ibc/core/connection/v1/connection.proto @@ -104,3 +104,9 @@ message Version { // list of features compatible with the specified identifier repeated string features = 2; } + +// Params defines the set of Connection parameters. +message Params { + // maximum time expected per block, used to enforce block delay. + uint64 max_time_per_block = 1 [(gogoproto.moretags) = "yaml:\"max_time_per_block\""]; +} diff --git a/proto/ibc/core/connection/v1/genesis.proto b/proto/ibc/core/connection/v1/genesis.proto index 62296e1e6dd..64f2e026aca 100644 --- a/proto/ibc/core/connection/v1/genesis.proto +++ b/proto/ibc/core/connection/v1/genesis.proto @@ -14,4 +14,5 @@ message GenesisState { [(gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"client_connection_paths\""]; // the sequence for the next generated connection identifier uint64 next_connection_sequence = 3 [(gogoproto.moretags) = "yaml:\"next_connection_sequence\""]; + Params params = 4 [(gogoproto.nullable) = false]; } From 6d98abdf99da17c49d9d901a17ee178ecd33c78e Mon Sep 17 00:00:00 2001 From: Aditya Sripal Date: Tue, 11 May 2021 17:26:42 -0400 Subject: [PATCH 02/15] complete block delay param --- modules/core/03-connection/keeper/verify.go | 36 +++++++++++---- modules/core/03-connection/types/params.go | 7 ++- .../core/03-connection/types/params_test.go | 29 ++++++++++++ modules/core/exported/client.go | 16 +++++-- modules/core/keeper/keeper.go | 4 +- .../06-solomachine/types/client_state.go | 8 ++++ .../07-tendermint/types/client_state.go | 43 ++++++++++++----- .../07-tendermint/types/errors.go | 25 +++++----- .../07-tendermint/types/store.go | 46 +++++++++++++++++-- .../07-tendermint/types/update.go | 4 +- .../09-localhost/types/client_state.go | 8 ++++ 11 files changed, 181 insertions(+), 45 deletions(-) create mode 100644 modules/core/03-connection/types/params_test.go diff --git a/modules/core/03-connection/keeper/verify.go b/modules/core/03-connection/keeper/verify.go index a6321442254..db19a94f3e4 100644 --- a/modules/core/03-connection/keeper/verify.go +++ b/modules/core/03-connection/keeper/verify.go @@ -165,13 +165,13 @@ func (k Keeper) VerifyPacketCommitment( // by the maximum expected time per block. Round up the block delay. timeDelay := connection.GetDelayPeriod() maxTimePerBlock := k.GetMaxTimePerBlock(ctx) - minBlocks := uint64(math.Ceil(float64(timeDelay) / float64(maxTimePerBlock))) + blockDelay := uint64(math.Ceil(float64(timeDelay) / float64(maxTimePerBlock))) // verify that block delay has passed if err := clientState.VerifyPacketCommitment( - clientStore, k.cdc, height, - uint64(ctx.BlockTime().UnixNano()), timeDelay, + clientStore, k.cdc, height, clienttypes.GetSelfHeight(ctx), + uint64(ctx.BlockTime().UnixNano()), timeDelay, blockDelay, connection.GetCounterparty().GetPrefix(), proof, portID, channelID, sequence, commitmentBytes, ); err != nil { @@ -205,9 +205,15 @@ func (k Keeper) VerifyPacketAcknowledgement( return sdkerrors.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } + // calculate minimum block delay by dividing time delay period + // by the maximum expected time per block. Round up the block delay. + timeDelay := connection.GetDelayPeriod() + maxTimePerBlock := k.GetMaxTimePerBlock(ctx) + blockDelay := uint64(math.Ceil(float64(timeDelay) / float64(maxTimePerBlock))) + if err := clientState.VerifyPacketAcknowledgement( - clientStore, k.cdc, height, - uint64(ctx.BlockTime().UnixNano()), connection.GetDelayPeriod(), + clientStore, k.cdc, height, clienttypes.GetSelfHeight(ctx), + uint64(ctx.BlockTime().UnixNano()), timeDelay, blockDelay, connection.GetCounterparty().GetPrefix(), proof, portID, channelID, sequence, acknowledgement, ); err != nil { @@ -241,9 +247,15 @@ func (k Keeper) VerifyPacketReceiptAbsence( return sdkerrors.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } + // calculate minimum block delay by dividing time delay period + // by the maximum expected time per block. Round up the block delay. + timeDelay := connection.GetDelayPeriod() + maxTimePerBlock := k.GetMaxTimePerBlock(ctx) + blockDelay := uint64(math.Ceil(float64(timeDelay) / float64(maxTimePerBlock))) + if err := clientState.VerifyPacketReceiptAbsence( - clientStore, k.cdc, height, - uint64(ctx.BlockTime().UnixNano()), connection.GetDelayPeriod(), + clientStore, k.cdc, height, clienttypes.GetSelfHeight(ctx), + uint64(ctx.BlockTime().UnixNano()), timeDelay, blockDelay, connection.GetCounterparty().GetPrefix(), proof, portID, channelID, sequence, ); err != nil { @@ -276,9 +288,15 @@ func (k Keeper) VerifyNextSequenceRecv( return sdkerrors.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } + // calculate minimum block delay by dividing time delay period + // by the maximum expected time per block. Round up the block delay. + timeDelay := connection.GetDelayPeriod() + maxTimePerBlock := k.GetMaxTimePerBlock(ctx) + blockDelay := uint64(math.Ceil(float64(timeDelay) / float64(maxTimePerBlock))) + if err := clientState.VerifyNextSequenceRecv( - clientStore, k.cdc, height, - uint64(ctx.BlockTime().UnixNano()), connection.GetDelayPeriod(), + clientStore, k.cdc, height, clienttypes.GetSelfHeight(ctx), + uint64(ctx.BlockTime().UnixNano()), timeDelay, blockDelay, connection.GetCounterparty().GetPrefix(), proof, portID, channelID, nextSequenceRecv, ); err != nil { diff --git a/modules/core/03-connection/types/params.go b/modules/core/03-connection/types/params.go index 6716b7590b4..b3676ca8ce0 100644 --- a/modules/core/03-connection/types/params.go +++ b/modules/core/03-connection/types/params.go @@ -9,7 +9,7 @@ import ( // DefaultTimePerBlock is the default value for maximum time // expected per block. -const DefaultTimePerBlock = 10 * time.Minute +const DefaultTimePerBlock = time.Hour // KeyMaxTimePerBlock is store's key for MaxTimePerBlock parameter var KeyMaxTimePerBlock = []byte("MaxTimePerBlock") @@ -31,8 +31,11 @@ func DefaultParams() Params { return NewParams(uint64(DefaultTimePerBlock)) } -// Validate is a no-op for connection parameters +// Validate ensures MaxTimePerBlock is non-zero func (p Params) Validate() error { + if p.MaxTimePerBlock == 0 { + return fmt.Errorf("MaxTimePerBlock cannot be zero") + } return nil } diff --git a/modules/core/03-connection/types/params_test.go b/modules/core/03-connection/types/params_test.go new file mode 100644 index 00000000000..0a04ed34a4b --- /dev/null +++ b/modules/core/03-connection/types/params_test.go @@ -0,0 +1,29 @@ +package types_test + +import ( + "testing" + + "github.com/cosmos/ibc-go/modules/core/03-connection/types" + "github.com/stretchr/testify/require" +) + +func TestValidateParams(t *testing.T) { + testCases := []struct { + name string + params types.Params + expPass bool + }{ + {"default params", types.DefaultParams(), true}, + {"custom params", types.NewParams(10), true}, + {"blank client", types.NewParams(0), false}, + } + + for _, tc := range testCases { + err := tc.params.Validate() + if tc.expPass { + require.NoError(t, err, tc.name) + } else { + require.Error(t, err, tc.name) + } + } +} diff --git a/modules/core/exported/client.go b/modules/core/exported/client.go index b79106c174a..f4e72d2c19c 100644 --- a/modules/core/exported/client.go +++ b/modules/core/exported/client.go @@ -130,8 +130,10 @@ type ClientState interface { store sdk.KVStore, cdc codec.BinaryCodec, height Height, + currentHeight Height, currentTimestamp uint64, - delayPeriod uint64, + delayTimePeriod uint64, + delayBlockPeriod uint64, prefix Prefix, proof []byte, portID, @@ -143,8 +145,10 @@ type ClientState interface { store sdk.KVStore, cdc codec.BinaryCodec, height Height, + currentHeight Height, currentTimestamp uint64, - delayPeriod uint64, + delayTimePeriod uint64, + delayBlockPeriod uint64, prefix Prefix, proof []byte, portID, @@ -156,8 +160,10 @@ type ClientState interface { store sdk.KVStore, cdc codec.BinaryCodec, height Height, + currentHeight Height, currentTimestamp uint64, - delayPeriod uint64, + delayTimePeriod uint64, + delayBlockPeriod uint64, prefix Prefix, proof []byte, portID, @@ -168,8 +174,10 @@ type ClientState interface { store sdk.KVStore, cdc codec.BinaryCodec, height Height, + currentHeight Height, currentTimestamp uint64, - delayPeriod uint64, + delayTimePeriod uint64, + delayBlockPeriod uint64, prefix Prefix, proof []byte, portID, diff --git a/modules/core/keeper/keeper.go b/modules/core/keeper/keeper.go index 0320bb467ee..441ce9bc0e5 100644 --- a/modules/core/keeper/keeper.go +++ b/modules/core/keeper/keeper.go @@ -4,6 +4,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" clientkeeper "github.com/cosmos/ibc-go/modules/core/02-client/keeper" clienttypes "github.com/cosmos/ibc-go/modules/core/02-client/types" connectionkeeper "github.com/cosmos/ibc-go/modules/core/03-connection/keeper" @@ -11,7 +12,6 @@ import ( portkeeper "github.com/cosmos/ibc-go/modules/core/05-port/keeper" porttypes "github.com/cosmos/ibc-go/modules/core/05-port/types" "github.com/cosmos/ibc-go/modules/core/types" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" ) var _ types.QueryServer = (*Keeper)(nil) @@ -37,7 +37,7 @@ func NewKeeper( scopedKeeper capabilitykeeper.ScopedKeeper, ) *Keeper { clientKeeper := clientkeeper.NewKeeper(cdc, key, paramSpace, stakingKeeper, upgradeKeeper) - connectionKeeper := connectionkeeper.NewKeeper(cdc, key, clientKeeper) + connectionKeeper := connectionkeeper.NewKeeper(cdc, key, paramSpace, clientKeeper) portKeeper := portkeeper.NewKeeper(scopedKeeper) channelKeeper := channelkeeper.NewKeeper(cdc, key, clientKeeper, connectionKeeper, portKeeper, scopedKeeper) diff --git a/modules/light-clients/06-solomachine/types/client_state.go b/modules/light-clients/06-solomachine/types/client_state.go index 7ce5fa1fade..a1b1a3af85e 100644 --- a/modules/light-clients/06-solomachine/types/client_state.go +++ b/modules/light-clients/06-solomachine/types/client_state.go @@ -266,6 +266,8 @@ func (cs *ClientState) VerifyPacketCommitment( store sdk.KVStore, cdc codec.BinaryCodec, height exported.Height, + _ exported.Height, + _ uint64, _ uint64, _ uint64, prefix exported.Prefix, @@ -307,6 +309,8 @@ func (cs *ClientState) VerifyPacketAcknowledgement( store sdk.KVStore, cdc codec.BinaryCodec, height exported.Height, + _ exported.Height, + _ uint64, _ uint64, _ uint64, prefix exported.Prefix, @@ -349,6 +353,8 @@ func (cs *ClientState) VerifyPacketReceiptAbsence( store sdk.KVStore, cdc codec.BinaryCodec, height exported.Height, + _ exported.Height, + _ uint64, _ uint64, _ uint64, prefix exported.Prefix, @@ -389,6 +395,8 @@ func (cs *ClientState) VerifyNextSequenceRecv( store sdk.KVStore, cdc codec.BinaryCodec, height exported.Height, + _ exported.Height, + _ uint64, _ uint64, _ uint64, prefix exported.Prefix, diff --git a/modules/light-clients/07-tendermint/types/client_state.go b/modules/light-clients/07-tendermint/types/client_state.go index 00d919aeaeb..7355d80d581 100644 --- a/modules/light-clients/07-tendermint/types/client_state.go +++ b/modules/light-clients/07-tendermint/types/client_state.go @@ -350,8 +350,10 @@ func (cs ClientState) VerifyPacketCommitment( store sdk.KVStore, cdc codec.BinaryCodec, height exported.Height, + currentHeight exported.Height, currentTimestamp uint64, - delayPeriod uint64, + delayTimePeriod uint64, + delayBlockPeriod uint64, prefix exported.Prefix, proof []byte, portID, @@ -365,7 +367,7 @@ func (cs ClientState) VerifyPacketCommitment( } // check delay period has passed - if err := verifyDelayPeriodPassed(store, height, currentTimestamp, delayPeriod); err != nil { + if err := verifyDelayPeriodPassed(store, height, currentHeight, currentTimestamp, delayTimePeriod, delayBlockPeriod); err != nil { return err } @@ -388,8 +390,10 @@ func (cs ClientState) VerifyPacketAcknowledgement( store sdk.KVStore, cdc codec.BinaryCodec, height exported.Height, + currentHeight exported.Height, currentTimestamp uint64, - delayPeriod uint64, + delayTimePeriod uint64, + delayBlockPeriod uint64, prefix exported.Prefix, proof []byte, portID, @@ -403,7 +407,7 @@ func (cs ClientState) VerifyPacketAcknowledgement( } // check delay period has passed - if err := verifyDelayPeriodPassed(store, height, currentTimestamp, delayPeriod); err != nil { + if err := verifyDelayPeriodPassed(store, height, currentHeight, currentTimestamp, delayTimePeriod, delayBlockPeriod); err != nil { return err } @@ -427,8 +431,10 @@ func (cs ClientState) VerifyPacketReceiptAbsence( store sdk.KVStore, cdc codec.BinaryCodec, height exported.Height, + currentHeight exported.Height, currentTimestamp uint64, - delayPeriod uint64, + delayTimePeriod uint64, + delayBlockPeriod uint64, prefix exported.Prefix, proof []byte, portID, @@ -441,7 +447,7 @@ func (cs ClientState) VerifyPacketReceiptAbsence( } // check delay period has passed - if err := verifyDelayPeriodPassed(store, height, currentTimestamp, delayPeriod); err != nil { + if err := verifyDelayPeriodPassed(store, height, currentHeight, currentTimestamp, delayTimePeriod, delayBlockPeriod); err != nil { return err } @@ -464,8 +470,10 @@ func (cs ClientState) VerifyNextSequenceRecv( store sdk.KVStore, cdc codec.BinaryCodec, height exported.Height, + currentHeight exported.Height, currentTimestamp uint64, - delayPeriod uint64, + delayTimePeriod uint64, + delayBlockPeriod uint64, prefix exported.Prefix, proof []byte, portID, @@ -478,7 +486,7 @@ func (cs ClientState) VerifyNextSequenceRecv( } // check delay period has passed - if err := verifyDelayPeriodPassed(store, height, currentTimestamp, delayPeriod); err != nil { + if err := verifyDelayPeriodPassed(store, height, currentHeight, currentTimestamp, delayTimePeriod, delayBlockPeriod); err != nil { return err } @@ -499,18 +507,29 @@ func (cs ClientState) VerifyNextSequenceRecv( // verifyDelayPeriodPassed will ensure that at least delayPeriod amount of time has passed since consensus state was submitted // before allowing verification to continue. -func verifyDelayPeriodPassed(store sdk.KVStore, proofHeight exported.Height, currentTimestamp, delayPeriod uint64) error { - // check that executing chain's timestamp has passed consensusState's processed time + delay period +func verifyDelayPeriodPassed(store sdk.KVStore, proofHeight, currentHeight exported.Height, currentTimestamp, delayTimePeriod, delayBlockPeriod uint64) error { + // check that executing chain's timestamp has passed consensusState's processed time + delay time period processedTime, ok := GetProcessedTime(store, proofHeight) if !ok { return sdkerrors.Wrapf(ErrProcessedTimeNotFound, "processed time not found for height: %s", proofHeight) } - validTime := processedTime + delayPeriod - // NOTE: delay period is inclusive, so if currentTimestamp is validTime, then we return no error + validTime := processedTime + delayTimePeriod + // NOTE: delay time period is inclusive, so if currentTimestamp is validTime, then we return no error if validTime > currentTimestamp { return sdkerrors.Wrapf(ErrDelayPeriodNotPassed, "cannot verify packet until time: %d, current time: %d", validTime, currentTimestamp) } + // check that executing chain's height has passed consensusState's processed height + delay block period + processedHeight, ok := GetProcessedHeight(store, proofHeight) + if !ok { + return sdkerrors.Wrapf(ErrProcessedHeightNotFound, "processed height not found for height: %s", proofHeight) + } + validHeight := clienttypes.NewHeight(processedHeight.GetRevisionNumber(), processedHeight.GetRevisionHeight()+delayBlockPeriod) + // NOTE: delay block period is inclusive, so if currentHeight is validHeight, then we return no error + if currentHeight.LT(validHeight) { + return sdkerrors.Wrapf(ErrDelayPeriodNotPassed, "cannot verify packet until height: %s, current height: %s", + validHeight, currentHeight) + } return nil } diff --git a/modules/light-clients/07-tendermint/types/errors.go b/modules/light-clients/07-tendermint/types/errors.go index 276c225b736..7b087e41af5 100644 --- a/modules/light-clients/07-tendermint/types/errors.go +++ b/modules/light-clients/07-tendermint/types/errors.go @@ -10,16 +10,17 @@ const ( // IBC tendermint client sentinel errors var ( - ErrInvalidChainID = sdkerrors.Register(SubModuleName, 2, "invalid chain-id") - ErrInvalidTrustingPeriod = sdkerrors.Register(SubModuleName, 3, "invalid trusting period") - ErrInvalidUnbondingPeriod = sdkerrors.Register(SubModuleName, 4, "invalid unbonding period") - ErrInvalidHeaderHeight = sdkerrors.Register(SubModuleName, 5, "invalid header height") - ErrInvalidHeader = sdkerrors.Register(SubModuleName, 6, "invalid header") - ErrInvalidMaxClockDrift = sdkerrors.Register(SubModuleName, 7, "invalid max clock drift") - ErrProcessedTimeNotFound = sdkerrors.Register(SubModuleName, 8, "processed time not found") - ErrDelayPeriodNotPassed = sdkerrors.Register(SubModuleName, 9, "packet-specified delay period has not been reached") - ErrTrustingPeriodExpired = sdkerrors.Register(SubModuleName, 10, "time since latest trusted state has passed the trusting period") - ErrUnbondingPeriodExpired = sdkerrors.Register(SubModuleName, 11, "time since latest trusted state has passed the unbonding period") - ErrInvalidProofSpecs = sdkerrors.Register(SubModuleName, 12, "invalid proof specs") - ErrInvalidValidatorSet = sdkerrors.Register(SubModuleName, 13, "invalid validator set") + ErrInvalidChainID = sdkerrors.Register(SubModuleName, 2, "invalid chain-id") + ErrInvalidTrustingPeriod = sdkerrors.Register(SubModuleName, 3, "invalid trusting period") + ErrInvalidUnbondingPeriod = sdkerrors.Register(SubModuleName, 4, "invalid unbonding period") + ErrInvalidHeaderHeight = sdkerrors.Register(SubModuleName, 5, "invalid header height") + ErrInvalidHeader = sdkerrors.Register(SubModuleName, 6, "invalid header") + ErrInvalidMaxClockDrift = sdkerrors.Register(SubModuleName, 7, "invalid max clock drift") + ErrProcessedTimeNotFound = sdkerrors.Register(SubModuleName, 8, "processed time not found") + ErrProcessedHeightNotFound = sdkerrors.Register(SubModuleName, 9, "processed height not found") + ErrDelayPeriodNotPassed = sdkerrors.Register(SubModuleName, 10, "packet-specified delay period has not been reached") + ErrTrustingPeriodExpired = sdkerrors.Register(SubModuleName, 11, "time since latest trusted state has passed the trusting period") + ErrUnbondingPeriodExpired = sdkerrors.Register(SubModuleName, 12, "time since latest trusted state has passed the unbonding period") + ErrInvalidProofSpecs = sdkerrors.Register(SubModuleName, 13, "invalid proof specs") + ErrInvalidValidatorSet = sdkerrors.Register(SubModuleName, 14, "invalid validator set") ) diff --git a/modules/light-clients/07-tendermint/types/store.go b/modules/light-clients/07-tendermint/types/store.go index 68793621547..c305325fa16 100644 --- a/modules/light-clients/07-tendermint/types/store.go +++ b/modules/light-clients/07-tendermint/types/store.go @@ -35,7 +35,10 @@ const KeyIterateConsensusStatePrefix = "iterateConsensusStates" var ( // KeyProcessedTime is appended to consensus state key to store the processed time KeyProcessedTime = []byte("/processedTime") - KeyIteration = []byte("/iterationKey") + // KeyProcessedHeight is appended to consensus state key to store the processed height + KeyProcessedHeight = []byte("/processedHeight") + // KeyIteration stores the key mapping to consensus state key for efficient iteration + KeyIteration = []byte("/iterationKey") ) // SetConsensusState stores the consensus state at the given height. @@ -106,7 +109,7 @@ func ProcessedTimeKey(height exported.Height) []byte { } // SetProcessedTime stores the time at which a header was processed and the corresponding consensus state was created. -// This is useful when validating whether a packet has reached the specified delay period in the tendermint client's +// This is useful when validating whether a packet has reached the time specified delay period in the tendermint client's // verification functions func SetProcessedTime(clientStore sdk.KVStore, height exported.Height, timeNs uint64) { key := ProcessedTimeKey(height) @@ -115,7 +118,7 @@ func SetProcessedTime(clientStore sdk.KVStore, height exported.Height, timeNs ui } // GetProcessedTime gets the time (in nanoseconds) at which this chain received and processed a tendermint header. -// This is used to validate that a received packet has passed the delay period. +// This is used to validate that a received packet has passed the time delay period. func GetProcessedTime(clientStore sdk.KVStore, height exported.Height) (uint64, bool) { key := ProcessedTimeKey(height) bz := clientStore.Get(key) @@ -131,6 +134,43 @@ func deleteProcessedTime(clientStore sdk.KVStore, height exported.Height) { clientStore.Delete(key) } +// ProcessedHeight Store code + +// ProcessedHeightKey returns the key under which the processed height will be stored in the client store. +func ProcessedHeightKey(height exported.Height) []byte { + return append(host.ConsensusStateKey(height), KeyProcessedHeight...) +} + +// SetProcessedHeight stores the height at which a header was processed and the corresponding consensus state was created. +// This is useful when validating whether a packet has reached the specified block delay period in the tendermint client's +// verification functions +func SetProcessedHeight(clientStore sdk.KVStore, consHeight, processedHeight exported.Height) { + key := ProcessedHeightKey(consHeight) + val := []byte(processedHeight.String()) + clientStore.Set(key, val) +} + +// GetProcessedHeight gets the height at which this chain received and processed a tendermint header. +// This is used to validate that a received packet has passed the block delay period. +func GetProcessedHeight(clientStore sdk.KVStore, height exported.Height) (exported.Height, bool) { + key := ProcessedHeightKey(height) + bz := clientStore.Get(key) + if bz == nil { + return nil, false + } + processedHeight, err := clienttypes.ParseHeight(string(bz)) + if err != nil { + return nil, false + } + return processedHeight, true +} + +// deleteProcessedHeight deletes the processedHeight for a given height +func deleteProcessedHeight(clientStore sdk.KVStore, height exported.Height) { + key := ProcessedHeightKey(height) + clientStore.Delete(key) +} + // Iteration Code // IterationKey returns the key under which the consensus state key will be stored. diff --git a/modules/light-clients/07-tendermint/types/update.go b/modules/light-clients/07-tendermint/types/update.go index bfabb324d7c..53ba47c90a4 100644 --- a/modules/light-clients/07-tendermint/types/update.go +++ b/modules/light-clients/07-tendermint/types/update.go @@ -212,10 +212,12 @@ func update(ctx sdk.Context, clientStore sdk.KVStore, clientState *ClientState, NextValidatorsHash: header.Header.NextValidatorsHash, } - // set context time as processed time as this is state internal to tendermint client logic. + // set context time as processed time and set context height as processed height + // as this is internal tendermint light client logic. // client state and consensus state will be set by client keeper // set iteration key to provide ability for efficient ordered iteration of consensus states. SetProcessedTime(clientStore, header.GetHeight(), uint64(ctx.BlockTime().UnixNano())) + SetProcessedHeight(clientStore, header.GetHeight(), clienttypes.GetSelfHeight(ctx)) SetIterationKey(clientStore, header.GetHeight()) return clientState, consensusState diff --git a/modules/light-clients/09-localhost/types/client_state.go b/modules/light-clients/09-localhost/types/client_state.go index 67da74d9c27..0fceebd07dd 100644 --- a/modules/light-clients/09-localhost/types/client_state.go +++ b/modules/light-clients/09-localhost/types/client_state.go @@ -231,6 +231,8 @@ func (cs ClientState) VerifyPacketCommitment( store sdk.KVStore, _ codec.BinaryCodec, _ exported.Height, + _ exported.Height, + _ uint64, _ uint64, _ uint64, _ exported.Prefix, @@ -263,6 +265,8 @@ func (cs ClientState) VerifyPacketAcknowledgement( store sdk.KVStore, _ codec.BinaryCodec, _ exported.Height, + _ exported.Height, + _ uint64, _ uint64, _ uint64, _ exported.Prefix, @@ -296,6 +300,8 @@ func (cs ClientState) VerifyPacketReceiptAbsence( store sdk.KVStore, _ codec.BinaryCodec, _ exported.Height, + _ exported.Height, + _ uint64, _ uint64, _ uint64, _ exported.Prefix, @@ -320,6 +326,8 @@ func (cs ClientState) VerifyNextSequenceRecv( store sdk.KVStore, _ codec.BinaryCodec, _ exported.Height, + _ exported.Height, + _ uint64, _ uint64, _ uint64, _ exported.Prefix, From d827dd0828163e9feab395fd56b8188b53c2759c Mon Sep 17 00:00:00 2001 From: Aditya Sripal Date: Wed, 12 May 2021 16:34:38 -0400 Subject: [PATCH 03/15] address most comments --- modules/core/03-connection/keeper/verify.go | 18 +++++------ modules/core/exported/client.go | 12 +++----- .../06-solomachine/types/client_state.go | 12 +++----- .../07-tendermint/types/client_state.go | 30 +++++++++---------- .../07-tendermint/types/store.go | 6 ---- .../09-localhost/types/client_state.go | 12 +++----- 6 files changed, 34 insertions(+), 56 deletions(-) diff --git a/modules/core/03-connection/keeper/verify.go b/modules/core/03-connection/keeper/verify.go index db19a94f3e4..329b0c74aa5 100644 --- a/modules/core/03-connection/keeper/verify.go +++ b/modules/core/03-connection/keeper/verify.go @@ -167,11 +167,9 @@ func (k Keeper) VerifyPacketCommitment( maxTimePerBlock := k.GetMaxTimePerBlock(ctx) blockDelay := uint64(math.Ceil(float64(timeDelay) / float64(maxTimePerBlock))) - // verify that block delay has passed - if err := clientState.VerifyPacketCommitment( - clientStore, k.cdc, height, clienttypes.GetSelfHeight(ctx), - uint64(ctx.BlockTime().UnixNano()), timeDelay, blockDelay, + ctx, clientStore, k.cdc, height, + timeDelay, blockDelay, connection.GetCounterparty().GetPrefix(), proof, portID, channelID, sequence, commitmentBytes, ); err != nil { @@ -212,8 +210,8 @@ func (k Keeper) VerifyPacketAcknowledgement( blockDelay := uint64(math.Ceil(float64(timeDelay) / float64(maxTimePerBlock))) if err := clientState.VerifyPacketAcknowledgement( - clientStore, k.cdc, height, clienttypes.GetSelfHeight(ctx), - uint64(ctx.BlockTime().UnixNano()), timeDelay, blockDelay, + ctx, clientStore, k.cdc, height, + timeDelay, blockDelay, connection.GetCounterparty().GetPrefix(), proof, portID, channelID, sequence, acknowledgement, ); err != nil { @@ -254,8 +252,8 @@ func (k Keeper) VerifyPacketReceiptAbsence( blockDelay := uint64(math.Ceil(float64(timeDelay) / float64(maxTimePerBlock))) if err := clientState.VerifyPacketReceiptAbsence( - clientStore, k.cdc, height, clienttypes.GetSelfHeight(ctx), - uint64(ctx.BlockTime().UnixNano()), timeDelay, blockDelay, + ctx, clientStore, k.cdc, height, + timeDelay, blockDelay, connection.GetCounterparty().GetPrefix(), proof, portID, channelID, sequence, ); err != nil { @@ -295,8 +293,8 @@ func (k Keeper) VerifyNextSequenceRecv( blockDelay := uint64(math.Ceil(float64(timeDelay) / float64(maxTimePerBlock))) if err := clientState.VerifyNextSequenceRecv( - clientStore, k.cdc, height, clienttypes.GetSelfHeight(ctx), - uint64(ctx.BlockTime().UnixNano()), timeDelay, blockDelay, + ctx, clientStore, k.cdc, height, + timeDelay, blockDelay, connection.GetCounterparty().GetPrefix(), proof, portID, channelID, nextSequenceRecv, ); err != nil { diff --git a/modules/core/exported/client.go b/modules/core/exported/client.go index f4e72d2c19c..8592057cbe5 100644 --- a/modules/core/exported/client.go +++ b/modules/core/exported/client.go @@ -127,11 +127,10 @@ type ClientState interface { channel ChannelI, ) error VerifyPacketCommitment( + ctx sdk.Context, store sdk.KVStore, cdc codec.BinaryCodec, height Height, - currentHeight Height, - currentTimestamp uint64, delayTimePeriod uint64, delayBlockPeriod uint64, prefix Prefix, @@ -142,11 +141,10 @@ type ClientState interface { commitmentBytes []byte, ) error VerifyPacketAcknowledgement( + ctx sdk.Context, store sdk.KVStore, cdc codec.BinaryCodec, height Height, - currentHeight Height, - currentTimestamp uint64, delayTimePeriod uint64, delayBlockPeriod uint64, prefix Prefix, @@ -157,11 +155,10 @@ type ClientState interface { acknowledgement []byte, ) error VerifyPacketReceiptAbsence( + ctx sdk.Context, store sdk.KVStore, cdc codec.BinaryCodec, height Height, - currentHeight Height, - currentTimestamp uint64, delayTimePeriod uint64, delayBlockPeriod uint64, prefix Prefix, @@ -171,11 +168,10 @@ type ClientState interface { sequence uint64, ) error VerifyNextSequenceRecv( + ctx sdk.Context, store sdk.KVStore, cdc codec.BinaryCodec, height Height, - currentHeight Height, - currentTimestamp uint64, delayTimePeriod uint64, delayBlockPeriod uint64, prefix Prefix, diff --git a/modules/light-clients/06-solomachine/types/client_state.go b/modules/light-clients/06-solomachine/types/client_state.go index a1b1a3af85e..36e24349230 100644 --- a/modules/light-clients/06-solomachine/types/client_state.go +++ b/modules/light-clients/06-solomachine/types/client_state.go @@ -263,11 +263,10 @@ func (cs *ClientState) VerifyChannelState( // VerifyPacketCommitment verifies a proof of an outgoing packet commitment at // the specified port, specified channel, and specified sequence. func (cs *ClientState) VerifyPacketCommitment( + ctx sdk.Context, store sdk.KVStore, cdc codec.BinaryCodec, height exported.Height, - _ exported.Height, - _ uint64, _ uint64, _ uint64, prefix exported.Prefix, @@ -306,11 +305,10 @@ func (cs *ClientState) VerifyPacketCommitment( // VerifyPacketAcknowledgement verifies a proof of an incoming packet // acknowledgement at the specified port, specified channel, and specified sequence. func (cs *ClientState) VerifyPacketAcknowledgement( + ctx sdk.Context, store sdk.KVStore, cdc codec.BinaryCodec, height exported.Height, - _ exported.Height, - _ uint64, _ uint64, _ uint64, prefix exported.Prefix, @@ -350,11 +348,10 @@ func (cs *ClientState) VerifyPacketAcknowledgement( // incoming packet receipt at the specified port, specified channel, and // specified sequence. func (cs *ClientState) VerifyPacketReceiptAbsence( + ctx sdk.Context, store sdk.KVStore, cdc codec.BinaryCodec, height exported.Height, - _ exported.Height, - _ uint64, _ uint64, _ uint64, prefix exported.Prefix, @@ -392,11 +389,10 @@ func (cs *ClientState) VerifyPacketReceiptAbsence( // VerifyNextSequenceRecv verifies a proof of the next sequence number to be // received of the specified channel at the specified port. func (cs *ClientState) VerifyNextSequenceRecv( + ctx sdk.Context, store sdk.KVStore, cdc codec.BinaryCodec, height exported.Height, - _ exported.Height, - _ uint64, _ uint64, _ uint64, prefix exported.Prefix, diff --git a/modules/light-clients/07-tendermint/types/client_state.go b/modules/light-clients/07-tendermint/types/client_state.go index 7355d80d581..3eb36e303c9 100644 --- a/modules/light-clients/07-tendermint/types/client_state.go +++ b/modules/light-clients/07-tendermint/types/client_state.go @@ -347,11 +347,10 @@ func (cs ClientState) VerifyChannelState( // VerifyPacketCommitment verifies a proof of an outgoing packet commitment at // the specified port, specified channel, and specified sequence. func (cs ClientState) VerifyPacketCommitment( + ctx sdk.Context, store sdk.KVStore, cdc codec.BinaryCodec, height exported.Height, - currentHeight exported.Height, - currentTimestamp uint64, delayTimePeriod uint64, delayBlockPeriod uint64, prefix exported.Prefix, @@ -367,7 +366,7 @@ func (cs ClientState) VerifyPacketCommitment( } // check delay period has passed - if err := verifyDelayPeriodPassed(store, height, currentHeight, currentTimestamp, delayTimePeriod, delayBlockPeriod); err != nil { + if err := verifyDelayPeriodPassed(ctx, store, height, delayTimePeriod, delayBlockPeriod); err != nil { return err } @@ -387,11 +386,10 @@ func (cs ClientState) VerifyPacketCommitment( // VerifyPacketAcknowledgement verifies a proof of an incoming packet // acknowledgement at the specified port, specified channel, and specified sequence. func (cs ClientState) VerifyPacketAcknowledgement( + ctx sdk.Context, store sdk.KVStore, cdc codec.BinaryCodec, height exported.Height, - currentHeight exported.Height, - currentTimestamp uint64, delayTimePeriod uint64, delayBlockPeriod uint64, prefix exported.Prefix, @@ -407,7 +405,7 @@ func (cs ClientState) VerifyPacketAcknowledgement( } // check delay period has passed - if err := verifyDelayPeriodPassed(store, height, currentHeight, currentTimestamp, delayTimePeriod, delayBlockPeriod); err != nil { + if err := verifyDelayPeriodPassed(ctx, store, height, delayTimePeriod, delayBlockPeriod); err != nil { return err } @@ -428,11 +426,10 @@ func (cs ClientState) VerifyPacketAcknowledgement( // incoming packet receipt at the specified port, specified channel, and // specified sequence. func (cs ClientState) VerifyPacketReceiptAbsence( + ctx sdk.Context, store sdk.KVStore, cdc codec.BinaryCodec, height exported.Height, - currentHeight exported.Height, - currentTimestamp uint64, delayTimePeriod uint64, delayBlockPeriod uint64, prefix exported.Prefix, @@ -447,7 +444,7 @@ func (cs ClientState) VerifyPacketReceiptAbsence( } // check delay period has passed - if err := verifyDelayPeriodPassed(store, height, currentHeight, currentTimestamp, delayTimePeriod, delayBlockPeriod); err != nil { + if err := verifyDelayPeriodPassed(ctx, store, height, delayTimePeriod, delayBlockPeriod); err != nil { return err } @@ -467,11 +464,10 @@ func (cs ClientState) VerifyPacketReceiptAbsence( // VerifyNextSequenceRecv verifies a proof of the next sequence number to be // received of the specified channel at the specified port. func (cs ClientState) VerifyNextSequenceRecv( + ctx sdk.Context, store sdk.KVStore, cdc codec.BinaryCodec, height exported.Height, - currentHeight exported.Height, - currentTimestamp uint64, delayTimePeriod uint64, delayBlockPeriod uint64, prefix exported.Prefix, @@ -486,7 +482,7 @@ func (cs ClientState) VerifyNextSequenceRecv( } // check delay period has passed - if err := verifyDelayPeriodPassed(store, height, currentHeight, currentTimestamp, delayTimePeriod, delayBlockPeriod); err != nil { + if err := verifyDelayPeriodPassed(ctx, store, height, delayTimePeriod, delayBlockPeriod); err != nil { return err } @@ -505,17 +501,18 @@ func (cs ClientState) VerifyNextSequenceRecv( return nil } -// verifyDelayPeriodPassed will ensure that at least delayPeriod amount of time has passed since consensus state was submitted -// before allowing verification to continue. -func verifyDelayPeriodPassed(store sdk.KVStore, proofHeight, currentHeight exported.Height, currentTimestamp, delayTimePeriod, delayBlockPeriod uint64) error { +// verifyDelayPeriodPassed will ensure that at least delayTimePeriod amount of time and delayBlockPerion number of blocks have passed +// since consensus state was submitted before allowing verification to continue. +func verifyDelayPeriodPassed(ctx sdk.Context, store sdk.KVStore, proofHeight exported.Height, delayTimePeriod, delayBlockPeriod uint64) error { // check that executing chain's timestamp has passed consensusState's processed time + delay time period processedTime, ok := GetProcessedTime(store, proofHeight) if !ok { return sdkerrors.Wrapf(ErrProcessedTimeNotFound, "processed time not found for height: %s", proofHeight) } + currentTimestamp := uint64(ctx.BlockTime().UnixNano()) validTime := processedTime + delayTimePeriod // NOTE: delay time period is inclusive, so if currentTimestamp is validTime, then we return no error - if validTime > currentTimestamp { + if currentTimestamp < validTime { return sdkerrors.Wrapf(ErrDelayPeriodNotPassed, "cannot verify packet until time: %d, current time: %d", validTime, currentTimestamp) } @@ -524,6 +521,7 @@ func verifyDelayPeriodPassed(store sdk.KVStore, proofHeight, currentHeight expor if !ok { return sdkerrors.Wrapf(ErrProcessedHeightNotFound, "processed height not found for height: %s", proofHeight) } + currentHeight := clienttypes.GetSelfHeight(ctx) validHeight := clienttypes.NewHeight(processedHeight.GetRevisionNumber(), processedHeight.GetRevisionHeight()+delayBlockPeriod) // NOTE: delay block period is inclusive, so if currentHeight is validHeight, then we return no error if currentHeight.LT(validHeight) { diff --git a/modules/light-clients/07-tendermint/types/store.go b/modules/light-clients/07-tendermint/types/store.go index c305325fa16..36459c30be9 100644 --- a/modules/light-clients/07-tendermint/types/store.go +++ b/modules/light-clients/07-tendermint/types/store.go @@ -101,8 +101,6 @@ func IterateProcessedTime(store sdk.KVStore, cb func(key, val []byte) bool) { } } -// ProcessedTime Store code - // ProcessedTimeKey returns the key under which the processed time will be stored in the client store. func ProcessedTimeKey(height exported.Height) []byte { return append(host.ConsensusStateKey(height), KeyProcessedTime...) @@ -134,8 +132,6 @@ func deleteProcessedTime(clientStore sdk.KVStore, height exported.Height) { clientStore.Delete(key) } -// ProcessedHeight Store code - // ProcessedHeightKey returns the key under which the processed height will be stored in the client store. func ProcessedHeightKey(height exported.Height) []byte { return append(host.ConsensusStateKey(height), KeyProcessedHeight...) @@ -171,8 +167,6 @@ func deleteProcessedHeight(clientStore sdk.KVStore, height exported.Height) { clientStore.Delete(key) } -// Iteration Code - // IterationKey returns the key under which the consensus state key will be stored. // The iteration key is a BigEndian representation of the consensus state key to support efficient iteration. func IterationKey(height exported.Height) []byte { diff --git a/modules/light-clients/09-localhost/types/client_state.go b/modules/light-clients/09-localhost/types/client_state.go index 0fceebd07dd..e428c0fc62b 100644 --- a/modules/light-clients/09-localhost/types/client_state.go +++ b/modules/light-clients/09-localhost/types/client_state.go @@ -228,11 +228,10 @@ func (cs ClientState) VerifyChannelState( // VerifyPacketCommitment verifies a proof of an outgoing packet commitment at // the specified port, specified channel, and specified sequence. func (cs ClientState) VerifyPacketCommitment( + ctx sdk.Context, store sdk.KVStore, _ codec.BinaryCodec, _ exported.Height, - _ exported.Height, - _ uint64, _ uint64, _ uint64, _ exported.Prefix, @@ -262,11 +261,10 @@ func (cs ClientState) VerifyPacketCommitment( // VerifyPacketAcknowledgement verifies a proof of an incoming packet // acknowledgement at the specified port, specified channel, and specified sequence. func (cs ClientState) VerifyPacketAcknowledgement( + ctx sdk.Context, store sdk.KVStore, _ codec.BinaryCodec, _ exported.Height, - _ exported.Height, - _ uint64, _ uint64, _ uint64, _ exported.Prefix, @@ -297,11 +295,10 @@ func (cs ClientState) VerifyPacketAcknowledgement( // incoming packet receipt at the specified port, specified channel, and // specified sequence. func (cs ClientState) VerifyPacketReceiptAbsence( + ctx sdk.Context, store sdk.KVStore, _ codec.BinaryCodec, _ exported.Height, - _ exported.Height, - _ uint64, _ uint64, _ uint64, _ exported.Prefix, @@ -323,11 +320,10 @@ func (cs ClientState) VerifyPacketReceiptAbsence( // VerifyNextSequenceRecv verifies a proof of the next sequence number to be // received of the specified channel at the specified port. func (cs ClientState) VerifyNextSequenceRecv( + ctx sdk.Context, store sdk.KVStore, _ codec.BinaryCodec, _ exported.Height, - _ exported.Height, - _ uint64, _ uint64, _ uint64, _ exported.Prefix, From 20a0803100be792c374f2fe32e13055802fbd9eb Mon Sep 17 00:00:00 2001 From: Aditya Sripal Date: Wed, 12 May 2021 16:43:56 -0400 Subject: [PATCH 04/15] address the rest --- .../core/03-connection/keeper/params_test.go | 4 +-- modules/core/03-connection/keeper/verify.go | 34 ++++++++++--------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/modules/core/03-connection/keeper/params_test.go b/modules/core/03-connection/keeper/params_test.go index 4da8ae8cff9..f444f98df61 100644 --- a/modules/core/03-connection/keeper/params_test.go +++ b/modules/core/03-connection/keeper/params_test.go @@ -10,8 +10,8 @@ func (suite *KeeperTestSuite) TestParams() { params := suite.chainA.App.GetIBCKeeper().ConnectionKeeper.GetParams(suite.chainA.GetContext()) suite.Require().Equal(expParams, params) - expParams.MaxTimePerBlock = 0 + expParams.MaxTimePerBlock = 10 suite.chainA.App.GetIBCKeeper().ConnectionKeeper.SetParams(suite.chainA.GetContext(), expParams) params = suite.chainA.App.GetIBCKeeper().ConnectionKeeper.GetParams(suite.chainA.GetContext()) - suite.Require().Equal(0, expParams.MaxTimePerBlock) + suite.Require().Equal(10, expParams.MaxTimePerBlock) } diff --git a/modules/core/03-connection/keeper/verify.go b/modules/core/03-connection/keeper/verify.go index 329b0c74aa5..c2f9868f31d 100644 --- a/modules/core/03-connection/keeper/verify.go +++ b/modules/core/03-connection/keeper/verify.go @@ -161,11 +161,9 @@ func (k Keeper) VerifyPacketCommitment( return sdkerrors.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } - // calculate minimum block delay by dividing time delay period - // by the maximum expected time per block. Round up the block delay. + // get time and block delays timeDelay := connection.GetDelayPeriod() - maxTimePerBlock := k.GetMaxTimePerBlock(ctx) - blockDelay := uint64(math.Ceil(float64(timeDelay) / float64(maxTimePerBlock))) + blockDelay := k.getBlockDelay(ctx, connection) if err := clientState.VerifyPacketCommitment( ctx, clientStore, k.cdc, height, @@ -203,11 +201,9 @@ func (k Keeper) VerifyPacketAcknowledgement( return sdkerrors.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } - // calculate minimum block delay by dividing time delay period - // by the maximum expected time per block. Round up the block delay. + // get time and block delays timeDelay := connection.GetDelayPeriod() - maxTimePerBlock := k.GetMaxTimePerBlock(ctx) - blockDelay := uint64(math.Ceil(float64(timeDelay) / float64(maxTimePerBlock))) + blockDelay := k.getBlockDelay(ctx, connection) if err := clientState.VerifyPacketAcknowledgement( ctx, clientStore, k.cdc, height, @@ -245,11 +241,9 @@ func (k Keeper) VerifyPacketReceiptAbsence( return sdkerrors.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } - // calculate minimum block delay by dividing time delay period - // by the maximum expected time per block. Round up the block delay. + // get time and block delays timeDelay := connection.GetDelayPeriod() - maxTimePerBlock := k.GetMaxTimePerBlock(ctx) - blockDelay := uint64(math.Ceil(float64(timeDelay) / float64(maxTimePerBlock))) + blockDelay := k.getBlockDelay(ctx, connection) if err := clientState.VerifyPacketReceiptAbsence( ctx, clientStore, k.cdc, height, @@ -286,11 +280,9 @@ func (k Keeper) VerifyNextSequenceRecv( return sdkerrors.Wrapf(clienttypes.ErrClientNotActive, "client (%s) status is %s", clientID, status) } - // calculate minimum block delay by dividing time delay period - // by the maximum expected time per block. Round up the block delay. + // get time and block delays timeDelay := connection.GetDelayPeriod() - maxTimePerBlock := k.GetMaxTimePerBlock(ctx) - blockDelay := uint64(math.Ceil(float64(timeDelay) / float64(maxTimePerBlock))) + blockDelay := k.getBlockDelay(ctx, connection) if err := clientState.VerifyNextSequenceRecv( ctx, clientStore, k.cdc, height, @@ -303,3 +295,13 @@ func (k Keeper) VerifyNextSequenceRecv( return nil } + +// getBlockDelay calculates the block delay period from the time delay of the connection +// and the maximum expected time per block. +func (k Keeper) getBlockDelay(ctx sdk.Context, connection exported.ConnectionI) uint64 { + // calculate minimum block delay by dividing time delay period + // by the maximum expected time per block. Round up the block delay. + timeDelay := connection.GetDelayPeriod() + maxTimePerBlock := k.GetMaxTimePerBlock(ctx) + return uint64(math.Ceil(float64(timeDelay) / float64(maxTimePerBlock))) +} From 6f6fd833d636759acc74a1e107d68320e12a97d8 Mon Sep 17 00:00:00 2001 From: Aditya Date: Sat, 15 May 2021 15:28:45 -0400 Subject: [PATCH 05/15] Update modules/light-clients/07-tendermint/types/client_state.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> --- modules/light-clients/07-tendermint/types/client_state.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/light-clients/07-tendermint/types/client_state.go b/modules/light-clients/07-tendermint/types/client_state.go index 3eb36e303c9..bc34047c413 100644 --- a/modules/light-clients/07-tendermint/types/client_state.go +++ b/modules/light-clients/07-tendermint/types/client_state.go @@ -501,7 +501,7 @@ func (cs ClientState) VerifyNextSequenceRecv( return nil } -// verifyDelayPeriodPassed will ensure that at least delayTimePeriod amount of time and delayBlockPerion number of blocks have passed +// verifyDelayPeriodPassed will ensure that at least delayTimePeriod amount of time and delayBlockPeriod number of blocks have passed // since consensus state was submitted before allowing verification to continue. func verifyDelayPeriodPassed(ctx sdk.Context, store sdk.KVStore, proofHeight exported.Height, delayTimePeriod, delayBlockPeriod uint64) error { // check that executing chain's timestamp has passed consensusState's processed time + delay time period From aeca52d11cb39ea01581a3e06015472140650dda Mon Sep 17 00:00:00 2001 From: Aditya Sripal Date: Mon, 17 May 2021 16:00:17 -0400 Subject: [PATCH 06/15] fix tm tests --- modules/core/03-connection/genesis.go | 1 + modules/core/keeper/keeper.go | 9 + .../07-tendermint/types/client_state_test.go | 172 +++++++++++++----- .../07-tendermint/types/tendermint_test.go | 2 +- 4 files changed, 135 insertions(+), 49 deletions(-) diff --git a/modules/core/03-connection/genesis.go b/modules/core/03-connection/genesis.go index ca2d9e7e90b..af46c8ba694 100644 --- a/modules/core/03-connection/genesis.go +++ b/modules/core/03-connection/genesis.go @@ -17,6 +17,7 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, gs types.GenesisState) { k.SetClientConnectionPaths(ctx, connPaths.ClientId, connPaths.Paths) } k.SetNextConnectionSequence(ctx, gs.NextConnectionSequence) + k.SetParams(ctx, gs.Params) } // ExportGenesis returns the ibc connection submodule's exported genesis. diff --git a/modules/core/keeper/keeper.go b/modules/core/keeper/keeper.go index 441ce9bc0e5..164fecfcd23 100644 --- a/modules/core/keeper/keeper.go +++ b/modules/core/keeper/keeper.go @@ -8,6 +8,7 @@ import ( clientkeeper "github.com/cosmos/ibc-go/modules/core/02-client/keeper" clienttypes "github.com/cosmos/ibc-go/modules/core/02-client/types" connectionkeeper "github.com/cosmos/ibc-go/modules/core/03-connection/keeper" + connectiontypes "github.com/cosmos/ibc-go/modules/core/03-connection/types" channelkeeper "github.com/cosmos/ibc-go/modules/core/04-channel/keeper" portkeeper "github.com/cosmos/ibc-go/modules/core/05-port/keeper" porttypes "github.com/cosmos/ibc-go/modules/core/05-port/types" @@ -36,6 +37,14 @@ func NewKeeper( stakingKeeper clienttypes.StakingKeeper, upgradeKeeper clienttypes.UpgradeKeeper, scopedKeeper capabilitykeeper.ScopedKeeper, ) *Keeper { + // register paramSpace at top level keeper + // set KeyTable if it has not already been set + if !paramSpace.HasKeyTable() { + keyTable := clienttypes.ParamKeyTable() + keyTable.RegisterParamSet(&connectiontypes.Params{}) + paramSpace = paramSpace.WithKeyTable(keyTable) + } + clientKeeper := clientkeeper.NewKeeper(cdc, key, paramSpace, stakingKeeper, upgradeKeeper) connectionKeeper := connectionkeeper.NewKeeper(cdc, key, paramSpace, clientKeeper) portKeeper := portkeeper.NewKeeper(scopedKeeper) diff --git a/modules/light-clients/07-tendermint/types/client_state_test.go b/modules/light-clients/07-tendermint/types/client_state_test.go index e6b62ddc76a..93125c04268 100644 --- a/modules/light-clients/07-tendermint/types/client_state_test.go +++ b/modules/light-clients/07-tendermint/types/client_state_test.go @@ -400,11 +400,12 @@ func (suite *TendermintTestSuite) TestVerifyChannelState() { // in the light client on chainA. A send from chainB to chainA is simulated. func (suite *TendermintTestSuite) TestVerifyPacketCommitment() { var ( - clientState *types.ClientState - proof []byte - delayPeriod uint64 - proofHeight exported.Height - prefix commitmenttypes.MerklePrefix + clientState *types.ClientState + proof []byte + delayTimePeriod uint64 + delayBlockPeriod uint64 + proofHeight exported.Height + prefix commitmenttypes.MerklePrefix ) testCases := []struct { @@ -416,19 +417,34 @@ func (suite *TendermintTestSuite) TestVerifyPacketCommitment() { "successful verification", func() {}, true, }, { - name: "delay period has passed", + name: "delay time period has passed", + malleate: func() { + delayTimePeriod = uint64(time.Second.Nanoseconds()) + }, + expPass: true, + }, + { + name: "delay time period has not passed", + malleate: func() { + delayTimePeriod = uint64(time.Hour.Nanoseconds()) + }, + expPass: false, + }, + { + name: "delay block period has passed", malleate: func() { - delayPeriod = uint64(time.Second.Nanoseconds()) + delayBlockPeriod = 1 }, expPass: true, }, { - name: "delay period has not passed", + name: "delay block period has not passed", malleate: func() { - delayPeriod = uint64(time.Hour.Nanoseconds()) + delayBlockPeriod = 1000 }, expPass: false, }, + { "ApplyPrefix failed", func() { prefix = commitmenttypes.MerklePrefix{} @@ -470,14 +486,17 @@ func (suite *TendermintTestSuite) TestVerifyPacketCommitment() { packetKey := host.PacketCommitmentKey(packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence()) proof, proofHeight = path.EndpointB.QueryProof(packetKey) + // reset time and block delays to 0, malleate may change to a specific non-zero value. + delayTimePeriod = 0 + delayBlockPeriod = 0 tc.malleate() // make changes as necessary - store := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), path.EndpointA.ClientID) + ctx := suite.chainA.GetContext() + store := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(ctx, path.EndpointA.ClientID) - currentTime := uint64(suite.chainA.GetContext().BlockTime().UnixNano()) commitment := channeltypes.CommitPacket(suite.chainA.App.GetIBCKeeper().Codec(), packet) err = clientState.VerifyPacketCommitment( - store, suite.chainA.Codec, proofHeight, currentTime, delayPeriod, &prefix, proof, + ctx, store, suite.chainA.Codec, proofHeight, delayTimePeriod, delayBlockPeriod, &prefix, proof, packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence(), commitment, ) @@ -495,11 +514,12 @@ func (suite *TendermintTestSuite) TestVerifyPacketCommitment() { // is simulated. func (suite *TendermintTestSuite) TestVerifyPacketAcknowledgement() { var ( - clientState *types.ClientState - proof []byte - delayPeriod uint64 - proofHeight exported.Height - prefix commitmenttypes.MerklePrefix + clientState *types.ClientState + proof []byte + delayTimePeriod uint64 + delayBlockPeriod uint64 + proofHeight exported.Height + prefix commitmenttypes.MerklePrefix ) testCases := []struct { @@ -511,19 +531,34 @@ func (suite *TendermintTestSuite) TestVerifyPacketAcknowledgement() { "successful verification", func() {}, true, }, { - name: "delay period has passed", + name: "delay time period has passed", + malleate: func() { + delayTimePeriod = uint64(time.Second.Nanoseconds()) + }, + expPass: true, + }, + { + name: "delay time period has not passed", + malleate: func() { + delayTimePeriod = uint64(time.Hour.Nanoseconds()) + }, + expPass: false, + }, + { + name: "delay block period has passed", malleate: func() { - delayPeriod = uint64(time.Second.Nanoseconds()) + delayBlockPeriod = 1 }, expPass: true, }, { - name: "delay period has not passed", + name: "delay block period has not passed", malleate: func() { - delayPeriod = uint64(time.Hour.Nanoseconds()) + delayBlockPeriod = 10 }, expPass: false, }, + { "ApplyPrefix failed", func() { prefix = commitmenttypes.MerklePrefix{} @@ -571,13 +606,16 @@ func (suite *TendermintTestSuite) TestVerifyPacketAcknowledgement() { acknowledgementKey := host.PacketAcknowledgementKey(packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence()) proof, proofHeight = suite.chainB.QueryProof(acknowledgementKey) + // reset time and block delays to 0, malleate may change to a specific non-zero value. + delayTimePeriod = 0 + delayBlockPeriod = 0 tc.malleate() // make changes as necessary - store := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), path.EndpointA.ClientID) + ctx := suite.chainA.GetContext() + store := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(ctx, path.EndpointA.ClientID) - currentTime := uint64(suite.chainA.GetContext().BlockTime().UnixNano()) err = clientState.VerifyPacketAcknowledgement( - store, suite.chainA.Codec, proofHeight, currentTime, delayPeriod, &prefix, proof, + ctx, store, suite.chainA.Codec, proofHeight, delayTimePeriod, delayBlockPeriod, &prefix, proof, packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence(), ibcmock.MockAcknowledgement.Acknowledgement(), ) @@ -595,11 +633,12 @@ func (suite *TendermintTestSuite) TestVerifyPacketAcknowledgement() { // no receive. func (suite *TendermintTestSuite) TestVerifyPacketReceiptAbsence() { var ( - clientState *types.ClientState - proof []byte - delayPeriod uint64 - proofHeight exported.Height - prefix commitmenttypes.MerklePrefix + clientState *types.ClientState + proof []byte + delayTimePeriod uint64 + delayBlockPeriod uint64 + proofHeight exported.Height + prefix commitmenttypes.MerklePrefix ) testCases := []struct { @@ -611,19 +650,34 @@ func (suite *TendermintTestSuite) TestVerifyPacketReceiptAbsence() { "successful verification", func() {}, true, }, { - name: "delay period has passed", + name: "delay time period has passed", + malleate: func() { + delayTimePeriod = uint64(time.Second.Nanoseconds()) + }, + expPass: true, + }, + { + name: "delay time period has not passed", + malleate: func() { + delayTimePeriod = uint64(time.Hour.Nanoseconds()) + }, + expPass: false, + }, + { + name: "delay block period has passed", malleate: func() { - delayPeriod = uint64(time.Second.Nanoseconds()) + delayBlockPeriod = 1 }, expPass: true, }, { - name: "delay period has not passed", + name: "delay block period has not passed", malleate: func() { - delayPeriod = uint64(time.Hour.Nanoseconds()) + delayBlockPeriod = 10 }, expPass: false, }, + { "ApplyPrefix failed", func() { prefix = commitmenttypes.MerklePrefix{} @@ -667,13 +721,16 @@ func (suite *TendermintTestSuite) TestVerifyPacketReceiptAbsence() { receiptKey := host.PacketReceiptKey(packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence()) proof, proofHeight = path.EndpointB.QueryProof(receiptKey) + // reset time and block delays to 0, malleate may change to a specific non-zero value. + delayTimePeriod = 0 + delayBlockPeriod = 0 tc.malleate() // make changes as necessary - store := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), path.EndpointA.ClientID) + ctx := suite.chainA.GetContext() + store := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(ctx, path.EndpointA.ClientID) - currentTime := uint64(suite.chainA.GetContext().BlockTime().UnixNano()) err = clientState.VerifyPacketReceiptAbsence( - store, suite.chainA.Codec, proofHeight, currentTime, delayPeriod, &prefix, proof, + ctx, store, suite.chainA.Codec, proofHeight, delayTimePeriod, delayBlockPeriod, &prefix, proof, packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence(), ) @@ -691,11 +748,12 @@ func (suite *TendermintTestSuite) TestVerifyPacketReceiptAbsence() { // simulated. func (suite *TendermintTestSuite) TestVerifyNextSeqRecv() { var ( - clientState *types.ClientState - proof []byte - delayPeriod uint64 - proofHeight exported.Height - prefix commitmenttypes.MerklePrefix + clientState *types.ClientState + proof []byte + delayTimePeriod uint64 + delayBlockPeriod uint64 + proofHeight exported.Height + prefix commitmenttypes.MerklePrefix ) testCases := []struct { @@ -707,19 +765,34 @@ func (suite *TendermintTestSuite) TestVerifyNextSeqRecv() { "successful verification", func() {}, true, }, { - name: "delay period has passed", + name: "delay time period has passed", + malleate: func() { + delayTimePeriod = uint64(time.Second.Nanoseconds()) + }, + expPass: true, + }, + { + name: "delay time period has not passed", + malleate: func() { + delayTimePeriod = uint64(time.Hour.Nanoseconds()) + }, + expPass: false, + }, + { + name: "delay block period has passed", malleate: func() { - delayPeriod = uint64(time.Second.Nanoseconds()) + delayBlockPeriod = 1 }, expPass: true, }, { - name: "delay period has not passed", + name: "delay block period has not passed", malleate: func() { - delayPeriod = uint64(time.Hour.Nanoseconds()) + delayBlockPeriod = 10 }, expPass: false, }, + { "ApplyPrefix failed", func() { prefix = commitmenttypes.MerklePrefix{} @@ -768,13 +841,16 @@ func (suite *TendermintTestSuite) TestVerifyNextSeqRecv() { nextSeqRecvKey := host.NextSequenceRecvKey(packet.GetDestPort(), packet.GetDestChannel()) proof, proofHeight = suite.chainB.QueryProof(nextSeqRecvKey) + // reset time and block delays to 0, malleate may change to a specific non-zero value. + delayTimePeriod = 0 + delayBlockPeriod = 0 tc.malleate() // make changes as necessary - store := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), path.EndpointA.ClientID) + ctx := suite.chainA.GetContext() + store := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(ctx, path.EndpointA.ClientID) - currentTime := uint64(suite.chainA.GetContext().BlockTime().UnixNano()) err = clientState.VerifyNextSequenceRecv( - store, suite.chainA.Codec, proofHeight, currentTime, delayPeriod, &prefix, proof, + ctx, store, suite.chainA.Codec, proofHeight, delayTimePeriod, delayBlockPeriod, &prefix, proof, packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence()+1, ) diff --git a/modules/light-clients/07-tendermint/types/tendermint_test.go b/modules/light-clients/07-tendermint/types/tendermint_test.go index 7bb8977c68a..a74aa8fe22d 100644 --- a/modules/light-clients/07-tendermint/types/tendermint_test.go +++ b/modules/light-clients/07-tendermint/types/tendermint_test.go @@ -10,12 +10,12 @@ import ( tmtypes "github.com/tendermint/tendermint/types" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/ibc-go/testing/simapp" sdk "github.com/cosmos/cosmos-sdk/types" clienttypes "github.com/cosmos/ibc-go/modules/core/02-client/types" ibctmtypes "github.com/cosmos/ibc-go/modules/light-clients/07-tendermint/types" ibctesting "github.com/cosmos/ibc-go/testing" ibctestingmock "github.com/cosmos/ibc-go/testing/mock" + "github.com/cosmos/ibc-go/testing/simapp" ) const ( From 5c2d14709d341e9ebb603a92383730b44fb04167 Mon Sep 17 00:00:00 2001 From: Aditya Sripal Date: Mon, 17 May 2021 16:05:26 -0400 Subject: [PATCH 07/15] fix lightclient tests --- .../06-solomachine/types/client_state_test.go | 12 ++++++++---- .../09-localhost/types/client_state_test.go | 10 +++++----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/modules/light-clients/06-solomachine/types/client_state_test.go b/modules/light-clients/06-solomachine/types/client_state_test.go index a3e6b703daa..3fd1ad5682e 100644 --- a/modules/light-clients/06-solomachine/types/client_state_test.go +++ b/modules/light-clients/06-solomachine/types/client_state_test.go @@ -655,9 +655,10 @@ func (suite *SoloMachineTestSuite) TestVerifyPacketCommitment() { tc := tc expSeq := tc.clientState.Sequence + 1 + ctx := suite.chainA.GetContext() err := tc.clientState.VerifyPacketCommitment( - suite.store, suite.chainA.Codec, solomachine.GetHeight(), 0, 0, tc.prefix, tc.proof, testPortID, testChannelID, solomachine.Sequence, commitmentBytes, + ctx, suite.store, suite.chainA.Codec, solomachine.GetHeight(), 0, 0, tc.prefix, tc.proof, testPortID, testChannelID, solomachine.Sequence, commitmentBytes, ) if tc.expPass { @@ -742,9 +743,10 @@ func (suite *SoloMachineTestSuite) TestVerifyPacketAcknowledgement() { tc := tc expSeq := tc.clientState.Sequence + 1 + ctx := suite.chainA.GetContext() err := tc.clientState.VerifyPacketAcknowledgement( - suite.store, suite.chainA.Codec, solomachine.GetHeight(), 0, 0, tc.prefix, tc.proof, testPortID, testChannelID, solomachine.Sequence, ack, + ctx, suite.store, suite.chainA.Codec, solomachine.GetHeight(), 0, 0, tc.prefix, tc.proof, testPortID, testChannelID, solomachine.Sequence, ack, ) if tc.expPass { @@ -829,9 +831,10 @@ func (suite *SoloMachineTestSuite) TestVerifyPacketReceiptAbsence() { tc := tc expSeq := tc.clientState.Sequence + 1 + ctx := suite.chainA.GetContext() err := tc.clientState.VerifyPacketReceiptAbsence( - suite.store, suite.chainA.Codec, solomachine.GetHeight(), 0, 0, tc.prefix, tc.proof, testPortID, testChannelID, solomachine.Sequence, + ctx, suite.store, suite.chainA.Codec, solomachine.GetHeight(), 0, 0, tc.prefix, tc.proof, testPortID, testChannelID, solomachine.Sequence, ) if tc.expPass { @@ -916,9 +919,10 @@ func (suite *SoloMachineTestSuite) TestVerifyNextSeqRecv() { tc := tc expSeq := tc.clientState.Sequence + 1 + ctx := suite.chainA.GetContext() err := tc.clientState.VerifyNextSequenceRecv( - suite.store, suite.chainA.Codec, solomachine.GetHeight(), 0, 0, tc.prefix, tc.proof, testPortID, testChannelID, nextSeqRecv, + ctx, suite.store, suite.chainA.Codec, solomachine.GetHeight(), 0, 0, tc.prefix, tc.proof, testPortID, testChannelID, nextSeqRecv, ) if tc.expPass { diff --git a/modules/light-clients/09-localhost/types/client_state_test.go b/modules/light-clients/09-localhost/types/client_state_test.go index 358ac294170..e2dbe89b78b 100644 --- a/modules/light-clients/09-localhost/types/client_state_test.go +++ b/modules/light-clients/09-localhost/types/client_state_test.go @@ -376,7 +376,7 @@ func (suite *LocalhostTestSuite) TestVerifyPacketCommitment() { tc.malleate() err := tc.clientState.VerifyPacketCommitment( - suite.store, suite.cdc, clientHeight, 0, 0, nil, []byte{}, testPortID, testChannelID, testSequence, tc.commitment, + suite.ctx, suite.store, suite.cdc, clientHeight, 0, 0, nil, []byte{}, testPortID, testChannelID, testSequence, tc.commitment, ) if tc.expPass { @@ -435,7 +435,7 @@ func (suite *LocalhostTestSuite) TestVerifyPacketAcknowledgement() { tc.malleate() err := tc.clientState.VerifyPacketAcknowledgement( - suite.store, suite.cdc, clientHeight, 0, 0, nil, []byte{}, testPortID, testChannelID, testSequence, tc.ack, + suite.ctx, suite.store, suite.cdc, clientHeight, 0, 0, nil, []byte{}, testPortID, testChannelID, testSequence, tc.ack, ) if tc.expPass { @@ -451,7 +451,7 @@ func (suite *LocalhostTestSuite) TestVerifyPacketReceiptAbsence() { clientState := types.NewClientState("chainID", clientHeight) err := clientState.VerifyPacketReceiptAbsence( - suite.store, suite.cdc, clientHeight, 0, 0, nil, nil, testPortID, testChannelID, testSequence, + suite.ctx, suite.store, suite.cdc, clientHeight, 0, 0, nil, nil, testPortID, testChannelID, testSequence, ) suite.Require().NoError(err, "receipt absence failed") @@ -459,7 +459,7 @@ func (suite *LocalhostTestSuite) TestVerifyPacketReceiptAbsence() { suite.store.Set(host.PacketReceiptKey(testPortID, testChannelID, testSequence), []byte("receipt")) err = clientState.VerifyPacketReceiptAbsence( - suite.store, suite.cdc, clientHeight, 0, 0, nil, nil, testPortID, testChannelID, testSequence, + suite.ctx, suite.store, suite.cdc, clientHeight, 0, 0, nil, nil, testPortID, testChannelID, testSequence, ) suite.Require().Error(err, "receipt exists in store") } @@ -515,7 +515,7 @@ func (suite *LocalhostTestSuite) TestVerifyNextSeqRecv() { tc.malleate() err := tc.clientState.VerifyNextSequenceRecv( - suite.store, suite.cdc, clientHeight, 0, 0, nil, []byte{}, testPortID, testChannelID, nextSeqRecv, + suite.ctx, suite.store, suite.cdc, clientHeight, 0, 0, nil, []byte{}, testPortID, testChannelID, nextSeqRecv, ) if tc.expPass { From afaaea20615dcdff59a2d8f294dfd520acac5e18 Mon Sep 17 00:00:00 2001 From: Aditya Sripal Date: Mon, 17 May 2021 16:44:17 -0400 Subject: [PATCH 08/15] add connection tests --- .../core/03-connection/keeper/params_test.go | 2 +- .../core/03-connection/keeper/verify_test.go | 128 +++++++++++++----- modules/core/genesis_test.go | 3 + 3 files changed, 100 insertions(+), 33 deletions(-) diff --git a/modules/core/03-connection/keeper/params_test.go b/modules/core/03-connection/keeper/params_test.go index f444f98df61..e740106a77a 100644 --- a/modules/core/03-connection/keeper/params_test.go +++ b/modules/core/03-connection/keeper/params_test.go @@ -13,5 +13,5 @@ func (suite *KeeperTestSuite) TestParams() { expParams.MaxTimePerBlock = 10 suite.chainA.App.GetIBCKeeper().ConnectionKeeper.SetParams(suite.chainA.GetContext(), expParams) params = suite.chainA.App.GetIBCKeeper().ConnectionKeeper.GetParams(suite.chainA.GetContext()) - suite.Require().Equal(10, expParams.MaxTimePerBlock) + suite.Require().Equal(uint64(10), expParams.MaxTimePerBlock) } diff --git a/modules/core/03-connection/keeper/verify_test.go b/modules/core/03-connection/keeper/verify_test.go index f57953feff6..620f4425e5f 100644 --- a/modules/core/03-connection/keeper/verify_test.go +++ b/modules/core/03-connection/keeper/verify_test.go @@ -290,10 +290,11 @@ func (suite *KeeperTestSuite) TestVerifyChannelState() { // packet is sent from chainA to chainB, but has not been received. func (suite *KeeperTestSuite) TestVerifyPacketCommitment() { var ( - path *ibctesting.Path - packet channeltypes.Packet - heightDiff uint64 - delayPeriod uint64 + path *ibctesting.Path + packet channeltypes.Packet + heightDiff uint64 + delayTimePeriod uint64 + timePerBlock uint64 ) cases := []struct { name string @@ -302,10 +303,16 @@ func (suite *KeeperTestSuite) TestVerifyPacketCommitment() { }{ {"verification success", func() {}, true}, {"verification success: delay period passed", func() { - delayPeriod = uint64(1 * time.Second.Nanoseconds()) + delayTimePeriod = uint64(1 * time.Second.Nanoseconds()) }, true}, - {"delay period has not passed", func() { - delayPeriod = uint64(1 * time.Hour.Nanoseconds()) + {"delay time period has not passed", func() { + delayTimePeriod = uint64(1 * time.Hour.Nanoseconds()) + }, false}, + {"delay block period has not passed", func() { + // make timePerBlock 1 nanosecond so that block delay is not passed. + // must also set a non-zero time delay to ensure block delay is enforced. + delayTimePeriod = uint64(1 * time.Second.Nanoseconds()) + timePerBlock = 1 }, false}, {"client state not found- changed client ID", func() { connection := path.EndpointB.GetConnection() @@ -338,13 +345,22 @@ func (suite *KeeperTestSuite) TestVerifyPacketCommitment() { err := path.EndpointA.SendPacket(packet) suite.Require().NoError(err) + // reset variables + heightDiff = 0 + delayTimePeriod = 0 + timePerBlock = 0 tc.malleate() connection := path.EndpointB.GetConnection() - connection.DelayPeriod = delayPeriod + connection.DelayPeriod = delayTimePeriod commitmentKey := host.PacketCommitmentKey(packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence()) proof, proofHeight := suite.chainA.QueryProof(commitmentKey) + // set time per block param + if timePerBlock != 0 { + suite.chainB.App.GetIBCKeeper().ConnectionKeeper.SetParams(suite.chainB.GetContext(), types.NewParams(timePerBlock)) + } + commitment := channeltypes.CommitPacket(suite.chainB.App.GetIBCKeeper().Codec(), packet) err = suite.chainB.App.GetIBCKeeper().ConnectionKeeper.VerifyPacketCommitment( suite.chainB.GetContext(), connection, malleateHeight(proofHeight, heightDiff), proof, @@ -365,10 +381,11 @@ func (suite *KeeperTestSuite) TestVerifyPacketCommitment() { // is sent from chainA to chainB and received. func (suite *KeeperTestSuite) TestVerifyPacketAcknowledgement() { var ( - path *ibctesting.Path - ack exported.Acknowledgement - heightDiff uint64 - delayPeriod uint64 + path *ibctesting.Path + ack exported.Acknowledgement + heightDiff uint64 + delayTimePeriod uint64 + timePerBlock uint64 ) cases := []struct { @@ -378,10 +395,16 @@ func (suite *KeeperTestSuite) TestVerifyPacketAcknowledgement() { }{ {"verification success", func() {}, true}, {"verification success: delay period passed", func() { - delayPeriod = uint64(1 * time.Second.Nanoseconds()) + delayTimePeriod = uint64(1 * time.Second.Nanoseconds()) }, true}, - {"delay period has not passed", func() { - delayPeriod = uint64(1 * time.Hour.Nanoseconds()) + {"delay time period has not passed", func() { + delayTimePeriod = uint64(1 * time.Hour.Nanoseconds()) + }, false}, + {"delay block period has not passed", func() { + // make timePerBlock 1 nanosecond so that block delay is not passed. + // must also set a non-zero time delay to ensure block delay is enforced. + delayTimePeriod = uint64(1 * time.Second.Nanoseconds()) + timePerBlock = 1 }, false}, {"client state not found- changed client ID", func() { connection := path.EndpointA.GetConnection() @@ -426,10 +449,19 @@ func (suite *KeeperTestSuite) TestVerifyPacketAcknowledgement() { packetAckKey := host.PacketAcknowledgementKey(packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence()) proof, proofHeight := suite.chainB.QueryProof(packetAckKey) + // reset variables + heightDiff = 0 + delayTimePeriod = 0 + timePerBlock = 0 tc.malleate() connection := path.EndpointA.GetConnection() - connection.DelayPeriod = delayPeriod + connection.DelayPeriod = delayTimePeriod + + // set time per block param + if timePerBlock != 0 { + suite.chainA.App.GetIBCKeeper().ConnectionKeeper.SetParams(suite.chainA.GetContext(), types.NewParams(timePerBlock)) + } err = suite.chainA.App.GetIBCKeeper().ConnectionKeeper.VerifyPacketAcknowledgement( suite.chainA.GetContext(), connection, malleateHeight(proofHeight, heightDiff), proof, @@ -450,10 +482,11 @@ func (suite *KeeperTestSuite) TestVerifyPacketAcknowledgement() { // a packet is sent from chainA to chainB and not received. func (suite *KeeperTestSuite) TestVerifyPacketReceiptAbsence() { var ( - path *ibctesting.Path - packet channeltypes.Packet - heightDiff uint64 - delayPeriod uint64 + path *ibctesting.Path + packet channeltypes.Packet + heightDiff uint64 + delayTimePeriod uint64 + timePerBlock uint64 ) cases := []struct { @@ -463,10 +496,16 @@ func (suite *KeeperTestSuite) TestVerifyPacketReceiptAbsence() { }{ {"verification success", func() {}, true}, {"verification success: delay period passed", func() { - delayPeriod = uint64(1 * time.Second.Nanoseconds()) + delayTimePeriod = uint64(1 * time.Second.Nanoseconds()) }, true}, - {"delay period has not passed", func() { - delayPeriod = uint64(1 * time.Hour.Nanoseconds()) + {"delay time period has not passed", func() { + delayTimePeriod = uint64(1 * time.Hour.Nanoseconds()) + }, false}, + {"delay block period has not passed", func() { + // make timePerBlock 1 nanosecond so that block delay is not passed. + // must also set a non-zero time delay to ensure block delay is enforced. + delayTimePeriod = uint64(1 * time.Second.Nanoseconds()) + timePerBlock = 1 }, false}, {"client state not found - changed client ID", func() { connection := path.EndpointA.GetConnection() @@ -505,10 +544,14 @@ func (suite *KeeperTestSuite) TestVerifyPacketReceiptAbsence() { err := path.EndpointA.SendPacket(packet) suite.Require().NoError(err) + // reset variables + heightDiff = 0 + delayTimePeriod = 0 + timePerBlock = 0 tc.malleate() connection := path.EndpointA.GetConnection() - connection.DelayPeriod = delayPeriod + connection.DelayPeriod = delayTimePeriod clientState := path.EndpointA.GetClientState().(*ibctmtypes.ClientState) if clientState.FrozenHeight.IsZero() { @@ -520,6 +563,11 @@ func (suite *KeeperTestSuite) TestVerifyPacketReceiptAbsence() { packetReceiptKey := host.PacketReceiptKey(packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence()) proof, proofHeight := suite.chainB.QueryProof(packetReceiptKey) + // set time per block param + if timePerBlock != 0 { + suite.chainA.App.GetIBCKeeper().ConnectionKeeper.SetParams(suite.chainA.GetContext(), types.NewParams(timePerBlock)) + } + err = suite.chainA.App.GetIBCKeeper().ConnectionKeeper.VerifyPacketReceiptAbsence( suite.chainA.GetContext(), connection, malleateHeight(proofHeight, heightDiff), proof, packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence(), @@ -539,10 +587,11 @@ func (suite *KeeperTestSuite) TestVerifyPacketReceiptAbsence() { // is sent from chainA to chainB and received. func (suite *KeeperTestSuite) TestVerifyNextSequenceRecv() { var ( - path *ibctesting.Path - heightDiff uint64 - delayPeriod uint64 - offsetSeq uint64 + path *ibctesting.Path + heightDiff uint64 + delayTimePeriod uint64 + timePerBlock uint64 + offsetSeq uint64 ) cases := []struct { @@ -552,10 +601,16 @@ func (suite *KeeperTestSuite) TestVerifyNextSequenceRecv() { }{ {"verification success", func() {}, true}, {"verification success: delay period passed", func() { - delayPeriod = uint64(1 * time.Second.Nanoseconds()) + delayTimePeriod = uint64(1 * time.Second.Nanoseconds()) }, true}, - {"delay period has not passed", func() { - delayPeriod = uint64(1 * time.Hour.Nanoseconds()) + {"delay time period has not passed", func() { + delayTimePeriod = uint64(1 * time.Hour.Nanoseconds()) + }, false}, + {"delay block period has not passed", func() { + // make timePerBlock 1 nanosecond so that block delay is not passed. + // must also set a non-zero time delay to ensure block delay is enforced. + delayTimePeriod = uint64(1 * time.Second.Nanoseconds()) + timePerBlock = 1 }, false}, {"client state not found- changed client ID", func() { connection := path.EndpointA.GetConnection() @@ -599,10 +654,19 @@ func (suite *KeeperTestSuite) TestVerifyNextSequenceRecv() { nextSeqRecvKey := host.NextSequenceRecvKey(packet.GetDestPort(), packet.GetDestChannel()) proof, proofHeight := suite.chainB.QueryProof(nextSeqRecvKey) + // reset variables + heightDiff = 0 + delayTimePeriod = 0 + timePerBlock = 0 tc.malleate() + // set time per block param + if timePerBlock != 0 { + suite.chainA.App.GetIBCKeeper().ConnectionKeeper.SetParams(suite.chainA.GetContext(), types.NewParams(timePerBlock)) + } + connection := path.EndpointA.GetConnection() - connection.DelayPeriod = delayPeriod + connection.DelayPeriod = delayTimePeriod err = suite.chainA.App.GetIBCKeeper().ConnectionKeeper.VerifyNextSequenceRecv( suite.chainA.GetContext(), connection, malleateHeight(proofHeight, heightDiff), proof, packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence()+offsetSeq, diff --git a/modules/core/genesis_test.go b/modules/core/genesis_test.go index 924fb42e2d3..5873440dc4b 100644 --- a/modules/core/genesis_test.go +++ b/modules/core/genesis_test.go @@ -117,6 +117,7 @@ func (suite *IBCTestSuite) TestValidateGenesis() { connectiontypes.NewConnectionPaths(clientID, []string{connectionID}), }, 0, + connectiontypes.NewParams(10), ), ChannelGenesis: channeltypes.NewGenesisState( []channeltypes.IdentifiedChannel{ @@ -192,6 +193,7 @@ func (suite *IBCTestSuite) TestValidateGenesis() { connectiontypes.NewConnectionPaths(clientID, []string{connectionID}), }, 0, + connectiontypes.Params{}, ), }, expPass: false, @@ -279,6 +281,7 @@ func (suite *IBCTestSuite) TestInitGenesis() { connectiontypes.NewConnectionPaths(clientID, []string{connectionID}), }, 0, + connectiontypes.NewParams(10), ), ChannelGenesis: channeltypes.NewGenesisState( []channeltypes.IdentifiedChannel{ From 89cb274a18101bdcd39816608d8ccd9fa9c8acb6 Mon Sep 17 00:00:00 2001 From: Aditya Sripal Date: Mon, 17 May 2021 16:59:41 -0400 Subject: [PATCH 09/15] DRY consensus metadata setting --- .../core/03-connection/types/genesis_test.go | 14 ++++++++++++++ .../07-tendermint/types/proposal_handle.go | 8 ++------ .../07-tendermint/types/update.go | 19 ++++++++++++------- .../07-tendermint/types/upgrade.go | 5 ++++- 4 files changed, 32 insertions(+), 14 deletions(-) diff --git a/modules/core/03-connection/types/genesis_test.go b/modules/core/03-connection/types/genesis_test.go index 8f38a8324be..9a64c86b499 100644 --- a/modules/core/03-connection/types/genesis_test.go +++ b/modules/core/03-connection/types/genesis_test.go @@ -106,6 +106,20 @@ func TestValidateGenesis(t *testing.T) { ), expPass: false, }, + { + name: "invalid params", + genState: types.NewGenesisState( + []types.IdentifiedConnection{ + types.NewIdentifiedConnection(connectionID, types.NewConnectionEnd(types.INIT, clientID, types.Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, []*types.Version{ibctesting.ConnectionVersion}, 500)), + }, + []types.ConnectionPaths{ + {clientID, []string{connectionID}}, + }, + 0, + types.Params{}, + ), + expPass: false, + }, } for _, tc := range testCases { diff --git a/modules/light-clients/07-tendermint/types/proposal_handle.go b/modules/light-clients/07-tendermint/types/proposal_handle.go index 55c00d0f9d5..780ffdf9ff4 100644 --- a/modules/light-clients/07-tendermint/types/proposal_handle.go +++ b/modules/light-clients/07-tendermint/types/proposal_handle.go @@ -90,12 +90,8 @@ func (cs ClientState) CheckSubstituteAndUpdateState( } SetConsensusState(subjectClientStore, cdc, consensusState, height) - processedTime, found := GetProcessedTime(substituteClientStore, height) - if !found { - continue - } - SetProcessedTime(subjectClientStore, height, processedTime) - + // set metadata for this consensus state + setConsensusMetadata(ctx, subjectClientStore, height) } cs.LatestHeight = substituteClientState.LatestHeight diff --git a/modules/light-clients/07-tendermint/types/update.go b/modules/light-clients/07-tendermint/types/update.go index 53ba47c90a4..4ade4896a83 100644 --- a/modules/light-clients/07-tendermint/types/update.go +++ b/modules/light-clients/07-tendermint/types/update.go @@ -212,13 +212,18 @@ func update(ctx sdk.Context, clientStore sdk.KVStore, clientState *ClientState, NextValidatorsHash: header.Header.NextValidatorsHash, } - // set context time as processed time and set context height as processed height - // as this is internal tendermint light client logic. - // client state and consensus state will be set by client keeper - // set iteration key to provide ability for efficient ordered iteration of consensus states. - SetProcessedTime(clientStore, header.GetHeight(), uint64(ctx.BlockTime().UnixNano())) - SetProcessedHeight(clientStore, header.GetHeight(), clienttypes.GetSelfHeight(ctx)) - SetIterationKey(clientStore, header.GetHeight()) + // set metadata for this consensus state + setConsensusMetadata(ctx, clientStore, header.GetHeight()) return clientState, consensusState } + +// set context time as processed time and set context height as processed height +// as this is internal tendermint light client logic. +// client state and consensus state will be set by client keeper +// set iteration key to provide ability for efficient ordered iteration of consensus states. +func setConsensusMetadata(ctx sdk.Context, clientStore sdk.KVStore, height exported.Height) { + SetProcessedTime(clientStore, height, uint64(ctx.BlockTime().UnixNano())) + SetProcessedHeight(clientStore, height, clienttypes.GetSelfHeight(ctx)) + SetIterationKey(clientStore, height) +} diff --git a/modules/light-clients/07-tendermint/types/upgrade.go b/modules/light-clients/07-tendermint/types/upgrade.go index ab5ebcf4148..b70cbd4879d 100644 --- a/modules/light-clients/07-tendermint/types/upgrade.go +++ b/modules/light-clients/07-tendermint/types/upgrade.go @@ -6,10 +6,10 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" clienttypes "github.com/cosmos/ibc-go/modules/core/02-client/types" commitmenttypes "github.com/cosmos/ibc-go/modules/core/23-commitment/types" "github.com/cosmos/ibc-go/modules/core/exported" - upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" ) // VerifyUpgradeAndUpdateState checks if the upgraded client has been committed by the current client @@ -122,6 +122,9 @@ func (cs ClientState) VerifyUpgradeAndUpdateState( tmUpgradeConsState.Timestamp, commitmenttypes.MerkleRoot{}, tmUpgradeConsState.NextValidatorsHash, ) + // set metadata for this consensus state + setConsensusMetadata(ctx, clientStore, tmUpgradeClient.LatestHeight) + return newClientState, newConsState, nil } From ed5c706816ef9492fb275ad270cc8a6afd0b810f Mon Sep 17 00:00:00 2001 From: Aditya Sripal Date: Mon, 17 May 2021 23:00:18 -0400 Subject: [PATCH 10/15] fix genesis and add safety check --- modules/core/03-connection/keeper/verify.go | 7 ++++++- modules/core/03-connection/types/genesis.go | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/modules/core/03-connection/keeper/verify.go b/modules/core/03-connection/keeper/verify.go index c2f9868f31d..21542fa3892 100644 --- a/modules/core/03-connection/keeper/verify.go +++ b/modules/core/03-connection/keeper/verify.go @@ -299,9 +299,14 @@ func (k Keeper) VerifyNextSequenceRecv( // getBlockDelay calculates the block delay period from the time delay of the connection // and the maximum expected time per block. func (k Keeper) getBlockDelay(ctx sdk.Context, connection exported.ConnectionI) uint64 { + // maxTimePerBlock should never be zero, however if it is then return a 0 blcok delay for safety + // as the maxTimePerBlock parameter was not set. + maxTimePerBlock := k.GetMaxTimePerBlock(ctx) + if maxTimePerBlock == 0 { + return 0 + } // calculate minimum block delay by dividing time delay period // by the maximum expected time per block. Round up the block delay. timeDelay := connection.GetDelayPeriod() - maxTimePerBlock := k.GetMaxTimePerBlock(ctx) return uint64(math.Ceil(float64(timeDelay) / float64(maxTimePerBlock))) } diff --git a/modules/core/03-connection/types/genesis.go b/modules/core/03-connection/types/genesis.go index aa6671979c6..313782184cd 100644 --- a/modules/core/03-connection/types/genesis.go +++ b/modules/core/03-connection/types/genesis.go @@ -74,5 +74,9 @@ func (gs GenesisState) Validate() error { return fmt.Errorf("next connection sequence %d must be greater than maximum sequence used in connection identifier %d", gs.NextConnectionSequence, maxSequence) } + if err := gs.Params.Validate(); err != nil { + return err + } + return nil } From 43f10893bc58588ae0146976b6eb87f89487f332 Mon Sep 17 00:00:00 2001 From: Aditya Sripal Date: Tue, 18 May 2021 15:36:06 -0400 Subject: [PATCH 11/15] switch param name and default --- docs/ibc/proto-docs.md | 2 +- modules/core/03-connection/keeper/params.go | 8 +- .../core/03-connection/keeper/params_test.go | 4 +- modules/core/03-connection/keeper/verify.go | 14 +-- .../core/03-connection/types/connection.pb.go | 114 +++++++++--------- modules/core/03-connection/types/params.go | 19 ++- proto/ibc/core/connection/v1/connection.proto | 4 +- 7 files changed, 82 insertions(+), 83 deletions(-) diff --git a/docs/ibc/proto-docs.md b/docs/ibc/proto-docs.md index 103b6a28c7a..412530b5d69 100644 --- a/docs/ibc/proto-docs.md +++ b/docs/ibc/proto-docs.md @@ -2408,7 +2408,7 @@ Params defines the set of Connection parameters. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `max_time_per_block` | [uint64](#uint64) | | maximum time expected per block, used to enforce block delay. | +| `expected_time_per_block` | [uint64](#uint64) | | expected time per block, used to enforce block delay. | diff --git a/modules/core/03-connection/keeper/params.go b/modules/core/03-connection/keeper/params.go index 63c14bd0e83..27d59ce32d4 100644 --- a/modules/core/03-connection/keeper/params.go +++ b/modules/core/03-connection/keeper/params.go @@ -5,16 +5,16 @@ import ( "github.com/cosmos/ibc-go/modules/core/03-connection/types" ) -// GetMaxTimePerBlock retrieves the maximum time per block from the paramstore -func (k Keeper) GetMaxTimePerBlock(ctx sdk.Context) uint64 { +// GetExpectedTimePerBlock retrieves the expected time per block from the paramstore +func (k Keeper) GetExpectedTimePerBlock(ctx sdk.Context) uint64 { var res uint64 - k.paramSpace.Get(ctx, types.KeyMaxTimePerBlock, &res) + k.paramSpace.Get(ctx, types.KeyExpectedTimePerBlock, &res) return res } // GetParams returns the total set of ibc-connection parameters. func (k Keeper) GetParams(ctx sdk.Context) types.Params { - return types.NewParams(k.GetMaxTimePerBlock(ctx)) + return types.NewParams(k.GetExpectedTimePerBlock(ctx)) } // SetParams sets the total set of ibc-connection parameters. diff --git a/modules/core/03-connection/keeper/params_test.go b/modules/core/03-connection/keeper/params_test.go index e740106a77a..dc35ba715cf 100644 --- a/modules/core/03-connection/keeper/params_test.go +++ b/modules/core/03-connection/keeper/params_test.go @@ -10,8 +10,8 @@ func (suite *KeeperTestSuite) TestParams() { params := suite.chainA.App.GetIBCKeeper().ConnectionKeeper.GetParams(suite.chainA.GetContext()) suite.Require().Equal(expParams, params) - expParams.MaxTimePerBlock = 10 + expParams.ExpectedTimePerBlock = 10 suite.chainA.App.GetIBCKeeper().ConnectionKeeper.SetParams(suite.chainA.GetContext(), expParams) params = suite.chainA.App.GetIBCKeeper().ConnectionKeeper.GetParams(suite.chainA.GetContext()) - suite.Require().Equal(uint64(10), expParams.MaxTimePerBlock) + suite.Require().Equal(uint64(10), expParams.ExpectedTimePerBlock) } diff --git a/modules/core/03-connection/keeper/verify.go b/modules/core/03-connection/keeper/verify.go index 21542fa3892..828867502f7 100644 --- a/modules/core/03-connection/keeper/verify.go +++ b/modules/core/03-connection/keeper/verify.go @@ -297,16 +297,16 @@ func (k Keeper) VerifyNextSequenceRecv( } // getBlockDelay calculates the block delay period from the time delay of the connection -// and the maximum expected time per block. +// and the expected time per block. func (k Keeper) getBlockDelay(ctx sdk.Context, connection exported.ConnectionI) uint64 { - // maxTimePerBlock should never be zero, however if it is then return a 0 blcok delay for safety - // as the maxTimePerBlock parameter was not set. - maxTimePerBlock := k.GetMaxTimePerBlock(ctx) - if maxTimePerBlock == 0 { + // expectedTimePerBlock should never be zero, however if it is then return a 0 blcok delay for safety + // as the expectedTimePerBlock parameter was not set. + expectedTimePerBlock := k.GetExpectedTimePerBlock(ctx) + if expectedTimePerBlock == 0 { return 0 } // calculate minimum block delay by dividing time delay period - // by the maximum expected time per block. Round up the block delay. + // by the expected time per block. Round up the block delay. timeDelay := connection.GetDelayPeriod() - return uint64(math.Ceil(float64(timeDelay) / float64(maxTimePerBlock))) + return uint64(math.Ceil(float64(timeDelay) / float64(expectedTimePerBlock))) } diff --git a/modules/core/03-connection/types/connection.pb.go b/modules/core/03-connection/types/connection.pb.go index 50e74664f50..b05314d39d9 100644 --- a/modules/core/03-connection/types/connection.pb.go +++ b/modules/core/03-connection/types/connection.pb.go @@ -356,8 +356,8 @@ var xxx_messageInfo_Version proto.InternalMessageInfo // Params defines the set of Connection parameters. type Params struct { - // maximum time expected per block, used to enforce block delay. - MaxTimePerBlock uint64 `protobuf:"varint,1,opt,name=max_time_per_block,json=maxTimePerBlock,proto3" json:"max_time_per_block,omitempty" yaml:"max_time_per_block"` + // expected time per block, used to enforce block delay. + ExpectedTimePerBlock uint64 `protobuf:"varint,1,opt,name=expected_time_per_block,json=expectedTimePerBlock,proto3" json:"expected_time_per_block,omitempty" yaml:"expected_time_per_block"` } func (m *Params) Reset() { *m = Params{} } @@ -393,9 +393,9 @@ func (m *Params) XXX_DiscardUnknown() { var xxx_messageInfo_Params proto.InternalMessageInfo -func (m *Params) GetMaxTimePerBlock() uint64 { +func (m *Params) GetExpectedTimePerBlock() uint64 { if m != nil { - return m.MaxTimePerBlock + return m.ExpectedTimePerBlock } return 0 } @@ -416,52 +416,52 @@ func init() { } var fileDescriptor_90572467c054e43a = []byte{ - // 707 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x54, 0xcd, 0x6e, 0xda, 0x4c, - 0x14, 0xc5, 0xc6, 0x10, 0x18, 0xc2, 0x17, 0xbe, 0x29, 0x6a, 0x5d, 0xa4, 0xd8, 0x96, 0x5b, 0xa9, - 0xa8, 0x52, 0xa0, 0x24, 0x52, 0xa5, 0xa6, 0xea, 0x22, 0x10, 0x2a, 0xb9, 0x3f, 0x14, 0x19, 0x52, - 0xa9, 0xd9, 0x20, 0x63, 0x4f, 0xc8, 0x28, 0xd8, 0x83, 0xec, 0x01, 0x85, 0x37, 0x88, 0xb2, 0xea, - 0xb6, 0x8b, 0x48, 0x95, 0xfa, 0x2e, 0x55, 0xd4, 0x55, 0x96, 0x5d, 0xa1, 0x2a, 0xd9, 0x76, 0xc5, - 0x13, 0x54, 0xf6, 0x80, 0x71, 0xd2, 0x66, 0x91, 0xb4, 0xbb, 0x7b, 0xe6, 0x9e, 0x73, 0x98, 0x7b, - 0xb8, 0x1e, 0xf0, 0x08, 0x77, 0xcd, 0xb2, 0x49, 0x5c, 0x54, 0x36, 0x89, 0xe3, 0x20, 0x93, 0x62, - 0xe2, 0x94, 0x47, 0x95, 0x08, 0x2a, 0x0d, 0x5c, 0x42, 0x09, 0xbc, 0x8b, 0xbb, 0x66, 0xc9, 0x27, - 0x96, 0x22, 0xad, 0x51, 0xa5, 0x90, 0xef, 0x91, 0x1e, 0x09, 0x28, 0x65, 0xbf, 0x62, 0xec, 0x42, - 0xd4, 0xd6, 0xb6, 0x31, 0xb5, 0x91, 0x43, 0x99, 0xed, 0x1c, 0x31, 0xa2, 0xfa, 0x95, 0x07, 0xd9, - 0x5a, 0x68, 0x58, 0x77, 0x2c, 0x58, 0x01, 0x69, 0xb3, 0x8f, 0x91, 0x43, 0x3b, 0xd8, 0x12, 0x39, - 0x85, 0x2b, 0xa6, 0xab, 0xf9, 0xe9, 0x44, 0xce, 0x8d, 0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 0x1a, 0x5a, 0x43, 0x6b, 0x6b, 0x5b, 0x6f, 0xb4, 0xdd, 0xfa, 0x76, - 0x67, 0xa7, 0xd1, 0x6a, 0xd6, 0x6b, 0xda, 0x4b, 0xad, 0xbe, 0x9d, 0x8b, 0x15, 0xfe, 0x3f, 0x3e, - 0x51, 0xb2, 0x97, 0x08, 0x50, 0x04, 0x80, 0xe9, 0xfc, 0xc3, 0x1c, 0x57, 0x48, 0x1d, 0x9f, 0x28, - 0x82, 0x5f, 0x43, 0x09, 0x64, 0x59, 0xa7, 0xad, 0x7f, 0x78, 0xd7, 0xac, 0x37, 0x72, 0x7c, 0x21, - 0x73, 0x7c, 0xa2, 0x2c, 0xcd, 0xe0, 0x42, 0x19, 0x34, 0xe3, 0x4c, 0xe9, 0xd7, 0x05, 0xe1, 0xe8, - 0x8b, 0x14, 0xab, 0xb6, 0x4e, 0xcf, 0x25, 0xee, 0xec, 0x5c, 0xe2, 0x7e, 0x9c, 0x4b, 0xdc, 0xc7, - 0x0b, 0x29, 0x76, 0x76, 0x21, 0xc5, 0xbe, 0x5f, 0x48, 0xb1, 0xdd, 0x67, 0x3d, 0x4c, 0xf7, 0x87, - 0x5d, 0x7f, 0x21, 0xca, 0x26, 0xf1, 0x6c, 0xe2, 0x95, 0x71, 0xd7, 0x5c, 0xeb, 0x91, 0xb2, 0x4d, - 0xac, 0x61, 0x1f, 0x79, 0xec, 0x91, 0x7e, 0xb2, 0xb1, 0x16, 0x79, 0xfe, 0xe9, 0x78, 0x80, 0xbc, - 0x6e, 0x32, 0x78, 0xa0, 0x37, 0x7e, 0x05, 0x00, 0x00, 0xff, 0xff, 0x9e, 0x3f, 0x99, 0x65, 0x22, - 0x06, 0x00, 0x00, + // 710 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x55, 0xc1, 0x6e, 0xda, 0x4a, + 0x14, 0xc5, 0xc6, 0x10, 0x18, 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x1b, 0xda, 0x2b, 0xad, 0xb9, 0x5b, 0x48, 0x94, + 0xfe, 0x39, 0x3b, 0x57, 0xf2, 0x37, 0x08, 0x50, 0x04, 0x80, 0xe9, 0xfc, 0xc3, 0x02, 0x57, 0xca, + 0x9c, 0x9d, 0x2b, 0x82, 0x5f, 0x43, 0x09, 0xe4, 0x59, 0xa7, 0xab, 0xef, 0xbf, 0x6b, 0x37, 0x5b, + 0x05, 0xbe, 0x94, 0x3b, 0x3b, 0x57, 0x56, 0x42, 0xb8, 0x54, 0x06, 0xcd, 0x24, 0x53, 0xfa, 0x75, + 0x49, 0x38, 0xfd, 0x2c, 0x25, 0xea, 0x9d, 0x8b, 0x2b, 0x89, 0xbb, 0xbc, 0x92, 0xb8, 0xef, 0x57, + 0x12, 0xf7, 0xe1, 0x5a, 0x4a, 0x5c, 0x5e, 0x4b, 0x89, 0x6f, 0xd7, 0x52, 0xe2, 0xe0, 0xf9, 0x00, + 0xd3, 0xa3, 0x71, 0xdf, 0xdf, 0x8f, 0xaa, 0x49, 0x3c, 0x9b, 0x78, 0x55, 0xdc, 0x37, 0x37, 0x06, + 0xa4, 0x6a, 0x13, 0x6b, 0x3c, 0x44, 0x1e, 0x7b, 0xb3, 0x9f, 0x6e, 0x6d, 0xc4, 0xfe, 0x0d, 0xe8, + 0x74, 0x84, 0xbc, 0x7e, 0x3a, 0x78, 0xaf, 0xb7, 0x7e, 0x06, 0x00, 0x00, 0xff, 0xff, 0xdf, 0x28, + 0x7b, 0x4a, 0x31, 0x06, 0x00, 0x00, } func (m *ConnectionEnd) Marshal() (dAtA []byte, err error) { @@ -776,8 +776,8 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if m.MaxTimePerBlock != 0 { - i = encodeVarintConnection(dAtA, i, uint64(m.MaxTimePerBlock)) + if m.ExpectedTimePerBlock != 0 { + i = encodeVarintConnection(dAtA, i, uint64(m.ExpectedTimePerBlock)) i-- dAtA[i] = 0x8 } @@ -931,8 +931,8 @@ func (m *Params) Size() (n int) { } var l int _ = l - if m.MaxTimePerBlock != 0 { - n += 1 + sovConnection(uint64(m.MaxTimePerBlock)) + if m.ExpectedTimePerBlock != 0 { + n += 1 + sovConnection(uint64(m.ExpectedTimePerBlock)) } return n } @@ -1837,9 +1837,9 @@ func (m *Params) Unmarshal(dAtA []byte) error { switch fieldNum { case 1: if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field MaxTimePerBlock", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field ExpectedTimePerBlock", wireType) } - m.MaxTimePerBlock = 0 + m.ExpectedTimePerBlock = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowConnection @@ -1849,7 +1849,7 @@ func (m *Params) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.MaxTimePerBlock |= uint64(b&0x7F) << shift + m.ExpectedTimePerBlock |= uint64(b&0x7F) << shift if b < 0x80 { break } diff --git a/modules/core/03-connection/types/params.go b/modules/core/03-connection/types/params.go index b3676ca8ce0..84589b137bc 100644 --- a/modules/core/03-connection/types/params.go +++ b/modules/core/03-connection/types/params.go @@ -7,12 +7,11 @@ import ( paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" ) -// DefaultTimePerBlock is the default value for maximum time -// expected per block. -const DefaultTimePerBlock = time.Hour +// DefaultTimePerBlock is the default value for expected time per block. +const DefaultTimePerBlock = 30 * time.Second -// KeyMaxTimePerBlock is store's key for MaxTimePerBlock parameter -var KeyMaxTimePerBlock = []byte("MaxTimePerBlock") +// KeyExpectedTimePerBlock is store's key for ExpectedTimePerBlock parameter +var KeyExpectedTimePerBlock = []byte("ExpectedTimePerBlock") // ParamKeyTable type declaration for parameters func ParamKeyTable() paramtypes.KeyTable { @@ -22,7 +21,7 @@ func ParamKeyTable() paramtypes.KeyTable { // NewParams creates a new parameter configuration for the ibc connection module func NewParams(timePerBlock uint64) Params { return Params{ - MaxTimePerBlock: timePerBlock, + ExpectedTimePerBlock: timePerBlock, } } @@ -31,10 +30,10 @@ func DefaultParams() Params { return NewParams(uint64(DefaultTimePerBlock)) } -// Validate ensures MaxTimePerBlock is non-zero +// Validate ensures ExpectedTimePerBlock is non-zero func (p Params) Validate() error { - if p.MaxTimePerBlock == 0 { - return fmt.Errorf("MaxTimePerBlock cannot be zero") + if p.ExpectedTimePerBlock == 0 { + return fmt.Errorf("ExpectedTimePerBlock cannot be zero") } return nil } @@ -42,7 +41,7 @@ func (p Params) Validate() error { // ParamSetPairs implements params.ParamSet func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { return paramtypes.ParamSetPairs{ - paramtypes.NewParamSetPair(KeyMaxTimePerBlock, p.MaxTimePerBlock, validateParams), + paramtypes.NewParamSetPair(KeyExpectedTimePerBlock, p.ExpectedTimePerBlock, validateParams), } } diff --git a/proto/ibc/core/connection/v1/connection.proto b/proto/ibc/core/connection/v1/connection.proto index 300f943e00e..2c7f8c482b5 100644 --- a/proto/ibc/core/connection/v1/connection.proto +++ b/proto/ibc/core/connection/v1/connection.proto @@ -107,6 +107,6 @@ message Version { // Params defines the set of Connection parameters. message Params { - // maximum time expected per block, used to enforce block delay. - uint64 max_time_per_block = 1 [(gogoproto.moretags) = "yaml:\"max_time_per_block\""]; + // expected time per block, used to enforce block delay. + uint64 expected_time_per_block = 1 [(gogoproto.moretags) = "yaml:\"expected_time_per_block\""]; } From e33ddca5628dc867b07a7a44fbc4d632f1cd7258 Mon Sep 17 00:00:00 2001 From: Aditya Sripal Date: Fri, 21 May 2021 16:40:59 -0400 Subject: [PATCH 12/15] set metadata on init and fix tests --- .../core/02-client/keeper/grpc_query_test.go | 3 +-- .../07-tendermint/types/client_state.go | 4 ++-- .../07-tendermint/types/store.go | 17 +++++++++++++++++ .../07-tendermint/types/update.go | 14 ++------------ .../07-tendermint/types/update_test.go | 19 +++++++++++++------ 5 files changed, 35 insertions(+), 22 deletions(-) diff --git a/modules/core/02-client/keeper/grpc_query_test.go b/modules/core/02-client/keeper/grpc_query_test.go index a2531c4dd62..f066b05b822 100644 --- a/modules/core/02-client/keeper/grpc_query_test.go +++ b/modules/core/02-client/keeper/grpc_query_test.go @@ -144,7 +144,7 @@ func (suite *KeeperTestSuite) TestQueryClientStates() { expClientStates = types.IdentifiedClientStates{idcs, idcs2}.Sort() req = &types.QueryClientStatesRequest{ Pagination: &query.PageRequest{ - Limit: 7, + Limit: 20, CountTotal: true, }, } @@ -159,7 +159,6 @@ func (suite *KeeperTestSuite) TestQueryClientStates() { expClientStates = nil tc.malleate() - // always add localhost which is created by default in init genesis localhostClientState := suite.chainA.GetClientState(exported.Localhost) identifiedLocalhost := types.NewIdentifiedClientState(exported.Localhost, localhostClientState) diff --git a/modules/light-clients/07-tendermint/types/client_state.go b/modules/light-clients/07-tendermint/types/client_state.go index f4c380f4f8e..bf93cdbf7d5 100644 --- a/modules/light-clients/07-tendermint/types/client_state.go +++ b/modules/light-clients/07-tendermint/types/client_state.go @@ -171,8 +171,8 @@ func (cs ClientState) Initialize(ctx sdk.Context, _ codec.BinaryCodec, clientSto return sdkerrors.Wrapf(clienttypes.ErrInvalidConsensus, "invalid initial consensus state. expected type: %T, got: %T", &ConsensusState{}, consState) } - // set processed time with initial consensus state height equal to initial client state's latest height - SetProcessedTime(clientStore, cs.GetLatestHeight(), uint64(ctx.BlockTime().UnixNano())) + // set metadata for initial consensus state. + setConsensusMetadata(ctx, clientStore, cs.GetLatestHeight()) return nil } diff --git a/modules/light-clients/07-tendermint/types/store.go b/modules/light-clients/07-tendermint/types/store.go index dd6b10dd2ec..ba21e81ba80 100644 --- a/modules/light-clients/07-tendermint/types/store.go +++ b/modules/light-clients/07-tendermint/types/store.go @@ -289,3 +289,20 @@ func bigEndianHeightBytes(height exported.Height) []byte { binary.BigEndian.PutUint64(heightBytes[8:], height.GetRevisionHeight()) return heightBytes } + +// setConsensusMetadata sets context time as processed time and set context height as processed height +// as this is internal tendermint light client logic. +// client state and consensus state will be set by client keeper +// set iteration key to provide ability for efficient ordered iteration of consensus states. +func setConsensusMetadata(ctx sdk.Context, clientStore sdk.KVStore, height exported.Height) { + SetProcessedTime(clientStore, height, uint64(ctx.BlockTime().UnixNano())) + SetProcessedHeight(clientStore, height, clienttypes.GetSelfHeight(ctx)) + SetIterationKey(clientStore, height) +} + +// deleteConsensusMetadata deletes the metadata stored for a particular consensus state. +func deleteConsensusMetadata(clientStore sdk.KVStore, height exported.Height) { + deleteProcessedTime(clientStore, height) + deleteProcessedHeight(clientStore, height) + deleteIterationKey(clientStore, height) +} diff --git a/modules/light-clients/07-tendermint/types/update.go b/modules/light-clients/07-tendermint/types/update.go index c9bbd6f2bad..c70746b4f74 100644 --- a/modules/light-clients/07-tendermint/types/update.go +++ b/modules/light-clients/07-tendermint/types/update.go @@ -134,9 +134,9 @@ func (cs ClientState) CheckHeaderAndUpdateState( } // if pruneHeight is set, delete consensus state and metadata if pruneHeight != nil { + deleteConsensusState(clientStore, pruneHeight) - deleteProcessedTime(clientStore, pruneHeight) - deleteIterationKey(clientStore, pruneHeight) + deleteConsensusMetadata(clientStore, pruneHeight) } newClientState, consensusState := update(ctx, clientStore, &cs, tmHeader) @@ -262,13 +262,3 @@ func update(ctx sdk.Context, clientStore sdk.KVStore, clientState *ClientState, return clientState, consensusState } - -// set context time as processed time and set context height as processed height -// as this is internal tendermint light client logic. -// client state and consensus state will be set by client keeper -// set iteration key to provide ability for efficient ordered iteration of consensus states. -func setConsensusMetadata(ctx sdk.Context, clientStore sdk.KVStore, height exported.Height) { - SetProcessedTime(clientStore, height, uint64(ctx.BlockTime().UnixNano())) - SetProcessedHeight(clientStore, height, clienttypes.GetSelfHeight(ctx)) - SetIterationKey(clientStore, height) -} diff --git a/modules/light-clients/07-tendermint/types/update_test.go b/modules/light-clients/07-tendermint/types/update_test.go index 95a159ef97c..b93168b5166 100644 --- a/modules/light-clients/07-tendermint/types/update_test.go +++ b/modules/light-clients/07-tendermint/types/update_test.go @@ -8,6 +8,7 @@ import ( clienttypes "github.com/cosmos/ibc-go/modules/core/02-client/types" commitmenttypes "github.com/cosmos/ibc-go/modules/core/23-commitment/types" + "github.com/cosmos/ibc-go/modules/core/exported" types "github.com/cosmos/ibc-go/modules/light-clients/07-tendermint/types" ibctesting "github.com/cosmos/ibc-go/testing" ibctestingmock "github.com/cosmos/ibc-go/testing/mock" @@ -377,10 +378,16 @@ func (suite *TendermintTestSuite) TestPruneConsensusState() { path := ibctesting.NewPath(suite.chainA, suite.chainB) suite.coordinator.SetupClients(path) - // call update client twice. When pruning occurs, only first consensus state should be pruned. - // this height will be pruned - path.EndpointA.UpdateClient() - pruneHeight := path.EndpointA.GetClientState().GetLatestHeight() + // get the first height as it will be pruned first. + var pruneHeight exported.Height + getFirstHeightCb := func(height exported.Height) bool { + pruneHeight = height + return true + } + ctx := path.EndpointA.Chain.GetContext() + clientStore := path.EndpointA.Chain.App.GetIBCKeeper().ClientKeeper.ClientStore(ctx, path.EndpointA.ClientID) + err := types.IterateConsensusStateAscending(clientStore, getFirstHeightCb) + suite.Require().Nil(err) // this height will be expired but not pruned path.EndpointA.UpdateClient() @@ -389,8 +396,8 @@ func (suite *TendermintTestSuite) TestPruneConsensusState() { // expected values that must still remain in store after pruning expectedConsState, ok := path.EndpointA.Chain.GetConsensusState(path.EndpointA.ClientID, expiredHeight) suite.Require().True(ok) - ctx := path.EndpointA.Chain.GetContext() - clientStore := path.EndpointA.Chain.App.GetIBCKeeper().ClientKeeper.ClientStore(ctx, path.EndpointA.ClientID) + ctx = path.EndpointA.Chain.GetContext() + clientStore = path.EndpointA.Chain.App.GetIBCKeeper().ClientKeeper.ClientStore(ctx, path.EndpointA.ClientID) expectedProcessTime, ok := types.GetProcessedTime(clientStore, expiredHeight) suite.Require().True(ok) expectedConsKey := types.GetIterationKey(clientStore, expiredHeight) From 40d0ed103cc1ba2ca8e9722a216f164613bb4471 Mon Sep 17 00:00:00 2001 From: Aditya Sripal Date: Fri, 21 May 2021 16:50:59 -0400 Subject: [PATCH 13/15] change param name --- docs/ibc/proto-docs.md | 2 +- modules/core/03-connection/keeper/params.go | 8 +- .../core/03-connection/keeper/params_test.go | 4 +- modules/core/03-connection/keeper/verify.go | 4 +- .../core/03-connection/types/connection.pb.go | 114 +++++++++--------- modules/core/03-connection/types/params.go | 16 +-- proto/ibc/core/connection/v1/connection.proto | 4 +- 7 files changed, 76 insertions(+), 76 deletions(-) diff --git a/docs/ibc/proto-docs.md b/docs/ibc/proto-docs.md index 412530b5d69..def53b54976 100644 --- a/docs/ibc/proto-docs.md +++ b/docs/ibc/proto-docs.md @@ -2408,7 +2408,7 @@ Params defines the set of Connection parameters. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `expected_time_per_block` | [uint64](#uint64) | | expected time per block, used to enforce block delay. | +| `max_expected_time_per_block` | [uint64](#uint64) | | maximum expected time per block, used to enforce block delay. | diff --git a/modules/core/03-connection/keeper/params.go b/modules/core/03-connection/keeper/params.go index 27d59ce32d4..df057f9d093 100644 --- a/modules/core/03-connection/keeper/params.go +++ b/modules/core/03-connection/keeper/params.go @@ -5,16 +5,16 @@ import ( "github.com/cosmos/ibc-go/modules/core/03-connection/types" ) -// GetExpectedTimePerBlock retrieves the expected time per block from the paramstore -func (k Keeper) GetExpectedTimePerBlock(ctx sdk.Context) uint64 { +// GetMaxExpectedTimePerBlock retrieves the maximum expected time per block from the paramstore +func (k Keeper) GetMaxExpectedTimePerBlock(ctx sdk.Context) uint64 { var res uint64 - k.paramSpace.Get(ctx, types.KeyExpectedTimePerBlock, &res) + k.paramSpace.Get(ctx, types.KeyMaxExpectedTimePerBlock, &res) return res } // GetParams returns the total set of ibc-connection parameters. func (k Keeper) GetParams(ctx sdk.Context) types.Params { - return types.NewParams(k.GetExpectedTimePerBlock(ctx)) + return types.NewParams(k.GetMaxExpectedTimePerBlock(ctx)) } // SetParams sets the total set of ibc-connection parameters. diff --git a/modules/core/03-connection/keeper/params_test.go b/modules/core/03-connection/keeper/params_test.go index dc35ba715cf..53ab160c9dc 100644 --- a/modules/core/03-connection/keeper/params_test.go +++ b/modules/core/03-connection/keeper/params_test.go @@ -10,8 +10,8 @@ func (suite *KeeperTestSuite) TestParams() { params := suite.chainA.App.GetIBCKeeper().ConnectionKeeper.GetParams(suite.chainA.GetContext()) suite.Require().Equal(expParams, params) - expParams.ExpectedTimePerBlock = 10 + expParams.MaxExpectedTimePerBlock = 10 suite.chainA.App.GetIBCKeeper().ConnectionKeeper.SetParams(suite.chainA.GetContext(), expParams) params = suite.chainA.App.GetIBCKeeper().ConnectionKeeper.GetParams(suite.chainA.GetContext()) - suite.Require().Equal(uint64(10), expParams.ExpectedTimePerBlock) + suite.Require().Equal(uint64(10), expParams.MaxExpectedTimePerBlock) } diff --git a/modules/core/03-connection/keeper/verify.go b/modules/core/03-connection/keeper/verify.go index 828867502f7..510039740ee 100644 --- a/modules/core/03-connection/keeper/verify.go +++ b/modules/core/03-connection/keeper/verify.go @@ -297,11 +297,11 @@ func (k Keeper) VerifyNextSequenceRecv( } // getBlockDelay calculates the block delay period from the time delay of the connection -// and the expected time per block. +// and the maximum expected time per block. func (k Keeper) getBlockDelay(ctx sdk.Context, connection exported.ConnectionI) uint64 { // expectedTimePerBlock should never be zero, however if it is then return a 0 blcok delay for safety // as the expectedTimePerBlock parameter was not set. - expectedTimePerBlock := k.GetExpectedTimePerBlock(ctx) + expectedTimePerBlock := k.GetMaxExpectedTimePerBlock(ctx) if expectedTimePerBlock == 0 { return 0 } diff --git a/modules/core/03-connection/types/connection.pb.go b/modules/core/03-connection/types/connection.pb.go index b05314d39d9..ae6fc5f0343 100644 --- a/modules/core/03-connection/types/connection.pb.go +++ b/modules/core/03-connection/types/connection.pb.go @@ -356,8 +356,8 @@ var xxx_messageInfo_Version proto.InternalMessageInfo // Params defines the set of Connection parameters. type Params struct { - // expected time per block, used to enforce block delay. - ExpectedTimePerBlock uint64 `protobuf:"varint,1,opt,name=expected_time_per_block,json=expectedTimePerBlock,proto3" json:"expected_time_per_block,omitempty" yaml:"expected_time_per_block"` + // maximum expected time per block, used to enforce block delay. + MaxExpectedTimePerBlock uint64 `protobuf:"varint,1,opt,name=max_expected_time_per_block,json=maxExpectedTimePerBlock,proto3" json:"max_expected_time_per_block,omitempty" yaml:"max_expected_time_per_block"` } func (m *Params) Reset() { *m = Params{} } @@ -393,9 +393,9 @@ func (m *Params) XXX_DiscardUnknown() { var xxx_messageInfo_Params proto.InternalMessageInfo -func (m *Params) GetExpectedTimePerBlock() uint64 { +func (m *Params) GetMaxExpectedTimePerBlock() uint64 { if m != nil { - return m.ExpectedTimePerBlock + return m.MaxExpectedTimePerBlock } return 0 } @@ -416,52 +416,52 @@ func init() { } var fileDescriptor_90572467c054e43a = []byte{ - // 710 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x55, 0xc1, 0x6e, 0xda, 0x4a, - 0x14, 0xc5, 0xc6, 0x10, 0x18, 0xc2, 0x7b, 0xbc, 0x79, 0xe8, 0xc5, 0x42, 0x8a, 0x6d, 0xf9, 0x55, - 0x2a, 0xaa, 0x14, 0x28, 0x89, 0x54, 0xa9, 0xa9, 0xba, 0x08, 0x84, 0x4a, 0x56, 0x5b, 0x8a, 0x0c, - 0xa9, 0x94, 0x6c, 0x90, 0xb1, 0x27, 0x64, 0x14, 0xec, 0x41, 0xf6, 0x80, 0xc2, 0x1f, 0x44, 0x59, - 0x75, 0xdb, 0x45, 0xa4, 0x4a, 0xfd, 0x97, 0x2a, 0xea, 0x2a, 0xcb, 0xae, 0x50, 0x95, 0x6c, 0xbb, - 0xe2, 0x0b, 0x2a, 0x7b, 0x8c, 0x71, 0xa2, 0x66, 0x91, 0xb4, 0xbb, 0x7b, 0xe6, 0x9e, 0x73, 0x98, - 0x7b, 0xb8, 0x0c, 0xe0, 0x31, 0xee, 0x9b, 0x55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 0xe2, 0xe0, 0xf9, 0x00, - 0xd3, 0xa3, 0x71, 0xdf, 0xdf, 0x8f, 0xaa, 0x49, 0x3c, 0x9b, 0x78, 0x55, 0xdc, 0x37, 0x37, 0x06, - 0xa4, 0x6a, 0x13, 0x6b, 0x3c, 0x44, 0x1e, 0x7b, 0xb3, 0x9f, 0x6e, 0x6d, 0xc4, 0xfe, 0x0d, 0xe8, - 0x74, 0x84, 0xbc, 0x7e, 0x3a, 0x78, 0xaf, 0xb7, 0x7e, 0x06, 0x00, 0x00, 0xff, 0xff, 0xdf, 0x28, - 0x7b, 0x4a, 0x31, 0x06, 0x00, 0x00, + // 717 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x55, 0x5f, 0x6b, 0xda, 0x5c, + 0x18, 0x37, 0x31, 0x5a, 0x3d, 0xd6, 0xf7, 0xf5, 0x3d, 0xaf, 0xbc, 0x0d, 0xbe, 0x34, 0x09, 0xd9, + 0xd8, 0x64, 0x50, 0x9d, 0x2d, 0x0c, 0xd6, 0xb1, 0x8b, 0x6a, 0x1d, 0x84, 0x6d, 0x4e, 0xa2, 0x1d, + 0xac, 0x37, 0x12, 0x93, 0x53, 0x7b, 0xa8, 0xc9, 0x91, 0xe4, 0x28, 0xfa, 0x0d, 0x4a, 0xaf, 0x76, + 0xbb, 0x8b, 0xc2, 0x60, 0xdf, 0x65, 0x94, 0x5d, 0xf5, 0x72, 0x57, 0x32, 0xda, 0xdb, 0x5d, 0xf9, + 0x09, 0x46, 0x72, 0xa2, 0xa6, 0x65, 0x1d, 0xb4, 0xdb, 0xdd, 0xf3, 0xe4, 0xf7, 0xc7, 0xe7, 0xf9, + 0xf9, 0x18, 0xc1, 0x43, 0xdc, 0x35, 0xcb, 0x26, 0x71, 0x51, 0xd9, 0x24, 0x8e, 0x83, 0x4c, 0x8a, + 0x89, 0x53, 0x1e, 0x55, 0x22, 0x5d, 0x69, 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0xbb, 0xfe, 0xa9, 0x94, 0x4d, 0xe2, 0xd9, + 0xc4, 0x2b, 0xe3, 0xae, 0xb9, 0xd1, 0x23, 0x65, 0x9b, 0x58, 0xc3, 0x3e, 0xf2, 0xd8, 0xeb, 0xfb, + 0xf1, 0xd6, 0x46, 0xe4, 0x8f, 0x81, 0x4e, 0x06, 0xc8, 0xeb, 0x26, 0x83, 0x57, 0xf7, 0xd6, 0x8f, + 0x00, 0x00, 0x00, 0xff, 0xff, 0xb4, 0x83, 0x45, 0x2b, 0x3c, 0x06, 0x00, 0x00, } func (m *ConnectionEnd) Marshal() (dAtA []byte, err error) { @@ -776,8 +776,8 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if m.ExpectedTimePerBlock != 0 { - i = encodeVarintConnection(dAtA, i, uint64(m.ExpectedTimePerBlock)) + if m.MaxExpectedTimePerBlock != 0 { + i = encodeVarintConnection(dAtA, i, uint64(m.MaxExpectedTimePerBlock)) i-- dAtA[i] = 0x8 } @@ -931,8 +931,8 @@ func (m *Params) Size() (n int) { } var l int _ = l - if m.ExpectedTimePerBlock != 0 { - n += 1 + sovConnection(uint64(m.ExpectedTimePerBlock)) + if m.MaxExpectedTimePerBlock != 0 { + n += 1 + sovConnection(uint64(m.MaxExpectedTimePerBlock)) } return n } @@ -1837,9 +1837,9 @@ func (m *Params) Unmarshal(dAtA []byte) error { switch fieldNum { case 1: if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ExpectedTimePerBlock", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field MaxExpectedTimePerBlock", wireType) } - m.ExpectedTimePerBlock = 0 + m.MaxExpectedTimePerBlock = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowConnection @@ -1849,7 +1849,7 @@ func (m *Params) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.ExpectedTimePerBlock |= uint64(b&0x7F) << shift + m.MaxExpectedTimePerBlock |= uint64(b&0x7F) << shift if b < 0x80 { break } diff --git a/modules/core/03-connection/types/params.go b/modules/core/03-connection/types/params.go index 84589b137bc..904bde60415 100644 --- a/modules/core/03-connection/types/params.go +++ b/modules/core/03-connection/types/params.go @@ -7,11 +7,11 @@ import ( paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" ) -// DefaultTimePerBlock is the default value for expected time per block. +// DefaultTimePerBlock is the default value for maximum expected time per block. const DefaultTimePerBlock = 30 * time.Second -// KeyExpectedTimePerBlock is store's key for ExpectedTimePerBlock parameter -var KeyExpectedTimePerBlock = []byte("ExpectedTimePerBlock") +// KeyMaxExpectedTimePerBlock is store's key for MaxExpectedTimePerBlock parameter +var KeyMaxExpectedTimePerBlock = []byte("MaxExpectedTimePerBlock") // ParamKeyTable type declaration for parameters func ParamKeyTable() paramtypes.KeyTable { @@ -21,7 +21,7 @@ func ParamKeyTable() paramtypes.KeyTable { // NewParams creates a new parameter configuration for the ibc connection module func NewParams(timePerBlock uint64) Params { return Params{ - ExpectedTimePerBlock: timePerBlock, + MaxExpectedTimePerBlock: timePerBlock, } } @@ -30,10 +30,10 @@ func DefaultParams() Params { return NewParams(uint64(DefaultTimePerBlock)) } -// Validate ensures ExpectedTimePerBlock is non-zero +// Validate ensures MaxExpectedTimePerBlock is non-zero func (p Params) Validate() error { - if p.ExpectedTimePerBlock == 0 { - return fmt.Errorf("ExpectedTimePerBlock cannot be zero") + if p.MaxExpectedTimePerBlock == 0 { + return fmt.Errorf("MaxExpectedTimePerBlock cannot be zero") } return nil } @@ -41,7 +41,7 @@ func (p Params) Validate() error { // ParamSetPairs implements params.ParamSet func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { return paramtypes.ParamSetPairs{ - paramtypes.NewParamSetPair(KeyExpectedTimePerBlock, p.ExpectedTimePerBlock, validateParams), + paramtypes.NewParamSetPair(KeyMaxExpectedTimePerBlock, p.MaxExpectedTimePerBlock, validateParams), } } diff --git a/proto/ibc/core/connection/v1/connection.proto b/proto/ibc/core/connection/v1/connection.proto index 2c7f8c482b5..5e6ef2dc1d5 100644 --- a/proto/ibc/core/connection/v1/connection.proto +++ b/proto/ibc/core/connection/v1/connection.proto @@ -107,6 +107,6 @@ message Version { // Params defines the set of Connection parameters. message Params { - // expected time per block, used to enforce block delay. - uint64 expected_time_per_block = 1 [(gogoproto.moretags) = "yaml:\"expected_time_per_block\""]; + // maximum expected time per block, used to enforce block delay. + uint64 max_expected_time_per_block = 1 [(gogoproto.moretags) = "yaml:\"max_expected_time_per_block\""]; } From 780de2964d6d7169f3ecdd89c126b9535eea634b Mon Sep 17 00:00:00 2001 From: Aditya Sripal Date: Fri, 21 May 2021 16:51:48 -0400 Subject: [PATCH 14/15] CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8119e1019a7..e05d119b1fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,6 +62,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (modules/light-clients/07-tendermint) [\#141](https://github.com/cosmos/ibc-go/pull/141) Freeze the client if there's a conflicting header submitted for an existing consensus state. * (modules/core/02-client) [\#8405](https://github.com/cosmos/cosmos-sdk/pull/8405) Refactor IBC client update governance proposals to use a substitute client to update a frozen or expired client. * (modules/core/02-client) [\#8673](https://github.com/cosmos/cosmos-sdk/pull/8673) IBC upgrade logic moved to 02-client and an IBC UpgradeProposal is added. +* (modules/core/03-connection) [\#171](https://github.com/cosmos/ibc-go/pull/171) Introduces a new parameter `MaxExpectedTimePerBlock` to allow connections to calculate and enforce a block delay that is proportional to time delay set by connection. ### Improvements From e00d91f9ae9e4fc7698e6011aec81a52726dfc58 Mon Sep 17 00:00:00 2001 From: Aditya Sripal Date: Fri, 21 May 2021 16:54:38 -0400 Subject: [PATCH 15/15] add param documentation: --- docs/ibc/proto-docs.md | 2 +- modules/core/03-connection/types/connection.pb.go | 4 +++- proto/ibc/core/connection/v1/connection.proto | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/ibc/proto-docs.md b/docs/ibc/proto-docs.md index def53b54976..b098c732179 100644 --- a/docs/ibc/proto-docs.md +++ b/docs/ibc/proto-docs.md @@ -2408,7 +2408,7 @@ Params defines the set of Connection parameters. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `max_expected_time_per_block` | [uint64](#uint64) | | maximum expected time per block, used to enforce block delay. | +| `max_expected_time_per_block` | [uint64](#uint64) | | maximum expected time per block, used to enforce block delay. This parameter should reflect the largest amount of time that the chain might reasonably take to produce the next block under normal operating conditions. A safe choice is 3-5x the expected time per block. | diff --git a/modules/core/03-connection/types/connection.pb.go b/modules/core/03-connection/types/connection.pb.go index ae6fc5f0343..07577489103 100644 --- a/modules/core/03-connection/types/connection.pb.go +++ b/modules/core/03-connection/types/connection.pb.go @@ -356,7 +356,9 @@ var xxx_messageInfo_Version proto.InternalMessageInfo // Params defines the set of Connection parameters. type Params struct { - // maximum expected time per block, used to enforce block delay. + // maximum expected time per block, used to enforce block delay. This parameter should reflect the largest amount of + // time that the chain might reasonably take to produce the next block under normal operating conditions. A safe + // choice is 3-5x the expected time per block. MaxExpectedTimePerBlock uint64 `protobuf:"varint,1,opt,name=max_expected_time_per_block,json=maxExpectedTimePerBlock,proto3" json:"max_expected_time_per_block,omitempty" yaml:"max_expected_time_per_block"` } diff --git a/proto/ibc/core/connection/v1/connection.proto b/proto/ibc/core/connection/v1/connection.proto index 5e6ef2dc1d5..e09f1529d92 100644 --- a/proto/ibc/core/connection/v1/connection.proto +++ b/proto/ibc/core/connection/v1/connection.proto @@ -107,6 +107,8 @@ message Version { // Params defines the set of Connection parameters. message Params { - // maximum expected time per block, used to enforce block delay. + // maximum expected time per block, used to enforce block delay. This parameter should reflect the largest amount of + // time that the chain might reasonably take to produce the next block under normal operating conditions. A safe + // choice is 3-5x the expected time per block. uint64 max_expected_time_per_block = 1 [(gogoproto.moretags) = "yaml:\"max_expected_time_per_block\""]; }