-
Notifications
You must be signed in to change notification settings - Fork 411
Add CandidateRouteHop to channel_penalty_msat inputs #2551
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
Merged
TheBlueMatt
merged 6 commits into
lightningdevkit:main
from
jbesraa:expose-CandidateRouteHop-to-channel_penalty_msat
Dec 6, 2023
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ec95e58
Add `outbound` flag to `DirectedChannelInfo`
jbesraa 366d688
Add `source` and `target` to `DirectedChannelInfo`
jbesraa a1d15ac
Add `source` and `target` fn's to `CandidateRouteHop`
jbesraa 04e93fc
Change `CandidateRouteHop` functions visbility
jbesraa f0ecc3e
Use `CandidateRouteHop` as input for `channel_penalty_msat`
jbesraa cbde4a7
Remove `node_id` from `PathBuildingHop`
jbesraa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -870,31 +870,31 @@ impl ChannelInfo { | |
/// Returns a [`DirectedChannelInfo`] for the channel directed to the given `target` from a | ||
/// returned `source`, or `None` if `target` is not one of the channel's counterparties. | ||
pub fn as_directed_to(&self, target: &NodeId) -> Option<(DirectedChannelInfo, &NodeId)> { | ||
let (direction, source) = { | ||
let (direction, source, outbound) = { | ||
if target == &self.node_one { | ||
(self.two_to_one.as_ref(), &self.node_two) | ||
(self.two_to_one.as_ref(), &self.node_two, false) | ||
} else if target == &self.node_two { | ||
(self.one_to_two.as_ref(), &self.node_one) | ||
(self.one_to_two.as_ref(), &self.node_one, true) | ||
} else { | ||
return None; | ||
} | ||
}; | ||
direction.map(|dir| (DirectedChannelInfo::new(self, dir), source)) | ||
direction.map(|dir| (DirectedChannelInfo::new(self, dir, outbound), source)) | ||
} | ||
|
||
/// Returns a [`DirectedChannelInfo`] for the channel directed from the given `source` to a | ||
/// returned `target`, or `None` if `source` is not one of the channel's counterparties. | ||
pub fn as_directed_from(&self, source: &NodeId) -> Option<(DirectedChannelInfo, &NodeId)> { | ||
let (direction, target) = { | ||
let (direction, target, outbound) = { | ||
if source == &self.node_one { | ||
(self.one_to_two.as_ref(), &self.node_two) | ||
(self.one_to_two.as_ref(), &self.node_two, true) | ||
} else if source == &self.node_two { | ||
(self.two_to_one.as_ref(), &self.node_one) | ||
(self.two_to_one.as_ref(), &self.node_one, false) | ||
} else { | ||
return None; | ||
} | ||
}; | ||
direction.map(|dir| (DirectedChannelInfo::new(self, dir), target)) | ||
direction.map(|dir| (DirectedChannelInfo::new(self, dir, outbound), target)) | ||
} | ||
|
||
/// Returns a [`ChannelUpdateInfo`] based on the direction implied by the channel_flag. | ||
|
@@ -992,24 +992,32 @@ pub struct DirectedChannelInfo<'a> { | |
direction: &'a ChannelUpdateInfo, | ||
htlc_maximum_msat: u64, | ||
effective_capacity: EffectiveCapacity, | ||
/// Outbound from the perspective of `node_one`. | ||
/// | ||
/// If true, the channel is considered to be outbound from `node_one` perspective. | ||
/// If false, the channel is considered to be outbound from `node_two` perspective. | ||
/// | ||
/// [`ChannelInfo::node_one`] | ||
/// [`ChannelInfo::node_two`] | ||
outbound: bool, | ||
TheBlueMatt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
impl<'a> DirectedChannelInfo<'a> { | ||
#[inline] | ||
fn new(channel: &'a ChannelInfo, direction: &'a ChannelUpdateInfo) -> Self { | ||
fn new(channel: &'a ChannelInfo, direction: &'a ChannelUpdateInfo, outbound: bool) -> Self { | ||
let mut htlc_maximum_msat = direction.htlc_maximum_msat; | ||
let capacity_msat = channel.capacity_sats.map(|capacity_sats| capacity_sats * 1000); | ||
|
||
let effective_capacity = match capacity_msat { | ||
Some(capacity_msat) => { | ||
htlc_maximum_msat = cmp::min(htlc_maximum_msat, capacity_msat); | ||
EffectiveCapacity::Total { capacity_msat, htlc_maximum_msat: htlc_maximum_msat } | ||
EffectiveCapacity::Total { capacity_msat, htlc_maximum_msat } | ||
}, | ||
None => EffectiveCapacity::AdvertisedMaxHTLC { amount_msat: htlc_maximum_msat }, | ||
}; | ||
|
||
Self { | ||
channel, direction, htlc_maximum_msat, effective_capacity | ||
channel, direction, htlc_maximum_msat, effective_capacity, outbound | ||
} | ||
} | ||
|
||
|
@@ -1035,6 +1043,16 @@ impl<'a> DirectedChannelInfo<'a> { | |
/// Returns information for the direction. | ||
#[inline] | ||
pub(super) fn direction(&self) -> &'a ChannelUpdateInfo { self.direction } | ||
|
||
/// Returns the `node_id` of the source hop. | ||
/// | ||
/// Refers to the `node_id` forwarding the payment to the next hop. | ||
Comment on lines
+1047
to
+1049
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's just combine this as: /// Returns the `node_id` forwarding the payment to the next hop.
|
||
pub(super) fn source(&self) -> &'a NodeId { if self.outbound { &self.channel.node_one } else { &self.channel.node_two } } | ||
|
||
/// Returns the `node_id` of the target hop. | ||
/// | ||
/// Refers to the `node_id` receiving the payment from the previous hop. | ||
Comment on lines
+1052
to
+1054
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar. |
||
pub(super) fn target(&self) -> &'a NodeId { if self.outbound { &self.channel.node_two } else { &self.channel.node_one } } | ||
} | ||
|
||
impl<'a> fmt::Debug for DirectedChannelInfo<'a> { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.