-
Notifications
You must be signed in to change notification settings - Fork 398
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 ChannelContext::get_commitment_stats
#3682
base: main
Are you sure you want to change the base?
Add ChannelContext::get_commitment_stats
#3682
Conversation
👋 Thanks for assigning @TheBlueMatt as a reviewer! |
0af1b43
to
31300c3
Compare
Why is this draft? |
@TheBlueMatt I don't feel great about the code duplication between Let me know what you think. |
I'm working on further cleanups now. |
d6b1f51
to
c540347
Compare
@wpaulino the PR is in a better spot now, let me know what you think. |
c540347
to
c9b30cb
Compare
e637050
to
4d6bf13
Compare
5a212d8
to
d682615
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3682 +/- ##
==========================================
- Coverage 89.18% 89.16% -0.03%
==========================================
Files 155 155
Lines 120796 120861 +65
Branches 120796 120861 +65
==========================================
+ Hits 107731 107760 +29
- Misses 10415 10446 +31
- Partials 2650 2655 +5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
d682615
to
6f80f99
Compare
@TheBlueMatt take a look when you can thank you! |
lightning/src/ln/channel.rs
Outdated
@@ -223,6 +223,25 @@ impl From<&InboundHTLCState> for Option<InboundHTLCStateDetails> { | |||
} | |||
} | |||
|
|||
impl InboundHTLCState { | |||
fn as_str(&self) -> &str { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heh, if its just for logging I think we can #[derive(Debug)]
:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Debug
would log all their inner contents too - don't think that's what we want here ?
I would have to derive Debug
in a bunch more places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I'll just move that function to an impl fmt::Debug for InboundHTLCState
:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Went with an impl fmt::Display
here, seems this corresponds most to what we want.
lightning/src/ln/channel.rs
Outdated
/// have not yet committed it. Such HTLCs will only be included in transactions which are being | ||
/// generated by the peer which proposed adding the HTLCs, and thus we need to understand both | ||
/// which peer generated this transaction and "to whom" this transaction flows. | ||
fn for_each_inbound<F>(&self, generated_by_local: bool, mut for_each: F) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fn name here doesn't really communicate what it does/is used for. Maybe inbound_htlcs_in_commitment
? It might also be more Rust-y to return an impl Iterator
and let the callsite do the for, rather than doing it as a callback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We initially had something like this is it closer to what you have in mind?
for htlc in self.pending_inbound_htlcs.iter() {
if htlc.state.included_in_commitment(generated_by_local) {
..
} else {
..
}
}
some other options for that specific function's return value:
- one iterator yielding (included, htlc)
- two iterators each yielding htlc, one for included, one for excluded.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Went with the very first option above.
6f80f99
to
a6c6eac
Compare
It can be useful to get the stats on a potential commitment transaction without actually building it. Therefore, this commit splits the stats calculations from the actual build of a commitment transaction. This introduces an extra loop over the pending htlcs, but current network behavior produces very few concurrent htlcs on channels. Furthermore, each iteration of the loop in the stats calculation is very cheap.
a6c6eac
to
71df614
Compare
Requested by @wpaulino in #3641