From 2db9c6ec1ba619e73bf491001f6e6dbff15bc060 Mon Sep 17 00:00:00 2001 From: Elias Rohrer Date: Mon, 11 Sep 2023 16:52:11 +0200 Subject: [PATCH] Account for new `ChannelId` type --- src/event.rs | 36 +++++++++++++----------------------- src/lib.rs | 8 ++++---- src/types.rs | 25 ++----------------------- src/uniffi_types.rs | 4 ++-- 4 files changed, 21 insertions(+), 52 deletions(-) diff --git a/src/event.rs b/src/event.rs index 74d26b5f5..f33b231fe 100644 --- a/src/event.rs +++ b/src/event.rs @@ -1,6 +1,5 @@ use crate::{ - hex_utils, ChannelId, ChannelManager, Config, Error, KeysManager, NetworkGraph, UserChannelId, - Wallet, + hex_utils, ChannelManager, Config, Error, KeysManager, NetworkGraph, UserChannelId, Wallet, }; use crate::payment_store::{ @@ -17,7 +16,7 @@ use lightning::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, use lightning::events::Event as LdkEvent; use lightning::events::PaymentPurpose; use lightning::impl_writeable_tlv_based_enum; -use lightning::ln::PaymentHash; +use lightning::ln::{ChannelId, PaymentHash}; use lightning::routing::gossip::NodeId; use lightning::util::errors::APIError; use lightning::util::persist::KVStore; @@ -573,7 +572,7 @@ where }); } } - LdkEvent::SpendableOutputs { outputs } => { + LdkEvent::SpendableOutputs { outputs, channel_id: _ } => { // TODO: We should eventually remember the outputs and supply them to the wallet's coin selection, once BDK allows us to do so. let destination_address = self.wallet.get_new_address().unwrap_or_else(|e| { log_error!(self.logger, "Failed to get destination address: {}", e); @@ -664,7 +663,7 @@ where let nodes = read_only_network_graph.nodes(); let channels = self.channel_manager.list_channels(); - let node_str = |channel_id: &Option<[u8; 32]>| { + let node_str = |channel_id: &Option| { channel_id .and_then(|channel_id| channels.iter().find(|c| c.channel_id == channel_id)) .and_then(|channel| { @@ -678,11 +677,9 @@ where }) }) }; - let channel_str = |channel_id: &Option<[u8; 32]>| { + let channel_str = |channel_id: &Option| { channel_id - .map(|channel_id| { - format!(" with channel {}", hex_utils::to_string(&channel_id)) - }) + .map(|channel_id| format!(" with channel {}", channel_id)) .unwrap_or_default() }; let from_prev_str = format!( @@ -725,16 +722,14 @@ where log_info!( self.logger, "New channel {} with counterparty {} has been created and is pending confirmation on chain.", - hex_utils::to_string(&channel_id), + channel_id, counterparty_node_id, ); self.event_queue .add_event(Event::ChannelPending { - channel_id: ChannelId(channel_id), + channel_id, user_channel_id: UserChannelId(user_channel_id), - former_temporary_channel_id: ChannelId( - former_temporary_channel_id.unwrap(), - ), + former_temporary_channel_id: former_temporary_channel_id.unwrap(), counterparty_node_id, funding_txo, }) @@ -749,12 +744,12 @@ where log_info!( self.logger, "Channel {} with counterparty {} ready to be used.", - hex_utils::to_string(&channel_id), + channel_id, counterparty_node_id, ); self.event_queue .add_event(Event::ChannelReady { - channel_id: ChannelId(channel_id), + channel_id, user_channel_id: UserChannelId(user_channel_id), counterparty_node_id: Some(counterparty_node_id), }) @@ -770,15 +765,10 @@ where counterparty_node_id, .. } => { - log_info!( - self.logger, - "Channel {} closed due to: {:?}", - hex_utils::to_string(&channel_id), - reason - ); + log_info!(self.logger, "Channel {} closed due to: {:?}", channel_id, reason); self.event_queue .add_event(Event::ChannelClosed { - channel_id: ChannelId(channel_id), + channel_id, user_channel_id: UserChannelId(user_channel_id), counterparty_node_id, }) diff --git a/src/lib.rs b/src/lib.rs index 2d99dd959..093cbf31e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -119,14 +119,14 @@ use payment_store::PaymentStore; pub use payment_store::{PaymentDetails, PaymentDirection, PaymentStatus}; use peer_store::{PeerInfo, PeerStore}; use types::{ChainMonitor, ChannelManager, KeysManager, NetworkGraph, PeerManager, Router, Scorer}; -pub use types::{ChannelDetails, ChannelId, PeerDetails, UserChannelId}; +pub use types::{ChannelDetails, PeerDetails, UserChannelId}; use wallet::Wallet; use logger::{log_debug, log_error, log_info, log_trace, FilesystemLogger, Logger}; use lightning::chain::Confirm; use lightning::ln::channelmanager::{self, PaymentId, RecipientOnionFields, Retry}; -use lightning::ln::{PaymentHash, PaymentPreimage}; +use lightning::ln::{ChannelId, PaymentHash, PaymentPreimage}; use lightning::sign::EntropySource; use lightning::util::persist::KVStore; @@ -1032,7 +1032,7 @@ impl Node { &self, channel_id: &ChannelId, counterparty_node_id: PublicKey, ) -> Result<(), Error> { self.peer_store.remove_peer(&counterparty_node_id)?; - match self.channel_manager.close_channel(&channel_id.0, &counterparty_node_id) { + match self.channel_manager.close_channel(&channel_id, &counterparty_node_id) { Ok(_) => Ok(()), Err(_) => Err(Error::ChannelClosingFailed), } @@ -1046,7 +1046,7 @@ impl Node { self.channel_manager .update_channel_config( &counterparty_node_id, - &[channel_id.0], + &[*channel_id], &(*channel_config).clone().into(), ) .map_err(|_| Error::ChannelConfigUpdateFailed) diff --git a/src/types.rs b/src/types.rs index d5bb3ca62..d7aae5d2f 100644 --- a/src/types.rs +++ b/src/types.rs @@ -6,6 +6,7 @@ use lightning::ln::channelmanager::ChannelDetails as LdkChannelDetails; use lightning::ln::msgs::RoutingMessageHandler; use lightning::ln::msgs::SocketAddress as LdkSocketAddress; use lightning::ln::peer_handler::IgnoringMessageHandler; +use lightning::ln::ChannelId; use lightning::routing::gossip; use lightning::routing::router::DefaultRouter; use lightning::routing::scoring::{ProbabilisticScorer, ProbabilisticScoringFeeParameters}; @@ -106,28 +107,6 @@ impl lightning::onion_message::MessageRouter for FakeMessageRouter { } } -/// The global identifier of a channel. -/// -/// Note that this will start out to be a temporary ID until channel funding negotiation is -/// finalized, at which point it will change to be a permanent global ID tied to the on-chain -/// funding transaction. -#[derive(Debug, Copy, Clone, PartialEq, Eq)] -pub struct ChannelId(pub [u8; 32]); - -impl Writeable for ChannelId { - fn write(&self, writer: &mut W) -> Result<(), lightning::io::Error> { - Ok(self.0.write(writer)?) - } -} - -impl Readable for ChannelId { - fn read( - reader: &mut R, - ) -> Result { - Ok(Self(Readable::read(reader)?)) - } -} - /// A local, potentially user-provided, identifier of a channel. /// /// By default, this will be randomly generated for the user to ensure local uniqueness. @@ -224,7 +203,7 @@ pub struct ChannelDetails { impl From for ChannelDetails { fn from(value: LdkChannelDetails) -> Self { ChannelDetails { - channel_id: ChannelId(value.channel_id), + channel_id: value.channel_id, counterparty_node_id: value.counterparty.node_id, funding_txo: value.funding_txo.and_then(|o| Some(o.into_bitcoin_outpoint())), channel_value_sats: value.channel_value_satoshis, diff --git a/src/uniffi_types.rs b/src/uniffi_types.rs index 14349bb9f..c0bdea5b7 100644 --- a/src/uniffi_types.rs +++ b/src/uniffi_types.rs @@ -3,13 +3,13 @@ use crate::UniffiCustomTypeConverter; use crate::error::Error; use crate::hex_utils; use crate::io::SqliteStore; -use crate::{ChannelId, Node, SocketAddress, UserChannelId}; +use crate::{Node, SocketAddress, UserChannelId}; use bitcoin::hashes::sha256::Hash as Sha256; use bitcoin::hashes::Hash; use bitcoin::secp256k1::PublicKey; use bitcoin::{Address, Txid}; -use lightning::ln::{PaymentHash, PaymentPreimage, PaymentSecret}; +use lightning::ln::{ChannelId, PaymentHash, PaymentPreimage, PaymentSecret}; use lightning_invoice::{Bolt11Invoice, SignedRawBolt11Invoice}; use bip39::Mnemonic;