Skip to content

Commit 50565dc

Browse files
committed
Review findings, minor, renames, simplification
1 parent 3a46ad3 commit 50565dc

File tree

3 files changed

+13
-22
lines changed

3 files changed

+13
-22
lines changed

lightning/src/chain/transaction.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
1212
use crate::ln::channel::ChannelId;
1313
use bitcoin::hash_types::Txid;
14+
use bitcoin::hashes::Hash;
1415
use bitcoin::blockdata::transaction::OutPoint as BitcoinOutPoint;
1516
use bitcoin::blockdata::transaction::Transaction;
1617

@@ -57,9 +58,9 @@ pub struct OutPoint {
5758
}
5859

5960
impl OutPoint {
60-
/// Convert an `OutPoint` to a lightning channel id. Alternatively use ChannelId::from_funding_outpoint().
61+
/// Convert an `OutPoint` to a lightning channel id.
6162
pub fn to_channel_id(&self) -> ChannelId {
62-
ChannelId::from_funding_outpoint(&self)
63+
ChannelId::v1_from_funding_txid(&self.txid.as_inner(), self.index)
6364
}
6465

6566
/// Converts this OutPoint into the OutPoint field as used by rust-bitcoin

lightning/src/ln/channel.rs

+9-19
Original file line numberDiff line numberDiff line change
@@ -610,13 +610,8 @@ pub struct ChannelId {
610610
}
611611

612612
impl ChannelId {
613-
/// Create channel ID based on a funding TX outpoint
614-
pub fn from_funding_outpoint(funding_tx_outpoint: &OutPoint) -> Self {
615-
Self::from_funding_txid(&funding_tx_outpoint.txid.as_inner(), funding_tx_outpoint.index)
616-
}
617-
618-
/// Create channel ID based on a funding TX ID and output index
619-
pub fn from_funding_txid(txid: &[u8; 32], output_index: u16) -> Self {
613+
/// Create v1 channel ID based on a funding TX ID and output index
614+
pub fn v1_from_funding_txid(txid: &[u8; 32], output_index: u16) -> Self {
620615
let mut res = [0; 32];
621616
res[..].copy_from_slice(&txid[..]);
622617
res[30] ^= ((output_index >> 8) & 0xff) as u8;
@@ -625,13 +620,13 @@ impl ChannelId {
625620
}
626621

627622
/// Create a temporary channel ID randomly, based on an entropy source.
628-
pub fn from_entropy_source<ES: Deref>(entropy_source: &ES) -> Self
623+
pub fn temporary_from_entropy_source<ES: Deref>(entropy_source: &ES) -> Self
629624
where ES::Target: EntropySource {
630625
Self::from_bytes(entropy_source.get_secure_random_bytes())
631626
}
632627

633628
/// Generic constructor; create a new channel ID from the provided data.
634-
/// Use a more specific from_* constructor when possible.
629+
/// Use a more specific *from_* constructor when possible.
635630
/// This constructor is useful for tests, and internally, e.g. when the channel ID is being deserialized.
636631
pub fn from_bytes(data: [u8; 32]) -> Self {
637632
Self{data}
@@ -646,11 +641,6 @@ impl ChannelId {
646641
pub fn bytes(&self) -> &[u8; 32] {
647642
&self.data
648643
}
649-
650-
/// Serialization helper
651-
pub fn serialized_length(&self) -> usize {
652-
self.bytes().serialized_length()
653-
}
654644
}
655645

656646
impl Writeable for ChannelId {
@@ -5676,7 +5666,7 @@ impl<Signer: WriteableEcdsaChannelSigner> OutboundV1Channel<Signer> {
56765666
Err(_) => return Err(APIError::ChannelUnavailable { err: "Failed to get destination script".to_owned()}),
56775667
};
56785668

5679-
let temporary_channel_id = ChannelId::from_entropy_source(entropy_source);
5669+
let temporary_channel_id = ChannelId::temporary_from_entropy_source(entropy_source);
56805670

56815671
Ok(Self {
56825672
context: ChannelContext {
@@ -7575,15 +7565,15 @@ mod tests {
75757565

75767566
#[test]
75777567
fn test_channel_id_from_funding_tx2() {
7578-
let channel_id = ChannelId::from_funding_txid(&[2; 32], 1);
7568+
let channel_id = ChannelId::v1_from_funding_txid(&[2; 32], 1);
75797569
assert_eq!(channel_id.to_hex(), "0202020202020202020202020202020202020202020202020202020202020203");
75807570
}
75817571

75827572
#[test]
75837573
fn test_channel_id_equals() {
7584-
let channel_id11 = ChannelId::from_funding_txid(&[2; 32], 2);
7585-
let channel_id12 = ChannelId::from_funding_txid(&[2; 32], 2);
7586-
let channel_id21 = ChannelId::from_funding_txid(&[2; 32], 42);
7574+
let channel_id11 = ChannelId::v1_from_funding_txid(&[2; 32], 2);
7575+
let channel_id12 = ChannelId::v1_from_funding_txid(&[2; 32], 2);
7576+
let channel_id21 = ChannelId::v1_from_funding_txid(&[2; 32], 42);
75877577
assert_eq!(channel_id11, channel_id12);
75887578
assert_ne!(channel_id11, channel_id21);
75897579
}

lightning/src/ln/channelmanager.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10526,7 +10526,7 @@ mod tests {
1052610526

1052710527
// If we provide a channel_id not associated with the peer, we should get an error and no updates
1052810528
// should be applied to ensure update atomicity as specified in the API docs.
10529-
let bad_channel_id = ChannelId::from_funding_txid(&[10; 32], 10);
10529+
let bad_channel_id = ChannelId::v1_from_funding_txid(&[10; 32], 10);
1053010530
let current_fee = nodes[0].node.list_channels()[0].config.unwrap().forwarding_fee_proportional_millionths;
1053110531
let new_fee = current_fee + 100;
1053210532
assert!(

0 commit comments

Comments
 (0)