+/// A read-only view of [`NetworkGraph`].
+pub struct ReadOnlyNetworkGraph<'a> {
+ channels: RwLockReadGuard<'a, BTreeMap<u64, ChannelInfo>>,
+ nodes: RwLockReadGuard<'a, BTreeMap<PublicKey, NodeInfo>>,
+}
+
+/// Update to the [`NetworkGraph`] based on payment failure information conveyed via the Onion
+/// return packet by a node along the route. See [BOLT #4] for details.
+///
+/// [BOLT #4]: https://github.com/lightningnetwork/lightning-rfc/blob/master/04-onion-routing.md
+#[derive(Clone, Debug, PartialEq)]
+pub enum NetworkUpdate {
+ /// An error indicating a `channel_update` messages should be applied via
+ /// [`NetworkGraph::update_channel`].
+ ChannelUpdateMessage {
+ /// The update to apply via [`NetworkGraph::update_channel`].
+ msg: ChannelUpdate,
+ },
+ /// An error indicating only that a channel has been closed, which should be applied via
+ /// [`NetworkGraph::close_channel_from_update`].
+ ChannelClosed {
+ /// The short channel id of the closed channel.
+ short_channel_id: u64,
+ /// Whether the channel should be permanently removed or temporarily disabled until a new
+ /// `channel_update` message is received.
+ is_permanent: bool,
+ },
+ /// An error indicating only that a node has failed, which should be applied via
+ /// [`NetworkGraph::fail_node`].
+ NodeFailure {
+ /// The node id of the failed node.
+ node_id: PublicKey,
+ /// Whether the node should be permanently removed from consideration or can be restored
+ /// when a new `channel_update` message is received.
+ is_permanent: bool,
+ }
+}
+
+impl_writeable_tlv_based_enum_upgradable!(NetworkUpdate,
+ (0, ChannelUpdateMessage) => {
+ (0, msg, required),
+ },
+ (2, ChannelClosed) => {
+ (0, short_channel_id, required),
+ (2, is_permanent, required),
+ },
+ (4, NodeFailure) => {
+ (0, node_id, required),
+ (2, is_permanent, required),
+ },
+);
+
+impl<C: Deref, L: Deref> EventHandler for NetGraphMsgHandler<C, L>
+where C::Target: chain::Access, L::Target: Logger {
+ fn handle_event(&self, event: &Event) {
+ if let Event::PaymentPathFailed { payment_hash: _, rejected_by_dest: _, network_update, .. } = event {
+ if let Some(network_update) = network_update {
+ self.handle_network_update(network_update);
+ }
+ }
+ }
+}