Skip to content

Commit c57cd65

Browse files
authored
Merge pull request #2848 from TheBlueMatt/2024-01-121-bindings
0.0.121 bindings changes
2 parents 4bab9c8 + e01edf6 commit c57cd65

File tree

33 files changed

+284
-244
lines changed

33 files changed

+284
-244
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 2 additions & 1 deletion
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::{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

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

lightning-background-processor/src/lib.rs

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,10 @@ where
694694
persister, chain_monitor,
695695
chain_monitor.process_pending_events_async(async_event_handler).await,
696696
channel_manager, channel_manager.process_pending_events_async(async_event_handler).await,
697-
peer_manager, process_onion_message_handler_events_async(&peer_manager, async_event_handler).await,
697+
peer_manager,
698+
for event in onion_message_handler_events(peer_manager) {
699+
handler(event).await
700+
},
698701
gossip_sync, logger, scorer, should_break, {
699702
let fut = Selector {
700703
a: channel_manager.get_event_or_persistence_needed_future(),
@@ -719,23 +722,11 @@ where
719722
)
720723
}
721724

722-
#[cfg(feature = "futures")]
723-
async fn process_onion_message_handler_events_async<
724-
EventHandlerFuture: core::future::Future<Output = ()>,
725-
EventHandler: Fn(Event) -> EventHandlerFuture,
726-
PM: 'static + Deref + Send + Sync,
727-
>(
728-
peer_manager: &PM, handler: EventHandler
729-
)
730-
where
731-
PM::Target: APeerManager + Send + Sync,
732-
{
733-
let events = core::cell::RefCell::new(Vec::new());
734-
peer_manager.onion_message_handler().process_pending_events(&|e| events.borrow_mut().push(e));
735-
736-
for event in events.into_inner() {
737-
handler(event).await
738-
}
725+
fn onion_message_handler_events<PM: 'static + Deref + Send + Sync>(
726+
peer_manager: &PM
727+
) -> impl Iterator<Item=Event> where PM::Target: APeerManager + Send + Sync {
728+
peer_manager.onion_message_handler().get_and_clear_connections_needed()
729+
.into_iter().map(|(node_id, addresses)| Event::ConnectionNeeded { node_id, addresses })
739730
}
740731

741732
#[cfg(feature = "std")]
@@ -851,7 +842,9 @@ impl BackgroundProcessor {
851842
persister, chain_monitor, chain_monitor.process_pending_events(&event_handler),
852843
channel_manager, channel_manager.process_pending_events(&event_handler),
853844
peer_manager,
854-
peer_manager.onion_message_handler().process_pending_events(&event_handler),
845+
for event in onion_message_handler_events(&peer_manager) {
846+
event_handler.handle_event(event);
847+
},
855848
gossip_sync, logger, scorer, stop_thread.load(Ordering::Acquire),
856849
{ Sleeper::from_two_futures(
857850
channel_manager.get_event_or_persistence_needed_future(),
@@ -984,9 +977,8 @@ mod tests {
984977
Arc<DefaultRouter<
985978
Arc<NetworkGraph<Arc<test_utils::TestLogger>>>,
986979
Arc<test_utils::TestLogger>,
987-
Arc<LockingWrapper<TestScorer>>,
988-
(),
989-
TestScorer>
980+
Arc<KeysManager>,
981+
Arc<LockingWrapper<TestScorer>>>
990982
>,
991983
Arc<test_utils::TestLogger>>;
992984

@@ -1143,9 +1135,10 @@ mod tests {
11431135
}
11441136

11451137
impl ScoreLookUp for TestScorer {
1138+
#[cfg(not(c_bindings))]
11461139
type ScoreParams = ();
11471140
fn channel_penalty_msat(
1148-
&self, _candidate: &CandidateRouteHop, _usage: ChannelUsage, _score_params: &Self::ScoreParams
1141+
&self, _candidate: &CandidateRouteHop, _usage: ChannelUsage, _score_params: &lightning::routing::scoring::ProbabilisticScoringFeeParameters
11491142
) -> u64 { unimplemented!(); }
11501143
}
11511144

@@ -1263,12 +1256,12 @@ mod tests {
12631256
let genesis_block = genesis_block(network);
12641257
let network_graph = Arc::new(NetworkGraph::new(network, logger.clone()));
12651258
let scorer = Arc::new(LockingWrapper::new(TestScorer::new()));
1259+
let now = Duration::from_secs(genesis_block.header.time as u64);
12661260
let seed = [i as u8; 32];
1267-
let router = Arc::new(DefaultRouter::new(network_graph.clone(), logger.clone(), seed, scorer.clone(), Default::default()));
1261+
let keys_manager = Arc::new(KeysManager::new(&seed, now.as_secs(), now.subsec_nanos()));
1262+
let router = Arc::new(DefaultRouter::new(network_graph.clone(), logger.clone(), Arc::clone(&keys_manager), scorer.clone(), Default::default()));
12681263
let chain_source = Arc::new(test_utils::TestChainSource::new(Network::Bitcoin));
12691264
let kv_store = Arc::new(FilesystemStore::new(format!("{}_persister_{}", &persist_dir, i).into()));
1270-
let now = Duration::from_secs(genesis_block.header.time as u64);
1271-
let keys_manager = Arc::new(KeysManager::new(&seed, now.as_secs(), now.subsec_nanos()));
12721265
let chain_monitor = Arc::new(chainmonitor::ChainMonitor::new(Some(chain_source.clone()), tx_broadcaster.clone(), logger.clone(), fee_estimator.clone(), kv_store.clone()));
12731266
let best_block = BestBlock::from_network(network);
12741267
let params = ChainParameters { network, best_block };

lightning-invoice/src/payment.rs

Lines changed: 3 additions & 2 deletions
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::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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,8 @@ mod test {
825825
use lightning::ln::PaymentHash;
826826
#[cfg(feature = "std")]
827827
use lightning::ln::PaymentPreimage;
828-
use lightning::ln::channelmanager::{PhantomRouteHints, MIN_FINAL_CLTV_EXPIRY_DELTA, PaymentId, RecipientOnionFields, Retry};
828+
use lightning::ln::channelmanager::{PhantomRouteHints, MIN_FINAL_CLTV_EXPIRY_DELTA, PaymentId};
829+
use lightning::ln::outbound_payment::{RecipientOnionFields, Retry};
829830
use lightning::ln::functional_test_utils::*;
830831
use lightning::ln::msgs::ChannelMessageHandler;
831832
use lightning::routing::router::{PaymentParameters, RouteParameters};

lightning-rapid-gossip-sync/src/error.rs

Lines changed: 0 additions & 40 deletions
This file was deleted.

lightning-rapid-gossip-sync/src/lib.rs

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,42 @@ use core::ops::Deref;
7474
use core::sync::atomic::{AtomicBool, Ordering};
7575

7676
use lightning::io;
77+
use lightning::ln::msgs::{DecodeError, LightningError};
7778
use lightning::routing::gossip::NetworkGraph;
7879
use lightning::util::logger::Logger;
7980

80-
pub use crate::error::GraphSyncError;
81-
82-
/// Error types that these functions can return
83-
mod error;
84-
8581
/// Core functionality of this crate
8682
mod processing;
8783

84+
/// All-encompassing standard error type that processing can return
85+
#[derive(Debug)]
86+
pub enum GraphSyncError {
87+
/// Error trying to read the update data, typically due to an erroneous data length indication
88+
/// that is greater than the actual amount of data provided
89+
DecodeError(DecodeError),
90+
/// Error applying the patch to the network graph, usually the result of updates that are too
91+
/// old or missing prerequisite data to the application of updates out of order
92+
LightningError(LightningError),
93+
}
94+
95+
impl From<lightning::io::Error> for GraphSyncError {
96+
fn from(error: lightning::io::Error) -> Self {
97+
Self::DecodeError(DecodeError::Io(error.kind()))
98+
}
99+
}
100+
101+
impl From<DecodeError> for GraphSyncError {
102+
fn from(error: DecodeError) -> Self {
103+
Self::DecodeError(error)
104+
}
105+
}
106+
107+
impl From<LightningError> for GraphSyncError {
108+
fn from(error: LightningError) -> Self {
109+
Self::LightningError(error)
110+
}
111+
}
112+
88113
/// The main Rapid Gossip Sync object.
89114
///
90115
/// See [crate-level documentation] for usage.
@@ -167,7 +192,7 @@ mod tests {
167192
use lightning::ln::msgs::DecodeError;
168193
use lightning::routing::gossip::NetworkGraph;
169194
use lightning::util::test_utils::TestLogger;
170-
use crate::RapidGossipSync;
195+
use crate::{GraphSyncError, RapidGossipSync};
171196

172197
#[test]
173198
fn test_sync_from_file() {
@@ -265,7 +290,7 @@ mod tests {
265290
let start = std::time::Instant::now();
266291
let sync_result = rapid_sync
267292
.sync_network_graph_with_file_path("./res/full_graph.lngossip");
268-
if let Err(crate::error::GraphSyncError::DecodeError(DecodeError::Io(io_error))) = &sync_result {
293+
if let Err(GraphSyncError::DecodeError(DecodeError::Io(io_error))) = &sync_result {
269294
let error_string = format!("Input file lightning-rapid-gossip-sync/res/full_graph.lngossip is missing! Download it from https://bitcoin.ninja/ldk-compressed_graph-285cb27df79-2022-07-21.bin\n\n{:?}", io_error);
270295
#[cfg(not(require_route_graph_test))]
271296
{

lightning-rapid-gossip-sync/src/processing.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ use lightning::{log_debug, log_warn, log_trace, log_given_level, log_gossip};
1414
use lightning::util::ser::{BigSize, Readable};
1515
use lightning::io;
1616

17-
use crate::error::GraphSyncError;
18-
use crate::RapidGossipSync;
17+
use crate::{GraphSyncError, RapidGossipSync};
1918

2019
#[cfg(all(feature = "std", not(test)))]
2120
use std::time::{SystemTime, UNIX_EPOCH};
@@ -269,9 +268,8 @@ mod tests {
269268
use lightning::routing::gossip::NetworkGraph;
270269
use lightning::util::test_utils::TestLogger;
271270

272-
use crate::error::GraphSyncError;
273271
use crate::processing::STALE_RGS_UPDATE_AGE_LIMIT_SECS;
274-
use crate::RapidGossipSync;
272+
use crate::{GraphSyncError, RapidGossipSync};
275273

276274
const VALID_RGS_BINARY: [u8; 300] = [
277275
76, 68, 75, 1, 111, 226, 140, 10, 182, 241, 179, 114, 193, 166, 162, 70, 174, 99, 247,

lightning/src/blinded_path/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl BlindedPath {
9292
// be in relation to a specific channel.
9393
let htlc_maximum_msat = u64::max_value();
9494
Self::new_for_payment(
95-
&[], payee_node_id, payee_tlvs, htlc_maximum_msat, entropy_source, secp_ctx
95+
Vec::new(), payee_node_id, payee_tlvs, htlc_maximum_msat, entropy_source, secp_ctx
9696
)
9797
}
9898

@@ -106,19 +106,19 @@ impl BlindedPath {
106106
/// [`ForwardTlvs`]: crate::blinded_path::payment::ForwardTlvs
107107
// TODO: make all payloads the same size with padding + add dummy hops
108108
pub fn new_for_payment<ES: EntropySource + ?Sized, T: secp256k1::Signing + secp256k1::Verification>(
109-
intermediate_nodes: &[payment::ForwardNode], payee_node_id: PublicKey,
109+
intermediate_nodes: Vec<payment::ForwardNode>, payee_node_id: PublicKey,
110110
payee_tlvs: payment::ReceiveTlvs, htlc_maximum_msat: u64, entropy_source: &ES,
111111
secp_ctx: &Secp256k1<T>
112112
) -> Result<(BlindedPayInfo, Self), ()> {
113113
let blinding_secret_bytes = entropy_source.get_secure_random_bytes();
114114
let blinding_secret = SecretKey::from_slice(&blinding_secret_bytes[..]).expect("RNG is busted");
115115

116-
let blinded_payinfo = payment::compute_payinfo(intermediate_nodes, &payee_tlvs, htlc_maximum_msat)?;
116+
let blinded_payinfo = payment::compute_payinfo(&intermediate_nodes, &payee_tlvs, htlc_maximum_msat)?;
117117
Ok((blinded_payinfo, BlindedPath {
118118
introduction_node_id: intermediate_nodes.first().map_or(payee_node_id, |n| n.node_id),
119119
blinding_point: PublicKey::from_secret_key(secp_ctx, &blinding_secret),
120120
blinded_hops: payment::blinded_hops(
121-
secp_ctx, intermediate_nodes, payee_node_id, payee_tlvs, &blinding_secret
121+
secp_ctx, &intermediate_nodes, payee_node_id, payee_tlvs, &blinding_secret
122122
).map_err(|_| ())?,
123123
}))
124124
}

lightning/src/chain/channelmonitor.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ pub struct ChannelMonitor<Signer: WriteableEcdsaChannelSigner> {
753753
pub(super) inner: Mutex<ChannelMonitorImpl<Signer>>,
754754
}
755755

756-
impl<Signer: WriteableEcdsaChannelSigner> Clone for ChannelMonitor<Signer> where Signer: Clone {
756+
impl<Signer: WriteableEcdsaChannelSigner> Clone for ChannelMonitor<Signer> {
757757
fn clone(&self) -> Self {
758758
let inner = self.inner.lock().unwrap().clone();
759759
ChannelMonitor::from_impl(inner)
@@ -4338,8 +4338,8 @@ where
43384338

43394339
const MAX_ALLOC_SIZE: usize = 64*1024;
43404340

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

lightning/src/events/bump_transaction.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@ impl Utxo {
265265
}
266266

267267
/// Returns a `Utxo` with the `satisfaction_weight` estimate for a P2WPKH nested in P2SH output.
268+
///
269+
/// This is not exported to bindings users as WPubkeyHash is not yet exported
268270
pub fn new_nested_p2wpkh(outpoint: OutPoint, value: u64, pubkey_hash: &WPubkeyHash) -> Self {
269271
let script_sig_size = 1 /* script_sig length */ +
270272
1 /* OP_0 */ +
@@ -281,6 +283,8 @@ impl Utxo {
281283
}
282284

283285
/// Returns a `Utxo` with the `satisfaction_weight` estimate for a SegWit v0 P2WPKH output.
286+
///
287+
/// This is not exported to bindings users as WPubkeyHash is not yet exported
284288
pub fn new_v0_p2wpkh(outpoint: OutPoint, value: u64, pubkey_hash: &WPubkeyHash) -> Self {
285289
Self {
286290
outpoint,

lightning/src/ln/channel.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5604,7 +5604,7 @@ impl<SP: Deref> Channel<SP> where
56045604
return None;
56055605
}
56065606
};
5607-
let our_node_sig = match node_signer.sign_gossip_message(msgs::UnsignedGossipMessage::ChannelAnnouncement(&announcement)) {
5607+
let our_node_sig = match node_signer.sign_gossip_message(msgs::UnsignedGossipMessage::ChannelAnnouncement(announcement.clone())) {
56085608
Err(_) => {
56095609
log_error!(logger, "Failed to generate node signature for channel_announcement. Channel will not be announced!");
56105610
return None;
@@ -5650,7 +5650,7 @@ impl<SP: Deref> Channel<SP> where
56505650
.map_err(|_| ChannelError::Ignore("Signer failed to retrieve own public key".to_owned()))?);
56515651
let were_node_one = announcement.node_id_1 == our_node_key;
56525652

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

0 commit comments

Comments
 (0)