Skip to content

Commit

Permalink
apply new param to keeper code
Browse files Browse the repository at this point in the history
  • Loading branch information
shaspitz committed Sep 18, 2023
1 parent 5d7ab92 commit 2d46f4d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
6 changes: 1 addition & 5 deletions x/ccv/consumer/keeper/throttle_retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package keeper

import (
"fmt"
"time"

sdktypes "github.com/cosmos/cosmos-sdk/types"

Expand Down Expand Up @@ -44,9 +43,6 @@ import (
// This design is implemented below, and in relay.go under SendPackets() and OnAcknowledgementPacket().
//

// Retry delay period could be implemented as a param, but 1 hour is reasonable
const RetryDelayPeriod = time.Hour

// PacketSendingPermitted returns whether the consumer is allowed to send packets
// from the pending packets queue.
func (k Keeper) PacketSendingPermitted(ctx sdktypes.Context) bool {
Expand All @@ -60,7 +56,7 @@ func (k Keeper) PacketSendingPermitted(ctx sdktypes.Context) bool {
return false
}
// If retry delay period has elapsed, we can send again
return ctx.BlockTime().After(record.SendTime.Add(RetryDelayPeriod))
return ctx.BlockTime().After(record.SendTime.Add(k.GetRetryDelayPeriod(ctx)))
}

func (k Keeper) UpdateSlashRecordOnSend(ctx sdktypes.Context) {
Expand Down
7 changes: 5 additions & 2 deletions x/ccv/consumer/keeper/throttle_retry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ import (
"github.com/stretchr/testify/require"

testutil "github.com/cosmos/interchain-security/v3/testutil/keeper"
consumerkeeper "github.com/cosmos/interchain-security/v3/x/ccv/consumer/keeper"
consumertypes "github.com/cosmos/interchain-security/v3/x/ccv/consumer/types"
ccvtypes "github.com/cosmos/interchain-security/v3/x/ccv/types"
)

func TestPacketSendingPermitted(t *testing.T) {
consumerKeeper, ctx, ctrl, _ := testutil.GetConsumerKeeperAndCtx(t, testutil.NewInMemKeeperParams(t))
defer ctrl.Finish()

consumerKeeper.SetParams(ctx, ccvtypes.DefaultParams())

ctx = ctx.WithBlockTime(time.Now())

// No slash record exists, send is permitted
Expand Down Expand Up @@ -42,7 +44,8 @@ func TestPacketSendingPermitted(t *testing.T) {
require.False(t, consumerKeeper.PacketSendingPermitted(ctx))

// Elapse retry delay period
ctx = ctx.WithBlockTime(ctx.BlockTime().Add(2 * consumerkeeper.RetryDelayPeriod))
period := consumerKeeper.GetRetryDelayPeriod(ctx)
ctx = ctx.WithBlockTime(ctx.BlockTime().Add(2 * period))

// Now packet sending is permitted again
require.True(t, consumerKeeper.PacketSendingPermitted(ctx))
Expand Down

0 comments on commit 2d46f4d

Please sign in to comment.