@@ -1772,11 +1772,11 @@ impl ChannelMonitor {
1772
1772
let mut inputs_info = Vec :: new ( ) ;
1773
1773
1774
1774
macro_rules! sign_input {
1775
- ( $sighash_parts: expr, $input: expr, $amount: expr, $preimage: expr) => {
1775
+ ( $sighash_parts: expr, $input: expr, $amount: expr, $preimage: expr, $idx : expr ) => {
1776
1776
{
1777
1777
let ( sig, redeemscript, htlc_key) = match self . key_storage {
1778
1778
Storage :: Local { ref htlc_base_key, .. } => {
1779
- let htlc = & per_commitment_option. unwrap( ) [ $input . sequence as usize ] . 0 ;
1779
+ let htlc = & per_commitment_option. unwrap( ) [ $idx as usize ] . 0 ;
1780
1780
let redeemscript = chan_utils:: get_htlc_redeemscript_with_explicit_keys( htlc, & a_htlc_key, & b_htlc_key, & revocation_pubkey) ;
1781
1781
let sighash = hash_to_message!( & $sighash_parts. sighash_all( & $input, & redeemscript, $amount) [ ..] ) ;
1782
1782
let htlc_key = ignore_error!( chan_utils:: derive_private_key( & self . secp_ctx, revocation_point, & htlc_base_key) ) ;
@@ -1805,19 +1805,20 @@ impl ChannelMonitor {
1805
1805
}
1806
1806
if let Some ( payment_preimage) = self . payment_preimages . get ( & htlc. payment_hash ) {
1807
1807
if htlc. offered {
1808
- let input = TxIn {
1808
+ let mut input = TxIn {
1809
1809
previous_output : BitcoinOutPoint {
1810
1810
txid : commitment_txid,
1811
1811
vout : transaction_output_index,
1812
1812
} ,
1813
1813
script_sig : Script :: new ( ) ,
1814
- sequence : idx as u32 , // reset to 0xfffffffd in sign_input
1814
+ sequence : idx as u32 , // reset to 0xfffffffd before sign_input
1815
1815
witness : Vec :: new ( ) ,
1816
1816
} ;
1817
1817
if htlc. cltv_expiry > height + CLTV_SHARED_CLAIM_BUFFER {
1818
+ input. sequence = 0xff_ff_ff_fd ;
1818
1819
inputs. push ( input) ;
1819
1820
inputs_desc. push ( if htlc. offered { InputDescriptors :: OfferedHTLC } else { InputDescriptors :: ReceivedHTLC } ) ;
1820
- inputs_info. push ( ( payment_preimage, tx. output [ transaction_output_index as usize ] . value , htlc. cltv_expiry ) ) ;
1821
+ inputs_info. push ( ( payment_preimage, tx. output [ transaction_output_index as usize ] . value , htlc. cltv_expiry , idx ) ) ;
1821
1822
total_value += tx. output [ transaction_output_index as usize ] . value ;
1822
1823
} else {
1823
1824
let mut single_htlc_tx = Transaction {
@@ -1833,8 +1834,10 @@ impl ChannelMonitor {
1833
1834
let height_timer = Self :: get_height_timer ( height, htlc. cltv_expiry ) ;
1834
1835
let mut used_feerate;
1835
1836
if subtract_high_prio_fee ! ( self , fee_estimator, single_htlc_tx. output[ 0 ] . value, predicted_weight, used_feerate) {
1837
+ let idx = single_htlc_tx. input [ 0 ] . sequence ;
1838
+ single_htlc_tx. input [ 0 ] . sequence = 0xff_ff_ff_fd ;
1836
1839
let sighash_parts = bip143:: SighashComponents :: new ( & single_htlc_tx) ;
1837
- let ( redeemscript, htlc_key) = sign_input ! ( sighash_parts, single_htlc_tx. input[ 0 ] , htlc. amount_msat / 1000 , payment_preimage. 0 . to_vec( ) ) ;
1840
+ let ( redeemscript, htlc_key) = sign_input ! ( sighash_parts, single_htlc_tx. input[ 0 ] , htlc. amount_msat / 1000 , payment_preimage. 0 . to_vec( ) , idx ) ;
1838
1841
assert ! ( predicted_weight >= single_htlc_tx. get_weight( ) ) ;
1839
1842
spendable_outputs. push ( SpendableOutputDescriptor :: StaticOutput {
1840
1843
outpoint : BitcoinOutPoint { txid : single_htlc_tx. txid ( ) , vout : 0 } ,
@@ -1881,8 +1884,10 @@ impl ChannelMonitor {
1881
1884
let height_timer = Self :: get_height_timer ( height, htlc. cltv_expiry ) ;
1882
1885
let mut used_feerate;
1883
1886
if subtract_high_prio_fee ! ( self , fee_estimator, timeout_tx. output[ 0 ] . value, predicted_weight, used_feerate) {
1887
+ let idx = timeout_tx. input [ 0 ] . sequence ;
1888
+ timeout_tx. input [ 0 ] . sequence = 0xff_ff_ff_fd ;
1884
1889
let sighash_parts = bip143:: SighashComponents :: new ( & timeout_tx) ;
1885
- let ( redeemscript, htlc_key) = sign_input ! ( sighash_parts, timeout_tx. input[ 0 ] , htlc. amount_msat / 1000 , vec![ 0 ] ) ;
1890
+ let ( redeemscript, htlc_key) = sign_input ! ( sighash_parts, timeout_tx. input[ 0 ] , htlc. amount_msat / 1000 , vec![ 0 ] , idx ) ;
1886
1891
assert ! ( predicted_weight >= timeout_tx. get_weight( ) ) ;
1887
1892
//TODO: track SpendableOutputDescriptor
1888
1893
log_trace ! ( self , "Outpoint {}:{} is being being claimed, if it doesn't succeed, a bumped claiming txn is going to be broadcast at height {}" , timeout_tx. input[ 0 ] . previous_output. txid, timeout_tx. input[ 0 ] . previous_output. vout, height_timer) ;
@@ -1934,7 +1939,7 @@ impl ChannelMonitor {
1934
1939
let height_timer = Self :: get_height_timer ( height, soonest_timelock) ;
1935
1940
let spend_txid = spend_tx. txid ( ) ;
1936
1941
for ( input, info) in spend_tx. input . iter_mut ( ) . zip ( inputs_info. iter ( ) ) {
1937
- let ( redeemscript, htlc_key) = sign_input ! ( sighash_parts, input, info. 1 , ( info. 0 ) . 0 . to_vec( ) ) ;
1942
+ let ( redeemscript, htlc_key) = sign_input ! ( sighash_parts, input, info. 1 , ( info. 0 ) . 0 . to_vec( ) , info . 3 ) ;
1938
1943
log_trace ! ( self , "Outpoint {}:{} is being being claimed, if it doesn't succeed, a bumped claiming txn is going to be broadcast at height {}" , input. previous_output. txid, input. previous_output. vout, height_timer) ;
1939
1944
per_input_material. insert ( input. previous_output , InputMaterial :: RemoteHTLC { script : redeemscript, key : htlc_key, preimage : Some ( * ( info. 0 ) ) , amount : info. 1 , locktime : 0 } ) ;
1940
1945
match self . claimable_outpoints . entry ( input. previous_output ) {
@@ -2872,7 +2877,6 @@ impl ChannelMonitor {
2872
2877
for per_outp_material in cached_claim_datas. per_input_material . values ( ) {
2873
2878
match per_outp_material {
2874
2879
& InputMaterial :: Revoked { ref script, ref is_htlc, ref amount, .. } => {
2875
- log_trace ! ( self , "Is HLTC ? {}" , is_htlc) ;
2876
2880
inputs_witnesses_weight += Self :: get_witnesses_weight ( if !is_htlc { & [ InputDescriptors :: RevokedOutput ] } else if HTLCType :: scriptlen_to_htlctype ( script. len ( ) ) == Some ( HTLCType :: OfferedHTLC ) { & [ InputDescriptors :: RevokedOfferedHTLC ] } else if HTLCType :: scriptlen_to_htlctype ( script. len ( ) ) == Some ( HTLCType :: AcceptedHTLC ) { & [ InputDescriptors :: RevokedReceivedHTLC ] } else { unreachable ! ( ) } ) ;
2877
2881
amt += * amount;
2878
2882
} ,
0 commit comments