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

Change UpgradeTimeout to from absolute to relative #4511

Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions modules/core/04-channel/keeper/timeout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ func (suite *KeeperTestSuite) TestTimeoutExecuted() {
channel.State = types.FLUSHING
path.EndpointA.SetChannel(channel)
path.EndpointA.SetChannelCounterpartyUpgrade(types.Upgrade{
Timeout: types.DefaultTimeout,
Timeout: types.NewTimeout(clienttypes.ZeroHeight(), uint64(suite.chainA.GetContext().BlockTime().UnixNano())+types.DefaultTimeout.Timestamp),
})
},
func(packetCommitment []byte, err error) {
Expand Down Expand Up @@ -422,10 +422,10 @@ func (suite *KeeperTestSuite) TestTimeoutExecuted() {
path.EndpointA.SetChannel(channel)
path.EndpointA.SetChannelUpgrade(types.Upgrade{
Fields: path.EndpointA.GetProposedUpgrade().Fields,
Timeout: types.DefaultTimeout,
Timeout: types.NewTimeout(clienttypes.ZeroHeight(), uint64(suite.chainA.GetContext().BlockTime().UnixNano())+types.DefaultTimeout.Timestamp),
})
path.EndpointA.SetChannelCounterpartyUpgrade(types.Upgrade{
Timeout: types.DefaultTimeout,
Timeout: types.NewTimeout(clienttypes.ZeroHeight(), uint64(suite.chainB.GetContext().BlockTime().UnixNano())+types.DefaultTimeout.Timestamp),
})
},
func(packetCommitment []byte, err error) {
Expand Down
13 changes: 5 additions & 8 deletions modules/core/04-channel/keeper/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -769,19 +769,16 @@ func (k Keeper) startFlushing(ctx sdk.Context, portID, channelID string, upgrade
}

upgrade.LatestSequenceSend = nextSequenceSend - 1
upgrade.Timeout = k.getUpgradeTimeout(ctx)
upgrade.Timeout = k.getAbsoluteUpgradeTimeout(ctx)
k.SetUpgrade(ctx, portID, channelID, *upgrade)

return nil
}

// getUpgradeTimeout returns the absolute timeout for the given upgrade.
func (k Keeper) getUpgradeTimeout(ctx sdk.Context) types.Timeout {
// relativeTimeout := k.GetParams(ctx).UpgradeTimeout
// absoluteTimeoutHeight := clienttypes.NewHeight(clienttypes.ParseChainID(ctx.ChainID()), uint64(ctx.BlockHeight())+relativeTimeout.Height.RevisionHeight)
// absoluteTimeoutTimestamp := uint64(ctx.BlockTime().UnixNano()) + relativeTimeout.Timestamp
// return types.NewTimeout(absoluteTimeoutHeight, absoluteTimeoutTimestamp)
return k.GetParams(ctx).UpgradeTimeout
// getAbsoluteUpgradeTimeout returns the absolute timeout for the given upgrade.
func (k Keeper) getAbsoluteUpgradeTimeout(ctx sdk.Context) types.Timeout {
upgradeTimeout := k.GetParams(ctx).UpgradeTimeout
return types.NewTimeout(clienttypes.ZeroHeight(), uint64(ctx.BlockTime().UnixNano())+upgradeTimeout.Timestamp)
}

// syncUpgradeSequence ensures current upgrade handshake only continues if both channels are using the same upgrade sequence,
Expand Down
4 changes: 3 additions & 1 deletion modules/core/04-channel/keeper/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1764,7 +1764,9 @@ func (suite *KeeperTestSuite) TestStartFlush() {
suite.Require().Equal(types.FLUSHING, channel.State)
suite.Require().Equal(nextSequenceSend-1, upgrade.LatestSequenceSend)

suite.Require().Equal(types.DefaultTimeout, upgrade.Timeout)
expectedTimeoutTimestamp := types.DefaultTimeout.Timestamp + uint64(suite.chainB.GetContext().BlockTime().UnixNano())
suite.Require().Equal(expectedTimeoutTimestamp, upgrade.Timeout.Timestamp)
suite.Require().Equal(clienttypes.ZeroHeight(), upgrade.Timeout.Height, "only timestamp should be set")
suite.Require().NoError(err)
}
})
Expand Down
4 changes: 2 additions & 2 deletions modules/core/04-channel/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
)

// TODO: determine sane default value for upgrade timeout. and make this relative.
// TODO: determine sane default value for upgrade timeout.

var DefaultTimeout = NewTimeout(clienttypes.ZeroHeight(), uint64(time.Now().Add(time.Hour).UnixNano()))
var DefaultTimeout = NewTimeout(clienttypes.ZeroHeight(), uint64(time.Hour.Nanoseconds()))

// NewParams creates a new parameter configuration for the channel submodule
func NewParams(upgradeTimeout Timeout) Params {
Expand Down
Loading