ChannelManagerConstructor constructor = null;
GcCheck obj = new GcCheck();
- private TwoTuple<OutPoint, byte[]> test_mon_roundtrip(ChannelMonitor mon) {
+ private TwoTuple_OutPointScriptZ test_mon_roundtrip(ChannelMonitor mon) {
// Because get_funding_txo() returns an OutPoint in a tuple that is a reference to an OutPoint inside the
// ChannelMonitor, its a good test to ensure that the OutPoint isn't freed (or is cloned) before the
// ChannelMonitor is. This used to be broken.
- Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ roundtrip_monitor = UtilMethods.BlockHashChannelMonitorZ_read(mon.write(), keys_interface);
+ Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ roundtrip_monitor = UtilMethods.C2Tuple_BlockHashChannelMonitorZ_read(mon.write(), keys_interface);
assert roundtrip_monitor instanceof Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ.Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_OK;
- TwoTuple<OutPoint, byte[]> funding_txo = ((Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ.Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_OK) roundtrip_monitor).res.b.get_funding_txo();
+ TwoTuple_OutPointScriptZ funding_txo = ((Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ.Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_OK) roundtrip_monitor).res.get_b().get_funding_txo();
System.gc(); System.runFinalization(); // Give the GC a chance to run.
return funding_txo;
}
synchronized (monitors) {
String key = Arrays.toString(id.to_channel_id());
assert monitors.put(key, data) == null;
- TwoTuple<OutPoint, byte[]> res = test_mon_roundtrip(data);
- assert Arrays.equals(res.a.get_txid(), id.get_txid());
- assert res.a.get_index() == id.get_index();
+ TwoTuple_OutPointScriptZ res = test_mon_roundtrip(data);
+ assert Arrays.equals(res.get_a().get_txid(), id.get_txid());
+ assert res.get_a().get_index() == id.get_index();
}
return Result_NoneChannelMonitorUpdateErrZ.ok();
}
synchronized (monitors) {
String key = Arrays.toString(id.to_channel_id());
assert monitors.put(key, data) != null;
- TwoTuple<OutPoint, byte[]> res = test_mon_roundtrip(data);
- assert Arrays.equals(res.a.get_txid(), id.get_txid());
- assert res.a.get_index() == id.get_index();
+ TwoTuple_OutPointScriptZ res = test_mon_roundtrip(data);
+ assert Arrays.equals(res.get_a().get_txid(), id.get_txid());
+ assert res.get_a().get_index() == id.get_index();
}
return Result_NoneChannelMonitorUpdateErrZ.ok();
}
this.keys_interface = keys.as_KeysInterface();
this.explicit_keys_manager = keys;
}
- this.router = NetGraphMsgHandler.of(new byte[32], Option_AccessZ.some(Access.new_impl(new Access.AccessInterface() {
+ this.router = NetGraphMsgHandler.of(NetworkGraph.of(new byte[32]), 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)
}
@Override
- public TwoTuple<byte[], Type>[] get_and_clear_pending_msg() {
+ public TwoTuple_PublicKeyTypeZ[] get_and_clear_pending_msg() {
byte[][] bytes;
synchronized (custom_messages_to_send) {
bytes = custom_messages_to_send.toArray(new byte[0][0]);
custom_messages_to_send.clear();
}
- TwoTuple[] ret = new TwoTuple[bytes.length];
+ TwoTuple_PublicKeyTypeZ[] ret = new TwoTuple_PublicKeyTypeZ[bytes.length];
for (int i = 0; i < bytes.length; i++) {
final int msg_idx = i;
- ret[i] = new TwoTuple(connected_peer_node_id, Type.new_impl(new Type.TypeInterface() {
+ ret[i] = TwoTuple_PublicKeyTypeZ.of(connected_peer_node_id, Type.new_impl(new Type.TypeInterface() {
@Override public short type_id() { return 4096; }
@Override public String debug_str() { return "Custom Java Message"; }
@Override public byte[] write() { return bytes[msg_idx]; }
} else {
byte[] serialized = orig.monitors.values().stream().iterator().next().write();
Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ res =
- UtilMethods.BlockHashChannelMonitorZ_read(serialized, this.keys_interface);
+ UtilMethods.C2Tuple_BlockHashChannelMonitorZ_read(serialized, this.keys_interface);
assert res instanceof Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ.Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_OK;
- monitors[0] = ((Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ.Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_OK) res).res.b;
+ monitors[0] = ((Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ.Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_OK) res).res.get_b();
}
byte[] serialized = orig.chan_manager.write();
Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ read_res =
- UtilMethods.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, UserConfig.with_default(), 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.b;
- this.chain_watch.watch_channel(monitors[0].get_funding_txo().a, monitors[0]);
+ 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]);
byte[] random_data = keys_interface.get_secure_random_bytes();
this.peer_manager = PeerManager.of(chan_manager.as_ChannelMessageHandler(), router.as_RoutingMessageHandler(), keys_interface.get_node_secret(), random_data, logger, this.custom_message_handler);
if (!break_cross_peer_refs && (use_manual_watch || use_km_wrapper)) {
}
}
- TwoTuple<byte[], TwoTuple<Integer, TxOut>[]>[] connect_block(Block b, int height, long expected_monitor_update_len) {
+ TwoTuple_TxidCVec_C2Tuple_u32TxOutZZZ[] connect_block(Block b, int height, long expected_monitor_update_len) {
byte[] header = Arrays.copyOfRange(b.bitcoinSerialize(), 0, 80);
- TwoTuple<Long, byte[]>[] txn;
+ TwoTuple_usizeTransactionZ[] txn;
if (b.hasTransactions()) {
assert b.getTransactions().size() == 1;
- TwoTuple<Long, byte[]> txp = new TwoTuple<>((long) 0, b.getTransactions().get(0).bitcoinSerialize());
- txn = new TwoTuple[]{txp};
+ TwoTuple_usizeTransactionZ txp = TwoTuple_usizeTransactionZ.of((long) 0, b.getTransactions().get(0).bitcoinSerialize());
+ txn = new TwoTuple_usizeTransactionZ[]{txp};
} else
- txn = new TwoTuple[0];
+ txn = new TwoTuple_usizeTransactionZ[0];
if (chain_monitor != null) {
chan_manager.as_Listen().block_connected(b.bitcoinSerialize(), height);
chain_monitor.as_Listen().block_connected(b.bitcoinSerialize(), height);
synchronized (monitors) {
assert monitors.size() == 1;
for (ChannelMonitor mon : monitors.values()) {
- TwoTuple<byte[], TwoTuple<Integer, TxOut>[]>[] ret = mon.block_connected(header, txn, height, tx_broadcaster, fee_estimator, logger);
+ TwoTuple_TxidCVec_C2Tuple_u32TxOutZZZ[] ret = mon.block_connected(header, txn, height, tx_broadcaster, fee_estimator, logger);
assert ret.length == expected_monitor_update_len;
return ret;
}
connect_peers(peer1, peer2);
- Result_NoneAPIErrorZ cc_res = peer1.chan_manager.create_channel(peer2.node_id, 100000, 1000, 42, null);
- assert cc_res instanceof Result_NoneAPIErrorZ.Result_NoneAPIErrorZ_OK;
+ Result__u832APIErrorZ cc_res = peer1.chan_manager.create_channel(peer2.node_id, 100000, 1000, 42, null);
+ assert cc_res instanceof Result__u832APIErrorZ.Result__u832APIErrorZ_OK;
// Previously, this was a SEGFAULT instead of get_funding_txo() returning null.
ChannelDetails pre_funding_chan = peer1.chan_manager.list_channels()[0];
InvoiceFeatures invoice_features = ((Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK) invoice).res.features();
RouteHint[] route_hints = ((Result_InvoiceSignOrCreationErrorZ.Result_InvoiceSignOrCreationErrorZ_OK) invoice).res.route_hints();
- Result_RouteLightningErrorZ route_res = UtilMethods.get_route(peer1.chan_manager.get_our_node_id(), peer1.router.get_network_graph(), peer2.node_id, invoice_features, peer1_chans, route_hints, 10000000, 42, peer1.logger);
+ Result_RouteLightningErrorZ route_res = UtilMethods.get_route(
+ peer1.chan_manager.get_our_node_id(), peer1.router.get_network_graph(), peer2.node_id, invoice_features,
+ peer1_chans, route_hints, 10000000, 42, peer1.logger, Scorer.with_default().as_Score());
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;
- Result_NonePaymentSendFailureZ payment_res = peer1.chan_manager.send_payment(route, payment_hash, payment_secret);
- assert payment_res instanceof Result_NonePaymentSendFailureZ.Result_NonePaymentSendFailureZ_OK;
+ Result_PaymentIdPaymentSendFailureZ payment_res = peer1.chan_manager.send_payment(route, payment_hash, payment_secret);
+ assert payment_res instanceof Result_PaymentIdPaymentSendFailureZ.Result_PaymentIdPaymentSendFailureZ_OK;
RouteHop[][] hops = new RouteHop[1][1];
byte[] hop_pubkey = new byte[33];
hops[0][0] = RouteHop.of(hop_pubkey, NodeFeatures.known(), 42, ChannelFeatures.known(), 100, 0);
Route r2 = Route.of(hops);
payment_res = peer1.chan_manager.send_payment(r2, payment_hash, payment_secret);
- assert payment_res instanceof Result_NonePaymentSendFailureZ.Result_NonePaymentSendFailureZ_Err;
+ assert payment_res instanceof Result_PaymentIdPaymentSendFailureZ.Result_PaymentIdPaymentSendFailureZ_Err;
if (reload_peers) {
if (use_chan_manager_constructor) {
Thread.sleep(100);
}
+ if (state.peer1.chain_monitor != null) {
+ Balance[] peer1_balances = state.peer1.chain_monitor.get_claimable_balances(state.peer1.chan_manager.list_channels());
+ assert peer1_balances.length == 0;
+ Balance[] peer2_balances = state.peer2.chain_monitor.get_claimable_balances(state.peer2.chan_manager.list_channels());
+ assert peer2_balances.length == 0;
+ }
+
ChannelDetails[] peer1_chans = state.peer1.chan_manager.list_channels();
if (nice_close) {
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);
+ assert events[0] instanceof Event.ChannelClosed;
+
+ if (state.peer1.chain_monitor != null) {
+ Balance[] peer1_balances = state.peer1.chain_monitor.get_claimable_balances(state.peer1.chan_manager.list_channels());
+ assert peer1_balances.length == 1;
+ for (Balance bal : peer1_balances) {
+ assert bal instanceof Balance.ClaimableOnChannelClose;
+ long expected_tx_fee = 183;
+ assert ((Balance.ClaimableOnChannelClose) bal).claimable_amount_satoshis == 100000 - 1 - 10000 - expected_tx_fee;
+ }
+ Balance[] peer2_balances = state.peer2.chain_monitor.get_claimable_balances(state.peer2.chan_manager.list_channels());
+ assert peer2_balances.length == 1;
+ for (Balance bal : peer2_balances) {
+ assert bal instanceof Balance.ClaimableOnChannelClose;
+ assert ((Balance.ClaimableOnChannelClose) bal).claimable_amount_satoshis == 10000 + 1;
+ }
+ }
+
+ if (!nice_close) {
NetworkParameters bitcoinj_net = NetworkParameters.fromID(NetworkParameters.ID_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}));
- TwoTuple<byte[], TwoTuple<Integer, TxOut>[]>[] watch_outputs = state.peer2.connect_block(b, 10, 1);
+ TwoTuple_TxidCVec_C2Tuple_u32TxOutZZZ[] watch_outputs = state.peer2.connect_block(b, 10, 1);
if (watch_outputs != null) { // We only process watch_outputs manually when we use a manually-build Watch impl
assert watch_outputs.length == 1;
- assert Arrays.equals(watch_outputs[0].a, tx.getTxId().getReversedBytes());
- assert watch_outputs[0].b.length == 2;
- assert watch_outputs[0].b[0].a == 0;
- assert watch_outputs[0].b[1].a == 1;
+ assert Arrays.equals(watch_outputs[0].get_a(), tx.getTxId().getReversedBytes());
+ assert watch_outputs[0].get_b().length == 2;
+ assert watch_outputs[0].get_b()[0].get_a() == 0;
+ assert watch_outputs[0].get_b()[1].get_a() == 1;
}
for (int i = 11; i < 21; i++) {
}
}
- // Test exchanging a custom message
- byte[] custom_message_bytes = new byte[] { 0x42, 0x44, 0x43, 0x00 };
- state.peer1.custom_messages_to_send.add(custom_message_bytes);
- state.peer1.peer_manager.process_events();
- synchronized (state.peer2.received_custom_messages) {
- while (true) {
- if (state.peer2.received_custom_messages.isEmpty()) {
- state.peer2.received_custom_messages.wait();
- continue;
+ // Test exchanging a custom message (note that ChannelManagerConstructor) always loads an IgnorimgMessageHandler
+ // so we cannot exchange custom messages with it
+ if (!use_chan_manager_constructor) {
+ byte[] custom_message_bytes = new byte[]{0x42, 0x44, 0x43, 0x00};
+ state.peer1.custom_messages_to_send.add(custom_message_bytes);
+ state.peer1.peer_manager.process_events();
+ synchronized (state.peer2.received_custom_messages) {
+ while (true) {
+ if (state.peer2.received_custom_messages.isEmpty()) {
+ state.peer2.received_custom_messages.wait();
+ continue;
+ }
+ assert state.peer2.received_custom_messages.size() == 1;
+ assert Arrays.equals(state.peer2.received_custom_messages.get(0), custom_message_bytes);
+ break;
}
- assert state.peer2.received_custom_messages.size() == 1;
- assert Arrays.equals(state.peer2.received_custom_messages.get(0), custom_message_bytes);
- break;
}
}
}
@Test
public void test_message_handler() throws InterruptedException {
- for (int i = 0; i < (1 << 7) - 1; i++) {
+ for (int i = 0; i < (1 << 8) - 1; i++) {
boolean nice_close = (i & (1 << 0)) != 0;
boolean use_km_wrapper = (i & (1 << 1)) != 0;
boolean use_manual_watch = (i & (1 << 2)) != 0;