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

chore: simplify fn prune_messages_to_be_saved #414

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

quake
Copy link
Member

@quake quake commented Dec 21, 2024

The current implementation of prune_messages_to_be_saved is complex and unintuitive, it can be implemented in a much simpler way.

@quake quake requested a review from contrun December 21, 2024 10:42
@quake quake force-pushed the quake/refactor-prune_messages_to_be_saved branch from ab9c88a to 1a2ff8f Compare December 21, 2024 11:34
}
}
let mut sorted_messages = complete_messages.into_iter().collect::<Vec<_>>();
sorted_messages.sort_unstable();
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems to use the Ord implementation of BroadcastMessageWithTimestamp, which will sort messages according to their timestamp. It is possible that the timestamp of ChannelUpdate is smaller than that of Channel announcement (we didn't have code to specifically make the timestamp of ChannelUpdate later than the timestamp of the funding transaction block, we just use the system time).

Copy link
Member Author

Choose a reason for hiding this comment

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

will order by message_id first:

fiber/src/fiber/types.rs

Lines 2435 to 2441 in 1a2ff8f

impl Ord for BroadcastMessageWithTimestamp {
fn cmp(&self, other: &Self) -> Ordering {
self.message_id()
.cmp(&other.message_id())
.then(self.timestamp().cmp(&other.timestamp()))
}
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry. I didn't look carefully. In that case, this PR LGTM. I created a few tests for the dependency of channel gossip messages in #418 . Can you take a look and check if the code change here does not break the tests (I believe it doesn't. Still, it is better to
have some tests)?

Copy link
Member Author

Choose a reason for hiding this comment

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

rebased and pushed

@quake quake force-pushed the quake/refactor-prune_messages_to_be_saved branch from 1a2ff8f to c950ba1 Compare December 22, 2024 21:42
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.

2 participants