@@ -43,7 +43,7 @@ use chain::chaininterface::{BroadcasterInterface, FeeEstimator};
43
43
use chain:: transaction:: { OutPoint , TransactionData } ;
44
44
use chain:: keysinterface:: { SpendableOutputDescriptor , StaticPaymentOutputDescriptor , DelayedPaymentOutputDescriptor , Sign , KeysInterface } ;
45
45
use chain:: onchaintx:: OnchainTxHandler ;
46
- use chain:: onchain_utils:: { CounterpartyHTLCOutput , HolderFundingOutput , HolderHTLCOutput , InputDescriptors , PackageMalleability , PackageSolvingData , PackageTemplate , RevokedOutput } ;
46
+ use chain:: onchain_utils:: { CounterpartyHTLCOutput , HolderFundingOutput , HolderHTLCOutput , PackageMalleability , PackageSolvingData , PackageTemplate , RevokedOutput , WEIGHT_REVOKED_OUTPUT , WEIGHT_REVOKED_RECEIVED_HTLC , WEIGHT_REVOKED_OFFERED_HTLC } ;
47
47
use chain:: Filter ;
48
48
use util:: logger:: Logger ;
49
49
use util:: ser:: { Readable , ReadableArgs , MaybeReadable , Writer , Writeable , U48 } ;
@@ -1581,7 +1581,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
1581
1581
// First, process non-htlc outputs (to_holder & to_counterparty)
1582
1582
for ( idx, outp) in tx. output . iter ( ) . enumerate ( ) {
1583
1583
if outp. script_pubkey == revokeable_p2wsh {
1584
- let revk_outp = RevokedOutput :: build ( per_commitment_point, per_commitment_key, self . counterparty_tx_cache . counterparty_delayed_payment_base_key , self . counterparty_tx_cache . counterparty_htlc_base_key , InputDescriptors :: RevokedOutput , outp. value , None , self . counterparty_tx_cache . on_counterparty_tx_csv ) ;
1584
+ let revk_outp = RevokedOutput :: build ( per_commitment_point, per_commitment_key, self . counterparty_tx_cache . counterparty_delayed_payment_base_key , self . counterparty_tx_cache . counterparty_htlc_base_key , WEIGHT_REVOKED_OUTPUT , outp. value , None , self . counterparty_tx_cache . on_counterparty_tx_csv ) ;
1585
1585
let justice_package = PackageTemplate :: build_package ( commitment_txid, idx as u32 , PackageSolvingData :: RevokedOutput ( revk_outp) , PackageMalleability :: Malleable , height + self . counterparty_tx_cache . on_counterparty_tx_csv as u32 , true , 0 , None , height) ;
1586
1586
claimable_outpoints. push ( justice_package) ;
1587
1587
}
@@ -1595,7 +1595,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
1595
1595
tx. output [ transaction_output_index as usize ] . value != htlc. amount_msat / 1000 {
1596
1596
return ( claimable_outpoints, ( commitment_txid, watch_outputs) ) ; // Corrupted per_commitment_data, fuck this user
1597
1597
}
1598
- let revk_outp = RevokedOutput :: build ( per_commitment_point, per_commitment_key, self . counterparty_tx_cache . counterparty_delayed_payment_base_key , self . counterparty_tx_cache . counterparty_htlc_base_key , if htlc. offered { InputDescriptors :: RevokedOfferedHTLC } else { InputDescriptors :: RevokedReceivedHTLC } , htlc. amount_msat / 1000 , Some ( htlc. clone ( ) ) , self . counterparty_tx_cache . on_counterparty_tx_csv ) ;
1598
+ let revk_outp = RevokedOutput :: build ( per_commitment_point, per_commitment_key, self . counterparty_tx_cache . counterparty_delayed_payment_base_key , self . counterparty_tx_cache . counterparty_htlc_base_key , if htlc. offered { WEIGHT_REVOKED_OFFERED_HTLC } else { WEIGHT_REVOKED_RECEIVED_HTLC } , htlc. amount_msat / 1000 , Some ( htlc. clone ( ) ) , self . counterparty_tx_cache . on_counterparty_tx_csv ) ;
1599
1599
let justice_package = PackageTemplate :: build_package ( commitment_txid, transaction_output_index, PackageSolvingData :: RevokedOutput ( revk_outp) , PackageMalleability :: Malleable , htlc. cltv_expiry , true , 0 , None , height) ;
1600
1600
claimable_outpoints. push ( justice_package) ;
1601
1601
}
@@ -1777,7 +1777,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
1777
1777
let per_commitment_point = PublicKey :: from_secret_key ( & self . secp_ctx , & per_commitment_key) ;
1778
1778
1779
1779
log_trace ! ( logger, "Counterparty HTLC broadcast {}:{}" , htlc_txid, 0 ) ;
1780
- let revk_outp = RevokedOutput :: build ( per_commitment_point, per_commitment_key, self . counterparty_tx_cache . counterparty_delayed_payment_base_key , self . counterparty_tx_cache . counterparty_htlc_base_key , InputDescriptors :: RevokedOutput , tx. output [ 0 ] . value , None , self . counterparty_tx_cache . on_counterparty_tx_csv ) ;
1780
+ let revk_outp = RevokedOutput :: build ( per_commitment_point, per_commitment_key, self . counterparty_tx_cache . counterparty_delayed_payment_base_key , self . counterparty_tx_cache . counterparty_htlc_base_key , WEIGHT_REVOKED_OUTPUT , tx. output [ 0 ] . value , None , self . counterparty_tx_cache . on_counterparty_tx_csv ) ;
1781
1781
let justice_package = PackageTemplate :: build_package ( htlc_txid, 0 , PackageSolvingData :: RevokedOutput ( revk_outp) , PackageMalleability :: Malleable , height + self . counterparty_tx_cache . on_counterparty_tx_csv as u32 , true , 0 , None , height) ;
1782
1782
let claimable_outpoints = vec ! ( justice_package) ;
1783
1783
let outputs = vec ! [ ( 0 , tx. output[ 0 ] . clone( ) ) ] ;
@@ -2889,8 +2889,7 @@ mod tests {
2889
2889
use bitcoin:: network:: constants:: Network ;
2890
2890
use hex;
2891
2891
use chain:: channelmonitor:: ChannelMonitor ;
2892
- use chain:: onchain_utils;
2893
- use chain:: onchain_utils:: InputDescriptors ;
2892
+ use chain:: onchain_utils:: { WEIGHT_OFFERED_HTLC , WEIGHT_RECEIVED_HTLC , WEIGHT_REVOKED_OFFERED_HTLC , WEIGHT_REVOKED_RECEIVED_HTLC , WEIGHT_REVOKED_OUTPUT } ;
2894
2893
use chain:: transaction:: OutPoint ;
2895
2894
use ln:: channelmanager:: { BestBlock , PaymentPreimage , PaymentHash } ;
2896
2895
use ln:: chan_utils;
@@ -3048,25 +3047,25 @@ mod tests {
3048
3047
let mut sum_actual_sigs = 0 ;
3049
3048
3050
3049
macro_rules! sign_input {
3051
- ( $sighash_parts: expr, $idx: expr, $amount: expr, $input_type : expr, $sum_actual_sigs: expr) => {
3050
+ ( $sighash_parts: expr, $idx: expr, $amount: expr, $weight : expr, $sum_actual_sigs: expr) => {
3052
3051
let htlc = HTLCOutputInCommitment {
3053
- offered: if * $input_type == InputDescriptors :: RevokedOfferedHTLC || * $input_type == InputDescriptors :: OfferedHTLC { true } else { false } ,
3052
+ offered: if * $weight == WEIGHT_REVOKED_OFFERED_HTLC || * $weight == WEIGHT_OFFERED_HTLC { true } else { false } ,
3054
3053
amount_msat: 0 ,
3055
3054
cltv_expiry: 2 << 16 ,
3056
3055
payment_hash: PaymentHash ( [ 1 ; 32 ] ) ,
3057
3056
transaction_output_index: Some ( $idx as u32 ) ,
3058
3057
} ;
3059
- let redeem_script = if * $input_type == InputDescriptors :: RevokedOutput { chan_utils:: get_revokeable_redeemscript( & pubkey, 256 , & pubkey) } else { chan_utils:: get_htlc_redeemscript_with_explicit_keys( & htlc, & pubkey, & pubkey, & pubkey) } ;
3058
+ let redeem_script = if * $weight == WEIGHT_REVOKED_OUTPUT { chan_utils:: get_revokeable_redeemscript( & pubkey, 256 , & pubkey) } else { chan_utils:: get_htlc_redeemscript_with_explicit_keys( & htlc, & pubkey, & pubkey, & pubkey) } ;
3060
3059
let sighash = hash_to_message!( & $sighash_parts. signature_hash( $idx, & redeem_script, $amount, SigHashType :: All ) [ ..] ) ;
3061
3060
let sig = secp_ctx. sign( & sighash, & privkey) ;
3062
3061
$sighash_parts. access_witness( $idx) . push( sig. serialize_der( ) . to_vec( ) ) ;
3063
3062
$sighash_parts. access_witness( $idx) [ 0 ] . push( SigHashType :: All as u8 ) ;
3064
3063
sum_actual_sigs += $sighash_parts. access_witness( $idx) [ 0 ] . len( ) ;
3065
- if * $input_type == InputDescriptors :: RevokedOutput {
3064
+ if * $weight == WEIGHT_REVOKED_OUTPUT {
3066
3065
$sighash_parts. access_witness( $idx) . push( vec!( 1 ) ) ;
3067
- } else if * $input_type == InputDescriptors :: RevokedOfferedHTLC || * $input_type == InputDescriptors :: RevokedReceivedHTLC {
3066
+ } else if * $weight == WEIGHT_REVOKED_OFFERED_HTLC || * $weight == WEIGHT_REVOKED_RECEIVED_HTLC {
3068
3067
$sighash_parts. access_witness( $idx) . push( pubkey. clone( ) . serialize( ) . to_vec( ) ) ;
3069
- } else if * $input_type == InputDescriptors :: ReceivedHTLC {
3068
+ } else if * $weight == WEIGHT_RECEIVED_HTLC {
3070
3069
$sighash_parts. access_witness( $idx) . push( vec![ 0 ] ) ;
3071
3070
} else {
3072
3071
$sighash_parts. access_witness( $idx) . push( PaymentPreimage ( [ 1 ; 32 ] ) . 0 . to_vec( ) ) ;
@@ -3099,14 +3098,16 @@ mod tests {
3099
3098
value : 0 ,
3100
3099
} ) ;
3101
3100
let base_weight = claim_tx. get_weight ( ) ;
3102
- let inputs_des = vec ! [ InputDescriptors :: RevokedOutput , InputDescriptors :: RevokedOfferedHTLC , InputDescriptors :: RevokedOfferedHTLC , InputDescriptors :: RevokedReceivedHTLC ] ;
3101
+ let inputs_weight = vec ! [ WEIGHT_REVOKED_OUTPUT , WEIGHT_REVOKED_OFFERED_HTLC , WEIGHT_REVOKED_OFFERED_HTLC , WEIGHT_REVOKED_RECEIVED_HTLC ] ;
3102
+ let mut inputs_total_weight = 2 ; // count segwit flags
3103
3103
{
3104
3104
let mut sighash_parts = bip143:: SigHashCache :: new ( & mut claim_tx) ;
3105
- for ( idx, inp) in inputs_des . iter ( ) . enumerate ( ) {
3105
+ for ( idx, inp) in inputs_weight . iter ( ) . enumerate ( ) {
3106
3106
sign_input ! ( sighash_parts, idx, 0 , inp, sum_actual_sigs) ;
3107
+ inputs_total_weight += inp;
3107
3108
}
3108
3109
}
3109
- assert_eq ! ( base_weight + onchain_utils :: get_witnesses_weight ( & inputs_des [ .. ] ) , claim_tx. get_weight( ) + /* max_length_sig */ ( 73 * inputs_des . len( ) - sum_actual_sigs) ) ;
3110
+ assert_eq ! ( base_weight + inputs_total_weight as usize , claim_tx. get_weight( ) + /* max_length_sig */ ( 73 * inputs_weight . len( ) - sum_actual_sigs) ) ;
3110
3111
3111
3112
// Claim tx with 1 offered HTLCs, 3 received HTLCs
3112
3113
claim_tx. input . clear ( ) ;
@@ -3123,14 +3124,16 @@ mod tests {
3123
3124
} ) ;
3124
3125
}
3125
3126
let base_weight = claim_tx. get_weight ( ) ;
3126
- let inputs_des = vec ! [ InputDescriptors :: OfferedHTLC , InputDescriptors :: ReceivedHTLC , InputDescriptors :: ReceivedHTLC , InputDescriptors :: ReceivedHTLC ] ;
3127
+ let inputs_weight = vec ! [ WEIGHT_OFFERED_HTLC , WEIGHT_RECEIVED_HTLC , WEIGHT_RECEIVED_HTLC , WEIGHT_RECEIVED_HTLC ] ;
3128
+ let mut inputs_total_weight = 2 ; // count segwit flags
3127
3129
{
3128
3130
let mut sighash_parts = bip143:: SigHashCache :: new ( & mut claim_tx) ;
3129
- for ( idx, inp) in inputs_des . iter ( ) . enumerate ( ) {
3131
+ for ( idx, inp) in inputs_weight . iter ( ) . enumerate ( ) {
3130
3132
sign_input ! ( sighash_parts, idx, 0 , inp, sum_actual_sigs) ;
3133
+ inputs_total_weight += inp;
3131
3134
}
3132
3135
}
3133
- assert_eq ! ( base_weight + onchain_utils :: get_witnesses_weight ( & inputs_des [ .. ] ) , claim_tx. get_weight( ) + /* max_length_sig */ ( 73 * inputs_des . len( ) - sum_actual_sigs) ) ;
3136
+ assert_eq ! ( base_weight + inputs_total_weight as usize , claim_tx. get_weight( ) + /* max_length_sig */ ( 73 * inputs_weight . len( ) - sum_actual_sigs) ) ;
3134
3137
3135
3138
// Justice tx with 1 revoked HTLC-Success tx output
3136
3139
claim_tx. input . clear ( ) ;
@@ -3145,14 +3148,16 @@ mod tests {
3145
3148
witness : Vec :: new ( ) ,
3146
3149
} ) ;
3147
3150
let base_weight = claim_tx. get_weight ( ) ;
3148
- let inputs_des = vec ! [ InputDescriptors :: RevokedOutput ] ;
3151
+ let inputs_weight = vec ! [ WEIGHT_REVOKED_OUTPUT ] ;
3152
+ let mut inputs_total_weight = 2 ; // count segwit flags
3149
3153
{
3150
3154
let mut sighash_parts = bip143:: SigHashCache :: new ( & mut claim_tx) ;
3151
- for ( idx, inp) in inputs_des . iter ( ) . enumerate ( ) {
3155
+ for ( idx, inp) in inputs_weight . iter ( ) . enumerate ( ) {
3152
3156
sign_input ! ( sighash_parts, idx, 0 , inp, sum_actual_sigs) ;
3157
+ inputs_total_weight += inp;
3153
3158
}
3154
3159
}
3155
- assert_eq ! ( base_weight + onchain_utils :: get_witnesses_weight ( & inputs_des [ .. ] ) , claim_tx. get_weight( ) + /* max_length_isg */ ( 73 * inputs_des . len( ) - sum_actual_sigs) ) ;
3160
+ assert_eq ! ( base_weight + inputs_total_weight as usize , claim_tx. get_weight( ) + /* max_length_isg */ ( 73 * inputs_weight . len( ) - sum_actual_sigs) ) ;
3156
3161
}
3157
3162
3158
3163
// Further testing is done in the ChannelManager integration tests.
0 commit comments