X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Forg%2Fldk%2FHumanObjectPeerTest.java;h=3051239816e5bce07ebac9432cb285b18f1731eb;hb=293bcee787de3eb181b82175a1784a4ef311e012;hp=c4f1b9062a7462905ef0bc7f5b105277fff558a6;hpb=d941cc4e66ea53ce81912a04d35b164344f3a7ee;p=ldk-java diff --git a/src/test/java/org/ldk/HumanObjectPeerTest.java b/src/test/java/org/ldk/HumanObjectPeerTest.java index c4f1b906..30512398 100644 --- a/src/test/java/org/ldk/HumanObjectPeerTest.java +++ b/src/test/java/org/ldk/HumanObjectPeerTest.java @@ -14,6 +14,7 @@ import java.io.IOException; import java.lang.ref.WeakReference; import java.net.InetSocketAddress; import java.util.*; +import java.util.function.IntConsumer; class HumanObjectPeerTestInstance { private final boolean nice_close; @@ -26,6 +27,7 @@ class HumanObjectPeerTestInstance { private final boolean use_ignore_handler; private final boolean use_chan_manager_constructor; private final boolean use_invoice_payer; + TxOut gossip_txout = null; HumanObjectPeerTestInstance(boolean nice_close, boolean use_km_wrapper, boolean use_manual_watch, boolean reload_peers, boolean break_cross_peer_refs, boolean use_nio_peer_handler, boolean use_filter, boolean use_ignore_handler, boolean use_chan_manager_constructor, boolean use_invoice_payer) { this.nice_close = nice_close; @@ -149,14 +151,16 @@ class HumanObjectPeerTestInstance { } @Override - public MonitorEvent[] release_pending_monitor_events() { + public TwoTuple_OutPointCVec_MonitorEventZZ[] release_pending_monitor_events() { synchronized (monitors) { assert monitors.size() <= 1; for (ChannelMonitor mon : monitors.values()) { - return mon.get_and_clear_pending_monitor_events(); + TwoTuple_OutPointCVec_MonitorEventZZ[] res = new TwoTuple_OutPointCVec_MonitorEventZZ[1]; + res[0] = TwoTuple_OutPointCVec_MonitorEventZZ.of(mon.get_funding_txo().get_a(), mon.get_and_clear_pending_monitor_events()); + return res; } } - return new MonitorEvent[0]; + return new TwoTuple_OutPointCVec_MonitorEventZZ[0]; } }; Watch watch = Watch.new_impl(watch_impl); @@ -165,6 +169,14 @@ class HumanObjectPeerTestInstance { return watch; } + UserConfig get_config() { + ChannelHandshakeConfig channel_config = ChannelHandshakeConfig.with_default(); + channel_config.set_announced_channel(true); + UserConfig config = UserConfig.with_default(); + config.set_channel_handshake_config(channel_config); + return config; + } + NioPeerHandler nio_peer_handler; short nio_port; final byte seed; @@ -174,8 +186,8 @@ class HumanObjectPeerTestInstance { final KeysManager explicit_keys_manager; final KeysInterface keys_interface; final ChainMonitor chain_monitor; - final NetworkGraph router; - NetGraphMsgHandler route_handler; + NetworkGraph router; + P2PGossipSync route_handler; final Watch chain_watch; final HashSet filter_additions; Option_FilterZ filter; @@ -283,16 +295,6 @@ class HumanObjectPeerTestInstance { this.keys_interface = keys.as_KeysInterface(); this.explicit_keys_manager = keys; } - this.router = NetworkGraph.of(new byte[32]); - this.route_handler = NetGraphMsgHandler.of(this.router, Option_AccessZ.some(Access.new_impl(new Access.AccessInterface() { - @Override - public Result_TxOutAccessErrorZ get_utxo(byte[] genesis_hash, long short_channel_id) { - // We don't exchange any gossip, so should never actually get called, but providing a Some(Access) - // is a good test of our Option free'ing, which used to be broken and relies on a dirty hack. - assert false; - return Result_TxOutAccessErrorZ.err(AccessError.LDKAccessError_UnknownTx); - } - })), logger); this.custom_message_handler = CustomMessageHandler.new_impl(new CustomMessageHandler.CustomMessageHandlerInterface() { @Override @@ -346,19 +348,28 @@ class HumanObjectPeerTestInstance { } catch (IOException e) { assert i < 10_500; } } } + private void setup_route_handler() { + this.route_handler = P2PGossipSync.of(this.router, + Option_AccessZ.some(Access.new_impl((genesis_hash, short_channel_id) -> Result_TxOutAccessErrorZ.ok(gossip_txout))), this.logger); + } Peer(byte seed) { this(null, seed); + this.router = NetworkGraph.of(new byte[32], this.logger); + this.setup_route_handler(); + if (use_chan_manager_constructor) { if (use_ignore_handler) { - this.constructor = new ChannelManagerConstructor(Network.LDKNetwork_Bitcoin, UserConfig.with_default(), new byte[32], 0, + this.constructor = new ChannelManagerConstructor(Network.LDKNetwork_Bitcoin, get_config(), new byte[32], 0, this.keys_interface, this.fee_estimator, this.chain_monitor, null, this.tx_broadcaster, this.logger); } else { - this.constructor = new ChannelManagerConstructor(Network.LDKNetwork_Bitcoin, UserConfig.with_default(), new byte[32], 0, + this.constructor = new ChannelManagerConstructor(Network.LDKNetwork_Bitcoin, get_config(), new byte[32], 0, this.keys_interface, this.fee_estimator, this.chain_monitor, this.router, this.tx_broadcaster, this.logger); } - Result_ScorerDecodeErrorZ score_res = Scorer.read(Scorer.with_default().write()); + ProbabilisticScoringParameters params = ProbabilisticScoringParameters.with_default(); + ProbabilisticScorer default_scorer = ProbabilisticScorer.of(params, this.router, this.logger); + Result_ProbabilisticScorerDecodeErrorZ score_res = ProbabilisticScorer.read(default_scorer.write(), params, this.router, this.logger); assert score_res.is_ok(); - Score score = ((Result_ScorerDecodeErrorZ.Result_ScorerDecodeErrorZ_OK) score_res).res.as_Score(); + Score score = ((Result_ProbabilisticScorerDecodeErrorZ.Result_ProbabilisticScorerDecodeErrorZ_OK) score_res).res.as_Score(); MultiThreadedLockableScore scorer = null; if (use_invoice_payer) { scorer = MultiThreadedLockableScore.of(score); } constructor.chain_sync_completed(new ChannelManagerConstructor.EventHandler() { @@ -369,6 +380,8 @@ 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_scorer(byte[] scorer_bytes) { assert scorer_bytes.length > 1; } }, scorer); this.chan_manager = constructor.channel_manager; this.peer_manager = constructor.peer_manager; @@ -376,7 +389,7 @@ class HumanObjectPeerTestInstance { must_free_objs.add(new WeakReference<>(this.chan_manager)); } else { ChainParameters params = ChainParameters.of(Network.LDKNetwork_Bitcoin, BestBlock.of(new byte[32], 0)); - this.chan_manager = ChannelManager.of(this.fee_estimator, chain_watch, tx_broadcaster, logger, this.keys_interface, UserConfig.with_default(), params); + this.chan_manager = ChannelManager.of(this.fee_estimator, chain_watch, tx_broadcaster, logger, this.keys_interface, get_config(), params); byte[] random_data = keys_interface.get_secure_random_bytes(); Result_SecretKeyNoneZ node_secret = keys_interface.get_node_secret(Recipient.LDKRecipient_Node); assert node_secret.is_ok(); @@ -386,11 +399,11 @@ class HumanObjectPeerTestInstance { this.payer = InvoicePayer.of(this.chan_manager.as_Payer(), Router.new_impl(new Router.RouterInterface() { @Override public Result_RouteLightningErrorZ find_route(byte[] payer, RouteParameters params, byte[] payment_hash, ChannelDetails[] first_hops, Score scorer) { - return UtilMethods.find_route(payer, params, router, first_hops, logger, scorer); + return UtilMethods.find_route(payer, params, router, first_hops, logger, scorer, new byte[32]); } }), MultiThreadedLockableScore.of(Score.new_impl(new Score.ScoreInterface() { @Override public void payment_path_failed(RouteHop[] path, long scid) {} - @Override public long channel_penalty_msat(long short_channel_id, long send_amt_msat, long channel_capacity_msat, NodeId source, NodeId target) { return 0; } + @Override public long channel_penalty_msat(long short_channel_id, NodeId source, NodeId target, ChannelUsage usage) { return 0; } @Override public void payment_path_successful(RouteHop[] path) {} @Override public byte[] write() { assert false; return null; } })), logger, EventHandler.new_impl(new EventHandler.EventHandlerInterface() { @@ -400,7 +413,7 @@ class HumanObjectPeerTestInstance { pending_manager_events.notifyAll(); } } - }), RetryAttempts.of(0)); + }), Retry.attempts(0)); } } @@ -416,32 +429,35 @@ class HumanObjectPeerTestInstance { if (use_chan_manager_constructor) { byte[][] monitors = {orig.monitors.values().stream().iterator().next().write()}; byte[] serialized = orig.chan_manager.write(); + byte[] serialized_router = orig.router.write(); try { Filter filter_nullable = null; if (this.filter instanceof Option_FilterZ.Some) { filter_nullable = ((Option_FilterZ.Some) this.filter).some; } if (use_ignore_handler) { - this.constructor = new ChannelManagerConstructor(serialized, monitors, UserConfig.with_default(), + this.constructor = new ChannelManagerConstructor(serialized, monitors, get_config(), this.keys_interface, this.fee_estimator, this.chain_monitor, filter_nullable, null, this.tx_broadcaster, this.logger); } else { - this.constructor = new ChannelManagerConstructor(serialized, monitors, UserConfig.with_default(), + this.constructor = new ChannelManagerConstructor(serialized, monitors, get_config(), this.keys_interface, this.fee_estimator, this.chain_monitor, filter_nullable, - this.router, this.tx_broadcaster, this.logger); + serialized_router, this.tx_broadcaster, this.logger); try { // Test that ChannelManagerConstructor correctly rejects duplicate ChannelMonitors byte[][] monitors_dupd = new byte[2][]; monitors_dupd[0] = monitors[0]; monitors_dupd[1] = monitors[0]; - ChannelManagerConstructor constr = this.constructor = new ChannelManagerConstructor(serialized, monitors_dupd, UserConfig.with_default(), + ChannelManagerConstructor constr = this.constructor = new ChannelManagerConstructor(serialized, monitors_dupd, get_config(), this.keys_interface, this.fee_estimator, this.chain_monitor, filter_nullable, null, this.tx_broadcaster, this.logger); assert false; } catch (ChannelManagerConstructor.InvalidSerializedDataException e) {} } + this.router = this.constructor.net_graph; + setup_route_handler(); MultiThreadedLockableScore scorer = null; - if (use_invoice_payer) { scorer = MultiThreadedLockableScore.of(Scorer.with_default().as_Score()); } + if (use_invoice_payer) { scorer = MultiThreadedLockableScore.of(ProbabilisticScorer.of(ProbabilisticScoringParameters.with_default(), this.router, this.logger).as_Score()); } constructor.chain_sync_completed(new ChannelManagerConstructor.EventHandler() { @Override public void handle_event(Event event) { synchronized (pending_manager_events) { @@ -450,6 +466,8 @@ 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_scorer(byte[] scorer_bytes) { assert scorer_bytes.length > 1; } }, scorer); this.chan_manager = constructor.channel_manager; this.payer = constructor.payer; @@ -466,6 +484,8 @@ class HumanObjectPeerTestInstance { assert false; } } else { + this.router = NetworkGraph.of(new byte[32], this.logger); + this.setup_route_handler(); ChannelMonitor[] monitors = new ChannelMonitor[1]; assert orig.monitors.size() == 1; if (!break_cross_peer_refs) { @@ -479,7 +499,7 @@ class HumanObjectPeerTestInstance { } byte[] serialized = orig.chan_manager.write(); Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ read_res = - UtilMethods.C2Tuple_BlockHashChannelManagerZ_read(serialized, this.keys_interface, this.fee_estimator, this.chain_watch, this.tx_broadcaster, this.logger, UserConfig.with_default(), monitors); + UtilMethods.C2Tuple_BlockHashChannelManagerZ_read(serialized, this.keys_interface, this.fee_estimator, this.chain_watch, this.tx_broadcaster, this.logger, get_config(), monitors); assert read_res instanceof Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ.Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_OK; this.chan_manager = ((Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ.Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_OK) read_res).res.get_b(); this.chain_watch.watch_channel(monitors[0].get_funding_txo().get_a(), monitors[0]); @@ -499,10 +519,10 @@ class HumanObjectPeerTestInstance { this.payer = InvoicePayer.of(this.chan_manager.as_Payer(), Router.new_impl(new Router.RouterInterface() { @Override public Result_RouteLightningErrorZ find_route(byte[] payer, RouteParameters params, byte[] _payment_hash, ChannelDetails[] first_hops, Score scorer) { - return UtilMethods.find_route(payer, params, router, first_hops, logger, scorer); + return UtilMethods.find_route(payer, params, router, first_hops, logger, scorer, new byte[32]); } }), MultiThreadedLockableScore.of(Score.new_impl(new Score.ScoreInterface() { - @Override public long channel_penalty_msat(long short_channel_id, long send_amt_msat, long channel_capacity_msat, NodeId source, NodeId target) { return 0; } + @Override public long channel_penalty_msat(long short_channel_id, NodeId source, NodeId target, ChannelUsage usage) { return 0; } @Override public void payment_path_failed(RouteHop[] path, long scid) {} @Override public void payment_path_successful(RouteHop[] path) {} @Override public byte[] write() { assert false; return null; } @@ -513,7 +533,7 @@ class HumanObjectPeerTestInstance { pending_manager_events.notifyAll(); } } - }), RetryAttempts.of(0)); + }), Retry.attempts(0)); } } this.node_id = chan_manager.get_our_node_id(); @@ -664,9 +684,6 @@ class HumanObjectPeerTestInstance { void maybe_exchange_peer_messages(Peer peer1, Peer peer2) { if (!use_nio_peer_handler) { - synchronized (runqueue) { - ran = false; - } while (true) { peer1.peer_manager.process_events(); peer2.peer_manager.process_events(); @@ -735,10 +752,10 @@ class HumanObjectPeerTestInstance { @Override public long hash() { return 1; } }); - Result_CVec_u8ZPeerHandleErrorZ conn_res = peer1.peer_manager.new_outbound_connection(peer2.node_id, descriptor1.val); + Result_CVec_u8ZPeerHandleErrorZ conn_res = peer1.peer_manager.new_outbound_connection(peer2.node_id, descriptor1.val, Option_NetAddressZ.none()); assert conn_res instanceof Result_CVec_u8ZPeerHandleErrorZ.Result_CVec_u8ZPeerHandleErrorZ_OK; - Result_NonePeerHandleErrorZ inbound_conn_res = peer2.peer_manager.new_inbound_connection(descriptor2); + Result_NonePeerHandleErrorZ inbound_conn_res = peer2.peer_manager.new_inbound_connection(descriptor2, Option_NetAddressZ.none()); assert inbound_conn_res instanceof Result_NonePeerHandleErrorZ.Result_NonePeerHandleErrorZ_OK; do_read_event(peer2.peer_manager, descriptor2, ((Result_CVec_u8ZPeerHandleErrorZ.Result_CVec_u8ZPeerHandleErrorZ_OK) conn_res).res); @@ -774,9 +791,11 @@ class HumanObjectPeerTestInstance { funding.getInputs().get(0).setWitness(new TransactionWitness(2)); // Make sure we don't complain about lack of witness funding.getInput(0).getWitness().setPush(0, new byte[]{0x1}); funding.addOutput(Coin.SATOSHI.multiply(100000), new Script(funding_spk)); - Result_NoneAPIErrorZ funding_res = peer1.chan_manager.funding_transaction_generated(chan_id, funding.bitcoinSerialize()); + Result_NoneAPIErrorZ funding_res = peer1.chan_manager.funding_transaction_generated(chan_id, peer2.node_id, funding.bitcoinSerialize()); assert funding_res instanceof Result_NoneAPIErrorZ.Result_NoneAPIErrorZ_OK; + gossip_txout = new TxOut(100000, funding_spk); + maybe_exchange_peer_messages(peer1, peer2); synchronized (peer1.broadcast_set) { while (peer1.broadcast_set.size() != 1) { @@ -814,14 +833,14 @@ class HumanObjectPeerTestInstance { assert Arrays.equals(peer1_chans[0].get_channel_id(), funding.getTxId().getReversedBytes()); assert Arrays.equals(peer2_chans[0].get_channel_id(), funding.getTxId().getReversedBytes()); - Result_InvoiceSignOrCreationErrorZ invoice = UtilMethods.create_invoice_from_channelmanager(peer2.chan_manager, peer2.keys_interface, Currency.LDKCurrency_Bitcoin, Option_u64Z.some(10000000), "Invoice Description"); + Result_InvoiceSignOrCreationErrorZ invoice = UtilMethods.create_invoice_from_channelmanager(peer2.chan_manager, peer2.keys_interface, Currency.LDKCurrency_Bitcoin, Option_u64Z.some(10000000), "Invoice Description", 7200); assert invoice instanceof Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK; System.out.println("Got invoice: " + ((Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK) invoice).res.to_str()); - Result_InvoiceNoneZ parsed_invoice = Invoice.from_str(((Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK) invoice).res.to_str()); - assert parsed_invoice instanceof Result_InvoiceNoneZ.Result_InvoiceNoneZ_OK; - assert Arrays.equals(((Result_InvoiceNoneZ.Result_InvoiceNoneZ_OK) parsed_invoice).res.payment_hash(), ((Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK) invoice).res.payment_hash()); - SignedRawInvoice signed_raw = ((Result_InvoiceNoneZ.Result_InvoiceNoneZ_OK) parsed_invoice).res.into_signed_raw(); + Result_InvoiceParseOrSemanticErrorZ parsed_invoice = Invoice.from_str(((Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK) invoice).res.to_str()); + assert parsed_invoice instanceof Result_InvoiceParseOrSemanticErrorZ.Result_InvoiceParseOrSemanticErrorZ_OK; + assert Arrays.equals(((Result_InvoiceParseOrSemanticErrorZ.Result_InvoiceParseOrSemanticErrorZ_OK) parsed_invoice).res.payment_hash(), ((Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK) invoice).res.payment_hash()); + SignedRawInvoice signed_raw = ((Result_InvoiceParseOrSemanticErrorZ.Result_InvoiceParseOrSemanticErrorZ_OK) parsed_invoice).res.into_signed_raw(); RawInvoice raw_invoice = signed_raw.raw_invoice(); byte[] desc_hash = raw_invoice.hash(); Description raw_invoice_description = raw_invoice.description(); @@ -836,11 +855,11 @@ class HumanObjectPeerTestInstance { InvoiceFeatures invoice_features = ((Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK) invoice).res.features(); RouteHint[] route_hints = ((Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK) invoice).res.route_hints(); - PaymentParameters payee = PaymentParameters.of(peer2.node_id, invoice_features, route_hints, Option_u64Z.none(), 6*24*14); + PaymentParameters payee = PaymentParameters.of(peer2.node_id, invoice_features, route_hints, Option_u64Z.none(), 6*24*14, (byte)1); RouteParameters route_params = RouteParameters.of(payee, 10000000, 42); Result_RouteLightningErrorZ route_res = UtilMethods.find_route( peer1.chan_manager.get_our_node_id(), route_params, peer1.router, - peer1_chans, peer1.logger, Scorer.with_default().as_Score()); + peer1_chans, peer1.logger, ProbabilisticScorer.of(ProbabilisticScoringParameters.with_default(), peer1.router, peer1.logger).as_Score(), new byte[32]); assert route_res instanceof Result_RouteLightningErrorZ.Result_RouteLightningErrorZ_OK; Route route = ((Result_RouteLightningErrorZ.Result_RouteLightningErrorZ_OK) route_res).res; assert route.get_paths().length == 1; @@ -859,7 +878,7 @@ class HumanObjectPeerTestInstance { payment_res = peer1.chan_manager.send_payment(r2, payment_hash, payment_secret); assert payment_res instanceof Result_PaymentIdPaymentSendFailureZ.Result_PaymentIdPaymentSendFailureZ_Err; } else { - Result_PaymentIdPaymentErrorZ send_res = peer1.payer.pay_invoice(((Result_InvoiceNoneZ.Result_InvoiceNoneZ_OK) parsed_invoice).res); + Result_PaymentIdPaymentErrorZ send_res = peer1.payer.pay_invoice(((Result_InvoiceParseOrSemanticErrorZ.Result_InvoiceParseOrSemanticErrorZ_OK) parsed_invoice).res); assert send_res instanceof Result_PaymentIdPaymentErrorZ.Result_PaymentIdPaymentErrorZ_OK; } @@ -916,6 +935,12 @@ class HumanObjectPeerTestInstance { assert !Arrays.equals(payment_preimage, new byte[32]); state.peer2.chan_manager.claim_funds(payment_preimage); + events = state.peer2.get_manager_events(1, state.peer1, state.peer2); + assert events[0] instanceof Event.PaymentClaimed; + assert ((Event.PaymentClaimed)events[0]).purpose instanceof PaymentPurpose.InvoicePayment; + payment_preimage = ((PaymentPurpose.InvoicePayment)((Event.PaymentClaimed)events[0]).purpose).payment_preimage; + assert !Arrays.equals(payment_preimage, new byte[32]); + events = state.peer1.get_manager_events(2, state.peer1, state.peer2); assert events[0] instanceof Event.PaymentSent; assert Arrays.equals(((Event.PaymentSent) events[0]).payment_preimage, payment_preimage); @@ -939,7 +964,7 @@ class HumanObjectPeerTestInstance { ChannelDetails[] peer1_chans = state.peer1.chan_manager.list_channels(); if (nice_close) { - Result_NoneAPIErrorZ close_res = state.peer1.chan_manager.close_channel(peer1_chans[0].get_channel_id()); + Result_NoneAPIErrorZ close_res = state.peer1.chan_manager.close_channel(peer1_chans[0].get_channel_id(), state.peer2.node_id); assert close_res instanceof Result_NoneAPIErrorZ.Result_NoneAPIErrorZ_OK; maybe_exchange_peer_messages(state.peer1, state.peer2); synchronized (state.peer1.broadcast_set) { @@ -948,11 +973,8 @@ class HumanObjectPeerTestInstance { synchronized (state.peer2.broadcast_set) { while (state.peer2.broadcast_set.size() != 1) state.peer2.broadcast_set.wait(); } - - assert state.peer1.broadcast_set.size() == 1; - assert state.peer2.broadcast_set.size() == 1; } else { - state.peer1.chan_manager.force_close_all_channels(); + state.peer1.chan_manager.force_close_all_channels_broadcasting_latest_txn(); maybe_exchange_peer_messages(state.peer1, state.peer2); synchronized (state.peer1.broadcast_set) { while (state.peer1.broadcast_set.size() != 1) state.peer1.broadcast_set.wait(); @@ -960,11 +982,11 @@ class HumanObjectPeerTestInstance { synchronized (state.peer2.broadcast_set) { while (state.peer2.broadcast_set.size() != 1) state.peer2.broadcast_set.wait(); } - - assert state.peer1.broadcast_set.size() == 1; - assert state.peer2.broadcast_set.size() == 1; } + assert state.peer1.broadcast_set.size() == 1; + assert state.peer2.broadcast_set.size() == 1; + events = state.peer2.get_manager_events(1, state.peer1, state.peer2); assert events[0] instanceof Event.ChannelClosed; events = state.peer1.get_manager_events(1, state.peer1, state.peer2); @@ -1061,7 +1083,8 @@ class HumanObjectPeerTestInstance { t.interrupt(); - state.peer1.router.write(); + if (state.peer1.router != null) + state.peer1.router.write(); // Construct the only Option_Enum::Variant(OpaqueStruct) we have in the codebase as this used to cause double-frees: byte[] serd = new byte[] {(byte)0xd9,(byte)0x77,(byte)0xcb,(byte)0x9b,(byte)0x53,(byte)0xd9,(byte)0x3a,(byte)0x6f,(byte)0xf6,(byte)0x4b,(byte)0xb5,(byte)0xf1,(byte)0xe1,(byte)0x58,(byte)0xb4,(byte)0x09,(byte)0x4b,(byte)0x66,(byte)0xe7,(byte)0x98,(byte)0xfb,(byte)0x12,(byte)0x91,(byte)0x11,(byte)0x68,(byte)0xa3,(byte)0xcc,(byte)0xdf,(byte)0x80,(byte)0xa8,(byte)0x30,(byte)0x96,(byte)0x34,(byte)0x0a,(byte)0x6a,(byte)0x95,(byte)0xda,(byte)0x0a,(byte)0xe8,(byte)0xd9,(byte)0xf7,(byte)0x76,(byte)0x52,(byte)0x8e,(byte)0xec,(byte)0xdb,(byte)0xb7,(byte)0x47,(byte)0xeb,(byte)0x6b,(byte)0x54,(byte)0x54,(byte)0x95,(byte)0xa4,(byte)0x31,(byte)0x9e,(byte)0xd5,(byte)0x37,(byte)0x8e,(byte)0x35,(byte)0xb2,(byte)0x1e,(byte)0x07,(byte)0x3a,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x19,(byte)0xd6,(byte)0x68,(byte)0x9c,(byte)0x08,(byte)0x5a,(byte)0xe1,(byte)0x65,(byte)0x83,(byte)0x1e,(byte)0x93,(byte)0x4f,(byte)0xf7,(byte)0x63,(byte)0xae,(byte)0x46,(byte)0xa2,(byte)0xa6,(byte)0xc1,(byte)0x72,(byte)0xb3,(byte)0xf1,(byte)0xb6,(byte)0x0a,(byte)0x8c,(byte)0xe2,(byte)0x6f,(byte)0x00,(byte)0x08,(byte)0x3a,(byte)0x84,(byte)0x00,(byte)0x00,(byte)0x03,(byte)0x4d,(byte)0x01,(byte)0x34,(byte)0x13,(byte)0xa7,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x90,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x0f,(byte)0x42,(byte)0x40,(byte)0x00,(byte)0x00,(byte)0x27,(byte)0x10,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x14,}; @@ -1083,13 +1106,13 @@ class HumanObjectPeerTestInstance { } } public class HumanObjectPeerTest { - HumanObjectPeerTestInstance do_test_run(boolean nice_close, boolean use_km_wrapper, boolean use_manual_watch, boolean reload_peers, boolean break_cross_peer_refs, boolean nio_peer_handler, boolean use_ignoring_routing_handler, boolean use_chan_manager_constructor, boolean use_invoice_payer) throws InterruptedException { + static HumanObjectPeerTestInstance do_test_run(boolean nice_close, boolean use_km_wrapper, boolean use_manual_watch, boolean reload_peers, boolean break_cross_peer_refs, boolean nio_peer_handler, boolean use_ignoring_routing_handler, boolean use_chan_manager_constructor, boolean use_invoice_payer) throws InterruptedException { HumanObjectPeerTestInstance instance = new HumanObjectPeerTestInstance(nice_close, use_km_wrapper, use_manual_watch, reload_peers, break_cross_peer_refs, nio_peer_handler, !nio_peer_handler, use_ignoring_routing_handler, use_chan_manager_constructor, use_invoice_payer); HumanObjectPeerTestInstance.TestState state = instance.do_test_message_handler(); instance.do_test_message_handler_b(state); return instance; } - void do_test(boolean nice_close, boolean use_km_wrapper, boolean use_manual_watch, boolean reload_peers, boolean break_cross_peer_refs, boolean nio_peer_handler, boolean use_ignoring_routing_handler, boolean use_chan_manager_constructor, boolean use_invoice_payer) throws InterruptedException { + static void do_test(boolean nice_close, boolean use_km_wrapper, boolean use_manual_watch, boolean reload_peers, boolean break_cross_peer_refs, boolean nio_peer_handler, boolean use_ignoring_routing_handler, boolean use_chan_manager_constructor, boolean use_invoice_payer) throws InterruptedException { HumanObjectPeerTestInstance instance = do_test_run(nice_close, use_km_wrapper, use_manual_watch, reload_peers, break_cross_peer_refs, nio_peer_handler, use_ignoring_routing_handler, use_chan_manager_constructor, use_invoice_payer); while (instance.gc_count != instance.gc_exp_count) { System.gc(); @@ -1098,8 +1121,8 @@ public class HumanObjectPeerTest { for (WeakReference o : instance.must_free_objs) assert o.get() == null; } - @Test - public void test_message_handler() throws InterruptedException { + public static final int TEST_ITERATIONS = (1 << 9); + public static void do_test_message_handler(IntConsumer statusFunction) throws InterruptedException { Thread gc_thread = new Thread(() -> { while (true) { System.gc(); @@ -1108,7 +1131,7 @@ public class HumanObjectPeerTest { } }, "Test GC Thread"); gc_thread.start(); - for (int i = 0; i < (1 << 9) - 1; i++) { + for (int i = 0; i < TEST_ITERATIONS; i++) { boolean nice_close = (i & (1 << 0)) != 0; boolean use_km_wrapper = (i & (1 << 1)) != 0; boolean use_manual_watch = (i & (1 << 2)) != 0; @@ -1137,17 +1160,21 @@ public class HumanObjectPeerTest { // InvoicePayer to send payments in this case. continue; } - System.err.println("Running test with flags " + i); + statusFunction.accept(i); do_test(nice_close, use_km_wrapper, use_manual_watch, reload_peers, break_cross_refs, nio_peer_handler, use_ignoring_routing_handler, use_chan_manager_constructor, use_invoice_payer); } gc_thread.interrupt(); gc_thread.join(); } + @Test + public void test_message_handler() throws InterruptedException { + do_test_message_handler(i -> System.err.println("Running test with flags " + i)); + } // This is used in the test jar to test the built jar is runnable public static void main(String[] args) { try { - new HumanObjectPeerTest().test_message_handler(); + do_test_message_handler(i -> System.err.println("Running test with flags " + i)); } catch (Exception e) { System.err.println("Caught exception:"); System.err.println(e);