@@ -1733,12 +1733,19 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref> ChannelMan
1733
1733
}
1734
1734
if total_value >= msgs:: MAX_VALUE_MSAT || total_value > data. total_msat {
1735
1735
for htlc in htlcs. iter ( ) {
1736
+ let mut htlc_msat_height_data = byte_utils:: be64_to_array ( htlc. value ) . to_vec ( ) ;
1737
+ htlc_msat_height_data. extend_from_slice (
1738
+ & byte_utils:: be32_to_array (
1739
+ self . latest_block_height . load ( Ordering :: Acquire )
1740
+ as u32 ,
1741
+ ) ,
1742
+ ) ;
1736
1743
failed_forwards. push ( ( HTLCSource :: PreviousHopData ( HTLCPreviousHopData {
1737
1744
short_channel_id : htlc. prev_hop . short_channel_id ,
1738
1745
htlc_id : htlc. prev_hop . htlc_id ,
1739
1746
incoming_packet_shared_secret : htlc. prev_hop . incoming_packet_shared_secret ,
1740
1747
} ) , payment_hash,
1741
- HTLCFailReason :: Reason { failure_code : 0x4000 | 15 , data : byte_utils :: be64_to_array ( htlc . value ) . to_vec ( ) }
1748
+ HTLCFailReason :: Reason { failure_code : 0x4000 | 15 , data : htlc_msat_height_data }
1742
1749
) ) ;
1743
1750
}
1744
1751
} else if total_value == data. total_msat {
@@ -1819,9 +1826,13 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref> ChannelMan
1819
1826
if let Some ( mut sources) = removed_source {
1820
1827
for htlc in sources. drain ( ..) {
1821
1828
if channel_state. is_none ( ) { channel_state = Some ( self . channel_state . lock ( ) . unwrap ( ) ) ; }
1829
+ let mut htlc_msat_height_data = byte_utils:: be64_to_array ( htlc. value ) . to_vec ( ) ;
1830
+ htlc_msat_height_data. extend_from_slice ( & byte_utils:: be32_to_array (
1831
+ self . latest_block_height . load ( Ordering :: Acquire ) as u32 ,
1832
+ ) ) ;
1822
1833
self . fail_htlc_backwards_internal ( channel_state. take ( ) . unwrap ( ) ,
1823
1834
HTLCSource :: PreviousHopData ( htlc. prev_hop ) , payment_hash,
1824
- HTLCFailReason :: Reason { failure_code : 0x4000 | 15 , data : byte_utils :: be64_to_array ( htlc . value ) . to_vec ( ) } ) ;
1835
+ HTLCFailReason :: Reason { failure_code : 0x4000 | 15 , data : htlc_msat_height_data } ) ;
1825
1836
}
1826
1837
true
1827
1838
} else { false }
@@ -1845,9 +1856,9 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref> ChannelMan
1845
1856
match & onion_error {
1846
1857
& HTLCFailReason :: LightningError { ref err } => {
1847
1858
#[ cfg( test) ]
1848
- let ( channel_update, payment_retryable, onion_error_code) = onion_utils:: process_onion_failure ( & self . secp_ctx , & self . logger , & source, err. data . clone ( ) ) ;
1859
+ let ( channel_update, payment_retryable, onion_error_code, onion_error_data ) = onion_utils:: process_onion_failure ( & self . secp_ctx , & self . logger , & source, err. data . clone ( ) ) ;
1849
1860
#[ cfg( not( test) ) ]
1850
- let ( channel_update, payment_retryable, _) = onion_utils:: process_onion_failure ( & self . secp_ctx , & self . logger , & source, err. data . clone ( ) ) ;
1861
+ let ( channel_update, payment_retryable, _, _ ) = onion_utils:: process_onion_failure ( & self . secp_ctx , & self . logger , & source, err. data . clone ( ) ) ;
1851
1862
// TODO: If we decided to blame ourselves (or one of our channels) in
1852
1863
// process_onion_failure we should close that channel as it implies our
1853
1864
// next-hop is needlessly blaming us!
@@ -1863,13 +1874,17 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref> ChannelMan
1863
1874
payment_hash : payment_hash. clone ( ) ,
1864
1875
rejected_by_dest : !payment_retryable,
1865
1876
#[ cfg( test) ]
1866
- error_code : onion_error_code
1877
+ error_code : onion_error_code,
1878
+ #[ cfg( test) ]
1879
+ error_data : onion_error_data
1867
1880
}
1868
1881
) ;
1869
1882
} ,
1870
1883
& HTLCFailReason :: Reason {
1871
1884
#[ cfg( test) ]
1872
1885
ref failure_code,
1886
+ #[ cfg( test) ]
1887
+ ref data,
1873
1888
.. } => {
1874
1889
// we get a fail_malformed_htlc from the first hop
1875
1890
// TODO: We'd like to generate a PaymentFailureNetworkUpdate for temporary
@@ -1884,6 +1899,8 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref> ChannelMan
1884
1899
rejected_by_dest : path. len ( ) == 1 ,
1885
1900
#[ cfg( test) ]
1886
1901
error_code : Some ( * failure_code) ,
1902
+ #[ cfg( test) ]
1903
+ error_data : Some ( data. clone ( ) ) ,
1887
1904
}
1888
1905
) ;
1889
1906
}
@@ -1982,12 +1999,13 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref> ChannelMan
1982
1999
for htlc in sources. drain ( ..) {
1983
2000
if channel_state. is_none ( ) { channel_state = Some ( self . channel_state . lock ( ) . unwrap ( ) ) ; }
1984
2001
if ( is_mpp && !valid_mpp) || ( !is_mpp && ( htlc. value < expected_amount || htlc. value > expected_amount * 2 ) ) {
1985
- let mut htlc_msat_data = byte_utils:: be64_to_array ( htlc. value ) . to_vec ( ) ;
1986
- let mut height_data = byte_utils:: be32_to_array ( self . latest_block_height . load ( Ordering :: Acquire ) as u32 ) . to_vec ( ) ;
1987
- htlc_msat_data. append ( & mut height_data) ;
2002
+ let mut htlc_msat_height_data = byte_utils:: be64_to_array ( htlc. value ) . to_vec ( ) ;
2003
+ htlc_msat_height_data. extend_from_slice ( & byte_utils:: be32_to_array (
2004
+ self . latest_block_height . load ( Ordering :: Acquire ) as u32 ,
2005
+ ) ) ;
1988
2006
self . fail_htlc_backwards_internal ( channel_state. take ( ) . unwrap ( ) ,
1989
2007
HTLCSource :: PreviousHopData ( htlc. prev_hop ) , & payment_hash,
1990
- HTLCFailReason :: Reason { failure_code : 0x4000 |15 , data : htlc_msat_data } ) ;
2008
+ HTLCFailReason :: Reason { failure_code : 0x4000 |15 , data : htlc_msat_height_data } ) ;
1991
2009
} else {
1992
2010
match self . claim_funds_from_hop ( channel_state. as_mut ( ) . unwrap ( ) , htlc. prev_hop , payment_preimage) {
1993
2011
Err ( Some ( e) ) => {
0 commit comments