@@ -162,6 +162,7 @@ public MonitorEvent[] release_pending_monitor_events() {
162162 final Logger logger ;
163163 final FeeEstimator fee_estimator ;
164164 final BroadcasterInterface tx_broadcaster ;
165+ final KeysManager explicit_keys_manager ;
165166 final KeysInterface keys_interface ;
166167 final ChainMonitor chain_monitor ;
167168 final NetGraphMsgHandler router ;
@@ -251,8 +252,10 @@ public Result_NoneChannelMonitorUpdateErrZ update_persisted_channel(OutPoint id,
251252 KeysManager keys = KeysManager .constructor_new (key_seed , System .currentTimeMillis () / 1000 , (int ) (System .currentTimeMillis () * 1000 ));
252253 if (use_km_wrapper ) {
253254 this .keys_interface = manual_keysif (keys .as_KeysInterface ());
255+ this .explicit_keys_manager = null ;
254256 } else {
255257 this .keys_interface = keys .as_KeysInterface ();
258+ this .explicit_keys_manager = keys ;
256259 }
257260 this .router = NetGraphMsgHandler .constructor_new (new byte [32 ], null , logger );
258261 }
@@ -349,7 +352,7 @@ TwoTuple<byte[], TwoTuple<Integer, TxOut>[]>[] connect_block(Block b, int height
349352 TwoTuple <Long , byte []>[] txn ;
350353 if (b .hasTransactions ()) {
351354 assert b .getTransactions ().size () == 1 ;
352- TwoTuple <Long , byte []> txp = new TwoTuple <>((long ) 1 , b .getTransactions ().get (0 ).bitcoinSerialize ());
355+ TwoTuple <Long , byte []> txp = new TwoTuple <>((long ) 0 , b .getTransactions ().get (0 ).bitcoinSerialize ());
353356 txn = new TwoTuple []{txp };
354357 } else
355358 txn = new TwoTuple [0 ];
@@ -387,7 +390,7 @@ Route get_route(byte[] dest_node, ChannelDetails[] our_chans) {
387390 try (LockedNetworkGraph netgraph = this .router .read_locked_graph ()) {
388391 NetworkGraph graph = netgraph .graph ();
389392 long res = bindings .get_route (this .node_id , graph ._test_only_get_ptr (), dest_node , 0L , new long []{our_chans [0 ]._test_only_get_ptr ()},
390- new long [0 ], 1000 , 42 , this .logger ._test_only_get_ptr ());
393+ new long [0 ], 1000000 , 42 , this .logger ._test_only_get_ptr ());
391394 assert bindings .LDKCResult_RouteLightningErrorZ_result_ok (res );
392395 byte [] serialized_route = bindings .Route_write (bindings .LDKCResult_RouteLightningErrorZ_get_ok (res ));
393396 must_free_objs .add (new WeakReference <>(serialized_route ));
@@ -665,12 +668,35 @@ void do_test_message_handler_b(TestState state) {
665668 if (watch_outputs != null ) { // We only process watch_outputs manually when we use a manually-build Watch impl
666669 assert watch_outputs .length == 1 ;
667670 assert Arrays .equals (watch_outputs [0 ].a , tx .getTxId ().getReversedBytes ());
668- assert watch_outputs [0 ].b .length == 1 ;
671+ assert watch_outputs [0 ].b .length == 2 ;
672+ assert watch_outputs [0 ].b [0 ].a == 0 ;
673+ assert watch_outputs [0 ].b [1 ].a == 1 ;
669674 }
670675
676+ for (int i = 11 ; i < 21 ; i ++) {
677+ b = new Block (bitcoinj_net , 2 , b .getHash (), Sha256Hash .ZERO_HASH , 42 , 0 , 0 , new ArrayList <>());
678+ state .peer2 .connect_block (b , i , 0 );
679+ }
680+
681+ Event [] broadcastable_event = null ;
682+ if (state .peer2 .chain_monitor != null ) {
683+ broadcastable_event = state .peer2 .chain_monitor .as_EventsProvider ().get_and_clear_pending_events ();
684+ }
671685 // This used to be buggy and double-free, so go ahead and fetch them!
672686 for (ChannelMonitor mon : state .peer2 .monitors .values ()) {
673687 byte [][] txn = mon .get_latest_holder_commitment_txn (state .peer2 .logger );
688+ if (state .peer2 .chain_monitor == null ) {
689+ broadcastable_event = mon .get_and_clear_pending_events ();
690+ }
691+ }
692+ assert broadcastable_event .length == 1 ;
693+ assert broadcastable_event [0 ] instanceof Event .SpendableOutputs ;
694+ if (state .peer2 .explicit_keys_manager != null ) {
695+ Result_TransactionNoneZ tx_res = state .peer2 .explicit_keys_manager .spend_spendable_outputs (((Event .SpendableOutputs ) broadcastable_event [0 ]).outputs , new TxOut [0 ], new byte [] {0x00 }, 253 );
696+ assert tx_res instanceof Result_TransactionNoneZ .Result_TransactionNoneZ_OK ;
697+ Transaction built_tx = new Transaction (bitcoinj_net , ((Result_TransactionNoneZ .Result_TransactionNoneZ_OK ) tx_res ).res );
698+ assert built_tx .getOutputs ().size () == 1 ;
699+ assert Arrays .equals (built_tx .getOutput (0 ).getScriptBytes (), new byte []{0x00 });
674700 }
675701 }
676702
0 commit comments