Skip to content

Commit 3b4ec0a

Browse files
authored
Fix tests for LSPS4 and Logger generic additions (#19)
LiquidityManager gained an 8th generic parameter (Logger) and KVStore targets now require KVStoreSync. Several test files and doctests were not updated after these changes landed. background-processor: The NO_LIQUIDITY_MANAGER const uses a dyn trait object for KVStore, but trait objects can only name one trait. Add a KVStoreFull supertrait combining KVStore and KVStoreSync so the dyn bound remains expressible. Add the Logger generic and KVStoreSync impl to the process_events_async doctest's stub Store type. lightning-liquidity tests: Add missing lsps4_service_config and lsps4_client_config fields (None) to config initializers in lsps0, lsps2, and lsps5 integration tests. Pass logger to LiquidityManagerSync::new calls and add TestLogger to type annotations. channel.rs tests: Remove duplicate import block left over from a bad merge in 736d3a8. Fix field accesses that moved from ChannelContext to FundingScope (channel_value_satoshis, holder_selected_channel_reserve_satoshis). Update TestFeeEstimator construction to use the new constructor API.
1 parent a10b923 commit 3b4ec0a

6 files changed

Lines changed: 50 additions & 41 deletions

File tree

lightning-background-processor/src/lib.rs

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,11 @@ pub const NO_ONION_MESSENGER: Option<
416416
>,
417417
> = None;
418418

419+
/// Supertrait combining [`KVStore`] and [`KVStoreSync`] so that a single `dyn` trait object can
420+
/// satisfy the bounds required by [`ALiquidityManager`].
421+
pub trait KVStoreFull: KVStore + KVStoreSync {}
422+
impl<T: KVStore + KVStoreSync + ?Sized> KVStoreFull for T {}
423+
419424
/// When initializing a background processor without a liquidity manager, this can be used to avoid
420425
/// specifying a concrete `LiquidityManager` type.
421426
#[cfg(not(c_bindings))]
@@ -430,8 +435,8 @@ pub const NO_LIQUIDITY_MANAGER: Option<
430435
CM = &DynChannelManager,
431436
Filter = dyn chain::Filter + Send + Sync,
432437
C = &(dyn chain::Filter + Send + Sync),
433-
KVStore = dyn lightning::util::persist::KVStore + Send + Sync,
434-
K = &(dyn lightning::util::persist::KVStore + Send + Sync),
438+
KVStore = dyn KVStoreFull + Send + Sync,
439+
K = &(dyn KVStoreFull + Send + Sync),
435440
TimeProvider = dyn lightning_liquidity::utils::time::TimeProvider + Send + Sync,
436441
TP = &(dyn lightning_liquidity::utils::time::TimeProvider + Send + Sync),
437442
BroadcasterInterface = dyn lightning::chain::chaininterface::BroadcasterInterface
@@ -762,6 +767,12 @@ use futures_util::{dummy_waker, Joiner, OptionalSelector, Selector, SelectorOutp
762767
/// # fn remove(&self, primary_namespace: &str, secondary_namespace: &str, key: &str, lazy: bool) -> Pin<Box<dyn Future<Output = Result<(), io::Error>> + 'static + Send>> { todo!() }
763768
/// # fn list(&self, primary_namespace: &str, secondary_namespace: &str) -> Pin<Box<dyn Future<Output = Result<Vec<String>, io::Error>> + 'static + Send>> { todo!() }
764769
/// # }
770+
/// # impl lightning::util::persist::KVStoreSync for Store {
771+
/// # fn read(&self, primary_namespace: &str, secondary_namespace: &str, key: &str) -> io::Result<Vec<u8>> { Ok(Vec::new()) }
772+
/// # fn write(&self, primary_namespace: &str, secondary_namespace: &str, key: &str, buf: Vec<u8>) -> io::Result<()> { Ok(()) }
773+
/// # fn remove(&self, primary_namespace: &str, secondary_namespace: &str, key: &str, lazy: bool) -> io::Result<()> { Ok(()) }
774+
/// # fn list(&self, primary_namespace: &str, secondary_namespace: &str) -> io::Result<Vec<String>> { Ok(Vec::new()) }
775+
/// # }
765776
/// # use core::time::Duration;
766777
/// # struct DefaultTimeProvider;
767778
/// #
@@ -786,7 +797,7 @@ use futures_util::{dummy_waker, Joiner, OptionalSelector, Selector, SelectorOutp
786797
/// # type P2PGossipSync<UL> = lightning::routing::gossip::P2PGossipSync<Arc<NetworkGraph>, Arc<UL>, Arc<Logger>>;
787798
/// # type ChannelManager<B, F, FE> = lightning::ln::channelmanager::SimpleArcChannelManager<ChainMonitor<B, F, FE>, B, FE, Logger>;
788799
/// # type OnionMessenger<B, F, FE> = lightning::onion_message::messenger::OnionMessenger<Arc<lightning::sign::KeysManager>, Arc<lightning::sign::KeysManager>, Arc<Logger>, Arc<ChannelManager<B, F, FE>>, Arc<lightning::onion_message::messenger::DefaultMessageRouter<Arc<NetworkGraph>, Arc<Logger>, Arc<lightning::sign::KeysManager>>>, Arc<ChannelManager<B, F, FE>>, lightning::ln::peer_handler::IgnoringMessageHandler, lightning::ln::peer_handler::IgnoringMessageHandler, lightning::ln::peer_handler::IgnoringMessageHandler>;
789-
/// # type LiquidityManager<B, F, FE> = lightning_liquidity::LiquidityManager<Arc<lightning::sign::KeysManager>, Arc<lightning::sign::KeysManager>, Arc<ChannelManager<B, F, FE>>, Arc<F>, Arc<Store>, Arc<DefaultTimeProvider>, Arc<B>>;
800+
/// # type LiquidityManager<B, F, FE> = lightning_liquidity::LiquidityManager<Arc<lightning::sign::KeysManager>, Arc<lightning::sign::KeysManager>, Arc<ChannelManager<B, F, FE>>, Arc<F>, Arc<Store>, Arc<DefaultTimeProvider>, Arc<B>, Arc<Logger>>;
790801
/// # type Scorer = RwLock<lightning::routing::scoring::ProbabilisticScorer<Arc<NetworkGraph>, Arc<Logger>>>;
791802
/// # type PeerManager<B, F, FE, UL> = lightning::ln::peer_handler::SimpleArcPeerManager<SocketDescriptor, ChainMonitor<B, F, FE>, B, FE, Arc<UL>, Logger, F, StoreSync>;
792803
/// # type OutputSweeper<B, D, FE, F, O> = lightning::util::sweep::OutputSweeper<Arc<B>, Arc<D>, Arc<FE>, Arc<F>, Arc<Store>, Arc<Logger>, Arc<O>>;
@@ -1967,6 +1978,7 @@ mod tests {
19671978
Arc<Persister>,
19681979
DefaultTimeProvider,
19691980
Arc<test_utils::TestBroadcaster>,
1981+
Arc<test_utils::TestLogger>,
19701982
>;
19711983

19721984
struct Node {
@@ -2426,6 +2438,7 @@ mod tests {
24262438
Arc::clone(&tx_broadcaster),
24272439
None,
24282440
None,
2441+
Arc::clone(&logger),
24292442
)
24302443
.unwrap(),
24312444
);
@@ -2798,10 +2811,10 @@ mod tests {
27982811
let kv_store = KVStoreSyncWrapper(kv_store_sync);
27992812

28002813
// Yes, you can unsafe { turn off the borrow checker }
2801-
let lm_async: &'static LiquidityManager<_, _, _, _, _, _, _> = unsafe {
2814+
let lm_async: &'static LiquidityManager<_, _, _, _, _, _, _, _> = unsafe {
28022815
&*(nodes[0].liquidity_manager.get_lm_async()
2803-
as *const LiquidityManager<_, _, _, _, _, _, _>)
2804-
as &'static LiquidityManager<_, _, _, _, _, _, _>
2816+
as *const LiquidityManager<_, _, _, _, _, _, _, _>)
2817+
as &'static LiquidityManager<_, _, _, _, _, _, _, _>
28052818
};
28062819
let sweeper_async: &'static OutputSweeper<_, _, _, _, _, _, _> = unsafe {
28072820
&*(nodes[0].sweeper.sweeper_async() as *const OutputSweeper<_, _, _, _, _, _, _>)
@@ -3317,10 +3330,10 @@ mod tests {
33173330
let kv_store = KVStoreSyncWrapper(kv_store_sync);
33183331

33193332
// Yes, you can unsafe { turn off the borrow checker }
3320-
let lm_async: &'static LiquidityManager<_, _, _, _, _, _, _> = unsafe {
3333+
let lm_async: &'static LiquidityManager<_, _, _, _, _, _, _, _> = unsafe {
33213334
&*(nodes[0].liquidity_manager.get_lm_async()
3322-
as *const LiquidityManager<_, _, _, _, _, _, _>)
3323-
as &'static LiquidityManager<_, _, _, _, _, _, _>
3335+
as *const LiquidityManager<_, _, _, _, _, _, _, _>)
3336+
as &'static LiquidityManager<_, _, _, _, _, _, _, _>
33243337
};
33253338
let sweeper_async: &'static OutputSweeper<_, _, _, _, _, _, _> = unsafe {
33263339
&*(nodes[0].sweeper.sweeper_async() as *const OutputSweeper<_, _, _, _, _, _, _>)
@@ -3544,10 +3557,10 @@ mod tests {
35443557
let (exit_sender, exit_receiver) = tokio::sync::watch::channel(());
35453558

35463559
// Yes, you can unsafe { turn off the borrow checker }
3547-
let lm_async: &'static LiquidityManager<_, _, _, _, _, _, _> = unsafe {
3560+
let lm_async: &'static LiquidityManager<_, _, _, _, _, _, _, _> = unsafe {
35483561
&*(nodes[0].liquidity_manager.get_lm_async()
3549-
as *const LiquidityManager<_, _, _, _, _, _, _>)
3550-
as &'static LiquidityManager<_, _, _, _, _, _, _>
3562+
as *const LiquidityManager<_, _, _, _, _, _, _, _>)
3563+
as &'static LiquidityManager<_, _, _, _, _, _, _, _>
35513564
};
35523565
let sweeper_async: &'static OutputSweeper<_, _, _, _, _, _, _> = unsafe {
35533566
&*(nodes[0].sweeper.sweeper_async() as *const OutputSweeper<_, _, _, _, _, _, _>)

lightning-liquidity/tests/common/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use lightning_liquidity::{LiquidityClientConfig, LiquidityManagerSync, Liquidity
66
use lightning::chain::{BestBlock, Filter};
77
use lightning::ln::channelmanager::ChainParameters;
88
use lightning::ln::functional_test_utils::{Node, TestChannelManager};
9-
use lightning::util::test_utils::{TestBroadcaster, TestKeysInterface, TestStore};
9+
use lightning::util::test_utils::{TestBroadcaster, TestKeysInterface, TestLogger, TestStore};
1010

1111
use bitcoin::Network;
1212

@@ -47,6 +47,7 @@ fn build_service_and_client_nodes<'a, 'b, 'c>(
4747
Some(service_config),
4848
None,
4949
Arc::clone(&time_provider),
50+
service_inner.logger,
5051
)
5152
.unwrap();
5253

@@ -61,6 +62,7 @@ fn build_service_and_client_nodes<'a, 'b, 'c>(
6162
None,
6263
Some(client_config),
6364
time_provider,
65+
client_inner.logger,
6466
)
6567
.unwrap();
6668

