Skip to content

Conversation

@jtobin
Copy link
Member

@jtobin jtobin commented Nov 19, 2025

Simply rebases 0-8-0-staging onto main, and merges it.

@gemini-code-assist
Copy link

Summary of Changes

Hello @jtobin, 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 integrates the 0-8-0-staging branch into main, bringing several significant improvements. It introduces a new reorg-aware block header cache to optimize blockchain data access. The AddrReceives RPC and its tapcli counterpart have been enhanced with pagination and sorting features, providing users with more flexible event retrieval. Additionally, the internal handling of macaroon whitelisting has been restructured for clearer access control, and the fee rate calculation for anchor transactions has been made more robust.

Highlights

  • Block Header Caching: Introduced a new reorg-aware BlockHeaderCache to efficiently store and retrieve block headers, reducing RPC calls and improving performance for blockchain data lookups. This cache handles blockchain reorganizations by invalidating affected entries.
  • AddrReceives RPC Enhancements: The AddrReceives RPC now supports pagination and sorting. New fields offset, limit, and direction have been added to the request, allowing users to retrieve address events in a more controlled and efficient manner.
  • tapcli Integration for AddrReceives: The tapcli addrs receives command has been updated with new flags (--limit, --offset, --direction) to leverage the pagination and sorting capabilities of the enhanced AddrReceives RPC.
  • Macaroon Whitelist Refactoring: The macaroon whitelist logic has been refactored to provide more granular control over public access to Universe RPC endpoints. Default whitelisting is now handled inline within the MacaroonWhitelist function, ensuring better permission management.
  • Fee Rate Calculation Refinement: The logic for calculating the anchor transaction fee rate has been refined, including checks against the minimum relay fee and improved handling of manual fee rate assignments.
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 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 counter productive. 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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

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 merges the 0-8-0-staging branch into main, introducing several new features and improvements. Key changes include adding pagination and sorting capabilities to the AddrReceives RPC, implementing a BlockHeaderCache to optimize chain interactions by reducing RPC calls, and refactoring macaroon permissions for better security and control. The tests have been updated to cover the new functionalities. My review identifies a bug in a SQL query that could lead to incorrect ordering and a minor redundancy in the RPC server logic. Overall, these are solid improvements to the codebase.

Comment on lines +231 to +232
CASE WHEN sqlc.narg('sort_direction') = 1 THEN addr_events.creation_time END DESC,
CASE WHEN sqlc.narg('sort_direction') != 1 THEN addr_events.creation_time END ASC

Choose a reason for hiding this comment

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

high

The current ORDER BY clause has a subtle bug when sort_direction is NULL. In SQL, NULL != 1 evaluates to NULL, not true. This means if sort_direction is not provided (and becomes NULL), no ordering will be applied, leading to unpredictable results. The default behavior should be ascending order as per the comments.

A more robust way to write this is to handle the NULL case explicitly to default to ascending order.

    CASE sqlc.narg('sort_direction')
        WHEN 1 THEN addr_events.creation_time
    END DESC,
    CASE sqlc.narg('sort_direction')
        WHEN 1 THEN NULL
        ELSE addr_events.creation_time
    END ASC


sqlQuery.Offset = req.Offset
sqlQuery.Limit = req.Limit
sqlQuery.SortDirection = address.DescSortDirection

Choose a reason for hiding this comment

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

medium

This line is redundant. The following switch statement correctly handles all cases for setting sqlQuery.SortDirection. The default value for the req.Direction enum is SORT_DIRECTION_DESC, which is handled in the switch.

darioAnongba and others added 23 commits November 19, 2025 17:09
Refactor the function by introducing an internal helper to improve
readability.
Refactor MacaroonWhitelist to handle public universe proof courier
permissions independently. This clarifies the logic and avoids coupling
courier access with other universe server permissions.
Remove the defaultMacaroonWhitelist map and inline its entries directly
into the conditional logic within MacaroonWhitelist. This ensures that
access to previously always-available endpoints is now governed by
explicit user configuration (read/write/courier), improving permission
control and aligning with expected access restrictions.
Separate the mint anchor transaction fee rate calculation from
fundGenesisPsbt into anchorTxFeeRate.

