Skip to content

staticaddr: show deposits and swap hashes in cli #991

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

hieblmi
Copy link
Collaborator

@hieblmi hieblmi commented Aug 12, 2025

This PR adds displaing the swap hash in listdeposits and the used deposits in listswaps.

Examples:

loop static listswaps:

"swaps":  [
        {
            "swap_hash":  "842011a3881fcf74b04031dfdfc39c5ad2ee295c7fb29251fdf536f04c440b7e",
            "deposit_outpoints":  [
                "3b6d20e7cf6d9cd1e2dac45d1f10e222992fcac9196c21d35705a9e5bb360a4a:0",
                "7b3cfabfc34d821865307f171a8ebf4f554094736d9211608a28248b3a009180:0"
            ],
            "state":  "SUCCEEDED",
            "swap_amount_satoshis":  "500000",
            "payment_request_amount_satoshis":  "496713",
            "deposits":  [
                {
                    "id":  "6a77c7ec31a55c420e51b9658961e3388091e4c402ebec0bcf43c4215b036857",
                    "state":  "LOOPED_IN",
                    "outpoint":  "3b6d20e7cf6d9cd1e2dac45d1f10e222992fcac9196c21d35705a9e5bb360a4a:0",
                    "value":  "250000",
                    "confirmation_height":  "120",
                    "blocks_until_expiry":  "0",
                    "swap_hash":  "842011a3881fcf74b04031dfdfc39c5ad2ee295c7fb29251fdf536f04c440b7e"
                },
                {
                    "id":  "0186d9dd10cdeffe23eeeab0bfb28526bc2727e01b6dc761e2e57acffc2576c2",
                    "state":  "LOOPED_IN",
                    "outpoint":  "7b3cfabfc34d821865307f171a8ebf4f554094736d9211608a28248b3a009180:0",
                    "value":  "250000",
                    "confirmation_height":  "120",
                    "blocks_until_expiry":  "0",
                    "swap_hash":  "842011a3881fcf74b04031dfdfc39c5ad2ee295c7fb29251fdf536f04c440b7e"
                }
            ]
        }
    ]

loop static listdeposits:

"filtered_deposits":  [
        {
            "id":  "6a77c7ec31a55c420e51b9658961e3388091e4c402ebec0bcf43c4215b036857",
            "state":  "LOOPED_IN",
            "outpoint":  "3b6d20e7cf6d9cd1e2dac45d1f10e222992fcac9196c21d35705a9e5bb360a4a:0",
            "value":  "250000",
            "confirmation_height":  "120",
            "blocks_until_expiry":  "14395",
            "swap_hash":  "842011a3881fcf74b04031dfdfc39c5ad2ee295c7fb29251fdf536f04c440b7e"
        },
        {
            "id":  "0186d9dd10cdeffe23eeeab0bfb28526bc2727e01b6dc761e2e57acffc2576c2",
            "state":  "LOOPED_IN",
            "outpoint":  "7b3cfabfc34d821865307f171a8ebf4f554094736d9211608a28248b3a009180:0",
            "value":  "250000",
            "confirmation_height":  "120",
            "blocks_until_expiry":  "14395",
            "swap_hash":  "842011a3881fcf74b04031dfdfc39c5ad2ee295c7fb29251fdf536f04c440b7e"
        }
    ]

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.

Summary of Changes

Hello @hieblmi, 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 significantly enhances the command-line interface (CLI) for static address swaps and deposits by integrating more comprehensive data. Previously, certain details were not readily available. The changes introduce the display of associated deposit information and swap hashes directly within the CLI output, making it easier for users to track and understand the state of their static address operations. This improves the overall observability and user experience without altering core swap or deposit functionalities.

Highlights

  • Enhanced Static Address Swap Details: The ListStaticAddressSwaps RPC now includes detailed deposit information for each static address loop-in swap. This is achieved by fetching all deposits and associating them with their respective swaps using the SwapHash.
  • Deposit-to-Swap Linkage: The Deposit message now contains a SwapHash field, directly linking individual deposits to the static address loop-in swaps they are part of. This provides a clearer relationship between deposits and swaps.
  • Database Performance Improvements: New database indices have been added to the deposits and deposit_updates tables. These indices (deposits_id_index and deposit_updates_id_timestamp_index) will improve the performance of database queries related to deposits.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue 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 enhances the CLI by showing deposits and swap hashes, which is a great improvement for user visibility. The changes are well-implemented across the database schema, protobuf definitions, and server logic. I've identified one area for improvement to ensure API consistency: the BlocksUntilExpiry field for deposits within a swap is not populated. I've added comments with suggestions to address this.

Comment on lines 1778 to 1809
pd := &looprpc.Deposit{
Id: d.ID[:],
State: toClientDepositState(d.GetState()),
Outpoint: d.OutPoint.String(),
Value: int64(d.Value),
ConfirmationHeight: d.ConfirmationHeight,
SwapHash: d.SwapHash,
}

Choose a reason for hiding this comment

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

medium

The BlocksUntilExpiry field is not being set for the deposits associated with a swap. This is inconsistent with the ListStaticAddressDeposits endpoint where this field is populated. This field should be calculated using the bestBlockHeight and expiry variables.

				pd := &looprpc.Deposit{
					Id:                 d.ID[:],
					State:              toClientDepositState(d.GetState()),
					Outpoint:           d.OutPoint.String(),
					Value:              int64(d.Value),
					ConfirmationHeight: d.ConfirmationHeight,
					SwapHash:           d.SwapHash,
					BlocksUntilExpiry:  d.ConfirmationHeight + expiry - bestBlockHeight,
				}

