Skip to content

Commit ac95bc0

Browse files
committed
Update Test Framework
This commit introduces `OffersMessageFlow` in `functional_test`, transitioning the source of `OffersMessageHandler` implementation to `OffersMessageFlow`. With this change, the `ChannelManager`'s implementation becomes redundant and will be removed in the next commit.
1 parent 57e8ccc commit ac95bc0

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

lightning/src/ln/functional_test_utils.rs

+25-6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use crate::chain::transaction::OutPoint;
1616
use crate::events::{ClaimedHTLC, ClosureReason, Event, HTLCDestination, MessageSendEvent, MessageSendEventsProvider, PathFailure, PaymentPurpose, PaymentFailureReason};
1717
use crate::events::bump_transaction::{BumpTransactionEvent, BumpTransactionEventHandler, Wallet, WalletSource};
1818
use crate::ln::types::ChannelId;
19+
use crate::offers::flow::OffersMessageFlow;
1920
use crate::types::payment::{PaymentPreimage, PaymentHash, PaymentSecret};
2021
use crate::ln::channelmanager::{AChannelManager, ChainParameters, ChannelManager, ChannelManagerReadArgs, OffersMessageCommons, PaymentId, PaymentSendFailure, RAACommitmentOrder, RecipientOnionFields, MIN_CLTV_EXPIRY_DELTA};
2122
use crate::types::features::InitFeatures;
@@ -408,14 +409,21 @@ type TestChannelManager<'node_cfg, 'chan_mon_cfg> = ChannelManager<
408409
&'chan_mon_cfg test_utils::TestLogger,
409410
>;
410411

