From: Matt Corallo Date: Wed, 31 May 2023 23:44:31 +0000 (+0000) Subject: [Java] Correctly set `gossip_sync` in `ChannelManagerConstructor` X-Git-Tag: v0.0.115.1^2~9 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=32f9a53661edef495b11b2be5dce7115bb2b34d8;p=ldk-java [Java] Correctly set `gossip_sync` in `ChannelManagerConstructor` If `use_p2p_graph_sync` is set, we need to set the `gossip_sync` given to the `BackgroundProcessor` to `P2P`, rather than `None`. We also add a regression test for this. --- diff --git a/src/main/java/org/ldk/batteries/ChannelManagerConstructor.java b/src/main/java/org/ldk/batteries/ChannelManagerConstructor.java index b05bd7e0..dec3d676 100644 --- a/src/main/java/org/ldk/batteries/ChannelManagerConstructor.java +++ b/src/main/java/org/ldk/batteries/ChannelManagerConstructor.java @@ -297,9 +297,9 @@ public class ChannelManagerConstructor { GossipSync gossip_sync; if (use_p2p_graph_sync) - gossip_sync = GossipSync.none(); - else gossip_sync = GossipSync.p2_p(graph_msg_handler); + else + gossip_sync = GossipSync.none(); Option_WriteableScoreZ writeable_score = Option_WriteableScoreZ.some(scorer.as_WriteableScore()); diff --git a/src/test/java/org/ldk/HumanObjectPeerTest.java b/src/test/java/org/ldk/HumanObjectPeerTest.java index 9eb8e62a..5adc32ac 100644 --- a/src/test/java/org/ldk/HumanObjectPeerTest.java +++ b/src/test/java/org/ldk/HumanObjectPeerTest.java @@ -214,6 +214,7 @@ class HumanObjectPeerTestInstance { final LinkedList received_custom_messages = new LinkedList<>(); final LinkedList custom_messages_to_send = new LinkedList<>(); ChannelManagerConstructor constructor = null; + long network_graph_persists = 0; GcCheck obj = new GcCheck(); private ChannelMonitor test_mon_roundtrip(OutPoint expected_id, byte[] data) { @@ -397,7 +398,7 @@ class HumanObjectPeerTestInstance { } } @Override public void persist_manager(byte[] channel_manager_bytes) { assert channel_manager_bytes.length > 1; } - @Override public void persist_network_graph(byte[] graph_bytes) { assert graph_bytes.length > 1; } + @Override public void persist_network_graph(byte[] graph_bytes) { assert graph_bytes.length > 1; network_graph_persists += 1; } @Override public void persist_scorer(byte[] scorer_bytes) { assert scorer_bytes.length > 1; } }, !use_ignore_handler); this.chan_manager = constructor.channel_manager; @@ -493,7 +494,7 @@ class HumanObjectPeerTestInstance { } } @Override public void persist_manager(byte[] channel_manager_bytes) { assert channel_manager_bytes.length > 1; } - @Override public void persist_network_graph(byte[] graph_bytes) { assert graph_bytes.length > 1; } + @Override public void persist_network_graph(byte[] graph_bytes) { assert graph_bytes.length > 1; network_graph_persists += 1; } @Override public void persist_scorer(byte[] scorer_bytes) { assert scorer_bytes.length > 1; } }, !use_ignore_handler); this.chan_manager = constructor.channel_manager; @@ -956,9 +957,18 @@ class HumanObjectPeerTestInstance { } if (reload_peers) { + assert peer1.network_graph_persists == 0; + assert peer2.network_graph_persists == 0; if (use_chan_manager_constructor) { peer1.constructor.interrupt(); peer2.constructor.interrupt(); + if (!use_ignore_handler) { + assert peer1.network_graph_persists >= 1; + assert peer2.network_graph_persists >= 1; + } else { + assert peer1.network_graph_persists == 0; + assert peer2.network_graph_persists == 0; + } } else if (use_nio_peer_handler) { peer1.nio_peer_handler.interrupt(); peer2.nio_peer_handler.interrupt(); @@ -1152,8 +1162,17 @@ class HumanObjectPeerTestInstance { state.peer2.get_monitor_events(0); if (use_chan_manager_constructor) { + assert state.peer1.network_graph_persists == 0; + assert state.peer2.network_graph_persists == 0; state.peer1.constructor.interrupt(); state.peer2.constructor.interrupt(); + if (!use_ignore_handler) { + assert state.peer1.network_graph_persists >= 1; + assert state.peer2.network_graph_persists >= 1; + } else { + assert state.peer1.network_graph_persists == 0; + assert state.peer2.network_graph_persists == 0; + } } t.interrupt();