]> git.bitcoin.ninja Git - ldk-java/commitdiff
[Java] Correctly set `gossip_sync` in `ChannelManagerConstructor`
authorMatt Corallo <git@bluematt.me>
Wed, 31 May 2023 23:44:31 +0000 (23:44 +0000)
committerMatt Corallo <git@bluematt.me>
Thu, 1 Jun 2023 20:23:10 +0000 (20:23 +0000)
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.

src/main/java/org/ldk/batteries/ChannelManagerConstructor.java
src/test/java/org/ldk/HumanObjectPeerTest.java

index b05bd7e050298e290007f39812b0107072a94bd1..dec3d676c15ab6f54c44426160cb784c8073c129 100644 (file)
@@ -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());
 
index 9eb8e62a386cc3b3ecc1dfe16d91f0a219880251..5adc32ac3f55789ace20ad0a3524c91dd04fe15e 100644 (file)
@@ -214,6 +214,7 @@ class HumanObjectPeerTestInstance {
         final LinkedList<byte[]> received_custom_messages = new LinkedList<>();
         final LinkedList<byte[]> 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();