Skip to content

Commit 836c7b0

Browse files
committed
Merge branch 'master' into message_handling_extraction
# Conflicts: # lightning/src/ln/peer_handler.rs
2 parents bf11673 + 2087032 commit 836c7b0

16 files changed

+919
-557
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ impl TestChannelMonitor {
9696
}
9797
}
9898
}
99-
impl channelmonitor::ManyChannelMonitor<EnforcingChannelKeys> for TestChannelMonitor {
99+
impl channelmonitor::ManyChannelMonitor for TestChannelMonitor {
100+
type Keys = EnforcingChannelKeys;
101+
100102
fn add_monitor(&self, funding_txo: OutPoint, monitor: channelmonitor::ChannelMonitor<EnforcingChannelKeys>) -> Result<(), channelmonitor::ChannelMonitorUpdateErr> {
101103
let mut ser = VecWriter(Vec::new());
102104
monitor.write_for_disk(&mut ser).unwrap();
@@ -164,6 +166,7 @@ impl KeysInterface for KeyProvider {
164166
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(),
165167
[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],
166168
channel_value_satoshis,
169+
(0, 0),
167170
))
168171
}
169172

@@ -195,7 +198,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
195198
config.channel_options.fee_proportional_millionths = 0;
196199
config.channel_options.announced_channel = true;
197200
config.peer_channel_config_limits.min_dust_limit_satoshis = 0;
198-
(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)),
199202
monitor)
200203
} }
201204
}
@@ -267,7 +270,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
267270
let tx = Transaction { version: $chan_id, lock_time: 0, input: Vec::new(), output: vec![TxOut {
268271
value: *channel_value_satoshis, script_pubkey: output_script.clone(),
269272
}]};
270-
funding_output = OutPoint::new(tx.txid(), 0);
273+
funding_output = OutPoint { txid: tx.txid(), index: 0 };
271274
$source.funding_transaction_generated(&temporary_channel_id, funding_output);
272275
channel_txn.push(tx);
273276
} else { panic!("Wrong event type"); }

fuzz/src/full_stack.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,17 @@ impl<'a> std::hash::Hash for Peer<'a> {
134134
}
135135
}
136136

137+
type ChannelMan = ChannelManager<
138+
EnforcingChannelKeys,
139+
Arc<channelmonitor::SimpleManyChannelMonitor<OutPoint, EnforcingChannelKeys, Arc<TestBroadcaster>, Arc<FuzzEstimator>, Arc<dyn Logger>, Arc<ChainWatchInterfaceUtil>>>,
140+
Arc<TestBroadcaster>, Arc<KeyProvider>, Arc<FuzzEstimator>, Arc<dyn Logger>>;
141+
type PeerMan<'a> = PeerManager<Peer<'a>, Arc<ChannelMan>, Arc<NetGraphMsgHandler<Arc<ChainWatchInterfaceUtil>, Arc<dyn Logger>>>, Arc<dyn Logger>>;
142+
137143
struct MoneyLossDetector<'a> {
138-
manager: Arc<ChannelManager<EnforcingChannelKeys, Arc<channelmonitor::SimpleManyChannelMonitor<OutPoint, EnforcingChannelKeys, Arc<TestBroadcaster>, Arc<FuzzEstimator>, Arc<dyn Logger>, Arc<ChainWatchInterfaceUtil>>>, Arc<TestBroadcaster>, Arc<KeyProvider>, Arc<FuzzEstimator>, Arc<dyn Logger>>>,
139-
monitor: Arc<channelmonitor::SimpleManyChannelMonitor<OutPoint, EnforcingChannelKeys, Arc<TestBroadcaster>, Arc<FuzzEstimator>, Arc<dyn Logger>, Arc<ChainWatchInterfaceUtil>>>,
140-
handler: PeerManager<Peer<'a>, Arc<ChannelManager<EnforcingChannelKeys, Arc<channelmonitor::SimpleManyChannelMonitor<OutPoint, EnforcingChannelKeys, Arc<TestBroadcaster>, Arc<FuzzEstimator>, Arc<dyn Logger>, Arc<ChainWatchInterfaceUtil>>>, Arc<TestBroadcaster>, Arc<KeyProvider>, Arc<FuzzEstimator>, Arc<dyn Logger>>>, Arc<dyn Logger>>,
144+
manager: Arc<ChannelMan>,
145+
monitor: Arc<channelmonitor::SimpleManyChannelMonitor<
146+
OutPoint, EnforcingChannelKeys, Arc<TestBroadcaster>, Arc<FuzzEstimator>, Arc<dyn Logger>, Arc<ChainWatchInterfaceUtil>>>,
147+
handler: PeerMan<'a>,
141148

