mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-23 09:04:22 +01:00
htlc: keep rval (if known).
This makes struct htlc a complete object, containing its own information. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -19,6 +19,8 @@ struct htlc {
|
||||
struct abs_locktime expiry;
|
||||
/* The hash of the preimage which can redeem this HTLC */
|
||||
struct sha256 rhash;
|
||||
/* The preimage which hashes to rhash (if known) */
|
||||
struct rval *r;
|
||||
|
||||
/* FIXME: We could union these together: */
|
||||
/* Routing information sent with this HTLC. */
|
||||
|
||||
13
daemon/pay.c
13
daemon/pay.c
@@ -16,21 +16,19 @@ struct pay_command {
|
||||
struct command *cmd;
|
||||
};
|
||||
|
||||
void complete_pay_command(struct peer *peer,
|
||||
struct htlc *htlc,
|
||||
const struct rval *rval)
|
||||
void complete_pay_command(struct peer *peer, struct htlc *htlc)
|
||||
{
|
||||
struct pay_command *i;
|
||||
|
||||
list_for_each(&peer->pay_commands, i, list) {
|
||||
if (i->htlc == htlc) {
|
||||
if (rval) {
|
||||
if (htlc->r) {
|
||||
struct json_result *response;
|
||||
|
||||
response = new_json_result(i->cmd);
|
||||
json_object_start(response, NULL);
|
||||
json_add_hex(response, "preimage",
|
||||
rval->r, sizeof(rval->r));
|
||||
htlc->r, sizeof(*htlc->r));
|
||||
json_object_end(response);
|
||||
command_success(i->cmd, response);
|
||||
} else {
|
||||
@@ -39,10 +37,11 @@ void complete_pay_command(struct peer *peer,
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Can happen if RPC connection goes away. */
|
||||
log_unusual(peer->log, "No command for HTLC %"PRIu64" %s",
|
||||
htlc->id, rval ? "fulfill" : "fail");
|
||||
}
|
||||
htlc->id, htlc->r ? "fulfill" : "fail");
|
||||
}
|
||||
|
||||
static void remove_from_list(struct pay_command *pc)
|
||||
{
|
||||
|
||||
@@ -6,8 +6,6 @@ struct peer;
|
||||
struct htlc;
|
||||
struct rval;
|
||||
|
||||
void complete_pay_command(struct peer *peer,
|
||||
struct htlc *htlc,
|
||||
const struct rval *rval);
|
||||
void complete_pay_command(struct peer *peer, struct htlc *htlc);
|
||||
|
||||
#endif /* LIGHTNING_DAEMON_PAY_H */
|
||||
|
||||
@@ -561,6 +561,9 @@ static bool command_htlc_fulfill(struct peer *peer,
|
||||
struct htlc *htlc,
|
||||
const struct rval *r)
|
||||
{
|
||||
assert(!htlc->r);
|
||||
htlc->r = tal_dup(htlc, struct rval, r);
|
||||
|
||||
if (!state_can_remove_htlc(peer->state))
|
||||
return false;
|
||||
|
||||
@@ -904,6 +907,7 @@ struct htlc *peer_new_htlc(struct peer *peer,
|
||||
h->id = id;
|
||||
h->msatoshis = msatoshis;
|
||||
h->rhash = *rhash;
|
||||
h->r = NULL;
|
||||
if (!blocks_to_abs_locktime(expiry, &h->expiry))
|
||||
fatal("Invalid HTLC expiry %u", expiry);
|
||||
h->routing = tal_dup_arr(h, u8, route, routelen, 0);
|
||||
@@ -1633,8 +1637,11 @@ void our_htlc_fulfilled(struct peer *peer, struct htlc *htlc,
|
||||
{
|
||||
if (htlc->src)
|
||||
command_htlc_fulfill(htlc->src->peer, htlc->src, preimage);
|
||||
else
|
||||
complete_pay_command(peer, htlc, preimage);
|
||||
else {
|
||||
assert(!htlc->r);
|
||||
htlc->r = tal_dup(htlc, struct rval, preimage);
|
||||
complete_pay_command(peer, htlc);
|
||||
}
|
||||
}
|
||||
|
||||
static void their_htlc_depth(struct peer *peer,
|
||||
@@ -2449,7 +2456,7 @@ static void our_htlc_failed(struct peer *peer, struct htlc *htlc)
|
||||
if (htlc->src)
|
||||
command_htlc_fail(htlc->src->peer, htlc->src);
|
||||
else
|
||||
complete_pay_command(peer, htlc, NULL);
|
||||
complete_pay_command(peer, htlc);
|
||||
}
|
||||
|
||||
/* When changes are committed to. */
|
||||
|
||||
Reference in New Issue
Block a user