Skip to content

Commit e594021

Browse files
authored
Merge pull request #2847 from TheBlueMatt/2024-01-bindings-upstream
Misc Tweaks for bindings
2 parents 8d9d099 + fb693ec commit e594021

File tree

16 files changed

+157
-168
lines changed

16 files changed

+157
-168
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,9 @@ impl Router for FuzzRouter {
103103
})
104104
}
105105

106-
fn create_blinded_payment_paths<
107-
ES: EntropySource + ?Sized, T: secp256k1::Signing + secp256k1::Verification
108-
>(
106+
fn create_blinded_payment_paths<T: secp256k1::Signing + secp256k1::Verification>(
109107
&self, _recipient: PublicKey, _first_hops: Vec<ChannelDetails>, _tlvs: ReceiveTlvs,
110-
_amount_msats: u64, _entropy_source: &ES, _secp_ctx: &Secp256k1<T>
108+
_amount_msats: u64, _secp_ctx: &Secp256k1<T>,
111109
) -> Result<Vec<(BlindedPayInfo, BlindedPath)>, ()> {
112110
unreachable!()
113111
}
@@ -120,11 +118,8 @@ impl MessageRouter for FuzzRouter {
120118
unreachable!()
121119
}
122120

123-
fn create_blinded_paths<
124-
ES: EntropySource + ?Sized, T: secp256k1::Signing + secp256k1::Verification
125-
>(
126-
&self, _recipient: PublicKey, _peers: Vec<PublicKey>, _entropy_source: &ES,
127-
_secp_ctx: &Secp256k1<T>
121+
fn create_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
122+
&self, _recipient: PublicKey, _peers: Vec<PublicKey>, _secp_ctx: &Secp256k1<T>,
128123
) -> Result<Vec<BlindedPath>, ()> {
129124
unreachable!()
130125
}

fuzz/src/full_stack.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,9 @@ impl Router for FuzzRouter {
145145
})
146146
}
147147

148-
fn create_blinded_payment_paths<
149-
ES: EntropySource + ?Sized, T: secp256k1::Signing + secp256k1::Verification
150-
>(
148+
fn create_blinded_payment_paths<T: secp256k1::Signing + secp256k1::Verification>(
151149
&self, _recipient: PublicKey, _first_hops: Vec<ChannelDetails>, _tlvs: ReceiveTlvs,
152-
_amount_msats: u64, _entropy_source: &ES, _secp_ctx: &Secp256k1<T>
150+
_amount_msats: u64, _secp_ctx: &Secp256k1<T>,
153151
) -> Result<Vec<(BlindedPayInfo, BlindedPath)>, ()> {
154152
unreachable!()
155153
}
@@ -162,11 +160,8 @@ impl MessageRouter for FuzzRouter {
162160
unreachable!()
163161
}
164162

165-
fn create_blinded_paths<
166-
ES: EntropySource + ?Sized, T: secp256k1::Signing + secp256k1::Verification
167-
>(
168-
&self, _recipient: PublicKey, _peers: Vec<PublicKey>, _entropy_source: &ES,
169-
_secp_ctx: &Secp256k1<T>
163+
fn create_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
164+
&self, _recipient: PublicKey, _peers: Vec<PublicKey>, _secp_ctx: &Secp256k1<T>,
170165
) -> Result<Vec<BlindedPath>, ()> {
171166
unreachable!()
172167
}

fuzz/src/onion_message.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,8 @@ impl MessageRouter for TestMessageRouter {
8686
})
8787
}
8888

89-
fn create_blinded_paths<
90-
ES: EntropySource + ?Sized, T: secp256k1::Signing + secp256k1::Verification
91-
>(
92-
&self, _recipient: PublicKey, _peers: Vec<PublicKey>, _entropy_source: &ES,
93-
_secp_ctx: &Secp256k1<T>
89+
fn create_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
90+
&self, _recipient: PublicKey, _peers: Vec<PublicKey>, _secp_ctx: &Secp256k1<T>,
9491
) -> Result<Vec<BlindedPath>, ()> {
9592
unreachable!()
9693
}

