@@ -17,7 +17,7 @@ use secp256k1;
17
17
use ln:: msgs:: DecodeError ;
18
18
use ln:: channelmonitor:: { ANTI_REORG_DELAY , CLTV_SHARED_CLAIM_BUFFER , InputMaterial , ClaimRequest } ;
19
19
use ln:: channelmanager:: PaymentPreimage ;
20
- use ln:: chan_utils:: { HTLCType , LocalCommitmentTransaction , HTLCOutputInCommitment } ;
20
+ use ln:: chan_utils:: { LocalCommitmentTransaction , HTLCOutputInCommitment } ;
21
21
use chain:: chaininterface:: { FeeEstimator , BroadcasterInterface , ConfirmationTarget , MIN_RELAY_FEE_SAT_PER_1000_WEIGHT } ;
22
22
use chain:: keysinterface:: ChannelKeys ;
23
23
use util:: logger:: Logger ;
@@ -102,15 +102,62 @@ impl Readable for ClaimTxBumpMaterial {
102
102
}
103
103
}
104
104
105
- #[ derive( PartialEq ) ]
106
- pub ( super ) enum InputDescriptors {
105
+ #[ derive( PartialEq , Clone , Copy ) ]
106
+ pub ( crate ) enum InputDescriptors {
107
107
RevokedOfferedHTLC ,
108
108
RevokedReceivedHTLC ,
109
109
OfferedHTLC ,
110
110
ReceivedHTLC ,
111
111
RevokedOutput , // either a revoked to_local output on commitment tx, a revoked HTLC-Timeout output or a revoked HTLC-Success output
112
112
}
113
113
114
+ impl Writeable for InputDescriptors {
115
+ fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , :: std:: io:: Error > {
116
+ match self {
117
+ & InputDescriptors :: RevokedOfferedHTLC => {
118
+ writer. write_all ( & [ 0 ; 1 ] ) ?;
119
+ } ,
120
+ & InputDescriptors :: RevokedReceivedHTLC => {
121
+ writer. write_all ( & [ 1 ; 1 ] ) ?;
122
+ } ,
123
+ & InputDescriptors :: OfferedHTLC => {
124
+ writer. write_all ( & [ 2 ; 1 ] ) ?;
125
+ } ,
126
+ & InputDescriptors :: ReceivedHTLC => {
127
+ writer. write_all ( & [ 3 ; 1 ] ) ?;
128
+ }
129
+ & InputDescriptors :: RevokedOutput => {
130
+ writer. write_all ( & [ 4 ; 1 ] ) ?;
131
+ }
132
+ }
133
+ Ok ( ( ) )
134
+ }
135
+ }
136
+
137
+ impl Readable for InputDescriptors {
138
+ fn read < R : :: std:: io:: Read > ( reader : & mut R ) -> Result < Self , DecodeError > {
139
+ let input_descriptor = match <u8 as Readable >:: read ( reader) ? {
140
+ 0 => {
141
+ InputDescriptors :: RevokedOfferedHTLC
142
+ } ,
143
+ 1 => {
144
+ InputDescriptors :: RevokedReceivedHTLC
145
+ } ,
146
+ 2 => {
147
+ InputDescriptors :: OfferedHTLC
148
+ } ,
149
+ 3 => {
150
+ InputDescriptors :: ReceivedHTLC
151
+ } ,
152
+ 4 => {
153
+ InputDescriptors :: RevokedOutput
154
+ }
155
+ _ => return Err ( DecodeError :: InvalidValue ) ,
156
+ } ;
157
+ Ok ( input_descriptor)
158
+ }
159
+ }
160
+
114
161
macro_rules! subtract_high_prio_fee {
115
162
( $self: ident, $fee_estimator: expr, $value: expr, $predicted_weight: expr, $used_feerate: expr) => {
116
163
{
@@ -548,8 +595,8 @@ impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
548
595
let mut dynamic_fee = true ;
549
596
for per_outp_material in cached_claim_datas. per_input_material . values ( ) {
550
597
match per_outp_material {
551
- & InputMaterial :: Revoked { ref witness_script , ref is_htlc , ref amount, .. } => {
552
- 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 ! ( ) } ) ;
598
+ & InputMaterial :: Revoked { ref input_descriptor , ref amount, .. } => {
599
+ inputs_witnesses_weight += Self :: get_witnesses_weight ( & [ * input_descriptor ] ) ;
553
600
amt += * amount;
554
601
} ,
555
602
& InputMaterial :: RemoteHTLC { ref preimage, ref amount, .. } => {
@@ -587,19 +634,19 @@ impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
587
634
588
635
for ( i, ( outp, per_outp_material) ) in cached_claim_datas. per_input_material . iter ( ) . enumerate ( ) {
589
636
match per_outp_material {
590
- & InputMaterial :: Revoked { ref witness_script, ref pubkey, ref key, ref is_htlc , ref amount } => {
637
+ & InputMaterial :: Revoked { ref witness_script, ref pubkey, ref key, ref input_descriptor , ref amount } => {
591
638
let sighash_parts = bip143:: SighashComponents :: new ( & bumped_tx) ;
592
639
let sighash = hash_to_message ! ( & sighash_parts. sighash_all( & bumped_tx. input[ i] , & witness_script, * amount) [ ..] ) ;
593
640
let sig = self . secp_ctx . sign ( & sighash, & key) ;
594
641
bumped_tx. input [ i] . witness . push ( sig. serialize_der ( ) . to_vec ( ) ) ;
595
642
bumped_tx. input [ i] . witness [ 0 ] . push ( SigHashType :: All as u8 ) ;
596
- if * is_htlc {
643
+ if * input_descriptor != InputDescriptors :: RevokedOutput {
597
644
bumped_tx. input [ i] . witness . push ( pubkey. unwrap ( ) . clone ( ) . serialize ( ) . to_vec ( ) ) ;
598
645
} else {
599
646
bumped_tx. input [ i] . witness . push ( vec ! ( 1 ) ) ;
600
647
}
601
648
bumped_tx. input [ i] . witness . push ( witness_script. clone ( ) . into_bytes ( ) ) ;
602
- 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) ;
649
+ 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) ;
603
650
} ,
604
651
& InputMaterial :: RemoteHTLC { ref witness_script, ref key, ref preimage, ref amount, ref locktime } => {
605
652
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