@@ -25,6 +25,8 @@ use ln::msgs::DecodeError;
25
25
use ln:: PaymentPreimage ;
26
26
use ln:: chan_utils;
27
27
use ln:: chan_utils:: { TxCreationKeys , ChannelTransactionParameters , HolderCommitmentTransaction } ;
28
+ use ln:: package:: InputDescriptors ;
29
+ use ln:: package;
28
30
use chain:: chaininterface:: { FeeEstimator , BroadcasterInterface , ConfirmationTarget , MIN_RELAY_FEE_SAT_PER_1000_WEIGHT } ;
29
31
use chain:: channelmonitor:: { ANTI_REORG_DELAY , CLTV_SHARED_CLAIM_BUFFER , InputMaterial , ClaimRequest } ;
30
32
use chain:: keysinterface:: { Sign , KeysInterface } ;
@@ -123,62 +125,6 @@ impl Readable for ClaimTxBumpMaterial {
123
125
}
124
126
}
125
127
126
- #[ derive( PartialEq , Clone , Copy ) ]
127
- pub ( crate ) enum InputDescriptors {
128
- RevokedOfferedHTLC ,
129
- RevokedReceivedHTLC ,
130
- OfferedHTLC ,
131
- ReceivedHTLC ,
132
- RevokedOutput , // either a revoked to_holder output on commitment tx, a revoked HTLC-Timeout output or a revoked HTLC-Success output
133
- }
134
-
135
- impl Writeable for InputDescriptors {
136
- fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , :: std:: io:: Error > {
137
- match self {
138
- & InputDescriptors :: RevokedOfferedHTLC => {
139
- writer. write_all ( & [ 0 ; 1 ] ) ?;
140
- } ,
141
- & InputDescriptors :: RevokedReceivedHTLC => {
142
- writer. write_all ( & [ 1 ; 1 ] ) ?;
143
- } ,
144
- & InputDescriptors :: OfferedHTLC => {
145
- writer. write_all ( & [ 2 ; 1 ] ) ?;
146
- } ,
147
- & InputDescriptors :: ReceivedHTLC => {
148
- writer. write_all ( & [ 3 ; 1 ] ) ?;
149
- }
150
- & InputDescriptors :: RevokedOutput => {
151
- writer. write_all ( & [ 4 ; 1 ] ) ?;
152
- }
153
- }
154
- Ok ( ( ) )
155
- }
156
- }
157
-
158
- impl Readable for InputDescriptors {
159
- fn read < R : :: std:: io:: Read > ( reader : & mut R ) -> Result < Self , DecodeError > {
160
- let input_descriptor = match <u8 as Readable >:: read ( reader) ? {
161
- 0 => {
162
- InputDescriptors :: RevokedOfferedHTLC
163
- } ,
164
- 1 => {
165
- InputDescriptors :: RevokedReceivedHTLC
166
- } ,
167
- 2 => {
168
- InputDescriptors :: OfferedHTLC
169
- } ,
170
- 3 => {
171
- InputDescriptors :: ReceivedHTLC
172
- } ,
173
- 4 => {
174
- InputDescriptors :: RevokedOutput
175
- }
176
- _ => return Err ( DecodeError :: InvalidValue ) ,
177
- } ;
178
- Ok ( input_descriptor)
179
- }
180
- }
181
-
182
128
macro_rules! subtract_high_prio_fee {
183
129
( $logger: ident, $fee_estimator: expr, $value: expr, $predicted_weight: expr, $used_feerate: expr) => {
184
130
{
@@ -271,7 +217,7 @@ pub struct OnchainTxHandler<ChannelSigner: Sign> {
271
217
prev_holder_commitment : Option < HolderCommitmentTransaction > ,
272
218
prev_holder_htlc_sigs : Option < Vec < Option < ( usize , Signature ) > > > ,
273
219
274
- signer : ChannelSigner ,
220
+ pub ( super ) signer : ChannelSigner ,
275
221
pub ( crate ) channel_transaction_parameters : ChannelTransactionParameters ,
276
222
277
223
// Used to track claiming requests. If claim tx doesn't confirm before height timer expiration we need to bump
@@ -305,7 +251,7 @@ pub struct OnchainTxHandler<ChannelSigner: Sign> {
305
251
306
252
latest_height : u32 ,
307
253
308
- secp_ctx : Secp256k1 < secp256k1:: All > ,
254
+ pub ( super ) secp_ctx : Secp256k1 < secp256k1:: All > ,
309
255
}
310
256
311
257
const SERIALIZATION_VERSION : u8 = 1 ;
@@ -471,36 +417,6 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
471
417
}
472
418
}
473
419
474
- pub ( crate ) fn get_witnesses_weight ( inputs : & [ InputDescriptors ] ) -> usize {
475
- let mut tx_weight = 2 ; // count segwit flags
476
- for inp in inputs {
477
- // We use expected weight (and not actual) as signatures and time lock delays may vary
478
- tx_weight += match inp {
479
- // number_of_witness_elements + sig_length + revocation_sig + pubkey_length + revocationpubkey + witness_script_length + witness_script
480
- & InputDescriptors :: RevokedOfferedHTLC => {
481
- 1 + 1 + 73 + 1 + 33 + 1 + 133
482
- } ,
483
- // number_of_witness_elements + sig_length + revocation_sig + pubkey_length + revocationpubkey + witness_script_length + witness_script
484
- & InputDescriptors :: RevokedReceivedHTLC => {
485
- 1 + 1 + 73 + 1 + 33 + 1 + 139
486
- } ,
487
- // number_of_witness_elements + sig_length + counterpartyhtlc_sig + preimage_length + preimage + witness_script_length + witness_script
488
- & InputDescriptors :: OfferedHTLC => {
489
- 1 + 1 + 73 + 1 + 32 + 1 + 133
490
- } ,
491
- // number_of_witness_elements + sig_length + revocation_sig + pubkey_length + revocationpubkey + witness_script_length + witness_script
492
- & InputDescriptors :: ReceivedHTLC => {
493
- 1 + 1 + 73 + 1 + 1 + 1 + 139
494
- } ,
495
- // number_of_witness_elements + sig_length + revocation_sig + true_length + op_true + witness_script_length + witness_script
496
- & InputDescriptors :: RevokedOutput => {
497
- 1 + 1 + 73 + 1 + 1 + 1 + 77
498
- } ,
499
- } ;
500
- }
501
- tx_weight
502
- }
503
-
504
420
/// In LN, output claimed are time-sensitive, which means we have to spend them before reaching some timelock expiration. At in-channel
505
421
/// output detection, we generate a first version of a claim tx and associate to it a height timer. A height timer is an absolute block
506
422
/// height than once reached we should generate a new bumped "version" of the claim tx to be sure than we safely claim outputs before
@@ -592,11 +508,11 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
592
508
for per_outp_material in cached_claim_datas. per_input_material . values ( ) {
593
509
match per_outp_material {
594
510
& InputMaterial :: Revoked { ref input_descriptor, ref amount, .. } => {
595
- inputs_witnesses_weight += Self :: get_witnesses_weight ( & [ * input_descriptor] ) ;
511
+ inputs_witnesses_weight += package :: get_witnesses_weight ( & [ * input_descriptor] ) ;
596
512
amt += * amount;
597
513
} ,
598
514
& InputMaterial :: CounterpartyHTLC { ref preimage, ref htlc, .. } => {
599
- inputs_witnesses_weight += Self :: get_witnesses_weight ( if preimage. is_some ( ) { & [ InputDescriptors :: OfferedHTLC ] } else { & [ InputDescriptors :: ReceivedHTLC ] } ) ;
515
+ inputs_witnesses_weight += package :: get_witnesses_weight ( if preimage. is_some ( ) { & [ InputDescriptors :: OfferedHTLC ] } else { & [ InputDescriptors :: ReceivedHTLC ] } ) ;
600
516
amt += htlc. amount_msat / 1000 ;
601
517
} ,
602
518
& InputMaterial :: HolderHTLC { .. } => {
0 commit comments