use crate::ln::{PaymentPreimage, PaymentHash, PaymentSecret};
+use crate::routing::gossip::NodeId;
+
/// 21 million * 10^8 * 1000
pub(crate) const MAX_VALUE_MSAT: u64 = 21_000_000_0000_0000_000;
}
}
+/// Represents the set of gossip messages that require a signature from a node's identity key.
+pub enum UnsignedGossipMessage<'a> {
+ /// An unsigned channel announcement.
+ ChannelAnnouncement(&'a UnsignedChannelAnnouncement),
+ /// An unsigned channel update.
+ ChannelUpdate(&'a UnsignedChannelUpdate),
+ /// An unsigned node announcement.
+ NodeAnnouncement(&'a UnsignedNodeAnnouncement)
+}
+
+impl<'a> Writeable for UnsignedGossipMessage<'a> {
+ fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
+ match self {
+ UnsignedGossipMessage::ChannelAnnouncement(ref msg) => msg.write(writer),
+ UnsignedGossipMessage::ChannelUpdate(ref msg) => msg.write(writer),
+ UnsignedGossipMessage::NodeAnnouncement(ref msg) => msg.write(writer),
+ }
+ }
+}
/// The unsigned part of a [`node_announcement`] message.
///
pub timestamp: u32,
/// The `node_id` this announcement originated from (don't rebroadcast the `node_announcement` back
/// to this node).
- pub node_id: PublicKey,
+ pub node_id: NodeId,
/// An RGB color for UI purposes
pub rgb: [u8; 3],
/// An alias, for UI purposes.
/// The short channel ID
pub short_channel_id: u64,
/// One of the two `node_id`s which are endpoints of this channel
- pub node_id_1: PublicKey,
+ pub node_id_1: NodeId,
/// The other of the two `node_id`s which are endpoints of this channel
- pub node_id_2: PublicKey,
+ pub node_id_2: NodeId,
/// The funding key for the first node
- pub bitcoin_key_1: PublicKey,
+ pub bitcoin_key_1: NodeId,
/// The funding key for the second node
- pub bitcoin_key_2: PublicKey,
+ pub bitcoin_key_2: NodeId,
pub(crate) excess_data: Vec<u8>,
}
/// A [`channel_announcement`] message to be sent to or received from a peer.
pub short_channel_ids: Vec<u64>,
}
-/// A [`reply_short_channel_ids_end message`] is sent as a reply to a
+/// A [`reply_short_channel_ids_end`] message is sent as a reply to a
/// message. The query recipient makes a best
/// effort to respond based on their local network view which may not be
/// a perfect view of the network.
fn handle_announcement_signatures(&self, their_node_id: &PublicKey, msg: &AnnouncementSignatures);
// Connection loss/reestablish:
- /// Indicates a connection to the peer failed/an existing connection was lost. If no connection
- /// is believed to be possible in the future (eg they're sending us messages we don't
- /// understand or indicate they require unknown feature bits), `no_connection_possible` is set
- /// and any outstanding channels should be failed.
- ///
- /// Note that in some rare cases this may be called without a corresponding
- /// [`Self::peer_connected`].
- fn peer_disconnected(&self, their_node_id: &PublicKey, no_connection_possible: bool);
+ /// Indicates a connection to the peer failed/an existing connection was lost.
+ fn peer_disconnected(&self, their_node_id: &PublicKey);
/// Handle a peer reconnecting, possibly generating `channel_reestablish` message(s).
///
/// May return an `Err(())` if the features the peer supports are not sufficient to communicate
/// with us. Implementors should be somewhat conservative about doing so, however, as other
/// message handlers may still wish to communicate with this peer.
- fn peer_connected(&self, their_node_id: &PublicKey, msg: &Init) -> Result<(), ()>;
+ fn peer_connected(&self, their_node_id: &PublicKey, msg: &Init, inbound: bool) -> Result<(), ()>;
/// Handle an incoming `channel_reestablish` message from the given peer.
fn handle_channel_reestablish(&self, their_node_id: &PublicKey, msg: &ChannelReestablish);
/// the node *after* the provided pubkey and including up to one announcement immediately
/// higher (as defined by `<PublicKey as Ord>::cmp`) than `starting_point`.
/// If `None` is provided for `starting_point`, we start at the first node.
- fn get_next_node_announcement(&self, starting_point: Option<&PublicKey>) -> Option<NodeAnnouncement>;
+ fn get_next_node_announcement(&self, starting_point: Option<&NodeId>) -> Option<NodeAnnouncement>;
/// Called when a connection is established with a peer. This can be used to
/// perform routing table synchronization using a strategy defined by the
/// implementor.
/// May return an `Err(())` if the features the peer supports are not sufficient to communicate
/// with us. Implementors should be somewhat conservative about doing so, however, as other
/// message handlers may still wish to communicate with this peer.
- fn peer_connected(&self, their_node_id: &PublicKey, init: &Init) -> Result<(), ()>;
+ fn peer_connected(&self, their_node_id: &PublicKey, init: &Init, inbound: bool) -> Result<(), ()>;
/// Handles the reply of a query we initiated to learn about channels
/// for a given range of blocks. We can expect to receive one or more
/// replies to a single query.
/// list of `short_channel_id`s.
fn handle_query_short_channel_ids(&self, their_node_id: &PublicKey, msg: QueryShortChannelIds) -> Result<(), LightningError>;
+ // Handler queueing status:
+ /// Indicates that there are a large number of [`ChannelAnnouncement`] (or other) messages
+ /// pending some async action. While there is no guarantee of the rate of future messages, the
+ /// caller should seek to reduce the rate of new gossip messages handled, especially
+ /// [`ChannelAnnouncement`]s.
+ fn processing_queue_high(&self) -> bool;
+
// Handler information:
/// Gets the node feature flags which this handler itself supports. All available handlers are
/// queried similarly and their feature flags are OR'd together to form the [`NodeFeatures`]
/// May return an `Err(())` if the features the peer supports are not sufficient to communicate
/// with us. Implementors should be somewhat conservative about doing so, however, as other
/// message handlers may still wish to communicate with this peer.
- fn peer_connected(&self, their_node_id: &PublicKey, init: &Init) -> Result<(), ()>;
+ fn peer_connected(&self, their_node_id: &PublicKey, init: &Init, inbound: bool) -> Result<(), ()>;
/// Indicates a connection to the peer failed/an existing connection was lost. Allows handlers to
/// drop and refuse to forward onion messages to this peer.
- ///
- /// Note that in some rare cases this may be called without a corresponding
- /// [`Self::peer_connected`].
- fn peer_disconnected(&self, their_node_id: &PublicKey, no_connection_possible: bool);
+ fn peer_disconnected(&self, their_node_id: &PublicKey);
// Handler information:
/// Gets the node feature flags which this handler itself supports. All available handlers are
fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
let features: NodeFeatures = Readable::read(r)?;
let timestamp: u32 = Readable::read(r)?;
- let node_id: PublicKey = Readable::read(r)?;
+ let node_id: NodeId = Readable::read(r)?;
let mut rgb = [0; 3];
r.read_exact(&mut rgb)?;
let alias: [u8; 32] = Readable::read(r)?;
use crate::ln::features::{ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures};
use crate::ln::msgs;
use crate::ln::msgs::{FinalOnionHopData, OptionalField, OnionErrorPacket, OnionHopDataFormat};
+ use crate::routing::gossip::NodeId;
use crate::util::ser::{Writeable, Readable, Hostname};
use bitcoin::hashes::hex::FromHex;
features,
chain_hash: BlockHash::from_hex("6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000").unwrap(),
short_channel_id: 2316138423780173,
- node_id_1: pubkey_1,
- node_id_2: pubkey_2,
- bitcoin_key_1: pubkey_3,
- bitcoin_key_2: pubkey_4,
+ node_id_1: NodeId::from_pubkey(&pubkey_1),
+ node_id_2: NodeId::from_pubkey(&pubkey_2),
+ bitcoin_key_1: NodeId::from_pubkey(&pubkey_3),
+ bitcoin_key_2: NodeId::from_pubkey(&pubkey_4),
excess_data: if excess_data { vec![10, 0, 0, 20, 0, 0, 30, 0, 0, 40] } else { Vec::new() },
};
let channel_announcement = msgs::ChannelAnnouncement {
let unsigned_node_announcement = msgs::UnsignedNodeAnnouncement {
features,
timestamp: 20190119,
- node_id: pubkey_1,
+ node_id: NodeId::from_pubkey(&pubkey_1),
rgb: [32; 3],
alias: [16;32],
addresses,