Copy link
Member

Choose a reason for hiding this comment

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

Shall we fill BlocksUntilExpiry?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I wasn't sure about the applicability of this field since it shouldn't provide value after a deposit is swapped. But I guess we can add it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

added

@hieblmi hieblmi self-assigned this Aug 12, 2025
@hieblmi hieblmi force-pushed the cli-show-deposits-and-swaphashes branch 5 times, most recently from ef480c6 to d068e9e Compare August 18, 2025 11:26
Copy link
Member

@bhandras bhandras left a comment

Choose a reason for hiding this comment

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

Looks good, just a few nits!

Comment on lines 1778 to 1809
pd := &looprpc.Deposit{
Id: d.ID[:],
State: toClientDepositState(d.GetState()),
Outpoint: d.OutPoint.String(),
Value: int64(d.Value),
ConfirmationHeight: d.ConfirmationHeight,
SwapHash: d.SwapHash,
}
Copy link
Member

Choose a reason for hiding this comment

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

Shall we fill BlocksUntilExpiry?

@hieblmi hieblmi force-pushed the cli-show-deposits-and-swaphashes branch from d068e9e to 0b699c2 Compare August 18, 2025 13:36
@hieblmi hieblmi requested a review from bhandras August 18, 2025 13:37
Copy link
Collaborator

@starius starius left a comment

Choose a reason for hiding this comment

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

LGTM pending comments 💾

@hieblmi hieblmi force-pushed the cli-show-deposits-and-swaphashes branch from 0b699c2 to 8d04f67 Compare August 18, 2025 17:27
@hieblmi hieblmi requested a review from starius August 18, 2025 17:27
Copy link
Member

@bhandras bhandras left a comment

Choose a reason for hiding this comment

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

LGTM, pending build fix 🎉

@hieblmi hieblmi force-pushed the cli-show-deposits-and-swaphashes branch from 8d04f67 to 1bacf26 Compare August 19, 2025 20:28
@@ -281,6 +290,7 @@ func ToDeposit(row sqlc.Deposit, lastUpdate sqlc.DepositUpdate) (*Deposit,
ConfirmationHeight: row.ConfirmationHeight,
TimeOutSweepPkScript: row.TimeoutSweepPkScript,
ExpirySweepTxid: expirySweepTxid,
SwapHash: &swapHash,
Copy link
Collaborator

Choose a reason for hiding this comment

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

It should be nil if row.SwapHash == nil

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

To avoid the pointer pitfalls I've changed the declaration of SwapHash to lntypes.Hash instead of a pointer.


depositsBySwap := make(map[lntypes.Hash][]*deposit.Deposit, len(swaps))
for _, d := range allDeposits {
if len(d.SwapHash) == 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

if d.SwapHash == nil
It's a pointer to lntypes.Hash now, not a byte slice.

Copy link
Collaborator

Choose a reason for hiding this comment

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

len(d.SwapHash) always return the length of lntypes.Hash array type.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this code below panics if d.SwapHash is nil:

			pd := &looprpc.Deposit{
					Id:                 d.ID[:],
					State:              state,
					Outpoint:           d.OutPoint.String(),
					Value:              int64(d.Value),
					ConfirmationHeight: d.ConfirmationHeight,
					SwapHash:           d.SwapHash[:],
					BlocksUntilExpiry:  blocksUntilExpiry,
				}

d.SwapHash[:] is segfault.

Could you add an test/itest to safeguard against this in the future, please?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

added a unit-test.

@@ -270,6 +271,14 @@ func ToDeposit(row sqlc.Deposit, lastUpdate sqlc.DepositUpdate) (*Deposit,
}
}

var swapHash lntypes.Hash
Copy link
Collaborator

Choose a reason for hiding this comment

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

var swapHash *lntypes.Hash

@hieblmi hieblmi force-pushed the cli-show-deposits-and-swaphashes branch 2 times, most recently from 701b631 to 574ca7a Compare August 20, 2025 09:31

/*
The swap hash of the swap that this deposit is part of. This field is only
set if the deposit is part of a loop-in swap.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This field is empty inside looprpc.ListStaticAddressWithdrawalResponse but it is an array of zero bytes inside looprpc.ListStaticAddressDepositsResponse for deposits not associated with a swap.

Function filter in loopd/swapclient_server.go sets it to an array of zero bytes if it is ZeroHash. It is called e.g. to fill looprpc.ListStaticAddressDepositsResponse proto message.

Can we update the code to always produce an empty slice for this field in proto for consistency? I propose to verify this with a test.

}
}

func dummyTxHashBytes() []byte {
Copy link
Collaborator

Choose a reason for hiding this comment

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

s/dummyTxHashBytes/dummyHashBytes/

It is not a tx hash.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

changed the name

@hieblmi hieblmi force-pushed the cli-show-deposits-and-swaphashes branch from 574ca7a to b2a4d7a Compare August 20, 2025 15:10
Copy link
Collaborator

@starius starius left a comment

Choose a reason for hiding this comment

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

LGTM! 🏗

I tested this PR manually with loop static listdeposits. It works as intended! It provides swap hashes for swap associated deposits and "swap_hash": "" otherwise.

@hieblmi hieblmi merged commit 7c2f676 into lightninglabs:master Aug 20, 2025
4 checks passed
@hieblmi hieblmi deleted the cli-show-deposits-and-swaphashes branch August 20, 2025 16:36
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.

3 participants