Merge pull request #791 from jkczyz/2021-01-spv-client
authorMatt Corallo <649246+TheBlueMatt@users.noreply.github.com>
Fri, 26 Feb 2021 15:54:01 +0000 (07:54 -0800)
committerGitHub <noreply@github.com>
Fri, 26 Feb 2021 15:54:01 +0000 (07:54 -0800)
SPV client utility for syncing a lightning node

1  2 
lightning/src/ln/channelmanager.rs

index bdf9b1e968ee4559c63ee15291e5014f9eab749f,8f7fbde5f9cb131312ea2ae0d8be6df4b634474a..8fd243ae7720276c6025d6a0ece52509edc9e8c0
@@@ -18,7 -18,7 +18,7 @@@
  //! imply it needs to fail HTLCs/payments/channels it manages).
  //!
  
- use bitcoin::blockdata::block::BlockHeader;
+ use bitcoin::blockdata::block::{Block, BlockHeader};
  use bitcoin::blockdata::constants::genesis_block;
  use bitcoin::network::constants::Network;
  
@@@ -2507,7 -2507,7 +2507,7 @@@ impl<Signer: Sign, M: Deref, T: Deref, 
                }
        }
  
 -      fn internal_shutdown(&self, counterparty_node_id: &PublicKey, msg: &msgs::Shutdown) -> Result<(), MsgHandleErrInternal> {
 +      fn internal_shutdown(&self, counterparty_node_id: &PublicKey, their_features: &InitFeatures, msg: &msgs::Shutdown) -> Result<(), MsgHandleErrInternal> {
                let (mut dropped_htlcs, chan_option) = {
                        let mut channel_state_lock = self.channel_state.lock().unwrap();
                        let channel_state = &mut *channel_state_lock;
                                        if chan_entry.get().get_counterparty_node_id() != *counterparty_node_id {
                                                return Err(MsgHandleErrInternal::send_err_msg_no_close("Got a message for a channel from the wrong node!".to_owned(), msg.channel_id));
                                        }
 -                                      let (shutdown, closing_signed, dropped_htlcs) = try_chan_entry!(self, chan_entry.get_mut().shutdown(&self.fee_estimator, &msg), channel_state, chan_entry);
 +                                      let (shutdown, closing_signed, dropped_htlcs) = try_chan_entry!(self, chan_entry.get_mut().shutdown(&self.fee_estimator, &their_features, &msg), channel_state, chan_entry);
                                        if let Some(msg) = shutdown {
                                                channel_state.pending_msg_events.push(events::MessageSendEvent::SendShutdown {
                                                        node_id: counterparty_node_id.clone(),
@@@ -3139,6 -3139,24 +3139,24 @@@ impl<Signer: Sign, M: Deref, T: Deref, 
        }
  }
  
+ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> chain::Listen for ChannelManager<Signer, M, T, K, F, L>
+ where
+       M::Target: chain::Watch<Signer>,
+       T::Target: BroadcasterInterface,
+       K::Target: KeysInterface<Signer = Signer>,
+       F::Target: FeeEstimator,
+       L::Target: Logger,
+ {
+       fn block_connected(&self, block: &Block, height: u32) {
+               let txdata: Vec<_> = block.txdata.iter().enumerate().collect();
+               ChannelManager::block_connected(self, &block.header, &txdata, height);
+       }
+       fn block_disconnected(&self, header: &BlockHeader, _height: u32) {
+               ChannelManager::block_disconnected(self, header);
+       }
+ }
  impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<Signer, M, T, K, F, L>
        where M::Target: chain::Watch<Signer>,
          T::Target: BroadcasterInterface,
@@@ -3351,9 -3369,9 +3369,9 @@@ impl<Signer: Sign, M: Deref + Sync + Se
                let _ = handle_error!(self, self.internal_funding_locked(counterparty_node_id, msg), *counterparty_node_id);
        }
  
 -      fn handle_shutdown(&self, counterparty_node_id: &PublicKey, msg: &msgs::Shutdown) {
 +      fn handle_shutdown(&self, counterparty_node_id: &PublicKey, their_features: &InitFeatures, msg: &msgs::Shutdown) {
                let _persistence_guard = PersistenceNotifierGuard::new(&self.total_consistency_lock, &self.persistence_notifier);
 -              let _ = handle_error!(self, self.internal_shutdown(counterparty_node_id, msg), *counterparty_node_id);
 +              let _ = handle_error!(self, self.internal_shutdown(counterparty_node_id, their_features, msg), *counterparty_node_id);
        }
  
        fn handle_closing_signed(&self, counterparty_node_id: &PublicKey, msg: &msgs::ClosingSigned) {