Type: IBCMiddleware
The IBCMiddleware
type implements the IBCModule
and ICS4Wrapper
interfaces, and it has nontrivial implementations of {OnRecvPacket, OnAcknowledgementPacket, OnTimeoutPacket}
. All the other methods for the IBCModule
interface pass the arguments unmodified to the middleware's app
's corresponding methods, and all the methods for the ICS4Wrapper
interface pass the arguments unmodified to the middleware's keeper
's corresponding methods.
Function: OnRecvPacket
The OnRecvPacket
function does the following:
It passes packets of types other than
FungibleTokenPacketData
up the module stack.If the
FungibleTokenPacketData
'smemo
field is not JSON or does not have a "forward" key, it passes it up the module stack.If the
memo
field does not unmarshal as aPacketMetadata
, it acknowledges the packet with an error.If the metadata specifies an empty receiver, invalid port, or invalid channel, it acknowledges the packet with an error.
It computes the temporary address
Bech32(SHA256(SHA256("packetforwardmiddleware") || packet.DestinationChannel || "/" || data.Sender))
.If
ProcessedKey
is unset or set to false in the context (see Finding ref↗),receiveFunds
receives the transfer by passing a modified packet (with the replaced recipient and an empty memo) to receive the funds to the temporary address on the current chain; if an error occurs in receiving the transfer (including a deferred acknowledgment), it acknowledges the original packet with an error.If
DisableDenomCompositionKey
is unset or set to false in the context, it removes the counterparty's path prefix from the denom and converts it to a native denom if no path remains.If the metadata specifies a nonpositive time-out duration, it uses the
IBCMiddleware
'sforwardTimeout
as a default.If the metadata does not specify an amount of retries, it uses the
IBCMiddleware
'sretriesOnTimeout
as a default.It invokes the
Keeper.ForwardTransferPacket
function to forward the packet with the above modifications to the next chain; if an error occurs in forwarding the packet, it acknowledges the original packet with an error.It does not synchronously acknowledge the packet; it defers acknowledgment to
OnAcknowledgementPacket
/OnTimeoutPacket
for the forwarded packet.
Function: OnAcknowledgementPacket
The OnAcknowledgementPacket
function does the following:
It passes acknowledgments for packets of types other than
FungibleTokenPacketData
up the module stack.If the acknowledgment data does not unmarshal as an
Acknowledgement
, it returns an error.It calls
Keeper.GetAndClearInFlightPacket
to get the packetInFlightData
and number of remaining retries.If the
InFlightData
is present, it calls and returns the result ofKeeper.WriteAcknowledgementForForwardedPacket
.If the
InFlightData
is absent, it passes the acknowledgment up the module stack.
Function: OnTimeoutPacket
The OnTimeoutPacket
function does the following:
It passes time-outs for packets of types other than
FungibleTokenPacketData
up the module stack.It retrieves the
InFlightData
viaKeeper.TimeoutShouldRetry
.If the
InFlightData
is out of retries, it removes it viaRemoveInFlightPacket
and notifies the previous hop of the error withKeeper.WriteAcknowledgementForForwardedPacket
.If the
InFlightData
has remaining retries, it handles the underlying time-out on the current chain and then callsKeeper.RetryTimeout
.If there is no
InFlightData
, it passes the time-out up the module stack.