package org.ldk;
+import org.bitcoinj.base.BitcoinNetwork;
+import org.bitcoinj.base.Coin;
+import org.bitcoinj.base.Sha256Hash;
import org.bitcoinj.core.*;
+import org.bitcoinj.params.BitcoinNetworkParams;
import org.bitcoinj.script.Script;
import org.junit.jupiter.api.Test;
import org.ldk.batteries.ChannelManagerConstructor;
if (use_chan_manager_constructor) {
this.constructor = new ChannelManagerConstructor(Network.LDKNetwork_Bitcoin, get_config(), new byte[32], 0,
- this.explicit_keys_manager, this.fee_estimator, this.chain_monitor, this.net_graph,
- ProbabilisticScoringParameters.with_default(), this.tx_broadcaster, this.logger);
+ this.explicit_keys_manager.as_EntropySource(), this.explicit_keys_manager.as_NodeSigner(), this.explicit_keys_manager.as_SignerProvider(),
+ this.fee_estimator, this.chain_monitor, this.net_graph,
+ ProbabilisticScoringParameters.with_default(), (ChannelManagerConstructor.RouterWrapper)
+ (payer_node_id, route_params, first_hops, inflight_htlcs, payment_hash, payment_id, default_router) -> {
+ assert payment_hash != null && payment_id != null;
+ Router r = default_router.as_Router();
+ must_free_objs.add(new WeakReference<>(r));
+ return r.find_route_with_id(payer_node_id, route_params, first_hops, inflight_htlcs, payment_hash, payment_id);
+ },
+ this.tx_broadcaster, this.logger);
constructor.chain_sync_completed(new ChannelManagerConstructor.EventHandler() {
@Override public void handle_event(Event event) {
synchronized (pending_manager_events) {
}
}
return UtilMethods.find_route(payer, params, net_graph, first_hops, logger, Score.new_impl(new Score.ScoreInterface() {
- @Override public void payment_path_failed(RouteHop[] path, long scid) {}
+ @Override public void payment_path_failed(Path path, long scid) {}
@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 void probe_failed(RouteHop[] path, long short_channel_id) { assert false; }
- @Override public void probe_successful(RouteHop[] path) { assert false; }
+ @Override public void payment_path_successful(Path path) {}
+ @Override public void probe_failed(Path path, long short_channel_id) { assert false; }
+ @Override public void probe_successful(Path path) { assert false; }
@Override public byte[] write() { assert false; return null; }
}), new byte[32]);
}
filter_nullable = ((Option_FilterZ.Some) this.filter).some;
}
this.constructor = new ChannelManagerConstructor(serialized, monitors, get_config(),
- this.explicit_keys_manager, this.fee_estimator, this.chain_monitor, filter_nullable,
- serialized_graph, ProbabilisticScoringParameters.with_default(), serialized_scorer,
+ this.explicit_keys_manager.as_EntropySource(), this.explicit_keys_manager.as_NodeSigner(), this.explicit_keys_manager.as_SignerProvider(),
+ this.fee_estimator, this.chain_monitor, filter_nullable,
+ serialized_graph, ProbabilisticScoringParameters.with_default(), serialized_scorer, null,
this.tx_broadcaster, this.logger);
try {
// Test that ChannelManagerConstructor correctly rejects duplicate ChannelMonitors
monitors_dupd[0] = monitors[0];
monitors_dupd[1] = monitors[0];
ChannelManagerConstructor constr = new ChannelManagerConstructor(serialized, monitors_dupd, get_config(),
- this.explicit_keys_manager, this.fee_estimator, this.chain_monitor, filter_nullable,
- serialized_graph, ProbabilisticScoringParameters.with_default(), serialized_scorer,
+ this.explicit_keys_manager.as_EntropySource(), this.explicit_keys_manager.as_NodeSigner(), this.explicit_keys_manager.as_SignerProvider(),
+ this.fee_estimator, this.chain_monitor, filter_nullable,
+ serialized_graph, ProbabilisticScoringParameters.with_default(), serialized_scorer, null,
this.tx_broadcaster, this.logger);
assert false;
} catch (ChannelManagerConstructor.InvalidSerializedDataException e) {}
}
}
return UtilMethods.find_route(payer, params, net_graph, first_hops, logger, Score.new_impl(new Score.ScoreInterface() {
- @Override public void payment_path_failed(RouteHop[] path, long scid) {}
+ @Override public void payment_path_failed(Path path, long scid) {}
@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 void probe_failed(RouteHop[] path, long short_channel_id) { assert false; }
- @Override public void probe_successful(RouteHop[] path) { assert false; }
+ @Override public void payment_path_successful(Path path) {}
+ @Override public void probe_failed(Path path, long short_channel_id) { assert false; }
+ @Override public void probe_successful(Path path) { assert false; }
@Override public byte[] write() { assert false; return null; }
}), new byte[32]);
}
assert funding_spk.length == 34 && funding_spk[0] == 0 && funding_spk[1] == 32; // P2WSH
byte[] chan_id = ((Event.FundingGenerationReady) events[0]).temporary_channel_id;
- NetworkParameters bitcoinj_net = NetworkParameters.fromID(NetworkParameters.ID_MAINNET);
+ BitcoinNetworkParams bitcoinj_net = BitcoinNetworkParams.of(BitcoinNetwork.MAINNET);
Transaction funding = new Transaction(bitcoinj_net);
funding.addInput(new TransactionInput(bitcoinj_net, funding, new byte[0]));
}
}
+ events = peer1.get_manager_events(1, peer1, peer2);
+ assert events[0] instanceof Event.ChannelPending;
+
+ events = peer2.get_manager_events(1, peer1, peer2);
+ assert events[0] instanceof Event.ChannelPending;
+
assert peer1.broadcast_set.size() == 1;
assert Arrays.equals(peer1.broadcast_set.get(0), funding.bitcoinSerialize());
peer1.broadcast_set.clear();
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 ((Result_InvoiceParseOrSemanticErrorZ.Result_InvoiceParseOrSemanticErrorZ_OK) parsed_invoice).res.fallback_addresses().length == 0;
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();
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, (byte)1, (byte)2, new long[0], 42);
+ PaymentParameters payee = PaymentParameters.of(peer2.node_id, invoice_features, Hints.clear(route_hints), Option_u64Z.none(), 6*24*14, (byte)1, (byte)2, new long[0], 42);
RouteParameters route_params = RouteParameters.of(payee, 10000000);
Result_RouteLightningErrorZ route_res = UtilMethods.find_route(
peer1.chan_manager.get_our_node_id(), route_params, peer1.net_graph,
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;
- assert route.get_paths()[0].length == 1;
- assert route.get_paths()[0][0].get_fee_msat() == 10000000;
+ assert route.get_paths()[0].get_hops().length == 1;
+ assert route.get_paths()[0].final_value_msat() == 10000000;
byte[] payment_id = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 };
- Result_NonePaymentSendFailureZ payment_res = peer1.chan_manager.send_payment(route, payment_hash, payment_secret, payment_id);
+ Result_NonePaymentSendFailureZ payment_res = peer1.chan_manager.send_payment_with_route(route, payment_hash, RecipientOnionFields.secret_only(payment_secret), payment_id);
assert payment_res instanceof Result_NonePaymentSendFailureZ.Result_NonePaymentSendFailureZ_OK;
- RouteHop[][] hops = new RouteHop[1][1];
+ RouteHop[] hops = new RouteHop[1];
byte[] hop_pubkey = new byte[33];
hop_pubkey[0] = 3;
hop_pubkey[1] = 42;
NodeFeatures node_features = NodeFeatures.empty();
ChannelFeatures channel_features = ChannelFeatures.empty();
- hops[0][0] = RouteHop.of(hop_pubkey, node_features, 42, channel_features, 100, 0);
- Route r2 = Route.of(hops, payee);
- payment_res = peer1.chan_manager.send_payment(r2, payment_hash, payment_secret, payment_id);
+ hops[0] = RouteHop.of(hop_pubkey, node_features, 42, channel_features, 100, 0);
+ Path[] paths = new Path[1];
+ paths[0] = Path.of(hops, null);
+ Route r2 = Route.of(paths, payee);
+ payment_res = peer1.chan_manager.send_payment_with_route(r2, payment_hash, RecipientOnionFields.secret_only(payment_secret), payment_id);
assert payment_res instanceof Result_NonePaymentSendFailureZ.Result_NonePaymentSendFailureZ_Err;
} else {
Result_PaymentIdPaymentErrorZ send_res = UtilMethods.pay_invoice(((Result_InvoiceParseOrSemanticErrorZ.Result_InvoiceParseOrSemanticErrorZ_OK) parsed_invoice).res, Retry.attempts(0), peer1.chan_manager);
this.best_blockhash = best_blockhash;
}
}
- void do_test_message_handler_b(TestState state) throws InterruptedException {
+ void do_test_message_handler_b(TestState state) throws Exception {
GcCheck obj = new GcCheck();
if (state.ref_block != null) {
// Ensure the original peers get freed before we move on. Note that we have to be in a different function
}
if (!nice_close) {
- NetworkParameters bitcoinj_net = NetworkParameters.fromID(NetworkParameters.ID_MAINNET);
+ BitcoinNetworkParams bitcoinj_net = BitcoinNetworkParams.of(BitcoinNetwork.MAINNET);
Transaction tx = new Transaction(bitcoinj_net, state.peer1.broadcast_set.getFirst());
Block b = new Block(bitcoinj_net, 2, state.best_blockhash, Sha256Hash.ZERO_HASH, 42, 0, 0,
Arrays.asList(new Transaction[]{tx}));
assert upd_msg instanceof Result_ChannelUpdateDecodeErrorZ.Result_ChannelUpdateDecodeErrorZ_OK;
assert ((Result_ChannelUpdateDecodeErrorZ.Result_ChannelUpdateDecodeErrorZ_OK) upd_msg).res.get_contents().get_htlc_maximum_msat() == 0xdeadbeef42424242L;
Option_NetworkUpdateZ upd = Option_NetworkUpdateZ.some(NetworkUpdate.channel_update_message(((Result_ChannelUpdateDecodeErrorZ.Result_ChannelUpdateDecodeErrorZ_OK) upd_msg).res));
+
+ if (use_chan_manager_constructor) {
+ // Lock the scorer twice back-to-back to check that the try-with-resources AutoCloseable on the scorer works.
+ try (ChannelManagerConstructor.ScorerWrapper score = state.peer1.constructor.get_locked_scorer()) {
+ score.prob_scorer.debug_log_liquidity_stats();
+ }
+ try (ChannelManagerConstructor.ScorerWrapper score = state.peer1.constructor.get_locked_scorer()) {
+ score.prob_scorer.clear_manual_penalties();
+ }
+ }
}
java.util.LinkedList<WeakReference<Object>> must_free_objs = new java.util.LinkedList();
}
}
public class HumanObjectPeerTest {
- 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 {
+ 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 Exception {
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;
}
- 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 {
+ 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 Exception {
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();
assert o.get() == null;
}
public static final int TEST_ITERATIONS = (1 << 9);
- public static void do_test_message_handler(IntConsumer statusFunction) throws InterruptedException {
+ public static void do_test_message_handler(IntConsumer statusFunction) throws Exception {
Thread gc_thread = new Thread(() -> {
while (true) {
System.gc();
gc_thread.join();
}
@Test
- public void test_message_handler() throws InterruptedException {
+ public void test_message_handler() throws Exception {
do_test_message_handler(i -> System.err.println("Running test with flags " + i));
}