@@ -141,6 +143,7 @@ pub(crate) struct LiquidityNode<'a, 'b, 'c> {
141143
Arc<TestStore>,
142144
Arc<dyn TimeProvider + Send + Sync>,
143145
&'c TestBroadcaster,
146+
&'c TestLogger,
144147
>,
145148
}
146149

@@ -155,6 +158,7 @@ impl<'a, 'b, 'c> LiquidityNode<'a, 'b, 'c> {
155158
Arc<TestStore>,
156159
Arc<dyn TimeProvider + Send + Sync>,
157160
&'c TestBroadcaster,
161+
&'c TestLogger,
158162
>,
159163
) -> Self {
160164
Self { inner: node, liquidity_manager }

lightning-liquidity/tests/lsps0_integration_tests.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ fn list_protocols_integration_test() {
4040
#[cfg(lsps1_service)]
4141
lsps1_service_config: Some(lsps1_service_config),
4242
lsps2_service_config: Some(lsps2_service_config),
43+
lsps4_service_config: None,
4344
lsps5_service_config: Some(lsps5_service_config),
4445
advertise_service: true,
4546
};
@@ -54,6 +55,7 @@ fn list_protocols_integration_test() {
5455
#[cfg(not(lsps1_service))]
5556
lsps1_client_config: None,
5657
lsps2_client_config: Some(lsps2_client_config),
58+
lsps4_client_config: None,
5759
lsps5_client_config: Some(lsps5_client_config),
5860
};
5961

lightning-liquidity/tests/lsps2_integration_tests.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ fn build_lsps2_configs() -> ([u8; 32], LiquidityServiceConfig, LiquidityClientCo
7373
#[cfg(lsps1_service)]
7474
lsps1_service_config: None,
7575
lsps2_service_config: Some(lsps2_service_config),
76+
lsps4_service_config: None,
7677
lsps5_service_config: None,
7778
advertise_service: true,
7879
};
@@ -81,6 +82,7 @@ fn build_lsps2_configs() -> ([u8; 32], LiquidityServiceConfig, LiquidityClientCo
8182
let client_config = LiquidityClientConfig {
8283
lsps1_client_config: None,
8384
lsps2_client_config: Some(lsps2_client_config),
85+
lsps4_client_config: None,
8486
lsps5_client_config: None,
8587
};
8688

@@ -958,6 +960,7 @@ fn lsps2_service_handler_persistence_across_restarts() {
958960
#[cfg(lsps1_service)]
959961
lsps1_service_config: None,
960962
lsps2_service_config: Some(LSPS2ServiceConfig { promise_secret }),
963+
lsps4_service_config: None,
961964
lsps5_service_config: None,
962965
advertise_service: true,
963966
};
@@ -1102,6 +1105,7 @@ fn lsps2_service_handler_persistence_across_restarts() {
11021105
Some(service_config),
11031106
None,
11041107
time_provider,
1108+
nodes_restart[0].logger,
11051109
)
11061110
.unwrap();
11071111

lightning-liquidity/tests/lsps5_integration_tests.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ pub(crate) fn lsps5_test_setup_with_kv_stores<'a, 'b, 'c>(
5959
#[cfg(lsps1_service)]
6060
lsps1_service_config: None,
6161
lsps2_service_config: None,
62+
lsps4_service_config: None,
6263
lsps5_service_config: Some(lsps5_service_config),
6364
advertise_service: true,
6465
};
@@ -68,6 +69,7 @@ pub(crate) fn lsps5_test_setup_with_kv_stores<'a, 'b, 'c>(
6869
let client_config = LiquidityClientConfig {
6970
lsps1_client_config: None,
7071
lsps2_client_config: None,
72+
lsps4_client_config: None,
7173
lsps5_client_config: Some(lsps5_client_config),
7274
};
7375

@@ -243,6 +245,7 @@ pub(crate) fn lsps5_lsps2_test_setup<'a, 'b, 'c>(
243245
#[cfg(lsps1_service)]
244246
lsps1_service_config: None,
245247
lsps2_service_config: Some(lsps2_service_config),
248+
lsps4_service_config: None,
246249
lsps5_service_config: Some(lsps5_service_config),
247250
advertise_service: true,
248251
};
@@ -252,6 +255,7 @@ pub(crate) fn lsps5_lsps2_test_setup<'a, 'b, 'c>(
252255
let client_config = LiquidityClientConfig {
253256
lsps1_client_config: None,
254257
lsps2_client_config: Some(lsps2_client_config),
258+
lsps4_client_config: None,
255259
lsps5_client_config: Some(lsps5_client_config),
256260
};
257261

