projects
/
rust-lightning
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge pull request #1826 from TheBlueMatt/2022-10-idempotency-err
[rust-lightning]
/
lightning
/
src
/
util
/
events.rs
diff --git
a/lightning/src/util/events.rs
b/lightning/src/util/events.rs
index 5a0a9d0cc0a7cf584f7509fda22669fb28b9d5df..a06c7f1e3c0b75ca7bba3562407afb22f5cd158a 100644
(file)
--- a/
lightning/src/util/events.rs
+++ b/
lightning/src/util/events.rs
@@
-24,7
+24,7
@@
use crate::ln::msgs;
use crate::ln::msgs::DecodeError;
use crate::ln::{PaymentPreimage, PaymentHash, PaymentSecret};
use crate::routing::gossip::NetworkUpdate;
use crate::ln::msgs::DecodeError;
use crate::ln::{PaymentPreimage, PaymentHash, PaymentSecret};
use crate::routing::gossip::NetworkUpdate;
-use crate::util::ser::{BigSize, FixedLengthReader, Writeable, Writer, MaybeReadable, Readable,
VecReadWrapper, VecWriteWrapper
, OptionDeserWrapper};
+use crate::util::ser::{BigSize, FixedLengthReader, Writeable, Writer, MaybeReadable, Readable,
WithoutLength
, OptionDeserWrapper};
use crate::routing::router::{RouteHop, RouteParameters};
use bitcoin::{PackedLockTime, Transaction};
use crate::routing::router::{RouteHop, RouteParameters};
use bitcoin::{PackedLockTime, Transaction};
@@
-318,11
+318,11
@@
pub enum Event {
channel_value_satoshis: u64,
/// The script which should be used in the transaction output.
output_script: Script,
channel_value_satoshis: u64,
/// The script which should be used in the transaction output.
output_script: Script,
- /// The `user_channel_id` value passed in to [`ChannelManager::create_channel`], or
0 for
- /// an inbound channel.
+ /// The `user_channel_id` value passed in to [`ChannelManager::create_channel`], or
a
+ ///
random value for
an inbound channel.
///
/// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
///
/// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
- user_channel_id: u
64
,
+ user_channel_id: u
128
,
},
/// Indicates we've received (an offer of) money! Just gotta dig out that payment preimage and
/// feed it to [`ChannelManager::claim_funds`] to get it....
},
/// Indicates we've received (an offer of) money! Just gotta dig out that payment preimage and
/// feed it to [`ChannelManager::claim_funds`] to get it....
@@
-612,12
+612,12
@@
pub enum Event {
/// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound
/// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if
/// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
/// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound
/// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if
/// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
- /// `user_channel_id` will be
0
for an inbound channel.
+ /// `user_channel_id` will be
randomized
for an inbound channel.
///
/// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
/// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
/// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
///
/// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
/// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
/// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
- user_channel_id: u
64
,
+ user_channel_id: u
128
,
/// The node_id of the channel counterparty.
counterparty_node_id: PublicKey,
/// The features that this channel will operate with.
/// The node_id of the channel counterparty.
counterparty_node_id: PublicKey,
/// The features that this channel will operate with.
@@
-632,13
+632,13
@@
pub enum Event {
/// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound
/// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if
/// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
/// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound
/// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if
/// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
- /// `user_channel_id` will be
0
for an inbound channel.
+ /// `user_channel_id` will be
randomized
for an inbound channel.
/// This will always be zero for objects serialized with LDK versions prior to 0.0.102.
///
/// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
/// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
/// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
/// This will always be zero for objects serialized with LDK versions prior to 0.0.102.
///
/// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
/// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
/// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
- user_channel_id: u
64
,
+ user_channel_id: u
128
,
/// The reason the channel was closed.
reason: ClosureReason
},
/// The reason the channel was closed.
reason: ClosureReason
},
@@
-785,7
+785,7
@@
impl Writeable for Event {
(1, network_update, option),
(2, payment_failed_permanently, required),
(3, all_paths_failed, required),
(1, network_update, option),
(2, payment_failed_permanently, required),
(3, all_paths_failed, required),
- (5, path, vec_type),
+ (5,
*
path, vec_type),
(7, short_channel_id, option),
(9, retry, option),
(11, payment_id, option),
(7, short_channel_id, option),
(9, retry, option),
(11, payment_id, option),
@@
-799,7
+799,7
@@
impl Writeable for Event {
&Event::SpendableOutputs { ref outputs } => {
5u8.write(writer)?;
write_tlv_fields!(writer, {
&Event::SpendableOutputs { ref outputs } => {
5u8.write(writer)?;
write_tlv_fields!(writer, {
- (0,
VecWriteWrapper
(outputs), required),
+ (0,
WithoutLength
(outputs), required),
});
},
&Event::PaymentForwarded { fee_earned_msat, prev_channel_id, claim_from_onchain_tx, next_channel_id } => {
});
},
&Event::PaymentForwarded { fee_earned_msat, prev_channel_id, claim_from_onchain_tx, next_channel_id } => {
@@
-813,10
+813,16
@@
impl Writeable for Event {
},
&Event::ChannelClosed { ref channel_id, ref user_channel_id, ref reason } => {
9u8.write(writer)?;
},
&Event::ChannelClosed { ref channel_id, ref user_channel_id, ref reason } => {
9u8.write(writer)?;
+ // `user_channel_id` used to be a single u64 value. In order to remain backwards
+ // compatible with versions prior to 0.0.113, the u128 is serialized as two
+ // separate u64 values.
+ let user_channel_id_low = *user_channel_id as u64;
+ let user_channel_id_high = (*user_channel_id >> 64) as u64;
write_tlv_fields!(writer, {
(0, channel_id, required),
write_tlv_fields!(writer, {
(0, channel_id, required),
- (1, user_channel_id, required),
- (2, reason, required)
+ (1, user_channel_id_low, required),
+ (2, reason, required),
+ (3, user_channel_id_high, required),
});
},
&Event::DiscardFunding { ref channel_id, ref transaction } => {
});
},
&Event::DiscardFunding { ref channel_id, ref transaction } => {
@@
-831,7
+837,7
@@
impl Writeable for Event {
write_tlv_fields!(writer, {
(0, payment_id, required),
(2, payment_hash, option),
write_tlv_fields!(writer, {
(0, payment_id, required),
(2, payment_hash, option),
- (4, path, vec_type)
+ (4,
*
path, vec_type)
})
},
&Event::PaymentFailed { ref payment_id, ref payment_hash } => {
})
},
&Event::PaymentFailed { ref payment_id, ref payment_hash } => {
@@
-859,7
+865,7
@@
impl Writeable for Event {
write_tlv_fields!(writer, {
(0, payment_id, required),
(2, payment_hash, required),
write_tlv_fields!(writer, {
(0, payment_id, required),
(2, payment_hash, required),
- (4, path, vec_type)
+ (4,
*
path, vec_type)
})
},
&Event::ProbeFailed { ref payment_id, ref payment_hash, ref path, ref short_channel_id } => {
})
},
&Event::ProbeFailed { ref payment_id, ref payment_hash, ref path, ref short_channel_id } => {
@@
-867,7
+873,7
@@
impl Writeable for Event {
write_tlv_fields!(writer, {
(0, payment_id, required),
(2, payment_hash, required),
write_tlv_fields!(writer, {
(0, payment_id, required),
(2, payment_hash, required),
- (4, path, vec_type),
+ (4,
*
path, vec_type),
(6, short_channel_id, option),
})
},
(6, short_channel_id, option),
})
},
@@
-1007,7
+1013,7
@@
impl MaybeReadable for Event {
4u8 => Ok(None),
5u8 => {
let f = || {
4u8 => Ok(None),
5u8 => {
let f = || {
- let mut outputs =
VecReadWrapper
(Vec::new());
+ let mut outputs =
WithoutLength
(Vec::new());
read_tlv_fields!(reader, {
(0, outputs, required),
});
read_tlv_fields!(reader, {
(0, outputs, required),
});
@@
-1035,14
+1041,22
@@
impl MaybeReadable for Event {
let f = || {
let mut channel_id = [0; 32];
let mut reason = None;
let f = || {
let mut channel_id = [0; 32];
let mut reason = None;
- let mut user_channel_id_opt = None;
+ let mut user_channel_id_low_opt: Option<u64> = None;
+ let mut user_channel_id_high_opt: Option<u64> = None;
read_tlv_fields!(reader, {
(0, channel_id, required),
read_tlv_fields!(reader, {
(0, channel_id, required),
- (1, user_channel_id_opt, option),
+ (1, user_channel_id_
low_
opt, option),
(2, reason, ignorable),
(2, reason, ignorable),
+ (3, user_channel_id_high_opt, option),
});
if reason.is_none() { return Ok(None); }
});
if reason.is_none() { return Ok(None); }
- let user_channel_id = if let Some(id) = user_channel_id_opt { id } else { 0 };
+
+ // `user_channel_id` used to be a single u64 value. In order to remain
+ // backwards compatible with versions prior to 0.0.113, the u128 is serialized
+ // as two separate u64 values.
+ let user_channel_id = (user_channel_id_low_opt.unwrap_or(0) as u128) +
+ ((user_channel_id_high_opt.unwrap_or(0) as u128) << 64);
+
Ok(Some(Event::ChannelClosed { channel_id, user_channel_id, reason: reason.unwrap() }))
};
f()
Ok(Some(Event::ChannelClosed { channel_id, user_channel_id, reason: reason.unwrap() }))
};
f()
@@
-1180,7
+1194,7
@@
impl MaybeReadable for Event {
29u8 => {
let f = || {
let mut channel_id = [0; 32];
29u8 => {
let f = || {
let mut channel_id = [0; 32];
- let mut user_channel_id: u
64
= 0;
+ let mut user_channel_id: u
128
= 0;
let mut counterparty_node_id = OptionDeserWrapper(None);
let mut channel_type = OptionDeserWrapper(None);
read_tlv_fields!(reader, {
let mut counterparty_node_id = OptionDeserWrapper(None);
let mut channel_type = OptionDeserWrapper(None);
read_tlv_fields!(reader, {
@@
-1400,6
+1414,10
@@
pub trait OnionMessageProvider {
///
/// Events are processed by passing an [`EventHandler`] to [`process_pending_events`].
///
///
/// Events are processed by passing an [`EventHandler`] to [`process_pending_events`].
///
+/// Implementations of this trait may also feature an async version of event handling, as shown with
+/// [`ChannelManager::process_pending_events_async`] and
+/// [`ChainMonitor::process_pending_events_async`].
+///
/// # Requirements
///
/// When using this trait, [`process_pending_events`] will call [`handle_event`] for each pending
/// # Requirements
///
/// When using this trait, [`process_pending_events`] will call [`handle_event`] for each pending
@@
-1426,6
+1444,8
@@
pub trait OnionMessageProvider {
/// [`handle_event`]: EventHandler::handle_event
/// [`ChannelManager::process_pending_events`]: crate::ln::channelmanager::ChannelManager#method.process_pending_events
/// [`ChainMonitor::process_pending_events`]: crate::chain::chainmonitor::ChainMonitor#method.process_pending_events
/// [`handle_event`]: EventHandler::handle_event
/// [`ChannelManager::process_pending_events`]: crate::ln::channelmanager::ChannelManager#method.process_pending_events
/// [`ChainMonitor::process_pending_events`]: crate::chain::chainmonitor::ChainMonitor#method.process_pending_events
+/// [`ChannelManager::process_pending_events_async`]: crate::ln::channelmanager::ChannelManager::process_pending_events_async
+/// [`ChainMonitor::process_pending_events_async`]: crate::chain::chainmonitor::ChainMonitor::process_pending_events_async
pub trait EventsProvider {
/// Processes any events generated since the last call using the given event handler.
///
pub trait EventsProvider {
/// Processes any events generated since the last call using the given event handler.
///
@@
-1434,21
+1454,25
@@
pub trait EventsProvider {
}
/// A trait implemented for objects handling events from [`EventsProvider`].
}
/// A trait implemented for objects handling events from [`EventsProvider`].
+///
+/// An async variation also exists for implementations of [`EventsProvider`] that support async
+/// event handling. The async event handler should satisfy the generic bounds: `F:
+/// core::future::Future, H: Fn(Event) -> F`.
pub trait EventHandler {
/// Handles the given [`Event`].
///
/// See [`EventsProvider`] for details that must be considered when implementing this method.
pub trait EventHandler {
/// Handles the given [`Event`].
///
/// See [`EventsProvider`] for details that must be considered when implementing this method.
- fn handle_event(&self, event:
&
Event);
+ fn handle_event(&self, event: Event);
}
}
-impl<F> EventHandler for F where F: Fn(
&
Event) {
- fn handle_event(&self, event:
&
Event) {
+impl<F> EventHandler for F where F: Fn(Event) {
+ fn handle_event(&self, event: Event) {
self(event)
}
}
impl<T: EventHandler> EventHandler for Arc<T> {
self(event)
}
}
impl<T: EventHandler> EventHandler for Arc<T> {
- fn handle_event(&self, event:
&
Event) {
+ fn handle_event(&self, event: Event) {
self.deref().handle_event(event)
}
}
self.deref().handle_event(event)
}
}