This refactor is part of a broader effort to simplify calling
fundGenesisPsbt from unit tests.
Extract the wallet funding call into a closure that is passed as an
argument. This prepares fundGenesisPsbt to become a standalone
function, making it easier to call in unit tests.
Pass the pending batch and chain params into fundGenesisPsbt and convert
it into a standalone function rather than a method on ChainPlanter. This
change makes it easier to call fundGenesisPsbt from unit tests.
The batch key was only used for logging. This commit moves the log
messages outside fundGenesisPsbt, simplifying the function for
better code health.
The mock helper FundGenesisTx now returns the index of the change
output. It also dynamically computes the index of the change output it
adds. These enhancements will be useful when handling packets with
supply pre-commitment outputs.
The funding routine now uses the refactored fundGenesisPsbt function,
introduced in a previous commit. Which adds test coverage for the batch
funding logic.

An optional argument is also added to allow skipping funding.
Refactored GetBlockTimestamp to call GetBlockHeaderByHeight and return
an optional error type. Removed the timestamp-to-block-height cache, as
it did not handle re-orgs correctly. This prepares the codebase for a
more comprehensive caching mechanism to be added in a follow-up commit.
Introduce a reusable cache that stores full headers keyed by height and
hash. Tracks confirmation depth and treats shallow entries as unsettled
(return miss). Detects conflicts at a height and invalidates shallower
headers on reorg. Size and random purge fraction are configurable
(default 100k entries, 10 percent).

Not yet used by LndRpcChainBridge.
Adds a block header cache to LndRpcChainBridge, which indirectly
improves performance of methods like GetBlockTimestamp by avoiding
repeated block header fetches.
@coveralls
Copy link

Pull Request Test Coverage Report for Build 19502409622

Details

  • 396 of 504 (78.57%) changed or added relevant lines in 17 files are covered.
  • 62 unchanged lines in 17 files lost coverage.
  • Overall coverage increased (+0.1%) to 56.541%

Changes Missing Coverage Covered Lines Changed/Added Lines %
universe/supplycommit/mock.go 0 2 0.0%
tapcfg/server.go 14 17 82.35%
tapgarden/mock.go 32 35 91.43%
taprpc/perms.go 38 44 86.36%
cmd/commands/addrs.go 0 7 0.0%
lndservices/block_header_cache.go 152 161 94.41%
taprpc/universerpc/universe.pb.go 1 10 10.0%
taprpc/taprootassets.pb.go 4 15 26.67%
tapgarden/planter.go 79 91 86.81%
lndservices/chain_bridge.go 17 31 54.84%
Files with Coverage Reduction New Missed Lines %
fn/context_guard.go 1 91.94%
tapgarden/mock.go 1 74.29%
asset/group_key.go 2 72.15%
mssmt/compacted_tree.go 2 78.11%
tapdb/addrs.go 2 76.62%
tapdb/assets_common.go 2 78.34%
tapdb/mssmt.go 2 90.45%
asset/mock.go 3 73.21%
itest/multisig.go 3 97.94%
tapchannel/aux_leaf_signer.go 3 43.53%
Totals Coverage Status
Change from base Build 19501755090: 0.1%
Covered Lines: 64317
Relevant Lines: 113753

💛 - Coveralls

Copy link
Contributor

@ffranr ffranr left a comment

Choose a reason for hiding this comment

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

This looks fine to me. I don't think any of the commit contents have changed.

Copy link
Contributor

@darioAnongba darioAnongba left a comment

Choose a reason for hiding this comment

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

LGTM. Please no more staging branches ever again 🤣

@jtobin jtobin added this pull request to the merge queue Nov 20, 2025
Merged via the queue into lightninglabs:main with commit 18db746 Nov 20, 2025
37 of 38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants