1- #![ cfg_attr( rustfmt,  rustfmt_skip) ]  
2- 
31// This file is Copyright its original authors, visible in version control 
42// history. 
53// 
1513//! building, tracking, bumping and notifications functions. 
1614
1715use  bitcoin:: amount:: Amount ; 
16+ use  bitcoin:: hash_types:: { BlockHash ,  Txid } ; 
17+ use  bitcoin:: hashes:: sha256:: Hash  as  Sha256 ; 
18+ use  bitcoin:: hashes:: { Hash ,  HashEngine } ; 
1819use  bitcoin:: locktime:: absolute:: LockTime ; 
19- use  bitcoin:: transaction:: Transaction ; 
20- use  bitcoin:: transaction:: OutPoint  as  BitcoinOutPoint ; 
2120use  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 } ; 
2621use  bitcoin:: secp256k1; 
22+ use  bitcoin:: secp256k1:: { ecdsa:: Signature ,  Secp256k1 } ; 
23+ use  bitcoin:: transaction:: OutPoint  as  BitcoinOutPoint ; 
24+ use  bitcoin:: transaction:: Transaction ; 
2725
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 } ; 
3428use  crate :: chain:: channelmonitor:: ANTI_REORG_DELAY ; 
3529use  crate :: chain:: package:: { PackageSolvingData ,  PackageTemplate } ; 
3630use  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 } ; 
3737use  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+ } ; 
3941
4042use  crate :: io; 
4143use  crate :: prelude:: * ; 
4244use  alloc:: collections:: BTreeMap ; 
4345use  core:: cmp; 
44- use  core:: ops:: Deref ; 
4546use  core:: mem:: replace; 
4647use  core:: mem:: swap; 
48+ use  core:: ops:: Deref ; 
4749
48- const  MAX_ALLOC_SIZE :  usize  = 64 * 1024 ; 
50+ const  MAX_ALLOC_SIZE :  usize  = 64   *   1024 ; 
4951
5052/// An entry for an [`OnchainEvent`], stating the block height when the event was observed and the 
5153/// transaction causing it. 
@@ -77,18 +79,14 @@ enum OnchainEvent {
7779 	/// as the request. This claim can either be ours or from the counterparty. Once the claiming 
7880 	/// transaction has met [`ANTI_REORG_DELAY`] confirmations, we consider it final and remove the 
7981 	/// pending request. 
80-  	Claim  { 
81- 		claim_id :  ClaimId , 
82- 	} , 
82+  	Claim  {  claim_id :  ClaimId  } , 
8383	/// The counterparty has claimed an outpoint from one of our pending requests through a 
8484 	/// different transaction than ours. If our transaction was attempting to claim multiple 
8585 	/// outputs, we need to drop the outpoint claimed by the counterparty and regenerate a new claim 
8686 	/// transaction for ourselves. We keep tracking, separately, the outpoint claimed by the 
8787 	/// counterparty up to [`ANTI_REORG_DELAY`] confirmations to ensure we attempt to re-claim it 
8888 	/// if the counterparty's claim is reorged from the chain. 
89-  	ContentiousOutpoint  { 
90- 		package :  PackageTemplate , 
91- 	} 
89+  	ContentiousOutpoint  {  package :  PackageTemplate  } , 
9290} 
9391
9492impl  Writeable  for  OnchainEventEntry  { 
@@ -104,6 +102,7 @@ impl Writeable for OnchainEventEntry {
104102} 
105103
106104impl  MaybeReadable  for  OnchainEventEntry  { 
105+ 	#[ rustfmt:: skip]  
107106	fn  read < R :  io:: Read > ( reader :  & mut  R )  -> Result < Option < Self > ,  DecodeError >  { 
108107		let  mut  txid = Txid :: all_zeros ( ) ; 
109108		let  mut  height = 0 ; 
@@ -129,6 +128,7 @@ impl_writeable_tlv_based_enum_upgradable!(OnchainEvent,
129128) ; 
130129
131130impl  Readable  for  Option < Vec < Option < ( usize ,  Signature ) > > >  { 
131+ 	#[ rustfmt:: skip]  
132132	fn  read < R :  io:: Read > ( reader :  & mut  R )  -> Result < Self ,  DecodeError >  { 
133133		match  Readable :: read ( reader) ? { 
134134			0u8  => Ok ( None ) , 
@@ -221,8 +221,8 @@ pub(crate) enum FeerateStrategy {
221221/// do RBF bumping if possible. 
222222#[ derive( Clone ) ]  
223223pub  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. 
226226	destination_script :  ScriptBuf ,  // Deprecated as of 0.2. 
227227	holder_commitment :  HolderCommitmentTransaction , 
228228	prev_holder_commitment :  Option < HolderCommitmentTransaction > , 
@@ -277,6 +277,7 @@ pub struct OnchainTxHandler<ChannelSigner: EcdsaChannelSigner> {
277277} 
278278
279279impl < ChannelSigner :  EcdsaChannelSigner >  PartialEq  for  OnchainTxHandler < ChannelSigner >  { 
280+ 	#[ rustfmt:: skip]  
280281	fn  eq ( & self ,  other :  & Self )  -> bool  { 
281282		// `signer`, `secp_ctx`, and `pending_claim_events` are excluded on purpose. 
282283		self . channel_value_satoshis  == other. channel_value_satoshis  &&
@@ -296,6 +297,7 @@ const SERIALIZATION_VERSION: u8 = 1;
296297const  MIN_SERIALIZATION_VERSION :  u8  = 1 ; 
297298
298299impl < ChannelSigner :  EcdsaChannelSigner >  OnchainTxHandler < ChannelSigner >  { 
300+ 	#[ rustfmt:: skip]  
299301	pub ( crate )  fn  write < W :  Writer > ( & self ,  writer :  & mut  W )  -> Result < ( ) ,  io:: Error >  { 
300302		write_ver_prefix ! ( writer,  SERIALIZATION_VERSION ,  MIN_SERIALIZATION_VERSION ) ; 
301303
@@ -343,7 +345,10 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
343345	} 
344346} 
345347
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]  
347352	fn  read < R :  io:: Read > ( reader :  & mut  R ,  args :  ( & ' a  ES ,  & ' b  SP ,  u64 ,  [ u8 ;  32 ] ) )  -> Result < Self ,  DecodeError >  { 
348353		let  entropy_source = args. 0 ; 
349354		let  signer_provider = args. 1 ; 
@@ -438,7 +443,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
438443	pub ( crate )  fn  new ( 
439444		channel_value_satoshis :  u64 ,  channel_keys_id :  [ u8 ;  32 ] ,  destination_script :  ScriptBuf , 
440445		signer :  ChannelSigner ,  channel_parameters :  ChannelTransactionParameters , 
441- 		holder_commitment :  HolderCommitmentTransaction ,  secp_ctx :  Secp256k1 < secp256k1:: All > 
446+ 		holder_commitment :  HolderCommitmentTransaction ,  secp_ctx :  Secp256k1 < secp256k1:: All > , 
442447	)  -> Self  { 
443448		OnchainTxHandler  { 
444449			channel_value_satoshis, 
@@ -476,6 +481,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
476481 	/// feerate changes between blocks, and ensuring reliability if broadcasting fails. We recommend 
477482 	/// invoking this every 30 seconds, or lower if running in an environment with spotty 
478483 	/// connections, like on mobile. 
484+  	#[ rustfmt:: skip]  
479485	pub ( super )  fn  rebroadcast_pending_claims < B :  Deref ,  F :  Deref ,  L :  Logger > ( 
480486		& mut  self ,  current_height :  u32 ,  feerate_strategy :  FeerateStrategy ,  broadcaster :  & B , 
481487		conf_target :  ConfirmationTarget ,  destination_script :  & Script , 
@@ -532,8 +538,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
532538
533539	/// Returns true if we are currently tracking any pending claim requests that are not fully 
534540 	/// confirmed yet. 
535-  	pub ( super )  fn  has_pending_claims ( & self )  -> bool 
536- 	{ 
541+  	pub ( super )  fn  has_pending_claims ( & self )  -> bool  { 
537542		self . pending_claim_requests . len ( )  != 0 
538543	} 
539544
@@ -545,6 +550,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
545550 	/// 
546551 	/// Panics if there are signing errors, because signing operations in reaction to on-chain 
547552 	/// events are not expected to fail, and if they do, we may lose funds. 
553+  	#[ rustfmt:: skip]  
548554	fn  generate_claim < F :  Deref ,  L :  Logger > ( 
549555		& mut  self ,  cur_height :  u32 ,  cached_request :  & PackageTemplate , 
550556		feerate_strategy :  & FeerateStrategy ,  conf_target :  ConfirmationTarget , 
@@ -713,6 +719,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
713719		None 
714720	} 
715721
722+ 	#[ rustfmt:: skip]  
716723	pub  fn  abandon_claim ( & mut  self ,  outpoint :  & BitcoinOutPoint )  { 
717724		let  claim_id = self . claimable_outpoints . get ( outpoint) . map ( |( claim_id,  _) | * claim_id) 
718725			. or_else ( || { 
@@ -741,6 +748,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
741748 	/// `conf_height` represents the height at which the request was generated. This 
742749 	/// does not need to equal the current blockchain tip height, which should be provided via 
743750 	/// `cur_height`, however it must never be higher than `cur_height`. 
751+  	#[ rustfmt:: skip]  
744752	pub ( super )  fn  update_claims_view_from_requests < B :  Deref ,  F :  Deref ,  L :  Logger > ( 
745753		& mut  self ,  mut  requests :  Vec < PackageTemplate > ,  conf_height :  u32 ,  cur_height :  u32 , 
746754		broadcaster :  & B ,  conf_target :  ConfirmationTarget ,  destination_script :  & Script , 
@@ -895,6 +903,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
895903 	/// `conf_height` represents the height at which the transactions in `txn_matched` were 
896904 	/// confirmed. This does not need to equal the current blockchain tip height, which should be 
897905 	/// provided via `cur_height`, however it must never be higher than `cur_height`. 
906+  	#[ rustfmt:: skip]  
898907	pub ( super )  fn  update_claims_view_from_matched_txn < B :  Deref ,  F :  Deref ,  L :  Logger > ( 
899908		& mut  self ,  txn_matched :  & [ & Transaction ] ,  conf_height :  u32 ,  conf_hash :  BlockHash , 
900909		cur_height :  u32 ,  broadcaster :  & B ,  conf_target :  ConfirmationTarget , 
@@ -933,6 +942,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
933942							} 
934943						} 
935944
945+ 						#[ rustfmt:: skip]  
936946						macro_rules!  clean_claim_request_after_safety_delay { 
937947							( )  => { 
938948								let  entry = OnchainEventEntry  { 
@@ -1081,6 +1091,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
10811091		} 
10821092	} 
10831093
1094+ 	#[ rustfmt:: skip]  
10841095	pub ( super )  fn  transaction_unconfirmed < B :  Deref ,  F :  Deref ,  L :  Logger > ( 
10851096		& mut  self , 
10861097		txid :  & Txid , 
@@ -1108,6 +1119,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
11081119		} 
11091120	} 
11101121
1122+ 	#[ rustfmt:: skip]  
11111123	pub ( super )  fn  block_disconnected < B :  Deref ,  F :  Deref ,  L :  Logger > ( 
11121124		& mut  self ,  height :  u32 ,  broadcaster :  B ,  conf_target :  ConfirmationTarget , 
11131125		destination_script :  & Script ,  fee_estimator :  & LowerBoundedFeeEstimator < F > ,  logger :  & L , 
@@ -1190,6 +1202,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
11901202		self . claimable_outpoints . get ( outpoint) . is_some ( ) 
11911203	} 
11921204
1205+ 	#[ rustfmt:: skip]  
11931206	pub ( crate )  fn  get_relevant_txids ( & self )  -> Vec < ( Txid ,  u32 ,  Option < BlockHash > ) >  { 
11941207		let  mut  txids:  Vec < ( Txid ,  u32 ,  Option < BlockHash > ) >  = self . onchain_events_awaiting_threshold_conf 
11951208			. iter ( ) 
@@ -1243,6 +1256,7 @@ mod tests {
12431256	// immediately while claims with locktime greater than the current height are only broadcast 
12441257	// once the locktime is reached. 
12451258	#[ test]  
1259+ 	#[ rustfmt:: skip]  
12461260	fn  test_broadcast_height ( )  { 
12471261		let  secp_ctx = Secp256k1 :: new ( ) ; 
12481262		let  signer = InMemorySigner :: new ( 
0 commit comments