@@ -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 ;
@@ -111,15 +111,62 @@ impl Readable for ClaimTxBumpMaterial {
111
111
}
112
112
}
113
113
114
- #[ derive( PartialEq ) ]
115
- pub ( super ) enum InputDescriptors {
114
+ #[ derive( PartialEq , Clone , Copy ) ]
115
+ pub ( crate ) enum InputDescriptors {
116
116
RevokedOfferedHTLC ,
117
117
RevokedReceivedHTLC ,
118
118
OfferedHTLC ,
119
119
ReceivedHTLC ,
120
120
RevokedOutput , // either a revoked to_local output on commitment tx, a revoked HTLC-Timeout output or a revoked HTLC-Success output
121
121
}
122
122
123
+ impl Writeable for InputDescriptors {
124
+ fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , :: std:: io:: Error > {
125
+ match self {
126
+ & InputDescriptors :: RevokedOfferedHTLC => {
127
+ writer. write_all ( & [ 0 ; 1 ] ) ?;
128
+ } ,
129
+ & InputDescriptors :: RevokedReceivedHTLC => {
130
+ writer. write_all ( & [ 1 ; 1 ] ) ?;
131
+ } ,
132
+ & InputDescriptors :: OfferedHTLC => {
133
+ writer. write_all ( & [ 2 ; 1 ] ) ?;
134
+ } ,
135
+ & InputDescriptors :: ReceivedHTLC => {
136
+ writer. write_all ( & [ 3 ; 1 ] ) ?;
137
+ }
138
+ & InputDescriptors :: RevokedOutput => {
139
+ writer. write_all ( & [ 4 ; 1 ] ) ?;
140
+ }
141
+ }
142
+ Ok ( ( ) )
143
+ }
144
+ }
145
+
146
+ impl Readable for InputDescriptors {
147
+ fn read < R : :: std:: io:: Read > ( reader : & mut R ) -> Result < Self , DecodeError > {
148
+ let input_descriptor = match <u8 as Readable >:: read ( reader) ? {
149
+ 0 => {
150
+ InputDescriptors :: RevokedOfferedHTLC
151
+ } ,
152
+ 1 => {
153
+ InputDescriptors :: RevokedReceivedHTLC
154
+ } ,
155
+ 2 => {
156
+ InputDescriptors :: OfferedHTLC
157
+ } ,
158
+ 3 => {
159
+ InputDescriptors :: ReceivedHTLC
160
+ } ,
161
+ 4 => {
162
+ InputDescriptors :: RevokedOutput
163
+ }
164
+ _ => return Err ( DecodeError :: InvalidValue ) ,
165
+ } ;
166
+ Ok ( input_descriptor)
167
+ }
168
+ }
169
+
123
170
macro_rules! subtract_high_prio_fee {
124
171
( $self: ident, $fee_estimator: expr, $value: expr, $predicted_weight: expr, $used_feerate: expr) => {
125
172
{
@@ -579,8 +626,8 @@ impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
579
626
let mut dynamic_fee = true ;
580
627
for per_outp_material in cached_claim_datas. per_input_material . values ( ) {
581
628
match per_outp_material {
582
- & InputMaterial :: Revoked { ref witness_script , ref is_htlc , ref amount, .. } => {
583
- 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 ! ( ) } ) ;
629
+ & InputMaterial :: Revoked { ref input_descriptor , ref amount, .. } => {
630
+ inputs_witnesses_weight += Self :: get_witnesses_weight ( & [ * input_descriptor ] ) ;
584
631
amt += * amount;
585
632
} ,
586
633
& InputMaterial :: RemoteHTLC { ref preimage, ref amount, .. } => {
@@ -618,19 +665,19 @@ impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
618
665
619
666
for ( i, ( outp, per_outp_material) ) in cached_claim_datas. per_input_material . iter ( ) . enumerate ( ) {
620
667
match per_outp_material {
621
- & InputMaterial :: Revoked { ref witness_script, ref pubkey, ref key, ref is_htlc , ref amount } => {
668
+ & InputMaterial :: Revoked { ref witness_script, ref pubkey, ref key, ref input_descriptor , ref amount } => {
622
669
let sighash_parts = bip143:: SighashComponents :: new ( & bumped_tx) ;
623
670
let sighash = hash_to_message ! ( & sighash_parts. sighash_all( & bumped_tx. input[ i] , & witness_script, * amount) [ ..] ) ;
624
671
let sig = self . secp_ctx . sign ( & sighash, & key) ;
625
672
bumped_tx. input [ i] . witness . push ( sig. serialize_der ( ) . to_vec ( ) ) ;
626
673
bumped_tx. input [ i] . witness [ 0 ] . push ( SigHashType :: All as u8 ) ;
627
- if * is_htlc {
674
+ if * input_descriptor != InputDescriptors :: RevokedOutput {
628
675
bumped_tx. input [ i] . witness . push ( pubkey. unwrap ( ) . clone ( ) . serialize ( ) . to_vec ( ) ) ;
629
676
} else {
630
677
bumped_tx. input [ i] . witness . push ( vec ! ( 1 ) ) ;
631
678
}
632
679
bumped_tx. input [ i] . witness . push ( witness_script. clone ( ) . into_bytes ( ) ) ;
633
- 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) ;
680
+ 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) ;
634
681
} ,
635
682
& InputMaterial :: RemoteHTLC { ref witness_script, ref key, ref preimage, ref amount, ref locktime } => {
636
683
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