@@ -154,31 +154,56 @@ impl Liquidity {
154154 /// The given `token` will be used by the LSP to authenticate the user.
155155 /// `trust_peer_0conf` controls whether the node will accept 0-confirmation channels opened by this
156156 /// LSP. Note this supersedes [`Config::trusted_peers_0conf`] for this peer.
157- /// Duplicate `node_id`s are ignored .
157+ /// Re-adding an existing `node_id` updates its address/token/0conf settings and reconnects .
158158 pub fn add_liquidity_source (
159159 & self , node_id : PublicKey , address : SocketAddress , token : Option < String > ,
160160 trust_peer_0conf : bool ,
161161 ) -> Result < ( ) , Error > {
162+ let mut previous: Option < ( SocketAddress , Option < String > , bool , Option < Vec < u16 > > ) > = None ;
162163 {
163164 let mut lsp_nodes = self . liquidity_source . lsp_nodes . write ( ) . expect ( "lock" ) ;
164- if lsp_nodes. iter ( ) . any ( |n| n. node_id == node_id) {
165- log_info ! ( self . logger, "LSP node {} already added, skipping." , node_id) ;
166- return Ok ( ( ) ) ;
165+ if let Some ( existing) = lsp_nodes. iter_mut ( ) . find ( |n| n. node_id == node_id) {
166+ if existing. address == address {
167+ log_info ! ( self . logger, "LSP node {} already added, skipping." , node_id) ;
168+ return Ok ( ( ) ) ;
169+ }
170+ log_info ! (
171+ self . logger,
172+ "Updating existing LSP node {} address/config and reconnecting." ,
173+ node_id
174+ ) ;
175+ let prev_address = std:: mem:: replace ( & mut existing. address , address. clone ( ) ) ;
176+ let prev_token = std:: mem:: replace ( & mut existing. token , token. clone ( ) ) ;
177+ let prev_trust =
178+ std:: mem:: replace ( & mut existing. trust_peer_0conf , trust_peer_0conf) ;
179+ // Force rediscovery after config/address change.
180+ let prev_protocols = std:: mem:: take ( & mut existing. supported_protocols ) ;
181+ previous = Some ( ( prev_address, prev_token, prev_trust, prev_protocols) ) ;
182+ } else {
183+ lsp_nodes. push ( LspNode {
184+ node_id,
185+ address : address. clone ( ) ,
186+ token : token. clone ( ) ,
187+ trust_peer_0conf,
188+ supported_protocols : None ,
189+ } ) ;
167190 }
168-
169- lsp_nodes. push ( LspNode {
170- node_id,
171- address : address. clone ( ) ,
172- token : token. clone ( ) ,
173- trust_peer_0conf,
174- supported_protocols : None ,
175- } ) ;
176191 }
177192
178- // If anything below fails, drop the half-initialized entry so the user can retry cleanly .
193+ // On failure: remove half-initialized inserts; restore prior config for updates .
179194 let lsp_nodes = Arc :: clone ( & self . liquidity_source . lsp_nodes ) ;
180195 let cleanup = move || {
181- lsp_nodes. write ( ) . expect ( "lock" ) . retain ( |n| n. node_id != node_id) ;
196+ let mut nodes = lsp_nodes. write ( ) . expect ( "lock" ) ;
197+ if let Some ( ( prev_address, prev_token, prev_trust, prev_protocols) ) = previous {
198+ if let Some ( existing) = nodes. iter_mut ( ) . find ( |n| n. node_id == node_id) {
199+ existing. address = prev_address;
200+ existing. token = prev_token;
201+ existing. trust_peer_0conf = prev_trust;
202+ existing. supported_protocols = prev_protocols;
203+ }
204+ } else {
205+ nodes. retain ( |n| n. node_id != node_id) ;
206+ }
182207 } ;
183208
184209 let con_cm = Arc :: clone ( & self . connection_manager ) ;
0 commit comments