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
address the rest
  • Loading branch information
AdityaSripal committed May 12, 2021
commit 20a0803100be792c374f2fe32e13055802fbd9eb
4 changes: 2 additions & 2 deletions modules/core/03-connection/keeper/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
34 changes: 18 additions & 16 deletions modules/core/03-connection/keeper/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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)))
}