← Back to Pull requests

lnwallet+rpc: add label filter to GetTransactions #10806

Open
saraogiraj94 opened this pull request with 248 lines diff across 11 files
View on GitHub
saraogiraj94 saraogiraj94 commented on May 15, 2026 04:59 UTC
Author

Closes #10785

Summary

  • Adds an optional label field (proto field 6) to GetTransactionsRequest so callers can filter chain transactions by their label

  • WalletController.ListTransactionDetails gains a labelFilter string parameter; when non-empty, only transactions whose Label field exactly matches are returned

  • lncli listchaintxns gains a --label flag
  • Testing

  • All existing mocks and integration-test call sites updated to pass the new parameter

  • New integration test testListTransactionDetailsLabelFilter covers: exact match by label A, exact match by label B, no filter returns all, unknown label returns empty
  • Release Notes

    Updates docs/release-notes/release-notes-0.22.0.md under RPC Additions and lncli Additions.

    🤖 Generated with Claude Code

    Diff: 248 lines (+229 / -19) across 11 files Reviewer: TechLateef Review duration: 272068m
    All Vouch review confidence checks passed
    Residual risk 0.10 = Change Risk (0.63) × (1 − Review Confidence (0.84)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.63 · 248 lines diff across 11 files
    0.63
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.87 · 5 substantive comment(s)
    0.87
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    83%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.330
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    25 items
    gemini-code-assist[bot] gemini-code-assist[bot] commented on May 15, 2026 04:59 UTC
    Bot

    Summary of Changes

    Hello, I'm Gemini Code Assist[^1]! 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 introduces label-based filtering for chain transactions across the RPC, CLI, and internal wallet interfaces. By allowing users to filter transactions by a specific label, it improves the discoverability and management of wallet activity. The changes include updates to the gRPC definition, internal wallet controller logic, and command-line interface, accompanied by comprehensive integration tests to ensure correctness.

    Highlights

    RPC API Update: Added an optional label field to GetTransactionsRequest to allow filtering chain transactions by label.
    Wallet Controller Enhancement: Updated WalletController.ListTransactionDetails to accept a labelFilter parameter for precise transaction retrieval.
    CLI Tooling: Introduced a new --label flag to the listchaintxns command in lncli.
    Testing: Implemented a new integration test testListTransactionDetailsLabelFilter to verify exact label matching and empty result scenarios.

    <details>
    <summary><b>New Features</b></summary>

    🧠 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.
    </details>

    <details>
    <summary><b>Using Gemini Code Assist</b></summary>
    <br>

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

    <b>Invoking Gemini</b>

    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.

    <b>Customization</b>

    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.

    <b>Limitations & Feedback</b>

    Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with :thumbsup: and :thumbsdown: 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.
    </details>

    [^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[bot] gemini-code-assist[bot] commented on code on May 15, 2026 05:00 UTC
    Code Review
    docs/release-notes/release-notes-0.22.0.md:1
    @@ -27,8 +27,16 @@
     
     ## RPC Additions
     
    +* [`GetTransactions`](https://github.com/lightningnetwork/lnd/pull/10806)

    !medium

    The pull request link contains a placeholder XXXX. Please update this with the actual pull request number once it is assigned.

    gemini-code-assist[bot] gemini-code-assist[bot] commented on code on May 15, 2026 05:00 UTC
    Code Review
    lnrpc/lightning_grpc.pb.go:1
    @@ -19,418 +19,431 @@ const _ = grpc.SupportPackageIsVersion7
     // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
     type LightningClient interface {
     	// lncli: `walletbalance`
    -	// WalletBalance returns total unspent outputs(confirmed and unconfirmed), all
    -	// confirmed unspent outputs and all unconfirmed unspent outputs under control
    -	// of the wallet.
    +	//WalletBalance returns total unspent outputs(confirmed and unconfirmed), all
    +	//confirmed unspent outputs and all unconfirmed unspent outputs under control
    +	//of the wallet.

    !medium

    This file contains extensive formatting changes in the comments (e.g., removing the space after //), which appear to be regressions and create significant diff noise. Since this is a generated file, please ensure it is regenerated using the project's standard toolchain and version of protoc-gen-go-grpc to maintain consistency and readability.

    gemini-code-assist[bot] gemini-code-assist[bot] commented on May 15, 2026 05:00 UTC
    Reviewer

    Code Review

    This pull request introduces an optional "label" filter to the GetTransactions RPC and the listchaintxns CLI command, allowing users to filter transactions by their exact label. The changes span the API definitions, the wallet controller interface, and the btcwallet implementation, supported by new integration tests. Review feedback highlighted a placeholder PR number in the release notes that needs updating and noted significant formatting regressions in the generated gRPC code, suggesting the file be regenerated using the standard project toolchain to reduce diff noise.

    github-actions[bot] github-actions[bot] commented on May 15, 2026 05:03 UTC
    Bot

    PR Severity: CRITICAL - lnwallet and rpcserver.go changes require expert review. <\!-- pr-severity-bot -->

    github-actions[bot] github-actions[bot] commented on May 15, 2026 05:03 UTC
    Bot

    PR Severity: CRITICAL

    Automated classification | 9 files | 210 lines changed (excluding auto-generated and test files)

    Critical (5 files):

  • lnwallet/btcwallet/btcwallet.go - Wallet operations (lnwallet/)

  • lnwallet/interface.go - Core wallet interface (lnwallet/)

  • lnwallet/mock.go - Wallet mock (lnwallet/)

  • lnwallet/test/test_interface.go - Wallet test interface (lnwallet/)

  • rpcserver.go - Core server coordination
  • High (2 files):

  • lnrpc/lightning.proto - RPC/API definitions (lnrpc/)

  • lnrpc/lightning.swagger.json - RPC/API definitions (lnrpc/)
  • Medium (1 file): cmd/commands/commands.go
    Low (1 file): docs/release-notes/release-notes-0.22.0.md
    Excluded (auto-gen/test): lnrpc/lightning.pb.go, lnrpc/lightning_grpc.pb.go, lntest/mock/walletcontroller.go

    Analysis: This PR modifies lnwallet/* and rpcserver.go, both CRITICAL. The wallet interface change (lnwallet/interface.go) affects channel funding, signing, and commitment transactions. The lnrpc proto addition adds new RPC surface. No severity bump: 9 files (threshold 20) and 210 lines (threshold 500).

    To override: add a severity-override-{critical,high,medium,low} label.
    <\!-- pr-severity-bot -->

    saraogiraj94 saraogiraj94 commented on code on May 16, 2026 10:23 UTC
    Code Review
    docs/release-notes/release-notes-0.22.0.md:1
    @@ -27,8 +27,16 @@
     
     ## RPC Additions
     
    +* [`GetTransactions`](https://github.com/lightningnetwork/lnd/pull/10806)

    It is fixed !

    saraogiraj94 saraogiraj94 commented on code on May 16, 2026 10:23 UTC
    Code Review
    lnrpc/lightning_grpc.pb.go:1
    @@ -19,418 +19,431 @@ const _ = grpc.SupportPackageIsVersion7
     // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
     type LightningClient interface {
     	// lncli: `walletbalance`
    -	// WalletBalance returns total unspent outputs(confirmed and unconfirmed), all
    -	// confirmed unspent outputs and all unconfirmed unspent outputs under control
    -	// of the wallet.
    +	//WalletBalance returns total unspent outputs(confirmed and unconfirmed), all
    +	//confirmed unspent outputs and all unconfirmed unspent outputs under control
    +	//of the wallet.

    Its auto generated.

    murraystewart96 murraystewart96 commented on May 18, 2026 13:07 UTC
    Contributor

    Looks good. Nice use of the in place filter!

    TechLateef TechLateef commented on code on May 25, 2026 06:29 UTC
    Code Review
    lnwallet/btcwallet/btcwallet.go:1
    @@ -1523,6 +1523,18 @@ func (b *BtcWallet) ListTransactionDetails(startHeight, endHeight int32,
     		txDetails = append(txDetails, detail)
     	}
     
    +	// If a label filter is specified, only include transactions whose label
    +	// matches exactly.
    +	if labelFilter != "" {

    This look solid!

    However, there might be a little bug here with how pagination interacts with this filter. Since the code above this block populates txDetails from the database using the raw maxTransactions limit, the result set is already truncated before it hits this loop.

    If a node has thousands of transactions, but the client queries with a default maxTransactions window (like 20 or 50) along with a specific label, the filter will only check that initial batch. If the matching transaction sits further down in the history, it'll be missed entirely. The label filter likely needs to be applied to the raw results before the pagination slices and offsets are handled.

    TechLateef TechLateef commented on code on May 25, 2026 06:35 UTC
    Code Review
    lnwallet/test/test_interface.go:1
    @@ -1374,50 +1374,180 @@ func testListTransactionDetailsOffset(miner *rpctest.Harness,
     	// Query for transactions, setting max_transactions to less than the
     	// number of transactions we have (5).
     	txDetails, _, _, err = alice.ListTransactionDetails(
    -		startHeight, chainTip, "", 0, 1,
    +		startHeight, chainTip, "", "", 0, 1,
     	)
     	require.NoError(t, err)
     	require.Len(t, txDetails, 1)
     
     	// Query for transactions, setting indexOffset to 5 (equal to number
     	// of transactions we have) and max_transactions to 0.
     	txDetails, _, _, err = alice.ListTransactionDetails(
    -		startHeight, chainTip, "", 5, 0,
    +		startHeight, chainTip, "", "", 5, 0,
     	)
     	require.NoError(t, err)
     	require.Len(t, txDetails, 0)
     
     	// Query for transactions, setting indexOffset to 4 (edge offset) and
     	// max_transactions to 0.
     	txDetails, _, _, err = alice.ListTransactionDetails(
    -		startHeight, chainTip, "", 4, 0,
    +		startHeight, chainTip, "", "", 4, 0,
     	)
     	require.NoError(t, err)
     	require.Len(t, txDetails, 1)
     
     	// Query for transactions, setting max_transactions to 0.
     	txDetails, _, _, err = alice.ListTransactionDetails(
    -		startHeight, chainTip, "", 0, 0,
    +		startHeight, chainTip, "", "", 0, 0,
     	)
     	require.NoError(t, err)
     	require.Len(t, txDetails, 5)
     
     	// Query for transactions, more than we have in the wallet (5).
     	txDetails, _, _, err = alice.ListTransactionDetails(
    -		startHeight, chainTip, "", 0, 10,
    +		startHeight, chainTip, "", "", 0, 10,
     	)
     	require.NoError(t, err)
     	require.Len(t, txDetails, 5)
     
     	// Query for transactions where the offset is greater than the number
     	// of transactions available.
     	txDetails, _, _, err = alice.ListTransactionDetails(
    -		startHeight, chainTip, "", 10, 100,
    +		startHeight, chainTip, "", "", 10, 100,
     	)
     	require.NoError(t, err)
     	require.Len(t, txDetails, 0)
     }
     

    The test cases cover the exact matching nicely.

    One minor thing: all the test queries here pass 0 for maxTransactions, which fetches the whole history at once and disables pagination boundaries. Because of that, it doesn't catch the edge case where a client passes both a label filter and a tight max_transactions limit at the same time.

    It would be great to add one more test assertion in here that uses a small maxTransactions limit to verify that pagination doesn't accidentally chop off matching records from the results.

    saraogiraj94 saraogiraj94 commented on code on Jun 01, 2026 12:18 UTC
    Code Review
    lnwallet/btcwallet/btcwallet.go:1
    @@ -1523,6 +1523,18 @@ func (b *BtcWallet) ListTransactionDetails(startHeight, endHeight int32,
     		txDetails = append(txDetails, detail)
     	}
     
    +	// If a label filter is specified, only include transactions whose label
    +	// matches exactly.
    +	if labelFilter != "" {

    @TechLateef Thanks for the review! I want to clarify the flow here — the label filter is actually applied to the full result set before any pagination kicks in.

    The DB call on line 1496:

    txns, err := b.wallet.GetTransactions(start, stop, accountFilter, nil)
    comes from the btcwallet library with this signature:

    func (w Wallet) GetTransactions(startBlock, endBlock BlockIdentifier, accountName string, cancel <-chan struct{}) (*GetTransactionsResult, error)

    The last argument is a cancel channel, not a limit — there is no maxTransactions parameter. The function returns every transaction in the block range unconditionally.

    So the order of operations is:

    Fetch all transactions in [startHeight, endHeight] from the DB (no limit)
    Convert to txDetails slice (still the full set)
    Label filter applied here (line 1528) — filters on the complete set
    Pagination (indexOffset + maxTransactions) applied after — slices the already-filtered set
    A client querying with maxTransactions=20 and label="pay-bob" will have all transactions in the block range filtered first, then the first 20 matching results returned. No labelled transaction can be silently missed.

    saraogiraj94 saraogiraj94 commented on code on Jun 01, 2026 12:28 UTC
    Code Review
    lnwallet/test/test_interface.go:1
    @@ -1374,50 +1374,180 @@ func testListTransactionDetailsOffset(miner *rpctest.Harness,
     	// Query for transactions, setting max_transactions to less than the
     	// number of transactions we have (5).
     	txDetails, _, _, err = alice.ListTransactionDetails(
    -		startHeight, chainTip, "", 0, 1,
    +		startHeight, chainTip, "", "", 0, 1,
     	)
     	require.NoError(t, err)
     	require.Len(t, txDetails, 1)
     
     	// Query for transactions, setting indexOffset to 5 (equal to number
     	// of transactions we have) and max_transactions to 0.
     	txDetails, _, _, err = alice.ListTransactionDetails(
    -		startHeight, chainTip, "", 5, 0,
    +		startHeight, chainTip, "", "", 5, 0,
     	)
     	require.NoError(t, err)
     	require.Len(t, txDetails, 0)
     
     	// Query for transactions, setting indexOffset to 4 (edge offset) and
     	// max_transactions to 0.
     	txDetails, _, _, err = alice.ListTransactionDetails(
    -		startHeight, chainTip, "", 4, 0,
    +		startHeight, chainTip, "", "", 4, 0,
     	)
     	require.NoError(t, err)
     	require.Len(t, txDetails, 1)
     
     	// Query for transactions, setting max_transactions to 0.
     	txDetails, _, _, err = alice.ListTransactionDetails(
    -		startHeight, chainTip, "", 0, 0,
    +		startHeight, chainTip, "", "", 0, 0,
     	)
     	require.NoError(t, err)
     	require.Len(t, txDetails, 5)
     
     	// Query for transactions, more than we have in the wallet (5).
     	txDetails, _, _, err = alice.ListTransactionDetails(
    -		startHeight, chainTip, "", 0, 10,
    +		startHeight, chainTip, "", "", 0, 10,
     	)
     	require.NoError(t, err)
     	require.Len(t, txDetails, 5)
     
     	// Query for transactions where the offset is greater than the number
     	// of transactions available.
     	txDetails, _, _, err = alice.ListTransactionDetails(
    -		startHeight, chainTip, "", 10, 100,
    +		startHeight, chainTip, "", "", 10, 100,
     	)
     	require.NoError(t, err)
     	require.Len(t, txDetails, 0)
     }
     

    @TechLateef
    Good catch! Added two new assertions that combine a label filter with a non-zero maxTransactions and indexOffset to cover this path:

    labelA + maxTransactions=1 + offset=0 → returns exactly the first matching tx
    labelA + maxTransactions=1 + offset=1 → returns exactly the second matching tx
    This exercises the pagination code path on the already-filtered set, which the previous tests bypassed by passing maxTransactions=

    saraogiraj94 saraogiraj94 commented on Jun 01, 2026 12:43 UTC
    Author

    @lightninglabs-deploy the changes requested are pushed

    TechLateef TechLateef commented on code on Jun 01, 2026 13:15 UTC
    Code Review
    lnwallet/btcwallet/btcwallet.go:1
    @@ -1523,6 +1523,18 @@ func (b *BtcWallet) ListTransactionDetails(startHeight, endHeight int32,
     		txDetails = append(txDetails, detail)
     	}
     
    +	// If a label filter is specified, only include transactions whose label
    +	// matches exactly.
    +	if labelFilter != "" {

    Oh, got it! That makes sense. I didn't realize GetTransactions was returning the entire block range unconditionally without a database-level limit.
    Since the label filter is applied to the full dataset before the pagination slice occurs, there's no risk of missing matching records. Thanks for clarifying the order of operations!

    TechLateef TechLateef commented on code on Jun 01, 2026 13:23 UTC
    Code Review
    lnwallet/btcwallet/btcwallet.go:1
    @@ -1481,7 +1481,7 @@ func unminedTransactionsToDetail(
     //
     // This is a part of the WalletController interface.

    I feel like the function documentation will require an update to reflect the new labelFilter parameter since the function signature changed.

    TechLateef TechLateef commented on Jun 01, 2026 13:33 UTC
    Contributor

    With the new tests added, this is looking great on my end! Once that function doc update is in place, it's ready to go. Great work!

    TechLateef TechLateef approved these changes on Jun 01, 2026 13:34 UTC
    Approved Reviewer

    Approved these changes.

    saraogiraj94 saraogiraj94 commented on Jun 08, 2026 16:13 UTC
    Author

    @lightninglabs-deploy the re review is triggered and good to go, @saubyk I am not sure tagging is you is correct or not, can you assist whom to tag for futher review and next steps.

    saubyk saubyk commented on Jun 08, 2026 16:55 UTC
    Contributor

    Hi @saraogiraj94
    As noted in the code contribution guidelines: https://github.com/lightningnetwork/lnd/blob/master/docs/code_contribution_guidelines.md#new-contributors, prs from new contributors are not typically prioritized for review. Unfortunately we don't have enough review cycles to allocate to LLM generated prs from new contributors.

    Would welcome your contributions in form of Issue reports and reviews on other prs. Once you have built a good track record of contributions in that form, we would be happy to review your prs.

    If there is a requirement you would want us to address in LND, recommend creating an issue report instead of putting up a pr.

    saraogiraj94 saraogiraj94 commented on Jun 08, 2026 19:11 UTC
    Author

    @saubyk

    Thanks for the clarification.

    This PR was created to address issue https://github.com/lightningnetwork/lnd/issues/10785, which was previously discussed and opened with a specific requirement. I understand the review bandwidth constraints and the policy regarding new contributors.

    I've spent time understanding the relevant code path and testing the change locally before submitting the PR. If there are specific concerns about the implementation or approach, I'd be happy to address them.

    Otherwise, I'll continue contributing through issue reports and PR reviews and hope to build a track record within the project over time.

    litbot-9000 litbot-9000 commented on Jun 15, 2026 20:23 UTC
    Contributor

    @saraogiraj94, remember to re-request review from reviewers when ready

    saraogiraj94 saraogiraj94 commented on Jun 16, 2026 08:16 UTC
    Author

    @saraogiraj94, remember to re-request review from reviewers when ready

    Whom to re request ?

    saubyk saubyk commented on Jun 16, 2026 14:16 UTC
    Contributor

    !lightninglabs-deploy mute

    Reviewers
    Assignees
    saraogiraj94 saraogiraj94
    Labels
    risk: low confidence: 83.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 62.7% (MEDIUM) · Higher = larger blast radius
    62.7%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 83.7% · Lower = rushed or shallow review
    83.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 10.2% · Safe to merge
    10.2%