Skip to content

Clean channelmonitor.rs code #3429

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

Conversation

andrei-21
Copy link
Contributor

  • Replace deprecated u64::max_value()
  • Use Option::is_some()
  • Use Iterator::any() instead of Iterator::find()

* Replace deprecated `u64::max_value()`
* Use `Option::is_some()`
* Use `Iterator::any()` instead of `Iterator::find()`
Copy link
Contributor

@vincenzopalazzo vincenzopalazzo left a comment

Choose a reason for hiding this comment

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

looks like that CI is complaining?

@andrei-21
Copy link
Contributor Author

looks like that CI is complaining?

Seems that it is not related to the changes. Or do you mean something specific?

Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

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

Thanks!

@@ -104,7 +104,7 @@ pub struct ChannelMonitorUpdate {

/// LDK prior to 0.1 used this constant as the [`ChannelMonitorUpdate::update_id`] for any
/// [`ChannelMonitorUpdate`]s which were generated after the channel was closed.
const LEGACY_CLOSED_CHANNEL_UPDATE_ID: u64 = core::u64::MAX;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is gonna conflict with #3413.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean here? I only dropped core:: prefix, you are not touching this line in your PR.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, sorry, I had my PRs confused. The one I was thinking of already landed lol

@@ -794,10 +794,10 @@ struct IrrevocablyResolvedHTLC {
// In LDK versions prior to 0.0.111 commitment_tx_output_idx was not Option-al and
// IrrevocablyResolvedHTLC objects only existed for non-dust HTLCs. This was a bug, but to maintain
// backwards compatibility we must ensure we always write out a commitment_tx_output_idx field,
// using `u32::max_value()` as a sentinal to indicate the HTLC was dust.
// using `u32::MAX` as a sentinal to indicate the HTLC was dust.
Copy link
Collaborator

Choose a reason for hiding this comment

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

while you're here can you [] link?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Also made it a Rust comment (prefixed with ///).

Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

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

Otherwise LGTM

}
}
let (onchain_events_reaching_threshold_conf, onchain_events_awaiting_threshold_conf): (Vec<_>, Vec<_>) =
self.onchain_events_awaiting_threshold_conf.drain(..).partition(
Copy link
Collaborator

Choose a reason for hiding this comment

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

This adds an assumption that onchain_events_awaiting_threshold_conf is sorted by when events will reach their confirmation threshold. That may be the case in practice (its not entirely clear to me from the code), but I'm not super happy with adding that assumption here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, how? partition() does not make such an assumption:

partition() returns a pair, all of the elements for which it returned true, and all of the elements for which it returned false.

https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.partition

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, that's a terrible name for that function lol.

@TheBlueMatt TheBlueMatt modified the milestone: 0.1 Dec 4, 2024
Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

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

Thanks

@TheBlueMatt TheBlueMatt merged commit 726dd5c into lightningdevkit:main Dec 4, 2024
14 of 19 checks passed
@andrei-21 andrei-21 deleted the feature/channelmonitor-goodies branch December 4, 2024 14:58
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.

3 participants