Skip to content

Commit ed0c932

Browse files
committed
f: review comments
1 parent fd7500f commit ed0c932

File tree

6 files changed

+40
-20
lines changed

6 files changed

+40
-20
lines changed

bindings/ldk_node.udl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ interface Builder {
9494
void set_announcement_addresses(sequence<SocketAddress> announcement_addresses);
9595
[Throws=BuildError]
9696
void set_node_alias(string node_alias);
97+
[Throws=BuildError]
9798
void set_async_payments_role(AsyncPaymentsRole? role);
9899
[Throws=BuildError]
99100
Node build();
@@ -356,6 +357,7 @@ enum BuildError {
356357
"WalletSetupFailed",
357358
"LoggerSetupFailed",
358359
"NetworkMismatch",
360+
"AsyncPaymentsConfigMismatch",
359361
};
360362

361363
[Trait]

src/builder.rs

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ pub enum BuildError {
192192
LoggerSetupFailed,
193193
/// The given network does not match the node's previously configured network.
194194
NetworkMismatch,
195+
/// The role of the node in an asynchronous payments context is not compatible with the current configuration.
196+
AsyncPaymentsConfigMismatch,
195197
}
196198

197199
impl fmt::Display for BuildError {
@@ -220,6 +222,12 @@ impl fmt::Display for BuildError {
220222
Self::NetworkMismatch => {
221223
write!(f, "Given network does not match the node's previously configured network.")
222224
},
225+
Self::AsyncPaymentsConfigMismatch => {
226+
write!(
227+
f,
228+
"The async payments role is not compatible with the current configuration."
229+
)
230+
},
223231
}
224232
}
225233
}
@@ -241,8 +249,8 @@ pub struct NodeBuilder {
241249
gossip_source_config: Option<GossipSourceConfig>,
242250
liquidity_source_config: Option<LiquiditySourceConfig>,
243251
log_writer_config: Option<LogWriterConfig>,
244-
runtime_handle: Option<tokio::runtime::Handle>,
245252
async_payments_role: Option<AsyncPaymentsRole>,
253+
runtime_handle: Option<tokio::runtime::Handle>,
246254
}
247255

248256
impl NodeBuilder {
@@ -547,10 +555,18 @@ impl NodeBuilder {
547555
Ok(self)
548556
}
549557

550-
/// Sets the role of the node in an asynchronous payments context.
551-
pub fn set_async_payments_role(&mut self, role: Option<AsyncPaymentsRole>) -> &mut Self {
558+
/// Sets the role of the node in an asynchronous payments context. See https://github.com/lightning/bolts/pull/1149
559+
/// for more information about the async payments protocol.
560+
pub fn set_async_payments_role(
561+
&mut self, role: Option<AsyncPaymentsRole>,
562+
) -> Result<&mut Self, BuildError> {
563+
if let Some(AsyncPaymentsRole::Server) = role {
564+
may_announce_channel(&self.config)
565+
.map_err(|_| BuildError::AsyncPaymentsConfigMismatch)?;
566+
}
567+
552568
self.async_payments_role = role;
553-
self
569+
Ok(self)
554570
}
555571

556572
/// Builds a [`Node`] instance with a [`SqliteStore`] backend and according to the options
@@ -709,11 +725,11 @@ impl NodeBuilder {
709725
self.chain_data_source_config.as_ref(),
710726
self.gossip_source_config.as_ref(),
711727
self.liquidity_source_config.as_ref(),
728+
self.async_payments_role,
712729
seed_bytes,
713730
runtime,
714731
logger,
715732
Arc::new(vss_store),
716-
self.async_payments_role,
717733
)
718734
}
719735

@@ -742,11 +758,11 @@ impl NodeBuilder {
742758
self.chain_data_source_config.as_ref(),
743759
self.gossip_source_config.as_ref(),
744760
self.liquidity_source_config.as_ref(),
761+
self.async_payments_role,
745762
seed_bytes,
746763
runtime,
747764
logger,
748765
kv_store,
749-
self.async_payments_role,
750766
)
751767
}
752768
}
@@ -1001,8 +1017,10 @@ impl ArcedNodeBuilder {
10011017
}
10021018

10031019
/// Sets the role of the node in an asynchronous payments context.
1004-
pub fn set_async_payments_role(&self, role: Option<AsyncPaymentsRole>) {
1005-
_ = self.inner.write().unwrap().set_async_payments_role(role)
1020+
pub fn set_async_payments_role(
1021+
&self, role: Option<AsyncPaymentsRole>,
1022+
) -> Result<(), BuildError> {
1023+
self.inner.write().unwrap().set_async_payments_role(role).map(|_| ())
10061024
}
10071025

10081026
/// Builds a [`Node`] instance with a [`SqliteStore`] backend and according to the options
@@ -1098,9 +1116,9 @@ impl ArcedNodeBuilder {
10981116
fn build_with_store_internal(
10991117
config: Arc<Config>, chain_data_source_config: Option<&ChainDataSourceConfig>,
11001118
gossip_source_config: Option<&GossipSourceConfig>,
1101-
liquidity_source_config: Option<&LiquiditySourceConfig>, seed_bytes: [u8; 64],
1102-
runtime: Arc<Runtime>, logger: Arc<Logger>, kv_store: Arc<DynStore>,
1103-
async_payments_role: Option<AsyncPaymentsRole>,
1119+
liquidity_source_config: Option<&LiquiditySourceConfig>,
1120+
async_payments_role: Option<AsyncPaymentsRole>, seed_bytes: [u8; 64], runtime: Arc<Runtime>,
1121+
logger: Arc<Logger>, kv_store: Arc<DynStore>,
11041122
) -> Result<Node, BuildError> {
11051123
optionally_install_rustls_cryptoprovider();
11061124

src/config.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -535,12 +535,13 @@ impl From<MaxDustHTLCExposure> for LdkMaxDustHTLCExposure {
535535
}
536536

537537
#[derive(Debug, Clone, Copy)]
538-
/// The role of the node in an asynchronous payments context.
538+
/// The role of the node in an asynchronous payments context. See https://github.com/lightning/bolts/pull/1149 for more
539+
/// information about the async payments protocol.
539540
pub enum AsyncPaymentsRole {
540541
/// Node acts a client in an async payments context. This means that if possible, it will instruct its peers to hold
541-
/// htlcs for it, so that it can go offline.
542+
/// HTLCs for it, so that it can go offline.
542543
Client,
543-
/// Node acts as a server in an async payments context. This means that it will hold async payments htlcs and onion
544+
/// Node acts as a server in an async payments context. This means that it will hold async payments HTLCs and onion
544545
/// messages for its peers.
545546
Server,
546547
}

src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,9 @@ pub use builder::BuildError;
126126
pub use builder::NodeBuilder as Builder;
127127

128128
use chain::ChainSource;
129-
use config::AsyncPaymentsRole;
130129
use config::{
131-
default_user_config, may_announce_channel, ChannelConfig, Config, NODE_ANN_BCAST_INTERVAL,
132-
PEER_RECONNECTION_INTERVAL, RGS_SYNC_INTERVAL,
130+
default_user_config, may_announce_channel, AsyncPaymentsRole, ChannelConfig, Config,
131+
NODE_ANN_BCAST_INTERVAL, PEER_RECONNECTION_INTERVAL, RGS_SYNC_INTERVAL,
133132
};
134133
use connection::ConnectionManager;
135134
use event::{EventHandler, EventQueue};

src/payment/asynchronous/om_mailbox.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use bitcoin::secp256k1::PublicKey;
55
use lightning::ln::msgs::OnionMessage;
66

77
pub(crate) struct OnionMessageMailbox {
8-
map: Mutex<HashMap<bitcoin::secp256k1::PublicKey, VecDeque<lightning::ln::msgs::OnionMessage>>>,
8+
map: Mutex<HashMap<PublicKey, VecDeque<OnionMessage>>>,
99
}
1010

1111
impl OnionMessageMailbox {
@@ -35,7 +35,7 @@ impl OnionMessageMailbox {
3535
}
3636

3737
pub(crate) fn onion_message_peer_connected(
38-
&self, peer_node_id: bitcoin::secp256k1::PublicKey,
38+
&self, peer_node_id: PublicKey,
3939
) -> Vec<OnionMessage> {
4040
let mut map = self.map.lock().unwrap();
4141

tests/common/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ pub(crate) fn setup_node_for_async_payments(
382382
}
383383
}
384384

385-
builder.set_async_payments_role(async_payments_role);
385+
builder.set_async_payments_role(async_payments_role).unwrap();
386386

387387
let test_sync_store = Arc::new(TestSyncStore::new(config.node_config.storage_dir_path.into()));
388388
let node = builder.build_with_store(test_sync_store).unwrap();

0 commit comments

Comments
 (0)