Pull out the HTLC forwarding loop into a function