142149
peers: &'a RefCell<[bool; 256]>,
143150
funding_txn: Vec<Transaction>,
@@ -149,9 +156,9 @@ struct MoneyLossDetector<'a> {
149156
}
150157
impl<'a> MoneyLossDetector<'a> {
151158
pub fn new(peers: &'a RefCell<[bool; 256]>,
152-
manager: Arc<ChannelManager<EnforcingChannelKeys, Arc<channelmonitor::SimpleManyChannelMonitor<OutPoint, EnforcingChannelKeys, Arc<TestBroadcaster>, Arc<FuzzEstimator>, Arc<dyn Logger>, Arc<ChainWatchInterfaceUtil>>>, Arc<TestBroadcaster>, Arc<KeyProvider>, Arc<FuzzEstimator>, Arc<dyn Logger>>>,
159+
manager: Arc<ChannelMan>,
153160
monitor: Arc<channelmonitor::SimpleManyChannelMonitor<OutPoint, EnforcingChannelKeys, Arc<TestBroadcaster>, Arc<FuzzEstimator>, Arc<dyn Logger>, Arc<ChainWatchInterfaceUtil>>>,
154-
handler: PeerManager<Peer<'a>, Arc<ChannelManager<EnforcingChannelKeys, Arc<channelmonitor::SimpleManyChannelMonitor<OutPoint, EnforcingChannelKeys, Arc<TestBroadcaster>, Arc<FuzzEstimator>, Arc<dyn Logger>, Arc<ChainWatchInterfaceUtil>>>, Arc<TestBroadcaster>, Arc<KeyProvider>, Arc<FuzzEstimator>, Arc<dyn Logger>>>, Arc<dyn Logger>>) -> Self {
161+
handler: PeerMan<'a>) -> Self {
155162
MoneyLossDetector {
156163
manager,
157164
monitor,
@@ -262,6 +269,7 @@ impl KeysInterface for KeyProvider {
262269
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, 5, ctr]).unwrap(),
263270
[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, 6, ctr],
264271
channel_value_satoshis,
272+
(0, 0),
265273
)
266274
} else {
267275
InMemoryChannelKeys::new(
@@ -273,6 +281,7 @@ impl KeysInterface for KeyProvider {
273281
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, 11, ctr]).unwrap(),
274282
[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, 12, ctr],
275283
channel_value_satoshis,
284+
(0, 0),
276285
)
277286
})
278287
}
@@ -332,7 +341,7 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
332341
config.channel_options.fee_proportional_millionths = slice_to_be32(get_slice!(4));
333342
config.channel_options.announced_channel = get_slice!(1)[0] != 0;
334343
config.peer_channel_config_limits.min_dust_limit_satoshis = 0;
335-
let channelmanager = Arc::new(ChannelManager::new(Network::Bitcoin, fee_est.clone(), monitor.clone(), broadcast.clone(), Arc::clone(&logger), keys_manager.clone(), config, 0).unwrap());
344+
let channelmanager = Arc::new(ChannelManager::new(Network::Bitcoin, fee_est.clone(), monitor.clone(), broadcast.clone(), Arc::clone(&logger), keys_manager.clone(), config, 0));
336345
let our_id = PublicKey::from_secret_key(&Secp256k1::signing_only(), &keys_manager.get_node_secret());
337346
let net_graph_msg_handler = Arc::new(NetGraphMsgHandler::new(watch.clone(), Arc::clone(&logger)));
338347

