Skip to content

Commit

Permalink
stash
Browse files Browse the repository at this point in the history
  • Loading branch information
contrun committed Nov 8, 2024
1 parent 8997904 commit b47fb5e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
22 changes: 15 additions & 7 deletions src/fiber/graph.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::network::{get_chain_hash, SendPaymentData, SendPaymentResponse};
use super::path::NodeHeap;
use super::types::Pubkey;
use super::types::{ChannelAnnouncement, ChannelUpdate, Hash256, NodeAnnouncement};
use super::types::{ChannelUpdate, Hash256, NodeAnnouncement};
use crate::fiber::channel::CHANNEL_DISABLED_FLAG;
use crate::fiber::fee::calculate_tlc_forward_fee;
use crate::fiber::path::{NodeHeapElement, ProbabilityEvaluator};
Expand Down Expand Up @@ -32,9 +32,17 @@ pub struct CompactNodeInfo {
pub anouncement_msg: NodeAnnouncement,
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[derive(Clone, Debug, PartialEq)]
pub struct CompactChannelInfo {
pub announcement_msg: ChannelAnnouncement,
pub features: u64,
pub channel_outpoint: OutPoint,

pub node1_id: Pubkey,
pub node2_id: Pubkey,
// The total capacity of the channel.
pub capacity: u128,
// UDT script
pub udt_type_script: Option<Script>,
pub node1_to_node2: Option<CompactChannelUpdateInfo>,
pub node2_to_node1: Option<CompactChannelUpdateInfo>,
// The time that the channel was announced to the network.
Expand All @@ -43,15 +51,15 @@ pub struct CompactChannelInfo {

impl CompactChannelInfo {
pub fn out_point(&self) -> OutPoint {
self.announcement_msg.channel_outpoint.clone()
self.channel_outpoint.clone()
}

pub fn node1(&self) -> Pubkey {
self.announcement_msg.node1_id
self.node1_id
}

pub fn node2(&self) -> Pubkey {
self.announcement_msg.node2_id
self.node2_id
}

pub fn channel_annoucement_timestamp(&self) -> u64 {
Expand Down Expand Up @@ -94,7 +102,7 @@ impl CompactChannelInfo {
}

pub fn capacity(&self) -> u128 {
self.announcement_msg.capacity
self.capacity
}
}

Expand Down
15 changes: 8 additions & 7 deletions src/fiber/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1009,12 +1009,7 @@ where
}) => {
let channel_info = network_graph.get_channel(&channel_outpoint);
match channel_info {
Some(channel_info) => {
let channel_announcement = FiberBroadcastMessage::ChannelAnnouncement(
channel_info.announcement_msg.clone(),
);
Ok(channel_announcement)
}
Some(channel_info) => {}
None => Err(Error::InvalidParameter(format!(
"Channel not found: {:?}",
&channel_outpoint
Expand Down Expand Up @@ -2036,7 +2031,13 @@ where

// Add the channel to the network graph.
let channel_info = CompactChannelInfo {
announcement_msg: channel_announcement.clone(),
features: channel_announcement.features,
channel_outpoint: channel_announcement.channel_outpoint,
node1_id: channel_announcement.node1_id,
node2_id: channel_announcement.node2_id,
capacity: channel_announcement.capacity,
udt_type_script: channel_announcement.udt_type_script,

node1_to_node2: None, // wait for channel update message
node2_to_node1: None,
timestamp: std::time::UNIX_EPOCH.elapsed().unwrap().as_millis() as u64,
Expand Down

0 comments on commit b47fb5e

Please sign in to comment.