Skip to content

Conversation

@mubarak23
Copy link
Contributor

@mubarak23 mubarak23 commented Jun 13, 2025

closes #264
This PR refactors the LightningNode trait and its implementations to remove unnecessary &mut self references for methods that do not mutate internal state.

Motivation

Previously, several trait methods like get_network and list_channels required &mut self, even though they only retrieved information. This requirement leaked internal implementation details—specifically, that the underlying client field required a mutable reference to make gRPC or HTTP calls.

This design was misleading and unnecessarily restricted usage of the trait, e.g. preventing multiple read-only operations from being performed concurrently on the same node.

Changes

Wrapped client fields (e.g. NodeClient, EclairClient, etc.) inside tokio::sync::Mutex.

Updated all client usages to acquire a mutable lock via let mut client = self.client.lock().await;.

Updated trait method signatures to require &self instead of &mut self where applicable.

Ensured thread-safe, concurrent-friendly behavior without sacrificing correctness or clarity.

@mubarak23 mubarak23 marked this pull request as draft June 13, 2025 15:11
Copy link
Contributor

@carlaKC carlaKC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cACK, heading in the right direction 👍

@mubarak23 mubarak23 marked this pull request as ready for review June 16, 2025 09:49
@mubarak23 mubarak23 requested review from carlaKC and elnosh June 24, 2025 22:25
Copy link
Collaborator

@elnosh elnosh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

think should be good to squash

@carlaKC
Copy link
Contributor

carlaKC commented Jun 25, 2025

Small nit for when you do squash: take a look at commit structure in contributing guide - we use an odd format (historical reasons), would be nice to align with that while you're at it.

@mubarak23 mubarak23 force-pushed the fix-remove-mut-ref branch from 64c2815 to 3e7ac44 Compare June 25, 2025 18:01
Copy link
Contributor

@carlaKC carlaKC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK, nice cleanup 🥦

@carlaKC carlaKC merged commit c4059cd into bitcoin-dev-project:main Jun 25, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

simln-lib: refactor LightningNode trait to not use mutable references

3 participants