|
@ -359,15 +359,28 @@ static bool rcvd_htlc_reply(struct subd *subd, const u8 *msg, const int *fds, |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
struct htlc_out *send_htlc_out(struct peer *out, u64 amount, u32 cltv, |
|
|
enum onion_type send_htlc_out(struct peer *out, u64 amount, u32 cltv, |
|
|
const struct sha256 *payment_hash, |
|
|
const struct sha256 *payment_hash, |
|
|
const u8 *onion_routing_packet, |
|
|
const u8 *onion_routing_packet, |
|
|
struct htlc_in *in, |
|
|
struct htlc_in *in, |
|
|
struct pay_command *pc) |
|
|
struct pay_command *pc, |
|
|
|
|
|
struct htlc_out **houtp) |
|
|
{ |
|
|
{ |
|
|
struct htlc_out *hout; |
|
|
struct htlc_out *hout; |
|
|
u8 *msg; |
|
|
u8 *msg; |
|
|
|
|
|
|
|
|
|
|
|
if (!peer_can_add_htlc(out)) { |
|
|
|
|
|
log_info(out->log, "Attempt to send HTLC but not ready (%s)", |
|
|
|
|
|
peer_state_name(out->state)); |
|
|
|
|
|
return WIRE_UNKNOWN_NEXT_PEER; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!out->owner) { |
|
|
|
|
|
log_info(out->log, "Attempt to send HTLC but unowned (%s)", |
|
|
|
|
|
peer_state_name(out->state)); |
|
|
|
|
|
return WIRE_TEMPORARY_CHANNEL_FAILURE; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/* Make peer's daemon own it, catch if it dies. */ |
|
|
/* Make peer's daemon own it, catch if it dies. */ |
|
|
hout = new_htlc_out(out->owner, out, amount, cltv, |
|
|
hout = new_htlc_out(out->owner, out, amount, cltv, |
|
|
payment_hash, onion_routing_packet, in, pc); |
|
|
payment_hash, onion_routing_packet, in, pc); |
|
@ -376,7 +389,10 @@ struct htlc_out *send_htlc_out(struct peer *out, u64 amount, u32 cltv, |
|
|
msg = towire_channel_offer_htlc(out, amount, cltv, payment_hash, |
|
|
msg = towire_channel_offer_htlc(out, amount, cltv, payment_hash, |
|
|
onion_routing_packet); |
|
|
onion_routing_packet); |
|
|
subd_req(out->ld, out->owner, take(msg), -1, 0, rcvd_htlc_reply, hout); |
|
|
subd_req(out->ld, out->owner, take(msg), -1, 0, rcvd_htlc_reply, hout); |
|
|
return hout; |
|
|
|
|
|
|
|
|
if (houtp) |
|
|
|
|
|
*houtp = hout; |
|
|
|
|
|
return 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
static void forward_htlc(struct htlc_in *hin, |
|
|
static void forward_htlc(struct htlc_in *hin, |
|
@ -397,20 +413,6 @@ static void forward_htlc(struct htlc_in *hin, |
|
|
goto fail; |
|
|
goto fail; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (!peer_can_add_htlc(next)) { |
|
|
|
|
|
log_info(next->log, "Attempt to forward HTLC but not ready (%s)", |
|
|
|
|
|
peer_state_name(next->state)); |
|
|
|
|
|
failcode = WIRE_UNKNOWN_NEXT_PEER; |
|
|
|
|
|
goto fail; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!next->owner) { |
|
|
|
|
|
log_info(next->log, "Attempt to forward HTLC but unowned (%s)", |
|
|
|
|
|
peer_state_name(next->state)); |
|
|
|
|
|
failcode = WIRE_TEMPORARY_CHANNEL_FAILURE; |
|
|
|
|
|
goto fail; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* BOLT #7:
|
|
|
/* BOLT #7:
|
|
|
* |
|
|
* |
|
|
* The node creating `channel_update` SHOULD accept HTLCs which pay a |
|
|
* The node creating `channel_update` SHOULD accept HTLCs which pay a |
|
@ -456,9 +458,10 @@ static void forward_htlc(struct htlc_in *hin, |
|
|
goto fail; |
|
|
goto fail; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
send_htlc_out(next, amt_to_forward, |
|
|
failcode = send_htlc_out(next, amt_to_forward, |
|
|
outgoing_cltv_value, &hin->payment_hash, |
|
|
outgoing_cltv_value, &hin->payment_hash, |
|
|
next_onion, hin, NULL); |
|
|
next_onion, hin, NULL, NULL); |
|
|
|
|
|
if (!failcode) |
|
|
return; |
|
|
return; |
|
|
|
|
|
|
|
|
fail: |
|
|
fail: |
|
|