@@ -23,7 +23,9 @@ use bitcoin::transaction::OutPoint as BitcoinOutPoint;
2323use bitcoin:: transaction:: Transaction ;
2424
2525use crate :: chain:: chaininterface:: ConfirmationTarget ;
26- use crate :: chain:: chaininterface:: { BroadcasterInterface , FeeEstimator , LowerBoundedFeeEstimator } ;
26+ use crate :: chain:: chaininterface:: {
27+ BroadcasterInterface , FeeEstimator , LowerBoundedFeeEstimator , TransactionType ,
28+ } ;
2729use crate :: chain:: channelmonitor:: ANTI_REORG_DELAY ;
2830use crate :: chain:: package:: { PackageSolvingData , PackageTemplate } ;
2931use crate :: chain:: transaction:: MaybeSignedTransaction ;
@@ -33,6 +35,7 @@ use crate::ln::chan_utils::{
3335 HTLCOutputInCommitment , HolderCommitmentTransaction ,
3436} ;
3537use crate :: ln:: msgs:: DecodeError ;
38+ use crate :: ln:: types:: ChannelId ;
3639use crate :: sign:: { ecdsa:: EcdsaChannelSigner , EntropySource , HTLCDescriptor , SignerProvider } ;
3740use crate :: util:: logger:: Logger ;
3841use crate :: util:: ser:: {
@@ -221,6 +224,7 @@ pub(crate) enum FeerateStrategy {
221224/// do RBF bumping if possible.
222225#[ derive( Clone ) ]
223226pub struct OnchainTxHandler < ChannelSigner : EcdsaChannelSigner > {
227+ channel_id : ChannelId ,
224228 channel_value_satoshis : u64 , // Deprecated as of 0.2.
225229 channel_keys_id : [ u8 ; 32 ] , // Deprecated as of 0.2.
226230 destination_script : ScriptBuf , // Deprecated as of 0.2.
@@ -283,7 +287,8 @@ impl<ChannelSigner: EcdsaChannelSigner> PartialEq for OnchainTxHandler<ChannelSi
283287 #[ rustfmt:: skip]
284288 fn eq ( & self , other : & Self ) -> bool {
285289 // `signer`, `secp_ctx`, and `pending_claim_events` are excluded on purpose.
286- self . channel_value_satoshis == other. channel_value_satoshis &&
290+ self . channel_id == other. channel_id &&
291+ self . channel_value_satoshis == other. channel_value_satoshis &&
287292 self . channel_keys_id == other. channel_keys_id &&
288293 self . destination_script == other. destination_script &&
289294 self . holder_commitment == other. holder_commitment &&
@@ -346,6 +351,14 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
346351 write_tlv_fields ! ( writer, { } ) ;
347352 Ok ( ( ) )
348353 }
354+
355+ // `ChannelMonitor`s already track the `channel_id`, however, due to the derserialization order
356+ // there we can't make use of `ReadableArgs` to hand it into `OnchainTxHandler`'s
357+ // deserialization logic directly. Instead we opt to initialize it with 0s and override it
358+ // after reading the respective field via this method.
359+ pub ( crate ) fn set_channel_id ( & mut self , channel_id : ChannelId ) {
360+ self . channel_id = channel_id;
361+ }
349362}
350363
351364impl < ' a , ' b , ES : EntropySource , SP : SignerProvider > ReadableArgs < ( & ' a ES , & ' b SP , u64 , [ u8 ; 32 ] ) >
@@ -367,7 +380,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
367380 let prev_holder_commitment = Readable :: read ( reader) ?;
368381 let _prev_holder_htlc_sigs: Option < Vec < Option < ( usize , Signature ) > > > = Readable :: read ( reader) ?;
369382
370- let channel_parameters = ReadableArgs :: < Option < u64 > > :: read ( reader, Some ( channel_value_satoshis) ) ?;
383+ let channel_parameters: ChannelTransactionParameters = ReadableArgs :: < Option < u64 > > :: read ( reader, Some ( channel_value_satoshis) ) ?;
371384
372385 // Read the serialized signer bytes, but don't deserialize them, as we'll obtain our signer
373386 // by re-deriving the private key material.
@@ -421,10 +434,17 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
421434
422435 read_tlv_fields ! ( reader, { } ) ;
423436
437+ // `ChannelMonitor`s already track the `channel_id`, however, due to the derserialization
438+ // order there we can't make use of `ReadableArgs` to hand it in directly. Instead we opt
439+ // to initialize it with 0s and override it after reading the respective field via
440+ // `OnchainTxHandler::set_channel_id`.
441+ let channel_id = ChannelId ( [ 0u8 ; 32 ] ) ;
442+
424443 let mut secp_ctx = Secp256k1 :: new ( ) ;
425444 secp_ctx. seeded_randomize ( & entropy_source. get_secure_random_bytes ( ) ) ;
426445
427446 Ok ( OnchainTxHandler {
447+ channel_id,
428448 channel_value_satoshis,
429449 channel_keys_id,
430450 destination_script,
@@ -444,11 +464,13 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
444464
445465impl < ChannelSigner : EcdsaChannelSigner > OnchainTxHandler < ChannelSigner > {
446466 pub ( crate ) fn new (
447- channel_value_satoshis : u64 , channel_keys_id : [ u8 ; 32 ] , destination_script : ScriptBuf ,
448- signer : ChannelSigner , channel_parameters : ChannelTransactionParameters ,
467+ channel_id : ChannelId , channel_value_satoshis : u64 , channel_keys_id : [ u8 ; 32 ] ,
468+ destination_script : ScriptBuf , signer : ChannelSigner ,
469+ channel_parameters : ChannelTransactionParameters ,
449470 holder_commitment : HolderCommitmentTransaction , secp_ctx : Secp256k1 < secp256k1:: All > ,
450471 ) -> Self {
451472 OnchainTxHandler {
473+ channel_id,
452474 channel_value_satoshis,
453475 channel_keys_id,
454476 destination_script,
@@ -516,7 +538,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
516538 if tx. is_fully_signed ( ) {
517539 let log_start = if feerate_was_bumped { "Broadcasting RBF-bumped" } else { "Rebroadcasting" } ;
518540 log_info ! ( logger, "{} onchain {}" , log_start, log_tx!( tx. 0 ) ) ;
519- broadcaster. broadcast_transactions ( & [ & tx. 0 ] ) ;
541+ broadcaster. broadcast_transactions ( & [ ( & tx. 0 , TransactionType :: Claim { channel_id : self . channel_id } ) ] ) ;
520542 } else {
521543 log_info ! ( logger, "Waiting for signature of unsigned onchain transaction {}" , tx. 0 . compute_txid( ) ) ;
522544 }
@@ -863,7 +885,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
863885 OnchainClaim :: Tx ( tx) => {
864886 if tx. is_fully_signed ( ) {
865887 log_info ! ( logger, "Broadcasting onchain {}" , log_tx!( tx. 0 ) ) ;
866- broadcaster. broadcast_transactions ( & [ & tx. 0 ] ) ;
888+ broadcaster. broadcast_transactions ( & [ ( & tx. 0 , TransactionType :: Claim { channel_id : self . channel_id } ) ] ) ;
867889 } else {
868890 log_info ! ( logger, "Waiting for signature of unsigned onchain transaction {}" , tx. 0 . compute_txid( ) ) ;
869891 }
@@ -1084,7 +1106,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
10841106 OnchainClaim :: Tx ( bump_tx) => {
10851107 if bump_tx. is_fully_signed ( ) {
10861108 log_info ! ( logger, "Broadcasting RBF-bumped onchain {}" , log_tx!( bump_tx. 0 ) ) ;
1087- broadcaster. broadcast_transactions ( & [ & bump_tx. 0 ] ) ;
1109+ broadcaster. broadcast_transactions ( & [ ( & bump_tx. 0 , TransactionType :: Claim { channel_id : self . channel_id } ) ] ) ;
10881110 } else {
10891111 log_info ! ( logger, "Waiting for signature of RBF-bumped unsigned onchain transaction {}" ,
10901112 bump_tx. 0 . compute_txid( ) ) ;
@@ -1187,7 +1209,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
11871209 OnchainClaim :: Tx ( bump_tx) => {
11881210 if bump_tx. is_fully_signed ( ) {
11891211 log_info ! ( logger, "Broadcasting onchain {}" , log_tx!( bump_tx. 0 ) ) ;
1190- broadcaster. broadcast_transactions ( & [ & bump_tx. 0 ] ) ;
1212+ broadcaster. broadcast_transactions ( & [ ( & bump_tx. 0 , TransactionType :: Claim { channel_id : self . channel_id } ) ] ) ;
11911213 } else {
11921214 log_info ! ( logger, "Waiting for signature of unsigned onchain transaction {}" , bump_tx. 0 . compute_txid( ) ) ;
11931215 }
@@ -1281,6 +1303,7 @@ mod tests {
12811303 } ;
12821304 use crate :: ln:: channel_keys:: { DelayedPaymentBasepoint , HtlcBasepoint , RevocationBasepoint } ;
12831305 use crate :: ln:: functional_test_utils:: create_dummy_block;
1306+ use crate :: ln:: types:: ChannelId ;
12841307 use crate :: sign:: { ChannelDerivationParameters , ChannelSigner , HTLCDescriptor , InMemorySigner } ;
12851308 use crate :: types:: payment:: { PaymentHash , PaymentPreimage } ;
12861309 use crate :: util:: test_utils:: { TestBroadcaster , TestFeeEstimator , TestLogger } ;
@@ -1365,6 +1388,7 @@ mod tests {
13651388 let holder_commit = HolderCommitmentTransaction :: dummy ( 1000000 , funding_outpoint, nondust_htlcs) ;
13661389 let destination_script = ScriptBuf :: new ( ) ;
13671390 let mut tx_handler = OnchainTxHandler :: new (
1391+ ChannelId :: from_bytes ( [ 0 ; 32 ] ) ,
13681392 1000000 ,
13691393 [ 0 ; 32 ] ,
13701394 destination_script. clone ( ) ,
0 commit comments