Skip to content

Commit 00d3628

Browse files
nepetcdecker
authored andcommitted
gl-plugin: Add channel filter for trampoline pay
We need to filter out channels that are drained and can not end out an htlc with an actual amount greater than 0. Signed-off-by: Peter Neuroth <[email protected]>
1 parent e1a4f39 commit 00d3628

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

libs/gl-plugin/src/tramp.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ const PAY_UNPARSEABLE_ONION_MSG: &str = "Malformed error reply";
3232
const PAY_UNPARSEABLE_ONION_CODE: i32 = 202;
3333
// How long do we wait for channels to re-establish?
3434
const AWAIT_CHANNELS_TIMEOUT_SEC: u64 = 20;
35+
// Minimum amount we can send through a channel.
36+
const MIN_HTLC_AMOUNT: u64 = 1;
3537

3638
fn feature_guard(features: impl Into<Vec<u8>>, feature_bit: usize) -> Result<()> {
3739
let mut features = features.into();
@@ -215,9 +217,20 @@ pub async fn trampolinepay(
215217
return None;
216218
}
217219
};
220+
let min_htlc_out_msat = match ch.minimum_htlc_out_msat {
221+
Some(m) => m.msat(),
222+
None => {
223+
warn!(
224+
"Missing missing minimum_htlc_out_msat on channel with scid={}",
225+
short_channel_id.to_string()
226+
);
227+
return None;
228+
}
229+
};
218230
return Some(ChannelData {
219231
short_channel_id,
220232
spendable_msat,
233+
min_htlc_out_msat,
221234
});
222235
})
223236
.collect();
@@ -245,6 +258,16 @@ pub async fn trampolinepay(
245258
break;
246259
}
247260

261+
// Filter out channels that lack minimum funds and can not send an htlc.
262+
if std::cmp::max(MIN_HTLC_AMOUNT, channel.min_htlc_out_msat) > channel.spendable_msat {
263+
debug!("Skip channel {}: has spendable_msat={} and minimum_htlc_out_msat={} and can not send htlc.",
264+
channel.short_channel_id,
265+
channel.spendable_msat,
266+
channel.min_htlc_out_msat,
267+
);
268+
continue;
269+
}
270+
248271
if (channel.spendable_msat + acc) <= amount_msat {
249272
choosen.push((channel.short_channel_id, channel.spendable_msat));
250273
acc += channel.spendable_msat;
@@ -463,6 +486,7 @@ async fn reestablished_channels(
463486
struct ChannelData {
464487
short_channel_id: cln_rpc::primitives::ShortChannelId,
465488
spendable_msat: u64,
489+
min_htlc_out_msat: u64,
466490
}
467491

468492
#[derive(Clone, Debug, Deserialize, Serialize)]

0 commit comments

Comments
 (0)