Merge pull request #1374 from TheBlueMatt/2022-03-bindings-cleanups
authorMatt Corallo <649246+TheBlueMatt@users.noreply.github.com>
Wed, 23 Mar 2022 00:46:31 +0000 (00:46 +0000)
committerGitHub <noreply@github.com>
Wed, 23 Mar 2022 00:46:31 +0000 (00:46 +0000)
Trivial Bindings Cleanups

1  2 
lightning/src/ln/channelmanager.rs
lightning/src/ln/peer_handler.rs

index 2b10fad53976d90667010cefbeb3f582e9514343,f18ad6f530e480ab55ee16f2835f2bc8cbeacc4a..04a455233d993cb2ff6d48bef446ba7c2876e15c
@@@ -441,7 -441,6 +441,7 @@@ struct ClaimableHTLC 
        cltv_expiry: u32,
        value: u64,
        onion_payload: OnionPayload,
 +      timer_ticks: u8,
  }
  
  /// A payment identifier used to uniquely identify a payment to LDK.
@@@ -887,6 -886,8 +887,8 @@@ impl PendingOutboundPayment 
  /// issues such as overly long function definitions. Note that the ChannelManager can take any
  /// type that implements KeysInterface for its keys manager, but this type alias chooses the
  /// concrete type of the KeysManager.
+ ///
+ /// (C-not exported) as Arcs don't make sense in bindings
  pub type SimpleArcChannelManager<M, T, F, L> = ChannelManager<InMemorySigner, Arc<M>, Arc<T>, Arc<KeysManager>, Arc<F>, Arc<L>>;
  
  /// SimpleRefChannelManager is a type alias for a ChannelManager reference, and is the reference
  /// helps with issues such as long function definitions. Note that the ChannelManager can take any
  /// type that implements KeysInterface for its keys manager, but this type alias chooses the
  /// concrete type of the KeysManager.
+ ///
+ /// (C-not exported) as Arcs don't make sense in bindings
  pub type SimpleRefChannelManager<'a, 'b, 'c, 'd, 'e, M, T, F, L> = ChannelManager<InMemorySigner, &'a M, &'b T, &'c KeysManager, &'d F, &'e L>;
  
  /// Manager which keeps track of a number of channels and sends messages to the appropriate
@@@ -1149,9 -1152,6 +1153,9 @@@ const CHECK_CLTV_EXPIRY_SANITY_2: u32 
  /// pending HTLCs in flight.
  pub(crate) const PAYMENT_EXPIRY_BLOCKS: u32 = 3;
  
 +/// The number of ticks of [`ChannelManager::timer_tick_occurred`] until expiry of incomplete MPPs
 +pub(crate) const MPP_TIMEOUT_TICKS: u8 = 3;
 +
  /// Information needed for constructing an invoice route hint for this channel.
  #[derive(Clone, Debug, PartialEq)]
  pub struct CounterpartyForwardingInfo {
@@@ -3330,7 -3330,6 +3334,7 @@@ impl<Signer: Sign, M: Deref, T: Deref, 
                                                                                phantom_shared_secret,
                                                                        },
                                                                        value: amt_to_forward,
 +                                                                      timer_ticks: 0,
                                                                        cltv_expiry,
                                                                        onion_payload,
                                                                };
                        let new_feerate = self.fee_estimator.get_est_sat_per_1000_weight(ConfirmationTarget::Normal);
  
                        let mut handle_errors = Vec::new();
 +                      let mut timed_out_mpp_htlcs = Vec::new();
                        {
                                let mut channel_state_lock = self.channel_state.lock().unwrap();
                                let channel_state = &mut *channel_state_lock;
  
                                        true
                                });
 +
 +                              channel_state.claimable_htlcs.retain(|payment_hash, htlcs| {
 +                                      if htlcs.is_empty() {
 +                                              // This should be unreachable
 +                                              debug_assert!(false);
 +                                              return false;
 +                                      }
 +                                      if let OnionPayload::Invoice(ref final_hop_data) = htlcs[0].onion_payload {
 +                                              // Check if we've received all the parts we need for an MPP (the value of the parts adds to total_msat).
 +                                              // In this case we're not going to handle any timeouts of the parts here.
 +                                              if final_hop_data.total_msat == htlcs.iter().fold(0, |total, htlc| total + htlc.value) {
 +                                                      return true;
 +                                              } else if htlcs.into_iter().any(|htlc| {
 +                                                      htlc.timer_ticks += 1;
 +                                                      return htlc.timer_ticks >= MPP_TIMEOUT_TICKS
 +                                              }) {
 +                                                      timed_out_mpp_htlcs.extend(htlcs.into_iter().map(|htlc| (htlc.prev_hop.clone(), payment_hash.clone())));
 +                                                      return false;
 +                                              }
 +                                      }
 +                                      true
 +                              });
 +                      }
 +
 +                      for htlc_source in timed_out_mpp_htlcs.drain(..) {
 +                              self.fail_htlc_backwards_internal(self.channel_state.lock().unwrap(), HTLCSource::PreviousHopData(htlc_source.0), &htlc_source.1, HTLCFailReason::Reason { failure_code: 23, data: Vec::new() });
                        }
  
                        for (err, counterparty_node_id) in handle_errors.drain(..) {
@@@ -5931,7 -5903,6 +5935,7 @@@ impl<Signer: Sign, M: Deref , T: Deref 
                                        &events::MessageSendEvent::SendChannelRangeQuery { .. } => false,
                                        &events::MessageSendEvent::SendShortIdsQuery { .. } => false,
                                        &events::MessageSendEvent::SendReplyChannelRange { .. } => false,
 +                                      &events::MessageSendEvent::SendGossipTimestampFilter { .. } => false,
                                }
                        });
                }