lightning-background-processor/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,7 @@ mod tests {
984984
Arc<DefaultRouter<
985985
Arc<NetworkGraph<Arc<test_utils::TestLogger>>>,
986986
Arc<test_utils::TestLogger>,
987+
Arc<KeysManager>,
987988
Arc<LockingWrapper<TestScorer>>,
988989
(),
989990
TestScorer>
@@ -1263,12 +1264,12 @@ mod tests {
12631264
let genesis_block = genesis_block(network);
12641265
let network_graph = Arc::new(NetworkGraph::new(network, logger.clone()));
12651266
let scorer = Arc::new(LockingWrapper::new(TestScorer::new()));
1267+
let now = Duration::from_secs(genesis_block.header.time as u64);
12661268
let seed = [i as u8; 32];
1267-
let router = Arc::new(DefaultRouter::new(network_graph.clone(), logger.clone(), seed, scorer.clone(), Default::default()));
1269+
let keys_manager = Arc::new(KeysManager::new(&seed, now.as_secs(), now.subsec_nanos()));
1270+
let router = Arc::new(DefaultRouter::new(network_graph.clone(), logger.clone(), Arc::clone(&keys_manager), scorer.clone(), Default::default()));
12681271
let chain_source = Arc::new(test_utils::TestChainSource::new(Network::Bitcoin));
12691272
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()));
12721273
let chain_monitor = Arc::new(chainmonitor::ChainMonitor::new(Some(chain_source.clone()), tx_broadcaster.clone(), logger.clone(), fee_estimator.clone(), kv_store.clone()));
12731274
let best_block = BestBlock::from_network(network);
12741275
let params = ChainParameters { network, best_block };

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/ln/blinded_payment_tests.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,12 @@ fn three_hop_blinded_path_success() {
509509
let chan_upd_2_3 = create_announced_chan_between_nodes_with_value(&nodes, 2, 3, 1_000_000, 0).0.contents;
510510
let chan_upd_3_4 = create_announced_chan_between_nodes_with_value(&nodes, 3, 4, 1_000_000, 0).0.contents;
511511

512+
// Get all our nodes onto the same height so payments don't fail for CLTV violations.
513+
connect_blocks(&nodes[0], nodes[4].best_block_info().1 - nodes[0].best_block_info().1);
514+
connect_blocks(&nodes[1], nodes[4].best_block_info().1 - nodes[1].best_block_info().1);
515+
connect_blocks(&nodes[2], nodes[4].best_block_info().1 - nodes[2].best_block_info().1);
516+
assert_eq!(nodes[4].best_block_info().1, nodes[3].best_block_info().1);
517+
512518
let amt_msat = 5000;
513519
let (payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[4], Some(amt_msat), None);
514520
let route_params = get_blinded_route_parameters(amt_msat, payment_secret,

lightning/src/ln/channelmanager.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,7 @@ pub type SimpleArcChannelManager<M, T, F, L> = ChannelManager<
977977
Arc<DefaultRouter<
978978
Arc<NetworkGraph<Arc<L>>>,
979979
Arc<L>,
980+
Arc<KeysManager>,
980981
Arc<RwLock<ProbabilisticScorer<Arc<NetworkGraph<Arc<L>>>, Arc<L>>>>,
981982
ProbabilisticScoringFeeParameters,
982983
ProbabilisticScorer<Arc<NetworkGraph<Arc<L>>>, Arc<L>>,
@@ -1007,6 +1008,7 @@ pub type SimpleRefChannelManager<'a, 'b, 'c, 'd, 'e, 'f, 'g, 'h, M, T, F, L> =
10071008
&'e DefaultRouter<
10081009
&'f NetworkGraph<&'g L>,
10091010
&'g L,
1011+
&'c KeysManager,
10101012
&'h RwLock<ProbabilisticScorer<&'f NetworkGraph<&'g L>, &'g L>>,
10111013
ProbabilisticScoringFeeParameters,
10121014
ProbabilisticScorer<&'f NetworkGraph<&'g L>, &'g L>
@@ -7971,7 +7973,6 @@ where
79717973
/// Errors if the `MessageRouter` errors or returns an empty `Vec`.
79727974
fn create_blinded_path(&self) -> Result<BlindedPath, ()> {
79737975
let recipient = self.get_our_node_id();
7974-
let entropy_source = self.entropy_source.deref();
79757976
let secp_ctx = &self.secp_ctx;
79767977

79777978
let peers = self.per_peer_state.read().unwrap()
@@ -7981,7 +7982,7 @@ where
79817982
.collect::<Vec<_>>();
79827983

79837984
self.router
7984-
.create_blinded_paths(recipient, peers, entropy_source, secp_ctx)
7985+
.create_blinded_paths(recipient, peers, secp_ctx)
79857986
.and_then(|paths| paths.into_iter().next().ok_or(()))
79867987
}
79877988

@@ -7990,7 +7991,6 @@ where
79907991
fn create_blinded_payment_paths(
79917992
&self, amount_msats: u64, payment_secret: PaymentSecret
79927993
) -> Result<Vec<(BlindedPayInfo, BlindedPath)>, ()> {
7993-
let entropy_source = self.entropy_source.deref();
79947994
let secp_ctx = &self.secp_ctx;
79957995

79967996
let first_hops = self.list_usable_channels();
@@ -8005,7 +8005,7 @@ where
80058005
},
80068006
};
80078007
self.router.create_blinded_payment_paths(
8008-
payee_node_id, first_hops, payee_tlvs, amount_msats, entropy_source, secp_ctx
8008+
payee_node_id, first_hops, payee_tlvs, amount_msats, secp_ctx
80098009
)
80108010
}
80118011

