Drop completed blocked `ChannelMonitorUpdate`s on startup
[rust-lightning] / lightning / src / ln / msgs.rs
index 41d8974f29cbfa2637238b7d4b8a16cf3fea020c..c5763d08d6728867876274f1d882341369a2900f 100644 (file)
@@ -53,7 +53,7 @@ use crate::io::{self, Cursor, Read};
 use crate::io_extras::read_to_end;
 
 use crate::events::{EventsProvider, MessageSendEventsProvider};
-use crate::util::chacha20poly1305rfc::ChaChaPolyReadAdapter;
+use crate::crypto::streams::ChaChaPolyReadAdapter;
 use crate::util::logger;
 use crate::util::ser::{LengthReadable, LengthReadableArgs, Readable, ReadableArgs, Writeable, Writer, WithoutLength, FixedLengthReader, HighZeroBytesDroppedBigSize, Hostname, TransactionU16LenLimited, BigSize};
 use crate::util::base32;
@@ -695,7 +695,7 @@ pub struct OnionMessage {
        /// Used in decrypting the onion packet's payload.
        pub blinding_point: PublicKey,
        /// The full onion packet including hop data, pubkey, and hmac
-       pub onion_routing_packet: onion_message::Packet,
+       pub onion_routing_packet: onion_message::packet::Packet,
 }
 
 /// An [`update_fulfill_htlc`] message to be sent to or received from a peer.
@@ -1132,16 +1132,17 @@ impl FromStr for SocketAddress {
 }
 
 /// Represents the set of gossip messages that require a signature from a node's identity key.
-pub enum UnsignedGossipMessage<'a> {
+#[derive(Clone)]
+pub enum UnsignedGossipMessage {
        /// An unsigned channel announcement.
-       ChannelAnnouncement(&'a UnsignedChannelAnnouncement),
+       ChannelAnnouncement(UnsignedChannelAnnouncement),
        /// An unsigned channel update.
-       ChannelUpdate(&'a UnsignedChannelUpdate),
+       ChannelUpdate(UnsignedChannelUpdate),
        /// An unsigned node announcement.
-       NodeAnnouncement(&'a UnsignedNodeAnnouncement)
+       NodeAnnouncement(UnsignedNodeAnnouncement)
 }
 
-impl<'a> Writeable for UnsignedGossipMessage<'a> {
+impl Writeable for UnsignedGossipMessage {
        fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
                match self {
                        UnsignedGossipMessage::ChannelAnnouncement(ref msg) => msg.write(writer),
@@ -1631,7 +1632,16 @@ pub trait RoutingMessageHandler : MessageSendEventsProvider {
 }
 
 /// A handler for received [`OnionMessage`]s and for providing generated ones to send.
-pub trait OnionMessageHandler: EventsProvider {
+pub trait OnionMessageHandler {
+       /// Because much of the lightning network does not yet support forwarding onion messages, we
+       /// may need to directly connect to a node which will forward a message for us. In such a case,
+       /// this method will return the set of nodes which need connection by node_id and the
+       /// corresponding socket addresses where they may accept incoming connections.
+       ///
+       /// Thus, this method should be polled regularly to detect messages await such a direct
+       /// connection.
+       fn get_and_clear_connections_needed(&self) -> Vec<(PublicKey, Vec<SocketAddress>)>;
+
        /// Handle an incoming `onion_message` message from the given peer.
        fn handle_onion_message(&self, peer_node_id: &PublicKey, msg: &OnionMessage);
 
@@ -1714,7 +1724,7 @@ mod fuzzy_internal_msgs {
                        payment_relay: PaymentRelay,
                        payment_constraints: PaymentConstraints,
                        features: BlindedHopFeatures,
-                       intro_node_blinding_point: PublicKey,
+                       intro_node_blinding_point: Option<PublicKey>,
                },
                BlindedReceive {
                        sender_intended_htlc_amt_msat: u64,
@@ -2245,7 +2255,8 @@ impl Readable for OnionMessage {
                let blinding_point: PublicKey = Readable::read(r)?;
                let len: u16 = Readable::read(r)?;
                let mut packet_reader = FixedLengthReader::new(r, len as u64);
-               let onion_routing_packet: onion_message::Packet = <onion_message::Packet as LengthReadable>::read(&mut packet_reader)?;
+               let onion_routing_packet: onion_message::packet::Packet =
+                       <onion_message::packet::Packet as LengthReadable>::read(&mut packet_reader)?;
                Ok(Self {
                        blinding_point,
                        onion_routing_packet,
@@ -2393,7 +2404,7 @@ impl<NS: Deref> ReadableArgs<(Option<PublicKey>, &NS)> for InboundOnionPayload w
                                                payment_relay,
                                                payment_constraints,
                                                features,
-                                               intro_node_blinding_point: intro_node_blinding_point.ok_or(DecodeError::InvalidValue)?,
+                                               intro_node_blinding_point,
                                        })
                                },
                                ChaChaPolyReadAdapter { readable: BlindedPaymentTlvs::Receive(ReceiveTlvs {