@@ -18,7 +18,7 @@ use bitcoin::hashes::Hash;
1818use bitcoin:: locktime:: absolute:: LockTime ;
1919use bitcoin:: script:: { Script , ScriptBuf } ;
2020use bitcoin:: secp256k1;
21- use bitcoin:: secp256k1:: { ecdsa:: Signature , Secp256k1 } ;
21+ use bitcoin:: secp256k1:: { ecdsa:: Signature , PublicKey , Secp256k1 } ;
2222use bitcoin:: transaction:: OutPoint as BitcoinOutPoint ;
2323use bitcoin:: transaction:: Transaction ;
2424
@@ -224,6 +224,7 @@ pub(crate) enum FeerateStrategy {
224224#[ derive( Clone ) ]
225225pub struct OnchainTxHandler < ChannelSigner : EcdsaChannelSigner > {
226226 channel_id : ChannelId ,
227+ counterparty_node_id : PublicKey ,
227228 channel_value_satoshis : u64 , // Deprecated as of 0.2.
228229 channel_keys_id : [ u8 ; 32 ] , // Deprecated as of 0.2.
229230 destination_script : ScriptBuf , // Deprecated as of 0.2.
@@ -287,6 +288,7 @@ impl<ChannelSigner: EcdsaChannelSigner> PartialEq for OnchainTxHandler<ChannelSi
287288 fn eq ( & self , other : & Self ) -> bool {
288289 // `signer`, `secp_ctx`, and `pending_claim_events` are excluded on purpose.
289290 self . channel_id == other. channel_id &&
291+ self . counterparty_node_id == other. counterparty_node_id &&
290292 self . channel_value_satoshis == other. channel_value_satoshis &&
291293 self . channel_keys_id == other. channel_keys_id &&
292294 self . destination_script == other. destination_script &&
@@ -358,6 +360,14 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
358360 pub ( crate ) fn set_channel_id ( & mut self , channel_id : ChannelId ) {
359361 self . channel_id = channel_id;
360362 }
363+
364+ // `ChannelMonitor`s already track the `counterparty_node_id`, however, due to the
365+ // deserialization order there we can't make use of `ReadableArgs` to hand it into
366+ // `OnchainTxHandler`'s deserialization logic directly. Instead we opt to initialize it with a
367+ // dummy key and override it after reading the respective field via this method.
368+ pub ( crate ) fn set_counterparty_node_id ( & mut self , counterparty_node_id : PublicKey ) {
369+ self . counterparty_node_id = counterparty_node_id;
370+ }
361371}
362372
363373impl < ' a , ' b , ES : EntropySource , SP : SignerProvider > ReadableArgs < ( & ' a ES , & ' b SP , u64 , [ u8 ; 32 ] ) >
@@ -433,17 +443,20 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
433443
434444 read_tlv_fields ! ( reader, { } ) ;
435445
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`.
446+ // `ChannelMonitor`s already track the `channel_id` and `counterparty_node_id`, however, due
447+ // to the deserialization order there we can't make use of `ReadableArgs` to hand them in
448+ // directly. Instead we opt to initialize them with dummy values and override them after
449+ // reading the respective fields via `OnchainTxHandler::set_channel_id` and
450+ // `OnchainTxHandler::set_counterparty_node_id`.
440451 let channel_id = ChannelId ( [ 0u8 ; 32 ] ) ;
452+ let counterparty_node_id = PublicKey :: from_slice ( & [ 2 ; 33 ] ) . unwrap ( ) ;
441453
442454 let mut secp_ctx = Secp256k1 :: new ( ) ;
443455 secp_ctx. seeded_randomize ( & entropy_source. get_secure_random_bytes ( ) ) ;
444456
445457 Ok ( OnchainTxHandler {
446458 channel_id,
459+ counterparty_node_id,
447460 channel_value_satoshis,
448461 channel_keys_id,
449462 destination_script,
@@ -463,13 +476,14 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
463476
464477impl < ChannelSigner : EcdsaChannelSigner > OnchainTxHandler < ChannelSigner > {
465478 pub ( crate ) fn new (
466- channel_id : ChannelId , channel_value_satoshis : u64 , channel_keys_id : [ u8 ; 32 ] ,
467- destination_script : ScriptBuf , signer : ChannelSigner ,
479+ channel_id : ChannelId , counterparty_node_id : PublicKey , channel_value_satoshis : u64 ,
480+ channel_keys_id : [ u8 ; 32 ] , destination_script : ScriptBuf , signer : ChannelSigner ,
468481 channel_parameters : ChannelTransactionParameters ,
469482 holder_commitment : HolderCommitmentTransaction , secp_ctx : Secp256k1 < secp256k1:: All > ,
470483 ) -> Self {
471484 OnchainTxHandler {
472485 channel_id,
486+ counterparty_node_id,
473487 channel_value_satoshis,
474488 channel_keys_id,
475489 destination_script,
@@ -533,7 +547,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
533547 if tx. is_fully_signed ( ) {
534548 let log_start = if feerate_was_bumped { "Broadcasting RBF-bumped" } else { "Rebroadcasting" } ;
535549 log_info ! ( logger, "{} onchain {}" , log_start, log_tx!( tx. 0 ) ) ;
536- broadcaster. broadcast_transactions ( & [ ( & tx. 0 , TransactionType :: Claim { channel_id : self . channel_id } ) ] ) ;
550+ broadcaster. broadcast_transactions ( & [ ( & tx. 0 , TransactionType :: Claim { counterparty_node_id : self . counterparty_node_id , channel_id : self . channel_id } ) ] ) ;
537551 } else {
538552 log_info ! ( logger, "Waiting for signature of unsigned onchain transaction {}" , tx. 0 . compute_txid( ) ) ;
539553 }
@@ -875,7 +889,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
875889 OnchainClaim :: Tx ( tx) => {
876890 if tx. is_fully_signed ( ) {
877891 log_info ! ( logger, "Broadcasting onchain {}" , log_tx!( tx. 0 ) ) ;
878- broadcaster. broadcast_transactions ( & [ ( & tx. 0 , TransactionType :: Claim { channel_id : self . channel_id } ) ] ) ;
892+ broadcaster. broadcast_transactions ( & [ ( & tx. 0 , TransactionType :: Claim { counterparty_node_id : self . counterparty_node_id , channel_id : self . channel_id } ) ] ) ;
879893 } else {
880894 log_info ! ( logger, "Waiting for signature of unsigned onchain transaction {}" , tx. 0 . compute_txid( ) ) ;
881895 }
@@ -1093,7 +1107,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
10931107 OnchainClaim :: Tx ( bump_tx) => {
10941108 if bump_tx. is_fully_signed ( ) {
10951109 log_info ! ( logger, "Broadcasting RBF-bumped onchain {}" , log_tx!( bump_tx. 0 ) ) ;
1096- broadcaster. broadcast_transactions ( & [ ( & bump_tx. 0 , TransactionType :: Claim { channel_id : self . channel_id } ) ] ) ;
1110+ broadcaster. broadcast_transactions ( & [ ( & bump_tx. 0 , TransactionType :: Claim { counterparty_node_id : self . counterparty_node_id , channel_id : self . channel_id } ) ] ) ;
10971111 } else {
10981112 log_info ! ( logger, "Waiting for signature of RBF-bumped unsigned onchain transaction {}" ,
10991113 bump_tx. 0 . compute_txid( ) ) ;
@@ -1190,7 +1204,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
11901204 OnchainClaim :: Tx ( bump_tx) => {
11911205 if bump_tx. is_fully_signed ( ) {
11921206 log_info ! ( logger, "Broadcasting onchain {}" , log_tx!( bump_tx. 0 ) ) ;
1193- broadcaster. broadcast_transactions ( & [ ( & bump_tx. 0 , TransactionType :: Claim { channel_id : self . channel_id } ) ] ) ;
1207+ broadcaster. broadcast_transactions ( & [ ( & bump_tx. 0 , TransactionType :: Claim { counterparty_node_id : self . counterparty_node_id , channel_id : self . channel_id } ) ] ) ;
11941208 } else {
11951209 log_info ! ( logger, "Waiting for signature of unsigned onchain transaction {}" , bump_tx. 0 . compute_txid( ) ) ;
11961210 }
@@ -1368,8 +1382,10 @@ mod tests {
13681382 }
13691383 let holder_commit = HolderCommitmentTransaction :: dummy ( 1000000 , funding_outpoint, nondust_htlcs) ;
13701384 let destination_script = ScriptBuf :: new ( ) ;
1385+ let counterparty_node_id = PublicKey :: from_slice ( & [ 2 ; 33 ] ) . unwrap ( ) ;
13711386 let mut tx_handler = OnchainTxHandler :: new (
13721387 ChannelId :: from_bytes ( [ 0 ; 32 ] ) ,
1388+ counterparty_node_id,
13731389 1000000 ,
13741390 [ 0 ; 32 ] ,
13751391 destination_script. clone ( ) ,
0 commit comments