|
@ -148,6 +148,7 @@ static void fail_out_htlc(struct htlc_out *hout, const char *localfail) |
|
|
{ |
|
|
{ |
|
|
htlc_out_check(hout, __func__); |
|
|
htlc_out_check(hout, __func__); |
|
|
assert(hout->failcode || hout->failuremsg); |
|
|
assert(hout->failcode || hout->failuremsg); |
|
|
|
|
|
|
|
|
if (hout->am_origin) { |
|
|
if (hout->am_origin) { |
|
|
payment_failed(hout->key.channel->peer->ld, hout, localfail); |
|
|
payment_failed(hout->key.channel->peer->ld, hout, localfail); |
|
|
} else if (hout->in) { |
|
|
} else if (hout->in) { |
|
@ -374,9 +375,19 @@ static void rcvd_htlc_reply(struct subd *subd, const u8 *msg, const int *fds UNU |
|
|
(int)tal_count(failurestr), |
|
|
(int)tal_count(failurestr), |
|
|
(const char *)failurestr); |
|
|
(const char *)failurestr); |
|
|
payment_failed(ld, hout, localfail); |
|
|
payment_failed(ld, hout, localfail); |
|
|
} else if (hout->in) |
|
|
|
|
|
|
|
|
} else if (hout->in) { |
|
|
local_fail_htlc(hout->in, failure_code, |
|
|
local_fail_htlc(hout->in, failure_code, |
|
|
hout->key.channel->scid); |
|
|
hout->key.channel->scid); |
|
|
|
|
|
|
|
|
|
|
|
/* here we haven't called connect_htlc_out(),
|
|
|
|
|
|
* so set htlc field with NULL */ |
|
|
|
|
|
wallet_forwarded_payment_add(ld->wallet, |
|
|
|
|
|
hout->in, NULL, |
|
|
|
|
|
FORWARD_LOCAL_FAILED, |
|
|
|
|
|
failure_code); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/* Prevent hout from being failed twice. */ |
|
|
/* Prevent hout from being failed twice. */ |
|
|
tal_del_destructor(hout, destroy_hout_subd_died); |
|
|
tal_del_destructor(hout, destroy_hout_subd_died); |
|
|
tal_free(hout); |
|
|
tal_free(hout); |
|
@ -468,10 +479,15 @@ static void forward_htlc(struct htlc_in *hin, |
|
|
struct amount_msat fee; |
|
|
struct amount_msat fee; |
|
|
struct lightningd *ld = hin->key.channel->peer->ld; |
|
|
struct lightningd *ld = hin->key.channel->peer->ld; |
|
|
struct channel *next = active_channel_by_id(ld, next_hop, NULL); |
|
|
struct channel *next = active_channel_by_id(ld, next_hop, NULL); |
|
|
|
|
|
struct htlc_out *hout = NULL; |
|
|
|
|
|
|
|
|
/* Unknown peer, or peer not ready. */ |
|
|
/* Unknown peer, or peer not ready. */ |
|
|
if (!next || !next->scid) { |
|
|
if (!next || !next->scid) { |
|
|
local_fail_htlc(hin, WIRE_UNKNOWN_NEXT_PEER, NULL); |
|
|
local_fail_htlc(hin, WIRE_UNKNOWN_NEXT_PEER, NULL); |
|
|
|
|
|
wallet_forwarded_payment_add(hin->key.channel->peer->ld->wallet, |
|
|
|
|
|
hin, NULL, |
|
|
|
|
|
FORWARD_LOCAL_FAILED, |
|
|
|
|
|
hin->failcode); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -535,14 +551,26 @@ static void forward_htlc(struct htlc_in *hin, |
|
|
goto fail; |
|
|
goto fail; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
hout = tal(tmpctx, struct htlc_out); |
|
|
failcode = 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, &hout); |
|
|
if (!failcode) |
|
|
if (!failcode) |
|
|
return; |
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
/* In fact, we didn't get the new htlc_out in these 2 cases */ |
|
|
|
|
|
if (failcode == WIRE_UNKNOWN_NEXT_PEER || |
|
|
|
|
|
failcode == WIRE_TEMPORARY_CHANNEL_FAILURE) { |
|
|
|
|
|
tal_free(hout); |
|
|
|
|
|
hout = NULL; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
fail: |
|
|
fail: |
|
|
local_fail_htlc(hin, failcode, next->scid); |
|
|
local_fail_htlc(hin, failcode, next->scid); |
|
|
|
|
|
wallet_forwarded_payment_add(ld->wallet, |
|
|
|
|
|
hin, hout, |
|
|
|
|
|
FORWARD_LOCAL_FAILED, |
|
|
|
|
|
hin->failcode); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/* Temporary information, while we resolve the next hop */ |
|
|
/* Temporary information, while we resolve the next hop */ |
|
@ -570,6 +598,10 @@ static void channel_resolve_reply(struct subd *gossip, const u8 *msg, |
|
|
|
|
|
|
|
|
if (!peer_id) { |
|
|
if (!peer_id) { |
|
|
local_fail_htlc(gr->hin, WIRE_UNKNOWN_NEXT_PEER, NULL); |
|
|
local_fail_htlc(gr->hin, WIRE_UNKNOWN_NEXT_PEER, NULL); |
|
|
|
|
|
wallet_forwarded_payment_add(gr->hin->key.channel->peer->ld->wallet, |
|
|
|
|
|
gr->hin, NULL, |
|
|
|
|
|
FORWARD_LOCAL_FAILED, |
|
|
|
|
|
gr->hin->failcode); |
|
|
tal_free(gr); |
|
|
tal_free(gr); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
@ -717,7 +749,7 @@ static void fulfill_our_htlc_out(struct channel *channel, struct htlc_out *hout, |
|
|
else if (hout->in) { |
|
|
else if (hout->in) { |
|
|
fulfill_htlc(hout->in, preimage); |
|
|
fulfill_htlc(hout->in, preimage); |
|
|
wallet_forwarded_payment_add(ld->wallet, hout->in, hout, |
|
|
wallet_forwarded_payment_add(ld->wallet, hout->in, hout, |
|
|
FORWARD_SETTLED); |
|
|
FORWARD_SETTLED, 0); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -810,7 +842,8 @@ static bool peer_failed_our_htlc(struct channel *channel, |
|
|
htlc_out_check(hout, __func__); |
|
|
htlc_out_check(hout, __func__); |
|
|
|
|
|
|
|
|
if (hout->in) |
|
|
if (hout->in) |
|
|
wallet_forwarded_payment_add(ld->wallet, hout->in, hout, FORWARD_FAILED); |
|
|
wallet_forwarded_payment_add(ld->wallet, hout->in, |
|
|
|
|
|
hout, FORWARD_FAILED, hout->failcode); |
|
|
|
|
|
|
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
@ -845,9 +878,14 @@ void onchain_failed_our_htlc(const struct channel *channel, |
|
|
why); |
|
|
why); |
|
|
payment_failed(ld, hout, localfail); |
|
|
payment_failed(ld, hout, localfail); |
|
|
tal_free(localfail); |
|
|
tal_free(localfail); |
|
|
} else if (hout->in) |
|
|
} else if (hout->in) { |
|
|
local_fail_htlc(hout->in, WIRE_PERMANENT_CHANNEL_FAILURE, |
|
|
local_fail_htlc(hout->in, WIRE_PERMANENT_CHANNEL_FAILURE, |
|
|
hout->key.channel->scid); |
|
|
hout->key.channel->scid); |
|
|
|
|
|
wallet_forwarded_payment_add(hout->key.channel->peer->ld->wallet, |
|
|
|
|
|
hout->in, hout, |
|
|
|
|
|
FORWARD_LOCAL_FAILED, |
|
|
|
|
|
hout->failcode); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
static void remove_htlc_in(struct channel *channel, struct htlc_in *hin) |
|
|
static void remove_htlc_in(struct channel *channel, struct htlc_in *hin) |
|
@ -967,9 +1005,10 @@ static bool update_out_htlc(struct channel *channel, |
|
|
channel->dbid, |
|
|
channel->dbid, |
|
|
hout->msat); |
|
|
hout->msat); |
|
|
|
|
|
|
|
|
if (hout->in) |
|
|
if (hout->in) { |
|
|
wallet_forwarded_payment_add(ld->wallet, hout->in, hout, |
|
|
wallet_forwarded_payment_add(ld->wallet, hout->in, hout, |
|
|
FORWARD_OFFERED); |
|
|
FORWARD_OFFERED, 0); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/* For our own HTLCs, we commit payment to db lazily */ |
|
|
/* For our own HTLCs, we commit payment to db lazily */ |
|
|
if (hout->origin_htlc_id == 0) |
|
|
if (hout->origin_htlc_id == 0) |
|
@ -1396,6 +1435,11 @@ void peer_got_revoke(struct channel *channel, const u8 *msg) |
|
|
|
|
|
|
|
|
hin = find_htlc_in(&ld->htlcs_in, channel, changed[i].id); |
|
|
hin = find_htlc_in(&ld->htlcs_in, channel, changed[i].id); |
|
|
local_fail_htlc(hin, failcodes[i], NULL); |
|
|
local_fail_htlc(hin, failcodes[i], NULL); |
|
|
|
|
|
// in fact, now we don't know if this htlc is a forward or localpay!
|
|
|
|
|
|
wallet_forwarded_payment_add(ld->wallet, |
|
|
|
|
|
hin, NULL, |
|
|
|
|
|
FORWARD_LOCAL_FAILED, |
|
|
|
|
|
hin->failcode); |
|
|
} |
|
|
} |
|
|
wallet_channel_save(ld->wallet, channel); |
|
|
wallet_channel_save(ld->wallet, channel); |
|
|
} |
|
|
} |
|
@ -1870,6 +1914,7 @@ static void listforwardings_add_forwardings(struct json_stream *response, struct |
|
|
cur->fee, |
|
|
cur->fee, |
|
|
"fee", "fee_msat"); |
|
|
"fee", "fee_msat"); |
|
|
json_add_string(response, "status", forward_status_name(cur->status)); |
|
|
json_add_string(response, "status", forward_status_name(cur->status)); |
|
|
|
|
|
|
|
|
#ifdef COMPAT_V070 |
|
|
#ifdef COMPAT_V070 |
|
|
/* If a forwarding doesn't have received_time it was created
|
|
|
/* If a forwarding doesn't have received_time it was created
|
|
|
* before we added the tracking, do not include it here. */ |
|
|
* before we added the tracking, do not include it here. */ |
|
|