Skip to content

[0.0.124-bindings] Bindings-specific changes for 0.0.124 #3286

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
Show all changes
22 commits
Select commit Hold shift + click to select a range
12411d1
Specify imports manually in `types::features::sealed`
TheBlueMatt Sep 1, 2024
492b9c2
Make `as_directed_to` non-public
TheBlueMatt Mar 1, 2022
d5ef568
Restrict ChannelInfo::as_directed_from visibility
jkczyz Mar 29, 2022
0f1e819
Use an explicit `Sign` type on the `ChannelMonitor` read tuple
TheBlueMatt Dec 24, 2022
212e4a5
Export `outbound_payment` structs in their respective modules
TheBlueMatt Aug 22, 2024
4ae9bcf
Avoid enums containing references with lifetimes
TheBlueMatt Mar 5, 2023
0b978a1
Mark a few offers fields no-export as we have no mapping for them
TheBlueMatt May 11, 2024
ec446c9
Use `[u8; 3]` not `CurrencyCode` to skip type aliases to primitives
TheBlueMatt May 11, 2024
d8ec887
Hard-code scorer parameters to `ProbabilisticScoringFeeParameters`
TheBlueMatt Oct 21, 2023
f24cef0
Mark several types no-export which should be exported eventually
TheBlueMatt Jul 19, 2023
c029a65
`crate`-only several BOLT12 methods that require unbounded generics
TheBlueMatt Sep 28, 2023
67fb2f4
Make ChannelMonitor always clonable
TheBlueMatt Feb 1, 2021
e9b7acb
Make the custom message traits cloneable as they're deep in nested st…
TheBlueMatt Sep 24, 2021
c6cfe88
Avoid slices without inner references
TheBlueMatt Sep 28, 2023
6c8e19a
Avoid options holding references in the public API
TheBlueMatt Aug 17, 2024
8f6819d
Hide `Direction::select_node_id` due to lifetimes
TheBlueMatt May 11, 2024
fa674ef
Drop `SerialId` type as bindings don't support primitive aliasing
TheBlueMatt May 11, 2024
9301a0d
Minimal updates to `lightning-transaction-sync` for bindings
TheBlueMatt Jun 5, 2024
3ffb48d
Require an OM in BP as this should generally be true and its easier t…
TheBlueMatt Aug 20, 2024
020b479
Avoid returning references in `NodeAnnouncementInfo` accessors
TheBlueMatt Aug 24, 2024
03d4eb5
Use `[u8; 32]` rather than `Hmac<Sha256>` for simplicity
TheBlueMatt Aug 26, 2024
31b6b71
Use inline bounds for secp contexts, rather than `where` clauses
TheBlueMatt Aug 26, 2024
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
4 changes: 2 additions & 2 deletions fuzz/src/chanmon_consistency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ use lightning::events::MessageSendEventsProvider;
use lightning::ln::channel::FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE;
use lightning::ln::channel_state::ChannelDetails;
use lightning::ln::channelmanager::{
ChainParameters, ChannelManager, ChannelManagerReadArgs, PaymentId, PaymentSendFailure,
RecipientOnionFields,
ChainParameters, ChannelManager, ChannelManagerReadArgs, PaymentId,
};
use lightning::ln::outbound_payment::{RecipientOnionFields, PaymentSendFailure};
use lightning::ln::functional_test_utils::*;
use lightning::ln::msgs::{
self, ChannelMessageHandler, CommitmentUpdate, DecodeError, Init, UpdateAddHTLC,
Expand Down
3 changes: 2 additions & 1 deletion fuzz/src/full_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ use lightning::chain::{BestBlock, ChannelMonitorUpdateStatus, Confirm, Listen};
use lightning::events::Event;
use lightning::ln::channel_state::ChannelDetails;
use lightning::ln::channelmanager::{
ChainParameters, ChannelManager, InterceptId, PaymentId, RecipientOnionFields, Retry,
ChainParameters, ChannelManager, InterceptId, PaymentId,
};
use lightning::ln::outbound_payment::{RecipientOnionFields, Retry};
use lightning::ln::functional_test_utils::*;
use lightning::ln::msgs::{self, DecodeError};
use lightning::ln::peer_handler::{
Expand Down
27 changes: 9 additions & 18 deletions lightning-background-processor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ impl BackgroundProcessor {
SC: for<'b> WriteableScore<'b>,
>(
persister: PS, event_handler: EH, chain_monitor: M, channel_manager: CM,
onion_messenger: Option<OM>, gossip_sync: GossipSync<PGS, RGS, G, UL, L>, peer_manager: PM,
onion_messenger: OM, gossip_sync: GossipSync<PGS, RGS, G, UL, L>, peer_manager: PM,
logger: L, scorer: Option<S>,
) -> Self
where
Expand Down Expand Up @@ -962,34 +962,27 @@ impl BackgroundProcessor {
}
event_handler.handle_event(event)
};
let om_opt = Some(&*onion_messenger);
define_run_body!(
persister,
chain_monitor,
chain_monitor.process_pending_events(&event_handler),
channel_manager,
channel_manager.get_cm().process_pending_events(&event_handler),
onion_messenger,
if let Some(om) = &onion_messenger {
om.get_om().process_pending_events(&event_handler)
},
om_opt,
onion_messenger.get_om().process_pending_events(&event_handler),
peer_manager,
gossip_sync,
logger,
scorer,
stop_thread.load(Ordering::Acquire),
{
let sleeper = if let Some(om) = onion_messenger.as_ref() {
let sleeper =
Sleeper::from_three_futures(
&channel_manager.get_cm().get_event_or_persistence_needed_future(),
&chain_monitor.get_update_future(),
&om.get_om().get_update_future(),
)
} else {
Sleeper::from_two_futures(
&channel_manager.get_cm().get_event_or_persistence_needed_future(),
&chain_monitor.get_update_future(),
)
};
&onion_messenger.get_om().get_update_future(),
);
sleeper.wait_timeout(Duration::from_millis(100));
},
|_| Instant::now(),
Expand Down Expand Up @@ -1141,8 +1134,6 @@ mod tests {
Arc<test_utils::TestLogger>,
Arc<KeysManager>,
Arc<LockingWrapper<TestScorer>>,
(),
TestScorer,
>,
>,
Arc<test_utils::TestLogger>,
Expand Down Expand Up @@ -1404,10 +1395,10 @@ mod tests {
}

impl ScoreLookUp for TestScorer {
#[cfg(not(c_bindings))]
type ScoreParams = ();
fn channel_penalty_msat(
&self, _candidate: &CandidateRouteHop, _usage: ChannelUsage,
_score_params: &Self::ScoreParams,
&self, _candidate: &CandidateRouteHop, _usage: ChannelUsage, _score_params: &lightning::routing::scoring::ProbabilisticScoringFeeParameters
) -> u64 {
unimplemented!();
}
Expand Down
2 changes: 2 additions & 0 deletions lightning-transaction-sync/src/electrum.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Chain sync using the electrum protocol
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like these files are missing the license

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Right, we should address that upstream.


use crate::common::{ConfirmedTx, FilterQueue, SyncState};
use crate::error::{InternalError, TxSyncError};

Expand Down
2 changes: 2 additions & 0 deletions lightning-transaction-sync/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Common error types

use std::fmt;

#[derive(Debug)]
Expand Down
2 changes: 2 additions & 0 deletions lightning-transaction-sync/src/esplora.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Chain sync using the Esplora API

use crate::common::{ConfirmedTx, FilterQueue, SyncState};
use crate::error::{InternalError, TxSyncError};

Expand Down
6 changes: 3 additions & 3 deletions lightning-transaction-sync/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@
extern crate bdk_macros;

#[cfg(any(feature = "esplora-blocking", feature = "esplora-async"))]
mod esplora;
pub mod esplora;

#[cfg(any(feature = "electrum"))]
mod electrum;
pub mod electrum;

#[cfg(any(feature = "esplora-blocking", feature = "esplora-async", feature = "electrum"))]
mod common;
#[cfg(any(feature = "esplora-blocking", feature = "esplora-async", feature = "electrum"))]
mod error;
pub mod error;
#[cfg(any(feature = "esplora-blocking", feature = "esplora-async", feature = "electrum"))]
pub use error::TxSyncError;

Expand Down
6 changes: 5 additions & 1 deletion lightning-types/src/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ use alloc::vec::Vec;
use bech32::{u5, Base32Len, FromBase32, ToBase32, WriteBase32};

mod sealed {
use super::*;
use super::Features;

use alloc::vec::Vec;

/// The context in which [`Features`] are applicable. Defines which features are known to the
/// implementation, though specification of them as required or optional is up to the code
Expand Down Expand Up @@ -600,6 +602,7 @@ pub struct Features<T: sealed::Context> {
mark: PhantomData<T>,
}

/// This is not exported to bindings users but probably should be.
impl<T: sealed::Context, Rhs: Borrow<Self>> core::ops::BitOrAssign<Rhs> for Features<T> {
fn bitor_assign(&mut self, rhs: Rhs) {
let total_feature_len = cmp::max(self.flags.len(), rhs.borrow().flags.len());
Expand All @@ -610,6 +613,7 @@ impl<T: sealed::Context, Rhs: Borrow<Self>> core::ops::BitOrAssign<Rhs> for Feat
}
}

/// This is not exported to bindings users but probably should be.
impl<T: sealed::Context> core::ops::BitOr for Features<T> {
type Output = Self;

Expand Down
5 changes: 2 additions & 3 deletions lightning/src/blinded_path/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,12 @@ impl BlindedMessagePath {
/// introduction node.
///
/// Will only modify `self` when returning `Ok`.
pub fn advance_path_by_one<NS: Deref, NL: Deref, T>(
pub fn advance_path_by_one<NS: Deref, NL: Deref, T: secp256k1::Signing + secp256k1::Verification>(
&mut self, node_signer: &NS, node_id_lookup: &NL, secp_ctx: &Secp256k1<T>
) -> Result<(), ()>
where
NS::Target: NodeSigner,
NL::Target: NodeIdLookUp,
T: secp256k1::Signing + secp256k1::Verification,
{
let control_tlvs_ss = node_signer.ecdh(Recipient::Node, &self.0.blinding_point, None)?;
let rho = onion_utils::gen_rho_from_shared_secret(&control_tlvs_ss.secret_bytes());
Expand Down Expand Up @@ -334,7 +333,7 @@ pub enum OffersContext {
/// used with an [`InvoiceError`].
///
/// [`InvoiceError`]: crate::offers::invoice_error::InvoiceError
hmac: Option<Hmac<Sha256>>,
hmac: Option<[u8; 32]>,
},
/// Context used by a [`BlindedMessagePath`] as a reply path for a [`Bolt12Invoice`].
///
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/blinded_path/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,15 @@ impl_writeable!(BlindedHop, {

impl Direction {
/// Returns the [`NodeId`] from the inputs corresponding to the direction.
pub fn select_node_id(&self, node_a: NodeId, node_b: NodeId) -> NodeId {
pub(crate) fn select_node_id(&self, node_a: NodeId, node_b: NodeId) -> NodeId {
match self {
Direction::NodeOne => core::cmp::min(node_a, node_b),
Direction::NodeTwo => core::cmp::max(node_a, node_b),
}
}

/// Returns the [`PublicKey`] from the inputs corresponding to the direction.
pub fn select_pubkey<'a>(&self, node_a: &'a PublicKey, node_b: &'a PublicKey) -> &'a PublicKey {
pub(crate) fn select_pubkey<'a>(&self, node_a: &'a PublicKey, node_b: &'a PublicKey) -> &'a PublicKey {
let (node_one, node_two) = if NodeId::from_pubkey(node_a) < NodeId::from_pubkey(node_b) {
(node_a, node_b)
} else {
Expand Down
11 changes: 5 additions & 6 deletions lightning/src/blinded_path/payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl BlindedPaymentPath {
// be in relation to a specific channel.
let htlc_maximum_msat = u64::max_value();
Self::new(
&[], payee_node_id, payee_tlvs, htlc_maximum_msat, min_final_cltv_expiry_delta,
Vec::new(), payee_node_id, payee_tlvs, htlc_maximum_msat, min_final_cltv_expiry_delta,
entropy_source, secp_ctx
)
}
Expand All @@ -103,7 +103,7 @@ impl BlindedPaymentPath {
/// * any unknown features are required in the provided [`ForwardTlvs`]
// TODO: make all payloads the same size with padding + add dummy hops
pub fn new<ES: Deref, T: secp256k1::Signing + secp256k1::Verification>(
intermediate_nodes: &[PaymentForwardNode], payee_node_id: PublicKey,
intermediate_nodes: Vec<PaymentForwardNode>, payee_node_id: PublicKey,
payee_tlvs: ReceiveTlvs, htlc_maximum_msat: u64, min_final_cltv_expiry_delta: u16,
entropy_source: ES, secp_ctx: &Secp256k1<T>,
) -> Result<Self, ()> where ES::Target: EntropySource {
Expand All @@ -114,14 +114,14 @@ impl BlindedPaymentPath {
let blinding_secret = SecretKey::from_slice(&blinding_secret_bytes[..]).expect("RNG is busted");

let blinded_payinfo = compute_payinfo(
intermediate_nodes, &payee_tlvs, htlc_maximum_msat, min_final_cltv_expiry_delta
&intermediate_nodes, &payee_tlvs, htlc_maximum_msat, min_final_cltv_expiry_delta
)?;
Ok(Self {
inner_path: BlindedPath {
introduction_node,
blinding_point: PublicKey::from_secret_key(secp_ctx, &blinding_secret),
blinded_hops: blinded_hops(
secp_ctx, intermediate_nodes, payee_node_id, payee_tlvs, &blinding_secret
secp_ctx, &intermediate_nodes, payee_node_id, payee_tlvs, &blinding_secret
).map_err(|_| ())?,
},
payinfo: blinded_payinfo
Expand Down Expand Up @@ -157,13 +157,12 @@ impl BlindedPaymentPath {
/// introduction node.
///
/// Will only modify `self` when returning `Ok`.
pub fn advance_path_by_one<NS: Deref, NL: Deref, T>(
pub fn advance_path_by_one<NS: Deref, NL: Deref, T: secp256k1::Signing + secp256k1::Verification>(
&mut self, node_signer: &NS, node_id_lookup: &NL, secp_ctx: &Secp256k1<T>
) -> Result<(), ()>
where
NS::Target: NodeSigner,
NL::Target: NodeIdLookUp,
T: secp256k1::Signing + secp256k1::Verification,
{
let control_tlvs_ss = node_signer.ecdh(Recipient::Node, &self.inner_path.blinding_point, None)?;
let rho = onion_utils::gen_rho_from_shared_secret(&control_tlvs_ss.secret_bytes());
Expand Down
6 changes: 3 additions & 3 deletions lightning/src/chain/channelmonitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ pub struct ChannelMonitor<Signer: EcdsaChannelSigner> {
pub(super) inner: Mutex<ChannelMonitorImpl<Signer>>,
}

impl<Signer: EcdsaChannelSigner> Clone for ChannelMonitor<Signer> where Signer: Clone {
impl<Signer: EcdsaChannelSigner> Clone for ChannelMonitor<Signer> {
fn clone(&self) -> Self {
let inner = self.inner.lock().unwrap().clone();
ChannelMonitor::from_impl(inner)
Expand Down Expand Up @@ -4659,8 +4659,8 @@ where

const MAX_ALLOC_SIZE: usize = 64*1024;

impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP)>
for (BlockHash, ChannelMonitor<SP::EcdsaSigner>) {
impl<'a, 'b, ES: EntropySource, Signer: EcdsaChannelSigner, SP: SignerProvider<EcdsaSigner=Signer>> ReadableArgs<(&'a ES, &'b SP)>
for (BlockHash, ChannelMonitor<Signer>) {
fn read<R: io::Read>(reader: &mut R, args: (&'a ES, &'b SP)) -> Result<Self, DecodeError> {
macro_rules! unwrap_obj {
($key: expr) => {
Expand Down
4 changes: 4 additions & 0 deletions lightning/src/events/bump_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ impl Utxo {
}

/// Returns a `Utxo` with the `satisfaction_weight` estimate for a P2WPKH nested in P2SH output.
///
/// This is not exported to bindings users as WPubkeyHash is not yet exported
pub fn new_nested_p2wpkh(outpoint: OutPoint, value: Amount, pubkey_hash: &WPubkeyHash) -> Self {
let script_sig_size = 1 /* script_sig length */ +
1 /* OP_0 */ +
Expand All @@ -291,6 +293,8 @@ impl Utxo {
}

/// Returns a `Utxo` with the `satisfaction_weight` estimate for a SegWit v0 P2WPKH output.
///
/// This is not exported to bindings users as WPubkeyHash is not yet exported
pub fn new_v0_p2wpkh(outpoint: OutPoint, value: Amount, pubkey_hash: &WPubkeyHash) -> Self {
Self {
outpoint,
Expand Down
5 changes: 3 additions & 2 deletions lightning/src/ln/bolt11_payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use bitcoin::hashes::Hash;
use lightning_invoice::Bolt11Invoice;

use crate::ln::channelmanager::RecipientOnionFields;
use crate::ln::outbound_payment::RecipientOnionFields;
use crate::ln::types::PaymentHash;
use crate::routing::router::{PaymentParameters, RouteParameters};

Expand Down Expand Up @@ -161,7 +161,8 @@ mod tests {
#[test]
fn payment_metadata_end_to_end() {
use crate::events::Event;
use crate::ln::channelmanager::{PaymentId, Retry};
use crate::ln::channelmanager::PaymentId;
use crate::ln::outbound_payment::Retry;
use crate::ln::functional_test_utils::*;
use crate::ln::msgs::ChannelMessageHandler;

Expand Down
4 changes: 2 additions & 2 deletions lightning/src/ln/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7030,7 +7030,7 @@ impl<SP: Deref> Channel<SP> where
return None;
}
};
let our_node_sig = match node_signer.sign_gossip_message(msgs::UnsignedGossipMessage::ChannelAnnouncement(&announcement)) {
let our_node_sig = match node_signer.sign_gossip_message(msgs::UnsignedGossipMessage::ChannelAnnouncement(announcement.clone())) {
Err(_) => {
log_error!(logger, "Failed to generate node signature for channel_announcement. Channel will not be announced!");
return None;
Expand Down Expand Up @@ -7076,7 +7076,7 @@ impl<SP: Deref> Channel<SP> where
.map_err(|_| ChannelError::Ignore("Signer failed to retrieve own public key".to_owned()))?);
let were_node_one = announcement.node_id_1 == our_node_key;

let our_node_sig = node_signer.sign_gossip_message(msgs::UnsignedGossipMessage::ChannelAnnouncement(&announcement))
let our_node_sig = node_signer.sign_gossip_message(msgs::UnsignedGossipMessage::ChannelAnnouncement(announcement.clone()))
.map_err(|_| ChannelError::Ignore("Failed to generate node signature for channel_announcement".to_owned()))?;
match &self.context.holder_signer {
ChannelSignerType::Ecdsa(ecdsa) => {
Expand Down
Loading
Loading