@@ -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
197199impl 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
248256impl 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 {
10981116fn 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
0 commit comments