@@ -43,7 +43,8 @@ static struct bitcoin_tx *close_tx(const tal_t *ctx,
43
43
const struct amount_sat out [NUM_SIDES ],
44
44
enum side opener ,
45
45
struct amount_sat fee ,
46
- struct amount_sat dust_limit )
46
+ struct amount_sat dust_limit ,
47
+ const struct bitcoin_outpoint * wrong_funding )
47
48
{
48
49
struct bitcoin_tx * tx ;
49
50
struct amount_sat out_minus_fee [NUM_SIDES ];
@@ -75,6 +76,7 @@ static struct bitcoin_tx *close_tx(const tal_t *ctx,
75
76
out_minus_fee [LOCAL ],
76
77
out_minus_fee [REMOTE ],
77
78
dust_limit );
79
+ assert (tx );
78
80
if (!tx )
79
81
peer_failed_err (pps , channel_id ,
80
82
"Both outputs below dust limit:"
@@ -88,6 +90,12 @@ static struct bitcoin_tx *close_tx(const tal_t *ctx,
88
90
type_to_string (tmpctx , struct amount_sat , & dust_limit ),
89
91
type_to_string (tmpctx , struct amount_sat , & out [LOCAL ]),
90
92
type_to_string (tmpctx , struct amount_sat , & out [REMOTE ]));
93
+
94
+ if (wrong_funding )
95
+ bitcoin_tx_input_set_txid (tx , 0 ,
96
+ & wrong_funding -> txid ,
97
+ wrong_funding -> n );
98
+
91
99
return tx ;
92
100
}
93
101
@@ -148,13 +156,15 @@ static void do_reconnect(struct per_peer_state *pps,
148
156
u64 revocations_received ,
149
157
const u8 * channel_reestablish ,
150
158
const u8 * final_scriptpubkey ,
151
- const struct secret * last_remote_per_commit_secret )
159
+ const struct secret * last_remote_per_commit_secret ,
160
+ const struct bitcoin_outpoint * wrong_funding )
152
161
{
153
162
u8 * msg ;
154
163
struct channel_id their_channel_id ;
155
164
u64 next_local_commitment_number , next_remote_revocation_number ;
156
165
struct pubkey my_current_per_commitment_point , next_commitment_point ;
157
166
struct secret their_secret ;
167
+ struct tlv_shutdown_tlvs * tlvs ;
158
168
159
169
my_current_per_commitment_point = get_per_commitment_point (next_index [LOCAL ]- 1 );
160
170
@@ -218,8 +228,16 @@ static void do_reconnect(struct per_peer_state *pps,
218
228
* - if it has sent a previous `shutdown`:
219
229
* - MUST retransmit `shutdown`.
220
230
*/
221
- /* FIXME: retransmit wrong_funding */
222
- msg = towire_shutdown (NULL , channel_id , final_scriptpubkey , NULL );
231
+ if (wrong_funding ) {
232
+ tlvs = tlv_shutdown_tlvs_new (tmpctx );
233
+ tlvs -> wrong_funding
234
+ = tal (tlvs , struct tlv_shutdown_tlvs_wrong_funding );
235
+ tlvs -> wrong_funding -> txid = wrong_funding -> txid ;
236
+ tlvs -> wrong_funding -> outnum = wrong_funding -> n ;
237
+ } else
238
+ tlvs = NULL ;
239
+
240
+ msg = towire_shutdown (NULL , channel_id , final_scriptpubkey , tlvs );
223
241
sync_crypto_write (pps , take (msg ));
224
242
225
243
/* BOLT #2:
@@ -250,7 +268,8 @@ static void send_offer(struct per_peer_state *pps,
250
268
const struct amount_sat out [NUM_SIDES ],
251
269
enum side opener ,
252
270
struct amount_sat our_dust_limit ,
253
- struct amount_sat fee_to_offer )
271
+ struct amount_sat fee_to_offer ,
272
+ const struct bitcoin_outpoint * wrong_funding )
254
273
{
255
274
struct bitcoin_tx * tx ;
256
275
struct bitcoin_signature our_sig ;
@@ -269,7 +288,8 @@ static void send_offer(struct per_peer_state *pps,
269
288
funding ,
270
289
funding_wscript ,
271
290
out ,
272
- opener , fee_to_offer , our_dust_limit );
291
+ opener , fee_to_offer , our_dust_limit ,
292
+ wrong_funding );
273
293
274
294
/* BOLT #3:
275
295
*
@@ -329,6 +349,7 @@ receive_offer(struct per_peer_state *pps,
329
349
enum side opener ,
330
350
struct amount_sat our_dust_limit ,
331
351
struct amount_sat min_fee_to_accept ,
352
+ const struct bitcoin_outpoint * wrong_funding ,
332
353
struct bitcoin_txid * closing_txid )
333
354
{
334
355
u8 * msg ;
@@ -379,7 +400,8 @@ receive_offer(struct per_peer_state *pps,
379
400
funding_txout ,
380
401
funding ,
381
402
funding_wscript ,
382
- out , opener , received_fee , our_dust_limit );
403
+ out , opener , received_fee , our_dust_limit ,
404
+ wrong_funding );
383
405
384
406
if (!check_tx_sig (tx , 0 , NULL , funding_wscript ,
385
407
& funding_pubkey [REMOTE ], & their_sig )) {
@@ -410,7 +432,8 @@ receive_offer(struct per_peer_state *pps,
410
432
funding ,
411
433
funding_wscript ,
412
434
trimming_out ,
413
- opener , received_fee , our_dust_limit );
435
+ opener , received_fee , our_dust_limit ,
436
+ wrong_funding );
414
437
if (!trimmed
415
438
|| !check_tx_sig (trimmed , 0 , NULL , funding_wscript ,
416
439
& funding_pubkey [REMOTE ], & their_sig )) {
@@ -619,37 +642,39 @@ int main(int argc, char *argv[])
619
642
enum side whose_turn ;
620
643
u8 * channel_reestablish ;
621
644
struct secret last_remote_per_commit_secret ;
645
+ struct bitcoin_outpoint * wrong_funding ;
622
646
623
647
subdaemon_setup (argc , argv );
624
648
625
649
status_setup_sync (REQ_FD );
626
650
627
651
msg = wire_sync_read (tmpctx , REQ_FD );
628
652
if (!fromwire_closingd_init (ctx , msg ,
629
- & chainparams ,
630
- & pps ,
631
- & channel_id ,
632
- & funding_txid , & funding_txout ,
633
- & funding ,
634
- & funding_pubkey [LOCAL ],
635
- & funding_pubkey [REMOTE ],
636
- & opener ,
637
- & out [LOCAL ],
638
- & out [REMOTE ],
639
- & our_dust_limit ,
640
- & min_fee_to_accept , & commitment_fee ,
641
- & offer [LOCAL ],
642
- & scriptpubkey [LOCAL ],
643
- & scriptpubkey [REMOTE ],
644
- & fee_negotiation_step ,
645
- & fee_negotiation_step_unit ,
646
- & reconnected ,
647
- & next_index [LOCAL ],
648
- & next_index [REMOTE ],
649
- & revocations_received ,
650
- & channel_reestablish ,
651
- & last_remote_per_commit_secret ,
652
- & dev_fast_gossip ))
653
+ & chainparams ,
654
+ & pps ,
655
+ & channel_id ,
656
+ & funding_txid , & funding_txout ,
657
+ & funding ,
658
+ & funding_pubkey [LOCAL ],
659
+ & funding_pubkey [REMOTE ],
660
+ & opener ,
661
+ & out [LOCAL ],
662
+ & out [REMOTE ],
663
+ & our_dust_limit ,
664
+ & min_fee_to_accept , & commitment_fee ,
665
+ & offer [LOCAL ],
666
+ & scriptpubkey [LOCAL ],
667
+ & scriptpubkey [REMOTE ],
668
+ & fee_negotiation_step ,
669
+ & fee_negotiation_step_unit ,
670
+ & reconnected ,
671
+ & next_index [LOCAL ],
672
+ & next_index [REMOTE ],
673
+ & revocations_received ,
674
+ & channel_reestablish ,
675
+ & last_remote_per_commit_secret ,
676
+ & dev_fast_gossip ,
677
+ & wrong_funding ))
653
678
master_badmsg (WIRE_CLOSINGD_INIT , msg );
654
679
655
680
/* stdin == requests, 3 == peer, 4 = gossip, 5 = gossip_store, 6 = hsmd */
@@ -670,6 +695,11 @@ int main(int argc, char *argv[])
670
695
status_debug ("fee = %s" ,
671
696
type_to_string (tmpctx , struct amount_sat , & offer [LOCAL ]));
672
697
status_debug ("fee negotiation step = %s" , fee_negotiation_step_str );
698
+ if (wrong_funding )
699
+ status_unusual ("Seting wrong_funding_txid to %s:%u" ,
700
+ type_to_string (tmpctx , struct bitcoin_txid ,
701
+ & wrong_funding -> txid ),
702
+ wrong_funding -> n );
673
703
674
704
funding_wscript = bitcoin_redeem_2of2 (ctx ,
675
705
& funding_pubkey [LOCAL ],
@@ -679,7 +709,8 @@ int main(int argc, char *argv[])
679
709
do_reconnect (pps , & channel_id ,
680
710
next_index , revocations_received ,
681
711
channel_reestablish , scriptpubkey [LOCAL ],
682
- & last_remote_per_commit_secret );
712
+ & last_remote_per_commit_secret ,
713
+ wrong_funding );
683
714
684
715
peer_billboard (
685
716
true,
@@ -705,7 +736,8 @@ int main(int argc, char *argv[])
705
736
scriptpubkey , & funding_txid , funding_txout ,
706
737
funding , out , opener ,
707
738
our_dust_limit ,
708
- offer [LOCAL ]);
739
+ offer [LOCAL ],
740
+ wrong_funding );
709
741
} else {
710
742
if (i == 0 )
711
743
peer_billboard (false, "Waiting for their initial"
@@ -726,6 +758,7 @@ int main(int argc, char *argv[])
726
758
out , opener ,
727
759
our_dust_limit ,
728
760
min_fee_to_accept ,
761
+ wrong_funding ,
729
762
& closing_txid );
730
763
}
731
764
}
@@ -754,7 +787,8 @@ int main(int argc, char *argv[])
754
787
scriptpubkey , & funding_txid , funding_txout ,
755
788
funding , out , opener ,
756
789
our_dust_limit ,
757
- offer [LOCAL ]);
790
+ offer [LOCAL ],
791
+ wrong_funding );
758
792
} else {
759
793
peer_billboard (false, "Waiting for another"
760
794
" closing fee offer:"
@@ -770,6 +804,7 @@ int main(int argc, char *argv[])
770
804
out , opener ,
771
805
our_dust_limit ,
772
806
min_fee_to_accept ,
807
+ wrong_funding ,
773
808
& closing_txid );
774
809
}
775
810
@@ -782,6 +817,7 @@ int main(int argc, char *argv[])
782
817
783
818
#if DEVELOPER
784
819
/* We don't listen for master commands, so always check memleak here */
820
+ tal_free (wrong_funding );
785
821
closing_dev_memleak (ctx , scriptpubkey , funding_wscript );
786
822
#endif
787
823
0 commit comments