From 75bc9cf63b967c96dc3e22d536ddd434395a3790 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Tue, 2 Nov 2021 17:51:11 +0000 Subject: [PATCH] Add support for InvoicePayer to ChannelManagerConstructor and test Note that this adds an additional bit of runs in the HumanObjectPeerTest, bringing leaks for a full run to: 149 allocations remained for 1157302 bytes. --- .../batteries/ChannelManagerConstructor.java | 56 ++++-- .../java/org/ldk/HumanObjectPeerTest.java | 162 ++++++++++++------ 2 files changed, 153 insertions(+), 65 deletions(-) diff --git a/src/main/java/org/ldk/batteries/ChannelManagerConstructor.java b/src/main/java/org/ldk/batteries/ChannelManagerConstructor.java index 8cf57536..0e68a947 100644 --- a/src/main/java/org/ldk/batteries/ChannelManagerConstructor.java +++ b/src/main/java/org/ldk/batteries/ChannelManagerConstructor.java @@ -45,13 +45,22 @@ public class ChannelManagerConstructor { * A NioPeerHandler which manages a background thread to handle socket events and pass them to the peer_manager. */ public final NioPeerHandler nio_peer_handler; + /** + * If a `NetworkGraph` is provided to the constructor *and* a `LockableScore` is provided to + * `chain_sync_completed`, this will be non-null after `chain_sync_completed` returns. + * + * It should be used to send payments instead of doing so directly via the `channel_manager`. + * + * When payments are made through this, they are automatically retried and the provided Scorer + * will be updated with payment failure data. + */ + @Nullable public InvoicePayer payer; private final ChainMonitor chain_monitor; - + @Nullable private final NetworkGraph net_graph; + @Nullable private final NetGraphMsgHandler graph_msg_handler; private final Logger logger; - public final @Nullable NetGraphMsgHandler router; - /** * Deserializes a channel manager and a set of channel monitors from the given serialized copies and interface implementations * @@ -61,7 +70,7 @@ public class ChannelManagerConstructor { */ public ChannelManagerConstructor(byte[] channel_manager_serialized, byte[][] channel_monitors_serialized, KeysInterface keys_interface, FeeEstimator fee_estimator, ChainMonitor chain_monitor, @Nullable Filter filter, - @Nullable NetGraphMsgHandler router, + @Nullable NetworkGraph net_graph, BroadcasterInterface tx_broadcaster, Logger logger) throws InvalidSerializedDataException { final IgnoringMessageHandler no_custom_messages = IgnoringMessageHandler.of(); final ChannelMonitor[] monitors = new ChannelMonitor[channel_monitors_serialized.length]; @@ -84,14 +93,18 @@ public class ChannelManagerConstructor { this.channel_manager = ((Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ.Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_OK)res).res.get_b(); this.channel_manager_latest_block_hash = ((Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ.Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_OK)res).res.get_a(); this.chain_monitor = chain_monitor; - this.router = router; this.logger = logger; byte[] random_data = keys_interface.get_secure_random_bytes(); - if (router != null) { - this.peer_manager = PeerManager.of(channel_manager.as_ChannelMessageHandler(), router.as_RoutingMessageHandler(), + this.net_graph = net_graph; + if (net_graph != null) { + //TODO: We really need to expose the Access here to let users prevent DoS issues + this.graph_msg_handler = NetGraphMsgHandler.of(net_graph, Option_AccessZ.none(), logger); + this.peer_manager = PeerManager.of(channel_manager.as_ChannelMessageHandler(), + graph_msg_handler.as_RoutingMessageHandler(), keys_interface.get_node_secret(), random_data, logger, no_custom_messages.as_CustomMessageHandler()); } else { - this.peer_manager = PeerManager.of(channel_manager.as_ChannelMessageHandler(), (IgnoringMessageHandler.of()).as_RoutingMessageHandler(), + this.graph_msg_handler = null; + this.peer_manager = PeerManager.of(channel_manager.as_ChannelMessageHandler(), no_custom_messages.as_RoutingMessageHandler(), keys_interface.get_node_secret(), random_data, logger, no_custom_messages.as_CustomMessageHandler()); } NioPeerHandler nio_peer_handler = null; @@ -113,23 +126,27 @@ public class ChannelManagerConstructor { */ public ChannelManagerConstructor(Network network, UserConfig config, byte[] current_blockchain_tip_hash, int current_blockchain_tip_height, KeysInterface keys_interface, FeeEstimator fee_estimator, ChainMonitor chain_monitor, - @Nullable NetGraphMsgHandler router, + @Nullable NetworkGraph net_graph, BroadcasterInterface tx_broadcaster, Logger logger) { final IgnoringMessageHandler no_custom_messages = IgnoringMessageHandler.of(); channel_monitors = new TwoTuple_BlockHashChannelMonitorZ[0]; channel_manager_latest_block_hash = null; this.chain_monitor = chain_monitor; - this.router = router; BestBlock block = BestBlock.of(current_blockchain_tip_hash, current_blockchain_tip_height); ChainParameters params = ChainParameters.of(network, block); channel_manager = ChannelManager.of(fee_estimator, chain_monitor.as_Watch(), tx_broadcaster, logger, keys_interface, config, params); this.logger = logger; byte[] random_data = keys_interface.get_secure_random_bytes(); - if (router != null) { - this.peer_manager = PeerManager.of(channel_manager.as_ChannelMessageHandler(), router.as_RoutingMessageHandler(), + this.net_graph = net_graph; + if (net_graph != null) { + //TODO: We really need to expose the Access here to let users prevent DoS issues + this.graph_msg_handler = NetGraphMsgHandler.of(net_graph, Option_AccessZ.none(), logger); + this.peer_manager = PeerManager.of(channel_manager.as_ChannelMessageHandler(), + graph_msg_handler.as_RoutingMessageHandler(), keys_interface.get_node_secret(), random_data, logger, no_custom_messages.as_CustomMessageHandler()); } else { - this.peer_manager = PeerManager.of(channel_manager.as_ChannelMessageHandler(), (IgnoringMessageHandler.of()).as_RoutingMessageHandler(), + this.graph_msg_handler = null; + this.peer_manager = PeerManager.of(channel_manager.as_ChannelMessageHandler(), no_custom_messages.as_RoutingMessageHandler(), keys_interface.get_node_secret(), random_data, logger, no_custom_messages.as_CustomMessageHandler()); } NioPeerHandler nio_peer_handler = null; @@ -159,16 +176,23 @@ public class ChannelManagerConstructor { * This also spawns a background thread which will call the appropriate methods on the provided * EventHandler as required. */ - public void chain_sync_completed(EventHandler event_handler) { + public void chain_sync_completed(EventHandler event_handler, @Nullable LockableScore scorer) { if (background_processor != null) { return; } for (TwoTuple_BlockHashChannelMonitorZ monitor: channel_monitors) { this.chain_monitor.as_Watch().watch_channel(monitor.get_b().get_funding_txo().get_a(), monitor.get_b()); } + org.ldk.structs.EventHandler ldk_handler = org.ldk.structs.EventHandler.new_impl(event_handler::handle_event); + if (this.net_graph != null && scorer != null) { + Router router = DefaultRouter.of(net_graph, logger).as_Router(); + this.payer = InvoicePayer.of(this.channel_manager.as_Payer(), router, scorer, this.logger, ldk_handler, RetryAttempts.of(3)); +assert this.payer != null; + ldk_handler = this.payer.as_EventHandler(); + } + background_processor = BackgroundProcessor.start(org.ldk.structs.ChannelManagerPersister.new_impl(channel_manager -> { event_handler.persist_manager(channel_manager.write()); return Result_NoneErrorZ.ok(); - }), org.ldk.structs.EventHandler.new_impl(event_handler::handle_event), - this.chain_monitor, this.channel_manager, this.router, this.peer_manager, this.logger); + }), ldk_handler, this.chain_monitor, this.channel_manager, this.graph_msg_handler, this.peer_manager, this.logger); } /** diff --git a/src/test/java/org/ldk/HumanObjectPeerTest.java b/src/test/java/org/ldk/HumanObjectPeerTest.java index 656c2ebb..a123b6e3 100644 --- a/src/test/java/org/ldk/HumanObjectPeerTest.java +++ b/src/test/java/org/ldk/HumanObjectPeerTest.java @@ -26,8 +26,9 @@ class HumanObjectPeerTestInstance { private final boolean use_filter; private final boolean use_ignore_handler; private final boolean use_chan_manager_constructor; + private final boolean use_invoice_payer; - HumanObjectPeerTestInstance(boolean nice_close, boolean use_km_wrapper, boolean use_manual_watch, boolean reload_peers, boolean break_cross_peer_refs, boolean use_nio_peer_handler, boolean use_filter, boolean use_ignore_handler, boolean use_chan_manager_constructor) { + HumanObjectPeerTestInstance(boolean nice_close, boolean use_km_wrapper, boolean use_manual_watch, boolean reload_peers, boolean break_cross_peer_refs, boolean use_nio_peer_handler, boolean use_filter, boolean use_ignore_handler, boolean use_chan_manager_constructor, boolean use_invoice_payer) { this.nice_close = nice_close; this.use_km_wrapper = use_km_wrapper; this.use_manual_watch = use_manual_watch; @@ -37,6 +38,7 @@ class HumanObjectPeerTestInstance { this.use_filter = use_filter; this.use_ignore_handler = use_ignore_handler; this.use_chan_manager_constructor = use_chan_manager_constructor; + this.use_invoice_payer = use_invoice_payer; } class Peer { @@ -184,6 +186,7 @@ class HumanObjectPeerTestInstance { final LinkedList received_custom_messages = new LinkedList<>(); final LinkedList custom_messages_to_send = new LinkedList<>(); ChannelManagerConstructor constructor = null; + InvoicePayer payer = null; GcCheck obj = new GcCheck(); private TwoTuple_OutPointScriptZ test_mon_roundtrip(ChannelMonitor mon) { @@ -336,10 +339,14 @@ class HumanObjectPeerTestInstance { this(null, seed); if (use_chan_manager_constructor) { if (use_ignore_handler) { - this.route_handler = null; + this.constructor = new ChannelManagerConstructor(Network.LDKNetwork_Bitcoin, UserConfig.with_default(), new byte[32], 0, + this.keys_interface, this.fee_estimator, this.chain_monitor, null, this.tx_broadcaster, this.logger); + } else { + this.constructor = new ChannelManagerConstructor(Network.LDKNetwork_Bitcoin, UserConfig.with_default(), new byte[32], 0, + this.keys_interface, this.fee_estimator, this.chain_monitor, this.router, this.tx_broadcaster, this.logger); } - this.constructor = new ChannelManagerConstructor(Network.LDKNetwork_Bitcoin, UserConfig.with_default(), new byte[32], 0, - this.keys_interface, this.fee_estimator, this.chain_monitor, route_handler, this.tx_broadcaster, this.logger); + LockableScore scorer = null; + if (use_invoice_payer) { scorer = LockableScore.of(Scorer.with_default().as_Score()); } constructor.chain_sync_completed(new ChannelManagerConstructor.EventHandler() { @Override public void handle_event(Event event) { synchronized (pending_manager_events) { @@ -348,15 +355,35 @@ class HumanObjectPeerTestInstance { } } @Override public void persist_manager(byte[] channel_manager_bytes) { assert channel_manager_bytes.length > 1; } - }); + }, scorer); this.chan_manager = constructor.channel_manager; this.peer_manager = constructor.peer_manager; + this.payer = constructor.payer; must_free_objs.add(new WeakReference<>(this.chan_manager)); } else { ChainParameters params = ChainParameters.of(Network.LDKNetwork_Bitcoin, BestBlock.of(new byte[32], 0)); this.chan_manager = ChannelManager.of(this.fee_estimator, chain_watch, tx_broadcaster, logger, this.keys_interface, UserConfig.with_default(), params); byte[] random_data = keys_interface.get_secure_random_bytes(); this.peer_manager = PeerManager.of(chan_manager.as_ChannelMessageHandler(), route_handler.as_RoutingMessageHandler(), keys_interface.get_node_secret(), random_data, logger, this.custom_message_handler); + if (use_invoice_payer) { + this.payer = InvoicePayer.of(this.chan_manager.as_Payer(), Router.new_impl(new Router.RouterInterface() { + @Override + public Result_RouteLightningErrorZ find_route(byte[] payer, RouteParameters params, ChannelDetails[] first_hops, Score scorer) { + return UtilMethods.find_route(payer, params, router, first_hops, logger, scorer); + } + }), LockableScore.of(Score.new_impl(new Score.ScoreInterface() { + @Override public void payment_path_failed(RouteHop[] path, long scid) {} + @Override public long channel_penalty_msat(long scid, NodeId src, NodeId dst) { return 0; } + @Override public byte[] write() { assert false; return null; } + })), logger, EventHandler.new_impl(new EventHandler.EventHandlerInterface() { + @Override public void handle_event(Event event) { + synchronized (pending_manager_events) { + pending_manager_events.add(event); + pending_manager_events.notifyAll(); + } + } + }), RetryAttempts.of(0)); + } } this.node_id = chan_manager.get_our_node_id(); @@ -376,10 +403,14 @@ class HumanObjectPeerTestInstance { filter_nullable = ((Option_FilterZ.Some) this.filter).some; } if (use_ignore_handler) { - this.route_handler = null; + this.constructor = new ChannelManagerConstructor(serialized, monitors, this.keys_interface, + this.fee_estimator, this.chain_monitor, filter_nullable, null, this.tx_broadcaster, this.logger); + } else { + this.constructor = new ChannelManagerConstructor(serialized, monitors, this.keys_interface, + this.fee_estimator, this.chain_monitor, filter_nullable, this.router, this.tx_broadcaster, this.logger); } - this.constructor = new ChannelManagerConstructor(serialized, monitors, this.keys_interface, - this.fee_estimator, this.chain_monitor, filter_nullable, this.route_handler, this.tx_broadcaster, this.logger); + LockableScore scorer = null; + if (use_invoice_payer) { scorer = LockableScore.of(Scorer.with_default().as_Score()); } constructor.chain_sync_completed(new ChannelManagerConstructor.EventHandler() { @Override public void handle_event(Event event) { synchronized (pending_manager_events) { @@ -388,8 +419,9 @@ class HumanObjectPeerTestInstance { } } @Override public void persist_manager(byte[] channel_manager_bytes) { assert channel_manager_bytes.length > 1; } - }); + }, scorer); this.chan_manager = constructor.channel_manager; + this.payer = constructor.payer; this.peer_manager = constructor.peer_manager; must_free_objs.add(new WeakReference<>(this.chan_manager)); // If we are using a ChannelManagerConstructor, we may have pending events waiting on the old peer @@ -428,6 +460,25 @@ class HumanObjectPeerTestInstance { // shouldn't bother waiting for the original to be freed later on. cross_reload_ref_pollution = true; } + if (use_invoice_payer) { + this.payer = InvoicePayer.of(this.chan_manager.as_Payer(), Router.new_impl(new Router.RouterInterface() { + @Override + public Result_RouteLightningErrorZ find_route(byte[] payer, RouteParameters params, ChannelDetails[] first_hops, Score scorer) { + return UtilMethods.find_route(payer, params, router, first_hops, logger, scorer); + } + }), LockableScore.of(Score.new_impl(new Score.ScoreInterface() { + @Override public void payment_path_failed(RouteHop[] path, long scid) {} + @Override public long channel_penalty_msat(long scid, NodeId src, NodeId dst) { return 0; } + @Override public byte[] write() { assert false; return null; } + })), logger, EventHandler.new_impl(new EventHandler.EventHandlerInterface() { + @Override public void handle_event(Event event) { + synchronized (pending_manager_events) { + pending_manager_events.add(event); + pending_manager_events.notifyAll(); + } + } + }), RetryAttempts.of(0)); + } } this.node_id = chan_manager.get_our_node_id(); bind_nio(); @@ -725,7 +776,7 @@ class HumanObjectPeerTestInstance { assert Arrays.equals(peer1_chans[0].get_channel_id(), funding.getTxId().getReversedBytes()); assert Arrays.equals(peer2_chans[0].get_channel_id(), funding.getTxId().getReversedBytes()); - Result_InvoiceSignOrCreationErrorZ invoice = UtilMethods.create_invoice_from_channelmanager(peer2.chan_manager, peer2.keys_interface, Currency.LDKCurrency_Bitcoin, Option_u64Z.none(), "Invoice Description"); + Result_InvoiceSignOrCreationErrorZ invoice = UtilMethods.create_invoice_from_channelmanager(peer2.chan_manager, peer2.keys_interface, Currency.LDKCurrency_Bitcoin, Option_u64Z.some(10000000), "Invoice Description"); assert invoice instanceof Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK; System.out.println("Got invoice: " + ((Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK) invoice).res.to_str()); @@ -738,35 +789,41 @@ class HumanObjectPeerTestInstance { Description raw_invoice_description = raw_invoice.description(); String description_string = raw_invoice_description.into_inner(); assert description_string.equals("Invoice Description"); - byte[] payment_hash = ((Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK) invoice).res.payment_hash(); - byte[] payment_secret = ((Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK) invoice).res.payment_secret(); - byte[] dest_node_id = ((Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK) invoice).res.recover_payee_pub_key(); - assert Arrays.equals(dest_node_id, peer2.node_id); - InvoiceFeatures invoice_features = ((Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK) invoice).res.features(); - RouteHint[] route_hints = ((Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK) invoice).res.route_hints(); - - Payee payee = Payee.of(peer2.node_id, invoice_features, route_hints, Option_u64Z.none()); - RouteParameters route_params = RouteParameters.of(payee, 10000000, 42); - Result_RouteLightningErrorZ route_res = UtilMethods.find_route( - peer1.chan_manager.get_our_node_id(), route_params, peer1.router, - peer1_chans, peer1.logger, Scorer.with_default().as_Score()); - assert route_res instanceof Result_RouteLightningErrorZ.Result_RouteLightningErrorZ_OK; - Route route = ((Result_RouteLightningErrorZ.Result_RouteLightningErrorZ_OK) route_res).res; - assert route.get_paths().length == 1; - assert route.get_paths()[0].length == 1; - assert route.get_paths()[0][0].get_fee_msat() == 10000000; - - Result_PaymentIdPaymentSendFailureZ payment_res = peer1.chan_manager.send_payment(route, payment_hash, payment_secret); - assert payment_res instanceof Result_PaymentIdPaymentSendFailureZ.Result_PaymentIdPaymentSendFailureZ_OK; - - RouteHop[][] hops = new RouteHop[1][1]; - byte[] hop_pubkey = new byte[33]; - hop_pubkey[0] = 3; - hop_pubkey[1] = 42; - hops[0][0] = RouteHop.of(hop_pubkey, NodeFeatures.known(), 42, ChannelFeatures.known(), 100, 0); - Route r2 = Route.of(hops, payee); - payment_res = peer1.chan_manager.send_payment(r2, payment_hash, payment_secret); - assert payment_res instanceof Result_PaymentIdPaymentSendFailureZ.Result_PaymentIdPaymentSendFailureZ_Err; + + if (!use_invoice_payer) { + byte[] payment_hash = ((Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK) invoice).res.payment_hash(); + byte[] payment_secret = ((Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK) invoice).res.payment_secret(); + byte[] dest_node_id = ((Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK) invoice).res.recover_payee_pub_key(); + assert Arrays.equals(dest_node_id, peer2.node_id); + InvoiceFeatures invoice_features = ((Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK) invoice).res.features(); + RouteHint[] route_hints = ((Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK) invoice).res.route_hints(); + + Payee payee = Payee.of(peer2.node_id, invoice_features, route_hints, Option_u64Z.none()); + RouteParameters route_params = RouteParameters.of(payee, 10000000, 42); + Result_RouteLightningErrorZ route_res = UtilMethods.find_route( + peer1.chan_manager.get_our_node_id(), route_params, peer1.router, + peer1_chans, peer1.logger, Scorer.with_default().as_Score()); + assert route_res instanceof Result_RouteLightningErrorZ.Result_RouteLightningErrorZ_OK; + Route route = ((Result_RouteLightningErrorZ.Result_RouteLightningErrorZ_OK) route_res).res; + assert route.get_paths().length == 1; + assert route.get_paths()[0].length == 1; + assert route.get_paths()[0][0].get_fee_msat() == 10000000; + + Result_PaymentIdPaymentSendFailureZ payment_res = peer1.chan_manager.send_payment(route, payment_hash, payment_secret); + assert payment_res instanceof Result_PaymentIdPaymentSendFailureZ.Result_PaymentIdPaymentSendFailureZ_OK; + + RouteHop[][] hops = new RouteHop[1][1]; + byte[] hop_pubkey = new byte[33]; + hop_pubkey[0] = 3; + hop_pubkey[1] = 42; + hops[0][0] = RouteHop.of(hop_pubkey, NodeFeatures.known(), 42, ChannelFeatures.known(), 100, 0); + Route r2 = Route.of(hops, payee); + payment_res = peer1.chan_manager.send_payment(r2, payment_hash, payment_secret); + assert payment_res instanceof Result_PaymentIdPaymentSendFailureZ.Result_PaymentIdPaymentSendFailureZ_Err; + } else { + Result_PaymentIdPaymentErrorZ send_res = peer1.payer.pay_invoice(((Result_InvoiceNoneZ.Result_InvoiceNoneZ_OK) parsed_invoice).res); + assert send_res instanceof Result_PaymentIdPaymentErrorZ.Result_PaymentIdPaymentErrorZ_OK; + } if (reload_peers) { if (use_chan_manager_constructor) { @@ -984,14 +1041,14 @@ class HumanObjectPeerTestInstance { } } public class HumanObjectPeerTest { - HumanObjectPeerTestInstance do_test_run(boolean nice_close, boolean use_km_wrapper, boolean use_manual_watch, boolean reload_peers, boolean break_cross_peer_refs, boolean nio_peer_handler, boolean use_ignoring_routing_handler, boolean use_chan_manager_constructor) throws InterruptedException { - HumanObjectPeerTestInstance instance = new HumanObjectPeerTestInstance(nice_close, use_km_wrapper, use_manual_watch, reload_peers, break_cross_peer_refs, nio_peer_handler, !nio_peer_handler, use_ignoring_routing_handler, use_chan_manager_constructor); + HumanObjectPeerTestInstance do_test_run(boolean nice_close, boolean use_km_wrapper, boolean use_manual_watch, boolean reload_peers, boolean break_cross_peer_refs, boolean nio_peer_handler, boolean use_ignoring_routing_handler, boolean use_chan_manager_constructor, boolean use_invoice_payer) throws InterruptedException { + HumanObjectPeerTestInstance instance = new HumanObjectPeerTestInstance(nice_close, use_km_wrapper, use_manual_watch, reload_peers, break_cross_peer_refs, nio_peer_handler, !nio_peer_handler, use_ignoring_routing_handler, use_chan_manager_constructor, use_invoice_payer); HumanObjectPeerTestInstance.TestState state = instance.do_test_message_handler(); instance.do_test_message_handler_b(state); return instance; } - void do_test(boolean nice_close, boolean use_km_wrapper, boolean use_manual_watch, boolean reload_peers, boolean break_cross_peer_refs, boolean nio_peer_handler, boolean use_ignoring_routing_handler, boolean use_chan_manager_constructor) throws InterruptedException { - HumanObjectPeerTestInstance instance = do_test_run(nice_close, use_km_wrapper, use_manual_watch, reload_peers, break_cross_peer_refs, nio_peer_handler, use_ignoring_routing_handler, use_chan_manager_constructor); + void do_test(boolean nice_close, boolean use_km_wrapper, boolean use_manual_watch, boolean reload_peers, boolean break_cross_peer_refs, boolean nio_peer_handler, boolean use_ignoring_routing_handler, boolean use_chan_manager_constructor, boolean use_invoice_payer) throws InterruptedException { + HumanObjectPeerTestInstance instance = do_test_run(nice_close, use_km_wrapper, use_manual_watch, reload_peers, break_cross_peer_refs, nio_peer_handler, use_ignoring_routing_handler, use_chan_manager_constructor, use_invoice_payer); while (instance.gc_count != instance.gc_exp_count) { System.gc(); System.runFinalization(); @@ -1001,15 +1058,16 @@ public class HumanObjectPeerTest { } @Test public void test_message_handler() throws InterruptedException { - for (int i = 0; i < (1 << 8) - 1; i++) { + for (int i = 0; i < (1 << 9) - 1; i++) { boolean nice_close = (i & (1 << 0)) != 0; boolean use_km_wrapper = (i & (1 << 1)) != 0; boolean use_manual_watch = (i & (1 << 2)) != 0; boolean reload_peers = (i & (1 << 3)) != 0; boolean break_cross_refs = (i & (1 << 4)) != 0; - boolean nio_peer_handler = (i & (1 << 5)) != 0; - boolean use_ignoring_routing_handler = (i & (1 << 6)) != 0; - boolean use_chan_manager_constructor = (i & (1 << 7)) != 0; + boolean use_ignoring_routing_handler = (i & (1 << 5)) != 0; + boolean use_chan_manager_constructor = (i & (1 << 6)) != 0; + boolean use_invoice_payer = (i & (1 << 7)) != 0; + boolean nio_peer_handler = (i & (1 << 8)) != 0; if (break_cross_refs && !reload_peers) { // There are no cross refs to break without reloading peers. continue; @@ -1018,13 +1076,19 @@ public class HumanObjectPeerTest { // ChannelManagerConstructor requires a ChainMonitor as the Watch and creates a NioPeerHandler for us. continue; } - if (!use_chan_manager_constructor && use_ignoring_routing_handler) { + if (!use_chan_manager_constructor && (use_ignoring_routing_handler)) { // We rely on the ChannelManagerConstructor to convert null into an IgnoringMessageHandler, so don't // try to run with an IgnoringMessageHandler unless we're also using a ChannelManagerConstructor. continue; } + if (use_chan_manager_constructor && use_ignoring_routing_handler && use_invoice_payer) { + // As documented on ChannelManagerConstructor, if we provide a `null` NetworkGraph (because we want to + // use an IgnoringMessageHandler), no InvoicePayer will be constructored for us, thus we cannot use an + // InvoicePayer to send payments in this case. + continue; + } System.err.println("Running test with flags " + i); - do_test(nice_close, use_km_wrapper, use_manual_watch, reload_peers, break_cross_refs, nio_peer_handler, use_ignoring_routing_handler, use_chan_manager_constructor); + do_test(nice_close, use_km_wrapper, use_manual_watch, reload_peers, break_cross_refs, nio_peer_handler, use_ignoring_routing_handler, use_chan_manager_constructor, use_invoice_payer); } } -- 2.30.2