Fix full_stack_target mishandling of block disconnection
[rust-lightning] / fuzz / src / full_stack.rs
index 4408c4392bc7e4d9bcbad7b90b03394008db7ad2..e6496125ac656ded582209d631ae74db71ba728a 100644 (file)
@@ -26,6 +26,7 @@ use lightning::ln::channelmanager::{ChannelManager, PaymentHash, PaymentPreimage
 use lightning::ln::peer_handler::{MessageHandler,PeerManager,SocketDescriptor};
 use lightning::ln::router::Router;
 use lightning::util::events::{EventsProvider,Event};
+use lightning::util::enforcing_trait_impls::EnforcingChannelKeys;
 use lightning::util::logger::Logger;
 use lightning::util::config::UserConfig;
 
@@ -134,8 +135,8 @@ impl<'a> Hash for Peer<'a> {
        }
 }
 
-struct MoneyLossDetector<'a, 'b> {
-       manager: Arc<ChannelManager<'b, InMemoryChannelKeys>>,
+struct MoneyLossDetector<'a> {
+       manager: Arc<ChannelManager<EnforcingChannelKeys>>,
        monitor: Arc<channelmonitor::SimpleManyChannelMonitor<OutPoint>>,
        handler: PeerManager<Peer<'a>>,
 
@@ -147,8 +148,8 @@ struct MoneyLossDetector<'a, 'b> {
        max_height: usize,
        blocks_connected: u32,
 }
-impl<'a, 'b> MoneyLossDetector<'a, 'b> {
-       pub fn new(peers: &'a RefCell<[bool; 256]>, manager: Arc<ChannelManager<'b, InMemoryChannelKeys>>, monitor: Arc<channelmonitor::SimpleManyChannelMonitor<OutPoint>>, handler: PeerManager<Peer<'a>>) -> Self {
+impl<'a> MoneyLossDetector<'a> {
+       pub fn new(peers: &'a RefCell<[bool; 256]>, manager: Arc<ChannelManager<EnforcingChannelKeys>>, monitor: Arc<channelmonitor::SimpleManyChannelMonitor<OutPoint>>, handler: PeerManager<Peer<'a>>) -> Self {
                MoneyLossDetector {
                        manager,
                        monitor,
@@ -195,10 +196,10 @@ impl<'a, 'b> MoneyLossDetector<'a, 'b> {
 
        fn disconnect_block(&mut self) {
                if self.height > 0 && (self.max_height < 6 || self.height >= self.max_height - 6) {
-                       self.height -= 1;
                        let header = BlockHeader { version: 0x20000000, prev_blockhash: self.header_hashes[self.height], merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
                        self.manager.block_disconnected(&header, self.height as u32);
                        self.monitor.block_disconnected(&header, self.height as u32);
+                       self.height -= 1;
                        let removal_height = self.height;
                        self.txids_confirmed.retain(|_, height| {
                                removal_height != *height
@@ -207,7 +208,7 @@ impl<'a, 'b> MoneyLossDetector<'a, 'b> {
        }
 }
 
-impl<'a, 'b> Drop for MoneyLossDetector<'a, 'b> {
+impl<'a> Drop for MoneyLossDetector<'a> {
        fn drop(&mut self) {
                if !::std::thread::panicking() {
                        // Disconnect all peers
@@ -228,7 +229,7 @@ struct KeyProvider {
        counter: AtomicU64,
 }
 impl KeysInterface for KeyProvider {
-       type ChanKeySigner = InMemoryChannelKeys;
+       type ChanKeySigner = EnforcingChannelKeys;
 
        fn get_node_secret(&self) -> SecretKey {
                self.node_secret.clone()
@@ -246,9 +247,9 @@ impl KeysInterface for KeyProvider {
                PublicKey::from_secret_key(&secp_ctx, &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, 0, 0]).unwrap())
        }
 
-       fn get_channel_keys(&self, inbound: bool) -> InMemoryChannelKeys {
+       fn get_channel_keys(&self, inbound: bool) -> EnforcingChannelKeys {
                let ctr = self.counter.fetch_add(1, Ordering::Relaxed) as u8;
-               if inbound {
+               EnforcingChannelKeys::new(if inbound {
                        InMemoryChannelKeys {
                                funding_key:               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, 1, ctr]).unwrap(),
                                revocation_base_key:       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, 2, ctr]).unwrap(),
@@ -256,6 +257,7 @@ impl KeysInterface for KeyProvider {
                                delayed_payment_base_key:  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, 4, ctr]).unwrap(),
                                htlc_base_key:             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(),
                                commitment_seed: [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],
+                               remote_funding_pubkey: None,
                        }
                } else {
                        InMemoryChannelKeys {
@@ -265,8 +267,9 @@ impl KeysInterface for KeyProvider {
                                delayed_payment_base_key:  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, 10, ctr]).unwrap(),
                                htlc_base_key:             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(),
                                commitment_seed: [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],
+                               remote_funding_pubkey: None,
                        }
-               }
+               })
        }
 
        fn get_onion_rand(&self) -> (SecretKey, [u8; 32]) {