|
4 | 4 | import org.bitcoinj.core.Transaction; |
5 | 5 | import org.bitcoinj.script.Script; |
6 | 6 | import org.junit.jupiter.api.Test; |
| 7 | +import org.ldk.batteries.ChannelManagerConstructor; |
7 | 8 | import org.ldk.batteries.NioPeerHandler; |
8 | 9 | import org.ldk.enums.LDKNetwork; |
9 | 10 | import org.ldk.impl.bindings; |
|
13 | 14 | import java.io.IOException; |
14 | 15 | import java.lang.ref.WeakReference; |
15 | 16 | import java.net.InetSocketAddress; |
| 17 | +import java.util.ArrayList; |
16 | 18 | import java.util.Arrays; |
17 | 19 | import java.util.HashMap; |
18 | 20 | import java.util.LinkedList; |
@@ -264,28 +266,39 @@ private void bind_nio() { |
264 | 266 | Object ptr_to; |
265 | 267 | Peer(Peer orig) { |
266 | 268 | this(null, orig.seed); |
267 | | - ChannelMonitor[] monitors = new ChannelMonitor[1]; |
268 | | - synchronized (monitors) { |
269 | | - assert orig.monitors.size() == 1; |
270 | | - monitors[0] = orig.monitors.values().stream().iterator().next(); |
271 | | - if (break_cross_peer_refs) { |
272 | | - Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ res = UtilMethods.constructor_BlockHashChannelMonitorZ_read(monitors[0].write(), keys_interface); |
273 | | - assert res instanceof Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ.Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_OK; |
274 | | - monitors[0] = ((Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ.Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_OK) res).res.b; |
| 269 | + if (!break_cross_peer_refs) { |
| 270 | + ChannelMonitor[] monitors = new ChannelMonitor[1]; |
| 271 | + synchronized (monitors) { |
| 272 | + assert orig.monitors.size() == 1; |
| 273 | + monitors[0] = orig.monitors.values().stream().iterator().next(); |
| 274 | + } |
| 275 | + byte[] serialized = orig.chan_manager.write(); |
| 276 | + Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ read_res = |
| 277 | + UtilMethods.constructor_BlockHashChannelManagerZ_read(serialized, this.keys_interface, this.fee_estimator, this.chain_watch, this.tx_broadcaster, this.logger, UserConfig.constructor_default(), monitors); |
| 278 | + assert read_res instanceof Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ.Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_OK; |
| 279 | + this.chan_manager = ((Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ.Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_OK) read_res).res.b; |
| 280 | + this.chain_watch.watch_channel(monitors[0].get_funding_txo().a, monitors[0]); |
| 281 | + } else { |
| 282 | + final ArrayList<byte[]> channel_monitors = new ArrayList(); |
| 283 | + synchronized (monitors) { |
| 284 | + assert orig.monitors.size() == 1; |
| 285 | + channel_monitors.add(orig.monitors.values().stream().iterator().next().write()); |
| 286 | + } |
| 287 | + byte[] serialized = orig.chan_manager.write(); |
| 288 | + try { |
| 289 | + ChannelManagerConstructor constructed = new ChannelManagerConstructor(serialized, channel_monitors.toArray(new byte[1][]), this.keys_interface, this.fee_estimator, this.chain_watch, this.tx_broadcaster, this.logger); |
| 290 | + this.chan_manager = constructed.channel_manager; |
| 291 | + constructed.chain_sync_completed(); |
| 292 | + } catch (ChannelManagerConstructor.InvalidSerializedDataException e) { |
| 293 | + assert false; |
275 | 294 | } |
276 | 295 | } |
277 | | - byte[] serialized = orig.chan_manager.write(); |
278 | | - Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ read_res = |
279 | | - UtilMethods.constructor_BlockHashChannelManagerZ_read(serialized, this.keys_interface, this.fee_estimator, this.chain_watch, this.tx_broadcaster, this.logger, UserConfig.constructor_default(), monitors); |
280 | 296 | if (!break_cross_peer_refs && (use_manual_watch || use_km_wrapper)) { |
281 | 297 | // When we pass monitors[0] into chain_watch.watch_channel we create a reference from the new Peer to a |
282 | 298 | // field in the old peer, preventing freeing of the original Peer until the new Peer is freed. Thus, we |
283 | 299 | // shouldn't bother waiting for the original to be freed later on. |
284 | 300 | cross_reload_ref_pollution = true; |
285 | 301 | } |
286 | | - this.chain_watch.watch_channel(monitors[0].get_funding_txo().a, monitors[0]); |
287 | | - assert read_res instanceof Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ.Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_OK; |
288 | | - this.chan_manager = ((Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ.Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_OK) read_res).res.b; |
289 | 302 | this.node_id = chan_manager.get_our_node_id(); |
290 | 303 | this.chan_manager_events = chan_manager.as_EventsProvider(); |
291 | 304 |
|
|
0 commit comments