-use routing::gossip::{NetworkGraph, P2PGossipSync};
-use ln::features::{ChannelFeatures, NodeFeatures};
-use ln::msgs::{UnsignedChannelAnnouncement, ChannelAnnouncement, RoutingMessageHandler,
+use crate::routing::gossip::{NetworkGraph, NodeAlias, P2PGossipSync};
+use crate::ln::features::{ChannelFeatures, NodeFeatures};
+use crate::ln::msgs::{UnsignedChannelAnnouncement, ChannelAnnouncement, RoutingMessageHandler,
NodeAnnouncement, UnsignedNodeAnnouncement, ChannelUpdate, UnsignedChannelUpdate, MAX_VALUE_MSAT};
NodeAnnouncement, UnsignedNodeAnnouncement, ChannelUpdate, UnsignedChannelUpdate, MAX_VALUE_MSAT};
use bitcoin::secp256k1::{PublicKey,SecretKey};
use bitcoin::secp256k1::{Secp256k1, All};
use bitcoin::secp256k1::{PublicKey,SecretKey};
use bitcoin::secp256k1::{Secp256k1, All};
// Using the same keys for LN and BTC ids
pub(super) fn add_channel(
gossip_sync: &P2PGossipSync<Arc<NetworkGraph<Arc<test_utils::TestLogger>>>, Arc<test_utils::TestChainSource>, Arc<test_utils::TestLogger>>,
secp_ctx: &Secp256k1<All>, node_1_privkey: &SecretKey, node_2_privkey: &SecretKey, features: ChannelFeatures, short_channel_id: u64
) {
// Using the same keys for LN and BTC ids
pub(super) fn add_channel(
gossip_sync: &P2PGossipSync<Arc<NetworkGraph<Arc<test_utils::TestLogger>>>, Arc<test_utils::TestChainSource>, Arc<test_utils::TestLogger>>,
secp_ctx: &Secp256k1<All>, node_1_privkey: &SecretKey, node_2_privkey: &SecretKey, features: ChannelFeatures, short_channel_id: u64
) {
- let node_id_1 = PublicKey::from_secret_key(&secp_ctx, node_1_privkey);
- let node_id_2 = PublicKey::from_secret_key(&secp_ctx, node_2_privkey);
+ let node_id_1 = NodeId::from_pubkey(&PublicKey::from_secret_key(&secp_ctx, node_1_privkey));
+ let node_id_2 = NodeId::from_pubkey(&PublicKey::from_secret_key(&secp_ctx, node_2_privkey));
gossip_sync: &P2PGossipSync<Arc<NetworkGraph<Arc<test_utils::TestLogger>>>, Arc<test_utils::TestChainSource>, Arc<test_utils::TestLogger>>,
secp_ctx: &Secp256k1<All>, node_privkey: &SecretKey, features: NodeFeatures, timestamp: u32
) {
gossip_sync: &P2PGossipSync<Arc<NetworkGraph<Arc<test_utils::TestLogger>>>, Arc<test_utils::TestChainSource>, Arc<test_utils::TestLogger>>,
secp_ctx: &Secp256k1<All>, node_privkey: &SecretKey, features: NodeFeatures, timestamp: u32
) {
pub(super) fn get_nodes(secp_ctx: &Secp256k1<All>) -> (SecretKey, PublicKey, Vec<SecretKey>, Vec<PublicKey>) {
let privkeys: Vec<SecretKey> = (2..22).map(|i| {
pub(super) fn get_nodes(secp_ctx: &Secp256k1<All>) -> (SecretKey, PublicKey, Vec<SecretKey>, Vec<PublicKey>) {
let privkeys: Vec<SecretKey> = (2..22).map(|i| {
let our_id = PublicKey::from_secret_key(&secp_ctx, &our_privkey);
(our_privkey, our_id, privkeys, pubkeys)
let our_id = PublicKey::from_secret_key(&secp_ctx, &our_privkey);
(our_privkey, our_id, privkeys, pubkeys)
let secp_ctx = Secp256k1::new();
let logger = Arc::new(test_utils::TestLogger::new());
let chain_monitor = Arc::new(test_utils::TestChainSource::new(Network::Testnet));
let secp_ctx = Secp256k1::new();
let logger = Arc::new(test_utils::TestLogger::new());
let chain_monitor = Arc::new(test_utils::TestChainSource::new(Network::Testnet));
- let genesis_hash = genesis_block(Network::Testnet).header.block_hash();
- let network_graph = Arc::new(NetworkGraph::new(genesis_hash, Arc::clone(&logger)));
+ let network_graph = Arc::new(NetworkGraph::new(Network::Testnet, Arc::clone(&logger)));
let gossip_sync = P2PGossipSync::new(Arc::clone(&network_graph), None, Arc::clone(&logger));
// Build network from our_id to node 19:
let gossip_sync = P2PGossipSync::new(Arc::clone(&network_graph), None, Arc::clone(&logger));
// Build network from our_id to node 19:
add_channel(&gossip_sync, &secp_ctx, &cur_privkey, &next_privkey,
ChannelFeatures::from_le_bytes(id_to_feature_flags(1)), cur_short_channel_id);
update_channel(&gossip_sync, &secp_ctx, &cur_privkey, UnsignedChannelUpdate {
add_channel(&gossip_sync, &secp_ctx, &cur_privkey, &next_privkey,
ChannelFeatures::from_le_bytes(id_to_feature_flags(1)), cur_short_channel_id);
update_channel(&gossip_sync, &secp_ctx, &cur_privkey, UnsignedChannelUpdate {
excess_data: Vec::new()
});
update_channel(&gossip_sync, &secp_ctx, &next_privkey, UnsignedChannelUpdate {
excess_data: Vec::new()
});
update_channel(&gossip_sync, &secp_ctx, &next_privkey, UnsignedChannelUpdate {
short_channel_id: cur_short_channel_id,
timestamp: (idx as u32)+1,
flags: 1,
short_channel_id: cur_short_channel_id,
timestamp: (idx as u32)+1,
flags: 1,
let secp_ctx = Secp256k1::new();
let logger = Arc::new(test_utils::TestLogger::new());
let chain_monitor = Arc::new(test_utils::TestChainSource::new(Network::Testnet));
let secp_ctx = Secp256k1::new();
let logger = Arc::new(test_utils::TestLogger::new());
let chain_monitor = Arc::new(test_utils::TestChainSource::new(Network::Testnet));
- let genesis_hash = genesis_block(Network::Testnet).header.block_hash();
- let network_graph = Arc::new(NetworkGraph::new(genesis_hash, Arc::clone(&logger)));
+ let network_graph = Arc::new(NetworkGraph::new(Network::Testnet, Arc::clone(&logger)));
let gossip_sync = P2PGossipSync::new(Arc::clone(&network_graph), None, Arc::clone(&logger));
// Build network from our_id to node6:
//
let gossip_sync = P2PGossipSync::new(Arc::clone(&network_graph), None, Arc::clone(&logger));
// Build network from our_id to node6:
//
add_channel(&gossip_sync, &secp_ctx, &our_privkey, &privkeys[0], ChannelFeatures::from_le_bytes(id_to_feature_flags(1)), 1);
update_channel(&gossip_sync, &secp_ctx, &privkeys[0], UnsignedChannelUpdate {
add_channel(&gossip_sync, &secp_ctx, &our_privkey, &privkeys[0], ChannelFeatures::from_le_bytes(id_to_feature_flags(1)), 1);
update_channel(&gossip_sync, &secp_ctx, &privkeys[0], UnsignedChannelUpdate {
add_channel(&gossip_sync, &secp_ctx, &our_privkey, &privkeys[1], ChannelFeatures::from_le_bytes(id_to_feature_flags(2)), 2);
update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate {
add_channel(&gossip_sync, &secp_ctx, &our_privkey, &privkeys[1], ChannelFeatures::from_le_bytes(id_to_feature_flags(2)), 2);
update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate {
excess_data: Vec::new()
});
update_channel(&gossip_sync, &secp_ctx, &privkeys[1], UnsignedChannelUpdate {
excess_data: Vec::new()
});
update_channel(&gossip_sync, &secp_ctx, &privkeys[1], UnsignedChannelUpdate {
add_channel(&gossip_sync, &secp_ctx, &our_privkey, &privkeys[7], ChannelFeatures::from_le_bytes(id_to_feature_flags(12)), 12);
update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate {
add_channel(&gossip_sync, &secp_ctx, &our_privkey, &privkeys[7], ChannelFeatures::from_le_bytes(id_to_feature_flags(12)), 12);
update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate {
excess_data: Vec::new()
});
update_channel(&gossip_sync, &secp_ctx, &privkeys[7], UnsignedChannelUpdate {
excess_data: Vec::new()
});
update_channel(&gossip_sync, &secp_ctx, &privkeys[7], UnsignedChannelUpdate {
add_channel(&gossip_sync, &secp_ctx, &privkeys[0], &privkeys[2], ChannelFeatures::from_le_bytes(id_to_feature_flags(3)), 3);
update_channel(&gossip_sync, &secp_ctx, &privkeys[0], UnsignedChannelUpdate {
add_channel(&gossip_sync, &secp_ctx, &privkeys[0], &privkeys[2], ChannelFeatures::from_le_bytes(id_to_feature_flags(3)), 3);
update_channel(&gossip_sync, &secp_ctx, &privkeys[0], UnsignedChannelUpdate {
excess_data: Vec::new()
});
update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate {
excess_data: Vec::new()
});
update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate {
add_channel(&gossip_sync, &secp_ctx, &privkeys[1], &privkeys[2], ChannelFeatures::from_le_bytes(id_to_feature_flags(4)), 4);
update_channel(&gossip_sync, &secp_ctx, &privkeys[1], UnsignedChannelUpdate {
add_channel(&gossip_sync, &secp_ctx, &privkeys[1], &privkeys[2], ChannelFeatures::from_le_bytes(id_to_feature_flags(4)), 4);
update_channel(&gossip_sync, &secp_ctx, &privkeys[1], UnsignedChannelUpdate {
excess_data: Vec::new()
});
update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate {
excess_data: Vec::new()
});
update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate {
add_channel(&gossip_sync, &secp_ctx, &privkeys[7], &privkeys[2], ChannelFeatures::from_le_bytes(id_to_feature_flags(13)), 13);
update_channel(&gossip_sync, &secp_ctx, &privkeys[7], UnsignedChannelUpdate {
add_channel(&gossip_sync, &secp_ctx, &privkeys[7], &privkeys[2], ChannelFeatures::from_le_bytes(id_to_feature_flags(13)), 13);
update_channel(&gossip_sync, &secp_ctx, &privkeys[7], UnsignedChannelUpdate {
excess_data: Vec::new()
});
update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate {
excess_data: Vec::new()
});
update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate {
add_channel(&gossip_sync, &secp_ctx, &privkeys[2], &privkeys[4], ChannelFeatures::from_le_bytes(id_to_feature_flags(6)), 6);
update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate {
add_channel(&gossip_sync, &secp_ctx, &privkeys[2], &privkeys[4], ChannelFeatures::from_le_bytes(id_to_feature_flags(6)), 6);
update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate {
excess_data: Vec::new()
});
update_channel(&gossip_sync, &secp_ctx, &privkeys[4], UnsignedChannelUpdate {
excess_data: Vec::new()
});
update_channel(&gossip_sync, &secp_ctx, &privkeys[4], UnsignedChannelUpdate {
add_channel(&gossip_sync, &secp_ctx, &privkeys[4], &privkeys[3], ChannelFeatures::from_le_bytes(id_to_feature_flags(11)), 11);
update_channel(&gossip_sync, &secp_ctx, &privkeys[4], UnsignedChannelUpdate {
add_channel(&gossip_sync, &secp_ctx, &privkeys[4], &privkeys[3], ChannelFeatures::from_le_bytes(id_to_feature_flags(11)), 11);
update_channel(&gossip_sync, &secp_ctx, &privkeys[4], UnsignedChannelUpdate {
excess_data: Vec::new()
});
update_channel(&gossip_sync, &secp_ctx, &privkeys[3], UnsignedChannelUpdate {
excess_data: Vec::new()
});
update_channel(&gossip_sync, &secp_ctx, &privkeys[3], UnsignedChannelUpdate {
add_channel(&gossip_sync, &secp_ctx, &privkeys[2], &privkeys[5], ChannelFeatures::from_le_bytes(id_to_feature_flags(7)), 7);
update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate {
add_channel(&gossip_sync, &secp_ctx, &privkeys[2], &privkeys[5], ChannelFeatures::from_le_bytes(id_to_feature_flags(7)), 7);
update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate {
excess_data: Vec::new()
});
update_channel(&gossip_sync, &secp_ctx, &privkeys[5], UnsignedChannelUpdate {
excess_data: Vec::new()
});
update_channel(&gossip_sync, &secp_ctx, &privkeys[5], UnsignedChannelUpdate {