Skip to content

itest: stop litd nodes via litd's StopDaemon#1356

Open
Vandit1604 wants to merge 2 commits into
lightninglabs:masterfrom
Vandit1604:itest-stateless-stopdaemon
Open

itest: stop litd nodes via litd's StopDaemon#1356
Vandit1604 wants to merge 2 commits into
lightninglabs:masterfrom
Vandit1604:itest-stateless-stopdaemon

Conversation

@Vandit1604

Copy link
Copy Markdown
Contributor

This is split out of #1329 at @ViktorT-11's request, so it can be reviewed on its own. #1329 will be rebased on top of this.

What this does

The itest harness stops a node through litd's own StopDaemon when it has a lit connection, and falls back to lnd's StopDaemon otherwise. The lit connection (litConn) was only ever set up on the no-seed path in Start, so seed based nodes (stateless init, seed restarts) always fell back to lnd.

Two changes:

  1. litConn setup moves into initLightningClient, so every node gets one, seed or not.
  2. Stateless init nodes write no macaroon files to disk, so there is no lit macaroon to authenticate with. For those, the harness now bakes a lit super macaroon from the admin macaroon it gets back from Init / InitChangePassword, writes it to the node's directory, and uses that for litConn.

This mirrors what a real stateless setup does:

lncli create --stateless_init --save_to /tmp/admin.macaroon
litcli --macaroonpath /tmp/admin.macaroon bakesupermacaroon --save_to /tmp/lit.macaroon

Why it matters

On master this is a no-op in behaviour, since stopping lnd also brings litd down either way. It becomes necessary with #1329, where litd deliberately keeps running after lnd stops. Without it, seed based nodes stop lnd only, litd stays up by design, and the harness times out waiting for the process to exit.

Testing

terminal stateless init mode passes on this branch on top of master.

@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request updates the itest harness to ensure reliable node shutdown by prioritizing litd's StopDaemon RPC. By standardizing the connection to litd and implementing an in-memory macaroon baking process for stateless nodes, the harness can now correctly manage the lifecycle of litd-backed nodes regardless of their initialization method. This change is essential for future updates where litd and lnd lifecycles are fully decoupled.

Highlights

  • Unified Stop Logic: The itest harness now consistently uses litd's StopDaemon RPC to shut down nodes, ensuring proper lifecycle management even when litd and lnd are decoupled.
  • Universal Lit Connection: Moved lit connection initialization into initLightningClient, ensuring all nodes (including seed-based ones) maintain a connection to litd.
  • Stateless Macaroon Baking: Added logic to bake a super macaroon for stateless init nodes, allowing them to authenticate with litd's RPC when no macaroon file exists on disk.
New Features

🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request updates the integration test harness to support stateless node initialization by baking a super macaroon from the in-memory admin macaroon and refactoring the node startup, client initialization, and shutdown sequences to consistently use Lit's own RPCs. The review feedback highlights three key improvement opportunities: checking for a nil gRPC response before accessing its fields to prevent panics, restricting the file permissions of the written macaroon to 0600 for better security, and utilizing a context with a timeout when establishing the Lit RPC connection to avoid potential indefinite blocking.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread itest/litd_node.go
Comment on lines +1110 to +1115
if err != nil {
return err
}

// BakeSuperMacaroon hex encodes the returned macaroon.
superMacBytes, err := hex.DecodeString(resp.Macaroon)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

It is a good defensive programming practice to check if the gRPC response resp is nil before accessing its fields to prevent potential nil pointer dereference panics.

Suggested change
if err != nil {
return err
}
// BakeSuperMacaroon hex encodes the returned macaroon.
superMacBytes, err := hex.DecodeString(resp.Macaroon)
if err != nil {
return err
}
if resp == nil {
return errors.New("received empty response from BakeSuperMacaroon")
}
// BakeSuperMacaroon hex encodes the returned macaroon.
superMacBytes, err := hex.DecodeString(resp.Macaroon)

Comment thread itest/litd_node.go
Comment on lines +1123 to +1125
if err := os.WriteFile(macPath, superMacBytes, 0644); err != nil {
return err
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

security-medium medium

Macaroons are sensitive credentials and should be written with restrictive file permissions (e.g., 0600 instead of 0644) to prevent unauthorized local users from reading them.

Suggested change
if err := os.WriteFile(macPath, superMacBytes, 0644); err != nil {
return err
}
if err := os.WriteFile(macPath, superMacBytes, 0600); err != nil {
return err
}

Comment thread itest/litd_node.go
Comment on lines +1331 to +1352
litConn, err := connectLitRPC(
context.Background(), hn.Cfg.LitAddr(), hn.Cfg.LitTLSCertPath,
macPath,
)
if err != nil {
return fmt.Errorf("could not connect to Lit RPC: %w", err)
}
hn.litConn = litConn

ctxt, cancel := context.WithTimeout(
context.Background(), lntest.DefaultTimeout,
)
defer cancel()
err = wait.NoError(func() error {
litClient := litrpc.NewProxyClient(hn.litConn)

_, err := litClient.GetInfo(ctxt, &litrpc.GetInfoRequest{})
return err
}, lntest.DefaultTimeout)
if err != nil {
return err
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Calling connectLitRPC with context.Background() can cause the test harness to block indefinitely if there are connection issues, because connectLitRPC uses grpc.WithBlock(). We should reuse the context with timeout (ctxt) to ensure the connection attempt is bounded.

	ctxt, cancel := context.WithTimeout(
		context.Background(), lntest.DefaultTimeout,
	)
	defer cancel()

	litConn, err := connectLitRPC(
		ctxt, hn.Cfg.LitAddr(), hn.Cfg.LitTLSCertPath,
		macPath,
	)
	if err != nil {
		return fmt.Errorf("could not connect to Lit RPC: %w", err)
	}
	hn.litConn = litConn

	err = wait.NoError(func() error {
		litClient := litrpc.NewProxyClient(hn.litConn)

		_, err := litClient.GetInfo(ctxt, &litrpc.GetInfoRequest{})
		return err
	}, lntest.DefaultTimeout)
	if err != nil {
		return err
	}

@Vandit1604
Vandit1604 force-pushed the itest-stateless-stopdaemon branch from 71061fd to 523fae5 Compare July 18, 2026 20:42
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.

1 participant