lightning/src/ln/functional_test_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2980,7 +2980,7 @@ pub fn create_node_cfgs_with_persisters<'a>(node_count: usize, chanmon_cfgs: &'a
29802980
tx_broadcaster: &chanmon_cfgs[i].tx_broadcaster,
29812981
fee_estimator: &chanmon_cfgs[i].fee_estimator,
29822982
router: test_utils::TestRouter::new(network_graph.clone(), &chanmon_cfgs[i].logger, &chanmon_cfgs[i].scorer),
2983-
message_router: test_utils::TestMessageRouter::new(network_graph.clone()),
2983+
message_router: test_utils::TestMessageRouter::new(network_graph.clone(), &chanmon_cfgs[i].keys_manager),
29842984
chain_monitor,
29852985
keys_manager: &chanmon_cfgs[i].keys_manager,
29862986
node_seed: seed,

lightning/src/ln/functional_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5547,7 +5547,7 @@ fn test_key_derivation_params() {
55475547
let network_graph = Arc::new(NetworkGraph::new(Network::Testnet, &chanmon_cfgs[0].logger));
55485548
let scorer = RwLock::new(test_utils::TestScorer::new());
55495549
let router = test_utils::TestRouter::new(network_graph.clone(), &chanmon_cfgs[0].logger, &scorer);
5550-
let message_router = test_utils::TestMessageRouter::new(network_graph.clone());
5550+
let message_router = test_utils::TestMessageRouter::new(network_graph.clone(), &keys_manager);
55515551
let node = NodeCfg { chain_source: &chanmon_cfgs[0].chain_source, logger: &chanmon_cfgs[0].logger, tx_broadcaster: &chanmon_cfgs[0].tx_broadcaster, fee_estimator: &chanmon_cfgs[0].fee_estimator, router, message_router, chain_monitor, keys_manager: &keys_manager, network_graph, node_seed: seed, override_init_features: alloc::rc::Rc::new(core::cell::RefCell::new(None)) };
55525552
let mut node_cfgs = create_node_cfgs(3, &chanmon_cfgs);
55535553
node_cfgs.remove(0);

lightning/src/onion_message/functional_tests.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::blinded_path::BlindedPath;
1313
use crate::events::{Event, EventsProvider};
1414
use crate::ln::features::InitFeatures;
1515
use crate::ln::msgs::{self, DecodeError, OnionMessageHandler, SocketAddress};
16-
use crate::sign::{EntropySource, NodeSigner, Recipient};
16+
use crate::sign::{NodeSigner, Recipient};
1717
use crate::util::ser::{FixedLengthReader, LengthReadable, Writeable, Writer};
1818
use crate::util::test_utils;
1919
use super::messenger::{CustomOnionMessageHandler, Destination, MessageRouter, OnionMessagePath, OnionMessenger, PendingOnionMessage, SendError};
@@ -59,10 +59,9 @@ impl MessageRouter for TestMessageRouter {
5959
}
6060

6161
fn create_blinded_paths<
62-
ES: EntropySource + ?Sized, T: secp256k1::Signing + secp256k1::Verification
62+
T: secp256k1::Signing + secp256k1::Verification
6363
>(
64-
&self, _recipient: PublicKey, _peers: Vec<PublicKey>, _entropy_source: &ES,
65-
_secp_ctx: &Secp256k1<T>
64+
&self, _recipient: PublicKey, _peers: Vec<PublicKey>, _secp_ctx: &Secp256k1<T>,
6665
) -> Result<Vec<BlindedPath>, ()> {
6766
unreachable!()
6867
}

0 commit comments

Comments
 (0)