@@@ -6272,7 -6243,6 +6276,7 @@@ impl Readable for ClaimableHTLC 
                };
                Ok(Self {
                        prev_hop: prev_hop.0.unwrap(),
 +                      timer_ticks: 0,
                        value,
                        onion_payload,
                        cltv_expiry,
index 4c4e22c0c2b6b57020e789088e184721f9fd8e26,b59ddd11a6972ff2fc0dc49e6d93e7381198d67d..eef4054b34ad794048dd3970e96471fdb6f931c2
@@@ -69,7 -69,7 +69,7 @@@ impl RoutingMessageHandler for Ignoring
        fn get_next_channel_announcements(&self, _starting_point: u64, _batch_amount: u8) ->
                Vec<(msgs::ChannelAnnouncement, Option<msgs::ChannelUpdate>, Option<msgs::ChannelUpdate>)> { Vec::new() }
        fn get_next_node_announcements(&self, _starting_point: Option<&PublicKey>, _batch_amount: u8) -> Vec<msgs::NodeAnnouncement> { Vec::new() }
 -      fn sync_routing_table(&self, _their_node_id: &PublicKey, _init: &msgs::Init) {}
 +      fn peer_connected(&self, _their_node_id: &PublicKey, _init: &msgs::Init) {}
        fn handle_reply_channel_range(&self, _their_node_id: &PublicKey, _msg: msgs::ReplyChannelRange) -> Result<(), LightningError> { Ok(()) }
        fn handle_reply_short_channel_ids_end(&self, _their_node_id: &PublicKey, _msg: msgs::ReplyShortChannelIdsEnd) -> Result<(), LightningError> { Ok(()) }
        fn handle_query_channel_range(&self, _their_node_id: &PublicKey, _msg: msgs::QueryChannelRange) -> Result<(), LightningError> { Ok(()) }
@@@ -376,6 -376,8 +376,8 @@@ struct PeerHolder<Descriptor: SocketDes
  /// lifetimes). Other times you can afford a reference, which is more efficient, in which case
  /// SimpleRefPeerManager is the more appropriate type. Defining these type aliases prevents
  /// issues such as overly long function definitions.
+ ///
+ /// (C-not exported) as Arcs don't make sense in bindings
  pub type SimpleArcPeerManager<SD, M, T, F, C, L> = PeerManager<SD, Arc<SimpleArcChannelManager<M, T, F, L>>, Arc<NetGraphMsgHandler<Arc<NetworkGraph>, Arc<C>, Arc<L>>>, Arc<L>, Arc<IgnoringMessageHandler>>;
  
  /// SimpleRefPeerManager is a type alias for a PeerManager reference, and is the reference
  /// usage of lightning-net-tokio (since tokio::spawn requires parameters with static lifetimes).
  /// But if this is not necessary, using a reference is more efficient. Defining these type aliases
  /// helps with issues such as long function definitions.
+ ///
+ /// (C-not exported) as Arcs don't make sense in bindings
  pub type SimpleRefPeerManager<'a, 'b, 'c, 'd, 'e, 'f, 'g, 'h, SD, M, T, F, C, L> = PeerManager<SD, SimpleRefChannelManager<'a, 'b, 'c, 'd, 'e, M, T, F, L>, &'e NetGraphMsgHandler<&'g NetworkGraph, &'h C, &'f L>, &'f L, IgnoringMessageHandler>;
  
  /// A PeerManager manages a set of peers, described by their [`SocketDescriptor`] and marshalls
@@@ -1018,7 -1022,7 +1022,7 @@@ impl<Descriptor: SocketDescriptor, CM: 
                                        return Err(PeerHandleError{ no_connection_possible: true }.into());
                                }
  
 -                              self.message_handler.route_handler.sync_routing_table(&peer.their_node_id.unwrap(), &msg);
 +                              self.message_handler.route_handler.peer_connected(&peer.their_node_id.unwrap(), &msg);
  
                                self.message_handler.chan_handler.peer_connected(&peer.their_node_id.unwrap(), &msg);
                                peer.their_features = Some(msg.features);
                                                        msg.sync_complete);
                                                self.enqueue_message(get_peer_for_forwarding!(node_id), msg);
                                        }
 +                                      MessageSendEvent::SendGossipTimestampFilter { ref node_id, ref msg } => {
 +                                              self.enqueue_message(get_peer_for_forwarding!(node_id), msg);
 +                                      }
                                }
                        }