Skip to content

Commit f78e6b9

Browse files
committed
Use NodeAlias type in NodeAnnouncement
1 parent 157af6e commit f78e6b9

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

lightning/src/ln/msgs.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ use crate::util::ser::{LengthReadable, Readable, ReadableArgs, Writeable, Writer
4646

4747
use crate::ln::{PaymentPreimage, PaymentHash, PaymentSecret};
4848

49-
use crate::routing::gossip::NodeId;
49+
use crate::routing::gossip::{NodeAlias, NodeId};
5050

5151
/// 21 million * 10^8 * 1000
5252
pub(crate) const MAX_VALUE_MSAT: u64 = 21_000_000_0000_0000_000;
@@ -694,7 +694,7 @@ pub struct UnsignedNodeAnnouncement {
694694
/// An alias, for UI purposes.
695695
///
696696
/// This should be sanitized before use. There is no guarantee of uniqueness.
697-
pub alias: [u8; 32],
697+
pub alias: NodeAlias,
698698
/// List of addresses on which this node is reachable
699699
pub addresses: Vec<NetAddress>,
700700
pub(crate) excess_address_data: Vec<u8>,
@@ -1931,7 +1931,7 @@ impl Readable for UnsignedNodeAnnouncement {
19311931
let node_id: NodeId = Readable::read(r)?;
19321932
let mut rgb = [0; 3];
19331933
r.read_exact(&mut rgb)?;
1934-
let alias: [u8; 32] = Readable::read(r)?;
1934+
let alias: NodeAlias = Readable::read(r)?;
19351935

19361936
let addr_len: u16 = Readable::read(r)?;
19371937
let mut addresses: Vec<NetAddress> = Vec::new();
@@ -2138,7 +2138,7 @@ mod tests {
21382138
use crate::ln::features::{ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures};
21392139
use crate::ln::msgs;
21402140
use crate::ln::msgs::{FinalOnionHopData, OptionalField, OnionErrorPacket, OnionHopDataFormat};
2141-
use crate::routing::gossip::NodeId;
2141+
use crate::routing::gossip::{NodeAlias, NodeId};
21422142
use crate::util::ser::{Writeable, Readable, Hostname};
21432143

21442144
use bitcoin::hashes::hex::FromHex;
@@ -2333,7 +2333,7 @@ mod tests {
23332333
timestamp: 20190119,
23342334
node_id: NodeId::from_pubkey(&pubkey_1),
23352335
rgb: [32; 3],
2336-
alias: [16;32],
2336+
alias: NodeAlias([16;32]),
23372337
addresses,
23382338
excess_address_data: if excess_address_data { vec![33, 108, 40, 11, 83, 149, 162, 84, 110, 126, 75, 38, 99, 224, 79, 129, 22, 34, 241, 90, 79, 146, 232, 58, 162, 233, 43, 162, 165, 115, 193, 57, 20, 44, 84, 174, 99, 7, 42, 30, 193, 238, 125, 192, 192, 75, 222, 92, 132, 120, 6, 23, 42, 160, 92, 146, 194, 42, 232, 227, 8, 209, 210, 105] } else { Vec::new() },
23392339
excess_data: if excess_data { vec![59, 18, 204, 25, 92, 224, 162, 209, 189, 166, 168, 139, 239, 161, 159, 160, 127, 81, 202, 167, 92, 232, 56, 55, 242, 137, 101, 96, 11, 138, 172, 171, 8, 85, 255, 176, 231, 65, 236, 95, 124, 65, 66, 30, 152, 41, 169, 212, 134, 17, 200, 200, 49, 247, 27, 229, 234, 115, 230, 101, 148, 151, 127, 253] } else { Vec::new() },

lightning/src/ln/peer_handler.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use crate::ln::peer_channel_encryptor::{PeerChannelEncryptor,NextNoiseStep};
2828
use crate::ln::wire;
2929
use crate::ln::wire::Encode;
3030
use crate::onion_message::{CustomOnionMessageContents, CustomOnionMessageHandler, SimpleArcOnionMessenger, SimpleRefOnionMessenger};
31-
use crate::routing::gossip::{NetworkGraph, P2PGossipSync, NodeId};
31+
use crate::routing::gossip::{NetworkGraph, P2PGossipSync, NodeId, NodeAlias};
3232
use crate::util::atomic_counter::AtomicCounter;
3333
use crate::util::logger::Logger;
3434

@@ -2153,7 +2153,9 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
21532153
features,
21542154
timestamp: self.last_node_announcement_serial.fetch_add(1, Ordering::AcqRel),
21552155
node_id: NodeId::from_pubkey(&self.node_signer.get_node_id(Recipient::Node).unwrap()),
2156-
rgb, alias, addresses,
2156+
rgb,
2157+
alias: NodeAlias(alias),
2158+
addresses,
21572159
excess_address_data: Vec::new(),
21582160
excess_data: Vec::new(),
21592161
};

lightning/src/routing/gossip.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,7 @@ impl Readable for NodeAnnouncementInfo {
11031103
///
11041104
/// Since node aliases are provided by third parties, they are a potential avenue for injection
11051105
/// attacks. Care must be taken when processing.
1106-
#[derive(Clone, Debug, PartialEq, Eq)]
1106+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
11071107
pub struct NodeAlias(pub [u8; 32]);
11081108

11091109
impl fmt::Display for NodeAlias {
@@ -1396,7 +1396,7 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
13961396
features: msg.features.clone(),
13971397
last_update: msg.timestamp,
13981398
rgb: msg.rgb,
1399-
alias: NodeAlias(msg.alias),
1399+
alias: msg.alias,
14001400
announcement_message: if should_relay { full_msg.cloned() } else { None },
14011401
});
14021402

@@ -2029,7 +2029,7 @@ pub(crate) mod tests {
20292029
timestamp: 100,
20302030
node_id,
20312031
rgb: [0; 3],
2032-
alias: [0; 32],
2032+
alias: NodeAlias([0; 32]),
20332033
addresses: Vec::new(),
20342034
excess_address_data: Vec::new(),
20352035
excess_data: Vec::new(),

lightning/src/routing/test_utils.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// You may not use this file except in accordance with one or both of these
88
// licenses.
99

10-
use crate::routing::gossip::{NetworkGraph, P2PGossipSync};
10+
use crate::routing::gossip::{NetworkGraph, NodeAlias, P2PGossipSync};
1111
use crate::ln::features::{ChannelFeatures, NodeFeatures};
1212
use crate::ln::msgs::{UnsignedChannelAnnouncement, ChannelAnnouncement, RoutingMessageHandler,
1313
NodeAnnouncement, UnsignedNodeAnnouncement, ChannelUpdate, UnsignedChannelUpdate, MAX_VALUE_MSAT};
@@ -72,7 +72,7 @@ pub(super) fn add_or_update_node(
7272
timestamp,
7373
node_id,
7474
rgb: [0; 3],
75-
alias: [0; 32],
75+
alias: NodeAlias([0; 32]),
7676
addresses: Vec::new(),
7777
excess_address_data: Vec::new(),
7878
excess_data: Vec::new(),

0 commit comments

Comments
 (0)