@@ -4842,6 +4842,109 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4842
4842
self.counterparty_cur_commitment_point = Some(counterparty_cur_commitment_point_override);
4843
4843
self.get_initial_counterparty_commitment_signature(funding, logger)
4844
4844
}
4845
+
4846
+ fn get_channel_announcement<NS: Deref>(
4847
+ &self, funding: &FundingScope, node_signer: &NS, chain_hash: ChainHash,
4848
+ user_config: &UserConfig,
4849
+ ) -> Result<msgs::UnsignedChannelAnnouncement, ChannelError> where NS::Target: NodeSigner {
4850
+ if !self.config.announce_for_forwarding {
4851
+ return Err(ChannelError::Ignore("Channel is not available for public announcements".to_owned()));
4852
+ }
4853
+ if !self.is_usable() {
4854
+ return Err(ChannelError::Ignore("Cannot get a ChannelAnnouncement if the channel is not currently usable".to_owned()));
4855
+ }
4856
+
4857
+ let short_channel_id = self.get_short_channel_id()
4858
+ .ok_or(ChannelError::Ignore("Cannot get a ChannelAnnouncement if the channel has not been confirmed yet".to_owned()))?;
4859
+ let node_id = NodeId::from_pubkey(&node_signer.get_node_id(Recipient::Node)
4860
+ .map_err(|_| ChannelError::Ignore("Failed to retrieve own public key".to_owned()))?);
4861
+ let counterparty_node_id = NodeId::from_pubkey(&self.get_counterparty_node_id());
4862
+ let were_node_one = node_id.as_slice() < counterparty_node_id.as_slice();
4863
+
4864
+ let msg = msgs::UnsignedChannelAnnouncement {
4865
+ features: channelmanager::provided_channel_features(&user_config),
4866
+ chain_hash,
4867
+ short_channel_id,
4868
+ node_id_1: if were_node_one { node_id } else { counterparty_node_id },
4869
+ node_id_2: if were_node_one { counterparty_node_id } else { node_id },
4870
+ bitcoin_key_1: NodeId::from_pubkey(if were_node_one { &funding.get_holder_pubkeys().funding_pubkey } else { funding.counterparty_funding_pubkey() }),
4871
+ bitcoin_key_2: NodeId::from_pubkey(if were_node_one { funding.counterparty_funding_pubkey() } else { &funding.get_holder_pubkeys().funding_pubkey }),
4872
+ excess_data: Vec::new(),
4873
+ };
4874
+
4875
+ Ok(msg)
4876
+ }
4877
+
4878
+ fn get_announcement_sigs<NS: Deref, L: Deref>(
4879
+ &mut self, funding: &FundingScope, node_signer: &NS, chain_hash: ChainHash,
4880
+ user_config: &UserConfig, best_block_height: u32, logger: &L,
4881
+ ) -> Option<msgs::AnnouncementSignatures>
4882
+ where
4883
+ NS::Target: NodeSigner,
4884
+ L::Target: Logger
4885
+ {
4886
+ if self.funding_tx_confirmation_height == 0 || self.funding_tx_confirmation_height + 5 > best_block_height {
4887
+ return None;
4888
+ }
4889
+
4890
+ if !self.is_usable() {
4891
+ return None;
4892
+ }
4893
+
4894
+ if self.channel_state.is_peer_disconnected() {
4895
+ log_trace!(logger, "Cannot create an announcement_signatures as our peer is disconnected");
4896
+ return None;
4897
+ }
4898
+
4899
+ if self.announcement_sigs_state != AnnouncementSigsState::NotSent {
4900
+ return None;
4901
+ }
4902
+
4903
+ log_trace!(logger, "Creating an announcement_signatures message for channel {}", &self.channel_id());
4904
+ let announcement = match self.get_channel_announcement(funding, node_signer, chain_hash, user_config) {
4905
+ Ok(a) => a,
4906
+ Err(e) => {
4907
+ log_trace!(logger, "{:?}", e);
4908
+ return None;
4909
+ }
4910
+ };
4911
+ let our_node_sig = match node_signer.sign_gossip_message(msgs::UnsignedGossipMessage::ChannelAnnouncement(&announcement)) {
4912
+ Err(_) => {
4913
+ log_error!(logger, "Failed to generate node signature for channel_announcement. Channel will not be announced!");
4914
+ return None;
4915
+ },
4916
+ Ok(v) => v
4917
+ };
4918
+ match &self.holder_signer {
4919
+ ChannelSignerType::Ecdsa(ecdsa) => {
4920
+ let our_bitcoin_sig = match ecdsa.sign_channel_announcement_with_funding_key(
4921
+ &funding.channel_transaction_parameters, &announcement, &self.secp_ctx,
4922
+ ) {
4923
+ Err(_) => {
4924
+ log_error!(logger, "Signer rejected channel_announcement signing. Channel will not be announced!");
4925
+ return None;
4926
+ },
4927
+ Ok(v) => v
4928
+ };
4929
+ let short_channel_id = match self.get_short_channel_id() {
4930
+ Some(scid) => scid,
4931
+ None => return None,
4932
+ };
4933
+
4934
+ self.announcement_sigs_state = AnnouncementSigsState::MessageSent;
4935
+
4936
+ Some(msgs::AnnouncementSignatures {
4937
+ channel_id: self.channel_id(),
4938
+ short_channel_id,
4939
+ node_signature: our_node_sig,
4940
+ bitcoin_signature: our_bitcoin_sig,
4941
+ })
4942
+ },
4943
+ // TODO (taproot|arik)
4944
+ #[cfg(taproot)]
4945
+ _ => todo!()
4946
+ }
4947
+ }
4845
4948
}
4846
4949
4847
4950
// Internal utility functions for channels
@@ -8383,32 +8486,7 @@ impl<SP: Deref> FundedChannel<SP> where
8383
8486
fn get_channel_announcement<NS: Deref>(
8384
8487
&self, node_signer: &NS, chain_hash: ChainHash, user_config: &UserConfig,
8385
8488
) -> Result<msgs::UnsignedChannelAnnouncement, ChannelError> where NS::Target: NodeSigner {
8386
- if !self.context.config.announce_for_forwarding {
8387
- return Err(ChannelError::Ignore("Channel is not available for public announcements".to_owned()));
8388
- }
8389
- if !self.context.is_usable() {
8390
- return Err(ChannelError::Ignore("Cannot get a ChannelAnnouncement if the channel is not currently usable".to_owned()));
8391
- }
8392
-
8393
- let short_channel_id = self.context.get_short_channel_id()
8394
- .ok_or(ChannelError::Ignore("Cannot get a ChannelAnnouncement if the channel has not been confirmed yet".to_owned()))?;
8395
- let node_id = NodeId::from_pubkey(&node_signer.get_node_id(Recipient::Node)
8396
- .map_err(|_| ChannelError::Ignore("Failed to retrieve own public key".to_owned()))?);
8397
- let counterparty_node_id = NodeId::from_pubkey(&self.context.get_counterparty_node_id());
8398
- let were_node_one = node_id.as_slice() < counterparty_node_id.as_slice();
8399
-
8400
- let msg = msgs::UnsignedChannelAnnouncement {
8401
- features: channelmanager::provided_channel_features(&user_config),
8402
- chain_hash,
8403
- short_channel_id,
8404
- node_id_1: if were_node_one { node_id } else { counterparty_node_id },
8405
- node_id_2: if were_node_one { counterparty_node_id } else { node_id },
8406
- bitcoin_key_1: NodeId::from_pubkey(if were_node_one { &self.funding.get_holder_pubkeys().funding_pubkey } else { self.funding.counterparty_funding_pubkey() }),
8407
- bitcoin_key_2: NodeId::from_pubkey(if were_node_one { self.funding.counterparty_funding_pubkey() } else { &self.funding.get_holder_pubkeys().funding_pubkey }),
8408
- excess_data: Vec::new(),
8409
- };
8410
-
8411
- Ok(msg)
8489
+ self.context.get_channel_announcement(&self.funding, node_signer, chain_hash, user_config)
8412
8490
}
8413
8491
8414
8492
fn get_announcement_sigs<NS: Deref, L: Deref>(
@@ -8419,67 +8497,7 @@ impl<SP: Deref> FundedChannel<SP> where
8419
8497
NS::Target: NodeSigner,
8420
8498
L::Target: Logger
8421
8499
{
8422
- if self.context.funding_tx_confirmation_height == 0 || self.context.funding_tx_confirmation_height + 5 > best_block_height {
8423
- return None;
8424
- }
8425
-
8426
- if !self.context.is_usable() {
8427
- return None;
8428
- }
8429
-
8430
- if self.context.channel_state.is_peer_disconnected() {
8431
- log_trace!(logger, "Cannot create an announcement_signatures as our peer is disconnected");
8432
- return None;
8433
- }
8434
-
8435
- if self.context.announcement_sigs_state != AnnouncementSigsState::NotSent {
8436
- return None;
8437
- }
8438
-
8439
- log_trace!(logger, "Creating an announcement_signatures message for channel {}", &self.context.channel_id());
8440
- let announcement = match self.get_channel_announcement(node_signer, chain_hash, user_config) {
8441
- Ok(a) => a,
8442
- Err(e) => {
8443
- log_trace!(logger, "{:?}", e);
8444
- return None;
8445
- }
8446
- };
8447
- let our_node_sig = match node_signer.sign_gossip_message(msgs::UnsignedGossipMessage::ChannelAnnouncement(&announcement)) {
8448
- Err(_) => {
8449
- log_error!(logger, "Failed to generate node signature for channel_announcement. Channel will not be announced!");
8450
- return None;
8451
- },
8452
- Ok(v) => v
8453
- };
8454
- match &self.context.holder_signer {
8455
- ChannelSignerType::Ecdsa(ecdsa) => {
8456
- let our_bitcoin_sig = match ecdsa.sign_channel_announcement_with_funding_key(
8457
- &self.funding.channel_transaction_parameters, &announcement, &self.context.secp_ctx,
8458
- ) {
8459
- Err(_) => {
8460
- log_error!(logger, "Signer rejected channel_announcement signing. Channel will not be announced!");
8461
- return None;
8462
- },
8463
- Ok(v) => v
8464
- };
8465
- let short_channel_id = match self.context.get_short_channel_id() {
8466
- Some(scid) => scid,
8467
- None => return None,
8468
- };
8469
-
8470
- self.context.announcement_sigs_state = AnnouncementSigsState::MessageSent;
8471
-
8472
- Some(msgs::AnnouncementSignatures {
8473
- channel_id: self.context.channel_id(),
8474
- short_channel_id,
8475
- node_signature: our_node_sig,
8476
- bitcoin_signature: our_bitcoin_sig,
8477
- })
8478
- },
8479
- // TODO (taproot|arik)
8480
- #[cfg(taproot)]
8481
- _ => todo!()
8482
- }
8500
+ self.context.get_announcement_sigs(&self.funding, node_signer, chain_hash, user_config, best_block_height, logger)
8483
8501
}
8484
8502
8485
8503
/// Signs the given channel announcement, returning a ChannelError::Ignore if no keys are
0 commit comments