-
Notifications
You must be signed in to change notification settings - Fork 586
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
refactor: allow ICA authentication module provided timeout timestamp values #726
Changes from all commits
d8302de
de9aa19
7c39cab
9634000
486b572
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,9 +10,12 @@ import ( | |
channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" | ||
) | ||
|
||
// TrySendTx takes in a transaction from an authentication module and attempts to send the packet | ||
// if the base application has the capability to send on the provided portID | ||
func (k Keeper) TrySendTx(ctx sdk.Context, chanCap *capabilitytypes.Capability, portID string, icaPacketData icatypes.InterchainAccountPacketData) (uint64, error) { | ||
// TrySendTx takes pre-built packet data containing messages to be executed on the host chain from an authentication module and attempts to send the packet. | ||
// The packet sequence for the outgoing packet is returned as a result. | ||
// If the base application has the capability to send on the provided portID. An appropriate | ||
// absolute timeoutTimestamp must be provided. If the packet is timed out, the channel will be closed. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are there any pros or cons in using an absolute timestamp instead of relative? I am asking because for the transfer cli we have a relative timestamp, right? Maybe it's good to be consistent (if possible) on using either relative or absolute, but not a mix. |
||
// In the case of channel closure, a new channel may be reopened to reconnect to the host chain. | ||
func (k Keeper) TrySendTx(ctx sdk.Context, chanCap *capabilitytypes.Capability, portID string, icaPacketData icatypes.InterchainAccountPacketData, timeoutTimestamp uint64) (uint64, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This requires also a spec change, right? I am keeping track of all the changes so that we don't miss any. |
||
// Check for the active channel | ||
activeChannelID, found := k.GetActiveChannelID(ctx, portID) | ||
if !found { | ||
|
@@ -27,7 +30,11 @@ func (k Keeper) TrySendTx(ctx sdk.Context, chanCap *capabilitytypes.Capability, | |
destinationPort := sourceChannelEnd.GetCounterparty().GetPortID() | ||
destinationChannel := sourceChannelEnd.GetCounterparty().GetChannelID() | ||
|
||
return k.createOutgoingPacket(ctx, portID, activeChannelID, destinationPort, destinationChannel, chanCap, icaPacketData) | ||
if uint64(ctx.BlockTime().UnixNano()) >= timeoutTimestamp { | ||
return 0, icatypes.ErrInvalidTimeoutTimestamp | ||
} | ||
|
||
return k.createOutgoingPacket(ctx, portID, activeChannelID, destinationPort, destinationChannel, chanCap, icaPacketData, timeoutTimestamp) | ||
} | ||
|
||
func (k Keeper) createOutgoingPacket( | ||
|
@@ -38,6 +45,7 @@ func (k Keeper) createOutgoingPacket( | |
destinationChannel string, | ||
chanCap *capabilitytypes.Capability, | ||
icaPacketData icatypes.InterchainAccountPacketData, | ||
timeoutTimestamp uint64, | ||
) (uint64, error) { | ||
if err := icaPacketData.ValidateBasic(); err != nil { | ||
return 0, sdkerrors.Wrap(err, "invalid interchain account packet data") | ||
|
@@ -49,10 +57,6 @@ func (k Keeper) createOutgoingPacket( | |
return 0, sdkerrors.Wrapf(channeltypes.ErrSequenceSendNotFound, "failed to retrieve next sequence send for channel %s on port %s", sourceChannel, sourcePort) | ||
} | ||
|
||
// timeoutTimestamp is set to be a max number here so that we never recieve a timeout | ||
// ics-27-1 uses ordered channels which can close upon recieving a timeout, which is an undesired effect | ||
const timeoutTimestamp = ^uint64(0) >> 1 // Shift the unsigned bit to satisfy hermes relayer timestamp conversion | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. glad this is gone 😆 |
||
|
||
packet := channeltypes.NewPacket( | ||
icaPacketData.GetBytes(), | ||
sequence, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, I noticed this was missing the other day! I have a draft almost ready for review with some more doc updates/improvements :)