Pkt *accept_pkt_htlc_fulfill(struct peer *peer, const Pkt *pkt) { const UpdateFulfillHtlc *f = pkt->update_fulfill_htlc; size_t n_us, n_them; struct sha256 r, rhash; Pkt *err; err = find_commited_htlc(peer, f->id, &n_us, &n_them); if (err) return err; /* Now, it must solve the HTLC rhash puzzle. */ proto_to_sha256(f->r, &r); sha256(&rhash, &r, sizeof(r)); if (!structeq(&rhash, &peer->us.staging_cstate->a.htlcs[n_us].rhash)) return pkt_err(peer, "Invalid r for %"PRIu64, f->id); /* Same ID must have same rhash */ assert(structeq(&rhash, &peer->them.staging_cstate->b.htlcs[n_them].rhash)); funding_a_fulfill_htlc(peer->us.staging_cstate, n_us); funding_b_fulfill_htlc(peer->them.staging_cstate, n_them); return NULL; }
Pkt *accept_pkt_htlc_fail(struct peer *peer, const Pkt *pkt) { const UpdateFailHtlc *f = pkt->update_fail_htlc; struct htlc *htlc; Pkt *err; union htlc_staging stage; err = find_commited_htlc(peer, f->id, &htlc); if (err) return err; /* FIXME: Save reason. */ cstate_fail_htlc(peer->local.staging_cstate, htlc, OURS); /* BOLT #2: * * ... and the receiving node MUST add the HTLC fulfill/fail * to the unacked changeset for its local commitment. */ stage.fail.fail = HTLC_FAIL; stage.fail.htlc = htlc; add_unacked(&peer->local, &stage); return NULL; }
Pkt *accept_pkt_htlc_fail(struct peer *peer, const Pkt *pkt) { const UpdateFailHtlc *f = pkt->update_fail_htlc; size_t n_us, n_them; Pkt *err; err = find_commited_htlc(peer, f->id, &n_us, &n_them); if (err) return err; /* FIXME: Save reason. */ funding_a_fail_htlc(peer->us.staging_cstate, n_us); funding_b_fail_htlc(peer->them.staging_cstate, n_them); return NULL; }
Pkt *accept_pkt_htlc_fulfill(struct peer *peer, const Pkt *pkt) { const UpdateFulfillHtlc *f = pkt->update_fulfill_htlc; struct htlc *htlc; struct sha256 rhash; struct rval r; Pkt *err; union htlc_staging stage; err = find_commited_htlc(peer, f->id, &htlc); if (err) return err; /* Now, it must solve the HTLC rhash puzzle. */ proto_to_rval(f->r, &r); sha256(&rhash, &r, sizeof(r)); 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 * to the unacked changeset for its local commitment. */ cstate_fulfill_htlc(peer->local.staging_cstate, htlc, OURS); stage.fulfill.fulfill = HTLC_FULFILL; stage.fulfill.htlc = htlc; stage.fulfill.r = r; add_unacked(&peer->local, &stage); return NULL; }