@@ -17,6 +17,8 @@ use ln::channelmonitor::{ANTI_REORG_DELAY, CLTV_SHARED_CLAIM_BUFFER, InputMateri
17
17
use ln:: channelmanager:: PaymentPreimage ;
18
18
use ln:: chan_utils;
19
19
use ln:: chan_utils:: { TxCreationKeys , LocalCommitmentTransaction } ;
20
+ use ln:: onchain_utils:: InputDescriptors ;
21
+ use ln:: onchain_utils;
20
22
use chain:: chaininterface:: { FeeEstimator , BroadcasterInterface , ConfirmationTarget , MIN_RELAY_FEE_SAT_PER_1000_WEIGHT } ;
21
23
use chain:: keysinterface:: ChannelKeys ;
22
24
use util:: logger:: Logger ;
@@ -92,61 +94,6 @@ impl Readable for ClaimTxBumpMaterial {
92
94
}
93
95
}
94
96
95
- #[ derive( PartialEq , Clone , Copy ) ]
96
- pub ( crate ) enum InputDescriptors {
97
- RevokedOfferedHTLC ,
98
- RevokedReceivedHTLC ,
99
- OfferedHTLC ,
100
- ReceivedHTLC ,
101
- RevokedOutput , // either a revoked to_local output on commitment tx, a revoked HTLC-Timeout output or a revoked HTLC-Success output
102
- }
103
-
104
- impl Writeable for InputDescriptors {
105
- fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , :: std:: io:: Error > {
106
- match self {
107
- & InputDescriptors :: RevokedOfferedHTLC => {
108
- writer. write_all ( & [ 0 ; 1 ] ) ?;
109
- } ,
110
- & InputDescriptors :: RevokedReceivedHTLC => {
111
- writer. write_all ( & [ 1 ; 1 ] ) ?;
112
- } ,
113
- & InputDescriptors :: OfferedHTLC => {
114
- writer. write_all ( & [ 2 ; 1 ] ) ?;
115
- } ,
116
- & InputDescriptors :: ReceivedHTLC => {
117
- writer. write_all ( & [ 3 ; 1 ] ) ?;
118
- }
119
- & InputDescriptors :: RevokedOutput => {
120
- writer. write_all ( & [ 4 ; 1 ] ) ?;
121
- }
122
- }
123
- Ok ( ( ) )
124
- }
125
- }
126
-
127
- impl Readable for InputDescriptors {
128
- fn read < R : :: std:: io:: Read > ( reader : & mut R ) -> Result < Self , DecodeError > {
129
- let input_descriptor = match <u8 as Readable >:: read ( reader) ? {
130
- 0 => {
131
- InputDescriptors :: RevokedOfferedHTLC
132
- } ,
133
- 1 => {
134
- InputDescriptors :: RevokedReceivedHTLC
135
- } ,
136
- 2 => {
137
- InputDescriptors :: OfferedHTLC
138
- } ,
139
- 3 => {
140
- InputDescriptors :: ReceivedHTLC
141
- } ,
142
- 4 => {
143
- InputDescriptors :: RevokedOutput
144
- }
145
- _ => return Err ( DecodeError :: InvalidValue ) ,
146
- } ;
147
- Ok ( input_descriptor)
148
- }
149
- }
150
97
151
98
macro_rules! subtract_high_prio_fee {
152
99
( $logger: ident, $fee_estimator: expr, $value: expr, $predicted_weight: expr, $used_feerate: expr) => {
@@ -416,36 +363,6 @@ impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
416
363
}
417
364
}
418
365
419
- pub ( super ) fn get_witnesses_weight ( inputs : & [ InputDescriptors ] ) -> usize {
420
- let mut tx_weight = 2 ; // count segwit flags
421
- for inp in inputs {
422
- // We use expected weight (and not actual) as signatures and time lock delays may vary
423
- tx_weight += match inp {
424
- // number_of_witness_elements + sig_length + revocation_sig + pubkey_length + revocationpubkey + witness_script_length + witness_script
425
- & InputDescriptors :: RevokedOfferedHTLC => {
426
- 1 + 1 + 73 + 1 + 33 + 1 + 133
427
- } ,
428
- // number_of_witness_elements + sig_length + revocation_sig + pubkey_length + revocationpubkey + witness_script_length + witness_script
429
- & InputDescriptors :: RevokedReceivedHTLC => {
430
- 1 + 1 + 73 + 1 + 33 + 1 + 139
431
- } ,
432
- // number_of_witness_elements + sig_length + remotehtlc_sig + preimage_length + preimage + witness_script_length + witness_script
433
- & InputDescriptors :: OfferedHTLC => {
434
- 1 + 1 + 73 + 1 + 32 + 1 + 133
435
- } ,
436
- // number_of_witness_elements + sig_length + revocation_sig + pubkey_length + revocationpubkey + witness_script_length + witness_script
437
- & InputDescriptors :: ReceivedHTLC => {
438
- 1 + 1 + 73 + 1 + 1 + 1 + 139
439
- } ,
440
- // number_of_witness_elements + sig_length + revocation_sig + true_length + op_true + witness_script_length + witness_script
441
- & InputDescriptors :: RevokedOutput => {
442
- 1 + 1 + 73 + 1 + 1 + 1 + 77
443
- } ,
444
- } ;
445
- }
446
- tx_weight
447
- }
448
-
449
366
/// In LN, output claimed are time-sensitive, which means we have to spend them before reaching some timelock expiration. At in-channel
450
367
/// 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
451
368
/// height than once reached we should generate a new bumped "version" of the claim tx to be sure than we safely claim outputs before
@@ -535,11 +452,11 @@ impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
535
452
for per_outp_material in cached_claim_datas. per_input_material . values ( ) {
536
453
match per_outp_material {
537
454
& InputMaterial :: Revoked { ref input_descriptor, ref amount, .. } => {
538
- inputs_witnesses_weight += Self :: get_witnesses_weight ( & [ * input_descriptor] ) ;
455
+ inputs_witnesses_weight += onchain_utils :: get_witnesses_weight ( & [ * input_descriptor] ) ;
539
456
amt += * amount;
540
457
} ,
541
458
& InputMaterial :: RemoteHTLC { ref preimage, ref htlc, .. } => {
542
- inputs_witnesses_weight += Self :: get_witnesses_weight ( if preimage. is_some ( ) { & [ InputDescriptors :: OfferedHTLC ] } else { & [ InputDescriptors :: ReceivedHTLC ] } ) ;
459
+ inputs_witnesses_weight += onchain_utils :: get_witnesses_weight ( if preimage. is_some ( ) { & [ InputDescriptors :: OfferedHTLC ] } else { & [ InputDescriptors :: ReceivedHTLC ] } ) ;
543
460
amt += htlc. amount_msat / 1000 ;
544
461
} ,
545
462
& InputMaterial :: LocalHTLC { .. } => {
0 commit comments