Skip to content

feat: Implement self payment #3934

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4906,6 +4906,9 @@ where
path, payment_hash, recipient_onion, total_value, cur_height, payment_id, keysend_preimage,
invoice_request, bolt12_invoice, session_priv_bytes
} = args;



// The top-level caller should hold the total_consistency_lock read lock.
debug_assert!(self.total_consistency_lock.try_write().is_err());
let prng_seed = self.entropy_source.get_secure_random_bytes();
Expand Down
22 changes: 20 additions & 2 deletions lightning/src/routing/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ use crate::types::features::{
use crate::types::payment::{PaymentHash, PaymentPreimage};
use crate::util::logger::Logger;
use crate::util::ser::{Readable, ReadableArgs, Writeable, Writer};

use crate::io;
use crate::prelude::*;
use alloc::collections::BinaryHeap;
Expand Down Expand Up @@ -2453,7 +2452,7 @@ where L::Target: Logger {
let our_node_id = NodeId::from_pubkey(&our_node_pubkey);

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

fn create_self_payment_route(our_node_pubkey: &PublicKey, route_params: &RouteParameters) -> Result<Route, &'static str> {
let path = Path {
hops: vec![RouteHop {
pubkey: our_node_pubkey.clone(),
short_channel_id: 0 , // Dummy short_channel_id specifying self payment
fee_msat: 0, // Zero fees
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cltv_expiry_delta field is currently hardcoded to MIN_FINAL_CLTV_EXPIRY_DELTA, but it should instead use the value from route_params.final_cltv_expiry_delta to maintain consistency with the requested payment parameters. This ensures that self-payments respect the same CLTV constraints as regular payments.

Spotted by Diamond

Is this helpful? React 👍 or 👎 to let us know.

cltv_expiry_delta: MIN_FINAL_CLTV_EXPIRY_DELTA.into(),
node_features: NodeFeatures::empty(),
channel_features: ChannelFeatures::empty(),
maybe_announced_channel: false,
}],
blinded_tail: None,
};
Ok(Route {
paths: vec![path],
route_params: Some(route_params.clone()),
})
}

// When an adversarial intermediary node observes a payment, it may be able to infer its
// destination, if the remaining CLTV expiry delta exactly matches a feasible path in the network
// graph. In order to improve privacy, this method obfuscates the CLTV expiry deltas along the
Expand Down
Loading