@@ -476,7 +485,7 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
476485
let funding_output = 'search_loop: loop {
477486
let funding_txid = tx.txid();
478487
if let None = loss_detector.txids_confirmed.get(&funding_txid) {
479-
let outpoint = OutPoint::new(funding_txid, 0);
488+
let outpoint = OutPoint { txid: funding_txid, index: 0 };
480489
for chan in channelmanager.list_channels() {
481490
if chan.channel_id == outpoint.to_channel_id() {
482491
tx.version += 1;

lightning-net-tokio/src/lib.rs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
//! type ChainWatchInterface = dyn lightning::chain::chaininterface::ChainWatchInterface;
2929
//! type ChannelMonitor = lightning::ln::channelmonitor::SimpleManyChannelMonitor<lightning::chain::transaction::OutPoint, lightning::chain::keysinterface::InMemoryChannelKeys, Arc<TxBroadcaster>, Arc<FeeEstimator>, Arc<Logger>, Arc<ChainWatchInterface>>;
3030
//! type ChannelManager = lightning::ln::channelmanager::SimpleArcChannelManager<ChannelMonitor, TxBroadcaster, FeeEstimator, Logger>;
31-
//! type PeerManager = lightning::ln::peer_handler::SimpleArcPeerManager<lightning_net_tokio::SocketDescriptor, ChannelMonitor, TxBroadcaster, FeeEstimator, Logger>;
31+
//! type PeerManager = lightning::ln::peer_handler::SimpleArcPeerManager<lightning_net_tokio::SocketDescriptor, ChannelMonitor, TxBroadcaster, FeeEstimator, ChainWatchInterface, Logger>;
3232
//!
3333
//! // Connect to node with pubkey their_node_id at addr:
3434
//! async fn connect_to_node(peer_manager: PeerManager, channel_monitor: Arc<ChannelMonitor>, channel_manager: ChannelManager, their_node_id: PublicKey, addr: SocketAddr) {
@@ -70,7 +70,7 @@ use tokio::io::{AsyncReadExt, AsyncWrite, AsyncWriteExt};
7070

7171
use lightning::ln::peer_handler;
7272
use lightning::ln::peer_handler::SocketDescriptor as LnSocketTrait;
73-
use lightning::ln::msgs::ChannelMessageHandler;
73+
use lightning::ln::msgs::{ChannelMessageHandler, RoutingMessageHandler};
7474
use lightning::util::logger::Logger;
7575

7676
use std::{task, thread};
@@ -124,7 +124,10 @@ impl Connection {
124124
_ => panic!()
125125
}
126126
}
127-
async fn schedule_read<CMH: ChannelMessageHandler + 'static, L: Logger + 'static + ?Sized>(peer_manager: Arc<peer_handler::PeerManager<SocketDescriptor, Arc<CMH>, Arc<L>>>, us: Arc<Mutex<Self>>, mut reader: io::ReadHalf<TcpStream>, mut read_wake_receiver: mpsc::Receiver<()>, mut write_avail_receiver: mpsc::Receiver<()>) {
127+
async fn schedule_read<CMH, RMH, L>(peer_manager: Arc<peer_handler::PeerManager<SocketDescriptor, Arc<CMH>, Arc<RMH>, Arc<L>>>, us: Arc<Mutex<Self>>, mut reader: io::ReadHalf<TcpStream>, mut read_wake_receiver: mpsc::Receiver<()>, mut write_avail_receiver: mpsc::Receiver<()>) where
128+
CMH: ChannelMessageHandler + 'static,
129+
RMH: RoutingMessageHandler + 'static,
130+
L: Logger + 'static + ?Sized {
128131
let peer_manager_ref = peer_manager.clone();
129132
// 8KB is nice and big but also should never cause any issues with stack overflowing.
130133
let mut buf = [0; 8192];
@@ -234,7 +237,10 @@ impl Connection {
234237
/// not need to poll the provided future in order to make progress.
235238
///
236239
/// See the module-level documentation for how to handle the event_notify mpsc::Sender.
237-
pub fn setup_inbound<CMH: ChannelMessageHandler + 'static, L: Logger + 'static + ?Sized>(peer_manager: Arc<peer_handler::PeerManager<SocketDescriptor, Arc<CMH>, Arc<L>>>, event_notify: mpsc::Sender<()>, stream: TcpStream) -> impl std::future::Future<Output=()> {
240+
pub fn setup_inbound<CMH, RMH, L>(peer_manager: Arc<peer_handler::PeerManager<SocketDescriptor, Arc<CMH>, Arc<RMH>, Arc<L>>>, event_notify: mpsc::Sender<()>, stream: TcpStream) -> impl std::future::Future<Output=()> where
241+
CMH: ChannelMessageHandler + 'static,
242+
RMH: RoutingMessageHandler + 'static,
243+
L: Logger + 'static + ?Sized {
238244
let (reader, write_receiver, read_receiver, us) = Connection::new(event_notify, stream);
239245
#[cfg(debug_assertions)]
240246
let last_us = Arc::clone(&us);
@@ -273,7 +279,10 @@ pub fn setup_inbound<CMH: ChannelMessageHandler + 'static, L: Logger + 'static +
273279
/// not need to poll the provided future in order to make progress.
274280
///
275281
/// See the module-level documentation for how to handle the event_notify mpsc::Sender.
276-
pub fn setup_outbound<CMH: ChannelMessageHandler + 'static, L: Logger + 'static + ?Sized>(peer_manager: Arc<peer_handler::PeerManager<SocketDescriptor, Arc<CMH>, Arc<L>>>, event_notify: mpsc::Sender<()>, their_node_id: PublicKey, stream: TcpStream) -> impl std::future::Future<Output=()> {
282+
pub fn setup_outbound<CMH, RMH, L>(peer_manager: Arc<peer_handler::PeerManager<SocketDescriptor, Arc<CMH>, Arc<RMH>, Arc<L>>>, event_notify: mpsc::Sender<()>, their_node_id: PublicKey, stream: TcpStream) -> impl std::future::Future<Output=()> where
283+
CMH: ChannelMessageHandler + 'static,
284+
RMH: RoutingMessageHandler + 'static,
285+
L: Logger + 'static + ?Sized {
277286
let (reader, mut write_receiver, read_receiver, us) = Connection::new(event_notify, stream);
278287
#[cfg(debug_assertions)]
279288
let last_us = Arc::clone(&us);
@@ -342,7 +351,10 @@ pub fn setup_outbound<CMH: ChannelMessageHandler + 'static, L: Logger + 'static
342351
/// make progress.
343352
///
344353
/// See the module-level documentation for how to handle the event_notify mpsc::Sender.
345-
pub async fn connect_outbound<CMH: ChannelMessageHandler + 'static, L: Logger + 'static + ?Sized>(peer_manager: Arc<peer_handler::PeerManager<SocketDescriptor, Arc<CMH>, Arc<L>>>, event_notify: mpsc::Sender<()>, their_node_id: PublicKey, addr: SocketAddr) -> Option<impl std::future::Future<Output=()>> {
354+
pub async fn connect_outbound<CMH, RMH, L>(peer_manager: Arc<peer_handler::PeerManager<SocketDescriptor, Arc<CMH>, Arc<RMH>, Arc<L>>>, event_notify: mpsc::Sender<()>, their_node_id: PublicKey, addr: SocketAddr) -> Option<impl std::future::Future<Output=()>> where
355+
CMH: ChannelMessageHandler + 'static,
356+
RMH: RoutingMessageHandler + 'static,
357+
L: Logger + 'static + ?Sized {
346358
if let Ok(Ok(stream)) = time::timeout(Duration::from_secs(10), TcpStream::connect(&addr)).await {
347359
Some(setup_outbound(peer_manager, event_notify, their_node_id, stream))
348360
} else { None }
@@ -568,7 +580,7 @@ mod tests {
568580
});
569581
let a_manager = Arc::new(PeerManager::new(MessageHandler {
570582
chan_handler: Arc::clone(&a_handler),
571-
route_handler: Arc::clone(&a_handler) as Arc<dyn RoutingMessageHandler>,
583+
route_handler: Arc::clone(&a_handler),
572584
}, a_key.clone(), &[1; 32], Arc::new(TestLogger())));
573585

574586
let (b_connected_sender, mut b_connected) = mpsc::channel(1);
@@ -581,7 +593,7 @@ mod tests {
581593
});
582594
let b_manager = Arc::new(PeerManager::new(MessageHandler {
583595
chan_handler: Arc::clone(&b_handler),
584-
route_handler: Arc::clone(&b_handler) as Arc<dyn RoutingMessageHandler>,
596+
route_handler: Arc::clone(&b_handler),
585597
}, b_key.clone(), &[2; 32], Arc::new(TestLogger())));
586598

587599
// We bind on localhost, hoping the environment is properly configured with a local

0 commit comments

Comments
 (0)