Skip to content

Commit 7e2c5ef

Browse files
authored
Merge pull request lightningdevkit#3545 from TheBlueMatt/2024-12-0.1-bindings
0.1 bindings
2 parents d378023 + d2141e1 commit 7e2c5ef

File tree

40 files changed

+183
-161
lines changed

40 files changed

+183
-161
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ use lightning::ln::channel::FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE;
4848
use lightning::ln::channel_state::ChannelDetails;
4949
use lightning::ln::channelmanager::{
5050
ChainParameters, ChannelManager, ChannelManagerReadArgs, PaymentId, RecentPaymentDetails,
51-
RecipientOnionFields, Retry,
5251
};
5352
use lightning::ln::functional_test_utils::*;
5453
use lightning::ln::inbound_payment::ExpandedKey;
5554
use lightning::ln::msgs::{
5655
self, ChannelMessageHandler, CommitmentUpdate, DecodeError, Init, UpdateAddHTLC,
5756
};
57+
use lightning::ln::outbound_payment::{RecipientOnionFields, Retry};
5858
use lightning::ln::script::ShutdownScript;
5959
use lightning::ln::types::ChannelId;
6060
use lightning::offers::invoice::UnsignedBolt12Invoice;

fuzz/src/full_stack.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,11 @@ use lightning::chain::transaction::OutPoint;
3939
use lightning::chain::{BestBlock, ChannelMonitorUpdateStatus, Confirm, Listen};
4040
use lightning::events::Event;
4141
use lightning::ln::channel_state::ChannelDetails;
42-
use lightning::ln::channelmanager::{
43-
ChainParameters, ChannelManager, InterceptId, PaymentId, RecipientOnionFields, Retry,
44-
};
42+
use lightning::ln::channelmanager::{ChainParameters, ChannelManager, InterceptId, PaymentId};
4543
use lightning::ln::functional_test_utils::*;
4644
use lightning::ln::inbound_payment::ExpandedKey;
4745
use lightning::ln::msgs::{self, DecodeError};
46+
use lightning::ln::outbound_payment::{RecipientOnionFields, Retry};
4847
use lightning::ln::peer_handler::{
4948
IgnoringMessageHandler, MessageHandler, PeerManager, SocketDescriptor,
5049
};

fuzz/src/onion_message.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ impl AsyncPaymentsMessageHandler for TestAsyncPaymentsMessageHandler {
133133
fn handle_release_held_htlc(&self, _message: ReleaseHeldHtlc, _context: AsyncPaymentsContext) {}
134134
}
135135

136-
#[derive(Debug)]
136+
#[derive(Clone, Debug)]
137137
struct TestCustomMessage {}
138138

139139
const CUSTOM_MESSAGE_TYPE: u64 = 4242;