@@ -1519,6 +1523,7 @@ fn lsps5_service_handler_persistence_across_restarts() {
15191523
#[cfg(lsps1_service)]
15201524
lsps1_service_config: None,
15211525
lsps2_service_config: None,
1526+
lsps4_service_config: None,
15221527
lsps5_service_config: Some(LSPS5ServiceConfig::default()),
15231528
advertise_service: true,
15241529
};
@@ -1619,6 +1624,7 @@ fn lsps5_service_handler_persistence_across_restarts() {
16191624
Some(service_config),
16201625
None,
16211626
Arc::clone(&time_provider),
1627+
nodes_restart[0].logger,
16221628
)
16231629
.unwrap();
16241630

lightning/src/ln/channel.rs

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15743,28 +15743,7 @@ pub(crate) fn hold_time_since(send_timestamp: Option<Duration>) -> Option<u32> {
1574315743

1574415744
#[cfg(test)]
1574515745
mod tests {
15746-
use std::cmp;
15747-
use bitcoin::amount::Amount;
15748-
use bitcoin::constants::ChainHash;
15749-
use bitcoin::script::{ScriptBuf, Builder};
15750-
use bitcoin::transaction::{Transaction, TxOut, Version};
15751-
use bitcoin::opcodes;
15752-
use bitcoin::network::Network;
15753-
use crate::ln::onion_utils::INVALID_ONION_BLINDING;
15754-
use crate::types::payment::{PaymentHash, PaymentPreimage};
15755-
use crate::ln::channel_keys::{RevocationKey, RevocationBasepoint};
15756-
use crate::ln::channelmanager::{self, HTLCSource, PaymentId};
15757-
use crate::ln::channel::InitFeatures;
15758-
use crate::ln::channel::{AwaitingChannelReadyFlags, Channel, ChannelState, InboundHTLCOutput, OutboundV1Channel, InboundV1Channel, OutboundHTLCOutput, InboundHTLCState, OutboundHTLCState, HTLCCandidate, HTLCInitiator, HTLCUpdateAwaitingACK, commit_tx_fee_sat};
15759-
use crate::ln::channel::{MAX_FUNDING_SATOSHIS_NO_WUMBO, TOTAL_BITCOIN_SUPPLY_SATOSHIS};
15760-
use crate::types::features::{ChannelFeatures, ChannelTypeFeatures, NodeFeatures};
15761-
use crate::ln::msgs;
15762-
use crate::ln::msgs::{ChannelUpdate, DecodeError, UnsignedChannelUpdate, MAX_VALUE_MSAT};
15763-
use crate::ln::script::ShutdownScript;
15764-
use crate::ln::chan_utils::{self, htlc_success_tx_weight, htlc_timeout_tx_weight};
15765-
use crate::chain::BestBlock;
15766-
use crate::chain::chaininterface::{FeeEstimator, LowerBoundedFeeEstimator, ConfirmationTarget};
15767-
use crate::sign::{ChannelSigner, InMemorySigner, EntropySource, SignerProvider};
15746+
use crate::chain::chaininterface::LowerBoundedFeeEstimator;
1576815747
use crate::chain::transaction::OutPoint;
1576915748
use crate::chain::BestBlock;
1577015749
use crate::ln::chan_utils::{self, commit_tx_fee_sat, ChannelTransactionParameters};
@@ -16290,8 +16269,8 @@ mod tests {
1629016269
outbound_node_config.channel_handshake_config.their_channel_reserve_proportional_millionths = (outbound_selected_channel_reserve_perc * 1_000_000.0) as u32;
1629116270
let mut chan = OutboundV1Channel::<&TestKeysInterface>::new(&&fee_est, &&keys_provider, &&keys_provider, outbound_node_id, &channelmanager::provided_init_features(&outbound_node_config), channel_value_satoshis, 100_000, 42, &outbound_node_config, 0, 42, None, &logger).unwrap();
1629216271

16293-
let expected_outbound_selected_chan_reserve = cmp::max(outbound_node_config.channel_handshake_config.min_their_channel_reserve_satoshis, (chan.context.channel_value_satoshis as f64 * outbound_selected_channel_reserve_perc) as u64);
16294-
assert_eq!(chan.context.holder_selected_channel_reserve_satoshis, expected_outbound_selected_chan_reserve);
16272+
let expected_outbound_selected_chan_reserve = cmp::max(outbound_node_config.channel_handshake_config.min_their_channel_reserve_satoshis, (chan.funding.get_value_satoshis() as f64 * outbound_selected_channel_reserve_perc) as u64);
16273+
assert_eq!(chan.funding.holder_selected_channel_reserve_satoshis, expected_outbound_selected_chan_reserve);
1629516274

1629616275
let chan_open_channel_msg = chan.get_open_channel(ChainHash::using_genesis_block(network), &&logger).unwrap();
1629716276
let mut inbound_node_config = UserConfig::default();
@@ -16300,7 +16279,7 @@ mod tests {
1630016279
if outbound_selected_channel_reserve_perc + inbound_selected_channel_reserve_perc < 1.0 {
1630116280
let chan_inbound_node = InboundV1Channel::<&TestKeysInterface>::new(&&fee_est, &&keys_provider, &&keys_provider, inbound_node_id, &channelmanager::provided_channel_type_features(&inbound_node_config), &channelmanager::provided_init_features(&outbound_node_config), &chan_open_channel_msg, 7, &inbound_node_config, 0, &&logger, /*is_0conf=*/false).unwrap();
1630216281

16303-
let expected_inbound_selected_chan_reserve = cmp::max(inbound_node_config.channel_handshake_config.min_their_channel_reserve_satoshis, (chan.context.channel_value_satoshis as f64 * inbound_selected_channel_reserve_perc) as u64);
16282+
let expected_inbound_selected_chan_reserve = cmp::max(inbound_node_config.channel_handshake_config.min_their_channel_reserve_satoshis, (chan.funding.get_value_satoshis() as f64 * inbound_selected_channel_reserve_perc) as u64);
1630416283

1630516284
assert_eq!(chan_inbound_node.funding.holder_selected_channel_reserve_satoshis, expected_inbound_selected_chan_reserve);
1630616285
assert_eq!(chan_inbound_node.funding.counterparty_selected_channel_reserve_satoshis.unwrap(), expected_outbound_selected_chan_reserve);
@@ -16314,7 +16293,8 @@ mod tests {
1631416293
#[test]
1631516294
#[rustfmt::skip]
1631616295
fn test_configurable_min_channel_reserve() {
16317-
let fee_est = LowerBoundedFeeEstimator::new(&TestFeeEstimator { fee_est: 15_000 });
16296+
let inner_fee_est = TestFeeEstimator::new(15_000);
16297+
let fee_est = LowerBoundedFeeEstimator::new(&inner_fee_est);
1631816298
let logger = test_utils::TestLogger::new();
1631916299
let secp_ctx = Secp256k1::new();
1632016300
let keys_provider = test_utils::TestKeysInterface::new(&[42; 32], Network::Testnet);
@@ -16332,7 +16312,7 @@ mod tests {
1633216312
).unwrap();
1633316313

1633416314
// With 0 minimum and 0 proportional, reserve should be 0 (bypasses dust limit)
16335-
assert_eq!(chan.context.holder_selected_channel_reserve_satoshis, 0);
16315+
assert_eq!(chan.funding.holder_selected_channel_reserve_satoshis, 0);
1633616316

1633716317
// Test with custom minimum enforced when proportional is lower
1633816318
config.channel_handshake_config.min_their_channel_reserve_satoshis = 10_000;
@@ -16345,7 +16325,7 @@ mod tests {
1634516325
).unwrap();
1634616326

1634716327
// Proportional would be 1% of 100k = 1000, but minimum is 10000, so 10000 should be used
16348-
assert_eq!(chan_small.context.holder_selected_channel_reserve_satoshis, 10_000);
16328+
assert_eq!(chan_small.funding.holder_selected_channel_reserve_satoshis, 10_000);
1634916329

1635016330
// Test that dust limit is still enforced when min_their_channel_reserve_satoshis is non-zero but below dust limit
1635116331
config.channel_handshake_config.min_their_channel_reserve_satoshis = 100; // Below dust limit of 354

0 commit comments

Comments
 (0)