Skip to content

592+a few fixes #621

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

Merged
merged 14 commits into from
May 12, 2020
Merged
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
16 changes: 8 additions & 8 deletions ARCH.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ receive `ChannelMonitorUpdate`s from `ChannelManager` and persist them to disk b
channel steps forward.

There are two additional important structures that you may use either on the same device
as the `ChannelManager` or on a separate one. `Router` handles receiving channel and node
announcements and calculates routes for sending payments. `PeerManager` handles the
authenticated and encrypted communication protocol, monitoring for liveness of peers,
routing messages to `ChannelManager` and `Router` instances directly, and receiving
messages from them via the `EventsProvider` interface.
as the `ChannelManager` or on a separate one. `NetGraphMsgHandler` handles receiving channel
and node announcements, which are then used to calculate routes by `get_route` for sending payments.
`PeerManager` handles the authenticated and encrypted communication protocol,
monitoring for liveness of peers, routing messages to `ChannelManager` and `NetGraphMsgHandler`
instances directly, and receiving messages from them via the `EventsProvider` interface.

These structs communicate with each other using a public API, so that you can easily add
a proxy in between for special handling. Further, APIs for key generation, transaction
Expand Down Expand Up @@ -56,7 +56,7 @@ At a high level, some of the common interfaces fit together as follows:
| ----------------------- ---------
| | | Event |
(as RoutingMessageHandler) v ---------
\ ----------
-----------------> | Router |
----------
\ --------------------
-----------------> | NetGraphMsgHandler |
--------------------
```
3 changes: 2 additions & 1 deletion fuzz/src/chanmon_consistency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use lightning::chain::keysinterface::{KeysInterface, InMemoryChannelKeys};
use lightning::ln::channelmonitor;
use lightning::ln::channelmonitor::{ChannelMonitor, ChannelMonitorUpdateErr, HTLCUpdate};
use lightning::ln::channelmanager::{ChannelManager, PaymentHash, PaymentPreimage, PaymentSecret, ChannelManagerReadArgs};
use lightning::ln::router::{Route, RouteHop};
use lightning::ln::features::{ChannelFeatures, InitFeatures, NodeFeatures};
use lightning::ln::msgs::{CommitmentUpdate, ChannelMessageHandler, ErrorAction, UpdateAddHTLC, Init};
use lightning::util::enforcing_trait_impls::EnforcingChannelKeys;
Expand All @@ -36,6 +35,8 @@ use lightning::util::logger::Logger;
use lightning::util::config::UserConfig;
use lightning::util::events::{EventsProvider, MessageSendEventsProvider};
use lightning::util::ser::{Readable, ReadableArgs, Writeable, Writer};
use lightning::routing::router::{Route, RouteHop};


use utils::test_logger;

Expand Down
12 changes: 7 additions & 5 deletions fuzz/src/full_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ use lightning::chain::keysinterface::{InMemoryChannelKeys, KeysInterface};
use lightning::ln::channelmonitor;
use lightning::ln::channelmanager::{ChannelManager, PaymentHash, PaymentPreimage, PaymentSecret};
use lightning::ln::peer_handler::{MessageHandler,PeerManager,SocketDescriptor};
use lightning::ln::router::Router;
use lightning::routing::router::get_route;
use lightning::routing::network_graph::NetGraphMsgHandler;
use lightning::util::events::{EventsProvider,Event};
use lightning::util::enforcing_trait_impls::EnforcingChannelKeys;
use lightning::util::logger::Logger;
Expand Down Expand Up @@ -332,12 +333,13 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
config.channel_options.announced_channel = get_slice!(1)[0] != 0;
config.peer_channel_config_limits.min_dust_limit_satoshis = 0;
let channelmanager = Arc::new(ChannelManager::new(Network::Bitcoin, fee_est.clone(), monitor.clone(), broadcast.clone(), Arc::clone(&logger), keys_manager.clone(), config, 0).unwrap());
let router = Arc::new(Router::new(PublicKey::from_secret_key(&Secp256k1::signing_only(), &keys_manager.get_node_secret()), watch.clone(), Arc::clone(&logger)));
let our_id = PublicKey::from_secret_key(&Secp256k1::signing_only(), &keys_manager.get_node_secret());
let net_graph_msg_handler = Arc::new(NetGraphMsgHandler::new(watch.clone(), Arc::clone(&logger)));

let peers = RefCell::new([false; 256]);
let mut loss_detector = MoneyLossDetector::new(&peers, channelmanager.clone(), monitor.clone(), PeerManager::new(MessageHandler {
chan_handler: channelmanager.clone(),
route_handler: router.clone(),
route_handler: net_graph_msg_handler.clone(),
}, our_network_key, &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0], Arc::clone(&logger)));

let mut should_forward = false;
Expand Down Expand Up @@ -389,7 +391,7 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
},
4 => {
let value = slice_to_be24(get_slice!(3)) as u64;
let route = match router.get_route(&get_pubkey!(), None, &Vec::new(), value, 42) {
let route = match get_route(&our_id, &net_graph_msg_handler, &get_pubkey!(), None, &Vec::new(), value, 42, Arc::clone(&logger)) {
Ok(route) => route,
Err(_) => return,
};
Expand All @@ -406,7 +408,7 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
},
15 => {
let value = slice_to_be24(get_slice!(3)) as u64;
let mut route = match router.get_route(&get_pubkey!(), None, &Vec::new(), value, 42) {
let mut route = match get_route(&our_id, &net_graph_msg_handler, &get_pubkey!(), None, &Vec::new(), value, 42, Arc::clone(&logger)) {
Ok(route) => route,
Err(_) => return,
};
Expand Down
23 changes: 13 additions & 10 deletions fuzz/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ use lightning::ln::channelmanager::ChannelDetails;
use lightning::ln::features::InitFeatures;
use lightning::ln::msgs;
use lightning::ln::msgs::RoutingMessageHandler;
use lightning::ln::router::{Router, RouteHint};
use lightning::routing::router::{get_route, RouteHint};
use lightning::util::logger::Logger;
use lightning::util::ser::Readable;
use lightning::routing::network_graph::{NetGraphMsgHandler, RoutingFees};

use bitcoin::secp256k1::key::PublicKey;

Expand Down Expand Up @@ -156,7 +157,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
});

let our_pubkey = get_pubkey!();
let router = Router::new(our_pubkey.clone(), chain_monitor, Arc::clone(&logger));
let net_graph_msg_handler = NetGraphMsgHandler::new(chain_monitor, Arc::clone(&logger));

loop {
match get_slice!(1)[0] {
Expand All @@ -166,22 +167,22 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
if addr_len > (37+1)*4 {
return;
}
let _ = router.handle_node_announcement(&decode_msg_with_len16!(msgs::NodeAnnouncement, 64, 288));
let _ = net_graph_msg_handler.handle_node_announcement(&decode_msg_with_len16!(msgs::NodeAnnouncement, 64, 288));
},
1 => {
let _ = router.handle_channel_announcement(&decode_msg_with_len16!(msgs::ChannelAnnouncement, 64*4, 32+8+33*4));
let _ = net_graph_msg_handler.handle_channel_announcement(&decode_msg_with_len16!(msgs::ChannelAnnouncement, 64*4, 32+8+33*4));
},
2 => {
let _ = router.handle_channel_update(&decode_msg!(msgs::ChannelUpdate, 128));
let _ = net_graph_msg_handler.handle_channel_update(&decode_msg!(msgs::ChannelUpdate, 128));
},
3 => {
match get_slice!(1)[0] {
0 => {
router.handle_htlc_fail_channel_update(&msgs::HTLCFailChannelUpdate::ChannelUpdateMessage {msg: decode_msg!(msgs::ChannelUpdate, 128)});
net_graph_msg_handler.handle_htlc_fail_channel_update(&msgs::HTLCFailChannelUpdate::ChannelUpdateMessage {msg: decode_msg!(msgs::ChannelUpdate, 128)});
},
1 => {
let short_channel_id = slice_to_be64(get_slice!(8));
router.handle_htlc_fail_channel_update(&msgs::HTLCFailChannelUpdate::ChannelClosed {short_channel_id, is_permanent: false});
net_graph_msg_handler.handle_htlc_fail_channel_update(&msgs::HTLCFailChannelUpdate::ChannelClosed {short_channel_id, is_permanent: false});
},
_ => return,
}
Expand Down Expand Up @@ -217,15 +218,17 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
last_hops_vec.push(RouteHint {
src_node_id: get_pubkey!(),
short_channel_id: slice_to_be64(get_slice!(8)),
fee_base_msat: slice_to_be32(get_slice!(4)),
fee_proportional_millionths: slice_to_be32(get_slice!(4)),
fees: RoutingFees {
base_msat: slice_to_be32(get_slice!(4)),
proportional_millionths: slice_to_be32(get_slice!(4)),
},
cltv_expiry_delta: slice_to_be16(get_slice!(2)),
htlc_minimum_msat: slice_to_be64(get_slice!(8)),
});
}
&last_hops_vec[..]
};
let _ = router.get_route(&target, first_hops, last_hops, slice_to_be64(get_slice!(8)), slice_to_be32(get_slice!(4)));
let _ = get_route(&our_pubkey, &net_graph_msg_handler, &target, first_hops, last_hops, slice_to_be64(get_slice!(8)), slice_to_be32(get_slice!(4)), Arc::clone(&logger));
},
_ => return,
}
Expand Down
2 changes: 0 additions & 2 deletions lightning/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ Still missing tons of error-handling. See GitHub issues for suggested projects i
"""

[features]
# Supports tracking channels with a non-bitcoin chain hashes. Currently enables all kinds of fun DoS attacks.
non_bitcoin_chain_hash_routing = []
fuzztarget = ["bitcoin/fuzztarget"]
# Unlog messages superior at targeted level.
max_level_off = []
Expand Down
2 changes: 2 additions & 0 deletions lightning/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ extern crate bitcoin;
pub mod util;
pub mod chain;
pub mod ln;
pub mod routing;

Loading