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

[draft] Add cherry picks #1

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lightning-net-tokio/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,9 +590,11 @@ mod tests {
msg_events: Mutex<Vec<MessageSendEvent>>,
}
impl RoutingMessageHandler for MsgHandler {
fn handle_node_announcement(&self, _msg: &NodeAnnouncement) -> Result<bool, LightningError> { Ok(false) }
fn handle_channel_announcement(&self, _msg: &ChannelAnnouncement) -> Result<bool, LightningError> { Ok(false) }
fn handle_channel_update(&self, _msg: &ChannelUpdate) -> Result<bool, LightningError> { Ok(false) }
fn handle_node_announcement(&self, _their_node_id: Option<&PublicKey>, _msg: &NodeAnnouncement) -> Result<bool, LightningError> { Ok(false) }
fn handle_channel_announcement(&self, _their_node_id: Option<&PublicKey>, _msg: &ChannelAnnouncement) -> Result<bool, LightningError> { Ok(false) }
fn handle_channel_update(
&self, _their_node_id: Option<&PublicKey>, _msg: &ChannelUpdate,
) -> Result<bool, LightningError> { Ok(false) }
fn get_next_channel_announcement(&self, _starting_point: u64) -> Option<(ChannelAnnouncement, Option<ChannelUpdate>, Option<ChannelUpdate>)> { None }
fn get_next_node_announcement(&self, _starting_point: Option<&NodeId>) -> Option<NodeAnnouncement> { None }
fn peer_connected(&self, _their_node_id: &PublicKey, _init_msg: &Init, _inbound: bool) -> Result<(), ()> { Ok(()) }
Expand Down
9 changes: 5 additions & 4 deletions lightning/src/ln/chanmon_update_fail_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1941,10 +1941,11 @@ fn do_during_funding_monitor_fail(confirm_a_first: bool, restore_b_before_conf:
let (channel_ready, channel_id) = create_chan_between_nodes_with_value_confirm_second(&nodes[0], &nodes[1]);
(channel_id, create_chan_between_nodes_with_value_b(&nodes[1], &nodes[0], &channel_ready))
};
for node in nodes.iter() {
assert!(node.gossip_sync.handle_channel_announcement(&announcement).unwrap());
node.gossip_sync.handle_channel_update(&as_update).unwrap();
node.gossip_sync.handle_channel_update(&bs_update).unwrap();
for (i, node) in nodes.iter().enumerate() {
let counterparty_node_id = nodes[(i + 1) % 2].node.get_our_node_id();
assert!(node.gossip_sync.handle_channel_announcement(Some(&counterparty_node_id), &announcement).unwrap());
node.gossip_sync.handle_channel_update(Some(&counterparty_node_id), &as_update).unwrap();
node.gossip_sync.handle_channel_update(Some(&counterparty_node_id), &bs_update).unwrap();
}

if !restore_b_before_lock {
Expand Down
17 changes: 10 additions & 7 deletions lightning/src/ln/functional_test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1463,14 +1463,16 @@ pub fn create_unannounced_chan_between_nodes_with_value<'a, 'b, 'c, 'd>(nodes: &

pub fn update_nodes_with_chan_announce<'a, 'b, 'c, 'd>(nodes: &'a Vec<Node<'b, 'c, 'd>>, a: usize, b: usize, ann: &msgs::ChannelAnnouncement, upd_1: &msgs::ChannelUpdate, upd_2: &msgs::ChannelUpdate) {
for node in nodes {
assert!(node.gossip_sync.handle_channel_announcement(ann).unwrap());
node.gossip_sync.handle_channel_update(upd_1).unwrap();
node.gossip_sync.handle_channel_update(upd_2).unwrap();
let node_id_a = nodes[a].node.get_our_node_id();
let node_id_b = nodes[b].node.get_our_node_id();
assert!(node.gossip_sync.handle_channel_announcement(None, ann).unwrap());
node.gossip_sync.handle_channel_update(Some(&node_id_a), upd_1).unwrap();
node.gossip_sync.handle_channel_update(Some(&node_id_b), upd_2).unwrap();

// Note that channel_updates are also delivered to ChannelManagers to ensure we have
// forwarding info for local channels even if its not accepted in the network graph.
node.node.handle_channel_update(&nodes[a].node.get_our_node_id(), &upd_1);
node.node.handle_channel_update(&nodes[b].node.get_our_node_id(), &upd_2);
node.node.handle_channel_update(&node_id_a, &upd_1);
node.node.handle_channel_update(&node_id_b, &upd_2);
}
}

Expand Down Expand Up @@ -3463,9 +3465,10 @@ pub fn handle_announce_close_broadcast_events<'a, 'b, 'c>(nodes: &Vec<Node<'a, '
if dummy_connected {
disconnect_dummy_node(&nodes[b]);
}
let node_id_a = nodes[a].node.get_our_node_id();
for node in nodes {
node.gossip_sync.handle_channel_update(&as_update).unwrap();
node.gossip_sync.handle_channel_update(&bs_update).unwrap();
node.gossip_sync.handle_channel_update(Some(&node_id_a), &as_update).unwrap();
node.gossip_sync.handle_channel_update(Some(&node_id_a), &bs_update).unwrap();
}
}

Expand Down
8 changes: 5 additions & 3 deletions lightning/src/ln/functional_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2452,14 +2452,16 @@ fn channel_monitor_network_test() {
check_preimage_claim(&nodes[4], &node_txn);
(close_chan_update_1, close_chan_update_2)
};
nodes[3].gossip_sync.handle_channel_update(&close_chan_update_2).unwrap();
nodes[4].gossip_sync.handle_channel_update(&close_chan_update_1).unwrap();
let node_id_4 = nodes[4].node.get_our_node_id();
let node_id_3 = nodes[3].node.get_our_node_id();
nodes[3].gossip_sync.handle_channel_update(Some(&node_id_4), &close_chan_update_2).unwrap();
nodes[4].gossip_sync.handle_channel_update(Some(&node_id_3), &close_chan_update_1).unwrap();
assert_eq!(nodes[3].node.list_channels().len(), 0);
assert_eq!(nodes[4].node.list_channels().len(), 0);

assert_eq!(nodes[3].chain_monitor.chain_monitor.watch_channel(OutPoint { txid: chan_3.3.txid(), index: 0 }, chan_3_mon),
Ok(ChannelMonitorUpdateStatus::Completed));
check_closed_event!(nodes[3], 1, ClosureReason::HTLCsTimedOut, [nodes[4].node.get_our_node_id()], 100000);
check_closed_event!(nodes[3], 1, ClosureReason::HTLCsTimedOut, [node_id_4], 100000);
}

#[test]
Expand Down
12 changes: 9 additions & 3 deletions lightning/src/ln/msgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1562,13 +1562,19 @@ pub trait ChannelMessageHandler : MessageSendEventsProvider {
pub trait RoutingMessageHandler : MessageSendEventsProvider {
/// Handle an incoming `node_announcement` message, returning `true` if it should be forwarded on,
/// `false` or returning an `Err` otherwise.
fn handle_node_announcement(&self, msg: &NodeAnnouncement) -> Result<bool, LightningError>;
///
/// If `their_node_id` is `None`, the message was generated by our own local node.
fn handle_node_announcement(&self, their_node_id: Option<&PublicKey>, msg: &NodeAnnouncement) -> Result<bool, LightningError>;
/// Handle a `channel_announcement` message, returning `true` if it should be forwarded on, `false`
/// or returning an `Err` otherwise.
fn handle_channel_announcement(&self, msg: &ChannelAnnouncement) -> Result<bool, LightningError>;
///
/// If `their_node_id` is `None`, the message was generated by our own local node.
fn handle_channel_announcement(&self, their_node_id: Option<&PublicKey>, msg: &ChannelAnnouncement) -> Result<bool, LightningError>;
/// Handle an incoming `channel_update` message, returning true if it should be forwarded on,
/// `false` or returning an `Err` otherwise.
fn handle_channel_update(&self, msg: &ChannelUpdate) -> Result<bool, LightningError>;
///
/// If `their_node_id` is `None`, the message was generated by our own local node.
fn handle_channel_update(&self, their_node_id: Option<&PublicKey>, msg: &ChannelUpdate) -> Result<bool, LightningError>;
/// Gets channel announcements and updates required to dump our routing table to a remote node,
/// starting at the `short_channel_id` indicated by `starting_point` and including announcements
/// for a single channel.
Expand Down
5 changes: 3 additions & 2 deletions lightning/src/ln/offers_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,10 @@ fn announce_node_address<'a, 'b, 'c>(
contents: announcement
};

node.gossip_sync.handle_node_announcement(&msg).unwrap();
let node_pubkey = node.node.get_our_node_id();
node.gossip_sync.handle_node_announcement(None, &msg).unwrap();
for peer in peers {
peer.gossip_sync.handle_node_announcement(&msg).unwrap();
peer.gossip_sync.handle_node_announcement(Some(&node_pubkey), &msg).unwrap();
}
}

Expand Down
24 changes: 12 additions & 12 deletions lightning/src/ln/peer_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ impl MessageSendEventsProvider for IgnoringMessageHandler {
fn get_and_clear_pending_msg_events(&self) -> Vec<MessageSendEvent> { Vec::new() }
}
impl RoutingMessageHandler for IgnoringMessageHandler {
fn handle_node_announcement(&self, _msg: &msgs::NodeAnnouncement) -> Result<bool, LightningError> { Ok(false) }
fn handle_channel_announcement(&self, _msg: &msgs::ChannelAnnouncement) -> Result<bool, LightningError> { Ok(false) }
fn handle_channel_update(&self, _msg: &msgs::ChannelUpdate) -> Result<bool, LightningError> { Ok(false) }
fn handle_node_announcement(&self, _their_node_id: Option<&PublicKey>, _msg: &msgs::NodeAnnouncement) -> Result<bool, LightningError> { Ok(false) }
fn handle_channel_announcement(&self, _their_node_id: Option<&PublicKey>, _msg: &msgs::ChannelAnnouncement) -> Result<bool, LightningError> { Ok(false) }
fn handle_channel_update(&self, _their_node_id: Option<&PublicKey>, _msg: &msgs::ChannelUpdate) -> Result<bool, LightningError> { Ok(false) }
fn get_next_channel_announcement(&self, _starting_point: u64) ->
Option<(msgs::ChannelAnnouncement, Option<msgs::ChannelUpdate>, Option<msgs::ChannelUpdate>)> { None }
fn get_next_node_announcement(&self, _starting_point: Option<&NodeId>) -> Option<msgs::NodeAnnouncement> { None }
Expand Down Expand Up @@ -1869,22 +1869,22 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
self.message_handler.chan_handler.handle_announcement_signatures(&their_node_id, &msg);
},
wire::Message::ChannelAnnouncement(msg) => {
if self.message_handler.route_handler.handle_channel_announcement(&msg)
if self.message_handler.route_handler.handle_channel_announcement(Some(their_node_id), &msg)
.map_err(|e| -> MessageHandlingError { e.into() })? {
should_forward = Some(wire::Message::ChannelAnnouncement(msg));
}
self.update_gossip_backlogged();
},
wire::Message::NodeAnnouncement(msg) => {
if self.message_handler.route_handler.handle_node_announcement(&msg)
if self.message_handler.route_handler.handle_node_announcement(Some(their_node_id), &msg)
.map_err(|e| -> MessageHandlingError { e.into() })? {
should_forward = Some(wire::Message::NodeAnnouncement(msg));
}
self.update_gossip_backlogged();
},
wire::Message::ChannelUpdate(msg) => {
self.message_handler.chan_handler.handle_channel_update(&their_node_id, &msg);
if self.message_handler.route_handler.handle_channel_update(&msg)
self.message_handler.chan_handler.handle_channel_update(their_node_id, &msg);
if self.message_handler.route_handler.handle_channel_update(Some(their_node_id), &msg)
.map_err(|e| -> MessageHandlingError { e.into() })? {
should_forward = Some(wire::Message::ChannelUpdate(msg));
}
Expand Down Expand Up @@ -2267,13 +2267,13 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
},
MessageSendEvent::BroadcastChannelAnnouncement { msg, update_msg } => {
log_debug!(self.logger, "Handling BroadcastChannelAnnouncement event in peer_handler for short channel id {}", msg.contents.short_channel_id);
match self.message_handler.route_handler.handle_channel_announcement(&msg) {
match self.message_handler.route_handler.handle_channel_announcement(None, &msg) {
Ok(_) | Err(LightningError { action: msgs::ErrorAction::IgnoreDuplicateGossip, .. }) =>
self.forward_broadcast_msg(peers, &wire::Message::ChannelAnnouncement(msg), None),
_ => {},
}
if let Some(msg) = update_msg {
match self.message_handler.route_handler.handle_channel_update(&msg) {
match self.message_handler.route_handler.handle_channel_update(None, &msg) {
Ok(_) | Err(LightningError { action: msgs::ErrorAction::IgnoreDuplicateGossip, .. }) =>
self.forward_broadcast_msg(peers, &wire::Message::ChannelUpdate(msg), None),
_ => {},
Expand All @@ -2282,15 +2282,15 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
},
MessageSendEvent::BroadcastChannelUpdate { msg } => {
log_debug!(self.logger, "Handling BroadcastChannelUpdate event in peer_handler for contents {:?}", msg.contents);
match self.message_handler.route_handler.handle_channel_update(&msg) {
match self.message_handler.route_handler.handle_channel_update(None, &msg) {
Ok(_) | Err(LightningError { action: msgs::ErrorAction::IgnoreDuplicateGossip, .. }) =>
self.forward_broadcast_msg(peers, &wire::Message::ChannelUpdate(msg), None),
_ => {},
}
},
MessageSendEvent::BroadcastNodeAnnouncement { msg } => {
log_debug!(self.logger, "Handling BroadcastNodeAnnouncement event in peer_handler for node {}", msg.contents.node_id);
match self.message_handler.route_handler.handle_node_announcement(&msg) {
match self.message_handler.route_handler.handle_node_announcement(None, &msg) {
Ok(_) | Err(LightningError { action: msgs::ErrorAction::IgnoreDuplicateGossip, .. }) =>
self.forward_broadcast_msg(peers, &wire::Message::NodeAnnouncement(msg), None),
_ => {},
Expand Down Expand Up @@ -2653,7 +2653,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
};

log_debug!(self.logger, "Broadcasting NodeAnnouncement after passing it to our own RoutingMessageHandler.");
let _ = self.message_handler.route_handler.handle_node_announcement(&msg);
let _ = self.message_handler.route_handler.handle_node_announcement(None, &msg);
self.forward_broadcast_msg(&*self.peers.read().unwrap(), &wire::Message::NodeAnnouncement(msg), None);
}
}
Expand Down
9 changes: 5 additions & 4 deletions lightning/src/ln/priv_short_conf_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,11 @@ fn do_test_1_conf_open(connect_style: ConnectStyle) {
} else { panic!("Unexpected event"); };
assert_eq!(announcement, bs_announcement);

for node in nodes {
assert!(node.gossip_sync.handle_channel_announcement(&announcement).unwrap());
node.gossip_sync.handle_channel_update(&as_update).unwrap();
node.gossip_sync.handle_channel_update(&bs_update).unwrap();
for (i, node) in nodes.iter().enumerate() {
let counterparty_node_id = nodes[(i + 1) % 2].node.get_our_node_id();
assert!(node.gossip_sync.handle_channel_announcement(Some(&counterparty_node_id), &announcement).unwrap());
node.gossip_sync.handle_channel_update(Some(&counterparty_node_id), &as_update).unwrap();
node.gossip_sync.handle_channel_update(Some(&counterparty_node_id), &bs_update).unwrap();
}
}
#[test]
Expand Down
25 changes: 14 additions & 11 deletions lightning/src/ln/reload_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,10 @@ fn test_funding_peer_disconnect() {
};

// Provide the channel announcement and public updates to the network graph
nodes[0].gossip_sync.handle_channel_announcement(&chan_announcement).unwrap();
nodes[0].gossip_sync.handle_channel_update(&bs_update).unwrap();
nodes[0].gossip_sync.handle_channel_update(&as_update).unwrap();
let node_1_pubkey = nodes[1].node.get_our_node_id();
nodes[0].gossip_sync.handle_channel_announcement(Some(&node_1_pubkey), &chan_announcement).unwrap();
nodes[0].gossip_sync.handle_channel_update(Some(&node_1_pubkey), &bs_update).unwrap();
nodes[0].gossip_sync.handle_channel_update(Some(&node_1_pubkey), &as_update).unwrap();

let (route, _, _, _) = get_route_and_payment_hash!(nodes[0], nodes[1], 1000000);
let payment_preimage = send_along_route(&nodes[0], route, &[&nodes[1]], 1000000).0;
Expand Down Expand Up @@ -220,10 +221,11 @@ fn test_no_txn_manager_serialize_deserialize() {

let (channel_ready, _) = create_chan_between_nodes_with_value_confirm(&nodes[0], &nodes[1], &tx);
let (announcement, as_update, bs_update) = create_chan_between_nodes_with_value_b(&nodes[0], &nodes[1], &channel_ready);
for node in nodes.iter() {
assert!(node.gossip_sync.handle_channel_announcement(&announcement).unwrap());
node.gossip_sync.handle_channel_update(&as_update).unwrap();
node.gossip_sync.handle_channel_update(&bs_update).unwrap();
for (i, node) in nodes.iter().enumerate() {
let counterparty_node_id = nodes[(i + 1) % 2].node.get_our_node_id();
assert!(node.gossip_sync.handle_channel_announcement(Some(&counterparty_node_id), &announcement).unwrap());
node.gossip_sync.handle_channel_update(Some(&counterparty_node_id), &as_update).unwrap();
node.gossip_sync.handle_channel_update(Some(&counterparty_node_id), &bs_update).unwrap();
}

send_payment(&nodes[0], &[&nodes[1]], 1000000);
Expand Down Expand Up @@ -310,10 +312,11 @@ fn test_manager_serialize_deserialize_events() {

let (channel_ready, _) = create_chan_between_nodes_with_value_confirm(&nodes[0], &nodes[1], &tx);
let (announcement, as_update, bs_update) = create_chan_between_nodes_with_value_b(&nodes[0], &nodes[1], &channel_ready);
for node in nodes.iter() {
assert!(node.gossip_sync.handle_channel_announcement(&announcement).unwrap());
node.gossip_sync.handle_channel_update(&as_update).unwrap();
node.gossip_sync.handle_channel_update(&bs_update).unwrap();
for (i, node) in nodes.iter().enumerate() {
let counterparty_node_id = nodes[(i + 1) % 2].node.get_our_node_id();
assert!(node.gossip_sync.handle_channel_announcement(Some(&counterparty_node_id), &announcement).unwrap());
node.gossip_sync.handle_channel_update(Some(&counterparty_node_id), &as_update).unwrap();
node.gossip_sync.handle_channel_update(Some(&counterparty_node_id), &bs_update).unwrap();
}

send_payment(&nodes[0], &[&nodes[1]], 1000000);
Expand Down
Loading
Loading