@@ -18,7 +18,7 @@ use ln::msgs::DecodeError;
18
18
use ln:: channelmonitor:: { ANTI_REORG_DELAY , CLTV_SHARED_CLAIM_BUFFER , InputMaterial , ClaimRequest } ;
19
19
use ln:: channelmanager:: { HTLCSource , PaymentPreimage } ;
20
20
use ln:: chan_utils;
21
- use ln:: chan_utils:: { HTLCType , TxCreationKeys , HTLCOutputInCommitment } ;
21
+ use ln:: chan_utils:: { TxCreationKeys , HTLCOutputInCommitment } ;
22
22
use chain:: chaininterface:: { FeeEstimator , BroadcasterInterface , ConfirmationTarget , MIN_RELAY_FEE_SAT_PER_1000_WEIGHT } ;
23
23
use chain:: keysinterface:: ChannelKeys ;
24
24
use util:: logger:: Logger ;
@@ -112,15 +112,62 @@ impl Readable for ClaimTxBumpMaterial {
112
112
}
113
113
}
114
114
115
- #[ derive( PartialEq ) ]
116
- pub ( super ) enum InputDescriptors {
115
+ #[ derive( PartialEq , Clone , Copy ) ]
116
+ pub ( crate ) enum InputDescriptors {
117
117
RevokedOfferedHTLC ,
118
118
RevokedReceivedHTLC ,
119
119
OfferedHTLC ,
120
120
ReceivedHTLC ,
121
121
RevokedOutput , // either a revoked to_local output on commitment tx, a revoked HTLC-Timeout output or a revoked HTLC-Success output
122
122
}
123
123
124
+ impl Writeable for InputDescriptors {
125
+ fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , :: std:: io:: Error > {
126
+ match self {
127
+ & InputDescriptors :: RevokedOfferedHTLC => {
128
+ writer. write_all ( & [ 0 ; 1 ] ) ?;
129
+ } ,
130
+ & InputDescriptors :: RevokedReceivedHTLC => {
131
+ writer. write_all ( & [ 1 ; 1 ] ) ?;
132
+ } ,
133
+ & InputDescriptors :: OfferedHTLC => {
134
+ writer. write_all ( & [ 2 ; 1 ] ) ?;
135
+ } ,
136
+ & InputDescriptors :: ReceivedHTLC => {
137
+ writer. write_all ( & [ 3 ; 1 ] ) ?;
138
+ }
139
+ & InputDescriptors :: RevokedOutput => {
140
+ writer. write_all ( & [ 4 ; 1 ] ) ?;
141
+ }
142
+ }
143
+ Ok ( ( ) )
144
+ }
145
+ }
146
+
147
+ impl Readable for InputDescriptors {
148
+ fn read < R : :: std:: io:: Read > ( reader : & mut R ) -> Result < Self , DecodeError > {
149
+ let input_descriptor = match <u8 as Readable >:: read ( reader) ? {
150
+ 0 => {
151
+ InputDescriptors :: RevokedOfferedHTLC
152
+ } ,
153
+ 1 => {
154
+ InputDescriptors :: RevokedReceivedHTLC
155
+ } ,
156
+ 2 => {
157
+ InputDescriptors :: OfferedHTLC
158
+ } ,
159
+ 3 => {
160
+ InputDescriptors :: ReceivedHTLC
161
+ } ,
162
+ 4 => {
163
+ InputDescriptors :: RevokedOutput
164
+ }
165
+ _ => return Err ( DecodeError :: InvalidValue ) ,
166
+ } ;
167
+ Ok ( input_descriptor)
168
+ }
169
+ }
170
+
124
171
macro_rules! subtract_high_prio_fee {
125
172
( $self: ident, $fee_estimator: expr, $value: expr, $predicted_weight: expr, $used_feerate: expr) => {
126
173
{
@@ -580,8 +627,8 @@ impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
580
627
let mut dynamic_fee = true ;
581
628
for per_outp_material in cached_claim_datas. per_input_material . values ( ) {
582
629
match per_outp_material {
583
- & InputMaterial :: Revoked { ref witness_script , ref is_htlc , ref amount, .. } => {
584
- inputs_witnesses_weight += Self :: get_witnesses_weight ( if !is_htlc { & [ InputDescriptors :: RevokedOutput ] } else if HTLCType :: scriptlen_to_htlctype ( witness_script . len ( ) ) == Some ( HTLCType :: OfferedHTLC ) { & [ InputDescriptors :: RevokedOfferedHTLC ] } else if HTLCType :: scriptlen_to_htlctype ( witness_script . len ( ) ) == Some ( HTLCType :: AcceptedHTLC ) { & [ InputDescriptors :: RevokedReceivedHTLC ] } else { unreachable ! ( ) } ) ;
630
+ & InputMaterial :: Revoked { ref input_descriptor , ref amount, .. } => {
631
+ inputs_witnesses_weight += Self :: get_witnesses_weight ( & [ * input_descriptor ] ) ;
585
632
amt += * amount;
586
633
} ,
587
634
& InputMaterial :: RemoteHTLC { ref preimage, ref amount, .. } => {
@@ -619,19 +666,19 @@ impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
619
666
620
667
for ( i, ( outp, per_outp_material) ) in cached_claim_datas. per_input_material . iter ( ) . enumerate ( ) {
621
668
match per_outp_material {
622
- & InputMaterial :: Revoked { ref witness_script, ref pubkey, ref key, ref is_htlc , ref amount } => {
669
+ & InputMaterial :: Revoked { ref witness_script, ref pubkey, ref key, ref input_descriptor , ref amount } => {
623
670
let sighash_parts = bip143:: SighashComponents :: new ( & bumped_tx) ;
624
671
let sighash = hash_to_message ! ( & sighash_parts. sighash_all( & bumped_tx. input[ i] , & witness_script, * amount) [ ..] ) ;
625
672
let sig = self . secp_ctx . sign ( & sighash, & key) ;
626
673
bumped_tx. input [ i] . witness . push ( sig. serialize_der ( ) . to_vec ( ) ) ;
627
674
bumped_tx. input [ i] . witness [ 0 ] . push ( SigHashType :: All as u8 ) ;
628
- if * is_htlc {
675
+ if * input_descriptor != InputDescriptors :: RevokedOutput {
629
676
bumped_tx. input [ i] . witness . push ( pubkey. unwrap ( ) . clone ( ) . serialize ( ) . to_vec ( ) ) ;
630
677
} else {
631
678
bumped_tx. input [ i] . witness . push ( vec ! ( 1 ) ) ;
632
679
}
633
680
bumped_tx. input [ i] . witness . push ( witness_script. clone ( ) . into_bytes ( ) ) ;
634
- log_trace ! ( self , "Going to broadcast Penalty Transaction {} claiming revoked {} output {} from {} with new feerate {}..." , bumped_tx. txid( ) , if !is_htlc { "to_local" } else if HTLCType :: scriptlen_to_htlctype ( witness_script . len ( ) ) == Some ( HTLCType :: OfferedHTLC ) { "offered" } else if HTLCType :: scriptlen_to_htlctype ( witness_script . len ( ) ) == Some ( HTLCType :: AcceptedHTLC ) { "received" } else { "" } , outp. vout, outp. txid, new_feerate) ;
681
+ log_trace ! ( self , "Going to broadcast Penalty Transaction {} claiming revoked {} output {} from {} with new feerate {}..." , bumped_tx. txid( ) , if * input_descriptor == InputDescriptors :: RevokedOutput { "to_local" } else if * input_descriptor == InputDescriptors :: RevokedOfferedHTLC { "offered" } else if * input_descriptor == InputDescriptors :: RevokedReceivedHTLC { "received" } else { "" } , outp. vout, outp. txid, new_feerate) ;
635
682
} ,
636
683
& InputMaterial :: RemoteHTLC { ref witness_script, ref key, ref preimage, ref amount, ref locktime } => {
637
684
if !preimage. is_some ( ) { bumped_tx. lock_time = * locktime } ; // Right now we don't aggregate time-locked transaction, if we do we should set lock_time before to avoid breaking hash computation
0 commit comments