@@ -192,6 +192,8 @@ pub enum BuildError {
192
192
LoggerSetupFailed ,
193
193
/// The given network does not match the node's previously configured network.
194
194
NetworkMismatch ,
195
+ /// The role of the node in an asynchronous payments context is not compatible with the current configuration.
196
+ AsyncPaymentsConfigMismatch ,
195
197
}
196
198
197
199
impl fmt:: Display for BuildError {
@@ -220,6 +222,12 @@ impl fmt::Display for BuildError {
220
222
Self :: NetworkMismatch => {
221
223
write ! ( f, "Given network does not match the node's previously configured network." )
222
224
} ,
225
+ Self :: AsyncPaymentsConfigMismatch => {
226
+ write ! (
227
+ f,
228
+ "The async payments role is not compatible with the current configuration."
229
+ )
230
+ } ,
223
231
}
224
232
}
225
233
}
@@ -241,8 +249,8 @@ pub struct NodeBuilder {
241
249
gossip_source_config : Option < GossipSourceConfig > ,
242
250
liquidity_source_config : Option < LiquiditySourceConfig > ,
243
251
log_writer_config : Option < LogWriterConfig > ,
244
- runtime_handle : Option < tokio:: runtime:: Handle > ,
245
252
async_payments_role : Option < AsyncPaymentsRole > ,
253
+ runtime_handle : Option < tokio:: runtime:: Handle > ,
246
254
}
247
255
248
256
impl NodeBuilder {
@@ -547,10 +555,18 @@ impl NodeBuilder {
547
555
Ok ( self )
548
556
}
549
557
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
+
552
568
self . async_payments_role = role;
553
- self
569
+ Ok ( self )
554
570
}
555
571
556
572
/// Builds a [`Node`] instance with a [`SqliteStore`] backend and according to the options
@@ -709,11 +725,11 @@ impl NodeBuilder {
709
725
self . chain_data_source_config . as_ref ( ) ,
710
726
self . gossip_source_config . as_ref ( ) ,
711
727
self . liquidity_source_config . as_ref ( ) ,
728
+ self . async_payments_role ,
712
729
seed_bytes,
713
730
runtime,
714
731
logger,
715
732
Arc :: new ( vss_store) ,
716
- self . async_payments_role ,
717
733
)
718
734
}
719
735
@@ -742,11 +758,11 @@ impl NodeBuilder {
742
758
self . chain_data_source_config . as_ref ( ) ,
743
759
self . gossip_source_config . as_ref ( ) ,
744
760
self . liquidity_source_config . as_ref ( ) ,
761
+ self . async_payments_role ,
745
762
seed_bytes,
746
763
runtime,
747
764
logger,
748
765
kv_store,
749
- self . async_payments_role ,
750
766
)
751
767
}
752
768
}
@@ -1001,8 +1017,10 @@ impl ArcedNodeBuilder {
1001
1017
}
1002
1018
1003
1019
/// 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 ( |_| ( ) )
1006
1024
}
1007
1025
1008
1026
/// Builds a [`Node`] instance with a [`SqliteStore`] backend and according to the options
@@ -1098,9 +1116,9 @@ impl ArcedNodeBuilder {
1098
1116
fn build_with_store_internal (
1099
1117
config : Arc < Config > , chain_data_source_config : Option < & ChainDataSourceConfig > ,
1100
1118
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 > ,
1104
1122
) -> Result < Node , BuildError > {
1105
1123
optionally_install_rustls_cryptoprovider ( ) ;
1106
1124
0 commit comments