Skip to content

Commit 2e4e659

Browse files
committed
Merge branch 'master' into modular_handshake
# Conflicts: # fuzz/src/full_stack.rs # lightning-net-tokio/src/lib.rs # lightning/src/ln/mod.rs # lightning/src/ln/peers/handler.rs
2 parents be5e2a5 + 9be497c commit 2e4e659

33 files changed

+5280
-4349
lines changed

ARCH.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ receive `ChannelMonitorUpdate`s from `ChannelManager` and persist them to disk b
1111
channel steps forward.
1212

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

2020
These structs communicate with each other using a public API, so that you can easily add
2121
a proxy in between for special handling. Further, APIs for key generation, transaction
@@ -56,7 +56,7 @@ At a high level, some of the common interfaces fit together as follows:
5656
| ----------------------- ---------
5757
| | | Event |
5858
(as RoutingMessageHandler) v ---------
59-
\ ----------
60-
-----------------> | Router |
61-
----------
59+
\ --------------------
60+
-----------------> | NetGraphMsgHandler |
61+
--------------------
6262
```

fuzz/src/chanmon_consistency.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@ use bitcoin::hash_types::{BlockHash, WPubkeyHash};
2222

2323
use lightning::chain::chaininterface;
2424
use lightning::chain::transaction::OutPoint;
25-
use lightning::chain::chaininterface::{BroadcasterInterface,ConfirmationTarget,ChainListener,FeeEstimator,ChainWatchInterfaceUtil};
25+
use lightning::chain::chaininterface::{BroadcasterInterface,ConfirmationTarget,ChainListener,FeeEstimator,ChainWatchInterfaceUtil,ChainWatchInterface};
2626
use lightning::chain::keysinterface::{KeysInterface, InMemoryChannelKeys};
2727
use lightning::ln::channelmonitor;
2828
use lightning::ln::channelmonitor::{ChannelMonitor, ChannelMonitorUpdateErr, HTLCUpdate};
2929
use lightning::ln::channelmanager::{ChannelManager, PaymentHash, PaymentPreimage, PaymentSecret, ChannelManagerReadArgs};
30-
use lightning::ln::router::{Route, RouteHop};
3130
use lightning::ln::features::{ChannelFeatures, InitFeatures, NodeFeatures};
3231
use lightning::ln::msgs::{CommitmentUpdate, ChannelMessageHandler, ErrorAction, UpdateAddHTLC, Init};
3332
use lightning::util::enforcing_trait_impls::EnforcingChannelKeys;
@@ -36,6 +35,8 @@ use lightning::util::logger::Logger;
3635
use lightning::util::config::UserConfig;
3736
use lightning::util::events::{EventsProvider, MessageSendEventsProvider};
3837
use lightning::util::ser::{Readable, ReadableArgs, Writeable, Writer};
38+
use lightning::routing::router::{Route, RouteHop};
39+
3940

4041
use utils::test_logger;
4142

@@ -74,7 +75,7 @@ impl Writer for VecWriter {
7475

7576
struct TestChannelMonitor {
7677
pub logger: Arc<dyn Logger>,
77-
pub simple_monitor: Arc<channelmonitor::SimpleManyChannelMonitor<OutPoint, EnforcingChannelKeys, Arc<TestBroadcaster>, Arc<FuzzEstimator>>>,
78+
pub simple_monitor: Arc<channelmonitor::SimpleManyChannelMonitor<OutPoint, EnforcingChannelKeys, Arc<TestBroadcaster>, Arc<FuzzEstimator>, Arc<dyn Logger>, Arc<dyn ChainWatchInterface>>>,
7879
pub update_ret: Mutex<Result<(), channelmonitor::ChannelMonitorUpdateErr>>,
7980
// If we reload a node with an old copy of ChannelMonitors, the ChannelManager deserialization
8081
// logic will automatically force-close our channels for us (as we don't have an up-to-date
@@ -95,7 +96,9 @@ impl TestChannelMonitor {
9596
}
9697
}
9798
}
98-
impl channelmonitor::ManyChannelMonitor<EnforcingChannelKeys> for TestChannelMonitor {
99+
impl channelmonitor::ManyChannelMonitor for TestChannelMonitor {
100+
type Keys = EnforcingChannelKeys;
101+
99102
fn add_monitor(&self, funding_txo: OutPoint, monitor: channelmonitor::ChannelMonitor<EnforcingChannelKeys>) -> Result<(), channelmonitor::ChannelMonitorUpdateErr> {
100103
let mut ser = VecWriter(Vec::new());
101104
monitor.write_for_disk(&mut ser).unwrap();
@@ -114,8 +117,8 @@ impl channelmonitor::ManyChannelMonitor<EnforcingChannelKeys> for TestChannelMon
114117
hash_map::Entry::Vacant(_) => panic!("Didn't have monitor on update call"),
115118
};
116119
let mut deserialized_monitor = <(BlockHash, channelmonitor::ChannelMonitor<EnforcingChannelKeys>)>::
117-
read(&mut Cursor::new(&map_entry.get().1), Arc::clone(&self.logger)).unwrap().1;
118-
deserialized_monitor.update_monitor(update.clone(), &&TestBroadcaster {}).unwrap();
120+
read(&mut Cursor::new(&map_entry.get().1)).unwrap().1;
121+
deserialized_monitor.update_monitor(update.clone(), &&TestBroadcaster {}, &self.logger).unwrap();
119122
let mut ser = VecWriter(Vec::new());
120123
deserialized_monitor.write_for_disk(&mut ser).unwrap();
121124
map_entry.insert((update.update_id, ser.0));
@@ -163,6 +166,7 @@ impl KeysInterface for KeyProvider {
163166
SecretKey::from_slice(&[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, 8, self.node_id]).unwrap(),
164167
[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, 9, self.node_id],
165168
channel_value_satoshis,
169+
(0, 0),
166170
))
167171
}
168172

@@ -186,23 +190,23 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
186190
macro_rules! make_node {
187191
($node_id: expr) => { {
188192
let logger: Arc<dyn Logger> = Arc::new(test_logger::TestLogger::new($node_id.to_string(), out.clone()));
189-
let watch = Arc::new(ChainWatchInterfaceUtil::new(Network::Bitcoin, Arc::clone(&logger)));
193+
let watch = Arc::new(ChainWatchInterfaceUtil::new(Network::Bitcoin));
190194
let monitor = Arc::new(TestChannelMonitor::new(watch.clone(), broadcast.clone(), logger.clone(), fee_est.clone()));
191195

192196
let keys_manager = Arc::new(KeyProvider { node_id: $node_id, session_id: atomic::AtomicU8::new(0), channel_id: atomic::AtomicU8::new(0) });
193197
let mut config = UserConfig::default();
194198
config.channel_options.fee_proportional_millionths = 0;
195199
config.channel_options.announced_channel = true;
196200
config.peer_channel_config_limits.min_dust_limit_satoshis = 0;
197-
(Arc::new(ChannelManager::new(Network::Bitcoin, fee_est.clone(), monitor.clone(), broadcast.clone(), Arc::clone(&logger), keys_manager.clone(), config, 0).unwrap()),
201+
(Arc::new(ChannelManager::new(Network::Bitcoin, fee_est.clone(), monitor.clone(), broadcast.clone(), Arc::clone(&logger), keys_manager.clone(), config, 0)),
198202
monitor)
199203
} }
200204
}
201205

202206
macro_rules! reload_node {
203207
($ser: expr, $node_id: expr, $old_monitors: expr) => { {
204208
let logger: Arc<dyn Logger> = Arc::new(test_logger::TestLogger::new($node_id.to_string(), out.clone()));
205-
let watch = Arc::new(ChainWatchInterfaceUtil::new(Network::Bitcoin, Arc::clone(&logger)));
209+
let watch = Arc::new(ChainWatchInterfaceUtil::new(Network::Bitcoin));
206210
let monitor = Arc::new(TestChannelMonitor::new(watch.clone(), broadcast.clone(), logger.clone(), fee_est.clone()));
207211

208212
let keys_manager = Arc::new(KeyProvider { node_id: $node_id, session_id: atomic::AtomicU8::new(0), channel_id: atomic::AtomicU8::new(0) });
@@ -214,7 +218,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
214218
let mut monitors = HashMap::new();
215219
let mut old_monitors = $old_monitors.latest_monitors.lock().unwrap();
216220
for (outpoint, (update_id, monitor_ser)) in old_monitors.drain() {
217-
monitors.insert(outpoint, <(BlockHash, ChannelMonitor<EnforcingChannelKeys>)>::read(&mut Cursor::new(&monitor_ser), Arc::clone(&logger)).expect("Failed to read monitor").1);
221+
monitors.insert(outpoint, <(BlockHash, ChannelMonitor<EnforcingChannelKeys>)>::read(&mut Cursor::new(&monitor_ser)).expect("Failed to read monitor").1);
218222
monitor.latest_monitors.lock().unwrap().insert(outpoint, (update_id, monitor_ser));
219223
}
220224
let mut monitor_refs = HashMap::new();
@@ -232,7 +236,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
232236
channel_monitors: &mut monitor_refs,
233237
};
234238

235-
(<(BlockHash, ChannelManager<EnforcingChannelKeys, Arc<TestChannelMonitor>, Arc<TestBroadcaster>, Arc<KeyProvider>, Arc<FuzzEstimator>>)>::read(&mut Cursor::new(&$ser.0), read_args).expect("Failed to read manager").1, monitor)
239+
(<(BlockHash, ChannelManager<EnforcingChannelKeys, Arc<TestChannelMonitor>, Arc<TestBroadcaster>, Arc<KeyProvider>, Arc<FuzzEstimator>, Arc<dyn Logger>>)>::read(&mut Cursor::new(&$ser.0), read_args).expect("Failed to read manager").1, monitor)
236240
} }
237241
}
238242

@@ -266,7 +270,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
266270
let tx = Transaction { version: $chan_id, lock_time: 0, input: Vec::new(), output: vec![TxOut {
267271
value: *channel_value_satoshis, script_pubkey: output_script.clone(),
268272
}]};
269-
funding_output = OutPoint::new(tx.txid(), 0);
273+
funding_output = OutPoint { txid: tx.txid(), index: 0 };
270274
$source.funding_transaction_generated(&temporary_channel_id, funding_output);
271275
channel_txn.push(tx);
272276
} else { panic!("Wrong event type"); }

fuzz/src/chanmon_deser.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ use bitcoin::hash_types::BlockHash;
55

66
use lightning::util::enforcing_trait_impls::EnforcingChannelKeys;
77
use lightning::ln::channelmonitor;
8-
use lightning::util::ser::{ReadableArgs, Writer};
8+
use lightning::util::ser::{Readable, Writer};
99

1010
use utils::test_logger;
1111

1212
use std::io::Cursor;
13-
use std::sync::Arc;
1413

1514
struct VecWriter(Vec<u8>);
1615
impl Writer for VecWriter {
@@ -24,12 +23,11 @@ impl Writer for VecWriter {
2423
}
2524

2625
#[inline]
27-
pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
28-
let logger = Arc::new(test_logger::TestLogger::new("".to_owned(), out));
29-
if let Ok((latest_block_hash, monitor)) = <(BlockHash, channelmonitor::ChannelMonitor<EnforcingChannelKeys>)>::read(&mut Cursor::new(data), logger.clone()) {
26+
pub fn do_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
27+
if let Ok((latest_block_hash, monitor)) = <(BlockHash, channelmonitor::ChannelMonitor<EnforcingChannelKeys>)>::read(&mut Cursor::new(data)) {
3028
let mut w = VecWriter(Vec::new());
3129
monitor.write_for_disk(&mut w).unwrap();
32-
let deserialized_copy = <(BlockHash, channelmonitor::ChannelMonitor<EnforcingChannelKeys>)>::read(&mut Cursor::new(&w.0), logger.clone()).unwrap();
30+
let deserialized_copy = <(BlockHash, channelmonitor::ChannelMonitor<EnforcingChannelKeys>)>::read(&mut Cursor::new(&w.0)).unwrap();
3331
assert!(latest_block_hash == deserialized_copy.0);
3432
assert!(monitor == deserialized_copy.1);
3533
}

0 commit comments

Comments
 (0)