lightningd: record why a local forward failed in listforwards
What changed, and why it matters
This commit adds a new 'failure_reason' field to the listforwards RPC output and forward_event notification. It records why a local HTLC forward failed (for example, not enough outgoing liquidity, too many HTLCs, or the peer cannot afford the commitment fee). It is primarily an observability and diagnostics improvement, not a security fix or vulnerability.
No security action required. Treat as a normal feature/observability improvement. Reviewers may want to confirm that the new database column and wire field are handled correctly during downgrade scenarios, as the code already includes a fallback for unknown enum values.
Security signals we found
New enum classifies local forward failures for diagnostics
Database migration adds nullable 'reason' column to forwards table
Wire message channeld_offer_htlc_reply extended with reason field
No change to HTLC acceptance logic, only to failure metadata
New test cases verify failure_reason values for various local failure scenarios
Evidence from the diff
The change introduces enum forward_failure_reason, plumbs it through channeld ↔ lightningd wire messages, stores it in the wallet ‘forwards’ table via a migration, and exposes it in JSON-RPC, notifications, gRPC/Protobuf, and generated language bindings. It also splits CHANNEL_ERR_CHANNEL_CAPACITY_EXCEEDED into a new CHANNEL_ERR_OPENER_CANNOT_AFFORD_FEE so that failures caused by the peer’s inability to pay commitment fees are classified distinctly from the node’s own liquidity shortage. No protocol rules, cryptographic checks, or authorization boundaries are modified.
Changed components
lightningd/forwards.clightningd/peer_htlcs.cchanneld/channeld.cchanneld/full_channel.cwallet/wallet.cwallet/migrations.ccommon/forward_failure_reason.hdoc/schemas/listforwards.jsondoc/schemas/notification/forward_event.jsoncln-grpc/proto/node.protocln-rpc/src/model.rscln-rpc/src/notifications.rsInspect captured patch +1585 / −863
### .msggen.json
@@ -135,6 +135,24 @@
"perkb": 0,
"perkw": 1
},
+ "ForwardEventFailureReason": {
+ "channel_failed_permanent": 11,
+ "channel_shutting_down": 13,
+ "cltv_expiry_too_far": 8,
+ "cltv_expiry_too_soon": 7,
+ "cltv_incorrect": 6,
+ "dust_limit": 2,
+ "fee_insufficient": 5,
+ "htlc_above_maximum": 4,
+ "htlc_below_minimum": 3,
+ "insufficient_outgoing_liquidity": 0,
+ "invalid_onion": 12,
+ "max_htlc_value_in_flight": 14,
+ "outgoing_peer_offline": 10,
+ "peer_cannot_afford_fee": 15,
+ "too_many_htlcs": 1,
+ "unknown_next_peer": 9
+ },
"ForwardEventStatus": {
"failed": 3,
"local_failed": 2,
@@ -242,6 +260,24 @@
"ListconfigsConfigsConfSource": {
"cmdline": 0
},
+ "ListforwardsForwardsFailureReason": {
+ "channel_failed_permanent": 11,
+ "channel_shutting_down": 13,
+ "cltv_expiry_too_far": 8,
+ "cltv_expiry_too_soon": 7,
+ "cltv_incorrect": 6,
+ "dust_limit": 2,
+ "fee_insufficient": 5,
+ "htlc_above_maximum": 4,
+ "htlc_below_minimum": 3,
+ "insufficient_outgoing_liquidity": 0,
+ "invalid_onion": 12,
+ "max_htlc_value_in_flight": 14,
+ "outgoing_peer_offline": 10,
+ "peer_cannot_afford_fee": 15,
+ "too_many_htlcs": 1,
+ "unknown_next_peer": 9
+ },
"ListforwardsForwardsStatus": {
"failed": 3,
"local_failed": 2,
@@ -2015,6 +2051,7 @@
"ForwardEventNotification": {
"forward_event.failcode": 8,
"forward_event.failreason": 9,
+ "forward_event.failure_reason": 13,
"forward_event.fee_msat": 6,
"forward_event.in_channel": 2,
"forward_event.in_msat": 4,
@@ -3067,6 +3104,7 @@
"ListForwards.forwards[].created_index": 12,
"ListForwards.forwards[].failcode": 15,
"ListForwards.forwards[].failreason": 16,
+ "ListForwards.forwards[].failure_reason": 17,
"ListForwards.forwards[].fee_msat": 7,
"ListForwards.forwards[].in_channel": 1,
"ListForwards.forwards[].in_htlc_id": 10,
@@ -11161,6 +11199,10 @@
"added": "pre-v0.10.1",
"deprecated": null
},
+ "ListForwards.forwards[].failure_reason": {
+ "added": "v26.12",
+ "deprecated": null
+ },
"ListForwards.forwards[].fee_msat": {
"added": "pre-v0.10.1",
"deprecated": null
@@ -15745,6 +15787,10 @@
"added": "pre-v0.10.1",
"deprecated": null
},
+ "forward_event.failure_reason": {
+ "added": "v26.12",
+ "deprecated": null
+ },
"forward_event.fee_msat": {
"added": "pre-v0.10.1",
"deprecated": null
### channeld/channeld.c
@@ -24,6 +24,7 @@
#include <channeld/watchtower.h>
#include <common/billboard.h>
#include <common/ecdh_hsmd.h>
+#include <common/forward_failure_reason.h>
#include <common/interactivetx.h>
#include <common/key_derive.h>
#include <common/memleak.h>
@@ -6578,6 +6579,7 @@ static void handle_offer_htlc(struct peer *peer, const u8 *inmsg)
enum channel_add_err e;
const u8 *failwiremsg;
const char *failstr;
+ enum forward_failure_reason reason = FORWARD_FAIL_UNKNOWN;
struct amount_sat htlc_fee;
struct pubkey *path_key;
struct tlv_field *extra_tlvs;
@@ -6640,13 +6642,14 @@ static void handle_offer_htlc(struct peer *peer, const u8 *inmsg)
start_commit_timer(peer);
/* Tell the master. */
msg = towire_channeld_offer_htlc_reply(NULL, peer->htlc_id,
- 0, "");
+ 0, "", FORWARD_FAIL_UNKNOWN);
wire_sync_write(MASTER_FD, take(msg));
peer->htlc_id++;
return;
case CHANNEL_ERR_INVALID_EXPIRY:
failwiremsg = towire_incorrect_cltv_expiry(inmsg, cltv_expiry, NULL);
failstr = tal_fmt(inmsg, "Invalid cltv_expiry %u", cltv_expiry);
+ reason = FORWARD_FAIL_CLTV_INCORRECT;
goto failed;
case CHANNEL_ERR_DUPLICATE:
case CHANNEL_ERR_DUPLICATE_ID_DIFFERENT:
@@ -6656,25 +6659,36 @@ static void handle_offer_htlc(struct peer *peer, const u8 *inmsg)
case CHANNEL_ERR_MAX_HTLC_VALUE_EXCEEDED:
failwiremsg = towire_required_node_feature_missing(inmsg);
failstr = "Mini mode: maximum value exceeded";
+ reason = FORWARD_FAIL_HTLC_ABOVE_MAXIMUM;
goto failed;
case CHANNEL_ERR_MAX_HTLC_VALUE_IN_FLIGHT_EXCEEDED:
failwiremsg = towire_temporary_channel_failure(inmsg, NULL);
failstr = "Aggregate value of committed HTLCs would exceed max_htlc_value_in_flight_msat";
+ reason = FORWARD_FAIL_MAX_HTLC_VALUE_IN_FLIGHT;
goto failed;
/* FIXME: Fuzz the boundaries a bit to avoid probing? */
case CHANNEL_ERR_CHANNEL_CAPACITY_EXCEEDED:
failwiremsg = towire_temporary_channel_failure(inmsg, NULL);
failstr = tal_fmt(inmsg, "Capacity exceeded - HTLC fee: %s", fmt_amount_sat(inmsg, htlc_fee));
+ reason = FORWARD_FAIL_INSUFFICIENT_OUTGOING_LIQUIDITY;
+ goto failed;
+ case CHANNEL_ERR_OPENER_CANNOT_AFFORD_FEE:
+ failwiremsg = towire_temporary_channel_failure(inmsg, NULL);
+ failstr = tal_fmt(inmsg, "Peer (opener) cannot afford commitment fee - HTLC fee: %s",
+ fmt_amount_sat(inmsg, htlc_fee));
+ reason = FORWARD_FAIL_PEER_CANNOT_AFFORD_FEE;
goto failed;
case CHANNEL_ERR_HTLC_BELOW_MINIMUM:
failwiremsg = towire_amount_below_minimum(inmsg, amount, NULL);
failstr = tal_fmt(inmsg, "HTLC too small (%s minimum)",
fmt_amount_msat(tmpctx,
peer->channel->config[REMOTE].htlc_minimum));
+ reason = FORWARD_FAIL_HTLC_BELOW_MINIMUM;
goto failed;
case CHANNEL_ERR_TOO_MANY_HTLCS:
failwiremsg = towire_temporary_channel_failure(inmsg, NULL);
failstr = "Too many HTLCs";
+ reason = FORWARD_FAIL_TOO_MANY_HTLCS;
goto failed;
case CHANNEL_ERR_DUST_FAILURE:
/* BOLT-919 #2:
@@ -6685,14 +6699,15 @@ static void handle_offer_htlc(struct peer *peer, const u8 *inmsg)
*/
failwiremsg = towire_temporary_channel_failure(inmsg, NULL);
failstr = "HTLC too dusty, allowed dust limit reached";
+ reason = FORWARD_FAIL_DUST_LIMIT;
goto failed;
}
/* Shouldn't return anything else! */
abort();
failed:
/* lightningd appends update to this for us */
- msg = towire_channeld_offer_htlc_reply(NULL, 0, failwiremsg, failstr);
+ msg = towire_channeld_offer_htlc_reply(NULL, 0, failwiremsg, failstr, reason);
wire_sync_write(MASTER_FD, take(msg));
}
### channeld/channeld_wire.csv
@@ -110,6 +110,9 @@ msgdata,channeld_offer_htlc_reply,id,u64,
msgdata,channeld_offer_htlc_reply,len,u16,
msgdata,channeld_offer_htlc_reply,failuremsg,u8,len
msgdata,channeld_offer_htlc_reply,failurestr,wirestring,
+# enum forward_failure_reason (common/forward_failure_reason.h) - root cause
+# of the failure, 0 (FORWARD_FAIL_UNKNOWN) on success or if unclassified
+msgdata,channeld_offer_htlc_reply,reason,u8,
# Main daemon found out the preimage for an HTLC
#include <bitcoin/preimage.h>
### channeld/full_channel.c
@@ -836,16 +836,23 @@ static enum channel_add_err add_htlc(struct channel *channel,
/* Try not to add a payment which will take opener into fees
* on either our side or theirs. */
if (sender == LOCAL) {
+ /* If they opened the channel, their balance pays for
+ * the extra output, so this isn't our liquidity */
+ enum channel_add_err fee_err
+ = channel->opener == sender
+ ? CHANNEL_ERR_CHANNEL_CAPACITY_EXCEEDED
+ : CHANNEL_ERR_OPENER_CANNOT_AFFORD_FEE;
+
if (!get_room_above_reserve(channel, view,
adding, removing,
channel->opener,
&remainder))
- return CHANNEL_ERR_CHANNEL_CAPACITY_EXCEEDED;
+ return fee_err;
if ((option_anchor_outputs || option_anchors_zero_fee_htlc_tx)
&& channel->opener != sender
&& !amount_msat_deduct_sat(&remainder, AMOUNT_SAT(660)))
- return CHANNEL_ERR_CHANNEL_CAPACITY_EXCEEDED;
+ return fee_err;
/* Should be able to afford both their own commit tx
* fee, and other's commit tx fee, which are subtly
@@ -862,7 +869,7 @@ static enum channel_add_err add_htlc(struct channel *channel,
status_debug("Funder could not afford own fee %s with %s above reserve",
fmt_amount_sat(tmpctx, fee),
fmt_amount_msat(tmpctx, remainder));
- return CHANNEL_ERR_CHANNEL_CAPACITY_EXCEEDED;
+ return fee_err;
}
fee = fee_for_htlcs(channel,
committed,
@@ -876,7 +883,7 @@ static enum channel_add_err add_htlc(struct channel *channel,
status_debug("Funder could not afford peer's fee `%s with %s above reserve",
fmt_amount_sat(tmpctx, fee),
fmt_amount_msat(tmpctx, remainder));
- return CHANNEL_ERR_CHANNEL_CAPACITY_EXCEEDED;
+ return fee_err;
}
}
}
### channeld/full_channel_error.h
@@ -17,6 +17,9 @@ enum channel_add_err {
CHANNEL_ERR_MAX_HTLC_VALUE_IN_FLIGHT_EXCEEDED,
/* Can't afford it */
CHANNEL_ERR_CHANNEL_CAPACITY_EXCEEDED,
+ /* The remote opener can't afford the commitment fee (or anchors)
+ * for one more HTLC output, although we can afford the HTLC */
+ CHANNEL_ERR_OPENER_CANNOT_AFFORD_FEE,
/* HTLC is below htlc_minimum_msat */
CHANNEL_ERR_HTLC_BELOW_MINIMUM,
/* HTLC would push past max_accepted_htlcs */
### cln-grpc/proto/node.proto
@@ -2345,6 +2345,25 @@ message ListforwardsResponse {
}
message ListforwardsForwards {
+ // ListForwards.forwards[].failure_reason
+ enum ListforwardsForwardsFailureReason {
+ INSUFFICIENT_OUTGOING_LIQUIDITY = 0;
+ TOO_MANY_HTLCS = 1;
+ DUST_LIMIT = 2;
+ HTLC_BELOW_MINIMUM = 3;
+ HTLC_ABOVE_MAXIMUM = 4;
+ FEE_INSUFFICIENT = 5;
+ CLTV_INCORRECT = 6;
+ CLTV_EXPIRY_TOO_SOON = 7;
+ CLTV_EXPIRY_TOO_FAR = 8;
+ UNKNOWN_NEXT_PEER = 9;
+ OUTGOING_PEER_OFFLINE = 10;
+ CHANNEL_FAILED_PERMANENT = 11;
+ INVALID_ONION = 12;
+ CHANNEL_SHUTTING_DOWN = 13;
+ MAX_HTLC_VALUE_IN_FLIGHT = 14;
+ PEER_CANNOT_AFFORD_FEE = 15;
+ }
// ListForwards.forwards[].status
enum ListforwardsForwardsStatus {
OFFERED = 0;
@@ -2372,6 +2391,7 @@ message ListforwardsForwards {
optional double resolved_time = 14;
optional uint32 failcode = 15;
optional string failreason = 16;
+ optional ListforwardsForwardsFailureReason failure_reason = 17;
}
message ListoffersRequest {
@@ -4838,6 +4858,25 @@ message StreamForwardEventRequest {
}
message ForwardEventNotification {
+ // forward_event.failure_reason
+ enum ForwardEventFailureReason {
+ INSUFFICIENT_OUTGOING_LIQUIDITY = 0;
+ TOO_MANY_HTLCS = 1;
+ DUST_LIMIT = 2;
+ HTLC_BELOW_MINIMUM = 3;
+ HTLC_ABOVE_MAXIMUM = 4;
+ FEE_INSUFFICIENT = 5;
+ CLTV_INCORRECT = 6;
+ CLTV_EXPIRY_TOO_SOON = 7;
+ CLTV_EXPIRY_TOO_FAR = 8;
+ UNKNOWN_NEXT_PEER = 9;
+ OUTGOING_PEER_OFFLINE = 10;
+ CHANNEL_FAILED_PERMANENT = 11;
+ INVALID_ONION = 12;
+ CHANNEL_SHUTTING_DOWN = 13;
+ MAX_HTLC_VALUE_IN_FLIGHT = 14;
+ PEER_CANNOT_AFFORD_FEE = 15;
+ }
// forward_event.status
enum ForwardEventStatus {
OFFERED = 0;
@@ -4862,6 +4901,7 @@ message ForwardEventNotification {
optional ForwardEventStyle style = 10;
double received_time = 11;
optional double resolved_time = 12;
+ optional ForwardEventFailureReason failure_reason = 13;
}
message StreamInvoiceCreationRequest {
### cln-grpc/src/convert.rs
@@ -2266,6 +2266,7 @@ impl From<responses::ListforwardsForwards> for pb::ListforwardsForwards {
created_index: c.created_index, // Rule #2 for type u64
failcode: c.failcode, // Rule #2 for type u32?
failreason: c.failreason, // Rule #2 for type string?
+ failure_reason: c.failure_reason.map(|v| v as i32),
fee_msat: c.fee_msat.map(|f| f.into()), // Rule #2 for type msat?
in_channel: c.in_channel.to_string(), // Rule #2 for type short_channel_id
in_htlc_id: c.in_htlc_id, // Rule #2 for type u64?
@@ -5252,6 +5253,7 @@ impl From<notifications::ForwardEventNotification> for pb::ForwardEventNotificat
Self {
failcode: c.failcode, // Rule #2 for type u32?
failreason: c.failreason, // Rule #2 for type string?
+ failure_reason: c.failure_reason.map(|v| v as i32),
fee_msat: c.fee_msat.map(|f| f.into()), // Rule #2 for type msat?
in_channel: c.in_channel.to_string(), // Rule #2 for type short_channel_id
in_msat: Some(c.in_msat.into()), // Rule #2 for type msat
### cln-rpc/src/model.rs
@@ -9336,6 +9336,92 @@ pub mod responses {
}
}
+ /// ['The root cause of the failure, more specific than *failcode*/*failreason*. Only set for *local_failed* forwards, and not always known.', '*insufficient_outgoing_liquidity* means our own spendable balance on the outgoing channel was too low; *peer_cannot_afford_fee* means the peer opened the outgoing channel and cannot pay the commitment fee for another HTLC.']
+ #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
+ #[allow(non_camel_case_types)]
+ pub enum ListforwardsForwardsFailureReason {
+ #[serde(rename = "insufficient_outgoing_liquidity")]
+ INSUFFICIENT_OUTGOING_LIQUIDITY = 0,
+ #[serde(rename = "too_many_htlcs")]
+ TOO_MANY_HTLCS = 1,
+ #[serde(rename = "dust_limit")]
+ DUST_LIMIT = 2,
+ #[serde(rename = "htlc_below_minimum")]
+ HTLC_BELOW_MINIMUM = 3,
+ #[serde(rename = "htlc_above_maximum")]
+ HTLC_ABOVE_MAXIMUM = 4,
+ #[serde(rename = "fee_insufficient")]
+ FEE_INSUFFICIENT = 5,
+ #[serde(rename = "cltv_incorrect")]
+ CLTV_INCORRECT = 6,
+ #[serde(rename = "cltv_expiry_too_soon")]
+ CLTV_EXPIRY_TOO_SOON = 7,
+ #[serde(rename = "cltv_expiry_too_far")]
+ CLTV_EXPIRY_TOO_FAR = 8,
+ #[serde(rename = "unknown_next_peer")]
+ UNKNOWN_NEXT_PEER = 9,
+ #[serde(rename = "outgoing_peer_offline")]
+ OUTGOING_PEER_OFFLINE = 10,
+ #[serde(rename = "channel_failed_permanent")]
+ CHANNEL_FAILED_PERMANENT = 11,
+ #[serde(rename = "invalid_onion")]
+ INVALID_ONION = 12,
+ #[serde(rename = "channel_shutting_down")]
+ CHANNEL_SHUTTING_DOWN = 13,
+ #[serde(rename = "max_htlc_value_in_flight")]
+ MAX_HTLC_VALUE_IN_FLIGHT = 14,
+ #[serde(rename = "peer_cannot_afford_fee")]
+ PEER_CANNOT_AFFORD_FEE = 15,
+ }
+
+ impl TryFrom<i32> for ListforwardsForwardsFailureReason {
+ type Error = anyhow::Error;
+ fn try_from(c: i32) -> Result<ListforwardsForwardsFailureReason, anyhow::Error> {
+ match c {
+ 0 => Ok(ListforwardsForwardsFailureReason::INSUFFICIENT_OUTGOING_LIQUIDITY),
+ 1 => Ok(ListforwardsForwardsFailureReason::TOO_MANY_HTLCS),
+ 2 => Ok(ListforwardsForwardsFailureReason::DUST_LIMIT),
+ 3 => Ok(ListforwardsForwardsFailureReason::HTLC_BELOW_MINIMUM),
+ 4 => Ok(ListforwardsForwardsFailureReason::HTLC_ABOVE_MAXIMUM),
+ 5 => Ok(ListforwardsForwardsFailureReason::FEE_INSUFFICIENT),
+ 6 => Ok(ListforwardsForwardsFailureReason::CLTV_INCORRECT),
+ 7 => Ok(ListforwardsForwardsFailureReason::CLTV_EXPIRY_TOO_SOON),
+ 8 => Ok(ListforwardsForwardsFailureReason::CLTV_EXPIRY_TOO_FAR),
+ 9 => Ok(ListforwardsForwardsFailureReason::UNKNOWN_NEXT_PEER),
+ 10 => Ok(ListforwardsForwardsFailureReason::OUTGOING_PEER_OFFLINE),
+ 11 => Ok(ListforwardsForwardsFailureReason::CHANNEL_FAILED_PERMANENT),
+ 12 => Ok(ListforwardsForwardsFailureReason::INVALID_ONION),
+ 13 => Ok(ListforwardsForwardsFailureReason::CHANNEL_SHUTTING_DOWN),
+ 14 => Ok(ListforwardsForwardsFailureReason::MAX_HTLC_VALUE_IN_FLIGHT),
+ 15 => Ok(ListforwardsForwardsFailureReason::PEER_CANNOT_AFFORD_FEE),
+ o => Err(anyhow::anyhow!("Unknown variant {} for enum ListforwardsForwardsFailureReason", o)),
+ }
+ }
+ }
+
+ impl ToString for ListforwardsForwardsFailureReason {
+ fn to_string(&self) -> String {
+ match self {
+ ListforwardsForwardsFailureReason::INSUFFICIENT_OUTGOING_LIQUIDITY => "INSUFFICIENT_OUTGOING_LIQUIDITY",
+ ListforwardsForwardsFailureReason::TOO_MANY_HTLCS => "TOO_MANY_HTLCS",
+ ListforwardsForwardsFailureReason::DUST_LIMIT => "DUST_LIMIT",
+ ListforwardsForwardsFailureReason::HTLC_BELOW_MINIMUM => "HTLC_BELOW_MINIMUM",
+ ListforwardsForwardsFailureReason::HTLC_ABOVE_MAXIMUM => "HTLC_ABOVE_MAXIMUM",
+ ListforwardsForwardsFailureReason::FEE_INSUFFICIENT => "FEE_INSUFFICIENT",
+ ListforwardsForwardsFailureReason::CLTV_INCORRECT => "CLTV_INCORRECT",
+ ListforwardsForwardsFailureReason::CLTV_EXPIRY_TOO_SOON => "CLTV_EXPIRY_TOO_SOON",
+ ListforwardsForwardsFailureReason::CLTV_EXPIRY_TOO_FAR => "CLTV_EXPIRY_TOO_FAR",
+ ListforwardsForwardsFailureReason::UNKNOWN_NEXT_PEER => "UNKNOWN_NEXT_PEER",
+ ListforwardsForwardsFailureReason::OUTGOING_PEER_OFFLINE => "OUTGOING_PEER_OFFLINE",
+ ListforwardsForwardsFailureReason::CHANNEL_FAILED_PERMANENT => "CHANNEL_FAILED_PERMANENT",
+ ListforwardsForwardsFailureReason::INVALID_ONION => "INVALID_ONION",
+ ListforwardsForwardsFailureReason::CHANNEL_SHUTTING_DOWN => "CHANNEL_SHUTTING_DOWN",
+ ListforwardsForwardsFailureReason::MAX_HTLC_VALUE_IN_FLIGHT => "MAX_HTLC_VALUE_IN_FLIGHT",
+ ListforwardsForwardsFailureReason::PEER_CANNOT_AFFORD_FEE => "PEER_CANNOT_AFFORD_FEE",
+ }.to_string()
+ }
+ }
+
/// ['Either a legacy onion format or a modern tlv format.']
#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
#[allow(non_camel_case_types)]
@@ -9411,6 +9497,8 @@ pub mod responses {
#[serde(skip_serializing_if = "Option::is_none")]
pub failreason: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
+ pub failure_reason: Option<ListforwardsForwardsFailureReason>,
+ #[serde(skip_serializing_if = "Option::is_none")]
pub fee_msat: Option<Amount>,
#[serde(skip_serializing_if = "Option::is_none")]
pub in_htlc_id: Option<u64>,
### cln-rpc/src/notifications.rs
@@ -466,6 +466,92 @@ pub struct DisconnectNotification {
pub id: PublicKey,
}
+/// ['The root cause of the failure, more specific than *failcode*/*failreason*. Only set for *local_failed* forwards, and not always known.', '*insufficient_outgoing_liquidity* means our own spendable balance on the outgoing channel was too low; *peer_cannot_afford_fee* means the peer opened the outgoing channel and cannot pay the commitment fee for another HTLC.']
+#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
+#[allow(non_camel_case_types)]
+pub enum ForwardEventFailureReason {
+ #[serde(rename = "insufficient_outgoing_liquidity")]
+ INSUFFICIENT_OUTGOING_LIQUIDITY = 0,
+ #[serde(rename = "too_many_htlcs")]
+ TOO_MANY_HTLCS = 1,
+ #[serde(rename = "dust_limit")]
+ DUST_LIMIT = 2,
+ #[serde(rename = "htlc_below_minimum")]
+ HTLC_BELOW_MINIMUM = 3,
+ #[serde(rename = "htlc_above_maximum")]
+ HTLC_ABOVE_MAXIMUM = 4,
+ #[serde(rename = "fee_insufficient")]
+ FEE_INSUFFICIENT = 5,
+ #[serde(rename = "cltv_incorrect")]
+ CLTV_INCORRECT = 6,
+ #[serde(rename = "cltv_expiry_too_soon")]
+ CLTV_EXPIRY_TOO_SOON = 7,
+ #[serde(rename = "cltv_expiry_too_far")]
+ CLTV_EXPIRY_TOO_FAR = 8,
+ #[serde(rename = "unknown_next_peer")]
+ UNKNOWN_NEXT_PEER = 9,
+ #[serde(rename = "outgoing_peer_offline")]
+ OUTGOING_PEER_OFFLINE = 10,
+ #[serde(rename = "channel_failed_permanent")]
+ CHANNEL_FAILED_PERMANENT = 11,
+ #[serde(rename = "invalid_onion")]
+ INVALID_ONION = 12,
+ #[serde(rename = "channel_shutting_down")]
+ CHANNEL_SHUTTING_DOWN = 13,
+ #[serde(rename = "max_htlc_value_in_flight")]
+ MAX_HTLC_VALUE_IN_FLIGHT = 14,
+ #[serde(rename = "peer_cannot_afford_fee")]
+ PEER_CANNOT_AFFORD_FEE = 15,
+}
+
+impl TryFrom<i32> for ForwardEventFailureReason {
+ type Error = anyhow::Error;
+ fn try_from(c: i32) -> Result<ForwardEventFailureReason, anyhow::Error> {
+ match c {
+ 0 => Ok(ForwardEventFailureReason::INSUFFICIENT_OUTGOING_LIQUIDITY),
+ 1 => Ok(ForwardEventFailureReason::TOO_MANY_HTLCS),
+ 2 => Ok(ForwardEventFailureReason::DUST_LIMIT),
+ 3 => Ok(ForwardEventFailureReason::HTLC_BELOW_MINIMUM),
+ 4 => Ok(ForwardEventFailureReason::HTLC_ABOVE_MAXIMUM),
+ 5 => Ok(ForwardEventFailureReason::FEE_INSUFFICIENT),
+ 6 => Ok(ForwardEventFailureReason::CLTV_INCORRECT),
+ 7 => Ok(ForwardEventFailureReason::CLTV_EXPIRY_TOO_SOON),
+ 8 => Ok(ForwardEventFailureReason::CLTV_EXPIRY_TOO_FAR),
+ 9 => Ok(ForwardEventFailureReason::UNKNOWN_NEXT_PEER),
+ 10 => Ok(ForwardEventFailureReason::OUTGOING_PEER_OFFLINE),
+ 11 => Ok(ForwardEventFailureReason::CHANNEL_FAILED_PERMANENT),
+ 12 => Ok(ForwardEventFailureReason::INVALID_ONION),
+ 13 => Ok(ForwardEventFailureReason::CHANNEL_SHUTTING_DOWN),
+ 14 => Ok(ForwardEventFailureReason::MAX_HTLC_VALUE_IN_FLIGHT),
+ 15 => Ok(ForwardEventFailureReason::PEER_CANNOT_AFFORD_FEE),
+ o => Err(anyhow::anyhow!("Unknown variant {} for enum ForwardEventFailureReason", o)),
+ }
+ }
+}
+
+impl ToString for ForwardEventFailureReason {
+ fn to_string(&self) -> String {
+ match self {
+ ForwardEventFailureReason::INSUFFICIENT_OUTGOING_LIQUIDITY => "INSUFFICIENT_OUTGOING_LIQUIDITY",
+ ForwardEventFailureReason::TOO_MANY_HTLCS => "TOO_MANY_HTLCS",
+ ForwardEventFailureReason::DUST_LIMIT => "DUST_LIMIT",
+ ForwardEventFailureReason::HTLC_BELOW_MINIMUM => "HTLC_BELOW_MINIMUM",
+ ForwardEventFailureReason::HTLC_ABOVE_MAXIMUM => "HTLC_ABOVE_MAXIMUM",
+ ForwardEventFailureReason::FEE_INSUFFICIENT => "FEE_INSUFFICIENT",
+ ForwardEventFailureReason::CLTV_INCORRECT => "CLTV_INCORRECT",
+ ForwardEventFailureReason::CLTV_EXPIRY_TOO_SOON => "CLTV_EXPIRY_TOO_SOON",
+ ForwardEventFailureReason::CLTV_EXPIRY_TOO_FAR => "CLTV_EXPIRY_TOO_FAR",
+ ForwardEventFailureReason::UNKNOWN_NEXT_PEER => "UNKNOWN_NEXT_PEER",
+ ForwardEventFailureReason::OUTGOING_PEER_OFFLINE => "OUTGOING_PEER_OFFLINE",
+ ForwardEventFailureReason::CHANNEL_FAILED_PERMANENT => "CHANNEL_FAILED_PERMANENT",
+ ForwardEventFailureReason::INVALID_ONION => "INVALID_ONION",
+ ForwardEventFailureReason::CHANNEL_SHUTTING_DOWN => "CHANNEL_SHUTTING_DOWN",
+ ForwardEventFailureReason::MAX_HTLC_VALUE_IN_FLIGHT => "MAX_HTLC_VALUE_IN_FLIGHT",
+ ForwardEventFailureReason::PEER_CANNOT_AFFORD_FEE => "PEER_CANNOT_AFFORD_FEE",
+ }.to_string()
+ }
+}
+
/// ['The onion format used for the forward, if known.']
#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
#[allow(non_camel_case_types)]
@@ -541,6 +627,8 @@ pub struct ForwardEventNotification {
#[serde(skip_serializing_if = "Option::is_none")]
pub failreason: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
+ pub failure_reason: Option<ForwardEventFailureReason>,
+ #[serde(skip_serializing_if = "Option::is_none")]
pub fee_msat: Option<Amount>,
#[serde(skip_serializing_if = "Option::is_none")]
pub out_channel: Option<ShortChannelId>,
### common/Makefile
@@ -120,6 +120,7 @@ COMMON_HEADERS_NOGEN := $(COMMON_SRC_NOGEN:.c=.h) \
common/crypto_state.h \
common/ecdh.h \
common/errcode.h \
+ common/forward_failure_reason.h \
common/gossip_constants.h \
common/hash_str.h \
common/hsm_version.h \
### common/forward_failure_reason.h
@@ -0,0 +1,103 @@
+#ifndef LIGHTNING_COMMON_FORWARD_FAILURE_REASON_H
+#define LIGHTNING_COMMON_FORWARD_FAILURE_REASON_H
+#include "config.h"
+#include <ccan/str/str.h>
+#include <stdio.h>
+
+/* This is a DB ENUM!!!, please do not change the numbering of any
+ * already defined elements (adding is ok) */
+enum forward_failure_reason {
+ /* Not classified, or not applicable (not a local failure) */
+ FORWARD_FAIL_UNKNOWN = 0,
+ /* CHANNEL_ERR_CHANNEL_CAPACITY_EXCEEDED: not enough spendable
+ * balance/reserve on the outgoing channel */
+ FORWARD_FAIL_INSUFFICIENT_OUTGOING_LIQUIDITY = 1,
+ /* CHANNEL_ERR_TOO_MANY_HTLCS */
+ FORWARD_FAIL_TOO_MANY_HTLCS = 2,
+ /* CHANNEL_ERR_DUST_FAILURE */
+ FORWARD_FAIL_DUST_LIMIT = 3,
+ /* CHANNEL_ERR_HTLC_BELOW_MINIMUM, or amount below the next hop's
+ * advertised htlc_minimum_msat */
+ FORWARD_FAIL_HTLC_BELOW_MINIMUM = 4,
+ /* CHANNEL_ERR_MAX_HTLC_VALUE_EXCEEDED, or amount above the next
+ * hops advertised htlc_maximum_msat */
+ FORWARD_FAIL_HTLC_ABOVE_MAXIMUM = 5,
+ /* Forwarding fee offered was insufficient */
+ FORWARD_FAIL_FEE_INSUFFICIENT = 6,
+ /* CHANNEL_ERR_INVALID_EXPIRY, or cltv_expiry_delta check failed */
+ FORWARD_FAIL_CLTV_INCORRECT = 7,
+ /* Outgoing cltv too close to the current block height */
+ FORWARD_FAIL_CLTV_EXPIRY_TOO_SOON = 8,
+ /* Outgoing cltv beyond our configured max_htlc_cltv */
+ FORWARD_FAIL_CLTV_EXPIRY_TOO_FAR = 9,
+ /* No usable channel/peer for the requested next hop */
+ FORWARD_FAIL_UNKNOWN_NEXT_PEER = 10,
+ /* Outgoing peers subdaemon is not connected/owned */
+ FORWARD_FAIL_OUTGOING_PEER_OFFLINE = 11,
+ /* Outgoing HTLC failed permanently (onchain timeout) */
+ FORWARD_FAIL_CHANNEL_FAILED_PERMANENT = 12,
+ /* Onion could not be parsed/decoded */
+ FORWARD_FAIL_INVALID_ONION = 13,
+ /* Incoming channel could not accept the htlc because it is
+ * shutting down (not an outgoing/onchain failure) */
+ FORWARD_FAIL_CHANNEL_SHUTTING_DOWN = 14,
+ /* CHANNEL_ERR_MAX_HTLC_VALUE_IN_FLIGHT_EXCEEDED - aggregate value of
+ * HTLCs already committed on the outgoing channel would exceed its
+ * max_htlc_value_in_flight_msat */
+ FORWARD_FAIL_MAX_HTLC_VALUE_IN_FLIGHT = 15,
+ /* CHANNEL_ERR_OPENER_CANNOT_AFFORD_FEE - the peer opened the outgoing
+ * channel and can't pay the commitment fee for another HTLC output.
+ * Our own balance was sufficient */
+ FORWARD_FAIL_PEER_CANNOT_AFFORD_FEE = 16,
+};
+
+/* Returns NULL for FORWARD_FAIL_UNKNOWN - it is never serialized
+ * r is persisted (db column, wire field), so may take a value this
+ * binary doesn't know about (after a downgrade) - fall back to
+ * a formatted placeholder instead of aborting */
+static inline const char *forward_failure_reason_name(enum forward_failure_reason r)
+{
+ static char invalidbuf[sizeof("unknown_reason_") + STR_MAX_CHARS(int)];
+
+ switch (r) {
+ case FORWARD_FAIL_UNKNOWN:
+ return NULL;
+ case FORWARD_FAIL_INSUFFICIENT_OUTGOING_LIQUIDITY:
+ return "insufficient_outgoing_liquidity";
+ case FORWARD_FAIL_TOO_MANY_HTLCS:
+ return "too_many_htlcs";
+ case FORWARD_FAIL_DUST_LIMIT:
+ return "dust_limit";
+ case FORWARD_FAIL_HTLC_BELOW_MINIMUM:
+ return "htlc_below_minimum";
+ case FORWARD_FAIL_HTLC_ABOVE_MAXIMUM:
+ return "htlc_above_maximum";
+ case FORWARD_FAIL_FEE_INSUFFICIENT:
+ return "fee_insufficient";
+ case FORWARD_FAIL_CLTV_INCORRECT:
+ return "cltv_incorrect";
+ case FORWARD_FAIL_CLTV_EXPIRY_TOO_SOON:
+ return "cltv_expiry_too_soon";
+ case FORWARD_FAIL_CLTV_EXPIRY_TOO_FAR:
+ return "cltv_expiry_too_far";
+ case FORWARD_FAIL_UNKNOWN_NEXT_PEER:
+ return "unknown_next_peer";
+ case FORWARD_FAIL_OUTGOING_PEER_OFFLINE:
+ return "outgoing_peer_offline";
+ case FORWARD_FAIL_CHANNEL_FAILED_PERMANENT:
+ return "channel_failed_permanent";
+ case FORWARD_FAIL_INVALID_ONION:
+ return "invalid_onion";
+ case FORWARD_FAIL_CHANNEL_SHUTTING_DOWN:
+ return "channel_shutting_down";
+ case FORWARD_FAIL_MAX_HTLC_VALUE_IN_FLIGHT:
+ return "max_htlc_value_in_flight";
+ case FORWARD_FAIL_PEER_CANNOT_AFFORD_FEE:
+ return "peer_cannot_afford_fee";
+ }
+
+ snprintf(invalidbuf, sizeof(invalidbuf), "unknown_reason_%i", (int)r);
+ return invalidbuf;
+}
+
+#endif /* LIGHTNING_COMMON_FORWARD_FAILURE_REASON_H */
### contrib/msggen/msggen/schema.json
@@ -23585,6 +23585,7 @@
"out_htlc_id": {},
"failcode": {},
"failreason": {},
+ "failure_reason": {},
"fee_msat": {
"type": "msat",
"description": [
@@ -23615,6 +23616,7 @@
"resolved_time": {},
"failcode": {},
"failreason": {},
+ "failure_reason": {},
"out_channel": {}
}
}
@@ -23655,6 +23657,7 @@
"out_msat": {},
"failcode": {},
"failreason": {},
+ "failure_reason": {},
"resolved_time": {
"type": "number",
"description": [
@@ -23681,6 +23684,7 @@
"fee_msat": {},
"failcode": {},
"failreason": {},
+ "failure_reason": {},
"out_msatoshi": {},
"out_msat": {}
}
@@ -23730,6 +23734,32 @@
"description": [
"The name of the onion code returned."
]
+ },
+ "failure_reason": {
+ "type": "string",
+ "added": "v26.12",
+ "enum": [
+ "insufficient_outgoing_liquidity",
+ "too_many_htlcs",
+ "dust_limit",
+ "htlc_below_minimum",
+ "htlc_above_maximum",
+ "fee_insufficient",
+ "cltv_incorrect",
+ "cltv_expiry_too_soon",
+ "cltv_expiry_too_far",
+ "unknown_next_peer",
+ "outgoing_peer_offline",
+ "channel_failed_permanent",
+ "invalid_onion",
+ "channel_shutting_down",
+ "max_htlc_value_in_flight",
+ "peer_cannot_afford_fee"
+ ],
+ "description": [
+ "The root cause of the failure, more specific than *failcode*/*failreason*. Only set for *local_failed* forwards, and not always known.",
+ "*insufficient_outgoing_liquidity* means our own spendable balance on the outgoing channel was too low; *peer_cannot_afford_fee* means the peer opened the outgoing channel and cannot pay the commitment fee for another HTLC."
+ ]
}
}
},
@@ -23924,6 +23954,7 @@
"status": "local_failed",
"failcode": 4109,
"failreason": "WIRE_INCORRECT_CLTV_EXPIRY",
+ "failure_reason": "cltv_incorrect",
"style": "tlv",
"received_time": 1738000000.0
},
@@ -23936,6 +23967,7 @@
"status": "local_failed",
"failcode": 16394,
"failreason": "WIRE_UNKNOWN_NEXT_PEER",
+ "failure_reason": "unknown_next_peer",
"style": "tlv",
"received_time": 1738000000.0
},
@@ -23961,6 +23993,7 @@
"status": "local_failed",
"failcode": 4108,
"failreason": "WIRE_FEE_INSUFFICIENT",
+ "failure_reason": "fee_insufficient",
"style": "tlv",
"received_time": 1738000000.0
},
@@ -42377,6 +42410,32 @@
"The symbolic failcode name when the forward failed locally."
]
},
+ "failure_reason": {
+ "type": "string",
+ "added": "v26.12",
+ "enum": [
+ "insufficient_outgoing_liquidity",
+ "too_many_htlcs",
+ "dust_limit",
+ "htlc_below_minimum",
+ "htlc_above_maximum",
+ "fee_insufficient",
+ "cltv_incorrect",
+ "cltv_expiry_too_soon",
+ "cltv_expiry_too_far",
+ "unknown_next_peer",
+ "outgoing_peer_offline",
+ "channel_failed_permanent",
+ "invalid_onion",
+ "channel_shutting_down",
+ "max_htlc_value_in_flight",
+ "peer_cannot_afford_fee"
+ ],
+ "description": [
+ "The root cause of the failure, more specific than *failcode*/*failreason*. Only set for *local_failed* forwards, and not always known.",
+ "*insufficient_outgoing_liquidity* means our own spendable balance on the outgoing channel was too low; *peer_cannot_afford_fee* means the peer opened the outgoing channel and cannot pay the commitment fee for another HTLC."
+ ]
+ },
"style": {
"type": "string",
"enum": [
### contrib/pyln-grpc-proto/pyln/grpc/node_pb2.py
[binary or diff unavailable]
### contrib/pyln-testing/pyln/testing/grpc2py.py
@@ -1661,6 +1661,7 @@ def listaddresses2py(m):
def listforwards_forwards2py(m):
return remove_default({
+ "failure_reason": str(m.failure_reason), # EnumField in generate_composite
"status": str(m.status), # EnumField in generate_composite
"style": str(m.style), # EnumField in generate_composite
"created_index": m.created_index, # PrimitiveField in generate_composite
### doc/schemas/listforwards.json
@@ -192,6 +192,7 @@
"out_htlc_id": {},
"failcode": {},
"failreason": {},
+ "failure_reason": {},
"fee_msat": {
"type": "msat",
"description": [
@@ -222,6 +223,7 @@
"resolved_time": {},
"failcode": {},
"failreason": {},
+ "failure_reason": {},
"out_channel": {}
}
}
@@ -262,6 +264,7 @@
"out_msat": {},
"failcode": {},
"failreason": {},
+ "failure_reason": {},
"resolved_time": {
"type": "number",
"description": [
@@ -288,6 +291,7 @@
"fee_msat": {},
"failcode": {},
"failreason": {},
+ "failure_reason": {},
"out_msatoshi": {},
"out_msat": {}
}
@@ -337,6 +341,32 @@
"description": [
"The name of the onion code returned."
]
+ },
+ "failure_reason": {
+ "type": "string",
+ "added": "v26.12",
+ "enum": [
+ "insufficient_outgoing_liquidity",
+ "too_many_htlcs",
+ "dust_limit",
+ "htlc_below_minimum",
+ "htlc_above_maximum",
+ "fee_insufficient",
+ "cltv_incorrect",
+ "cltv_expiry_too_soon",
+ "cltv_expiry_too_far",
+ "unknown_next_peer",
+ "outgoing_peer_offline",
+ "channel_failed_permanent",
+ "invalid_onion",
+ "channel_shutting_down",
+ "max_htlc_value_in_flight",
+ "peer_cannot_afford_fee"
+ ],
+ "description": [
+ "The root cause of the failure, more specific than *failcode*/*failreason*. Only set for *local_failed* forwards, and not always known.",
+ "*insufficient_outgoing_liquidity* means our own spendable balance on the outgoing channel was too low; *peer_cannot_afford_fee* means the peer opened the outgoing channel and cannot pay the commitment fee for another HTLC."
+ ]
}
}
},
@@ -531,6 +561,7 @@
"status": "local_failed",
"failcode": 4109,
"failreason": "WIRE_INCORRECT_CLTV_EXPIRY",
+ "failure_reason": "cltv_incorrect",
"style": "tlv",
"received_time": 1738000000.0
},
@@ -543,6 +574,7 @@
"status": "local_failed",
"failcode": 16394,
"failreason": "WIRE_UNKNOWN_NEXT_PEER",
+ "failure_reason": "unknown_next_peer",
"style": "tlv",
"received_time": 1738000000.0
},
@@ -568,6 +600,7 @@
"status": "local_failed",
"failcode": 4108,
"failreason": "WIRE_FEE_INSUFFICIENT",
+ "failure_reason": "fee_insufficient",
"style": "tlv",
"received_time": 1738000000.0
},
### doc/schemas/notification/forward_event.json
@@ -78,6 +78,32 @@
"The symbolic failcode name when the forward failed locally."
]
},
+ "failure_reason": {
+ "type": "string",
+ "added": "v26.12",
+ "enum": [
+ "insufficient_outgoing_liquidity",
+ "too_many_htlcs",
+ "dust_limit",
+ "htlc_below_minimum",
+ "htlc_above_maximum",
+ "fee_insufficient",
+ "cltv_incorrect",
+ "cltv_expiry_too_soon",
+ "cltv_expiry_too_far",
+ "unknown_next_peer",
+ "outgoing_peer_offline",
+ "channel_failed_permanent",
+ "invalid_onion",
+ "channel_shutting_down",
+ "max_htlc_value_in_flight",
+ "peer_cannot_afford_fee"
+ ],
+ "description": [
+ "The root cause of the failure, more specific than *failcode*/*failreason*. Only set for *local_failed* forwards, and not always known.",
+ "*insufficient_outgoing_liquidity* means our own spendable balance on the outgoing channel was too low; *peer_cannot_afford_fee* means the peer opened the outgoing channel and cannot pay the commitment fee for another HTLC."
+ ]
+ },
"style": {
"type": "string",
"enum": [
### lightningd/forwards.c
@@ -129,6 +129,10 @@ void json_add_forwarding_fields(struct json_stream *response,
onion_wire_name(cur->failcode));
}
+ if (cur->reason != FORWARD_FAIL_UNKNOWN)
+ json_add_string(response, "failure_reason",
+ forward_failure_reason_name(cur->reason));
+
/* Old forwards don't have this field */
if (cur->forward_style != FORWARD_STYLE_UNKNOWN)
json_add_string(response, "style",
### lightningd/forwards.h
@@ -3,6 +3,7 @@
#define LIGHTNING_LIGHTNINGD_FORWARDS_H
#include "config.h"
#include <ccan/time/time.h>
+#include <common/forward_failure_reason.h>
#include <wire/onion_wiregen.h>
struct json_stream;
@@ -46,6 +47,9 @@ struct forwarding {
enum forward_style forward_style;
enum forward_status status;
enum onion_wire failcode;
+ /* Root cause of a FORWARD_LOCAL_FAILED forward - FORWARD_FAIL_UNKNOWN
+ * if not classified or not applicable */
+ enum forward_failure_reason reason;
struct timeabs received_time;
/* May not be present if the HTLC was not resolved yet. */
struct timeabs *resolved_time;
### lightningd/notification.c
@@ -351,6 +351,7 @@ static void forward_event_notification_serialize(struct json_stream *stream,
const struct amount_msat *amount_out,
enum forward_status state,
enum onion_wire failcode,
+ enum forward_failure_reason reason,
struct timeabs *resolved_time,
enum forward_style forward_style,
u64 created_index,
@@ -386,6 +387,7 @@ static void forward_event_notification_serialize(struct json_stream *stream,
cur->htlc_id_out = NULL;
cur->status = state;
cur->failcode = failcode;
+ cur->reason = reason;
cur->received_time = in->received_time;
cur->resolved_time = tal_steal(cur, resolved_time);
cur->forward_style = forward_style;
@@ -403,6 +405,7 @@ void notify_forward_event(struct lightningd *ld,
const struct amount_msat *amount_out,
enum forward_status state,
enum onion_wire failcode,
+ enum forward_failure_reason reason,
struct timeabs *resolved_time,
enum forward_style forward_style,
u64 created_index,
@@ -411,7 +414,7 @@ void notify_forward_event(struct lightningd *ld,
struct jsonrpc_notification *n = notify_start(ld, "forward_event");
if (!n)
return;
- forward_event_notification_serialize(n->stream, in, scid_out, amount_out, state, failcode, resolved_time, forward_style, created_index, updated_index);
+ forward_event_notification_serialize(n->stream, in, scid_out, amount_out, state, failcode, reason, resolved_time, forward_style, created_index, updated_index);
notify_send(ld, n);
}
### lightningd/notification.h
@@ -2,6 +2,7 @@
#define LIGHTNING_LIGHTNINGD_NOTIFICATION_H
#include "config.h"
#include <common/coin_mvt.h>
+#include <common/forward_failure_reason.h>
#include <lightningd/chaintopology.h>
#include <lightningd/pay.h>
#include <lightningd/plugin.h>
@@ -73,6 +74,7 @@ void notify_forward_event(struct lightningd *ld,
const struct amount_msat *amount_out,
enum forward_status state,
enum onion_wire failcode,
+ enum forward_failure_reason reason,
struct timeabs *resolved_time,
enum forward_style forward_style,
u64 created_index,
### lightningd/pay.c
@@ -792,7 +792,8 @@ static const u8 *send_onion(const tal_t *ctx, struct lightningd *ld,
return send_htlc_out(ctx, channel, first_hop->amount,
base_expiry + first_hop->delay,
final_amount, payment_hash,
- path_key, NULL, partid, groupid, onion, NULL, hout);
+ path_key, NULL, partid, groupid, onion, NULL, hout,
+ NULL);
}
static struct command_result *check_invoice_request_usage(struct command *cmd,
@@ -2128,7 +2129,7 @@ static struct command_result *json_injectpaymentonion(struct command *cmd,
payment_hash,
next_path_key, NULL, *partid, *groupid,
serialize_onionpacket(tmpctx, rs->next),
- NULL, &hout);
+ NULL, &hout, NULL);
if (failmsg) {
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"Could not send to first peer: %s",
### lightningd/peer_htlcs.c
@@ -627,6 +627,17 @@ static void destroy_hout_subd_died(struct htlc_out *hout)
fail_out_htlc(hout, "Outgoing subdaemon died");
+ if (!hout->am_origin && hout->in) {
+ struct short_channel_id scid
+ = channel_scid_or_local_alias(hout->key.channel);
+ wallet_forwarded_payment_add(hout->key.channel->peer->ld->wallet,
+ hout->in, FORWARD_STYLE_TLV,
+ &scid, NULL,
+ FORWARD_LOCAL_FAILED,
+ fromwire_peektype(hout->failmsg),
+ FORWARD_FAIL_OUTGOING_PEER_OFFLINE);
+ }
+
if (!have_tx)
db_commit_transaction(db);
}
@@ -638,17 +649,21 @@ static void rcvd_htlc_reply(struct subd *subd, const u8 *msg, const int *fds UNU
{
u8 *failmsg;
char *failurestr;
+ u8 reason_raw;
+ enum forward_failure_reason reason;
struct lightningd *ld = subd->ld;
if (!fromwire_channeld_offer_htlc_reply(msg, msg,
&hout->key.id,
&failmsg,
- &failurestr)) {
+ &failurestr,
+ &reason_raw)) {
channel_internal_error(subd->channel,
"Bad channel_offer_htlc_reply");
tal_free(hout);
return;
}
+ reason = reason_raw;
if (tal_count(failmsg)) {
/* BOLT #4:
@@ -697,7 +712,8 @@ static void rcvd_htlc_reply(struct subd *subd, const u8 *msg, const int *fds UNU
FORWARD_STYLE_TLV,
&scid, NULL,
FORWARD_LOCAL_FAILED,
- fromwire_peektype(hout->failmsg));
+ fromwire_peektype(hout->failmsg),
+ reason);
}
/* Prevent hout from being failed twice. */
@@ -754,7 +770,8 @@ const u8 *send_htlc_out(const tal_t *ctx,
u64 groupid,
const u8 *onion_routing_packet,
struct htlc_in *in,
- struct htlc_out **houtp)
+ struct htlc_out **houtp,
+ enum forward_failure_reason *reason)
{
u8 *msg, *raw_tlvs = NULL;
@@ -763,12 +780,16 @@ const u8 *send_htlc_out(const tal_t *ctx,
if (!channel_state_can_add_htlc(out->state)) {
log_info(out->log, "Attempt to send HTLC but not ready (%s)",
channel_state_name(out));
+ if (reason)
+ *reason = FORWARD_FAIL_UNKNOWN_NEXT_PEER;
return towire_unknown_next_peer(ctx);
}
if (!out->owner) {
log_info(out->log, "Attempt to send HTLC but unowned (%s)",
channel_state_name(out));
+ if (reason)
+ *reason = FORWARD_FAIL_OUTGOING_PEER_OFFLINE;
return towire_temporary_channel_failure(ctx,
channel_update_for_error(tmpctx, in, out));
}
@@ -864,6 +885,7 @@ static void forward_htlc(struct htlc_in *hin,
const struct tlv_field *extra_tlvs)
{
const u8 *failmsg;
+ enum forward_failure_reason reason = FORWARD_FAIL_UNKNOWN;
struct lightningd *ld = hin->key.channel->peer->ld;
struct channel *next;
struct htlc_out *hout = NULL;
@@ -887,7 +909,8 @@ static void forward_htlc(struct htlc_in *hin,
hin, FORWARD_STYLE_TLV,
forward_scid, NULL,
FORWARD_LOCAL_FAILED,
- WIRE_UNKNOWN_NEXT_PEER);
+ WIRE_UNKNOWN_NEXT_PEER,
+ FORWARD_FAIL_UNKNOWN_NEXT_PEER);
return;
}
@@ -911,20 +934,24 @@ static void forward_htlc(struct htlc_in *hin,
failmsg = towire_fee_insufficient(tmpctx, hin->msat,
channel_update_for_error(tmpctx,
hin, next));
+ reason = FORWARD_FAIL_FEE_INSUFFICIENT;
goto fail;
}
log_info(hin->key.channel->log,
"Allowing payment using older feerate");
}
- if (amount_msat_greater(amt_to_forward, next->htlc_maximum_msat)
+ bool above_max = amount_msat_greater(amt_to_forward, next->htlc_maximum_msat);
+ if (above_max
|| amount_msat_less(amt_to_forward, next->htlc_minimum_msat)) {
/* Are we in old-range grace-period? */
if (!timemono_before(time_mono(), next->old_feerate_timeout)
|| amount_msat_less(amt_to_forward, next->old_htlc_minimum_msat)
|| amount_msat_greater(amt_to_forward, next->old_htlc_maximum_msat)) {
failmsg = towire_temporary_channel_failure(tmpctx,
channel_update_for_error(tmpctx, hin, next));
+ reason = above_max ? FORWARD_FAIL_HTLC_ABOVE_MAXIMUM
+ : FORWARD_FAIL_HTLC_BELOW_MINIMUM;
goto fail;
}
log_info(hin->key.channel->log,
@@ -935,6 +962,7 @@ static void forward_htlc(struct htlc_in *hin,
ld->config.cltv_expiry_delta)) {
failmsg = towire_incorrect_cltv_expiry(tmpctx, cltv_expiry,
channel_update_for_error(tmpctx, hin, next));
+ reason = FORWARD_FAIL_CLTV_INCORRECT;
goto fail;
}
@@ -954,6 +982,7 @@ static void forward_htlc(struct htlc_in *hin,
get_block_height(ld->topology));
failmsg = towire_expiry_too_soon(tmpctx,
channel_update_for_error(tmpctx, hin, next));
+ reason = FORWARD_FAIL_CLTV_EXPIRY_TOO_SOON;
goto fail;
}
@@ -970,14 +999,15 @@ static void forward_htlc(struct htlc_in *hin,
get_block_height(ld->topology),
ld->config.max_htlc_cltv);
failmsg = towire_expiry_too_far(tmpctx);
+ reason = FORWARD_FAIL_CLTV_EXPIRY_TOO_FAR;
goto fail;
}
failmsg = send_htlc_out(tmpctx, next, amt_to_forward,
outgoing_cltv_value, AMOUNT_MSAT(0),
&hin->payment_hash,
next_path_key, extra_tlvs, 0 /* partid */, 0 /* groupid */,
- next_onion, hin, &hout);
+ next_onion, hin, &hout, &reason);
if (!failmsg)
return;
@@ -986,7 +1016,8 @@ static void forward_htlc(struct htlc_in *hin,
wallet_forwarded_payment_add(ld->wallet,
hin, FORWARD_STYLE_TLV, forward_scid, hout,
FORWARD_LOCAL_FAILED,
- fromwire_peektype(failmsg));
+ fromwire_peektype(failmsg),
+ reason);
}
/**
@@ -1698,7 +1729,8 @@ static void fulfill_our_htlc_out(struct channel *channel, struct htlc_out *hout,
wallet_forwarded_payment_add(ld->wallet, hout->in,
FORWARD_STYLE_TLV,
&scid, hout,
- FORWARD_SETTLED, 0);
+ FORWARD_SETTLED, 0,
+ FORWARD_FAIL_UNKNOWN);
}
}
}
@@ -1860,7 +1892,8 @@ static bool peer_failed_our_htlc(struct channel *channel,
hout, FORWARD_FAILED,
hout->failmsg
? fromwire_peektype(hout->failmsg)
- : 0);
+ : 0,
+ FORWARD_FAIL_UNKNOWN);
}
return true;
@@ -2009,7 +2042,8 @@ void onchain_failed_our_htlc(const struct channel *channel,
FORWARD_LOCAL_FAILED,
hout->failmsg
? fromwire_peektype(hout->failmsg)
- : 0);
+ : 0,
+ FORWARD_FAIL_CHANNEL_FAILED_PERMANENT);
} else {
/* This happens if we abandoned the incoming HTLC to avoid closure */
log_unusual(channel->log, "HTLC id %"PRIu64" is from nowhere: did we abandon it?",
@@ -2172,7 +2206,8 @@ static bool update_out_htlc(struct channel *channel,
wallet_forwarded_payment_add(ld->wallet, hout->in,
FORWARD_STYLE_TLV,
&scid, hout,
- FORWARD_OFFERED, 0);
+ FORWARD_OFFERED, 0,
+ FORWARD_FAIL_UNKNOWN);
}
}
@@ -2794,24 +2829,40 @@ void peer_got_revoke(struct channel *channel, const u8 *msg)
/* Now, any HTLCs we need to immediately fail? */
for (i = 0; i < tal_count(changed); i++) {
struct htlc_in *hin;
+ enum forward_failure_reason reason;
+ enum onion_wire failtype;
if (badonions[i]) {
hin = find_htlc_in(ld->htlcs_in, channel,
changed[i].id);
local_fail_in_htlc_badonion(hin, badonions[i]);
+ failtype = badonions[i];
+ reason = FORWARD_FAIL_INVALID_ONION;
} else if (failmsgs[i]) {
hin = find_htlc_in(ld->htlcs_in, channel,
changed[i].id);
local_fail_in_htlc(hin, failmsgs[i]);
+ failtype = fromwire_peektype(failmsgs[i]);
+
+ switch (failtype) {
+ case WIRE_PERMANENT_CHANNEL_FAILURE:
+ reason = FORWARD_FAIL_CHANNEL_SHUTTING_DOWN;
+ break;
+ case WIRE_INVALID_ONION_BLINDING:
+ reason = FORWARD_FAIL_INVALID_ONION;
+ break;
+ default:
+ reason = FORWARD_FAIL_UNKNOWN;
+ break;
+ }
} else
continue;
// in fact, now we don't know if this htlc is a forward or localpay!
wallet_forwarded_payment_add(ld->wallet,
hin, FORWARD_STYLE_UNKNOWN, NULL, NULL,
FORWARD_LOCAL_FAILED,
- badonions[i] ? badonions[i]
- : fromwire_peektype(failmsgs[i]));
+ failtype, reason);
}
wallet_channel_save(ld->wallet, channel);
### lightningd/peer_htlcs.h
@@ -2,6 +2,7 @@
#ifndef LIGHTNING_LIGHTNINGD_PEER_HTLCS_H
#define LIGHTNING_LIGHTNINGD_PEER_HTLCS_H
#include "config.h"
+#include <common/forward_failure_reason.h>
#include <common/htlc_wire.h>
struct channel;
@@ -38,7 +39,8 @@ const u8 *send_htlc_out(const tal_t *ctx,
u64 groupid,
const u8 *onion_routing_packet,
struct htlc_in *in,
- struct htlc_out **houtp);
+ struct htlc_out **houtp,
+ enum forward_failure_reason *reason);
void onchain_failed_our_htlc(const struct channel *channel,
const struct htlc_stub *htlc,
### tests/plugins/channeld_fakenet.c
@@ -23,6 +23,7 @@
#include <common/daemon_conn.h>
#include <common/derive_basepoints.h>
#include <common/ecdh.h>
+#include <common/forward_failure_reason.h>
#include <common/gossmap.h>
#include <common/onion_decode.h>
#include <common/status.h>
@@ -874,6 +875,7 @@ static void handle_offer_htlc(struct info *info, const u8 *inmsg)
enum channel_add_err e;
const u8 *failwiremsg;
const char *failstr;
+ enum forward_failure_reason reason = FORWARD_FAIL_UNKNOWN;
struct amount_sat htlc_fee;
struct pubkey *blinding;
static u64 htlc_id;
@@ -899,7 +901,7 @@ static void handle_offer_htlc(struct info *info, const u8 *inmsg)
case CHANNEL_ERR_ADD_OK:
/* Tell lightningd. */
msg = towire_channeld_offer_htlc_reply(NULL, htlc_id,
- 0, "");
+ 0, "", FORWARD_FAIL_UNKNOWN);
daemon_conn_send(info->dc, take(msg));
/* Tell it it's locked in */
update_commitment_tx_added(info, htlc_id);
@@ -912,6 +914,7 @@ static void handle_offer_htlc(struct info *info, const u8 *inmsg)
case CHANNEL_ERR_INVALID_EXPIRY:
failwiremsg = towire_incorrect_cltv_expiry(inmsg, cltv_expiry, NULL);
failstr = tal_fmt(inmsg, "Invalid cltv_expiry %u", cltv_expiry);
+ reason = FORWARD_FAIL_CLTV_INCORRECT;
goto failed;
case CHANNEL_ERR_DUPLICATE:
case CHANNEL_ERR_DUPLICATE_ID_DIFFERENT:
@@ -921,25 +924,36 @@ static void handle_offer_htlc(struct info *info, const u8 *inmsg)
case CHANNEL_ERR_MAX_HTLC_VALUE_EXCEEDED:
failwiremsg = towire_required_node_feature_missing(inmsg);
failstr = "Mini mode: maximum value exceeded";
+ reason = FORWARD_FAIL_HTLC_ABOVE_MAXIMUM;
goto failed;
case CHANNEL_ERR_MAX_HTLC_VALUE_IN_FLIGHT_EXCEEDED:
failwiremsg = towire_temporary_channel_failure(inmsg, NULL);
failstr = "Aggregate value of committed HTLCs would exceed max_htlc_value_in_flight_msat";
+ reason = FORWARD_FAIL_MAX_HTLC_VALUE_IN_FLIGHT;
goto failed;
/* FIXME: Fuzz the boundaries a bit to avoid probing? */
case CHANNEL_ERR_CHANNEL_CAPACITY_EXCEEDED:
failwiremsg = towire_temporary_channel_failure(inmsg, NULL);
failstr = tal_fmt(inmsg, "Capacity exceeded - HTLC fee: %s", fmt_amount_sat(inmsg, htlc_fee));
+ reason = FORWARD_FAIL_INSUFFICIENT_OUTGOING_LIQUIDITY;
+ goto failed;
+ case CHANNEL_ERR_OPENER_CANNOT_AFFORD_FEE:
+ failwiremsg = towire_temporary_channel_failure(inmsg, NULL);
+ failstr = tal_fmt(inmsg, "Peer (opener) cannot afford commitment fee - HTLC fee: %s",
+ fmt_amount_sat(inmsg, htlc_fee));
+ reason = FORWARD_FAIL_PEER_CANNOT_AFFORD_FEE;
goto failed;
case CHANNEL_ERR_HTLC_BELOW_MINIMUM:
failwiremsg = towire_amount_below_minimum(inmsg, amount, NULL);
failstr = tal_fmt(inmsg, "HTLC too small (%s minimum)",
fmt_amount_msat(tmpctx,
info->channel->config[REMOTE].htlc_minimum));
+ reason = FORWARD_FAIL_HTLC_BELOW_MINIMUM;
goto failed;
case CHANNEL_ERR_TOO_MANY_HTLCS:
failwiremsg = towire_temporary_channel_failure(inmsg, NULL);
failstr = "Too many HTLCs";
+ reason = FORWARD_FAIL_TOO_MANY_HTLCS;
goto failed;
case CHANNEL_ERR_DUST_FAILURE:
/* BOLT-919 #2:
@@ -950,14 +964,15 @@ static void handle_offer_htlc(struct info *info, const u8 *inmsg)
*/
failwiremsg = towire_temporary_channel_failure(inmsg, NULL);
failstr = "HTLC too dusty, allowed dust limit reached";
+ reason = FORWARD_FAIL_DUST_LIMIT;
goto failed;
}
/* Shouldn't return anything else! */
abort();
failed:
/* lightningd appends update to this for us */
- msg = towire_channeld_offer_htlc_reply(NULL, 0, failwiremsg, failstr);
+ msg = towire_channeld_offer_htlc_reply(NULL, 0, failwiremsg, failstr, reason);
daemon_conn_send(info->dc, take(msg));
}
### tests/test_pay.py
@@ -1720,6 +1720,83 @@ def test_forward_local_failed_stats(node_factory, bitcoind, executor):
# Correct in and out channels
assert [s['in_channel'] for s in stats['forwards']] == [c12] * 5
assert [s.get('out_channel') for s in stats['forwards']] == [c23, c24, c25, None, c24]
+ # And we record why each of them failed
+ assert [s.get('failure_reason') for s in stats['forwards']] == ['unknown_next_peer', 'fee_insufficient', 'htlc_above_maximum', 'invalid_onion', 'channel_failed_permanent']
+
+
+def test_forward_local_failed_reason(node_factory, bitcoind):
+ """
+ Check that we classify insufficient outgoing liquidity precisely
+ """
+ l1, l2, l3 = node_factory.get_nodes(3)
+
+ l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
+ l2.rpc.connect(l3.info['id'], 'localhost', l3.port)
+ l1.fundchannel(l2, 10**7)
+ c23, _ = l2.fundchannel(l3, 3 * 10**6)
+
+ mine_funding_to_announce(bitcoind, [l1, l2, l3])
+ l1.wait_channel_active(c23)
+ wait_for(lambda: len(l1.rpc.listchannels()['channels']) == 4)
+
+ # Drain most of l2's spendable balance on c23 over to l3
+ l1.rpc.xpay(l3.rpc.invoice(2_500_000_000, 'drain', 'drain')['bolt11'])
+
+ # Now ask for more than l2 has left to spend on c23. getroute is
+ # deprecated, so build the two-hop route by hand: the failure happens
+ # at l2, so the exact delays don't matter.
+ amt = 2_000_000_000
+ inv = l3.rpc.invoice(amt, "insufficient_liquidity", "desc")
+ payment_hash = inv['payment_hash']
+ c12 = l1.get_channel_scid(l2)
+ route = [{'amount_msat': amt + 10**6, 'id': l2.info['id'], 'delay': 30, 'channel': c12},
+ {'amount_msat': amt, 'id': l3.info['id'], 'delay': 20, 'channel': c23}]
+
+ with pytest.raises(RpcError):
+ l1.rpc.sendpay(route, payment_hash, payment_secret=inv['payment_secret'])
+ l1.rpc.waitsendpay(payment_hash)
+
+ wait_for(lambda: len(l2.rpc.listforwards(status='local_failed')['forwards']) == 1)
+
+ forward = only_one(l2.rpc.listforwards(status='local_failed')['forwards'])
+ assert forward['failure_reason'] == 'insufficient_outgoing_liquidity'
+
+
+@pytest.mark.openchannel('v1', 'Uses push-msat')
+def test_forward_local_failed_peer_cannot_afford_fee(node_factory, bitcoind):
+ """
+ If the peer opened the outgoing channel and can't pay the commitment
+ fee for one more HTLC, that's not *our* lack of liquidity.
+ """
+ l1, l2, l3 = node_factory.get_nodes(3)
+
+ l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
+ l3.rpc.connect(l2.info['id'], 'localhost', l2.port)
+ c12, _ = l1.fundchannel(l2, 10**7)
+
+ # l3 opens and pushes everything but its reserve to l2
+ l3.fundwallet(2 * 10**6)
+ txid = l3.rpc.fundchannel(l2.info['id'], 10**6, push_msat=990_000_000)['txid']
+ bitcoind.generate_block(1, wait_for_mempool=txid)
+ wait_for(lambda: l2.channel_state(l3) == 'CHANNELD_NORMAL')
+ c23 = l2.get_channel_scid(l3)
+
+ # We have plenty to spend on it...
+ amt = 100_000_000
+ chan = only_one(l2.rpc.listpeerchannels(l3.info['id'])['channels'])
+ assert chan['spendable_msat'] > amt
+
+ inv = l3.rpc.invoice(amt, "peer_cannot_afford_fee", "desc")
+ route = [{'amount_msat': amt + 10**6, 'id': l2.info['id'], 'delay': 30, 'channel': c12},
+ {'amount_msat': amt, 'id': l3.info['id'], 'delay': 20, 'channel': c23}]
+
+ with pytest.raises(RpcError):
+ l1.rpc.sendpay(route, inv['payment_hash'], payment_secret=inv['payment_secret'])
+ l1.rpc.waitsendpay(inv['payment_hash'])
+
+ # ...but l3 can't pay the fee for the extra HTLC output
+ forward = only_one(l2.rpc.listforwards(status='local_failed')['forwards'])
+ assert forward['failure_reason'] == 'peer_cannot_afford_fee'
@pytest.mark.slow_test
### tests/test_plugin.py
@@ -1772,6 +1772,7 @@ def test_forward_event_notification(node_factory, bitcoind, executor):
expect = stats[2].copy()
del expect['failcode']
del expect['failreason']
+ del expect['failure_reason']
del expect['out_htlc_id']
del expect['updated_index']
expect['status'] = 'offered'
@@ -4007,6 +4008,8 @@ def test_sql(node_factory, bitcoind):
{'name': 'failcode',
'type': 'u32'},
{'name': 'failreason',
+ 'type': 'string'},
+ {'name': 'failure_reason',
'type': 'string'}]},
'htlcs': {
'indices': [['short_channel_id', 'id']],
### tests/test_splicing.py
@@ -102,6 +102,9 @@ def test_splice_stored_feerate_repaired_on_upgrade(node_factory, bitcoind,
# safe. This is an absolute version, so it keeps pointing at the clamps
# when later migrations are appended.
l1.db_manip("UPDATE version SET version = {}".format(PRE_FEERATE_CLAMP_DB_VERSION))
+ # Every migration after the clamps runs again too, so undo the ones that
+ # cannot simply be repeated. Add to this as migrations are appended.
+ l1.db_manip("ALTER TABLE forwards DROP COLUMN reason")
l1.daemon.opts['database-upgrade'] = 'true'
l1.start()
### wallet/migrations.c
@@ -1221,6 +1221,9 @@ static const struct db_migration dbmigrations[] = {
/* Clamping is idempotent, so no revert needed */
NULL, NULL},
/* ^v26.09 */
+
+ {SQL("ALTER TABLE forwards ADD reason INTEGER DEFAULT NULL"), NULL,
+ SQL("ALTER TABLE forwards DROP COLUMN reason"), NULL},
};
const struct db_migration *get_db_migrations(size_t *num)
### wallet/test/run-chain_moves_duplicate-detect.c
@@ -304,6 +304,7 @@ void notify_forward_event(struct lightningd *ld UNNEEDED,
const struct amount_msat *amount_out UNNEEDED,
enum forward_status state UNNEEDED,
enum onion_wire failcode UNNEEDED,
+ enum forward_failure_reason reason UNNEEDED,
struct timeabs *resolved_time UNNEEDED,
enum forward_style forward_style UNNEEDED,
u64 created_index UNNEEDED,
### wallet/test/run-db.c
@@ -317,6 +317,7 @@ void notify_forward_event(struct lightningd *ld UNNEEDED,
const struct amount_msat *amount_out UNNEEDED,
enum forward_status state UNNEEDED,
enum onion_wire failcode UNNEEDED,
+ enum forward_failure_reason reason UNNEEDED,
struct timeabs *resolved_time UNNEEDED,
enum forward_style forward_style UNNEEDED,
u64 created_index UNNEEDED,
### wallet/test/run-migrate_remove_chain_moves_duplicates.c
@@ -350,6 +350,7 @@ void notify_forward_event(struct lightningd *ld UNNEEDED,
const struct amount_msat *amount_out UNNEEDED,
enum forward_status state UNNEEDED,
enum onion_wire failcode UNNEEDED,
+ enum forward_failure_reason reason UNNEEDED,
struct timeabs *resolved_time UNNEEDED,
enum forward_style forward_style UNNEEDED,
u64 created_index UNNEEDED,
### wallet/test/run-wallet.c
@@ -310,7 +310,7 @@ bool fromwire_channeld_got_commitsig(const tal_t *ctx UNNEEDED, const void *p UN
bool fromwire_channeld_got_revoke(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u64 *revokenum UNNEEDED, struct secret *per_commitment_secret UNNEEDED, struct pubkey *next_per_commit_point UNNEEDED, struct fee_states **fee_states UNNEEDED, struct height_states **blockheight_states UNNEEDED, struct changed_htlc **changed UNNEEDED, struct penalty_base **pbase UNNEEDED, struct bitcoin_tx **penalty_tx UNNEEDED)
{ fprintf(stderr, "fromwire_channeld_got_revoke called!\n"); abort(); }
/* Generated stub for fromwire_channeld_offer_htlc_reply */
-bool fromwire_channeld_offer_htlc_reply(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u64 *id UNNEEDED, u8 **failuremsg UNNEEDED, wirestring **failurestr UNNEEDED)
+bool fromwire_channeld_offer_htlc_reply(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u64 *id UNNEEDED, u8 **failuremsg UNNEEDED, wirestring **failurestr UNNEEDED, u8 *reason UNNEEDED)
{ fprintf(stderr, "fromwire_channeld_offer_htlc_reply called!\n"); abort(); }
/* Generated stub for fromwire_channeld_sending_commitsig */
bool fromwire_channeld_sending_commitsig(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u64 *commitnum UNNEEDED, struct penalty_base **pbase UNNEEDED, struct fee_states **fee_states UNNEEDED, struct height_states **blockheight_states UNNEEDED, struct changed_htlc **changed UNNEEDED)
@@ -550,6 +550,7 @@ void notify_forward_event(struct lightningd *ld UNNEEDED,
const struct amount_msat *amount_out UNNEEDED,
enum forward_status state UNNEEDED,
enum onion_wire failcode UNNEEDED,
+ enum forward_failure_reason reason UNNEEDED,
struct timeabs *resolved_time UNNEEDED,
enum forward_style forward_style UNNEEDED,
u64 created_index UNNEEDED,
### wallet/wallet.c
@@ -5487,6 +5487,7 @@ static bool wallet_forwarded_payment_update(struct wallet *w,
const struct htlc_out *out,
enum forward_status state,
enum onion_wire failcode,
+ enum forward_failure_reason reason,
struct timeabs *resolved_time,
enum forward_style forward_style)
{
@@ -5505,6 +5506,7 @@ static bool wallet_forwarded_payment_update(struct wallet *w,
", state=?"
", resolved_time=?"
", failcode=?"
+ ", reason=?"
", forward_style=?"
" WHERE in_htlc_id=? AND in_channel_scid=?"));
/* This may not work so don't increment index yet! */
@@ -5532,6 +5534,13 @@ static bool wallet_forwarded_payment_update(struct wallet *w,
db_bind_null(stmt);
}
+ if (reason != FORWARD_FAIL_UNKNOWN) {
+ assert(state == FORWARD_LOCAL_FAILED);
+ db_bind_int(stmt, (int)reason);
+ } else {
+ db_bind_null(stmt);
+ }
+
/* This can happen for malformed onions, reload from db. */
if (forward_style == FORWARD_STYLE_UNKNOWN)
db_bind_null(stmt);
@@ -5551,7 +5560,8 @@ void wallet_forwarded_payment_add(struct wallet *w, const struct htlc_in *in,
const struct short_channel_id *scid_out,
const struct htlc_out *out,
enum forward_status state,
- enum onion_wire failcode)
+ enum onion_wire failcode,
+ enum forward_failure_reason reason)
{
struct db_stmt *stmt;
struct timeabs *resolved_time;
@@ -5564,7 +5574,7 @@ void wallet_forwarded_payment_add(struct wallet *w, const struct htlc_in *in,
resolved_time = NULL;
}
- if (wallet_forwarded_payment_update(w, in, out, state, failcode, resolved_time, forward_style)) {
+ if (wallet_forwarded_payment_update(w, in, out, state, failcode, reason, resolved_time, forward_style)) {
updated_index =
forward_index_update_status(w->ld,
state,
@@ -5590,8 +5600,9 @@ void wallet_forwarded_payment_add(struct wallet *w, const struct htlc_in *in,
", received_time"
", resolved_time"
", failcode"
+ ", reason"
", forward_style"
- ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"));
+ ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"));
id = forward_index_created(w->ld,
state,
channel_scid_or_local_alias(in->key.channel),
@@ -5644,6 +5655,14 @@ void wallet_forwarded_payment_add(struct wallet *w, const struct htlc_in *in,
} else {
db_bind_null(stmt);
}
+
+ if (reason != FORWARD_FAIL_UNKNOWN) {
+ assert(state == FORWARD_LOCAL_FAILED);
+ db_bind_int(stmt, (int)reason);
+ } else {
+ db_bind_null(stmt);
+ }
+
/* This can happen for malformed onions, reload from db! */
if (forward_style == FORWARD_STYLE_UNKNOWN)
db_bind_null(stmt);
@@ -5654,7 +5673,7 @@ void wallet_forwarded_payment_add(struct wallet *w, const struct htlc_in *in,
notify:
notify_forward_event(w->ld, in, scid_out, out ? &out->msat : NULL,
- state, failcode, resolved_time, forward_style,
+ state, failcode, reason, resolved_time, forward_style,
id, updated_index);
}
@@ -5714,6 +5733,7 @@ struct db_stmt *forwarding_first(struct wallet *w,
", received_time"
", resolved_time"
", failcode "
+ ", reason "
", forward_style "
", rowid "
", updated_index "
@@ -5765,6 +5785,7 @@ struct db_stmt *forwarding_first(struct wallet *w,
", received_time"
", resolved_time"
", failcode "
+ ", reason "
", forward_style "
", rowid "
", updated_index "
@@ -5803,6 +5824,7 @@ struct db_stmt *forwarding_first(struct wallet *w,
", received_time"
", resolved_time"
", failcode "
+ ", reason "
", forward_style "
", rowid "
", updated_index "
@@ -5910,6 +5932,14 @@ const struct forwarding *forwarding_details(const tal_t *ctx,
} else {
fwd->failcode = 0;
}
+
+ if (!db_col_is_null(stmt, "reason")) {
+ assert(fwd->status == FORWARD_LOCAL_FAILED);
+ fwd->reason = db_col_int(stmt, "reason");
+ } else {
+ fwd->reason = FORWARD_FAIL_UNKNOWN;
+ }
+
if (db_col_is_null(stmt, "forward_style")) {
fwd->forward_style = FORWARD_STYLE_UNKNOWN;
} else {
### wallet/wallet.h
@@ -1342,7 +1342,8 @@ void wallet_forwarded_payment_add(struct wallet *w, const struct htlc_in *in,
const struct short_channel_id *scid_out,
const struct htlc_out *out,
enum forward_status state,
- enum onion_wire failcode);
+ enum onion_wire failcode,
+ enum forward_failure_reason reason);
/**
* Retrieve summary of successful forwarded payments' feesWhy this scored 19/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.