Skip to content
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

Add method to count total fees in a Route #999 #1063

Merged
merged 1 commit into from
Sep 21, 2021

Conversation

galderz
Copy link
Contributor

@galderz galderz commented Aug 27, 2021

Part of #999. Add a member function for Route that returns the total amount of fees paid across all paths.

Further work will be carried out following @valentinewallace's work in #1053, so that the same can be calculated post payment. This implies taking into account which payments were really confirmed and discard what failed or was retried.

@codecov
Copy link

codecov bot commented Aug 27, 2021

Codecov Report

Merging #1063 (03bb808) into main (4368b56) will decrease coverage by 0.07%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1063      +/-   ##
==========================================
- Coverage   90.82%   90.74%   -0.08%     
==========================================
  Files          65       65              
  Lines       32890    33948    +1058     
==========================================
+ Hits        29872    30806     +934     
- Misses       3018     3142     +124     
Impacted Files Coverage Δ
lightning/src/routing/router.rs 95.99% <100.00%> (+0.05%) ⬆️
lightning/src/ln/msgs.rs 85.70% <0.00%> (-3.41%) ⬇️
lightning/src/ln/chan_utils.rs 96.20% <0.00%> (-1.22%) ⬇️
lightning/src/util/ser_macros.rs 86.84% <0.00%> (-1.06%) ⬇️
lightning/src/util/enforcing_trait_impls.rs 89.38% <0.00%> (-1.01%) ⬇️
lightning/src/ln/channelmanager.rs 85.00% <0.00%> (-0.85%) ⬇️
lightning/src/chain/channelmonitor.rs 91.26% <0.00%> (-0.71%) ⬇️
lightning/src/chain/keysinterface.rs 94.86% <0.00%> (-0.51%) ⬇️
lightning-invoice/src/lib.rs 88.11% <0.00%> (-0.39%) ⬇️
lightning/src/util/ser.rs 91.92% <0.00%> (-0.28%) ⬇️
... and 22 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4368b56...03bb808. Read the comment docs.

@TheBlueMatt TheBlueMatt added this to the 0.0.101 milestone Sep 9, 2021
…devkit#999

* Added `get_total_fees` method to route,
to calculate all the fees paid accross each path.
* Added `get_total_amount` method to route,
to calculate the total of actual amounts paid in each path.
@galderz
Copy link
Contributor Author

galderz commented Sep 21, 2021

Reworked unit tests and added an extra get_total_amount method.

Copy link
Contributor

@valentinewallace valentinewallace left a comment

Choose a reason for hiding this comment

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

Just nits, LGTM

Comment on lines +76 to +77
/// This doesn't include any extra payment made to the recipient,
/// which can happen in excess of the amount passed to `get_route`'s `final_value_msat`.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: lines should be 100chars each

.flat_map(|path| path.split_last().unwrap().1)
.map(|hop| &hop.fee_msat)
.sum();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: newline below

.map(|hop| &hop.fee_msat)
.sum();
}
/// Returns the total amount paid on this Route, excluding the fees.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: ticks around Route and above

.sum();
}
/// Returns the total amount paid on this Route, excluding the fees.
pub fn get_total_amount(&self) -> u64 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Idk if it's worth noting for these methods that they'll panic for 0-length routes?

RouteHop {
pubkey: PublicKey::from_slice(&hex::decode("02eec7245d6b7d2ccb30380bfbe2a3648cd7a942653f5aa340edcea1f283686619").unwrap()[..]).unwrap(),
channel_features: ChannelFeatures::empty(), node_features: NodeFeatures::empty(),
short_channel_id: 0, fee_msat: 100, cltv_expiry_delta: 0 // Test vectors are garbage and not generateble from a RouteHop, we fill in payloads manually
Copy link
Contributor

Choose a reason for hiding this comment

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

nit here and below: s/generateble/generatable (i think these comments can all be deleted though 😛)

@TheBlueMatt
Copy link
Collaborator

Gonna land this, will handle val's comments in a new PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants