Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions bindings/ldk_node.udl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace ldk_node {

typedef dictionary Config;

typedef dictionary NodeColor;

typedef dictionary EsploraSyncConfig;

typedef dictionary ElectrumSyncConfig;
Expand Down Expand Up @@ -58,6 +60,7 @@ interface Builder {
void set_tor_config(TorConfig tor_config);
[Throws=BuildError]
void set_node_alias(string node_alias);
void set_node_color(u8 red, u8 green, u8 blue);
[Throws=BuildError]
void set_async_payments_role(AsyncPaymentsRole? role);
void set_wallet_recovery_mode();
Expand Down Expand Up @@ -92,6 +95,7 @@ interface Node {
sequence<SocketAddress>? listening_addresses();
sequence<SocketAddress>? announcement_addresses();
NodeAlias? node_alias();
NodeColor node_color();
Bolt11Payment bolt11_payment();
Bolt12Payment bolt12_payment();
SpontaneousPayment spontaneous_payment();
Expand Down
23 changes: 22 additions & 1 deletion src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,14 @@ impl NodeBuilder {
Ok(self)
}

/// Sets the RGB color that will be used when broadcasting announcements to the gossip network.
pub fn set_node_color(&mut self, red: u8, green: u8, blue: u8) -> &mut Self {
self.config.node_color.red = red;
self.config.node_color.green = green;
self.config.node_color.blue = blue;
self
}

/// Sets the role of the node in an asynchronous payments context.
///
/// See <https://github.com/lightning/bolts/pull/1149> for more information about the async payments protocol.
Expand Down Expand Up @@ -1093,6 +1101,11 @@ impl ArcedNodeBuilder {
self.inner.write().expect("lock").set_node_alias(node_alias).map(|_| ())
}

/// Sets the RGB color that will be used when broadcasting announcements to the gossip network.
pub fn set_node_color(&self, red: u8, green: u8, blue: u8) {
self.inner.write().expect("lock").set_node_color(red, green, blue);
}

/// Sets the role of the node in an asynchronous payments context.
pub fn set_async_payments_role(
&self, role: Option<AsyncPaymentsRole>,
Expand Down Expand Up @@ -2155,7 +2168,15 @@ pub(crate) fn sanitize_alias(alias_str: &str) -> Result<NodeAlias, BuildError> {

#[cfg(test)]
mod tests {
use super::{sanitize_alias, BuildError, NodeAlias};
use super::{sanitize_alias, BuildError, NodeAlias, NodeBuilder};

#[test]
fn set_node_color_updates_config() {
let mut builder = NodeBuilder::new();
builder.set_node_color(1, 2, 3);

assert_eq!(builder.config.node_color.as_rgb(), [1, 2, 3]);
}

#[test]
fn sanitize_empty_node_alias() {
Expand Down
48 changes: 35 additions & 13 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,20 @@ pub(crate) const LNURL_AUTH_TIMEOUT_SECS: u64 = 15;
///
/// ### Defaults
///
/// | Parameter | Value |
/// |----------------------------------------|--------------------------------------|
/// | `storage_dir_path` | /tmp/ldk_node/ |
/// | `network` | Bitcoin |
/// | `listening_addresses` | None |
/// | `announcement_addresses` | None |
/// | `node_alias` | None |
/// | `trusted_peers_0conf` | [] |
/// | `probing_liquidity_limit_multiplier` | 3 |
/// | `anchor_channels_config` | Some(..) |
/// | `route_parameters` | None |
/// | `tor_config` | None |
/// | `hrn_config` | HumanReadableNamesConfig::default() |
/// | Parameter | Value |
/// |----------------------------------------|--------------------------------------------|
/// | `storage_dir_path` | /tmp/ldk_node/ |
/// | `network` | Bitcoin |
/// | `listening_addresses` | None |
/// | `announcement_addresses` | None |
/// | `node_alias` | None |
/// | `node_color` | NodeColor { red: 0, green: 0, blue: 0 } |
/// | `trusted_peers_0conf` | [] |
/// | `probing_liquidity_limit_multiplier` | 3 |
/// | `anchor_channels_config` | Some(..) |
/// | `route_parameters` | None |
/// | `tor_config` | None |
/// | `hrn_config` | HumanReadableNamesConfig::default() |
///
/// See [`AnchorChannelsConfig`] and [`RouteParametersConfig`] for more information regarding their
/// respective default values.
Expand Down Expand Up @@ -158,6 +159,8 @@ pub struct Config {
/// **Note**: We will only allow opening and accepting public channels if the `node_alias` and the
/// `listening_addresses` are set.
pub node_alias: Option<NodeAlias>,
/// The RGB color that will be used when broadcasting announcements to the gossip network.
pub node_color: NodeColor,
/// A list of peers that we allow to establish zero confirmation channels to us.
///
/// **Note:** Allowing payments via zero-confirmation channels is potentially insecure if the
Expand Down Expand Up @@ -220,11 +223,30 @@ impl Default for Config {
tor_config: None,
route_parameters: None,
node_alias: None,
node_color: NodeColor::default(),
hrn_config: HumanReadableNamesConfig::default(),
}
}
}

/// The RGB color that will be used when broadcasting node announcements.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
pub struct NodeColor {
/// The red color component.
pub red: u8,
/// The green color component.
pub green: u8,
/// The blue color component.
pub blue: u8,
}

impl NodeColor {
pub(crate) fn as_rgb(&self) -> [u8; 3] {
[self.red, self.green, self.blue]
}
}

/// Configuration options for how our node resolves Human-Readable Names (BIP 353).
///
/// [BIP 353]: https://github.com/bitcoin/bips/blob/master/bip-0353.mediawiki
Expand Down
5 changes: 5 additions & 0 deletions src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ use lightning::routing::gossip::RoutingFees;
#[cfg(not(feature = "uniffi"))]
use lightning::routing::gossip::{ChannelInfo, NodeInfo};

#[cfg(feature = "uniffi")]
use crate::config::NodeColor;
use crate::types::Graph;

/// Represents the network as nodes and channels between them.
Expand Down Expand Up @@ -159,6 +161,8 @@ pub struct NodeAnnouncementInfo {
/// May be invalid or malicious (eg control chars),
/// should not be exposed to the user.
pub alias: String,
/// RGB color assigned to the node.
pub color: NodeColor,
/// List of addresses on which this node is reachable
pub addresses: Vec<SocketAddress>,
}
Expand All @@ -169,6 +173,7 @@ impl From<lightning::routing::gossip::NodeAnnouncementInfo> for NodeAnnouncement
Self {
last_update: value.last_update(),
alias: value.alias().to_string(),
color: NodeColor { red: value.rgb()[0], green: value.rgb()[1], blue: value.rgb()[2] },
addresses: value.addresses().iter().cloned().collect(),
}
}
Expand Down
9 changes: 8 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ pub use builder::BuildError;
#[cfg(not(feature = "uniffi"))]
pub use builder::NodeBuilder as Builder;
use chain::ChainSource;
#[cfg(feature = "uniffi")]
use config::NodeColor;
use config::{
default_user_config, may_announce_channel, AsyncPaymentsRole, ChannelConfig, Config,
LNURL_AUTH_TIMEOUT_SECS, NODE_ANN_BCAST_INTERVAL, PEER_RECONNECTION_INTERVAL,
Expand Down Expand Up @@ -538,7 +540,7 @@ impl Node {
};

if let Some(node_alias) = node_alias.as_ref() {
bcast_pm.broadcast_node_announcement([0; 3], node_alias.0, addresses);
bcast_pm.broadcast_node_announcement(bcast_config.node_color.as_rgb(), node_alias.0, addresses);

let unix_time_secs_opt =
SystemTime::now().duration_since(UNIX_EPOCH).ok().map(|d| d.as_secs());
Expand Down Expand Up @@ -873,6 +875,11 @@ impl Node {
self.config.node_alias
}

/// Returns our node color.
pub fn node_color(&self) -> crate::config::NodeColor {
self.config.node_color
}

/// Returns a payment handler allowing to create and pay [BOLT 11] invoices.
///
/// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
Expand Down
Loading