@@ -438,8 +438,6 @@ pub(crate) enum InputMaterial {
438
438
locktime : u32 ,
439
439
} ,
440
440
LocalHTLC {
441
- witness_script : Script ,
442
- sigs : ( Signature , Signature ) ,
443
441
preimage : Option < PaymentPreimage > ,
444
442
amount : u64 ,
445
443
} ,
@@ -467,11 +465,8 @@ impl Writeable for InputMaterial {
467
465
writer. write_all ( & byte_utils:: be64_to_array ( * amount) ) ?;
468
466
writer. write_all ( & byte_utils:: be32_to_array ( * locktime) ) ?;
469
467
} ,
470
- & InputMaterial :: LocalHTLC { ref witness_script , ref sigs , ref preimage, ref amount } => {
468
+ & InputMaterial :: LocalHTLC { ref preimage, ref amount } => {
471
469
writer. write_all ( & [ 2 ; 1 ] ) ?;
472
- witness_script. write ( writer) ?;
473
- sigs. 0 . write ( writer) ?;
474
- sigs. 1 . write ( writer) ?;
475
470
preimage. write ( writer) ?;
476
471
writer. write_all ( & byte_utils:: be64_to_array ( * amount) ) ?;
477
472
} ,
@@ -516,16 +511,11 @@ impl Readable for InputMaterial {
516
511
}
517
512
} ,
518
513
2 => {
519
- let witness_script = Readable :: read ( reader) ?;
520
- let their_sig = Readable :: read ( reader) ?;
521
- let our_sig = Readable :: read ( reader) ?;
522
514
let preimage = Readable :: read ( reader) ?;
523
515
let amount = Readable :: read ( reader) ?;
524
516
InputMaterial :: LocalHTLC {
525
- witness_script,
526
- sigs : ( their_sig, our_sig) ,
527
517
preimage,
528
- amount
518
+ amount,
529
519
}
530
520
} ,
531
521
3 => {
@@ -1679,49 +1669,32 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1679
1669
( claimable_outpoints, Some ( ( htlc_txid, tx. output . clone ( ) ) ) )
1680
1670
}
1681
1671
1682
- fn broadcast_by_local_state ( & self , commitment_tx : & Transaction , local_tx : & LocalSignedTx ) -> ( Vec < Transaction > , Vec < TxOut > , Option < ( Script , SecretKey , Script ) > ) {
1683
- let mut res = Vec :: with_capacity ( local_tx. htlc_outputs . len ( ) ) ;
1672
+ fn broadcast_by_local_state ( & self , commitment_tx : & Transaction , local_tx : & LocalSignedTx ) -> ( Vec < ClaimRequest > , Vec < TxOut > , Option < ( Script , SecretKey , Script ) > ) {
1673
+ let mut claim_requests = Vec :: with_capacity ( local_tx. htlc_outputs . len ( ) ) ;
1684
1674
let mut watch_outputs = Vec :: with_capacity ( local_tx. htlc_outputs . len ( ) ) ;
1685
1675
1686
1676
let redeemscript = chan_utils:: get_revokeable_redeemscript ( & local_tx. revocation_key , self . their_to_self_delay . unwrap ( ) , & local_tx. delayed_payment_key ) ;
1687
1677
let broadcasted_local_revokable_script = if let Ok ( local_delayedkey) = chan_utils:: derive_private_key ( & self . secp_ctx , & local_tx. per_commitment_point , self . onchain_detection . keys . delayed_payment_base_key ( ) ) {
1688
1678
Some ( ( redeemscript. to_v0_p2wsh ( ) , local_delayedkey, redeemscript) )
1689
1679
} else { None } ;
1690
1680
1691
- for & ( ref htlc, ref sigs , _) in local_tx. htlc_outputs . iter ( ) {
1681
+ for & ( ref htlc, _ , _) in local_tx. htlc_outputs . iter ( ) {
1692
1682
if let Some ( transaction_output_index) = htlc. transaction_output_index {
1693
- if let & Some ( ref their_sig) = sigs {
1694
- if htlc. offered {
1695
- log_trace ! ( self , "Broadcasting HTLC-Timeout transaction against local commitment transactions" ) ;
1696
- let mut htlc_timeout_tx = chan_utils:: build_htlc_transaction ( & local_tx. txid , local_tx. feerate_per_kw , self . their_to_self_delay . unwrap ( ) , htlc, & local_tx. delayed_payment_key , & local_tx. revocation_key ) ;
1697
- self . onchain_detection . keys . sign_htlc_transaction ( & mut htlc_timeout_tx, their_sig, & None , htlc, & local_tx. a_htlc_key , & local_tx. b_htlc_key , & local_tx. revocation_key , & local_tx. per_commitment_point , & self . secp_ctx ) ;
1698
-
1699
- log_trace ! ( self , "Outpoint {}:{} is being being claimed" , htlc_timeout_tx. input[ 0 ] . previous_output. vout, htlc_timeout_tx. input[ 0 ] . previous_output. txid) ;
1700
- res. push ( htlc_timeout_tx) ;
1701
- } else {
1702
- if let Some ( payment_preimage) = self . payment_preimages . get ( & htlc. payment_hash ) {
1703
- log_trace ! ( self , "Broadcasting HTLC-Success transaction against local commitment transactions" ) ;
1704
- let mut htlc_success_tx = chan_utils:: build_htlc_transaction ( & local_tx. txid , local_tx. feerate_per_kw , self . their_to_self_delay . unwrap ( ) , htlc, & local_tx. delayed_payment_key , & local_tx. revocation_key ) ;
1705
- self . onchain_detection . keys . sign_htlc_transaction ( & mut htlc_success_tx, their_sig, & Some ( * payment_preimage) , htlc, & local_tx. a_htlc_key , & local_tx. b_htlc_key , & local_tx. revocation_key , & local_tx. per_commitment_point , & self . secp_ctx ) ;
1706
-
1707
- log_trace ! ( self , "Outpoint {}:{} is being being claimed" , htlc_success_tx. input[ 0 ] . previous_output. vout, htlc_success_tx. input[ 0 ] . previous_output. txid) ;
1708
- res. push ( htlc_success_tx) ;
1709
- }
1710
- }
1711
- watch_outputs. push ( commitment_tx. output [ transaction_output_index as usize ] . clone ( ) ) ;
1712
- } else { panic ! ( "Should have sigs for non-dust local tx outputs!" ) }
1683
+ let preimage = if let Some ( preimage) = self . payment_preimages . get ( & htlc. payment_hash ) { Some ( * preimage) } else { None } ;
1684
+ claim_requests. push ( ClaimRequest { absolute_timelock : :: std:: u32:: MAX , aggregable : false , outpoint : BitcoinOutPoint { txid : local_tx. txid , vout : transaction_output_index as u32 } , witness_data : InputMaterial :: LocalHTLC { preimage, amount : htlc. amount_msat / 1000 } } ) ;
1685
+ watch_outputs. push ( commitment_tx. output [ transaction_output_index as usize ] . clone ( ) ) ;
1713
1686
}
1714
1687
}
1715
1688
1716
- ( res , watch_outputs, broadcasted_local_revokable_script)
1689
+ ( claim_requests , watch_outputs, broadcasted_local_revokable_script)
1717
1690
}
1718
1691
1719
1692
/// Attempts to claim any claimable HTLCs in a commitment transaction which was not (yet)
1720
1693
/// revoked using data in local_claimable_outpoints.
1721
1694
/// Should not be used if check_spend_revoked_transaction succeeds.
1722
- fn check_spend_local_transaction ( & mut self , tx : & Transaction , height : u32 ) -> ( Vec < Transaction > , ( Sha256dHash , Vec < TxOut > ) ) {
1695
+ fn check_spend_local_transaction ( & mut self , tx : & Transaction , height : u32 ) -> ( Vec < ClaimRequest > , ( Sha256dHash , Vec < TxOut > ) ) {
1723
1696
let commitment_txid = tx. txid ( ) ;
1724
- let mut local_txn = Vec :: new ( ) ;
1697
+ let mut claim_requests = Vec :: new ( ) ;
1725
1698
let mut watch_outputs = Vec :: new ( ) ;
1726
1699
1727
1700
macro_rules! wait_threshold_conf {
@@ -1749,7 +1722,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1749
1722
1750
1723
macro_rules! append_onchain_update {
1751
1724
( $updates: expr) => {
1752
- local_txn . append ( & mut $updates. 0 ) ;
1725
+ claim_requests = $updates. 0 ;
1753
1726
watch_outputs. append( & mut $updates. 1 ) ;
1754
1727
self . broadcasted_local_revokable_script = $updates. 2 ;
1755
1728
}
@@ -1796,7 +1769,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1796
1769
}
1797
1770
}
1798
1771
1799
- ( local_txn , ( commitment_txid, watch_outputs) )
1772
+ ( claim_requests , ( commitment_txid, watch_outputs) )
1800
1773
}
1801
1774
1802
1775
/// Used by ChannelManager deserialization to broadcast the latest local state if its copy of
@@ -1866,14 +1839,11 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1866
1839
watch_outputs. push ( new_outputs) ;
1867
1840
}
1868
1841
if new_outpoints. is_empty ( ) {
1869
- let ( local_txn, new_outputs) = self . check_spend_local_transaction ( & tx, height) ;
1870
- for tx in local_txn. iter ( ) {
1871
- log_trace ! ( self , "Broadcast onchain {}" , log_tx!( tx) ) ;
1872
- broadcaster. broadcast_transaction ( tx) ;
1873
- }
1842
+ let ( mut new_outpoints, new_outputs) = self . check_spend_local_transaction ( & tx, height) ;
1874
1843
if !new_outputs. 1 . is_empty ( ) {
1875
1844
watch_outputs. push ( new_outputs) ;
1876
1845
}
1846
+ claimable_outpoints. append ( & mut new_outpoints) ;
1877
1847
}
1878
1848
claimable_outpoints. append ( & mut new_outpoints) ;
1879
1849
}
@@ -1903,14 +1873,11 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1903
1873
if let Some ( ref cur_local_tx) = self . current_local_signed_commitment_tx {
1904
1874
if should_broadcast {
1905
1875
if let Some ( commitment_tx) = self . onchain_tx_handler . get_fully_signed_local_tx ( self . channel_value_satoshis . unwrap ( ) ) {
1906
- let ( txs , new_outputs, _) = self . broadcast_by_local_state ( & commitment_tx, cur_local_tx) ;
1876
+ let ( mut new_outpoints , new_outputs, _) = self . broadcast_by_local_state ( & commitment_tx, cur_local_tx) ;
1907
1877
if !new_outputs. is_empty ( ) {
1908
1878
watch_outputs. push ( ( cur_local_tx. txid . clone ( ) , new_outputs) ) ;
1909
1879
}
1910
- for tx in txs {
1911
- log_trace ! ( self , "Broadcast onchain {}" , log_tx!( tx) ) ;
1912
- broadcaster. broadcast_transaction ( & tx) ;
1913
- }
1880
+ claimable_outpoints. append ( & mut new_outpoints) ;
1914
1881
}
1915
1882
}
1916
1883
}
0 commit comments