Skip to content

Swap the dep order between lightning and lightning-invoice #3234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ resolver = "2"

members = [
"lightning",
"lightning-types",
"lightning-block-sync",
"lightning-invoice",
"lightning-net-tokio",
Expand Down
7 changes: 4 additions & 3 deletions fuzz/src/chanmon_consistency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ use lightning::ln::msgs::{
self, ChannelMessageHandler, CommitmentUpdate, DecodeError, Init, UpdateAddHTLC,
};
use lightning::ln::script::ShutdownScript;
use lightning::ln::{ChannelId, PaymentHash, PaymentPreimage, PaymentSecret};
use lightning::ln::types::{ChannelId, PaymentHash, PaymentPreimage, PaymentSecret};
use lightning::offers::invoice::{BlindedPayInfo, UnsignedBolt12Invoice};
use lightning::offers::invoice_request::UnsignedInvoiceRequest;
use lightning::onion_message::messenger::{Destination, MessageRouter, OnionMessagePath};
Expand All @@ -71,6 +71,8 @@ use lightning::util::logger::Logger;
use lightning::util::ser::{Readable, ReadableArgs, Writeable, Writer};
use lightning::util::test_channel_signer::{EnforcementState, TestChannelSigner};

use lightning_invoice::RawBolt11Invoice;

use crate::utils::test_logger::{self, Output};
use crate::utils::test_persister::TestPersister;

Expand All @@ -79,7 +81,6 @@ use bitcoin::secp256k1::ecdsa::{RecoverableSignature, Signature};
use bitcoin::secp256k1::schnorr;
use bitcoin::secp256k1::{self, Message, PublicKey, Scalar, Secp256k1, SecretKey};

use bech32::u5;
use std::cmp::{self, Ordering};
use std::io::Cursor;
use std::mem;
Expand Down Expand Up @@ -332,7 +333,7 @@ impl NodeSigner for KeyProvider {
}

fn sign_invoice(
&self, _hrp_bytes: &[u8], _invoice_data: &[u5], _recipient: Recipient,
&self, _invoice: &RawBolt11Invoice, _recipient: Recipient,
) -> Result<RecoverableSignature, ()> {
unreachable!()
}
Expand Down
7 changes: 4 additions & 3 deletions fuzz/src/full_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ use lightning::ln::peer_handler::{
IgnoringMessageHandler, MessageHandler, PeerManager, SocketDescriptor,
};
use lightning::ln::script::ShutdownScript;
use lightning::ln::{ChannelId, PaymentHash, PaymentPreimage, PaymentSecret};
use lightning::ln::types::{ChannelId, PaymentHash, PaymentPreimage, PaymentSecret};
use lightning::offers::invoice::{BlindedPayInfo, UnsignedBolt12Invoice};
use lightning::offers::invoice_request::UnsignedInvoiceRequest;
use lightning::onion_message::messenger::{Destination, MessageRouter, OnionMessagePath};
Expand All @@ -68,6 +68,8 @@ use lightning::util::logger::Logger;
use lightning::util::ser::{Readable, ReadableArgs, Writeable};
use lightning::util::test_channel_signer::{EnforcementState, TestChannelSigner};

use lightning_invoice::RawBolt11Invoice;

use crate::utils::test_logger;
use crate::utils::test_persister::TestPersister;

Expand All @@ -76,7 +78,6 @@ use bitcoin::secp256k1::ecdsa::{RecoverableSignature, Signature};
use bitcoin::secp256k1::schnorr;
use bitcoin::secp256k1::{self, Message, PublicKey, Scalar, Secp256k1, SecretKey};

use bech32::u5;
use std::cell::RefCell;
use std::cmp;
use std::convert::TryInto;
Expand Down Expand Up @@ -406,7 +407,7 @@ impl NodeSigner for KeyProvider {
}

fn sign_invoice(
&self, _hrp_bytes: &[u8], _invoice_data: &[u5], _recipient: Recipient,
&self, _invoice: &RawBolt11Invoice, _recipient: Recipient,
) -> Result<RecoverableSignature, ()> {
unreachable!()
}
Expand Down
5 changes: 3 additions & 2 deletions fuzz/src/onion_message.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Imports that need to be added manually
use bech32::u5;
use bitcoin::script::ScriptBuf;
use bitcoin::secp256k1::ecdh::SharedSecret;
use bitcoin::secp256k1::ecdsa::RecoverableSignature;
Expand Down Expand Up @@ -27,6 +26,8 @@ use lightning::util::logger::Logger;
use lightning::util::ser::{Readable, Writeable, Writer};
use lightning::util::test_channel_signer::TestChannelSigner;

use lightning_invoice::RawBolt11Invoice;

use crate::utils::test_logger;

use std::io::{self, Cursor};
Expand Down Expand Up @@ -225,7 +226,7 @@ impl NodeSigner for KeyProvider {
}

fn sign_invoice(
&self, _hrp_bytes: &[u8], _invoice_data: &[u5], _recipient: Recipient,
&self, _invoice: &RawBolt11Invoice, _recipient: Recipient,
) -> Result<RecoverableSignature, ()> {
unreachable!()
}
Expand Down
2 changes: 1 addition & 1 deletion fuzz/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use lightning::ln::channel_state::{ChannelCounterparty, ChannelDetails, ChannelS
use lightning::ln::channelmanager;
use lightning::ln::features::{BlindedHopFeatures, Bolt12InvoiceFeatures};
use lightning::ln::msgs;
use lightning::ln::ChannelId;
use lightning::ln::types::ChannelId;
use lightning::offers::invoice::BlindedPayInfo;
use lightning::routing::gossip::{NetworkGraph, RoutingFees};
use lightning::routing::router::{
Expand Down
7 changes: 3 additions & 4 deletions lightning-invoice/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,17 @@ rustdoc-args = ["--cfg", "docsrs"]

[features]
default = ["std"]
no-std = ["lightning/no-std"]
std = ["bitcoin/std", "lightning/std", "bech32/std"]
no-std = ["bitcoin/no-std"]
std = ["bitcoin/std", "bech32/std"]

[dependencies]
bech32 = { version = "0.9.1", default-features = false }
lightning = { version = "0.0.123-beta", path = "../lightning", default-features = false }
lightning-types = { version = "0.1", path = "../lightning-types", default-features = false }
secp256k1 = { version = "0.28.0", default-features = false, features = ["recovery", "alloc"] }
serde = { version = "1.0.118", optional = true }
bitcoin = { version = "0.31.2", default-features = false }

[dev-dependencies]
lightning = { version = "0.0.123-beta", path = "../lightning", default-features = false, features = ["_test_utils"] }
serde_json = { version = "1"}
hashbrown = { version = "0.13", default-features = false }

Expand Down
10 changes: 4 additions & 6 deletions lightning-invoice/src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ use bitcoin::{PubkeyHash, ScriptHash, WitnessVersion};
use bitcoin::hashes::Hash;
use bitcoin::hashes::sha256;
use crate::prelude::*;
use lightning::ln::types::PaymentSecret;
use lightning::routing::gossip::RoutingFees;
use lightning::routing::router::{RouteHint, RouteHintHop};
use lightning_types::payment::PaymentSecret;
use lightning_types::routing::{RoutingFees, RouteHint, RouteHintHop};

use secp256k1::ecdsa::{RecoveryId, RecoverableSignature};
use secp256k1::PublicKey;
Expand Down Expand Up @@ -918,8 +917,7 @@ mod test {

#[test]
fn test_parse_route() {
use lightning::routing::gossip::RoutingFees;
use lightning::routing::router::{RouteHint, RouteHintHop};
use lightning_types::routing::{RoutingFees, RouteHint, RouteHintHop};
use crate::PrivateRoute;
use bech32::FromBase32;

Expand Down Expand Up @@ -974,7 +972,7 @@ mod test {

#[test]
fn test_payment_secret_and_features_de_and_ser() {
use lightning::ln::features::Bolt11InvoiceFeatures;
use lightning_types::features::Bolt11InvoiceFeatures;
use secp256k1::ecdsa::{RecoveryId, RecoverableSignature};
use crate::TaggedField::*;
use crate::{SiPrefix, SignedRawBolt11Invoice, Bolt11InvoiceSignature, RawBolt11Invoice, RawHrp, RawDataPart,
Expand Down
62 changes: 33 additions & 29 deletions lightning-invoice/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@
#[cfg(not(any(feature = "std", feature = "no-std")))]
compile_error!("at least one of the `std` or `no-std` features must be enabled");

pub mod payment;
pub mod utils;

extern crate bech32;
#[macro_use] extern crate lightning;
extern crate lightning_types;
extern crate secp256k1;
extern crate alloc;
#[cfg(any(test, feature = "std"))]
Expand All @@ -40,12 +37,11 @@ extern crate serde;
#[cfg(feature = "std")]
use std::time::SystemTime;

use bech32::u5;
use bech32::{FromBase32, u5};
use bitcoin::{Address, Network, PubkeyHash, ScriptHash, WitnessProgram, WitnessVersion};
use bitcoin::address::Payload;
use bitcoin::hashes::{Hash, sha256};
use lightning::ln::features::Bolt11InvoiceFeatures;
use lightning::util::invoice::construct_invoice_preimage;
use lightning_types::features::Bolt11InvoiceFeatures;

use secp256k1::PublicKey;
use secp256k1::{Message, Secp256k1};
Expand All @@ -64,12 +60,10 @@ use core::str;
use serde::{Deserialize, Deserializer,Serialize, Serializer, de::Error};

#[doc(no_inline)]
pub use lightning::ln::types::PaymentSecret;
#[doc(no_inline)]
pub use lightning::routing::router::{RouteHint, RouteHintHop};
pub use lightning_types::payment::PaymentSecret;
#[doc(no_inline)]
pub use lightning::routing::gossip::RoutingFees;
use lightning::util::string::UntrustedString;
pub use lightning_types::routing::{RoutingFees, RouteHint, RouteHintHop};
use lightning_types::string::UntrustedString;

mod de;
mod ser;
Expand Down Expand Up @@ -139,19 +133,16 @@ pub const DEFAULT_EXPIRY_TIME: u64 = 3600;

/// Default minimum final CLTV expiry as defined by [BOLT 11].
///
/// Note that this is *not* the same value as rust-lightning's minimum CLTV expiry, which is
/// provided in [`MIN_FINAL_CLTV_EXPIRY_DELTA`].
/// Note that this is *not* the same value as rust-lightning's minimum CLTV expiry.
///
/// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
/// [`MIN_FINAL_CLTV_EXPIRY_DELTA`]: lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY_DELTA
pub const DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA: u64 = 18;

/// Builder for [`Bolt11Invoice`]s. It's the most convenient and advised way to use this library. It
/// ensures that only a semantically and syntactically correct invoice can be built using it.
///
/// ```
/// extern crate secp256k1;
/// extern crate lightning;
/// extern crate lightning_invoice;
/// extern crate bitcoin;
///
Expand All @@ -161,7 +152,7 @@ pub const DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA: u64 = 18;
/// use secp256k1::Secp256k1;
/// use secp256k1::SecretKey;
///
/// use lightning::ln::types::PaymentSecret;
/// use lightning_types::payment::PaymentSecret;
///
/// use lightning_invoice::{Currency, InvoiceBuilder};
///
Expand Down Expand Up @@ -970,7 +961,23 @@ macro_rules! find_all_extract {
impl RawBolt11Invoice {
/// Hash the HRP as bytes and signatureless data part.
fn hash_from_parts(hrp_bytes: &[u8], data_without_signature: &[u5]) -> [u8; 32] {
let preimage = construct_invoice_preimage(hrp_bytes, data_without_signature);
let mut preimage = Vec::<u8>::from(hrp_bytes);

let mut data_part = Vec::from(data_without_signature);
let overhang = (data_part.len() * 5) % 8;
if overhang > 0 {
// add padding if data does not end at a byte boundary
data_part.push(u5::try_from_u8(0).unwrap());

// if overhang is in (1..3) we need to add u5(0) padding two times
if overhang < 3 {
data_part.push(u5::try_from_u8(0).unwrap());
}
}

preimage.extend_from_slice(&Vec::<u8>::from_base32(&data_part)
.expect("No padding error may occur due to appended zero above."));

let mut hash: [u8; 32] = Default::default();
hash.copy_from_slice(&sha256::Hash::hash(&preimage)[..]);
hash
Expand Down Expand Up @@ -1636,15 +1643,12 @@ pub enum CreationError {
/// The supplied millisatoshi amount was greater than the total bitcoin supply.
InvalidAmount,

/// Route hints were required for this invoice and were missing. Applies to
/// [phantom invoices].
///
/// [phantom invoices]: crate::utils::create_phantom_invoice
// TODO: These two errors are really errors with things in the `lightning` crate and thus
// shouldn't live here.
/// Route hints were required for this invoice and were missing.
MissingRouteHints,

/// The provided `min_final_cltv_expiry_delta` was less than [`MIN_FINAL_CLTV_EXPIRY_DELTA`].
///
/// [`MIN_FINAL_CLTV_EXPIRY_DELTA`]: lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY_DELTA
/// The provided `min_final_cltv_expiry_delta` was less than rust-lightning's minimum.
MinFinalCltvExpiryDeltaTooShort,
}

Expand Down Expand Up @@ -1877,14 +1881,14 @@ mod test {
#[test]
fn test_check_feature_bits() {
use crate::TaggedField::*;
use lightning::ln::features::Bolt11InvoiceFeatures;
use lightning_types::features::Bolt11InvoiceFeatures;
use secp256k1::Secp256k1;
use secp256k1::SecretKey;
use crate::{Bolt11Invoice, RawBolt11Invoice, RawHrp, RawDataPart, Currency, Sha256, PositiveTimestamp,
Bolt11SemanticError};

let private_key = SecretKey::from_slice(&[42; 32]).unwrap();
let payment_secret = lightning::ln::types::PaymentSecret([21; 32]);
let payment_secret = lightning_types::payment::PaymentSecret([21; 32]);
let invoice_template = RawBolt11Invoice {
hrp: RawHrp {
currency: Currency::Bitcoin,
Expand Down Expand Up @@ -1998,7 +2002,7 @@ mod test {
#[test]
fn test_builder_fail() {
use crate::*;
use lightning::routing::router::RouteHintHop;
use lightning_types::routing::RouteHintHop;
use std::iter::FromIterator;
use secp256k1::PublicKey;

Expand Down Expand Up @@ -2052,7 +2056,7 @@ mod test {
#[test]
fn test_builder_ok() {
use crate::*;
use lightning::routing::router::RouteHintHop;
use lightning_types::routing::RouteHintHop;
use secp256k1::Secp256k1;
use secp256k1::{SecretKey, PublicKey};
use std::time::Duration;
Expand Down
1 change: 0 additions & 1 deletion lightning-invoice/tests/ser_de.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
extern crate bech32;
extern crate lightning;
extern crate lightning_invoice;
extern crate secp256k1;

Expand Down
25 changes: 25 additions & 0 deletions lightning-types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[package]
name = "lightning-types"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading the PR description I was expecting a name like lightning-common, but types is fine too I guess

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*-common seems a bit vague as it might imply actual "core" lightning functionality. I've seen the suffix be used a bit loosely to not only refer to types. *-types seems more appropriate IMO :)

Copy link
Collaborator Author

@TheBlueMatt TheBlueMatt Aug 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its also not really intended to be used by downstream crates, so I'm not sure it matters that much :)

version = "0.1.0"
authors = ["Matt Corallo"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/lightningdevkit/rust-lightning/"
description = """
Basic types which are used in the lightning network
"""
edition = "2021"

[package.metadata.docs.rs]
rustdoc-args = ["--cfg", "docsrs"]

[features]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When building lightning-types by itself, I found that the std/no-std features are missing:

Suggested change
[features]
[features]
default = ["std"]
no-std = ["bitcoin/no-std"]
std = ["bitcoin/std", "bech32/std"]

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be resolved when we upgrade to rust-bitcoin 32 in the same release.

_test_utils = []

[dependencies]
bitcoin = { version = "0.31", default-features = false }
# TODO: Once we switch to bitcoin 0.32 drop this explicit dep:
hex-conservative = { version = "0.2", default-features = false }
bech32 = { version = "0.9", default-features = false }

[lints]
workspace = true
Loading
Loading