lightning-background-processor/src/lib.rs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ impl BackgroundProcessor {
924924
SC: for<'b> WriteableScore<'b>,
925925
>(
926926
persister: PS, event_handler: EH, chain_monitor: M, channel_manager: CM,
927-
onion_messenger: Option<OM>, gossip_sync: GossipSync<PGS, RGS, G, UL, L>, peer_manager: PM,
927+
onion_messenger: OM, gossip_sync: GossipSync<PGS, RGS, G, UL, L>, peer_manager: PM,
928928
logger: L, scorer: Option<S>,
929929
) -> Self
930930
where
@@ -961,34 +961,27 @@ impl BackgroundProcessor {
961961
}
962962
event_handler.handle_event(event)
963963
};
964+
let om_opt = Some(&*onion_messenger);
964965
define_run_body!(
965966
persister,
966967
chain_monitor,
967968
chain_monitor.process_pending_events(&event_handler),
968969
channel_manager,
969970
channel_manager.get_cm().process_pending_events(&event_handler),
970-
onion_messenger,
971-
if let Some(om) = &onion_messenger {
972-
om.get_om().process_pending_events(&event_handler)
973-
},
971+
om_opt,
972+
onion_messenger.get_om().process_pending_events(&event_handler),
974973
peer_manager,
975974
gossip_sync,
976975
logger,
977976
scorer,
978977
stop_thread.load(Ordering::Acquire),
979978
{
980-
let sleeper = if let Some(om) = onion_messenger.as_ref() {
979+
let sleeper =
981980
Sleeper::from_three_futures(
982981
&channel_manager.get_cm().get_event_or_persistence_needed_future(),
983982
&chain_monitor.get_update_future(),
984-
&om.get_om().get_update_future(),
985-
)
986-
} else {
987-
Sleeper::from_two_futures(
988-
&channel_manager.get_cm().get_event_or_persistence_needed_future(),
989-
&chain_monitor.get_update_future(),
990-
)
991-
};
983+
&onion_messenger.get_om().get_update_future(),
984+
);
992985
sleeper.wait_timeout(Duration::from_millis(100));
993986
},
994987
|_| Instant::now(),
@@ -1141,8 +1134,6 @@ mod tests {
11411134
Arc<test_utils::TestLogger>,
11421135
Arc<KeysManager>,
11431136
Arc<LockingWrapper<TestScorer>>,
1144-
(),
1145-
TestScorer,
11461137
>,
11471138
>,
11481139
Arc<
@@ -1412,10 +1403,11 @@ mod tests {
14121403
}
14131404

14141405
impl ScoreLookUp for TestScorer {
1406+
#[cfg(not(c_bindings))]
14151407
type ScoreParams = ();
14161408
fn channel_penalty_msat(
14171409
&self, _candidate: &CandidateRouteHop, _usage: ChannelUsage,
1418-
_score_params: &Self::ScoreParams,
1410+
_score_params: &lightning::routing::scoring::ProbabilisticScoringFeeParameters,
14191411
) -> u64 {
14201412
unimplemented!();
14211413
}

lightning-dns-resolver/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,10 @@ mod test {
162162
use lightning::blinded_path::message::{BlindedMessagePath, MessageContext};
163163
use lightning::blinded_path::NodeIdLookUp;
164164
use lightning::events::{Event, PaymentPurpose};
165-
use lightning::ln::channelmanager::{PaymentId, Retry};
165+
use lightning::ln::channelmanager::PaymentId;
166166
use lightning::ln::functional_test_utils::*;
167167
use lightning::ln::msgs::{ChannelMessageHandler, Init, OnionMessageHandler};
168+
use lightning::ln::outbound_payment::Retry;
168169
use lightning::ln::peer_handler::IgnoringMessageHandler;
169170
use lightning::onion_message::dns_resolution::{HumanReadableName, OMNameResolver};
170171
use lightning::onion_message::messenger::{

lightning-invoice/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ pub use crate::ser::Base32Iterable;
8686
#[allow(missing_docs)]
8787
#[derive(PartialEq, Eq, Debug, Clone)]
8888
pub enum Bolt11ParseError {
89-
Bech32Error(CheckedHrpstringError),
89+
Bech32Error(
90+
/// This is not exported to bindings users as the specific error isn't all that useful.
91+
CheckedHrpstringError),
9092
ParseAmountError(ParseIntError),
9193
MalformedSignature(bitcoin::secp256k1::Error),
9294
BadPrefix,

lightning-liquidity/tests/common/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ type ChannelManager = channelmanager::ChannelManager<
8080
Arc<test_utils::TestLogger>,
8181
Arc<KeysManager>,
8282
Arc<LockingWrapper<TestScorer>>,
83-
(),
84-
TestScorer,
8583
>,
8684
>,
8785
Arc<
@@ -286,10 +284,11 @@ impl lightning::util::ser::Writeable for TestScorer {
286284
}
287285

288286
impl ScoreLookUp for TestScorer {
287+
#[cfg(not(c_bindings))]
289288
type ScoreParams = ();
290289
fn channel_penalty_msat(
291290
&self, _candidate: &CandidateRouteHop, _usage: ChannelUsage,
292-
_score_params: &Self::ScoreParams,
291+
_score_params: &lightning::routing::scoring::ProbabilisticScoringFeeParameters,
293292
) -> u64 {
294293
unimplemented!();
295294
}

lightning-transaction-sync/src/electrum.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
66
// accordance with one or both of these licenses.
77

8+
//! Chain sync using the electrum protocol
9+
810
use crate::common::{ConfirmedTx, FilterQueue, SyncState};
911
use crate::error::{InternalError, TxSyncError};
1012

lightning-transaction-sync/src/error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
66
// accordance with one or both of these licenses.
77

8+
//! Common error types
9+
810
use std::fmt;
911

1012
#[derive(Debug)]

lightning-transaction-sync/src/esplora.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
66
// accordance with one or both of these licenses.
77

8+
//! Chain sync using the Esplora API
9+
810
use crate::common::{ConfirmedTx, FilterQueue, SyncState};
911
use crate::error::{InternalError, TxSyncError};
1012

lightning-transaction-sync/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@
7272
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
7373

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

7777
#[cfg(any(feature = "electrum"))]
78-
mod electrum;
78+
pub mod electrum;
7979

8080
#[cfg(any(feature = "esplora-blocking", feature = "esplora-async", feature = "electrum"))]
8181
mod common;
8282
#[cfg(any(feature = "esplora-blocking", feature = "esplora-async", feature = "electrum"))]
83-
mod error;
83+
pub mod error;
8484
#[cfg(any(feature = "esplora-blocking", feature = "esplora-async", feature = "electrum"))]
8585
pub use error::TxSyncError;
8686

lightning-types/src/features.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,7 @@ pub struct Features<T: sealed::Context> {
638638
mark: PhantomData<T>,
639639
}
640640

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

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

lightning/src/blinded_path/message.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,12 @@ impl BlindedMessagePath {
143143
/// introduction node.
144144
///
145145
/// Will only modify `self` when returning `Ok`.
146-
pub fn advance_path_by_one<NS: Deref, NL: Deref, T>(
146+
pub fn advance_path_by_one<NS: Deref, NL: Deref, T: secp256k1::Signing + secp256k1::Verification>(
147147
&mut self, node_signer: &NS, node_id_lookup: &NL, secp_ctx: &Secp256k1<T>
148148
) -> Result<(), ()>
149149
where
150150
NS::Target: NodeSigner,
151151
NL::Target: NodeIdLookUp,
152-
T: secp256k1::Signing + secp256k1::Verification,
153152
{
154153
let control_tlvs_ss = node_signer.ecdh(Recipient::Node, &self.0.blinding_point, None)?;
155154
let rho = onion_utils::gen_rho_from_shared_secret(&control_tlvs_ss.secret_bytes());
@@ -344,7 +343,7 @@ pub enum OffersContext {
344343
/// used with an [`InvoiceError`].
345344
///
346345
/// [`InvoiceError`]: crate::offers::invoice_error::InvoiceError
347-
hmac: Option<Hmac<Sha256>>,
346+
hmac: Option<[u8; 32]>,
348347
},
349348
/// Context used by a [`BlindedMessagePath`] as a reply path for a [`Bolt12Invoice`].
350349
///
@@ -369,7 +368,7 @@ pub enum OffersContext {
369368
/// used to log the received [`InvoiceError`].
370369
///
371370
/// [`InvoiceError`]: crate::offers::invoice_error::InvoiceError
372-
hmac: Hmac<Sha256>,
371+
hmac: [u8; 32],
373372
},
374373
}
375374

@@ -400,7 +399,7 @@ pub enum AsyncPaymentsContext {
400399
///
401400
/// Prevents the recipient from being able to deanonymize us by creating a blinded path to us
402401
/// containing the expected [`PaymentId`].
403-
hmac: Hmac<Sha256>,
402+
hmac: [u8; 32],
404403
},
405404
}
406405

lightning/src/blinded_path/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,15 +185,15 @@ impl_writeable!(BlindedHop, {
185185

186186
impl Direction {
187187
/// Returns the [`NodeId`] from the inputs corresponding to the direction.
188-
pub fn select_node_id(&self, node_a: NodeId, node_b: NodeId) -> NodeId {
188+
pub(crate) fn select_node_id(&self, node_a: NodeId, node_b: NodeId) -> NodeId {
189189
match self {
190190
Direction::NodeOne => core::cmp::min(node_a, node_b),
191191
Direction::NodeTwo => core::cmp::max(node_a, node_b),
192192
}
193193
}
194194

195195
/// Returns the [`PublicKey`] from the inputs corresponding to the direction.
196-
pub fn select_pubkey<'a>(&self, node_a: &'a PublicKey, node_b: &'a PublicKey) -> &'a PublicKey {
196+
pub(crate) fn select_pubkey<'a>(&self, node_a: &'a PublicKey, node_b: &'a PublicKey) -> &'a PublicKey {
197197
let (node_one, node_two) = if NodeId::from_pubkey(node_a) < NodeId::from_pubkey(node_b) {
198198
(node_a, node_b)
199199
} else {

lightning/src/blinded_path/payment.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl BlindedPaymentPath {
9595
// be in relation to a specific channel.
9696
let htlc_maximum_msat = u64::max_value();
9797
Self::new(
98-
&[], payee_node_id, payee_tlvs, htlc_maximum_msat, min_final_cltv_expiry_delta,
98+
Vec::new(), payee_node_id, payee_tlvs, htlc_maximum_msat, min_final_cltv_expiry_delta,
9999
entropy_source, secp_ctx
100100
)
101101
}
@@ -108,7 +108,7 @@ impl BlindedPaymentPath {
108108
/// * any unknown features are required in the provided [`ForwardTlvs`]
109109
// TODO: make all payloads the same size with padding + add dummy hops
110110
pub fn new<ES: Deref, T: secp256k1::Signing + secp256k1::Verification>(
111-
intermediate_nodes: &[PaymentForwardNode], payee_node_id: PublicKey,
111+
intermediate_nodes: Vec<PaymentForwardNode>, payee_node_id: PublicKey,
112112
payee_tlvs: ReceiveTlvs, htlc_maximum_msat: u64, min_final_cltv_expiry_delta: u16,
113113
entropy_source: ES, secp_ctx: &Secp256k1<T>,
114114
) -> Result<Self, ()> where ES::Target: EntropySource {
@@ -119,14 +119,14 @@ impl BlindedPaymentPath {
119119
let blinding_secret = SecretKey::from_slice(&blinding_secret_bytes[..]).expect("RNG is busted");
120120

121121
let blinded_payinfo = compute_payinfo(
122-
intermediate_nodes, &payee_tlvs.tlvs, htlc_maximum_msat, min_final_cltv_expiry_delta
122+
&intermediate_nodes, &payee_tlvs.tlvs, htlc_maximum_msat, min_final_cltv_expiry_delta
123123
)?;
124124
Ok(Self {
125125
inner_path: BlindedPath {
126126
introduction_node,
127127
blinding_point: PublicKey::from_secret_key(secp_ctx, &blinding_secret),
128128
blinded_hops: blinded_hops(
129-
secp_ctx, intermediate_nodes, payee_node_id, payee_tlvs, &blinding_secret
129+
secp_ctx, &intermediate_nodes, payee_node_id, payee_tlvs, &blinding_secret
130130
).map_err(|_| ())?,
131131
},
132132
payinfo: blinded_payinfo
@@ -162,13 +162,12 @@ impl BlindedPaymentPath {
162162
/// introduction node.
163163
///
164164
/// Will only modify `self` when returning `Ok`.
165-
pub fn advance_path_by_one<NS: Deref, NL: Deref, T>(
165+
pub fn advance_path_by_one<NS: Deref, NL: Deref, T: secp256k1::Signing + secp256k1::Verification>(
166166
&mut self, node_signer: &NS, node_id_lookup: &NL, secp_ctx: &Secp256k1<T>
167167
) -> Result<(), ()>
168168
where
169169
NS::Target: NodeSigner,
170170
NL::Target: NodeIdLookUp,
171-
T: secp256k1::Signing + secp256k1::Verification,
172171
{
173172
let control_tlvs_ss = node_signer.ecdh(Recipient::Node, &self.inner_path.blinding_point, None)?;
174173
let rho = onion_utils::gen_rho_from_shared_secret(&control_tlvs_ss.secret_bytes());
@@ -264,7 +263,7 @@ pub struct ReceiveTlvs {
264263
/// The TLVs for which the HMAC in `authentication` is derived.
265264
pub(crate) tlvs: UnauthenticatedReceiveTlvs,
266265
/// An HMAC of `tlvs` along with a nonce used to construct it.
267-
pub(crate) authentication: (Hmac<Sha256>, Nonce),
266+
pub(crate) authentication: ([u8; 32], Nonce),
268267
}
269268

270269
impl ReceiveTlvs {

lightning/src/chain/channelmonitor.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@ pub struct ChannelMonitor<Signer: EcdsaChannelSigner> {
854854
pub(super) inner: Mutex<ChannelMonitorImpl<Signer>>,
855855
}
856856

857-
impl<Signer: EcdsaChannelSigner> Clone for ChannelMonitor<Signer> where Signer: Clone {
857+
impl<Signer: EcdsaChannelSigner> Clone for ChannelMonitor<Signer> {
858858
fn clone(&self) -> Self {
859859
let inner = self.inner.lock().unwrap().clone();
860860
ChannelMonitor::from_impl(inner)
@@ -4735,8 +4735,8 @@ where
47354735

47364736
const MAX_ALLOC_SIZE: usize = 64*1024;
47374737

4738-
impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP)>
4739-
for (BlockHash, ChannelMonitor<SP::EcdsaSigner>) {
4738+
impl<'a, 'b, ES: EntropySource, Signer: EcdsaChannelSigner, SP: SignerProvider<EcdsaSigner=Signer>> ReadableArgs<(&'a ES, &'b SP)>
4739+
for (BlockHash, ChannelMonitor<Signer>) {
47404740
fn read<R: io::Read>(reader: &mut R, args: (&'a ES, &'b SP)) -> Result<Self, DecodeError> {
47414741
macro_rules! unwrap_obj {
47424742
($key: expr) => {

lightning/src/events/bump_transaction.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ impl Utxo {
275275
}
276276

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

293295
/// Returns a `Utxo` with the `satisfaction_weight` estimate for a SegWit v0 P2WPKH output.
296+
///
297+
/// This is not exported to bindings users as WPubkeyHash is not yet exported
294298
pub fn new_v0_p2wpkh(outpoint: OutPoint, value: Amount, pubkey_hash: &WPubkeyHash) -> Self {
295299
Self {
296300
outpoint,

lightning/src/ln/bolt11_payment.rs

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

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

@@ -161,9 +161,10 @@ mod tests {
161161
#[test]
162162
fn payment_metadata_end_to_end() {
163163
use crate::events::Event;
164-
use crate::ln::channelmanager::{PaymentId, Retry};
164+
use crate::ln::channelmanager::PaymentId;
165165
use crate::ln::functional_test_utils::*;
166166
use crate::ln::msgs::ChannelMessageHandler;
167+
use crate::ln::outbound_payment::Retry;
167168

168169
// Test that a payment metadata read from an invoice passed to `pay_invoice` makes it all
169170
// the way out through the `PaymentClaimable` event.

0 commit comments

Comments
 (0)