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