412+
pub type TestOffersMessageFlow<'chan_man, 'node_cfg, 'chan_mon_cfg> = OffersMessageFlow<
413+
&'node_cfg test_utils::TestKeysInterface,
414+
&'chan_man TestChannelManager<'node_cfg, 'chan_mon_cfg>,
415+
&'node_cfg test_utils::TestKeysInterface,
416+
&'chan_mon_cfg test_utils::TestLogger,
417+
>;
418+
411419
#[cfg(not(feature = "dnssec"))]
412420
type TestOnionMessenger<'chan_man, 'node_cfg, 'chan_mon_cfg> = OnionMessenger<
413421
DedicatedEntropy,
414422
&'node_cfg test_utils::TestKeysInterface,
415423
&'chan_mon_cfg test_utils::TestLogger,
416424
&'chan_man TestChannelManager<'node_cfg, 'chan_mon_cfg>,
417425
&'node_cfg test_utils::TestMessageRouter<'chan_mon_cfg>,
418-
&'chan_man TestChannelManager<'node_cfg, 'chan_mon_cfg>,
426+
Arc<TestOffersMessageFlow<'chan_man, 'node_cfg, 'chan_mon_cfg>>,
419427
&'chan_man TestChannelManager<'node_cfg, 'chan_mon_cfg>,
420428
IgnoringMessageHandler,
421429
IgnoringMessageHandler,
@@ -428,7 +436,7 @@ type TestOnionMessenger<'chan_man, 'node_cfg, 'chan_mon_cfg> = OnionMessenger<
428436
&'chan_mon_cfg test_utils::TestLogger,
429437
&'chan_man TestChannelManager<'node_cfg, 'chan_mon_cfg>,
430438
&'node_cfg test_utils::TestMessageRouter<'chan_mon_cfg>,
431-
&'chan_man TestChannelManager<'node_cfg, 'chan_mon_cfg>,
439+
Arc<TestOffersMessageFlow<'chan_man, 'node_cfg, 'chan_mon_cfg>>,
432440
&'chan_man TestChannelManager<'node_cfg, 'chan_mon_cfg>,
433441
&'chan_man TestChannelManager<'node_cfg, 'chan_mon_cfg>,
434442
IgnoringMessageHandler,
@@ -455,6 +463,7 @@ pub struct Node<'chan_man, 'node_cfg: 'chan_man, 'chan_mon_cfg: 'node_cfg> {
455463
pub keys_manager: &'chan_mon_cfg test_utils::TestKeysInterface,
456464
pub node: &'chan_man TestChannelManager<'node_cfg, 'chan_mon_cfg>,
457465
pub onion_messenger: TestOnionMessenger<'chan_man, 'node_cfg, 'chan_mon_cfg>,
466+
pub offers_handler: Arc<TestOffersMessageFlow<'chan_man, 'node_cfg, 'chan_mon_cfg>>,
458467
pub network_graph: &'node_cfg NetworkGraph<&'chan_mon_cfg test_utils::TestLogger>,
459468
pub gossip_sync: P2PGossipSync<&'node_cfg NetworkGraph<&'chan_mon_cfg test_utils::TestLogger>, &'chan_mon_cfg test_utils::TestChainSource, &'chan_mon_cfg test_utils::TestLogger>,
460469
pub node_seed: [u8; 32],
@@ -1181,8 +1190,14 @@ macro_rules! reload_node {
11811190
$node.chain_monitor = &$new_chain_monitor;
11821191

11831192
$new_channelmanager = _reload_node(&$node, $new_config, &chanman_encoded, $monitors_encoded);
1193+
1194+
let offers_handler = $crate::sync::Arc::new($crate::offers::flow::OffersMessageFlow::new(
1195+
$node.keys_manager, &$new_channelmanager, $node.keys_manager, $node.logger
1196+
));
1197+
11841198
$node.node = &$new_channelmanager;
1185-
$node.onion_messenger.set_offers_handler(&$new_channelmanager);
1199+
$node.offers_handler = offers_handler.clone();
1200+
$node.onion_messenger.set_offers_handler(offers_handler);
11861201
};
11871202
($node: expr, $chanman_encoded: expr, $monitors_encoded: expr, $persister: ident, $new_chain_monitor: ident, $new_channelmanager: ident) => {
11881203
reload_node!($node, $crate::util::config::UserConfig::default(), $chanman_encoded, $monitors_encoded, $persister, $new_chain_monitor, $new_channelmanager);
@@ -3308,16 +3323,19 @@ pub fn create_network<'a, 'b: 'a, 'c: 'b>(node_count: usize, cfgs: &'b Vec<NodeC
33083323

33093324
for i in 0..node_count {
33103325
let dedicated_entropy = DedicatedEntropy(RandomBytes::new([i as u8; 32]));
3326+
let offers_handler = Arc::new(OffersMessageFlow::new(
3327+
cfgs[i].keys_manager, &chan_mgrs[i], cfgs[i].keys_manager, cfgs[i].logger
3328+
));
33113329
#[cfg(feature = "dnssec")]
33123330
let onion_messenger = OnionMessenger::new(
33133331
dedicated_entropy, cfgs[i].keys_manager, cfgs[i].logger, &chan_mgrs[i],
3314-
&cfgs[i].message_router, &chan_mgrs[i], &chan_mgrs[i], &chan_mgrs[i],
3332+
&cfgs[i].message_router, offers_handler.clone(), &chan_mgrs[i], &chan_mgrs[i],
33153333
IgnoringMessageHandler {},
33163334
);
33173335
#[cfg(not(feature = "dnssec"))]
33183336
let onion_messenger = OnionMessenger::new(
33193337
dedicated_entropy, cfgs[i].keys_manager, cfgs[i].logger, &chan_mgrs[i],
3320-
&cfgs[i].message_router, &chan_mgrs[i], &chan_mgrs[i], IgnoringMessageHandler {},
3338+
&cfgs[i].message_router, offers_handler.clone(), &chan_mgrs[i], IgnoringMessageHandler {},
33213339
IgnoringMessageHandler {},
33223340
);
33233341
let gossip_sync = P2PGossipSync::new(cfgs[i].network_graph.as_ref(), None, cfgs[i].logger);
@@ -3328,7 +3346,8 @@ pub fn create_network<'a, 'b: 'a, 'c: 'b>(node_count: usize, cfgs: &'b Vec<NodeC
33283346
message_router: &cfgs[i].message_router, chain_monitor: &cfgs[i].chain_monitor,
33293347
keys_manager: &cfgs[i].keys_manager, node: &chan_mgrs[i],
33303348
network_graph: cfgs[i].network_graph.as_ref(), gossip_sync,
3331-
node_seed: cfgs[i].node_seed, onion_messenger, network_chan_count: chan_count.clone(),
3349+
node_seed: cfgs[i].node_seed, onion_messenger, offers_handler,
3350+
network_chan_count: chan_count.clone(),
33323351
network_payment_count: payment_count.clone(), logger: cfgs[i].logger,
33333352
blocks: Arc::clone(&cfgs[i].tx_broadcaster.blocks),
33343353
connect_style: Rc::clone(&connect_style),

lightning/src/ln/max_payment_path_len_tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ fn bolt12_invoice_too_large_blinded_paths() {
394394
let invoice_om = nodes[1].onion_messenger.next_onion_message_for_peer(nodes[0].node.get_our_node_id()).unwrap();
395395
nodes[0].onion_messenger.handle_onion_message(nodes[1].node.get_our_node_id(), &invoice_om);
396396
// TODO: assert on the invoice error once we support replying to invoice OMs with failure info
397-
nodes[0].logger.assert_log_contains("lightning::ln::channelmanager", "Failed paying invoice: OnionPacketSizeExceeded", 1);
397+
nodes[0].logger.assert_log_contains("lightning::offers::flow", "Failed paying invoice: OnionPacketSizeExceeded", 1);
398398

399399
let events = nodes[0].node.get_and_clear_pending_events();
400400
assert_eq!(events.len(), 1);

0 commit comments

Comments
 (0)