Skip to content

Commit ef2156a

Browse files
authored
Merge pull request #2798 from TheBlueMatt/2023-12-119-bindings-upstream
Small API cleanups pre-0.0.119
2 parents f5e87d8 + 2aecfa4 commit ef2156a

File tree

9 files changed

+39
-32
lines changed

9 files changed

+39
-32
lines changed

ci/ci-tests.sh

+2
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ if [[ "$HOST_PLATFORM" != *windows* ]]; then
8989
[ "$RUSTC_MINOR_VERSION" -lt 65 ] && cargo update -p reqwest --precise "0.11.20" --verbose
9090
# Starting with version 1.10.0, the `regex` crate has an MSRV of rustc 1.65.0.
9191
[ "$RUSTC_MINOR_VERSION" -lt 65 ] && cargo update -p regex --precise "1.9.6" --verbose
92+
# Starting with version 0.5.9 (there is no .6-.8), the `home` crate has an MSRV of rustc 1.70.0.
93+
[ "$RUSTC_MINOR_VERSION" -lt 70 ] && cargo update -p home --precise "0.5.5" --verbose
9294

9395
DOWNLOAD_ELECTRS_AND_BITCOIND
9496

lightning-invoice/Cargo.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@ rustdoc-args = ["--cfg", "docsrs"]
1717
[features]
1818
default = ["std"]
1919
no-std = ["hashbrown", "lightning/no-std"]
20-
std = ["bitcoin_hashes/std", "num-traits/std", "lightning/std", "bech32/std"]
20+
std = ["bitcoin/std", "num-traits/std", "lightning/std", "bech32/std"]
2121

2222
[dependencies]
2323
bech32 = { version = "0.9.0", default-features = false }
2424
lightning = { version = "0.0.118", path = "../lightning", default-features = false }
2525
secp256k1 = { version = "0.27.0", default-features = false, features = ["recovery", "alloc"] }
2626
num-traits = { version = "0.2.8", default-features = false }
27-
bitcoin_hashes = { version = "0.12.0", default-features = false }
2827
hashbrown = { version = "0.8", optional = true }
2928
serde = { version = "1.0.118", optional = true }
3029
bitcoin = { version = "0.30.2", default-features = false }

lightning-invoice/src/de.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use bech32::{u5, FromBase32};
1111

