Skip to content

Commit 9b523d9

Browse files
authored
Merge pull request #3062 from TheBlueMatt/2024-04-123-bindings
[0.0.123-bindings] Bindings changes for 0.0.123
2 parents 475f736 + 4f8f9b4 commit 9b523d9

36 files changed

+233
-185
lines changed

fuzz/src/chanmon_consistency.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ use lightning::sign::{KeyMaterial, InMemorySigner, Recipient, EntropySource, Nod
4141
use lightning::events;
4242
use lightning::events::MessageSendEventsProvider;
4343
use lightning::ln::{ChannelId, PaymentHash, PaymentPreimage, PaymentSecret};
44-
use lightning::ln::channelmanager::{ChainParameters, ChannelDetails, ChannelManager, PaymentSendFailure, ChannelManagerReadArgs, PaymentId, RecipientOnionFields};
44+
use lightning::ln::channelmanager::{ChainParameters, ChannelDetails, ChannelManager, ChannelManagerReadArgs, PaymentId};
45+
use lightning::ln::outbound_payment::{RecipientOnionFields, PaymentSendFailure};
4546
use lightning::ln::channel::FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE;
4647
use lightning::ln::msgs::{self, CommitmentUpdate, ChannelMessageHandler, DecodeError, UpdateAddHTLC, Init};
4748
use lightning::ln::script::ShutdownScript;

fuzz/src/full_stack.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ use lightning::chain::transaction::OutPoint;
3737
use lightning::sign::{InMemorySigner, Recipient, KeyMaterial, EntropySource, NodeSigner, SignerProvider};
3838
use lightning::events::Event;
3939
use lightning::ln::{ChannelId, PaymentHash, PaymentPreimage, PaymentSecret};
40-
use lightning::ln::channelmanager::{ChainParameters, ChannelDetails, ChannelManager, PaymentId, RecipientOnionFields, Retry, InterceptId};
40+
use lightning::ln::channelmanager::{ChainParameters, ChannelDetails, ChannelManager, PaymentId, InterceptId};
41+
use lightning::ln::outbound_payment::{RecipientOnionFields, Retry};
4142
use lightning::ln::peer_handler::{MessageHandler,PeerManager,SocketDescriptor,IgnoringMessageHandler};
4243
use lightning::ln::msgs::{self, DecodeError};
4344
use lightning::ln::script::ShutdownScript;

lightning-background-processor/src/lib.rs

+19-27
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ macro_rules! define_run_body {
338338

339339
if $channel_manager.get_cm().get_and_clear_needs_persistence() {
340340
log_trace!($logger, "Persisting ChannelManager...");
341-
$persister.persist_manager(&$channel_manager)?;
341+
$persister.persist_manager($channel_manager.get_cm())?;
342342
log_trace!($logger, "Done persisting ChannelManager.");
343343
}
344344
if $timer_elapsed(&mut last_freshness_call, FRESHNESS_TIMER) {
@@ -440,7 +440,7 @@ macro_rules! define_run_body {
440440
// After we exit, ensure we persist the ChannelManager one final time - this avoids
441441
// some races where users quit while channel updates were in-flight, with
442442
// ChannelMonitor update(s) persisted without a corresponding ChannelManager update.
443-
$persister.persist_manager(&$channel_manager)?;
443+
$persister.persist_manager($channel_manager.get_cm())?;
444444

445445
// Persist Scorer on exit
446446
if let Some(ref scorer) = $scorer {
@@ -704,7 +704,10 @@ where
704704
persister, chain_monitor,
705705
chain_monitor.process_pending_events_async(async_event_handler).await,
706706
channel_manager, channel_manager.get_cm().process_pending_events_async(async_event_handler).await,
707-
peer_manager, process_onion_message_handler_events_async(&peer_manager, async_event_handler).await,
707+
peer_manager,
708+
for event in onion_message_handler_events(peer_manager) {
709+
handler(event).await
710+
},
708711
gossip_sync, logger, scorer, should_break, {
709712
let fut = Selector {
710713
a: channel_manager.get_cm().get_event_or_persistence_needed_future(),
@@ -729,23 +732,11 @@ where
729732
)
730733
}
731734

732-
#[cfg(feature = "futures")]
733-
async fn process_onion_message_handler_events_async<
734-
EventHandlerFuture: core::future::Future<Output = ()>,
735-
EventHandler: Fn(Event) -> EventHandlerFuture,
736-
PM: 'static + Deref + Send + Sync,
737-
>(
738-
peer_manager: &PM, handler: EventHandler
739-
)
740-
where
741-
PM::Target: APeerManager + Send + Sync,
742-
{
743-
let events = core::cell::RefCell::new(Vec::new());
744-
peer_manager.onion_message_handler().process_pending_events(&|e| events.borrow_mut().push(e));
745-
746-
for event in events.into_inner() {
747-
handler(event).await
748-
}
735+
fn onion_message_handler_events<PM: 'static + Deref + Send + Sync>(
736+
peer_manager: &PM
737+
) -> impl Iterator<Item=Event> where PM::Target: APeerManager + Send + Sync {
738+
peer_manager.onion_message_handler().get_and_clear_connections_needed()
739+
.into_iter().map(|(node_id, addresses)| Event::ConnectionNeeded { node_id, addresses })
749740
}
750741

751742
#[cfg(feature = "std")]
@@ -823,8 +814,8 @@ impl BackgroundProcessor {
823814
F::Target: 'static + FeeEstimator,
824815
L::Target: 'static + Logger,
825816
P::Target: 'static + Persist<<CM::Target as AChannelManager>::Signer>,
826-
PS::Target: 'static + Persister<'a, CM, L, SC>,
827-
CM::Target: AChannelManager + Send + Sync,
817+
PS::Target: 'static + Persister<'a, <<CM as Deref>::Target as AChannelManager>::M, <<CM as Deref>::Target as AChannelManager>::T, <<CM as Deref>::Target as AChannelManager>::ES, <<CM as Deref>::Target as AChannelManager>::NS, <<CM as Deref>::Target as AChannelManager>::SP, <<CM as Deref>::Target as AChannelManager>::F, <<CM as Deref>::Target as AChannelManager>::R, L, SC>,
818+
CM::Target: AChannelManager<L = L> + Send + Sync,
828819
PM::Target: APeerManager + Send + Sync,
829820
{
830821
let stop_thread = Arc::new(AtomicBool::new(false));
@@ -852,7 +843,9 @@ impl BackgroundProcessor {
852843
persister, chain_monitor, chain_monitor.process_pending_events(&event_handler),
853844
channel_manager, channel_manager.get_cm().process_pending_events(&event_handler),
854845
peer_manager,
855-
peer_manager.onion_message_handler().process_pending_events(&event_handler),
846+
for event in onion_message_handler_events(&peer_manager) {
847+
event_handler.handle_event(event);
848+
},
856849
gossip_sync, logger, scorer, stop_thread.load(Ordering::Acquire),
857850
{ Sleeper::from_two_futures(
858851
&channel_manager.get_cm().get_event_or_persistence_needed_future(),
@@ -989,9 +982,7 @@ mod tests {
989982
Arc<NetworkGraph<Arc<test_utils::TestLogger>>>,
990983
Arc<test_utils::TestLogger>,
991984
Arc<KeysManager>,
992-
Arc<LockingWrapper<TestScorer>>,
993-
(),
994-
TestScorer>
985+
Arc<LockingWrapper<TestScorer>>>
995986
>,
996987
Arc<test_utils::TestLogger>>;
997988

@@ -1151,9 +1142,10 @@ mod tests {
11511142
}
11521143

11531144
impl ScoreLookUp for TestScorer {
1145+
#[cfg(not(c_bindings))]
11541146
type ScoreParams = ();
11551147
fn channel_penalty_msat(
1156-
&self, _candidate: &CandidateRouteHop, _usage: ChannelUsage, _score_params: &Self::ScoreParams
1148+
&self, _candidate: &CandidateRouteHop, _usage: ChannelUsage, _score_params: &lightning::routing::scoring::ProbabilisticScoringFeeParameters
11571149
) -> u64 { unimplemented!(); }
11581150
}
11591151

lightning-invoice/src/payment.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::Bolt11Invoice;
1313
use bitcoin::hashes::Hash;
1414

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

1919
/// Builds the necessary parameters to pay or pre-flight probe the given zero-amount
@@ -170,7 +170,8 @@ mod tests {
170170
#[cfg(feature = "std")]
171171
fn payment_metadata_end_to_end() {
172172
use lightning::events::Event;
173-
use lightning::ln::channelmanager::{Retry, PaymentId};
173+
use lightning::ln::channelmanager::PaymentId;
174+
use lightning::ln::outbound_payment::Retry;
174175
use lightning::ln::msgs::ChannelMessageHandler;
175176
use lightning::ln::functional_test_utils::*;
176177
// Test that a payment metadata read from an invoice passed to `pay_invoice` makes it all

lightning-invoice/src/utils.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,8 @@ mod test {
827827
use lightning::ln::types::PaymentHash;
828828
#[cfg(feature = "std")]
829829
use lightning::ln::types::PaymentPreimage;
830-
use lightning::ln::channelmanager::{PhantomRouteHints, MIN_FINAL_CLTV_EXPIRY_DELTA, PaymentId, RecipientOnionFields, Retry};
830+
use lightning::ln::channelmanager::{PhantomRouteHints, MIN_FINAL_CLTV_EXPIRY_DELTA, PaymentId};
831+
use lightning::ln::outbound_payment::{RecipientOnionFields, Retry};
831832
use lightning::ln::functional_test_utils::*;
832833
use lightning::ln::msgs::ChannelMessageHandler;
833834
use lightning::routing::router::{PaymentParameters, RouteParameters};

lightning/src/blinded_path/mod.rs

+20-18
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ pub(crate) mod utils;
1515

1616
use bitcoin::secp256k1::{self, PublicKey, Secp256k1, SecretKey};
1717

18+
use core::ops::Deref;
19+
1820
use crate::ln::msgs::DecodeError;
1921
use crate::offers::invoice::BlindedPayInfo;
2022
use crate::routing::gossip::{NodeId, ReadOnlyNetworkGraph};
@@ -115,9 +117,9 @@ pub struct BlindedHop {
115117

116118
impl BlindedPath {
117119
/// Create a one-hop blinded path for a message.
118-
pub fn one_hop_for_message<ES: EntropySource + ?Sized, T: secp256k1::Signing + secp256k1::Verification>(
119-
recipient_node_id: PublicKey, entropy_source: &ES, secp_ctx: &Secp256k1<T>
120-
) -> Result<Self, ()> {
120+
pub fn one_hop_for_message<ES: Deref, T: secp256k1::Signing + secp256k1::Verification>(
121+
recipient_node_id: PublicKey, entropy_source: ES, secp_ctx: &Secp256k1<T>
122+
) -> Result<Self, ()> where ES::Target: EntropySource {
121123
Self::new_for_message(&[recipient_node_id], entropy_source, secp_ctx)
122124
}
123125

@@ -126,9 +128,9 @@ impl BlindedPath {
126128
///
127129
/// Errors if no hops are provided or if `node_pk`(s) are invalid.
128130
// TODO: make all payloads the same size with padding + add dummy hops
129-
pub fn new_for_message<ES: EntropySource + ?Sized, T: secp256k1::Signing + secp256k1::Verification>(
130-
node_pks: &[PublicKey], entropy_source: &ES, secp_ctx: &Secp256k1<T>
131-
) -> Result<Self, ()> {
131+
pub fn new_for_message<ES: Deref, T: secp256k1::Signing + secp256k1::Verification>(
132+
node_pks: &[PublicKey], entropy_source: ES, secp_ctx: &Secp256k1<T>
133+
) -> Result<Self, ()> where ES::Target: EntropySource {
132134
if node_pks.is_empty() { return Err(()) }
133135
let blinding_secret_bytes = entropy_source.get_secure_random_bytes();
134136
let blinding_secret = SecretKey::from_slice(&blinding_secret_bytes[..]).expect("RNG is busted");
@@ -142,15 +144,15 @@ impl BlindedPath {
142144
}
143145

144146
/// Create a one-hop blinded path for a payment.
145-
pub fn one_hop_for_payment<ES: EntropySource + ?Sized, T: secp256k1::Signing + secp256k1::Verification>(
147+
pub fn one_hop_for_payment<ES: Deref, T: secp256k1::Signing + secp256k1::Verification>(
146148
payee_node_id: PublicKey, payee_tlvs: payment::ReceiveTlvs, min_final_cltv_expiry_delta: u16,
147-
entropy_source: &ES, secp_ctx: &Secp256k1<T>
148-
) -> Result<(BlindedPayInfo, Self), ()> {
149+
entropy_source: ES, secp_ctx: &Secp256k1<T>
150+
) -> Result<(BlindedPayInfo, Self), ()> where ES::Target: EntropySource {
149151
// This value is not considered in pathfinding for 1-hop blinded paths, because it's intended to
150152
// be in relation to a specific channel.
151153
let htlc_maximum_msat = u64::max_value();
152154
Self::new_for_payment(
153-
&[], payee_node_id, payee_tlvs, htlc_maximum_msat, min_final_cltv_expiry_delta,
155+
Vec::new(), payee_node_id, payee_tlvs, htlc_maximum_msat, min_final_cltv_expiry_delta,
154156
entropy_source, secp_ctx
155157
)
156158
}
@@ -164,25 +166,25 @@ impl BlindedPath {
164166
///
165167
/// [`ForwardTlvs`]: crate::blinded_path::payment::ForwardTlvs
166168
// TODO: make all payloads the same size with padding + add dummy hops
167-
pub fn new_for_payment<ES: EntropySource + ?Sized, T: secp256k1::Signing + secp256k1::Verification>(
168-
intermediate_nodes: &[payment::ForwardNode], payee_node_id: PublicKey,
169+
pub fn new_for_payment<ES: Deref, T: secp256k1::Signing + secp256k1::Verification>(
170+
intermediate_nodes: Vec<payment::ForwardNode>, payee_node_id: PublicKey,
169171
payee_tlvs: payment::ReceiveTlvs, htlc_maximum_msat: u64, min_final_cltv_expiry_delta: u16,
170-
entropy_source: &ES, secp_ctx: &Secp256k1<T>
171-
) -> Result<(BlindedPayInfo, Self), ()> {
172+
entropy_source: ES, secp_ctx: &Secp256k1<T>
173+
) -> Result<(BlindedPayInfo, Self), ()> where ES::Target: EntropySource {
172174
let introduction_node = IntroductionNode::NodeId(
173175
intermediate_nodes.first().map_or(payee_node_id, |n| n.node_id)
174176
);
175177
let blinding_secret_bytes = entropy_source.get_secure_random_bytes();
176178
let blinding_secret = SecretKey::from_slice(&blinding_secret_bytes[..]).expect("RNG is busted");
177179

178180
let blinded_payinfo = payment::compute_payinfo(
179-
intermediate_nodes, &payee_tlvs, htlc_maximum_msat, min_final_cltv_expiry_delta
181+
&intermediate_nodes, &payee_tlvs, htlc_maximum_msat, min_final_cltv_expiry_delta
180182
)?;
181183
Ok((blinded_payinfo, BlindedPath {
182184
introduction_node,
183185
blinding_point: PublicKey::from_secret_key(secp_ctx, &blinding_secret),
184186
blinded_hops: payment::blinded_hops(
185-
secp_ctx, intermediate_nodes, payee_node_id, payee_tlvs, &blinding_secret
187+
secp_ctx, &intermediate_nodes, payee_node_id, payee_tlvs, &blinding_secret
186188
).map_err(|_| ())?,
187189
}))
188190
}
@@ -266,15 +268,15 @@ impl_writeable!(BlindedHop, {
266268

267269
impl Direction {
268270
/// Returns the [`NodeId`] from the inputs corresponding to the direction.
269-
pub fn select_node_id<'a>(&self, node_a: &'a NodeId, node_b: &'a NodeId) -> &'a NodeId {
271+
pub(crate) fn select_node_id<'a>(&self, node_a: &'a NodeId, node_b: &'a NodeId) -> &'a NodeId {
270272
match self {
271273
Direction::NodeOne => core::cmp::min(node_a, node_b),
272274
Direction::NodeTwo => core::cmp::max(node_a, node_b),
273275
}
274276
}
275277

276278
/// Returns the [`PublicKey`] from the inputs corresponding to the direction.
277-
pub fn select_pubkey<'a>(&self, node_a: &'a PublicKey, node_b: &'a PublicKey) -> &'a PublicKey {
279+
pub(crate) fn select_pubkey<'a>(&self, node_a: &'a PublicKey, node_b: &'a PublicKey) -> &'a PublicKey {
278280
let (node_one, node_two) = if NodeId::from_pubkey(node_a) < NodeId::from_pubkey(node_b) {
279281
(node_a, node_b)
280282
} else {

lightning/src/chain/channelmonitor.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ pub struct ChannelMonitor<Signer: WriteableEcdsaChannelSigner> {
781781
pub(super) inner: Mutex<ChannelMonitorImpl<Signer>>,
782782
}
783783

784-
impl<Signer: WriteableEcdsaChannelSigner> Clone for ChannelMonitor<Signer> where Signer: Clone {
784+
impl<Signer: WriteableEcdsaChannelSigner> Clone for ChannelMonitor<Signer> {
785785
fn clone(&self) -> Self {
786786
let inner = self.inner.lock().unwrap().clone();
787787
ChannelMonitor::from_impl(inner)
@@ -4468,8 +4468,8 @@ where
44684468

44694469
const MAX_ALLOC_SIZE: usize = 64*1024;
44704470

4471-
impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP)>
4472-
for (BlockHash, ChannelMonitor<SP::EcdsaSigner>) {
4471+
impl<'a, 'b, ES: EntropySource, Signer: WriteableEcdsaChannelSigner, SP: SignerProvider<EcdsaSigner=Signer>> ReadableArgs<(&'a ES, &'b SP)>
4472+
for (BlockHash, ChannelMonitor<Signer>) {
44734473
fn read<R: io::Read>(reader: &mut R, args: (&'a ES, &'b SP)) -> Result<Self, DecodeError> {
44744474
macro_rules! unwrap_obj {
44754475
($key: expr) => {

lightning/src/chain/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ impl BestBlock {
5252
}
5353

5454
/// Returns a `BestBlock` as identified by the given block hash and height.
55+
///
56+
/// This is not exported to bindings users directly as the bindings auto-generate an
57+
/// equivalent `new`.
5558
pub fn new(block_hash: BlockHash, height: u32) -> Self {
5659
BestBlock { block_hash, height }
5760
}

lightning/src/events/bump_transaction.rs

+4
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,8 @@ impl Utxo {
274274
}
275275

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

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

lightning/src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ pub use core2::io;
9696
#[cfg(not(feature = "std"))]
9797
#[doc(hidden)]
9898
/// IO utilities public only for use by in-crate macros. These should not be used externally
99+
///
100+
/// This is not exported to bindings users as it is not intended for public consumption.
99101
pub mod io_extras {
100102
use core2::io::{self, Read, Write};
101103

@@ -158,6 +160,8 @@ pub mod io_extras {
158160
#[cfg(feature = "std")]
159161
#[doc(hidden)]
160162
/// IO utilities public only for use by in-crate macros. These should not be used externally
163+
///
164+
/// This is not exported to bindings users as it is not intended for public consumption.
161165
mod io_extras {
162166
pub fn read_to_end<D: ::std::io::Read>(mut d: D) -> Result<Vec<u8>, ::std::io::Error> {
163167
let mut buf = Vec::new();

lightning/src/ln/channel.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6762,7 +6762,7 @@ impl<SP: Deref> Channel<SP> where
67626762
return None;
67636763
}
67646764
};
6765-
let our_node_sig = match node_signer.sign_gossip_message(msgs::UnsignedGossipMessage::ChannelAnnouncement(&announcement)) {
6765+
let our_node_sig = match node_signer.sign_gossip_message(msgs::UnsignedGossipMessage::ChannelAnnouncement(announcement.clone())) {
67666766
Err(_) => {
67676767
log_error!(logger, "Failed to generate node signature for channel_announcement. Channel will not be announced!");
67686768
return None;
@@ -6808,7 +6808,7 @@ impl<SP: Deref> Channel<SP> where
68086808
.map_err(|_| ChannelError::Ignore("Signer failed to retrieve own public key".to_owned()))?);
68096809
let were_node_one = announcement.node_id_1 == our_node_key;
68106810

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

0 commit comments

Comments
 (0)