@@ -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:: {
@@ -220,6 +223,7 @@ pub(crate) enum FeerateStrategy {
220223/// do RBF bumping if possible.
221224#[ derive( Clone ) ]
222225pub struct OnchainTxHandler < ChannelSigner : EcdsaChannelSigner > {
226+ channel_id : ChannelId ,
223227 channel_value_satoshis : u64 , // Deprecated as of 0.2.
224228 channel_keys_id : [ u8 ; 32 ] , // Deprecated as of 0.2.
225229 destination_script : ScriptBuf , // Deprecated as of 0.2.
@@ -282,7 +286,8 @@ impl<ChannelSigner: EcdsaChannelSigner> PartialEq for OnchainTxHandler<ChannelSi
282286 #[ rustfmt:: skip]
283287 fn eq ( & self , other : & Self ) -> bool {
284288 // `signer`, `secp_ctx`, and `pending_claim_events` are excluded on purpose.
285- self . channel_value_satoshis == other. channel_value_satoshis &&
289+ self . channel_id == other. channel_id &&
290+ self . channel_value_satoshis == other. channel_value_satoshis &&
286291 self . channel_keys_id == other. channel_keys_id &&
287292 self . destination_script == other. destination_script &&
288293 self . holder_commitment == other. holder_commitment &&
@@ -345,6 +350,14 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
345350 write_tlv_fields ! ( writer, { } ) ;
346351 Ok ( ( ) )
347352 }
353+
354+ // `ChannelMonitor`s already track the `channel_id`, however, due to the derserialization order
355+ // there we can't make use of `ReadableArgs` to hand it into `OnchainTxHandler`'s
356+ // deserialization logic directly. Instead we opt to initialize it with 0s and override it
357+ // after reading the respective field via this method.
358+ pub ( crate ) fn set_channel_id ( & mut self , channel_id : ChannelId ) {
359+ self . channel_id = channel_id;
360+ }
348361}
349362
350363impl < ' a , ' b , ES : EntropySource , SP : SignerProvider > ReadableArgs < ( & ' a ES , & ' b SP , u64 , [ u8 ; 32 ] ) >
@@ -366,7 +379,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
366379 let prev_holder_commitment = Readable :: read ( reader) ?;
367380 let _prev_holder_htlc_sigs: Option < Vec < Option < ( usize , Signature ) > > > = Readable :: read ( reader) ?;
368381
369- let channel_parameters = ReadableArgs :: < Option < u64 > > :: read ( reader, Some ( channel_value_satoshis) ) ?;
382+ let channel_parameters: ChannelTransactionParameters = ReadableArgs :: < Option < u64 > > :: read ( reader, Some ( channel_value_satoshis) ) ?;
370383
371384 // Read the serialized signer bytes, but don't deserialize them, as we'll obtain our signer
372385 // by re-deriving the private key material.
@@ -420,10 +433,17 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
420433
421434 read_tlv_fields ! ( reader, { } ) ;
422435
436+ // `ChannelMonitor`s already track the `channel_id`, however, due to the derserialization
437+ // order there we can't make use of `ReadableArgs` to hand it in directly. Instead we opt
438+ // to initialize it with 0s and override it after reading the respective field via
439+ // `OnchainTxHandler::set_channel_id`.
440+ let channel_id = ChannelId ( [ 0u8 ; 32 ] ) ;
441+
423442 let mut secp_ctx = Secp256k1 :: new ( ) ;
424443 secp_ctx. seeded_randomize ( & entropy_source. get_secure_random_bytes ( ) ) ;
425444
426445 Ok ( OnchainTxHandler {
446+ channel_id,
427447 channel_value_satoshis,
428448 channel_keys_id,
429449 destination_script,
@@ -443,11 +463,13 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
443463
444464impl < ChannelSigner : EcdsaChannelSigner > OnchainTxHandler < ChannelSigner > {
445465 pub ( crate ) fn new (
446- channel_value_satoshis : u64 , channel_keys_id : [ u8 ; 32 ] , destination_script : ScriptBuf ,
447- signer : ChannelSigner , channel_parameters : ChannelTransactionParameters ,
466+ channel_id : ChannelId , channel_value_satoshis : u64 , channel_keys_id : [ u8 ; 32 ] ,
467+ destination_script : ScriptBuf , signer : ChannelSigner ,
468+ channel_parameters : ChannelTransactionParameters ,
448469 holder_commitment : HolderCommitmentTransaction , secp_ctx : Secp256k1 < secp256k1:: All > ,
449470 ) -> Self {
450471 OnchainTxHandler {
472+ channel_id,
451473 channel_value_satoshis,
452474 channel_keys_id,
453475 destination_script,
@@ -511,7 +533,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
511533 if tx. is_fully_signed ( ) {
512534 let log_start = if feerate_was_bumped { "Broadcasting RBF-bumped" } else { "Rebroadcasting" } ;
513535 log_info ! ( logger, "{} onchain {}" , log_start, log_tx!( tx. 0 ) ) ;
514- broadcaster. broadcast_transactions ( & [ & tx. 0 ] ) ;
536+ broadcaster. broadcast_transactions ( & [ ( & tx. 0 , TransactionType :: Claim { channel_id : self . channel_id } ) ] ) ;
515537 } else {
516538 log_info ! ( logger, "Waiting for signature of unsigned onchain transaction {}" , tx. 0 . compute_txid( ) ) ;
517539 }
@@ -853,7 +875,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
853875 OnchainClaim :: Tx ( tx) => {
854876 if tx. is_fully_signed ( ) {
855877 log_info ! ( logger, "Broadcasting onchain {}" , log_tx!( tx. 0 ) ) ;
856- broadcaster. broadcast_transactions ( & [ & tx. 0 ] ) ;
878+ broadcaster. broadcast_transactions ( & [ ( & tx. 0 , TransactionType :: Claim { channel_id : self . channel_id } ) ] ) ;
857879 } else {
858880 log_info ! ( logger, "Waiting for signature of unsigned onchain transaction {}" , tx. 0 . compute_txid( ) ) ;
859881 }
@@ -1071,7 +1093,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
10711093 OnchainClaim :: Tx ( bump_tx) => {
10721094 if bump_tx. is_fully_signed ( ) {
10731095 log_info ! ( logger, "Broadcasting RBF-bumped onchain {}" , log_tx!( bump_tx. 0 ) ) ;
1074- broadcaster. broadcast_transactions ( & [ & bump_tx. 0 ] ) ;
1096+ broadcaster. broadcast_transactions ( & [ ( & bump_tx. 0 , TransactionType :: Claim { channel_id : self . channel_id } ) ] ) ;
10751097 } else {
10761098 log_info ! ( logger, "Waiting for signature of RBF-bumped unsigned onchain transaction {}" ,
10771099 bump_tx. 0 . compute_txid( ) ) ;
@@ -1168,7 +1190,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
11681190 OnchainClaim :: Tx ( bump_tx) => {
11691191 if bump_tx. is_fully_signed ( ) {
11701192 log_info ! ( logger, "Broadcasting onchain {}" , log_tx!( bump_tx. 0 ) ) ;
1171- broadcaster. broadcast_transactions ( & [ & bump_tx. 0 ] ) ;
1193+ broadcaster. broadcast_transactions ( & [ ( & bump_tx. 0 , TransactionType :: Claim { channel_id : self . channel_id } ) ] ) ;
11721194 } else {
11731195 log_info ! ( logger, "Waiting for signature of unsigned onchain transaction {}" , bump_tx. 0 . compute_txid( ) ) ;
11741196 }
@@ -1262,6 +1284,7 @@ mod tests {
12621284 } ;
12631285 use crate :: ln:: channel_keys:: { DelayedPaymentBasepoint , HtlcBasepoint , RevocationBasepoint } ;
12641286 use crate :: ln:: functional_test_utils:: create_dummy_block;
1287+ use crate :: ln:: types:: ChannelId ;
12651288 use crate :: sign:: { ChannelDerivationParameters , ChannelSigner , HTLCDescriptor , InMemorySigner } ;
12661289 use crate :: types:: payment:: { PaymentHash , PaymentPreimage } ;
12671290 use crate :: util:: test_utils:: { TestBroadcaster , TestFeeEstimator , TestLogger } ;
@@ -1346,6 +1369,7 @@ mod tests {
13461369 let holder_commit = HolderCommitmentTransaction :: dummy ( 1000000 , funding_outpoint, nondust_htlcs) ;
13471370 let destination_script = ScriptBuf :: new ( ) ;
13481371 let mut tx_handler = OnchainTxHandler :: new (
1372+ ChannelId :: from_bytes ( [ 0 ; 32 ] ) ,
13491373 1000000 ,
13501374 [ 0 ; 32 ] ,
13511375 destination_script. clone ( ) ,
0 commit comments