@@ -1833,22 +1833,43 @@ impl ChannelMonitor {
1833
1833
1834
1834
' outer_loop: for input in & tx. input {
1835
1835
let mut payment_data = None ;
1836
+ let revocation_sig_claim = ( input. witness . len ( ) == 3 && input. witness [ 2 ] . len ( ) == OFFERED_HTLC_SCRIPT_WEIGHT && input. witness [ 1 ] . len ( ) == 33 )
1837
+ || ( input. witness . len ( ) == 3 && input. witness [ 2 ] . len ( ) == ACCEPTED_HTLC_SCRIPT_WEIGHT && input. witness [ 1 ] . len ( ) == 33 ) ;
1838
+ let accepted_preimage_claim = input. witness . len ( ) == 5 && input. witness [ 4 ] . len ( ) == ACCEPTED_HTLC_SCRIPT_WEIGHT ;
1839
+ let offered_preimage_claim = input. witness . len ( ) == 3 && input. witness [ 2 ] . len ( ) == OFFERED_HTLC_SCRIPT_WEIGHT ;
1840
+
1841
+ macro_rules! log_claim {
1842
+ ( $source: expr, $local_tx: expr, $outbound_htlc: expr, $payment_hash: expr, $source_avail: expr) => {
1843
+ // We found the output in question, but aren't failing it backwards
1844
+ // as we have no corresponding source. This implies either it is an
1845
+ // inbound HTLC or an outbound HTLC on a revoked transaction.
1846
+ if ( $local_tx && revocation_sig_claim) ||
1847
+ ( $outbound_htlc && !$source_avail && ( accepted_preimage_claim || offered_preimage_claim) ) {
1848
+ log_error!( self , "Input spending {}:{} in {} resolves {} HTLC with payment hash {} from {} with {}!" ,
1849
+ input. previous_output. txid, input. previous_output. vout, tx. txid( ) ,
1850
+ if $outbound_htlc { "outbound" } else { "inbound" } , log_bytes!( $payment_hash. 0 ) , $source,
1851
+ if revocation_sig_claim { "revocation sig" } else { "preimage claim after we'd passed the HTLC resolution back" } ) ;
1852
+ } else {
1853
+ log_info!( self , "Input spending {}:{} in {} resolves {} HTLC with payment hash {} from {} with {}" ,
1854
+ input. previous_output. txid, input. previous_output. vout, tx. txid( ) ,
1855
+ if $outbound_htlc { "outbound" } else { "inbound" } , log_bytes!( $payment_hash. 0 ) , $source,
1856
+ if revocation_sig_claim { "revocation sig" } else if accepted_preimage_claim || offered_preimage_claim { "preimage" } else { "timeout" } ) ;
1857
+ }
1858
+ }
1859
+ }
1836
1860
1837
1861
macro_rules! scan_commitment {
1838
- ( $htlc_outputs: expr, $htlc_sources: expr, $source: expr) => {
1862
+ ( $htlc_outputs: expr, $htlc_sources: expr, $source: expr, $local_tx : expr ) => {
1839
1863
for & ( ref payment_hash, ref source, ref vout) in $htlc_sources. iter( ) {
1840
1864
if & Some ( input. previous_output. vout) == vout {
1841
- log_trace! ( self , "Input spending {}:{} resolves HTLC with payment hash {} from {}" , input . previous_output . txid , input . previous_output . vout , log_bytes! ( payment_hash. 0 ) , $source ) ;
1865
+ log_claim! ( $source , $local_tx , true , payment_hash, true ) ;
1842
1866
payment_data = Some ( ( source. clone( ) , * payment_hash) ) ;
1843
1867
}
1844
1868
}
1845
1869
if payment_data. is_none( ) {
1846
1870
for htlc_output in $htlc_outputs {
1847
- if input. previous_output. vout == htlc_output. transaction_output_index && !htlc_output. offered {
1848
- log_info!( self , "Input spending {}:{} in {} resolves inbound HTLC with timeout from {}" , input. previous_output. txid, input. previous_output. vout, tx. txid( ) , $source) ;
1849
- continue ' outer_loop;
1850
- } else if input. previous_output. vout == htlc_output. transaction_output_index && tx. lock_time > 0 {
1851
- log_info!( self , "Input spending {}:{} in {} resolves offered HTLC with HTLC-timeout from {}" , input. previous_output. txid, input. previous_output. vout, tx. txid( ) , $source) ;
1871
+ if input. previous_output. vout == htlc_output. transaction_output_index {
1872
+ log_claim!( $source, $local_tx, $local_tx == htlc_output. offered, htlc_output. payment_hash, false ) ;
1852
1873
continue ' outer_loop;
1853
1874
}
1854
1875
}
@@ -1860,31 +1881,28 @@ impl ChannelMonitor {
1860
1881
if input. previous_output . txid == current_local_signed_commitment_tx. txid {
1861
1882
scan_commitment ! ( current_local_signed_commitment_tx. htlc_outputs. iter( ) . map( |& ( ref a, _, _) | a) ,
1862
1883
current_local_signed_commitment_tx. htlc_sources,
1863
- "our latest local commitment tx" ) ;
1884
+ "our latest local commitment tx" , true ) ;
1864
1885
}
1865
1886
}
1866
1887
if let Some ( ref prev_local_signed_commitment_tx) = self . prev_local_signed_commitment_tx {
1867
1888
if input. previous_output . txid == prev_local_signed_commitment_tx. txid {
1868
1889
scan_commitment ! ( prev_local_signed_commitment_tx. htlc_outputs. iter( ) . map( |& ( ref a, _, _) | a) ,
1869
1890
prev_local_signed_commitment_tx. htlc_sources,
1870
- "our latest local commitment tx" ) ;
1891
+ "our latest local commitment tx" , true ) ;
1871
1892
}
1872
1893
}
1873
1894
if let Some ( & ( ref htlc_outputs, ref htlc_sources) ) = self . remote_claimable_outpoints . get ( & input. previous_output . txid ) {
1874
- scan_commitment ! ( htlc_outputs, htlc_sources, "remote commitment tx" ) ;
1895
+ scan_commitment ! ( htlc_outputs, htlc_sources, "remote commitment tx" , false ) ;
1875
1896
}
1876
1897
1877
1898
// If tx isn't solving htlc output from local/remote commitment tx and htlc isn't outbound we don't need
1878
1899
// to broadcast solving backward
1879
1900
if let Some ( ( source, payment_hash) ) = payment_data {
1880
1901
let mut payment_preimage = PaymentPreimage ( [ 0 ; 32 ] ) ;
1881
- if ( input. witness . len ( ) == 3 && input. witness [ 2 ] . len ( ) == OFFERED_HTLC_SCRIPT_WEIGHT && input. witness [ 1 ] . len ( ) == 33 )
1882
- || ( input. witness . len ( ) == 3 && input. witness [ 2 ] . len ( ) == ACCEPTED_HTLC_SCRIPT_WEIGHT && input. witness [ 1 ] . len ( ) == 33 ) {
1883
- log_error ! ( self , "Remote used revocation sig to take a {} HTLC output at index {} from commitment_tx {}" , if input. witness[ 2 ] . len( ) == OFFERED_HTLC_SCRIPT_WEIGHT { "offered" } else { "accepted" } , input. previous_output. vout, input. previous_output. txid) ;
1884
- } else if input. witness . len ( ) == 5 && input. witness [ 4 ] . len ( ) == ACCEPTED_HTLC_SCRIPT_WEIGHT {
1902
+ if accepted_preimage_claim {
1885
1903
payment_preimage. 0 . copy_from_slice ( & input. witness [ 3 ] ) ;
1886
1904
htlc_updated. push ( ( source, Some ( payment_preimage) , payment_hash) ) ;
1887
- } else if input . witness . len ( ) == 3 && input . witness [ 2 ] . len ( ) == OFFERED_HTLC_SCRIPT_WEIGHT {
1905
+ } else if offered_preimage_claim {
1888
1906
payment_preimage. 0 . copy_from_slice ( & input. witness [ 1 ] ) ;
1889
1907
htlc_updated. push ( ( source, Some ( payment_preimage) , payment_hash) ) ;
1890
1908
} else {
0 commit comments