Skip to content

Commit 7d78e4e

Browse files
committed
add rough logic for self payment
1 parent 42085b9 commit 7d78e4e

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4906,6 +4906,9 @@ where
49064906
path, payment_hash, recipient_onion, total_value, cur_height, payment_id, keysend_preimage,
49074907
invoice_request, bolt12_invoice, session_priv_bytes
49084908
} = args;
4909+
4910+
4911+
49094912
// The top-level caller should hold the total_consistency_lock read lock.
49104913
debug_assert!(self.total_consistency_lock.try_write().is_err());
49114914
let prng_seed = self.entropy_source.get_secure_random_bytes();

lightning/src/routing/router.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ use crate::types::features::{
3737
use crate::types::payment::{PaymentHash, PaymentPreimage};
3838
use crate::util::logger::Logger;
3939
use crate::util::ser::{Readable, ReadableArgs, Writeable, Writer};
40-
4140
use crate::io;
4241
use crate::prelude::*;
4342
use alloc::collections::BinaryHeap;
@@ -2453,7 +2452,7 @@ where L::Target: Logger {
24532452
let our_node_id = NodeId::from_pubkey(&our_node_pubkey);
24542453

24552454
if payee_node_id_opt.map_or(false, |payee| payee == our_node_id) {
2456-
return Err("Cannot generate a route to ourselves");
2455+
return create_self_payment_route(our_node_pubkey, route_params);
24572456
}
24582457
if our_node_id == maybe_dummy_payee_node_id {
24592458
return Err("Invalid origin node id provided, use a different one");
@@ -3727,6 +3726,25 @@ where L::Target: Logger {
37273726
Ok(route)
37283727
}
37293728

3729+
fn create_self_payment_route(our_node_pubkey: &PublicKey, route_params: &RouteParameters) -> Result<Route, &'static str> {
3730+
let path = Path {
3731+
hops: vec![RouteHop {
3732+
pubkey: our_node_pubkey.clone(),
3733+
short_channel_id: 0 , // Dummy short_channel_id specifying self payment
3734+
fee_msat: 0, // Zero fees
3735+
cltv_expiry_delta: MIN_FINAL_CLTV_EXPIRY_DELTA.into(),
3736+
node_features: NodeFeatures::empty(),
3737+
channel_features: ChannelFeatures::empty(),
3738+
maybe_announced_channel: false,
3739+
}],
3740+
blinded_tail: None,
3741+
};
3742+
Ok(Route {
3743+
paths: vec![path],
3744+
route_params: Some(route_params.clone()),
3745+
})
3746+
}
3747+
37303748
// When an adversarial intermediary node observes a payment, it may be able to infer its
37313749
// destination, if the remaining CLTV expiry delta exactly matches a feasible path in the network
37323750
// graph. In order to improve privacy, this method obfuscates the CLTV expiry deltas along the

0 commit comments

Comments
 (0)