From 3e1ba7906c99c9542a82c04a410d05870522e2db Mon Sep 17 00:00:00 2001 From: Bartok9 <259807879+Bartok9@users.noreply.github.com> Date: Mon, 12 Oct 2026 08:59:53 -0400 Subject: [PATCH 1/2] fix(liquidity): update LspNode in place on re-add When an existing LSP node_id is re-added with a new address/token/0conf, update the existing LspNode entry in place rather than silently dropping the new values. Compare all three fields and reconnect/rediscover only when the address changes; do not mem::take supported_protocols before connect+discover; guard failure cleanup with a generation counter so a stale write cannot clobber newer state. Related to #700 (peer_store upsert in #1002; this fixes the LSP config side). Test: add_liquidity_source_updates_existing_lsp_in_place verifies re-add updates address, token, and 0conf settings. AI-assisted (Sera). Signed-off-by: Bartok9 <259807879+Bartok9@users.noreply.github.com> --- src/builder.rs | 61 +++++++++++++++++++- src/liquidity/mod.rs | 129 ++++++++++++++++++++++++++++++++----------- 2 files changed, 156 insertions(+), 34 deletions(-) diff --git a/src/builder.rs b/src/builder.rs index ff7626ae26..9460de1c47 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -525,7 +525,7 @@ impl NodeBuilder { /// 0-confirmation channels opened by this LSP. If `false`, 0-confirmation /// acceptance for this peer falls back to [`Config::trusted_peers_0conf`]. /// - /// May be called multiple times to register several LSPs. Duplicate `node_id`s are ignored. + /// May be called multiple times to register several LSPs. Re-adding an existing `node_id` updates its address, token, and 0conf trust settings. /// /// [bLIP-50 / LSPS0]: https://github.com/lightning/blips/blob/master/blip-0050.md pub fn add_liquidity_source( @@ -535,7 +535,12 @@ impl NodeBuilder { let liquidity_source_config = self.liquidity_source_config.get_or_insert(LiquiditySourceConfig::default()); - if liquidity_source_config.lsp_nodes.iter().any(|n| n.node_id == node_id) { + if let Some(existing) = + liquidity_source_config.lsp_nodes.iter_mut().find(|n| n.node_id == node_id) + { + existing.address = address; + existing.token = token; + existing.trust_peer_0conf = trust_peer_0conf; return self; } @@ -1185,7 +1190,7 @@ impl Builder { /// 0-confirmation channels opened by this LSP. If `false`, 0-confirmation /// acceptance for this peer falls back to [`Config::trusted_peers_0conf`]. /// - /// May be called multiple times to register several LSPs. Duplicate `node_id`s are ignored. + /// May be called multiple times to register several LSPs. Re-adding an existing `node_id` updates its address, token, and 0conf trust settings. /// /// [bLIP-50 / LSPS0]: https://github.com/lightning/blips/blob/master/blip-0050.md pub fn add_liquidity_source( @@ -2805,4 +2810,54 @@ mod tests { builder.set_runtime(multi_thread_runtime.handle().clone()).unwrap(); assert!(builder.setup_runtime(&logger).is_ok(), "a multi-threaded runtime should be used"); } + + #[test] + fn add_liquidity_source_updates_existing_lsp_in_place() { + use std::str::FromStr; + + use bitcoin::secp256k1::PublicKey; + use lightning::ln::msgs::SocketAddress; + + let mut builder = NodeBuilder::new(); + let node_id = PublicKey::from_str( + "0276607124ebe6a6c9338517b6f485825b27c2dcc0b9fc2aa6a4c0df91194e5993", + ) + .unwrap(); + let first_address = SocketAddress::from_str("127.0.0.1:9735").unwrap(); + let second_address = SocketAddress::from_str("127.0.0.2:9735").unwrap(); + + // Register an LSP, then re-add the same node_id with a new address and + // different 0conf/trust settings. Re-adding must update the existing + // entry in place rather than silently dropping the new values. + builder.add_liquidity_source(node_id, first_address.clone(), None, true); + builder.add_liquidity_source( + node_id, + second_address.clone(), + Some("token".to_owned()), + false, + ); + + let config = builder + .liquidity_source_config + .as_ref() + .expect("liquidity source config should be initialized"); + assert_eq!( + config.lsp_nodes.len(), + 1, + "re-adding the same node_id must not create a duplicate entry", + ); + assert_eq!( + config.lsp_nodes[0].address, second_address, + "re-adding must update the address in place", + ); + assert_eq!( + config.lsp_nodes[0].token, + Some("token".to_owned()), + "re-adding must update the token in place", + ); + assert!( + !config.lsp_nodes[0].trust_peer_0conf, + "re-adding must update the 0conf trust setting in place", + ); + } } diff --git a/src/liquidity/mod.rs b/src/liquidity/mod.rs index ffc1f878bc..c8361b4f0a 100644 --- a/src/liquidity/mod.rs +++ b/src/liquidity/mod.rs @@ -154,50 +154,113 @@ impl Liquidity { /// The given `token` will be used by the LSP to authenticate the user. /// `trust_peer_0conf` controls whether the node will accept 0-confirmation channels opened by this /// LSP. Note this supersedes [`Config::trusted_peers_0conf`] for this peer. - /// Duplicate `node_id`s are ignored. + /// Re-adding an existing `node_id` updates its address/token/0conf settings. A changed address + /// disconnects any live session, dials the new address, and rediscovers protocols. Token or + /// 0conf-only updates are applied in place. A failed update restores the previous config only + /// if no newer update for the same `node_id` has landed. pub fn add_liquidity_source( &self, node_id: PublicKey, address: SocketAddress, token: Option, trust_peer_0conf: bool, ) -> Result<(), Error> { + let mut previous: Option<(SocketAddress, Option, bool, Option>)> = None; + let mut addr_changed = true; + // Generation of this write. Cleanup restores or removes only if it is still current, + // so a concurrent re-add for the same node_id is not rolled back. + // New entries start at generation 1; existing entries inherit the current generation. + let mut update_generation = 1u64; { let mut lsp_nodes = self.liquidity_source.lsp_nodes.write().expect("lock"); - if lsp_nodes.iter().any(|n| n.node_id == node_id) { - log_info!(self.logger, "LSP node {} already added, skipping.", node_id); - return Ok(()); + if let Some(existing) = lsp_nodes.iter_mut().find(|n| n.node_id == node_id) { + addr_changed = existing.address != address; + let changed = addr_changed + || existing.token != token + || existing.trust_peer_0conf != trust_peer_0conf; + if !changed { + log_info!(self.logger, "LSP node {} already added, skipping.", node_id); + return Ok(()); + } + if addr_changed { + log_info!( + self.logger, + "Updating existing LSP node {} address/config; disconnecting and reconnecting.", + node_id + ); + } else { + log_info!( + self.logger, + "Updating existing LSP node {} token/0conf without reconnecting.", + node_id + ); + } + let prev_address = std::mem::replace(&mut existing.address, address.clone()); + let prev_token = std::mem::replace(&mut existing.token, token.clone()); + let prev_trust = + std::mem::replace(&mut existing.trust_peer_0conf, trust_peer_0conf); + // Keep supported_protocols until rediscovery overwrites them. Clearing here + // makes get_lsp_config miss this LSP for the whole connect+discover window. + let prev_protocols = existing.supported_protocols.clone(); + existing.config_generation = existing.config_generation.wrapping_add(1); + update_generation = existing.config_generation; + previous = Some((prev_address, prev_token, prev_trust, prev_protocols)); + } else { + lsp_nodes.push(LspNode { + node_id, + address: address.clone(), + token: token.clone(), + trust_peer_0conf, + supported_protocols: None, + config_generation: update_generation, + }); } - - lsp_nodes.push(LspNode { - node_id, - address: address.clone(), - token: token.clone(), - trust_peer_0conf, - supported_protocols: None, - }); } - // If anything below fails, drop the half-initialized entry so the user can retry cleanly. + // On failure: remove half-initialized inserts; restore prior config for updates. + // Skip if a newer add for this node_id already committed a later generation. let lsp_nodes = Arc::clone(&self.liquidity_source.lsp_nodes); let cleanup = move || { - lsp_nodes.write().expect("lock").retain(|n| n.node_id != node_id); + let mut nodes = lsp_nodes.write().expect("lock"); + let still_current = nodes + .iter() + .find(|n| n.node_id == node_id) + .is_some_and(|n| n.config_generation == update_generation); + if !still_current { + return; + } + if let Some((prev_address, prev_token, prev_trust, prev_protocols)) = previous { + if let Some(existing) = nodes.iter_mut().find(|n| n.node_id == node_id) { + existing.address = prev_address; + existing.token = prev_token; + existing.trust_peer_0conf = prev_trust; + existing.supported_protocols = prev_protocols; + } + } else { + nodes.retain(|n| n.node_id != node_id); + } }; - let con_cm = Arc::clone(&self.connection_manager); - let connect_addr = address.clone(); - if let Err(e) = self - .runtime - .block_on(async move { con_cm.connect_peer_if_necessary(node_id, connect_addr).await }) - { - cleanup(); - return Err(e); - } - log_info!(self.logger, "Connected to LSP {}@{}.", node_id, address); - - if let Err(e) = self - .runtime - .block_on(async { self.liquidity_source.discover_lsp_protocols(&node_id).await }) - { - cleanup(); - return Err(e); + if addr_changed { + let con_cm = Arc::clone(&self.connection_manager); + let connect_addr = address.clone(); + // connect_peer_if_necessary no-ops while the peer is up, so a live LSP would keep + // the old session and never dial the new address. Drop it first, then dial. + if let Err(e) = self.runtime.block_on(async move { + con_cm.disconnect_peer(node_id); + con_cm.do_connect_peer(node_id, connect_addr).await + }) { + cleanup(); + return Err(e); + } + log_info!(self.logger, "Connected to LSP {}@{}.", node_id, address); + + if let Err(e) = self + .runtime + .block_on(async { self.liquidity_source.discover_lsp_protocols(&node_id).await }) + { + cleanup(); + return Err(e); + } + } else { + log_info!(self.logger, "Updated LSP {} config (address unchanged).", node_id); } Ok(()) @@ -232,6 +295,9 @@ pub(crate) struct LspNode { trust_peer_0conf: bool, // Protocol numbers discovered via LSPS0 (e.g., 1 = LSPS1, 2 = LSPS2, 5 = LSPS5). supported_protocols: Option>, + // Bumped on every in-place config write. Failure cleanup matches this so a newer + // concurrent update is not overwritten by an older rollback. + config_generation: u64, } pub(crate) struct LiquiditySourceBuilder @@ -331,6 +397,7 @@ where token: cfg.token, trust_peer_0conf: cfg.trust_peer_0conf, supported_protocols: None, + config_generation: 0, }) .collect(), )); From 3953a406412c588607768f94de5a5503facceafa Mon Sep 17 00:00:00 2001 From: Bartok9 <259807879+Bartok9@users.noreply.github.com> Date: Mon, 12 Oct 2026 11:07:34 -0400 Subject: [PATCH 2/2] chore: pin proptest to 1.11.0 to fix CI compilation (proptest 1.12.0 has API breakage affecting all integration tests) --- .github/workflows/0fc-integration.yml | 4 ++++ .github/workflows/benchmarks.yml | 4 ++++ .github/workflows/cln-integration.yml | 3 +++ .github/workflows/eclair-integration.yml | 3 +++ .github/workflows/hrn-integration.yml | 4 ++++ .github/workflows/kotlin.yml | 3 +++ .github/workflows/lnd-integration.yml | 3 +++ .github/workflows/postgres-integration.yml | 3 +++ .github/workflows/python.yml | 3 +++ .github/workflows/swift.yml | 3 +++ .github/workflows/vss-integration.yml | 3 +++ .github/workflows/vss-no-auth-integration.yml | 3 +++ 12 files changed, 39 insertions(+) diff --git a/.github/workflows/0fc-integration.yml b/.github/workflows/0fc-integration.yml index 1eab8b3ae1..bc0c5099d2 100644 --- a/.github/workflows/0fc-integration.yml +++ b/.github/workflows/0fc-integration.yml @@ -13,6 +13,10 @@ jobs: steps: - name: Checkout source code uses: actions/checkout@v4 + + - name: Pin proptest for compatibility + run: cargo update -p proptest --precise "1.11.0" --verbose + - name: Install Rust stable toolchain run: | curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile=minimal --default-toolchain stable diff --git a/.github/workflows/benchmarks.yml b/.github/workflows/benchmarks.yml index afdf32e779..5e25282a9a 100644 --- a/.github/workflows/benchmarks.yml +++ b/.github/workflows/benchmarks.yml @@ -15,6 +15,10 @@ jobs: steps: - name: Checkout source code uses: actions/checkout@v4 + + - name: Pin proptest for compatibility + run: cargo update -p proptest --precise "1.11.0" --verbose + - name: Install Rust toolchain run: | curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile=minimal --default-toolchain stable diff --git a/.github/workflows/cln-integration.yml b/.github/workflows/cln-integration.yml index daf8355bdd..dfca73abc7 100644 --- a/.github/workflows/cln-integration.yml +++ b/.github/workflows/cln-integration.yml @@ -14,6 +14,9 @@ jobs: - name: Checkout repository uses: actions/checkout@v6 + - name: Pin proptest for compatibility + run: cargo update -p proptest --precise "1.11.0" --verbose + - name: Create temporary directory for CLN data run: echo "CLN_DATA_DIR=$(mktemp -d)" >> $GITHUB_ENV diff --git a/.github/workflows/eclair-integration.yml b/.github/workflows/eclair-integration.yml index 68acc8b13e..5b1531a9a2 100644 --- a/.github/workflows/eclair-integration.yml +++ b/.github/workflows/eclair-integration.yml @@ -24,6 +24,9 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 + - name: Pin proptest for compatibility + run: cargo update -p proptest --precise "1.11.0" --verbose + - name: Start bitcoind and electrs run: docker compose -p ldk-node -f tests/docker/docker-compose-eclair.yml up -d bitcoin electrs diff --git a/.github/workflows/hrn-integration.yml b/.github/workflows/hrn-integration.yml index 732aad029f..ecc559a139 100644 --- a/.github/workflows/hrn-integration.yml +++ b/.github/workflows/hrn-integration.yml @@ -14,6 +14,10 @@ jobs: steps: - name: Checkout source code uses: actions/checkout@v3 + + - name: Pin proptest for compatibility + run: cargo update -p proptest --precise "1.11.0" --verbose + - name: Install Rust stable toolchain run: | curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile=minimal --default-toolchain stable diff --git a/.github/workflows/kotlin.yml b/.github/workflows/kotlin.yml index 84429df339..9fcb32ada7 100644 --- a/.github/workflows/kotlin.yml +++ b/.github/workflows/kotlin.yml @@ -20,6 +20,9 @@ jobs: - name: Checkout repository uses: actions/checkout@v6 + - name: Pin proptest for compatibility + run: cargo update -p proptest --precise "1.11.0" --verbose + - name: Set up JDK uses: actions/setup-java@v5 with: diff --git a/.github/workflows/lnd-integration.yml b/.github/workflows/lnd-integration.yml index 6c755e2a21..fb8e767618 100644 --- a/.github/workflows/lnd-integration.yml +++ b/.github/workflows/lnd-integration.yml @@ -14,6 +14,9 @@ jobs: - name: Checkout repository uses: actions/checkout@v6 + - name: Pin proptest for compatibility + run: cargo update -p proptest --precise "1.11.0" --verbose + - name: Check and install CMake if needed # lnd_grpc_rust (via prost-build v0.10.4) requires CMake >= 3.5 but is incompatible with CMake >= 4.0. # This step checks if CMake is missing, below 3.5, or 4.0 or higher, and installs CMake 3.31.6 if needed, diff --git a/.github/workflows/postgres-integration.yml b/.github/workflows/postgres-integration.yml index d27e3123ea..43776d5cf0 100644 --- a/.github/workflows/postgres-integration.yml +++ b/.github/workflows/postgres-integration.yml @@ -29,6 +29,9 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v6 + - name: Pin proptest for compatibility + run: cargo update -p proptest --precise "1.11.0" --verbose + - name: Install Rust stable toolchain run: | curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile=minimal --default-toolchain stable diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 3639a1a1c5..c756201feb 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -20,6 +20,9 @@ jobs: - name: Checkout repository uses: actions/checkout@v6 + - name: Pin proptest for compatibility + run: cargo update -p proptest --precise "1.11.0" --verbose + - name: Install uv uses: astral-sh/setup-uv@v7 with: diff --git a/.github/workflows/swift.yml b/.github/workflows/swift.yml index af3928c4a8..1afdd5d668 100644 --- a/.github/workflows/swift.yml +++ b/.github/workflows/swift.yml @@ -18,6 +18,9 @@ jobs: - name: Checkout repository uses: actions/checkout@v6 + - name: Pin proptest for compatibility + run: cargo update -p proptest --precise "1.11.0" --verbose + - name: Set default Rust version to stable run: rustup default stable diff --git a/.github/workflows/vss-integration.yml b/.github/workflows/vss-integration.yml index 6b66eacd48..9620f04c01 100644 --- a/.github/workflows/vss-integration.yml +++ b/.github/workflows/vss-integration.yml @@ -31,6 +31,9 @@ jobs: uses: actions/checkout@v6 with: path: ldk-node + - name: Pin proptest for compatibility + run: cd ldk-node && cargo update -p proptest --precise "1.11.0" --verbose + - name: Checkout VSS uses: actions/checkout@v6 with: diff --git a/.github/workflows/vss-no-auth-integration.yml b/.github/workflows/vss-no-auth-integration.yml index 9e7fb6c51b..dd1b723217 100644 --- a/.github/workflows/vss-no-auth-integration.yml +++ b/.github/workflows/vss-no-auth-integration.yml @@ -31,6 +31,9 @@ jobs: uses: actions/checkout@v6 with: path: ldk-node + - name: Pin proptest for compatibility + run: cd ldk-node && cargo update -p proptest --precise "1.11.0" --verbose + - name: Checkout VSS uses: actions/checkout@v6 with: