@@ -154,31 +154,59 @@ 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+ && existing. token == token
168+ && existing. trust_peer_0conf == trust_peer_0conf
169+ {
170+ log_info ! ( self . logger, "LSP node {} already added, skipping." , node_id) ;
171+ return Ok ( ( ) ) ;
172+ }
173+ log_info ! (
174+ self . logger,
175+ "Updating existing LSP node {} address/config and reconnecting." ,
176+ node_id
177+ ) ;
178+ let prev_address = std:: mem:: replace ( & mut existing. address , address. clone ( ) ) ;
179+ let prev_token = std:: mem:: replace ( & mut existing. token , token. clone ( ) ) ;
180+ let prev_trust =
181+ std:: mem:: replace ( & mut existing. trust_peer_0conf , trust_peer_0conf) ;
182+ // Force rediscovery after config/address change.
183+ let prev_protocols = std:: mem:: take ( & mut existing. supported_protocols ) ;
184+ previous = Some ( ( prev_address, prev_token, prev_trust, prev_protocols) ) ;
185+ } else {
186+ lsp_nodes. push ( LspNode {
187+ node_id,
188+ address : address. clone ( ) ,
189+ token : token. clone ( ) ,
190+ trust_peer_0conf,
191+ supported_protocols : None ,
192+ } ) ;
167193 }
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- } ) ;
176194 }
177195
178- // If anything below fails, drop the half-initialized entry so the user can retry cleanly .
196+ // On failure: remove half-initialized inserts; restore prior config for updates .
179197 let lsp_nodes = Arc :: clone ( & self . liquidity_source . lsp_nodes ) ;
180198 let cleanup = move || {
181- lsp_nodes. write ( ) . expect ( "lock" ) . retain ( |n| n. node_id != node_id) ;
199+ let mut nodes = lsp_nodes. write ( ) . expect ( "lock" ) ;
200+ if let Some ( ( prev_address, prev_token, prev_trust, prev_protocols) ) = previous {
201+ if let Some ( existing) = nodes. iter_mut ( ) . find ( |n| n. node_id == node_id) {
202+ existing. address = prev_address;
203+ existing. token = prev_token;
204+ existing. trust_peer_0conf = prev_trust;
205+ existing. supported_protocols = prev_protocols;
206+ }
207+ } else {
208+ nodes. retain ( |n| n. node_id != node_id) ;
209+ }
182210 } ;
183211
184212 let con_cm = Arc :: clone ( & self . connection_manager ) ;
@@ -225,6 +253,7 @@ pub(crate) struct LspConfig {
225253 pub trust_peer_0conf : bool ,
226254}
227255
256+ #[ derive( Clone ) ]
228257pub ( crate ) struct LspNode {
229258 node_id : PublicKey ,
230259 address : SocketAddress ,
@@ -234,6 +263,17 @@ pub(crate) struct LspNode {
234263 supported_protocols : Option < Vec < u16 > > ,
235264}
236265
266+ impl PartialEq for LspNode {
267+ fn eq ( & self , other : & Self ) -> bool {
268+ self . node_id == other. node_id
269+ && self . address == other. address
270+ && self . token == other. token
271+ && self . trust_peer_0conf == other. trust_peer_0conf
272+ }
273+ }
274+
275+ impl Eq for LspNode { }
276+
237277pub ( crate ) struct LiquiditySourceBuilder < L : Deref >
238278where
239279 L :: Target : LdkLogger ,
0 commit comments