1414import java .io .IOException ;
1515import java .lang .ref .WeakReference ;
1616import java .net .InetSocketAddress ;
17- import java .util .ArrayList ;
18- import java .util .Arrays ;
19- import java .util .HashMap ;
20- import java .util .LinkedList ;
17+ import java .util .*;
2118
2219class HumanObjectPeerTestInstance {
2320 private final boolean nice_close ;
@@ -26,14 +23,16 @@ class HumanObjectPeerTestInstance {
2623 private final boolean reload_peers ;
2724 private final boolean break_cross_peer_refs ;
2825 private final boolean use_nio_peer_handler ;
26+ private final boolean use_filter ;
2927
30- 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 ) {
28+ 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 ) {
3129 this .nice_close = nice_close ;
3230 this .use_km_wrapper = use_km_wrapper ;
3331 this .use_manual_watch = use_manual_watch ;
3432 this .reload_peers = reload_peers ;
3533 this .break_cross_peer_refs = break_cross_peer_refs ;
3634 this .use_nio_peer_handler = use_nio_peer_handler ;
35+ this .use_filter = use_filter ;
3736 }
3837
3938 class Peer {
@@ -167,6 +166,8 @@ public MonitorEvent[] release_pending_monitor_events() {
167166 final ChainMonitor chain_monitor ;
168167 final NetGraphMsgHandler router ;
169168 final Watch chain_watch ;
169+ final HashSet <String > filter_additions ;
170+ final Filter filter ;
170171 ChannelManager chan_manager ;
171172 EventsProvider chan_manager_events ;
172173 PeerManager peer_manager ;
@@ -218,11 +219,26 @@ public Result_NoneChannelMonitorUpdateErrZ update_persisted_channel(OutPoint id,
218219 return new Result_NoneChannelMonitorUpdateErrZ .Result_NoneChannelMonitorUpdateErrZ_OK ();
219220 }
220221 });
222+
223+ filter_additions = new HashSet <>();
224+ if (use_filter ) {
225+ this .filter = Filter .new_impl (new Filter .FilterInterface () {
226+ @ Override public void register_tx (byte [] txid , byte [] script_pubkey ) {
227+ filter_additions .add (Arrays .toString (txid ));
228+ }
229+ @ Override public void register_output (OutPoint outpoint , byte [] script_pubkey ) {
230+ filter_additions .add (Arrays .toString (outpoint .get_txid ()) + ":" + outpoint .get_index ());
231+ }
232+ });
233+ } else {
234+ this .filter = null ;
235+ }
236+
221237 if (use_manual_watch ) {
222238 chain_watch = get_manual_watch ();
223239 chain_monitor = null ;
224240 } else {
225- chain_monitor = ChainMonitor .constructor_new (null , tx_broadcaster , logger , fee_estimator , persister );
241+ chain_monitor = ChainMonitor .constructor_new (filter , tx_broadcaster , logger , fee_estimator , persister );
226242 chain_watch = chain_monitor .as_Watch ();
227243 }
228244
@@ -286,9 +302,14 @@ private void bind_nio() {
286302 }
287303 byte [] serialized = orig .chan_manager .write ();
288304 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 );
305+ 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 );
290306 this .chan_manager = constructed .channel_manager ;
291307 constructed .chain_sync_completed ();
308+ if (use_filter && !use_manual_watch ) {
309+ // With a manual watch we don't actually use the filter object at all.
310+ assert this .filter_additions .containsAll (orig .filter_additions ) &&
311+ orig .filter_additions .containsAll (this .filter_additions );
312+ }
292313 } catch (ChannelManagerConstructor .InvalidSerializedDataException e ) {
293314 assert false ;
294315 }
@@ -673,7 +694,7 @@ protected void finalize() throws Throwable {
673694}
674695public class HumanObjectPeerTest {
675696 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 {
676- HumanObjectPeerTestInstance instance = new HumanObjectPeerTestInstance (nice_close , use_km_wrapper , use_manual_watch , reload_peers , break_cross_peer_refs , nio_peer_handler );
697+ HumanObjectPeerTestInstance instance = new HumanObjectPeerTestInstance (nice_close , use_km_wrapper , use_manual_watch , reload_peers , break_cross_peer_refs , nio_peer_handler , ! nio_peer_handler );
677698 HumanObjectPeerTestInstance .TestState state = instance .do_test_message_handler ();
678699 instance .do_test_message_handler_b (state );
679700 return instance ;
0 commit comments