Browse Source

daemon: route fulfill back.

As soon as an HTLC we offered is fulfilled, fulfill the HTLC which
caused it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 9 years ago
parent
commit
31a5de644a
  1. 3
      daemon/packets.c
  2. 12
      daemon/peer.c
  3. 4
      daemon/peer.h

3
daemon/packets.c

@ -737,6 +737,9 @@ Pkt *accept_pkt_htlc_fulfill(struct peer *peer, const Pkt *pkt)
if (!structeq(&rhash, &htlc->rhash)) if (!structeq(&rhash, &htlc->rhash))
return pkt_err(peer, "Invalid r for %"PRIu64, f->id); return pkt_err(peer, "Invalid r for %"PRIu64, f->id);
/* We can relay this upstream immediately. */
our_htlc_fulfilled(peer, htlc, &r);
/* BOLT #2: /* BOLT #2:
* *
* ... and the receiving node MUST add the HTLC fulfill/fail * ... and the receiving node MUST add the HTLC fulfill/fail

12
daemon/peer.c

@ -43,8 +43,6 @@
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/types.h> #include <sys/types.h>
#define FIXME_STUB(peer) do { log_broken((peer)->dstate->base_log, "%s:%u: Implement %s!", __FILE__, __LINE__, __func__); abort(); } while(0)
struct json_connecting { struct json_connecting {
/* This owns us, so we're freed after command_fail or command_success */ /* This owns us, so we're freed after command_fail or command_success */
struct command *cmd; struct command *cmd;
@ -1635,9 +1633,13 @@ static void resolve_our_htlcs(struct peer *peer,
* preimage. Otherwise, the other node could spend it once it as *timed out* * preimage. Otherwise, the other node could spend it once it as *timed out*
* as above. * as above.
*/ */
bool resolve_one_htlc(struct peer *peer, u64 id, const struct rval *preimage) void our_htlc_fulfilled(struct peer *peer, struct htlc *htlc,
const struct rval *preimage)
{ {
FIXME_STUB(peer); if (htlc->src)
command_htlc_fulfill(htlc->src->peer, htlc->src, preimage);
else
complete_pay_command(peer, htlc, preimage);
} }
static void their_htlc_depth(struct peer *peer, static void their_htlc_depth(struct peer *peer,
@ -2514,7 +2516,7 @@ void peer_both_committed_to(struct peer *peer,
their_htlc_added(peer, changes[i].add.htlc); their_htlc_added(peer, changes[i].add.htlc);
break; break;
case HTLC_FULFILL: case HTLC_FULFILL:
/* FIXME: resolve_one_htlc(peer, id, preimage); */ /* We handled this as soon as we got it. */
break; break;
case HTLC_FAIL: case HTLC_FAIL:
our_htlc_failed(peer, changes[i].fail.htlc); our_htlc_failed(peer, changes[i].fail.htlc);

4
daemon/peer.h

@ -269,5 +269,7 @@ struct bitcoin_tx *peer_create_close_tx(struct peer *peer, u64 fee);
uint64_t commit_tx_fee(const struct bitcoin_tx *commit, uint64_t commit_tx_fee(const struct bitcoin_tx *commit,
uint64_t anchor_satoshis); uint64_t anchor_satoshis);
bool resolve_one_htlc(struct peer *peer, u64 id, const struct rval *preimage); void our_htlc_fulfilled(struct peer *peer, struct htlc *htlc,
const struct rval *preimage);
#endif /* LIGHTNING_DAEMON_PEER_H */ #endif /* LIGHTNING_DAEMON_PEER_H */

Loading…
Cancel
Save