From 31a5de644a232a1813e0f52ca0eae945afc22567 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 30 Jun 2016 09:08:11 +0930 Subject: [PATCH] daemon: route fulfill back. As soon as an HTLC we offered is fulfilled, fulfill the HTLC which caused it. Signed-off-by: Rusty Russell --- daemon/packets.c | 3 +++ daemon/peer.c | 12 +++++++----- daemon/peer.h | 4 +++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/daemon/packets.c b/daemon/packets.c index 45f2c6935..d0116679b 100644 --- a/daemon/packets.c +++ b/daemon/packets.c @@ -737,6 +737,9 @@ Pkt *accept_pkt_htlc_fulfill(struct peer *peer, const Pkt *pkt) if (!structeq(&rhash, &htlc->rhash)) return pkt_err(peer, "Invalid r for %"PRIu64, f->id); + /* We can relay this upstream immediately. */ + our_htlc_fulfilled(peer, htlc, &r); + /* BOLT #2: * * ... and the receiving node MUST add the HTLC fulfill/fail diff --git a/daemon/peer.c b/daemon/peer.c index 1d74ce005..d88749636 100644 --- a/daemon/peer.c +++ b/daemon/peer.c @@ -43,8 +43,6 @@ #include #include -#define FIXME_STUB(peer) do { log_broken((peer)->dstate->base_log, "%s:%u: Implement %s!", __FILE__, __LINE__, __func__); abort(); } while(0) - struct json_connecting { /* This owns us, so we're freed after command_fail or command_success */ 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* * 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, @@ -2514,7 +2516,7 @@ void peer_both_committed_to(struct peer *peer, their_htlc_added(peer, changes[i].add.htlc); break; case HTLC_FULFILL: - /* FIXME: resolve_one_htlc(peer, id, preimage); */ + /* We handled this as soon as we got it. */ break; case HTLC_FAIL: our_htlc_failed(peer, changes[i].fail.htlc); diff --git a/daemon/peer.h b/daemon/peer.h index de0e4171d..5d69d162b 100644 --- a/daemon/peer.h +++ b/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 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 */