Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block Delay Parameter #171

Merged
merged 18 commits into from
May 21, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix tm tests
  • Loading branch information
AdityaSripal committed May 17, 2021
commit aeca52d11cb39ea01581a3e06015472140650dda
1 change: 1 addition & 0 deletions modules/core/03-connection/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions modules/core/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{})
AdityaSripal marked this conversation as resolved.
Show resolved Hide resolved
paramSpace = paramSpace.WithKeyTable(keyTable)
}

clientKeeper := clientkeeper.NewKeeper(cdc, key, paramSpace, stakingKeeper, upgradeKeeper)
connectionKeeper := connectionkeeper.NewKeeper(cdc, key, paramSpace, clientKeeper)
portKeeper := portkeeper.NewKeeper(scopedKeeper)
Expand Down
172 changes: 124 additions & 48 deletions modules/light-clients/07-tendermint/types/client_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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{}
Expand Down Expand Up @@ -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,
)

Expand All @@ -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 {
Expand All @@ -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{}
Expand Down Expand Up @@ -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(),
)

Expand All @@ -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 {
Expand All @@ -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{}
Expand Down Expand Up @@ -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(),
)

Expand All @@ -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 {
Expand All @@ -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{}
Expand Down Expand Up @@ -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,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down