1212
use bitcoin::{PubkeyHash, ScriptHash};
1313
use bitcoin::address::WitnessVersion;
14-
use bitcoin_hashes::Hash;
15-
use bitcoin_hashes::sha256;
14+
use bitcoin::hashes::Hash;
15+
use bitcoin::hashes::sha256;
1616
use crate::prelude::*;
1717
use lightning::ln::PaymentSecret;
1818
use lightning::routing::gossip::RoutingFees;
@@ -564,14 +564,14 @@ impl FromBase32 for Fallback {
564564
17 => {
565565
let pkh = match PubkeyHash::from_slice(&bytes) {
566566
Ok(pkh) => pkh,
567-
Err(bitcoin_hashes::Error::InvalidLength(_, _)) => return Err(Bolt11ParseError::InvalidPubKeyHashLength),
567+
Err(bitcoin::hashes::Error::InvalidLength(_, _)) => return Err(Bolt11ParseError::InvalidPubKeyHashLength),
568568
};
569569
Ok(Fallback::PubKeyHash(pkh))
570570
}
571571
18 => {
572572
let sh = match ScriptHash::from_slice(&bytes) {
573573
Ok(sh) => sh,
574-
Err(bitcoin_hashes::Error::InvalidLength(_, _)) => return Err(Bolt11ParseError::InvalidScriptHashLength),
574+
Err(bitcoin::hashes::Error::InvalidLength(_, _)) => return Err(Bolt11ParseError::InvalidScriptHashLength),
575575
};
576576
Ok(Fallback::ScriptHash(sh))
577577
}
@@ -726,7 +726,7 @@ mod test {
726726
use crate::de::Bolt11ParseError;
727727
use secp256k1::PublicKey;
728728
use bech32::u5;
729-
use bitcoin_hashes::sha256;
729+
use bitcoin::hashes::sha256;
730730
use std::str::FromStr;
731731

732732
const CHARSET_REV: [i8; 128] = [
@@ -856,7 +856,7 @@ mod test {
856856
use bech32::FromBase32;
857857
use bitcoin::{PubkeyHash, ScriptHash};
858858
use bitcoin::address::WitnessVersion;
859-
use bitcoin_hashes::Hash;
859+
use bitcoin::hashes::Hash;
860860

861861
let cases = vec![
862862
(

lightning-invoice/src/lib.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ pub mod payment;
3030
pub mod utils;
3131

3232
extern crate bech32;
33-
extern crate bitcoin_hashes;
3433
#[macro_use] extern crate lightning;
3534
extern crate num_traits;
3635
extern crate secp256k1;
@@ -46,7 +45,7 @@ use std::time::SystemTime;
4645
use bech32::u5;
4746
use bitcoin::{Address, Network, PubkeyHash, ScriptHash};
4847
use bitcoin::address::{Payload, WitnessProgram, WitnessVersion};
49-
use bitcoin_hashes::{Hash, sha256};
48+
use bitcoin::hashes::{Hash, sha256};
5049
use lightning::ln::features::Bolt11InvoiceFeatures;
5150
use lightning::util::invoice::construct_invoice_preimage;
5251

@@ -166,10 +165,10 @@ pub const DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA: u64 = 18;
166165
/// extern crate secp256k1;
167166
/// extern crate lightning;
168167
/// extern crate lightning_invoice;
169-
/// extern crate bitcoin_hashes;
168+
/// extern crate bitcoin;
170169
///
171-
/// use bitcoin_hashes::Hash;
172-
/// use bitcoin_hashes::sha256;
170+
/// use bitcoin::hashes::Hash;
171+
/// use bitcoin::hashes::sha256;
173172
///
174173
/// use secp256k1::Secp256k1;
175174
/// use secp256k1::SecretKey;
@@ -527,7 +526,7 @@ impl Ord for Bolt11InvoiceSignature {
527526
/// The encoded route has to be <1024 5bit characters long (<=639 bytes or <=12 hops)
528527
///
529528
#[derive(Clone, Debug, Hash, Eq, PartialEq, Ord, PartialOrd)]
530-
pub struct PrivateRoute(pub RouteHint);
529+
pub struct PrivateRoute(RouteHint);
531530

532531
/// Tag constants as specified in BOLT11
533532
#[allow(missing_docs)]
@@ -1756,7 +1755,7 @@ impl<'de> Deserialize<'de> for Bolt11Invoice {
17561755
#[cfg(test)]
17571756
mod test {
17581757
use bitcoin::ScriptBuf;
1759-
use bitcoin_hashes::sha256;
1758+
use bitcoin::hashes::sha256;
17601759
use std::str::FromStr;
17611760

17621761
#[test]

lightning-invoice/src/payment.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//! Convenient utilities for paying Lightning invoices.
1111
1212
use crate::Bolt11Invoice;
13-
use crate::bitcoin_hashes::Hash;
13+
use bitcoin::hashes::Hash;
1414

1515
use lightning::ln::PaymentHash;
1616
use lightning::ln::channelmanager::RecipientOnionFields;
@@ -84,7 +84,7 @@ fn params_from_invoice(invoice: &Bolt11Invoice, amount_msat: u64)
8484
mod tests {
8585
use super::*;
8686
use crate::{InvoiceBuilder, Currency};
87-
use bitcoin_hashes::sha256::Hash as Sha256;
87+
use bitcoin::hashes::sha256::Hash as Sha256;
8888
use lightning::events::Event;
8989
use lightning::ln::channelmanager::{Retry, PaymentId};
9090
use lightning::ln::msgs::ChannelMessageHandler;

lightning-invoice/src/utils.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{Bolt11Invoice, CreationError, Currency, InvoiceBuilder, SignOrCreati
44

55
use crate::{prelude::*, Description, Bolt11InvoiceDescription, Sha256};
66
use bech32::ToBase32;
7-
use bitcoin_hashes::Hash;
7+
use bitcoin::hashes::Hash;
88
use lightning::chain;
99
use lightning::chain::chaininterface::{BroadcasterInterface, FeeEstimator};
1010
use lightning::sign::{Recipient, NodeSigner, SignerProvider, EntropySource};
@@ -819,8 +819,8 @@ mod test {
819819
use core::cell::RefCell;
820820
use core::time::Duration;
821821
use crate::{Currency, Description, Bolt11InvoiceDescription, SignOrCreationError, CreationError};
822-
use bitcoin_hashes::{Hash, sha256};
823-
use bitcoin_hashes::sha256::Hash as Sha256;
822+
use bitcoin::hashes::{Hash, sha256};
823+
use bitcoin::hashes::sha256::Hash as Sha256;
824824
use lightning::sign::PhantomKeysManager;
825825
use lightning::events::{MessageSendEvent, MessageSendEventsProvider, Event, EventsProvider};
826826
use lightning::ln::{PaymentPreimage, PaymentHash};

lightning-invoice/tests/ser_de.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
extern crate bech32;
2-
extern crate bitcoin_hashes;
32
extern crate lightning;
43
extern crate lightning_invoice;
54
extern crate secp256k1;
@@ -8,7 +7,7 @@ extern crate hex;
87
use bitcoin::address::WitnessVersion;
98
use bitcoin::{PubkeyHash, ScriptHash};
109
use bitcoin::hashes::hex::FromHex;
11-
use bitcoin_hashes::{sha256, Hash};
10+
use bitcoin::hashes::{sha256, Hash};
1211
use lightning::ln::PaymentSecret;
1312
use lightning::routing::gossip::RoutingFees;
1413
use lightning::routing::router::{RouteHint, RouteHintHop};

lightning/src/ln/msgs.rs

+16-8
Original file line numberDiff line numberDiff line change
@@ -1668,23 +1668,31 @@ pub trait OnionMessageHandler: EventsProvider {
16681668
fn provided_init_features(&self, their_node_id: &PublicKey) -> InitFeatures;
16691669
}
16701670

1671+
#[derive(Clone)]
1672+
#[cfg_attr(test, derive(Debug, PartialEq))]
1673+
/// Information communicated in the onion to the recipient for multi-part tracking and proof that
1674+
/// the payment is associated with an invoice.
1675+
pub struct FinalOnionHopData {
1676+
/// When sending a multi-part payment, this secret is used to identify a payment across HTLCs.
1677+
/// Because it is generated by the recipient and included in the invoice, it also provides
1678+
/// proof to the recipient that the payment was sent by someone with the generated invoice.
1679+
pub payment_secret: PaymentSecret,
1680+
/// The intended total amount that this payment is for.
1681+
///
1682+
/// Message serialization may panic if this value is more than 21 million Bitcoin.
1683+
pub total_msat: u64,
1684+
}
1685+
16711686
mod fuzzy_internal_msgs {
16721687
use bitcoin::secp256k1::PublicKey;
16731688
use crate::blinded_path::payment::{PaymentConstraints, PaymentRelay};
16741689
use crate::prelude::*;
16751690
use crate::ln::{PaymentPreimage, PaymentSecret};
16761691
use crate::ln::features::BlindedHopFeatures;
1692+
use super::FinalOnionHopData;
16771693

16781694
// These types aren't intended to be pub, but are exposed for direct fuzzing (as we deserialize
16791695
// them from untrusted input):
1680-
#[derive(Clone)]
1681-
#[cfg_attr(test, derive(Debug, PartialEq))]
1682-
pub struct FinalOnionHopData {
1683-
pub payment_secret: PaymentSecret,
1684-
/// The total value, in msat, of the payment as received by the ultimate recipient.
1685-
/// Message serialization may panic if this value is more than 21 million Bitcoin.
1686-
pub total_msat: u64,
1687-
}
16881696

16891697
pub enum InboundOnionPayload {
16901698
Forward {

lightning/src/routing/router.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl<G: Deref<Target = NetworkGraph<L>> + Clone, L: Deref, S: Deref, SP: Sized,
102102
.filter(|details| details.counterparty.features.supports_route_blinding())
103103
.filter(|details| amount_msats <= details.inbound_capacity_msat)
104104
.filter(|details| amount_msats >= details.inbound_htlc_minimum_msat.unwrap_or(0))
105-
.filter(|details| amount_msats <= details.inbound_htlc_maximum_msat.unwrap_or(0))
105+
.filter(|details| amount_msats <= details.inbound_htlc_maximum_msat.unwrap_or(u64::MAX))
106106
.filter(|details| network_graph
107107
.node(&NodeId::from_pubkey(&details.counterparty.node_id))
108108
.map(|node_info| node_info.channels.len() >= MIN_PEER_CHANNELS)
@@ -139,7 +139,7 @@ impl<G: Deref<Target = NetworkGraph<L>> + Clone, L: Deref, S: Deref, SP: Sized,
139139
features: BlindedHopFeatures::empty(),
140140
},
141141
node_id: details.counterparty.node_id,
142-
htlc_maximum_msat: details.inbound_htlc_maximum_msat.unwrap_or(0),
142+
htlc_maximum_msat: details.inbound_htlc_maximum_msat.unwrap_or(u64::MAX),
143143
})
144144
})
145145
.map(|forward_node| {

0 commit comments

Comments
 (0)