impl RoutingMessageHandler for Router {
fn handle_node_announcement(&self, msg: &msgs::NodeAnnouncement) -> Result<bool, HandleError> {
impl RoutingMessageHandler for Router {
fn handle_node_announcement(&self, msg: &msgs::NodeAnnouncement) -> Result<bool, HandleError> {
secp_verify_sig!(self.secp_ctx, &msg_hash, &msg.signature, &msg.contents.node_id);
if msg.contents.features.requires_unknown_bits() {
secp_verify_sig!(self.secp_ctx, &msg_hash, &msg.signature, &msg.contents.node_id);
if msg.contents.features.requires_unknown_bits() {
secp_verify_sig!(self.secp_ctx, &msg_hash, &msg.node_signature_1, &msg.contents.node_id_1);
secp_verify_sig!(self.secp_ctx, &msg_hash, &msg.node_signature_2, &msg.contents.node_id_2);
secp_verify_sig!(self.secp_ctx, &msg_hash, &msg.bitcoin_signature_1, &msg.contents.bitcoin_key_1);
secp_verify_sig!(self.secp_ctx, &msg_hash, &msg.node_signature_1, &msg.contents.node_id_1);
secp_verify_sig!(self.secp_ctx, &msg_hash, &msg.node_signature_2, &msg.contents.node_id_2);
secp_verify_sig!(self.secp_ctx, &msg_hash, &msg.bitcoin_signature_1, &msg.contents.bitcoin_key_1);
match network.channels.entry(NetworkMap::get_key(msg.contents.short_channel_id, msg.contents.chain_hash)) {
BtreeEntry::Occupied(mut entry) => {
//TODO: because asking the blockchain if short_channel_id is valid is only optional
match network.channels.entry(NetworkMap::get_key(msg.contents.short_channel_id, msg.contents.chain_hash)) {
BtreeEntry::Occupied(mut entry) => {
//TODO: because asking the blockchain if short_channel_id is valid is only optional
if msg.contents.flags & 1 == 1 {
dest_node_id = channel.one_to_two.src_node_id.clone();
secp_verify_sig!(self.secp_ctx, &msg_hash, &msg.signature, &channel.two_to_one.src_node_id);
if msg.contents.flags & 1 == 1 {
dest_node_id = channel.one_to_two.src_node_id.clone();
secp_verify_sig!(self.secp_ctx, &msg_hash, &msg.signature, &channel.two_to_one.src_node_id);
/// mark_channel_bad as a node may simply lie and suggest that an upstream channel from it is
/// what failed the route and not the node itself. Instead, setting the blamed_upstream_node
/// boolean will reduce the penalty, returning the node to usability faster. If the node is
/// mark_channel_bad as a node may simply lie and suggest that an upstream channel from it is
/// what failed the route and not the node itself. Instead, setting the blamed_upstream_node
/// boolean will reduce the penalty, returning the node to usability faster. If the node is
use util::logger::Logger;
use util::ser::{Writeable, Readable};
use util::logger::Logger;
use util::ser::{Writeable, Readable};
let node7 = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&hex::decode("0808080808080808080808080808080808080808080808080808080808080808").unwrap()[..]).unwrap());
let node8 = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&hex::decode("0909090909090909090909090909090909090909090909090909090909090909").unwrap()[..]).unwrap());
let node7 = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&hex::decode("0808080808080808080808080808080808080808080808080808080808080808").unwrap()[..]).unwrap());
let node8 = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&hex::decode("0909090909090909090909090909090909090909090909090909090909090909").unwrap()[..]).unwrap());
remote_network_id: node8.clone(),
channel_value_satoshis: 0,
user_id: 0,
remote_network_id: node8.clone(),
channel_value_satoshis: 0,
user_id: 0,
}];
let route = router.get_route(&node3, Some(&our_chans), &Vec::new(), 100, 42).unwrap();
assert_eq!(route.hops.len(), 2);
}];
let route = router.get_route(&node3, Some(&our_chans), &Vec::new(), 100, 42).unwrap();
assert_eq!(route.hops.len(), 2);
remote_network_id: node4.clone(),
channel_value_satoshis: 0,
user_id: 0,
remote_network_id: node4.clone(),
channel_value_satoshis: 0,
user_id: 0,
}];
let route = router.get_route(&node7, Some(&our_chans), &last_hops, 100, 42).unwrap();
assert_eq!(route.hops.len(), 2);
}];
let route = router.get_route(&node7, Some(&our_chans), &last_hops, 100, 42).unwrap();
assert_eq!(route.hops.len(), 2);