Skip to content

Commit

Permalink
[Java] Correctly set gossip_sync in ChannelManagerConstructor
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
TheBlueMatt committed May 31, 2023
1 parent 8fd3925 commit 710c51a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,9 @@ public void chain_sync_completed(EventHandler event_handler, boolean use_p2p_gra

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());

Expand Down
13 changes: 11 additions & 2 deletions src/test/java/org/ldk/HumanObjectPeerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ UserConfig get_config() {
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) {
Expand Down Expand Up @@ -397,7 +398,7 @@ private void setup_route_handler() {
}
}
@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;
Expand Down Expand Up @@ -493,7 +494,7 @@ public Result_RouteLightningErrorZ find_route(byte[] payer, RouteParameters para
}
}
@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;
Expand Down Expand Up @@ -956,9 +957,13 @@ TestState do_test_message_handler() throws InterruptedException {
}

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();
assert peer1.network_graph_persists >= 1;
assert peer2.network_graph_persists >= 1;
} else if (use_nio_peer_handler) {
peer1.nio_peer_handler.interrupt();
peer2.nio_peer_handler.interrupt();
Expand Down Expand Up @@ -1152,8 +1157,12 @@ void do_test_message_handler_b(TestState state) throws Exception {
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();
assert state.peer1.network_graph_persists == 1;
assert state.peer2.network_graph_persists == 1;
}

t.interrupt();
Expand Down

0 comments on commit 710c51a

Please sign in to comment.