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
FungibleTokenPacketDataup the module stack.If the
FungibleTokenPacketData'smemofield is not JSON or does not have a "forward" key, it passes it up the module stack.If the
memofield 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
ProcessedKeyis unset or set to false in the context (see Finding ref↗),receiveFundsreceives 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
DisableDenomCompositionKeyis 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'sforwardTimeoutas a default.If the metadata does not specify an amount of retries, it uses the
IBCMiddleware'sretriesOnTimeoutas a default.It invokes the
Keeper.ForwardTransferPacketfunction 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/OnTimeoutPacketfor the forwarded packet.
Function: OnAcknowledgementPacket
The OnAcknowledgementPacket function does the following:
It passes acknowledgments for packets of types other than
FungibleTokenPacketDataup the module stack.If the acknowledgment data does not unmarshal as an
Acknowledgement, it returns an error.It calls
Keeper.GetAndClearInFlightPacketto get the packetInFlightDataand number of remaining retries.If the
InFlightDatais present, it calls and returns the result ofKeeper.WriteAcknowledgementForForwardedPacket.If the
InFlightDatais 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
FungibleTokenPacketDataup the module stack.It retrieves the
InFlightDataviaKeeper.TimeoutShouldRetry.If the
InFlightDatais out of retries, it removes it viaRemoveInFlightPacketand notifies the previous hop of the error withKeeper.WriteAcknowledgementForForwardedPacket.If the
InFlightDatahas 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.