X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Futil%2Fevents.rs;h=8b8cc1230372821aa52c0cd4e6edbdc01cb5f1bd;hb=affefb677e3f9f1a586707484ac82b6c86f4f26b;hp=8f34605675c4ee2992a9f045bc8b49d19e9ffd81;hpb=5a2ed0324738e170e0b3b4dab3431242c7221a13;p=rust-lightning diff --git a/lightning/src/util/events.rs b/lightning/src/util/events.rs index 8f346056..8b8cc123 100644 --- a/lightning/src/util/events.rs +++ b/lightning/src/util/events.rs @@ -1,3 +1,12 @@ +// This file is Copyright its original authors, visible in version control +// history. +// +// This file is licensed under the Apache License, Version 2.0 or the MIT license +// , at your option. +// You may not use this file except in accordance with one or both of these +// licenses. + //! Events are returned from various bits in the library which indicate some action must be taken //! by the client. //! @@ -7,13 +16,12 @@ use ln::msgs; use ln::channelmanager::{PaymentPreimage, PaymentHash, PaymentSecret}; -use chain::transaction::OutPoint; use chain::keysinterface::SpendableOutputDescriptor; use util::ser::{Writeable, Writer, MaybeReadable, Readable}; use bitcoin::blockdata::script::Script; -use secp256k1::key::PublicKey; +use bitcoin::secp256k1::key::PublicKey; use std::time::Duration; @@ -22,6 +30,7 @@ use std::time::Duration; /// Note that while Writeable and Readable are implemented for Event, you probably shouldn't use /// them directly as they don't round-trip exactly (for example FundingGenerationReady is never /// written as it makes no sense to respond to it after reconnecting to peers). +#[derive(Clone, Debug)] pub enum Event { /// Used to indicate that the client should generate a funding transaction with the given /// parameters and then call ChannelManager::funding_transaction_generated. @@ -39,22 +48,16 @@ pub enum Event { /// The value passed in to ChannelManager::create_channel user_channel_id: u64, }, - /// Used to indicate that the client may now broadcast the funding transaction it created for a - /// channel. Broadcasting such a transaction prior to this event may lead to our counterparty - /// trivially stealing all funds in the funding transaction! - FundingBroadcastSafe { - /// The output, which was passed to ChannelManager::funding_transaction_generated, which is - /// now safe to broadcast. - funding_txo: OutPoint, - /// The value passed in to ChannelManager::create_channel - user_channel_id: u64, - }, /// Indicates we've received money! Just gotta dig out that payment preimage and feed it to /// ChannelManager::claim_funds to get it.... - /// Note that if the preimage is not known or the amount paid is incorrect, you must call - /// ChannelManager::fail_htlc_backwards to free up resources for this HTLC. + /// Note that if the preimage is not known or the amount paid is incorrect, you should call + /// ChannelManager::fail_htlc_backwards to free up resources for this HTLC and avoid + /// network congestion. /// The amount paid should be considered 'incorrect' when it is less than or more than twice /// the amount expected. + /// If you fail to call either ChannelManager::claim_funds or + /// ChannelManager::fail_htlc_backwards within the HTLC's timeout, the HTLC will be + /// automatically failed. PaymentReceived { /// The hash for which the preimage should be handed to the ChannelManager. payment_hash: PaymentHash, @@ -126,19 +129,14 @@ impl Writeable for Event { // We never write out FundingGenerationReady events as, upon disconnection, peers // drop any channels which have not yet exchanged funding_signed. }, - &Event::FundingBroadcastSafe { ref funding_txo, ref user_channel_id } => { - 1u8.write(writer)?; - funding_txo.write(writer)?; - user_channel_id.write(writer)?; - }, &Event::PaymentReceived { ref payment_hash, ref payment_secret, ref amt } => { - 2u8.write(writer)?; + 1u8.write(writer)?; payment_hash.write(writer)?; payment_secret.write(writer)?; amt.write(writer)?; }, &Event::PaymentSent { ref payment_preimage } => { - 3u8.write(writer)?; + 2u8.write(writer)?; payment_preimage.write(writer)?; }, &Event::PaymentFailed { ref payment_hash, ref rejected_by_dest, @@ -147,7 +145,7 @@ impl Writeable for Event { #[cfg(test)] ref error_data, } => { - 4u8.write(writer)?; + 3u8.write(writer)?; payment_hash.write(writer)?; rejected_by_dest.write(writer)?; #[cfg(test)] @@ -156,12 +154,12 @@ impl Writeable for Event { error_data.write(writer)?; }, &Event::PendingHTLCsForwardable { time_forwardable: _ } => { - 5u8.write(writer)?; + 4u8.write(writer)?; // We don't write the time_fordwardable out at all, as we presume when the user // deserializes us at least that much time has elapsed. }, &Event::SpendableOutputs { ref outputs } => { - 6u8.write(writer)?; + 5u8.write(writer)?; (outputs.len() as u64).write(writer)?; for output in outputs.iter() { output.write(writer)?; @@ -175,19 +173,15 @@ impl MaybeReadable for Event { fn read(reader: &mut R) -> Result, msgs::DecodeError> { match Readable::read(reader)? { 0u8 => Ok(None), - 1u8 => Ok(Some(Event::FundingBroadcastSafe { - funding_txo: Readable::read(reader)?, - user_channel_id: Readable::read(reader)?, - })), - 2u8 => Ok(Some(Event::PaymentReceived { + 1u8 => Ok(Some(Event::PaymentReceived { payment_hash: Readable::read(reader)?, payment_secret: Readable::read(reader)?, amt: Readable::read(reader)?, })), - 3u8 => Ok(Some(Event::PaymentSent { + 2u8 => Ok(Some(Event::PaymentSent { payment_preimage: Readable::read(reader)?, })), - 4u8 => Ok(Some(Event::PaymentFailed { + 3u8 => Ok(Some(Event::PaymentFailed { payment_hash: Readable::read(reader)?, rejected_by_dest: Readable::read(reader)?, #[cfg(test)] @@ -195,10 +189,10 @@ impl MaybeReadable for Event { #[cfg(test)] error_data: Readable::read(reader)?, })), - 5u8 => Ok(Some(Event::PendingHTLCsForwardable { + 4u8 => Ok(Some(Event::PendingHTLCsForwardable { time_forwardable: Duration::from_secs(0) })), - 6u8 => { + 5u8 => { let outputs_len: u64 = Readable::read(reader)?; let mut outputs = Vec::new(); for _ in 0..outputs_len { @@ -214,7 +208,7 @@ impl MaybeReadable for Event { /// An event generated by ChannelManager which indicates a message should be sent to a peer (or /// broadcast to most peers). /// These events are handled by PeerManager::process_events if you are using a PeerManager. -#[derive(Clone)] +#[derive(Clone, Debug)] pub enum MessageSendEvent { /// Used to indicate that we've accepted a channel open and should send the accept_channel /// message provided to the given peer. @@ -328,10 +322,33 @@ pub enum MessageSendEvent { action: msgs::ErrorAction }, /// When a payment fails we may receive updates back from the hop where it failed. In such - /// cases this event is generated so that we can inform the router of this information. + /// cases this event is generated so that we can inform the network graph of this information. PaymentFailureNetworkUpdate { - /// The channel/node update which should be sent to router + /// The channel/node update which should be sent to NetGraphMsgHandler update: msgs::HTLCFailChannelUpdate, + }, + /// Query a peer for channels with funding transaction UTXOs in a block range. + SendChannelRangeQuery { + /// The node_id of this message recipient + node_id: PublicKey, + /// The query_channel_range which should be sent. + msg: msgs::QueryChannelRange, + }, + /// Request routing gossip messages from a peer for a list of channels identified by + /// their short_channel_ids. + SendShortIdsQuery { + /// The node_id of this message recipient + node_id: PublicKey, + /// The query_short_channel_ids which should be sent. + msg: msgs::QueryShortChannelIds, + }, + /// Sends a reply to a channel range query. This may be one of several SendReplyChannelRange events + /// emitted during processing of the query. + SendReplyChannelRange { + /// The node_id of this message recipient + node_id: PublicKey, + /// The reply_channel_range which should be sent. + msg: msgs::ReplyChannelRange, } }