Skip to content

lndclient: add BlockUntilServerActive option - #291

Open
djkazic wants to merge 1 commit into
lightninglabs:masterfrom
djkazic:block-until-server-active
Open

djkazic wants to merge 1 commit into
lightninglabs:masterfrom
djkazic:block-until-server-active

Conversation

@djkazic

@djkazic djkazic commented Nov 9, 2026

Copy link
Copy Markdown

Problem

BlockUntilUnlocked makes NewLndServices return as soon as lnd reports the RPC_ACTIVE wallet state. At that point lnd's main server is still starting, so RPC calls made right after startup can still fail.

Change

Add a BlockUntilServerActive option to LndServicesConfig. When set, NewLndServices blocks until lnd reports SERVER_ACTIVE.

  • Setting it also waits for the unlock, so BlockUntilUnlocked does not need to be set as well.
  • BlockUntilUnlocked behaves exactly as before.
  • The wait can be aborted through CallerCtx, like the other startup waits.

Usage

services, err := lndclient.NewLndServices(&lndclient.LndServicesConfig{
	// ...
	BlockUntilServerActive: true,
	CallerCtx:              ctx,
})

Testing

TestGetLndInfo has two new cases:

  • the state sequence reaches SERVER_ACTIVE and the call returns;
  • the sequence stops at RPC_ACTIVE and the call keeps waiting until the context expires, rather than returning early.

The test mock now closes its channels on SERVER_ACTIVE, matching the real state client.

Checklist

  • PR is opened against correct version branch.
  • No change needed to the version compatibility matrix or minimal required version: the minimal supported lnd version already has SERVER_ACTIVE.
  • No new RPC methods, so macaroon_recipes.go is unchanged.

BlockUntilUnlocked returns as soon as lnd reports the RPC_ACTIVE wallet
state. At that point lnd's main server is still starting up, so RPC
calls made right after NewLndServices returns can still fail.

Add a BlockUntilServerActive config option that makes NewLndServices
wait for the SERVER_ACTIVE state instead. Setting it implies waiting
for the unlock. The behavior of BlockUntilUnlocked is unchanged.

@bhandras bhandras left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks!

@agammann agammann left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

BlockUntilServerActive promises to return only after WalletStateServerActive, and the comment says older lnd versions will wait until CallerCtx is canceled. But both closed-channel branches in getLndInfo still call getInfo() unconditionally. A v0.13 stream that closes after RPC_ACTIVE can therefore return successfully before SERVER_ACTIVE ever appears. Could those branches honor waitForServerActive (or return a version/stream-ended error) and add a regression where the state channel closes without the new state?

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.

3 participants