@@ -26,6 +26,8 @@ use ln::channelmonitor::{ANTI_REORG_DELAY, CLTV_SHARED_CLAIM_BUFFER, InputMateri
26
26
use ln:: channelmanager:: PaymentPreimage ;
27
27
use ln:: chan_utils;
28
28
use ln:: chan_utils:: { TxCreationKeys , HolderCommitmentTransaction } ;
29
+ use ln:: onchain_utils:: InputDescriptors ;
30
+ use ln:: onchain_utils;
29
31
use chain:: chaininterface:: { FeeEstimator , BroadcasterInterface , ConfirmationTarget , MIN_RELAY_FEE_SAT_PER_1000_WEIGHT } ;
30
32
use chain:: keysinterface:: ChannelKeys ;
31
33
use util:: logger:: Logger ;
@@ -101,62 +103,6 @@ impl Readable for ClaimTxBumpMaterial {
101
103
}
102
104
}
103
105
104
- #[ derive( PartialEq , Clone , Copy ) ]
105
- pub ( crate ) enum InputDescriptors {
106
- RevokedOfferedHTLC ,
107
- RevokedReceivedHTLC ,
108
- OfferedHTLC ,
109
- ReceivedHTLC ,
110
- RevokedOutput , // either a revoked to_holder output on commitment tx, a revoked HTLC-Timeout output or a revoked HTLC-Success output
111
- }
112
-
113
- impl Writeable for InputDescriptors {
114
- fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , :: std:: io:: Error > {
115
- match self {
116
- & InputDescriptors :: RevokedOfferedHTLC => {
117
- writer. write_all ( & [ 0 ; 1 ] ) ?;
118
- } ,
119
- & InputDescriptors :: RevokedReceivedHTLC => {
120
- writer. write_all ( & [ 1 ; 1 ] ) ?;
121
- } ,
122
- & InputDescriptors :: OfferedHTLC => {
123
- writer. write_all ( & [ 2 ; 1 ] ) ?;
124
- } ,
125
- & InputDescriptors :: ReceivedHTLC => {
126
- writer. write_all ( & [ 3 ; 1 ] ) ?;
127
- }
128
- & InputDescriptors :: RevokedOutput => {
129
- writer. write_all ( & [ 4 ; 1 ] ) ?;
130
- }
131
- }
132
- Ok ( ( ) )
133
- }
134
- }
135
-
136
- impl Readable for InputDescriptors {
137
- fn read < R : :: std:: io:: Read > ( reader : & mut R ) -> Result < Self , DecodeError > {
138
- let input_descriptor = match <u8 as Readable >:: read ( reader) ? {
139
- 0 => {
140
- InputDescriptors :: RevokedOfferedHTLC
141
- } ,
142
- 1 => {
143
- InputDescriptors :: RevokedReceivedHTLC
144
- } ,
145
- 2 => {
146
- InputDescriptors :: OfferedHTLC
147
- } ,
148
- 3 => {
149
- InputDescriptors :: ReceivedHTLC
150
- } ,
151
- 4 => {
152
- InputDescriptors :: RevokedOutput
153
- }
154
- _ => return Err ( DecodeError :: InvalidValue ) ,
155
- } ;
156
- Ok ( input_descriptor)
157
- }
158
- }
159
-
160
106
macro_rules! subtract_high_prio_fee {
161
107
( $logger: ident, $fee_estimator: expr, $value: expr, $predicted_weight: expr, $used_feerate: expr) => {
162
108
{
@@ -425,36 +371,6 @@ impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
425
371
}
426
372
}
427
373
428
- pub ( super ) fn get_witnesses_weight ( inputs : & [ InputDescriptors ] ) -> usize {
429
- let mut tx_weight = 2 ; // count segwit flags
430
- for inp in inputs {
431
- // We use expected weight (and not actual) as signatures and time lock delays may vary
432
- tx_weight += match inp {
433
- // number_of_witness_elements + sig_length + revocation_sig + pubkey_length + revocationpubkey + witness_script_length + witness_script
434
- & InputDescriptors :: RevokedOfferedHTLC => {
435
- 1 + 1 + 73 + 1 + 33 + 1 + 133
436
- } ,
437
- // number_of_witness_elements + sig_length + revocation_sig + pubkey_length + revocationpubkey + witness_script_length + witness_script
438
- & InputDescriptors :: RevokedReceivedHTLC => {
439
- 1 + 1 + 73 + 1 + 33 + 1 + 139
440
- } ,
441
- // number_of_witness_elements + sig_length + counterpartyhtlc_sig + preimage_length + preimage + witness_script_length + witness_script
442
- & InputDescriptors :: OfferedHTLC => {
443
- 1 + 1 + 73 + 1 + 32 + 1 + 133
444
- } ,
445
- // number_of_witness_elements + sig_length + revocation_sig + pubkey_length + revocationpubkey + witness_script_length + witness_script
446
- & InputDescriptors :: ReceivedHTLC => {
447
- 1 + 1 + 73 + 1 + 1 + 1 + 139
448
- } ,
449
- // number_of_witness_elements + sig_length + revocation_sig + true_length + op_true + witness_script_length + witness_script
450
- & InputDescriptors :: RevokedOutput => {
451
- 1 + 1 + 73 + 1 + 1 + 1 + 77
452
- } ,
453
- } ;
454
- }
455
- tx_weight
456
- }
457
-
458
374
/// In LN, output claimed are time-sensitive, which means we have to spend them before reaching some timelock expiration. At in-channel
459
375
/// 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
460
376
/// height than once reached we should generate a new bumped "version" of the claim tx to be sure than we safely claim outputs before
@@ -544,11 +460,11 @@ impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
544
460
for per_outp_material in cached_claim_datas. per_input_material . values ( ) {
545
461
match per_outp_material {
546
462
& InputMaterial :: Revoked { ref input_descriptor, ref amount, .. } => {
547
- inputs_witnesses_weight += Self :: get_witnesses_weight ( & [ * input_descriptor] ) ;
463
+ inputs_witnesses_weight += onchain_utils :: get_witnesses_weight ( & [ * input_descriptor] ) ;
548
464
amt += * amount;
549
465
} ,
550
466
& InputMaterial :: CounterpartyHTLC { ref preimage, ref htlc, .. } => {
551
- inputs_witnesses_weight += Self :: get_witnesses_weight ( if preimage. is_some ( ) { & [ InputDescriptors :: OfferedHTLC ] } else { & [ InputDescriptors :: ReceivedHTLC ] } ) ;
467
+ inputs_witnesses_weight += onchain_utils :: get_witnesses_weight ( if preimage. is_some ( ) { & [ InputDescriptors :: OfferedHTLC ] } else { & [ InputDescriptors :: ReceivedHTLC ] } ) ;
552
468
amt += htlc. amount_msat / 1000 ;
553
469
} ,
554
470
& InputMaterial :: HolderHTLC { .. } => {
0 commit comments