@@ -44,7 +44,7 @@ use chain::chaininterface::{BroadcasterInterface, FeeEstimator};
44
44
use chain:: transaction:: { OutPoint , TransactionData } ;
45
45
use chain:: keysinterface:: { SpendableOutputDescriptor , StaticPaymentOutputDescriptor , DelayedPaymentOutputDescriptor , Sign , KeysInterface } ;
46
46
use chain:: onchaintx:: OnchainTxHandler ;
47
- use chain:: onchain_utils:: { CounterpartyHTLCOutput , HolderFundingOutput , HolderHTLCOutput , InputDescriptors , PackageMalleability , PackageSolvingData , PackageTemplate , RevokedOutput } ;
47
+ use chain:: onchain_utils:: { CounterpartyHTLCOutput , HolderFundingOutput , HolderHTLCOutput , PackageMalleability , PackageSolvingData , PackageTemplate , RevokedOutput , WEIGHT_REVOKED_OUTPUT , WEIGHT_REVOKED_RECEIVED_HTLC , WEIGHT_REVOKED_OFFERED_HTLC } ;
48
48
use chain:: Filter ;
49
49
use util:: logger:: Logger ;
50
50
use util:: ser:: { Readable , ReadableArgs , MaybeReadable , Writer , Writeable , U48 } ;
@@ -1571,7 +1571,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
1571
1571
// First, process non-htlc outputs (to_holder & to_counterparty)
1572
1572
for ( idx, outp) in tx. output . iter ( ) . enumerate ( ) {
1573
1573
if outp. script_pubkey == revokeable_p2wsh {
1574
- 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 ) ;
1574
+ 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 ) ;
1575
1575
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) ;
1576
1576
claimable_outpoints. push ( justice_package) ;
1577
1577
}
@@ -1585,7 +1585,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
1585
1585
tx. output [ transaction_output_index as usize ] . value != htlc. amount_msat / 1000 {
1586
1586
return ( claimable_outpoints, ( commitment_txid, watch_outputs) ) ; // Corrupted per_commitment_data, fuck this user
1587
1587
}
1588
- 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 ) ;
1588
+ 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 ) ;
1589
1589
let justice_package = PackageTemplate :: build_package ( commitment_txid, transaction_output_index, PackageSolvingData :: RevokedOutput ( revk_outp) , PackageMalleability :: Malleable , htlc. cltv_expiry , true , 0 , None , height) ;
1590
1590
claimable_outpoints. push ( justice_package) ;
1591
1591
}
@@ -1767,7 +1767,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
1767
1767
let per_commitment_point = PublicKey :: from_secret_key ( & self . secp_ctx , & per_commitment_key) ;
1768
1768
1769
1769
log_trace ! ( logger, "Counterparty HTLC broadcast {}:{}" , htlc_txid, 0 ) ;
1770
- 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 ) ;
1770
+ 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 ) ;
1771
1771
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) ;
1772
1772
let claimable_outpoints = vec ! ( justice_package) ;
1773
1773
let outputs = vec ! [ ( 0 , tx. output[ 0 ] . clone( ) ) ] ;
@@ -2902,8 +2902,7 @@ mod tests {
2902
2902
use bitcoin:: network:: constants:: Network ;
2903
2903
use hex;
2904
2904
use chain:: channelmonitor:: ChannelMonitor ;
2905
- use chain:: onchain_utils;
2906
- use chain:: onchain_utils:: InputDescriptors ;
2905
+ use chain:: onchain_utils:: { WEIGHT_OFFERED_HTLC , WEIGHT_RECEIVED_HTLC , WEIGHT_REVOKED_OFFERED_HTLC , WEIGHT_REVOKED_RECEIVED_HTLC , WEIGHT_REVOKED_OUTPUT } ;
2907
2906
use chain:: transaction:: OutPoint ;
2908
2907
use ln:: { PaymentPreimage , PaymentHash } ;
2909
2908
use ln:: channelmanager:: BestBlock ;
@@ -3062,25 +3061,25 @@ mod tests {
3062
3061
let mut sum_actual_sigs = 0 ;
3063
3062
3064
3063
macro_rules! sign_input {
3065
- ( $sighash_parts: expr, $idx: expr, $amount: expr, $input_type : expr, $sum_actual_sigs: expr) => {
3064
+ ( $sighash_parts: expr, $idx: expr, $amount: expr, $weight : expr, $sum_actual_sigs: expr) => {
3066
3065
let htlc = HTLCOutputInCommitment {
3067
- offered: if * $input_type == InputDescriptors :: RevokedOfferedHTLC || * $input_type == InputDescriptors :: OfferedHTLC { true } else { false } ,
3066
+ offered: if * $weight == WEIGHT_REVOKED_OFFERED_HTLC || * $weight == WEIGHT_OFFERED_HTLC { true } else { false } ,
3068
3067
amount_msat: 0 ,
3069
3068
cltv_expiry: 2 << 16 ,
3070
3069
payment_hash: PaymentHash ( [ 1 ; 32 ] ) ,
3071
3070
transaction_output_index: Some ( $idx as u32 ) ,
3072
3071
} ;
3073
- 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) } ;
3072
+ 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) } ;
3074
3073
let sighash = hash_to_message!( & $sighash_parts. signature_hash( $idx, & redeem_script, $amount, SigHashType :: All ) [ ..] ) ;
3075
3074
let sig = secp_ctx. sign( & sighash, & privkey) ;
3076
3075
$sighash_parts. access_witness( $idx) . push( sig. serialize_der( ) . to_vec( ) ) ;
3077
3076
$sighash_parts. access_witness( $idx) [ 0 ] . push( SigHashType :: All as u8 ) ;
3078
3077
sum_actual_sigs += $sighash_parts. access_witness( $idx) [ 0 ] . len( ) ;
3079
- if * $input_type == InputDescriptors :: RevokedOutput {
3078
+ if * $weight == WEIGHT_REVOKED_OUTPUT {
3080
3079
$sighash_parts. access_witness( $idx) . push( vec!( 1 ) ) ;
3081
- } else if * $input_type == InputDescriptors :: RevokedOfferedHTLC || * $input_type == InputDescriptors :: RevokedReceivedHTLC {
3080
+ } else if * $weight == WEIGHT_REVOKED_OFFERED_HTLC || * $weight == WEIGHT_REVOKED_RECEIVED_HTLC {
3082
3081
$sighash_parts. access_witness( $idx) . push( pubkey. clone( ) . serialize( ) . to_vec( ) ) ;
3083
- } else if * $input_type == InputDescriptors :: ReceivedHTLC {
3082
+ } else if * $weight == WEIGHT_RECEIVED_HTLC {
3084
3083
$sighash_parts. access_witness( $idx) . push( vec![ 0 ] ) ;
3085
3084
} else {
3086
3085
$sighash_parts. access_witness( $idx) . push( PaymentPreimage ( [ 1 ; 32 ] ) . 0 . to_vec( ) ) ;
@@ -3113,14 +3112,16 @@ mod tests {
3113
3112
value : 0 ,
3114
3113
} ) ;
3115
3114
let base_weight = claim_tx. get_weight ( ) ;
3116
- let inputs_des = vec ! [ InputDescriptors :: RevokedOutput , InputDescriptors :: RevokedOfferedHTLC , InputDescriptors :: RevokedOfferedHTLC , InputDescriptors :: RevokedReceivedHTLC ] ;
3115
+ let inputs_weight = vec ! [ WEIGHT_REVOKED_OUTPUT , WEIGHT_REVOKED_OFFERED_HTLC , WEIGHT_REVOKED_OFFERED_HTLC , WEIGHT_REVOKED_RECEIVED_HTLC ] ;
3116
+ let mut inputs_total_weight = 2 ; // count segwit flags
3117
3117
{
3118
3118
let mut sighash_parts = bip143:: SigHashCache :: new ( & mut claim_tx) ;
3119
- for ( idx, inp) in inputs_des . iter ( ) . enumerate ( ) {
3119
+ for ( idx, inp) in inputs_weight . iter ( ) . enumerate ( ) {
3120
3120
sign_input ! ( sighash_parts, idx, 0 , inp, sum_actual_sigs) ;
3121
+ inputs_total_weight += inp;
3121
3122
}
3122
3123
}
3123
- 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) ) ;
3124
+ assert_eq ! ( base_weight + inputs_total_weight as usize , claim_tx. get_weight( ) + /* max_length_sig */ ( 73 * inputs_weight . len( ) - sum_actual_sigs) ) ;
3124
3125
3125
3126
// Claim tx with 1 offered HTLCs, 3 received HTLCs
3126
3127
claim_tx. input . clear ( ) ;
@@ -3137,14 +3138,16 @@ mod tests {
3137
3138
} ) ;
3138
3139
}
3139
3140
let base_weight = claim_tx. get_weight ( ) ;
3140
- let inputs_des = vec ! [ InputDescriptors :: OfferedHTLC , InputDescriptors :: ReceivedHTLC , InputDescriptors :: ReceivedHTLC , InputDescriptors :: ReceivedHTLC ] ;
3141
+ let inputs_weight = vec ! [ WEIGHT_OFFERED_HTLC , WEIGHT_RECEIVED_HTLC , WEIGHT_RECEIVED_HTLC , WEIGHT_RECEIVED_HTLC ] ;
3142
+ let mut inputs_total_weight = 2 ; // count segwit flags
3141
3143
{
3142
3144
let mut sighash_parts = bip143:: SigHashCache :: new ( & mut claim_tx) ;
3143
- for ( idx, inp) in inputs_des . iter ( ) . enumerate ( ) {
3145
+ for ( idx, inp) in inputs_weight . iter ( ) . enumerate ( ) {
3144
3146
sign_input ! ( sighash_parts, idx, 0 , inp, sum_actual_sigs) ;
3147
+ inputs_total_weight += inp;
3145
3148
}
3146
3149
}
3147
- 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) ) ;
3150
+ assert_eq ! ( base_weight + inputs_total_weight as usize , claim_tx. get_weight( ) + /* max_length_sig */ ( 73 * inputs_weight . len( ) - sum_actual_sigs) ) ;
3148
3151
3149
3152
// Justice tx with 1 revoked HTLC-Success tx output
3150
3153
claim_tx. input . clear ( ) ;
@@ -3159,14 +3162,16 @@ mod tests {
3159
3162
witness : Vec :: new ( ) ,
3160
3163
} ) ;
3161
3164
let base_weight = claim_tx. get_weight ( ) ;
3162
- let inputs_des = vec ! [ InputDescriptors :: RevokedOutput ] ;
3165
+ let inputs_weight = vec ! [ WEIGHT_REVOKED_OUTPUT ] ;
3166
+ let mut inputs_total_weight = 2 ; // count segwit flags
3163
3167
{
3164
3168
let mut sighash_parts = bip143:: SigHashCache :: new ( & mut claim_tx) ;
3165
- for ( idx, inp) in inputs_des . iter ( ) . enumerate ( ) {
3169
+ for ( idx, inp) in inputs_weight . iter ( ) . enumerate ( ) {
3166
3170
sign_input ! ( sighash_parts, idx, 0 , inp, sum_actual_sigs) ;
3171
+ inputs_total_weight += inp;
3167
3172
}
3168
3173
}
3169
- 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) ) ;
3174
+ assert_eq ! ( base_weight + inputs_total_weight as usize , claim_tx. get_weight( ) + /* max_length_isg */ ( 73 * inputs_weight . len( ) - sum_actual_sigs) ) ;
3170
3175
}
3171
3176
3172
3177
// Further testing is done in the ChannelManager integration tests.
0 commit comments