package org.ldk.batteries;
+import org.jetbrains.annotations.Nullable;
import org.ldk.enums.LDKNetwork;
import org.ldk.structs.*;
import org.ldk.util.TwoTuple;
/**
* Deserializes a channel manager and a set of channel monitors from the given serialized copies and interface implementations
+ *
+ * @param filter If provided, the outputs which were previously registered to be monitored for will be loaded into the filter.
*/
public ChannelManagerConstructor(byte[] channel_manager_serialized, byte[][] channel_monitors_serialized,
- KeysInterface keys_interface, FeeEstimator fee_estimator, Watch chain_watch,
+ KeysInterface keys_interface, FeeEstimator fee_estimator, Watch chain_watch, @Nullable Filter filter,
BroadcasterInterface tx_broadcaster, Logger logger) throws InvalidSerializedDataException {
final ChannelMonitor[] monitors = new ChannelMonitor[channel_monitors_serialized.length];
this.channel_monitors = new TwoTuple[monitors.length];
this.channel_manager = ((Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ.Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_OK)res).res.b;
this.channel_manager_latest_block_hash = ((Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ.Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_OK)res).res.a;
this.chain_watch = chain_watch;
+ if (filter != null) {
+ for (ChannelMonitor monitor : monitors) {
+ monitor.load_outputs_to_watch(filter);
+ }
+ }
}
/**
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.net.InetSocketAddress;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.LinkedList;
+import java.util.*;
class HumanObjectPeerTestInstance {
private final boolean nice_close;
private final boolean reload_peers;
private final boolean break_cross_peer_refs;
private final boolean use_nio_peer_handler;
+ private final boolean use_filter;
- 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) {
+ 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) {
this.nice_close = nice_close;
this.use_km_wrapper = use_km_wrapper;
this.use_manual_watch = use_manual_watch;
this.reload_peers = reload_peers;
this.break_cross_peer_refs = break_cross_peer_refs;
this.use_nio_peer_handler = use_nio_peer_handler;
+ this.use_filter = use_filter;
}
class Peer {
final ChainMonitor chain_monitor;
final NetGraphMsgHandler router;
final Watch chain_watch;
+ final HashSet<String> filter_additions;
+ final Filter filter;
ChannelManager chan_manager;
EventsProvider chan_manager_events;
PeerManager peer_manager;
return new Result_NoneChannelMonitorUpdateErrZ.Result_NoneChannelMonitorUpdateErrZ_OK();
}
});
+
+ filter_additions = new HashSet<>();
+ if (use_filter) {
+ this.filter = Filter.new_impl(new Filter.FilterInterface() {
+ @Override public void register_tx(byte[] txid, byte[] script_pubkey) {
+ filter_additions.add(Arrays.toString(txid));
+ }
+ @Override public void register_output(OutPoint outpoint, byte[] script_pubkey) {
+ filter_additions.add(Arrays.toString(outpoint.get_txid()) + ":" + outpoint.get_index());
+ }
+ });
+ } else {
+ this.filter = null;
+ }
+
if (use_manual_watch) {
chain_watch = get_manual_watch();
chain_monitor = null;
} else {
- chain_monitor = ChainMonitor.constructor_new(null, tx_broadcaster, logger, fee_estimator, persister);
+ chain_monitor = ChainMonitor.constructor_new(filter, tx_broadcaster, logger, fee_estimator, persister);
chain_watch = chain_monitor.as_Watch();
}
}
byte[] serialized = orig.chan_manager.write();
try {
- 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);
+ ChannelManagerConstructor constructed = new ChannelManagerConstructor(serialized, channel_monitors.toArray(new byte[1][]), this.keys_interface, this.fee_estimator, this.chain_watch, this.filter, this.tx_broadcaster, this.logger);
this.chan_manager = constructed.channel_manager;
constructed.chain_sync_completed();
+ if (use_filter && !use_manual_watch) {
+ // With a manual watch we don't actually use the filter object at all.
+ assert this.filter_additions.containsAll(orig.filter_additions) &&
+ orig.filter_additions.containsAll(this.filter_additions);
+ }
} catch (ChannelManagerConstructor.InvalidSerializedDataException e) {
assert false;
}
}
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) throws InterruptedException {
- HumanObjectPeerTestInstance instance = new HumanObjectPeerTestInstance(nice_close, use_km_wrapper, use_manual_watch, reload_peers, break_cross_peer_refs, nio_peer_handler);
+ HumanObjectPeerTestInstance instance = new HumanObjectPeerTestInstance(nice_close, use_km_wrapper, use_manual_watch, reload_peers, break_cross_peer_refs, nio_peer_handler, !nio_peer_handler);
HumanObjectPeerTestInstance.TestState state = instance.do_test_message_handler();
instance.do_test_message_handler_b(state);
return instance;