From 01ec5b20083f8c85df47737c7fd79d3c6cd2058d Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Mon, 1 Feb 2021 16:01:49 -0500 Subject: [PATCH] Fix missing-ptrs_to error by working around it in test --- src/test/java/org/ldk/HumanObjectPeerTest.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/ldk/HumanObjectPeerTest.java b/src/test/java/org/ldk/HumanObjectPeerTest.java index ef08d774..b47b6e8e 100644 --- a/src/test/java/org/ldk/HumanObjectPeerTest.java +++ b/src/test/java/org/ldk/HumanObjectPeerTest.java @@ -243,13 +243,14 @@ class HumanObjectPeerTestInstance { this.peer_manager = PeerManager.constructor_new(chan_manager.as_ChannelMessageHandler(), router.as_RoutingMessageHandler(), keys_interface.get_node_secret(), random_data, logger); System.gc(); } + Object ptr_to; Peer(Peer orig) { this(null, orig.seed); ChannelMonitor[] monitors = new ChannelMonitor[1]; synchronized (monitors) { assert orig.monitors.size() == 1; monitors[0] = orig.monitors.values().stream().iterator().next(); - if (break_cross_peer_refs && use_manual_watch) { + if (break_cross_peer_refs) { Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ res = UtilMethods.constructor_BlockHashChannelMonitorZ_read(monitors[0].write(), keys_interface); assert res instanceof Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ.Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_OK; monitors[0] = ((Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ.Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_OK) res).res.b; @@ -258,7 +259,7 @@ class HumanObjectPeerTestInstance { byte[] serialized = orig.chan_manager.write(); Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ read_res = UtilMethods.constructor_BlockHashChannelManagerZ_read(serialized, this.keys_interface, this.fee_estimator, this.chain_watch, this.tx_broadcaster, this.logger, UserConfig.constructor_default(), monitors); - if (!break_cross_peer_refs && use_manual_watch) { + if (!break_cross_peer_refs && (use_manual_watch || use_km_wrapper)) { // When we pass monitors[0] into chain_watch.watch_channel we create a reference from the new Peer to a // field in the old peer, preventing freeing of the original Peer until the new Peer is freed. Thus, we // shouldn't bother waiting for the original to be freed later on. @@ -270,6 +271,17 @@ class HumanObjectPeerTestInstance { this.node_id = chan_manager.get_our_node_id(); this.chan_manager_events = chan_manager.as_EventsProvider(); + if (cross_reload_ref_pollution) { + // This really, really needs to be handled at the bindings layer, but its rather complicated - + // ChannelSigners can be cloned and passed around without java being involved, resulting in them being + // owned by both one or more ChannelMonitors and a ChannelManager, with only one having proper pointers + // to the ChannelSigner. Ideally, the ChannelSigner would have a global reference to the Java + // implementation class, but that results in circular references. Instead, we need some ability to, + // while cloning ChannelSigners, add new references in the calling Java struct (ie ChannelMonitor) to + // the ChannelSigner. + this.ptr_to = orig.chan_manager; + } + byte[] random_data = new byte[32]; for (byte i = 0; i < 32; i++) { random_data[i] = (byte) ((i ^ seed) ^ 0xf0); -- 2.39.5