1
- #![ cfg_attr( rustfmt, rustfmt_skip) ]
2
-
3
1
// This file is Copyright its original authors, visible in version control
4
2
// history.
5
3
//
15
13
//! building, tracking, bumping and notifications functions.
16
14
17
15
use bitcoin:: amount:: Amount ;
16
+ use bitcoin:: hash_types:: { BlockHash , Txid } ;
17
+ use bitcoin:: hashes:: sha256:: Hash as Sha256 ;
18
+ use bitcoin:: hashes:: { Hash , HashEngine } ;
18
19
use bitcoin:: locktime:: absolute:: LockTime ;
19
- use bitcoin:: transaction:: Transaction ;
20
- use bitcoin:: transaction:: OutPoint as BitcoinOutPoint ;
21
20
use bitcoin:: script:: { Script , ScriptBuf } ;
22
- use bitcoin:: hashes:: { Hash , HashEngine } ;
23
- use bitcoin:: hashes:: sha256:: Hash as Sha256 ;
24
- use bitcoin:: hash_types:: { Txid , BlockHash } ;
25
- use bitcoin:: secp256k1:: { Secp256k1 , ecdsa:: Signature } ;
26
21
use bitcoin:: secp256k1;
22
+ use bitcoin:: secp256k1:: { ecdsa:: Signature , Secp256k1 } ;
23
+ use bitcoin:: transaction:: OutPoint as BitcoinOutPoint ;
24
+ use bitcoin:: transaction:: Transaction ;
27
25
28
- use crate :: chain:: chaininterface:: { ConfirmationTarget , compute_feerate_sat_per_1000_weight} ;
29
- use crate :: sign:: { EntropySource , HTLCDescriptor , SignerProvider , ecdsa:: EcdsaChannelSigner } ;
30
- use crate :: ln:: msgs:: DecodeError ;
31
- use crate :: ln:: chan_utils:: { self , ChannelTransactionParameters , HTLCOutputInCommitment , HolderCommitmentTransaction } ;
32
- use crate :: chain:: ClaimId ;
33
- use crate :: chain:: chaininterface:: { FeeEstimator , BroadcasterInterface , LowerBoundedFeeEstimator } ;
26
+ use crate :: chain:: chaininterface:: { compute_feerate_sat_per_1000_weight, ConfirmationTarget } ;
27
+ use crate :: chain:: chaininterface:: { BroadcasterInterface , FeeEstimator , LowerBoundedFeeEstimator } ;
34
28
use crate :: chain:: channelmonitor:: ANTI_REORG_DELAY ;
35
29
use crate :: chain:: package:: { PackageSolvingData , PackageTemplate } ;
36
30
use crate :: chain:: transaction:: MaybeSignedTransaction ;
31
+ use crate :: chain:: ClaimId ;
32
+ use crate :: ln:: chan_utils:: {
33
+ self , ChannelTransactionParameters , HTLCOutputInCommitment , HolderCommitmentTransaction ,
34
+ } ;
35
+ use crate :: ln:: msgs:: DecodeError ;
36
+ use crate :: sign:: { ecdsa:: EcdsaChannelSigner , EntropySource , HTLCDescriptor , SignerProvider } ;
37
37
use crate :: util:: logger:: Logger ;
38
- use crate :: util:: ser:: { Readable , ReadableArgs , MaybeReadable , UpgradableRequired , Writer , Writeable } ;
38
+ use crate :: util:: ser:: {
39
+ MaybeReadable , Readable , ReadableArgs , UpgradableRequired , Writeable , Writer ,
40
+ } ;
39
41
40
42
use crate :: io;
41
43
use crate :: prelude:: * ;
42
44
use alloc:: collections:: BTreeMap ;
43
45
use core:: cmp;
44
- use core:: ops:: Deref ;
45
46
use core:: mem:: replace;
46
47
use core:: mem:: swap;
48
+ use core:: ops:: Deref ;
47
49
48
- const MAX_ALLOC_SIZE : usize = 64 * 1024 ;
50
+ const MAX_ALLOC_SIZE : usize = 64 * 1024 ;
49
51
50
52
/// An entry for an [`OnchainEvent`], stating the block height when the event was observed and the
51
53
/// transaction causing it.
@@ -77,18 +79,14 @@ enum OnchainEvent {
77
79
/// as the request. This claim can either be ours or from the counterparty. Once the claiming
78
80
/// transaction has met [`ANTI_REORG_DELAY`] confirmations, we consider it final and remove the
79
81
/// pending request.
80
- Claim {
81
- claim_id : ClaimId ,
82
- } ,
82
+ Claim { claim_id : ClaimId } ,
83
83
/// The counterparty has claimed an outpoint from one of our pending requests through a
84
84
/// different transaction than ours. If our transaction was attempting to claim multiple
85
85
/// outputs, we need to drop the outpoint claimed by the counterparty and regenerate a new claim
86
86
/// transaction for ourselves. We keep tracking, separately, the outpoint claimed by the
87
87
/// counterparty up to [`ANTI_REORG_DELAY`] confirmations to ensure we attempt to re-claim it
88
88
/// if the counterparty's claim is reorged from the chain.
89
- ContentiousOutpoint {
90
- package : PackageTemplate ,
91
- }
89
+ ContentiousOutpoint { package : PackageTemplate } ,
92
90
}
93
91
94
92
impl Writeable for OnchainEventEntry {
@@ -104,6 +102,7 @@ impl Writeable for OnchainEventEntry {
104
102
}
105
103
106
104
impl MaybeReadable for OnchainEventEntry {
105
+ #[ rustfmt:: skip]
107
106
fn read < R : io:: Read > ( reader : & mut R ) -> Result < Option < Self > , DecodeError > {
108
107
let mut txid = Txid :: all_zeros ( ) ;
109
108
let mut height = 0 ;
@@ -129,6 +128,7 @@ impl_writeable_tlv_based_enum_upgradable!(OnchainEvent,
129
128
) ;
130
129
131
130
impl Readable for Option < Vec < Option < ( usize , Signature ) > > > {
131
+ #[ rustfmt:: skip]
132
132
fn read < R : io:: Read > ( reader : & mut R ) -> Result < Self , DecodeError > {
133
133
match Readable :: read ( reader) ? {
134
134
0u8 => Ok ( None ) ,
@@ -221,8 +221,8 @@ pub(crate) enum FeerateStrategy {
221
221
/// do RBF bumping if possible.
222
222
#[ derive( Clone ) ]
223
223
pub struct OnchainTxHandler < ChannelSigner : EcdsaChannelSigner > {
224
- channel_value_satoshis : u64 , // Deprecated as of 0.2.
225
- channel_keys_id : [ u8 ; 32 ] , // Deprecated as of 0.2.
224
+ channel_value_satoshis : u64 , // Deprecated as of 0.2.
225
+ channel_keys_id : [ u8 ; 32 ] , // Deprecated as of 0.2.
226
226
destination_script : ScriptBuf , // Deprecated as of 0.2.
227
227
holder_commitment : HolderCommitmentTransaction ,
228
228
prev_holder_commitment : Option < HolderCommitmentTransaction > ,
@@ -277,6 +277,7 @@ pub struct OnchainTxHandler<ChannelSigner: EcdsaChannelSigner> {
277
277
}
278
278
279
279
impl < ChannelSigner : EcdsaChannelSigner > PartialEq for OnchainTxHandler < ChannelSigner > {
280
+ #[ rustfmt:: skip]
280
281
fn eq ( & self , other : & Self ) -> bool {
281
282
// `signer`, `secp_ctx`, and `pending_claim_events` are excluded on purpose.
282
283
self . channel_value_satoshis == other. channel_value_satoshis &&
@@ -296,6 +297,7 @@ const SERIALIZATION_VERSION: u8 = 1;
296
297
const MIN_SERIALIZATION_VERSION : u8 = 1 ;
297
298
298
299
impl < ChannelSigner : EcdsaChannelSigner > OnchainTxHandler < ChannelSigner > {
300
+ #[ rustfmt:: skip]
299
301
pub ( crate ) fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , io:: Error > {
300
302
write_ver_prefix ! ( writer, SERIALIZATION_VERSION , MIN_SERIALIZATION_VERSION ) ;
301
303
@@ -343,7 +345,10 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
343
345
}
344
346
}
345
347
346
- impl < ' a , ' b , ES : EntropySource , SP : SignerProvider > ReadableArgs < ( & ' a ES , & ' b SP , u64 , [ u8 ; 32 ] ) > for OnchainTxHandler < SP :: EcdsaSigner > {
348
+ impl < ' a , ' b , ES : EntropySource , SP : SignerProvider > ReadableArgs < ( & ' a ES , & ' b SP , u64 , [ u8 ; 32 ] ) >
349
+ for OnchainTxHandler < SP :: EcdsaSigner >
350
+ {
351
+ #[ rustfmt:: skip]
347
352
fn read < R : io:: Read > ( reader : & mut R , args : ( & ' a ES , & ' b SP , u64 , [ u8 ; 32 ] ) ) -> Result < Self , DecodeError > {
348
353
let entropy_source = args. 0 ;
349
354
let signer_provider = args. 1 ;
@@ -438,7 +443,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
438
443
pub ( crate ) fn new (
439
444
channel_value_satoshis : u64 , channel_keys_id : [ u8 ; 32 ] , destination_script : ScriptBuf ,
440
445
signer : ChannelSigner , channel_parameters : ChannelTransactionParameters ,
441
- holder_commitment : HolderCommitmentTransaction , secp_ctx : Secp256k1 < secp256k1:: All >
446
+ holder_commitment : HolderCommitmentTransaction , secp_ctx : Secp256k1 < secp256k1:: All > ,
442
447
) -> Self {
443
448
OnchainTxHandler {
444
449
channel_value_satoshis,
@@ -476,6 +481,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
476
481
/// feerate changes between blocks, and ensuring reliability if broadcasting fails. We recommend
477
482
/// invoking this every 30 seconds, or lower if running in an environment with spotty
478
483
/// connections, like on mobile.
484
+ #[ rustfmt:: skip]
479
485
pub ( super ) fn rebroadcast_pending_claims < B : Deref , F : Deref , L : Logger > (
480
486
& mut self , current_height : u32 , feerate_strategy : FeerateStrategy , broadcaster : & B ,
481
487
conf_target : ConfirmationTarget , destination_script : & Script ,
@@ -532,8 +538,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
532
538
533
539
/// Returns true if we are currently tracking any pending claim requests that are not fully
534
540
/// confirmed yet.
535
- pub ( super ) fn has_pending_claims ( & self ) -> bool
536
- {
541
+ pub ( super ) fn has_pending_claims ( & self ) -> bool {
537
542
self . pending_claim_requests . len ( ) != 0
538
543
}
539
544
@@ -545,6 +550,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
545
550
///
546
551
/// Panics if there are signing errors, because signing operations in reaction to on-chain
547
552
/// events are not expected to fail, and if they do, we may lose funds.
553
+ #[ rustfmt:: skip]
548
554
fn generate_claim < F : Deref , L : Logger > (
549
555
& mut self , cur_height : u32 , cached_request : & PackageTemplate ,
550
556
feerate_strategy : & FeerateStrategy , conf_target : ConfirmationTarget ,
@@ -713,6 +719,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
713
719
None
714
720
}
715
721
722
+ #[ rustfmt:: skip]
716
723
pub fn abandon_claim ( & mut self , outpoint : & BitcoinOutPoint ) {
717
724
let claim_id = self . claimable_outpoints . get ( outpoint) . map ( |( claim_id, _) | * claim_id)
718
725
. or_else ( || {
@@ -741,6 +748,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
741
748
/// `conf_height` represents the height at which the request was generated. This
742
749
/// does not need to equal the current blockchain tip height, which should be provided via
743
750
/// `cur_height`, however it must never be higher than `cur_height`.
751
+ #[ rustfmt:: skip]
744
752
pub ( super ) fn update_claims_view_from_requests < B : Deref , F : Deref , L : Logger > (
745
753
& mut self , mut requests : Vec < PackageTemplate > , conf_height : u32 , cur_height : u32 ,
746
754
broadcaster : & B , conf_target : ConfirmationTarget , destination_script : & Script ,
@@ -895,6 +903,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
895
903
/// `conf_height` represents the height at which the transactions in `txn_matched` were
896
904
/// confirmed. This does not need to equal the current blockchain tip height, which should be
897
905
/// provided via `cur_height`, however it must never be higher than `cur_height`.
906
+ #[ rustfmt:: skip]
898
907
pub ( super ) fn update_claims_view_from_matched_txn < B : Deref , F : Deref , L : Logger > (
899
908
& mut self , txn_matched : & [ & Transaction ] , conf_height : u32 , conf_hash : BlockHash ,
900
909
cur_height : u32 , broadcaster : & B , conf_target : ConfirmationTarget ,
@@ -1081,6 +1090,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
1081
1090
}
1082
1091
}
1083
1092
1093
+ #[ rustfmt:: skip]
1084
1094
pub ( super ) fn transaction_unconfirmed < B : Deref , F : Deref , L : Logger > (
1085
1095
& mut self ,
1086
1096
txid : & Txid ,
@@ -1108,6 +1118,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
1108
1118
}
1109
1119
}
1110
1120
1121
+ #[ rustfmt:: skip]
1111
1122
pub ( super ) fn block_disconnected < B : Deref , F : Deref , L : Logger > (
1112
1123
& mut self , height : u32 , broadcaster : B , conf_target : ConfirmationTarget ,
1113
1124
destination_script : & Script , fee_estimator : & LowerBoundedFeeEstimator < F > , logger : & L ,
@@ -1190,6 +1201,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
1190
1201
self . claimable_outpoints . get ( outpoint) . is_some ( )
1191
1202
}
1192
1203
1204
+ #[ rustfmt:: skip]
1193
1205
pub ( crate ) fn get_relevant_txids ( & self ) -> Vec < ( Txid , u32 , Option < BlockHash > ) > {
1194
1206
let mut txids: Vec < ( Txid , u32 , Option < BlockHash > ) > = self . onchain_events_awaiting_threshold_conf
1195
1207
. iter ( )
@@ -1243,6 +1255,7 @@ mod tests {
1243
1255
// immediately while claims with locktime greater than the current height are only broadcast
1244
1256
// once the locktime is reached.
1245
1257
#[ test]
1258
+ #[ rustfmt:: skip]
1246
1259
fn test_broadcast_height ( ) {
1247
1260
let secp_ctx = Secp256k1 :: new ( ) ;
1248
1261
let signer = InMemorySigner :: new (
0 commit comments