Skip to content

Commit 7c07b22

Browse files
authored
Merge pull request lightningdevkit#3042 from TheBlueMatt/2024-05-123-backports
0.0.123 Backports
2 parents f0a3029 + 5cb2089 commit 7c07b22

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1239
-769
lines changed

lightning-background-processor/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ mod tests {
932932
use lightning::chain::transaction::OutPoint;
933933
use lightning::events::{Event, PathFailure, MessageSendEventsProvider, MessageSendEvent};
934934
use lightning::{get_event_msg, get_event};
935-
use lightning::ln::{PaymentHash, ChannelId};
935+
use lightning::ln::types::{PaymentHash, ChannelId};
936936
use lightning::ln::channelmanager;
937937
use lightning::ln::channelmanager::{BREAKDOWN_TIMEOUT, ChainParameters, MIN_CLTV_EXPIRY_DELTA, PaymentId};
938938
use lightning::ln::features::{ChannelFeatures, NodeFeatures};

lightning-custom-message/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
//! `Foo` and `Bar` messages, and further composing it with a handler for `Baz` messages.
1313
//!
1414
//!```
15+
//! # fn main() {} // Avoid #[macro_export] generating an in-function warning
1516
//! # extern crate bitcoin;
1617
//! extern crate lightning;
1718
//! #[macro_use]
@@ -167,7 +168,6 @@
167168
//! # }
168169
//! }
169170
//!
170-
//! # fn main() {
171171
//! // The first crate may define a handler composing `FooHandler` and `BarHandler` and export the
172172
//! // corresponding message type ids as a macro to use in further composition.
173173
//!
@@ -207,7 +207,6 @@
207207
//! macro_rules! foo_bar_baz_type_ids {
208208
//! () => { foo_bar_type_ids!() | baz_type_id!() }
209209
//! }
210-
//! # }
211210
//!```
212211
//!
213212
//! [BOLT 1]: https://github.com/lightning/bolts/blob/master/01-messaging.md

lightning-invoice/src/de.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use bitcoin::address::WitnessVersion;
1515
use bitcoin::hashes::Hash;
1616
use bitcoin::hashes::sha256;
1717
use crate::prelude::*;
18-
use lightning::ln::PaymentSecret;
18+
use lightning::ln::types::PaymentSecret;
1919
use lightning::routing::gossip::RoutingFees;
2020
use lightning::routing::router::{RouteHint, RouteHintHop};
2121

lightning-invoice/src/lib.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ use core::str;
6565
use serde::{Deserialize, Deserializer,Serialize, Serializer, de::Error};
6666

6767
#[doc(no_inline)]
68-
pub use lightning::ln::PaymentSecret;
68+
pub use lightning::ln::types::PaymentSecret;
6969
#[doc(no_inline)]
7070
pub use lightning::routing::router::{RouteHint, RouteHintHop};
7171
#[doc(no_inline)]
@@ -162,7 +162,7 @@ pub const DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA: u64 = 18;
162162
/// use secp256k1::Secp256k1;
163163
/// use secp256k1::SecretKey;
164164
///
165-
/// use lightning::ln::PaymentSecret;
165+
/// use lightning::ln::types::PaymentSecret;
166166
///
167167
/// use lightning_invoice::{Currency, InvoiceBuilder};
168168
///
@@ -577,7 +577,13 @@ impl<D: tb::Bool, H: tb::Bool, T: tb::Bool, C: tb::Bool, S: tb::Bool, M: tb::Boo
577577

578578
/// Sets the amount in millisatoshis. The optimal SI prefix is chosen automatically.
579579
pub fn amount_milli_satoshis(mut self, amount_msat: u64) -> Self {
580-
let amount = amount_msat * 10; // Invoices are denominated in "pico BTC"
580+
let amount = match amount_msat.checked_mul(10) { // Invoices are denominated in "pico BTC"
581+
Some(amt) => amt,
582+
None => {
583+
self.error = Some(CreationError::InvalidAmount);
584+
return self
585+
}
586+
};
581587
let biggest_possible_si_prefix = SiPrefix::values_desc()
582588
.iter()
583589
.find(|prefix| amount % prefix.multiplier() == 0)
@@ -1068,9 +1074,10 @@ impl RawBolt11Invoice {
10681074
find_all_extract!(self.known_tagged_fields(), TaggedField::PrivateRoute(ref x), x).collect()
10691075
}
10701076

1077+
/// Returns `None` if no amount is set or on overflow.
10711078
pub fn amount_pico_btc(&self) -> Option<u64> {
1072-
self.hrp.raw_amount.map(|v| {
1073-
v * self.hrp.si_prefix.as_ref().map_or(1_000_000_000_000, |si| { si.multiplier() })
1079+
self.hrp.raw_amount.and_then(|v| {
1080+
v.checked_mul(self.hrp.si_prefix.as_ref().map_or(1_000_000_000_000, |si| { si.multiplier() }))
10741081
})
10751082
}
10761083

@@ -1876,7 +1883,7 @@ mod test {
18761883
Bolt11SemanticError};
18771884

18781885
let private_key = SecretKey::from_slice(&[42; 32]).unwrap();
1879-
let payment_secret = lightning::ln::PaymentSecret([21; 32]);
1886+
let payment_secret = lightning::ln::types::PaymentSecret([21; 32]);
18801887
let invoice_template = RawBolt11Invoice {
18811888
hrp: RawHrp {
18821889
currency: Currency::Bitcoin,

lightning-invoice/src/payment.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use crate::Bolt11Invoice;
1313
use bitcoin::hashes::Hash;
1414

15-
use lightning::ln::PaymentHash;
15+
use lightning::ln::types::PaymentHash;
1616
use lightning::ln::channelmanager::RecipientOnionFields;
1717
use lightning::routing::router::{PaymentParameters, RouteParameters};
1818

@@ -85,7 +85,7 @@ mod tests {
8585
use super::*;
8686
use crate::{InvoiceBuilder, Currency};
8787
use bitcoin::hashes::sha256::Hash as Sha256;
88-
use lightning::ln::PaymentSecret;
88+
use lightning::ln::types::PaymentSecret;
8989
use lightning::routing::router::Payee;
9090
use secp256k1::{SecretKey, PublicKey, Secp256k1};
9191
use core::time::Duration;

lightning-invoice/src/utils.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use bitcoin::hashes::Hash;
88
use lightning::chain;
99
use lightning::chain::chaininterface::{BroadcasterInterface, FeeEstimator};
1010
use lightning::sign::{Recipient, NodeSigner, SignerProvider, EntropySource};
11-
use lightning::ln::{PaymentHash, PaymentSecret};
11+
use lightning::ln::types::{PaymentHash, PaymentSecret};
1212
use lightning::ln::channelmanager::{ChannelDetails, ChannelManager, MIN_FINAL_CLTV_EXPIRY_DELTA};
1313
use lightning::ln::channelmanager::{PhantomRouteHints, MIN_CLTV_EXPIRY_DELTA};
1414
use lightning::ln::inbound_payment::{create, create_from_hash, ExpandedKey};
@@ -824,9 +824,9 @@ mod test {
824824
use bitcoin::hashes::sha256::Hash as Sha256;
825825
use lightning::sign::PhantomKeysManager;
826826
use lightning::events::{MessageSendEvent, MessageSendEventsProvider};
827-
use lightning::ln::PaymentHash;
827+
use lightning::ln::types::PaymentHash;
828828
#[cfg(feature = "std")]
829-
use lightning::ln::PaymentPreimage;
829+
use lightning::ln::types::PaymentPreimage;
830830
use lightning::ln::channelmanager::{PhantomRouteHints, MIN_FINAL_CLTV_EXPIRY_DELTA, PaymentId, RecipientOnionFields, Retry};
831831
use lightning::ln::functional_test_utils::*;
832832
use lightning::ln::msgs::ChannelMessageHandler;

lightning/src/blinded_path/message.rs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use bitcoin::secp256k1::{self, PublicKey, Secp256k1, SecretKey};
33
#[allow(unused_imports)]
44
use crate::prelude::*;
55

6-
use crate::blinded_path::{BlindedHop, BlindedPath, IntroductionNode, NodeIdLookUp};
6+
use crate::blinded_path::{BlindedHop, BlindedPath, IntroductionNode, NextMessageHop, NodeIdLookUp};
77
use crate::blinded_path::utils;
88
use crate::io;
99
use crate::io::Cursor;
@@ -20,7 +20,7 @@ use core::ops::Deref;
2020
/// route, they are encoded into [`BlindedHop::encrypted_payload`].
2121
pub(crate) struct ForwardTlvs {
2222
/// The next hop in the onion message's path.
23-
pub(crate) next_hop: NextHop,
23+
pub(crate) next_hop: NextMessageHop,
2424
/// Senders to a blinded path use this value to concatenate the route they find to the
2525
/// introduction node with the blinded path.
2626
pub(crate) next_blinding_override: Option<PublicKey>,
@@ -34,20 +34,11 @@ pub(crate) struct ReceiveTlvs {
3434
pub(crate) path_id: Option<[u8; 32]>,
3535
}
3636

37-
/// The next hop to forward the onion message along its path.
38-
#[derive(Debug)]
39-
pub enum NextHop {
40-
/// The node id of the next hop.
41-
NodeId(PublicKey),
42-
/// The short channel id leading to the next hop.
43-
ShortChannelId(u64),
44-
}
45-
4637
impl Writeable for ForwardTlvs {
4738
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
4839
let (next_node_id, short_channel_id) = match self.next_hop {
49-
NextHop::NodeId(pubkey) => (Some(pubkey), None),
50-
NextHop::ShortChannelId(scid) => (None, Some(scid)),
40+
NextMessageHop::NodeId(pubkey) => (Some(pubkey), None),
41+
NextMessageHop::ShortChannelId(scid) => (None, Some(scid)),
5142
};
5243
// TODO: write padding
5344
encode_tlv_stream!(writer, {
@@ -75,7 +66,7 @@ pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
7566
) -> Result<Vec<BlindedHop>, secp256k1::Error> {
7667
let blinded_tlvs = unblinded_path.iter()
7768
.skip(1) // The first node's TLVs contains the next node's pubkey
78-
.map(|pk| ForwardTlvs { next_hop: NextHop::NodeId(*pk), next_blinding_override: None })
69+
.map(|pk| ForwardTlvs { next_hop: NextMessageHop::NodeId(*pk), next_blinding_override: None })
7970
.map(|tlvs| ControlTlvs::Forward(tlvs))
8071
.chain(core::iter::once(ControlTlvs::Receive(ReceiveTlvs { path_id: None })));
8172

@@ -102,8 +93,8 @@ where
10293
readable: ControlTlvs::Forward(ForwardTlvs { next_hop, next_blinding_override })
10394
}) => {
10495
let next_node_id = match next_hop {
105-
NextHop::NodeId(pubkey) => pubkey,
106-
NextHop::ShortChannelId(scid) => match node_id_lookup.next_node_id(scid) {
96+
NextMessageHop::NodeId(pubkey) => pubkey,
97+
NextMessageHop::ShortChannelId(scid) => match node_id_lookup.next_node_id(scid) {
10798
Some(pubkey) => pubkey,
10899
None => return Err(()),
109100
},

lightning/src/blinded_path/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ use crate::util::ser::{Readable, Writeable, Writer};
2424
use crate::io;
2525
use crate::prelude::*;
2626

27+
/// The next hop to forward an onion message along its path.
28+
///
29+
/// Note that payment blinded paths always specify their next hop using an explicit node id.
30+
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
31+
pub enum NextMessageHop {
32+
/// The node id of the next hop.
33+
NodeId(PublicKey),
34+
/// The short channel id leading to the next hop.
35+
ShortChannelId(u64),
36+
}
37+
2738
/// Onion messages and payments can be sent and received to blinded paths, which serve to hide the
2839
/// identity of the recipient.
2940
#[derive(Clone, Debug, Hash, PartialEq, Eq)]

lightning/src/blinded_path/payment.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use bitcoin::secp256k1::{self, PublicKey, Secp256k1, SecretKey};
77
use crate::blinded_path::BlindedHop;
88
use crate::blinded_path::utils;
99
use crate::io;
10-
use crate::ln::PaymentSecret;
10+
use crate::ln::types::PaymentSecret;
1111
use crate::ln::channelmanager::CounterpartyForwardingInfo;
1212
use crate::ln::features::BlindedHopFeatures;
1313
use crate::ln::msgs::DecodeError;
@@ -425,7 +425,7 @@ impl_writeable_tlv_based!(Bolt12RefundContext, {});
425425
mod tests {
426426
use bitcoin::secp256k1::PublicKey;
427427
use crate::blinded_path::payment::{ForwardNode, ForwardTlvs, ReceiveTlvs, PaymentConstraints, PaymentContext, PaymentRelay};
428-
use crate::ln::PaymentSecret;
428+
use crate::ln::types::PaymentSecret;
429429
use crate::ln::features::BlindedHopFeatures;
430430
use crate::ln::functional_test_utils::TEST_FINAL_CLTV;
431431

lightning/src/chain/chainmonitor.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use crate::chain::{ChannelMonitorUpdateStatus, Filter, WatchedOutput};
3131
use crate::chain::chaininterface::{BroadcasterInterface, FeeEstimator};
3232
use crate::chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, Balance, MonitorEvent, TransactionOutputs, WithChannelMonitor, LATENCY_GRACE_PERIOD_BLOCKS};
3333
use crate::chain::transaction::{OutPoint, TransactionData};
34-
use crate::ln::ChannelId;
34+
use crate::ln::types::ChannelId;
3535
use crate::sign::ecdsa::WriteableEcdsaChannelSigner;
3636
use crate::events;
3737
use crate::events::{Event, EventHandler};
@@ -296,6 +296,8 @@ pub struct ChainMonitor<ChannelSigner: WriteableEcdsaChannelSigner, C: Deref, T:
296296
/// The best block height seen, used as a proxy for the passage of time.
297297
highest_chain_height: AtomicUsize,
298298

299+
/// A [`Notifier`] used to wake up the background processor in case we have any [`Event`]s for
300+
/// it to give to users (or [`MonitorEvent`]s for `ChannelManager` to process).
299301
event_notifier: Notifier,
300302
}
301303

@@ -738,6 +740,8 @@ where
738740
monitor.block_connected(
739741
header, txdata, height, &*self.broadcaster, &*self.fee_estimator, &self.logger)
740742
});
743+
// Assume we may have some new events and wake the event processor
744+
self.event_notifier.notify();
741745
}
742746

743747
fn block_disconnected(&self, header: &Header, height: u32) {
@@ -765,6 +769,8 @@ where
765769
monitor.transactions_confirmed(
766770
header, txdata, height, &*self.broadcaster, &*self.fee_estimator, &self.logger)
767771
});
772+
// Assume we may have some new events and wake the event processor
773+
self.event_notifier.notify();
768774
}
769775

770776
fn transaction_unconfirmed(&self, txid: &Txid) {
@@ -785,6 +791,8 @@ where
785791
header, height, &*self.broadcaster, &*self.fee_estimator, &self.logger
786792
)
787793
});
794+
// Assume we may have some new events and wake the event processor
795+
self.event_notifier.notify();
788796
}
789797

790798
fn get_relevant_txids(&self) -> Vec<(Txid, u32, Option<BlockHash>)> {

0 commit comments

Comments
 (0)