Skip to content

Commit

Permalink
chore: make code more readable
Browse files Browse the repository at this point in the history
  • Loading branch information
contrun committed Jan 6, 2025
1 parent a82e613 commit 93bdbb5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
10 changes: 7 additions & 3 deletions src/fiber/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4390,6 +4390,12 @@ impl ChannelActorState {
.expect("Funding transaction outpoint is present")
}

pub fn must_get_funding_transaction_timestamp(&self) -> u64 {
self.funding_tx_confirmed_at
.expect("Funding transaction confirmed at present")
.2
}

pub fn get_local_shutdown_script(&self) -> Script {
self.local_shutdown_script.clone()
}
Expand Down Expand Up @@ -5388,9 +5394,7 @@ impl ChannelActorState {
.send_message(NetworkActorMessage::new_command(
NetworkActorCommand::BroadcastMessages(vec![
BroadcastMessageWithTimestamp::ChannelAnnouncement(
self.funding_tx_confirmed_at
.expect("funding tx confirmed")
.2,
self.must_get_funding_transaction_timestamp(),
channel_announcement,
),
BroadcastMessageWithTimestamp::ChannelUpdate(channel_update),
Expand Down
9 changes: 5 additions & 4 deletions src/fiber/gossip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1085,21 +1085,22 @@ impl<S: GossipMessageStore> ExtendedGossipMessageStoreState<S> {
self.broadcast_messages(messages);
}

fn get_channel_annnouncement(&self, outpoint: &OutPoint) -> Option<(u64, ChannelAnnouncement)> {
fn get_channel_annnouncement(&self, outpoint: &OutPoint) -> Option<ChannelAnnouncement> {
self.store
.get_latest_channel_announcement(outpoint)
.map(|(_, m)| m)
.or_else(|| self.get_channel_annnouncement_in_memory(outpoint))
}

fn get_channel_annnouncement_in_memory(
&self,
outpoint: &OutPoint,
) -> Option<(u64, ChannelAnnouncement)> {
) -> Option<ChannelAnnouncement> {
self.messages_to_be_saved.iter().find_map(|m| match m {
BroadcastMessage::ChannelAnnouncement(channel_announcement)
if &channel_announcement.channel_outpoint == outpoint =>
{
Some((0, channel_announcement.clone()))
Some(channel_announcement.clone())
}
_ => None,
})
Expand All @@ -1119,7 +1120,7 @@ impl<S: GossipMessageStore> ExtendedGossipMessageStoreState<S> {
}
}

if let Some(_) = self.messages_to_be_saved.get(&message) {
if self.messages_to_be_saved.contains(&message) {
return Ok(());
}

Expand Down

0 comments on commit 93bdbb5

Please sign in to comment.