Skip to content

Commit 166dce6

Browse files
committed
Account for new ChannelId type
1 parent 5243521 commit 166dce6

File tree

4 files changed

+21
-52
lines changed

4 files changed

+21
-52
lines changed

src/event.rs

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::{
2-
hex_utils, ChannelId, ChannelManager, Config, Error, KeysManager, NetworkGraph, UserChannelId,
3-
Wallet,
2+
hex_utils, ChannelManager, Config, Error, KeysManager, NetworkGraph, UserChannelId, Wallet,
43
};
54

65
use crate::payment_store::{
@@ -17,7 +16,7 @@ use lightning::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget,
1716
use lightning::events::Event as LdkEvent;
1817
use lightning::events::PaymentPurpose;
1918
use lightning::impl_writeable_tlv_based_enum;
20-
use lightning::ln::PaymentHash;
19+
use lightning::ln::{ChannelId, PaymentHash};
2120
use lightning::routing::gossip::NodeId;
2221
use lightning::util::errors::APIError;
2322
use lightning::util::persist::KVStore;
@@ -574,7 +573,7 @@ where
574573
});
575574
}
576575
}
577-
LdkEvent::SpendableOutputs { outputs } => {
576+
LdkEvent::SpendableOutputs { outputs, channel_id: _ } => {
578577
// TODO: We should eventually remember the outputs and supply them to the wallet's coin selection, once BDK allows us to do so.
579578
let destination_address = self.wallet.get_new_address().unwrap_or_else(|e| {
580579
log_error!(self.logger, "Failed to get destination address: {}", e);
@@ -665,7 +664,7 @@ where
665664
let nodes = read_only_network_graph.nodes();
666665
let channels = self.channel_manager.list_channels();
667666

668-
let node_str = |channel_id: &Option<[u8; 32]>| {
667+
let node_str = |channel_id: &Option<ChannelId>| {
669668
channel_id
670669
.and_then(|channel_id| channels.iter().find(|c| c.channel_id == channel_id))
671670
.and_then(|channel| {
@@ -679,11 +678,9 @@ where
679678
})
680679
})
681680
};
682-
let channel_str = |channel_id: &Option<[u8; 32]>| {
681+
let channel_str = |channel_id: &Option<ChannelId>| {
683682
channel_id
684-
.map(|channel_id| {
685-
format!(" with channel {}", hex_utils::to_string(&channel_id))
686-
})
683+
.map(|channel_id| format!(" with channel {}", channel_id))
687684
.unwrap_or_default()
688685
};
689686
let from_prev_str = format!(
@@ -726,16 +723,14 @@ where
726723
log_info!(
727724
self.logger,
728725
"New channel {} with counterparty {} has been created and is pending confirmation on chain.",
729-
hex_utils::to_string(&channel_id),
726+
channel_id,
730727
counterparty_node_id,
731728
);
732729
self.event_queue
733730
.add_event(Event::ChannelPending {
734-
channel_id: ChannelId(channel_id),
731+
channel_id,
735732
user_channel_id: UserChannelId(user_channel_id),
736-
former_temporary_channel_id: ChannelId(
737-
former_temporary_channel_id.unwrap(),
738-
),
733+
former_temporary_channel_id: former_temporary_channel_id.unwrap(),
739734
counterparty_node_id,
740735
funding_txo,
741736
})
@@ -750,12 +745,12 @@ where
750745
log_info!(
751746
self.logger,
752747
"Channel {} with counterparty {} ready to be used.",
753-
hex_utils::to_string(&channel_id),
748+
channel_id,
754749
counterparty_node_id,
755750
);
756751
self.event_queue
757752
.add_event(Event::ChannelReady {
758-
channel_id: ChannelId(channel_id),
753+
channel_id,
759754
user_channel_id: UserChannelId(user_channel_id),
760755
counterparty_node_id: Some(counterparty_node_id),
761756
})
@@ -771,15 +766,10 @@ where
771766
counterparty_node_id,
772767
..
773768
} => {
774-
log_info!(
775-
self.logger,
776-
"Channel {} closed due to: {:?}",
777-
hex_utils::to_string(&channel_id),
778-
reason
779-
);
769+
log_info!(self.logger, "Channel {} closed due to: {:?}", channel_id, reason);
780770
self.event_queue
781771
.add_event(Event::ChannelClosed {
782-
channel_id: ChannelId(channel_id),
772+
channel_id,
783773
user_channel_id: UserChannelId(user_channel_id),
784774
counterparty_node_id,
785775
})

src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,14 @@ use payment_store::PaymentStore;
119119
pub use payment_store::{PaymentDetails, PaymentDirection, PaymentStatus};
120120
use peer_store::{PeerInfo, PeerStore};
121121
use types::{ChainMonitor, ChannelManager, KeysManager, NetworkGraph, PeerManager, Router, Scorer};
122-
pub use types::{ChannelDetails, ChannelId, PeerDetails, UserChannelId};
122+
pub use types::{ChannelDetails, PeerDetails, UserChannelId};
123123
use wallet::Wallet;
124124

125125
use logger::{log_debug, log_error, log_info, log_trace, FilesystemLogger, Logger};
126126

127127
use lightning::chain::Confirm;
128128
use lightning::ln::channelmanager::{self, PaymentId, RecipientOnionFields, Retry};
129-
use lightning::ln::{PaymentHash, PaymentPreimage};
129+
use lightning::ln::{ChannelId, PaymentHash, PaymentPreimage};
130130
use lightning::sign::EntropySource;
131131

132132
use lightning::util::persist::KVStore;
@@ -1032,7 +1032,7 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
10321032
&self, channel_id: &ChannelId, counterparty_node_id: PublicKey,
10331033
) -> Result<(), Error> {
10341034
self.peer_store.remove_peer(&counterparty_node_id)?;
1035-
match self.channel_manager.close_channel(&channel_id.0, &counterparty_node_id) {
1035+
match self.channel_manager.close_channel(&channel_id, &counterparty_node_id) {
10361036
Ok(_) => Ok(()),
10371037
Err(_) => Err(Error::ChannelClosingFailed),
10381038
}
@@ -1046,7 +1046,7 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
10461046
self.channel_manager
10471047
.update_channel_config(
10481048
&counterparty_node_id,
1049-
&[channel_id.0],
1049+
&[*channel_id],
10501050
&(*channel_config).clone().into(),
10511051
)
10521052
.map_err(|_| Error::ChannelConfigUpdateFailed)

src/types.rs

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use lightning::ln::channelmanager::ChannelDetails as LdkChannelDetails;
66
use lightning::ln::msgs::RoutingMessageHandler;
77
use lightning::ln::msgs::SocketAddress as LdkSocketAddress;
88
use lightning::ln::peer_handler::IgnoringMessageHandler;
9+
use lightning::ln::ChannelId;
910
use lightning::routing::gossip;
1011
use lightning::routing::router::DefaultRouter;
1112
use lightning::routing::scoring::{ProbabilisticScorer, ProbabilisticScoringFeeParameters};
@@ -106,28 +107,6 @@ impl lightning::onion_message::MessageRouter for FakeMessageRouter {
106107
}
107108
}
108109

109-
/// The global identifier of a channel.
110-
///
111-
/// Note that this will start out to be a temporary ID until channel funding negotiation is
112-
/// finalized, at which point it will change to be a permanent global ID tied to the on-chain
113-
/// funding transaction.
114-
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
115-
pub struct ChannelId(pub [u8; 32]);
116-
117-
impl Writeable for ChannelId {
118-
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), lightning::io::Error> {
119-
Ok(self.0.write(writer)?)
120-
}
121-
}
122-
123-
impl Readable for ChannelId {
124-
fn read<R: lightning::io::Read>(
125-
reader: &mut R,
126-
) -> Result<Self, lightning::ln::msgs::DecodeError> {
127-
Ok(Self(Readable::read(reader)?))
128-
}
129-
}
130-
131110
/// A local, potentially user-provided, identifier of a channel.
132111
///
133112
/// By default, this will be randomly generated for the user to ensure local uniqueness.
@@ -224,7 +203,7 @@ pub struct ChannelDetails {
224203
impl From<LdkChannelDetails> for ChannelDetails {
225204
fn from(value: LdkChannelDetails) -> Self {
226205
ChannelDetails {
227-
channel_id: ChannelId(value.channel_id),
206+
channel_id: value.channel_id,
228207
counterparty_node_id: value.counterparty.node_id,
229208
funding_txo: value.funding_txo.and_then(|o| Some(o.into_bitcoin_outpoint())),
230209
channel_value_sats: value.channel_value_satoshis,

src/uniffi_types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ use crate::UniffiCustomTypeConverter;
33
use crate::error::Error;
44
use crate::hex_utils;
55
use crate::io::sqlite_store::SqliteStore;
6-
use crate::{ChannelId, Node, SocketAddress, UserChannelId};
6+
use crate::{Node, SocketAddress, UserChannelId};
77

88
use bitcoin::hashes::sha256::Hash as Sha256;
99
use bitcoin::hashes::Hash;
1010
use bitcoin::secp256k1::PublicKey;
1111
use bitcoin::{Address, Txid};
12-
use lightning::ln::{PaymentHash, PaymentPreimage, PaymentSecret};
12+
use lightning::ln::{ChannelId, PaymentHash, PaymentPreimage, PaymentSecret};
1313
use lightning_invoice::{Bolt11Invoice, SignedRawBolt11Invoice};
1414

1515
use bip39::Mnemonic;

0 commit comments

Comments
 (0)