Skip to content

staticaddr: persist withdrawal info #938

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

hieblmi
Copy link
Collaborator

@hieblmi hieblmi commented May 9, 2025

addresses #936

sample output:

loop --network=regtest s listwithdrawals  
{
    "withdrawals": [
        {
            "tx_id": "9379f48176ad724396322018b1a6f04ae6a19e868bd5fb0ef1d44a28889bf6a9",
            "outpoints": [
                "4cf5f636a598ffdb4fcd9ba9f2574a4a4cb2347decce88f25c4b0efa9e7a4e58:0",
                "29062f15a18cd1fc16a7701acbd608c232e3063302716a138f34b908de371d69:1"
            ],
            "total_deposit_amount_satoshis": "500000",
            "withdrawn_amount_satoshis": "483150",
            "change_amount_satoshis": "0",
            "confirmation_height": 129
        },
        {
            "tx_id": "5f2943ef018617cc3b0e3967b6e34a1ca472c5896282425f96c2bae159da25d9",
            "outpoints": [
                "25a16919cc297f21e6d25812dd4cb6d9c5f6b7158dba25522d3b658fefd8bc0a:1",
                "be4f24f4dde6cc51b5f9e06132cf5fcad895afcb0b7b471c627cd3bd71003e53:0",
                "5a5b8c7ea10409c81c6f8637402b83c008a4f3fdf4f5b02b52069b72df50ba11:0",
                "0dc433eef2191ecefdf950e111850f650905d9b9f2350a90766fee137e476858:0",
                "5bed66d98a76bda5fa1e35cd86060e8c15a3d7432a2d3c4708294decc54852d2:0"
            ],
            "total_deposit_amount_satoshis": "1034600",
            "withdrawn_amount_satoshis": "1000000",
            "change_amount_satoshis": "34216",
            "confirmation_height": 150
        }
    ]
}

@hieblmi hieblmi marked this pull request as draft May 9, 2025 13:18
@hieblmi hieblmi self-assigned this May 9, 2025
@hieblmi hieblmi force-pushed the withdraw-info branch 2 times, most recently from aab693b to e22b2b2 Compare May 13, 2025 09:40
@hieblmi hieblmi marked this pull request as ready for review May 13, 2025 09:40
@hieblmi hieblmi requested review from sputn1ck, bhandras and starius May 13, 2025 10:01
@hieblmi
Copy link
Collaborator Author

hieblmi commented May 15, 2025

Rebased.

@hieblmi
Copy link
Collaborator Author

hieblmi commented May 20, 2025

Rebased

Copy link
Member

@sputn1ck sputn1ck left a comment

Choose a reason for hiding this comment

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

LGTM, but I think a quick sql store unit test would be nice


// SqlStore is the backing store for static address withdrawals.
type SqlStore struct {
baseDB *loopdb.BaseDB
Copy link
Member

@sputn1ck sputn1ck May 20, 2025

Choose a reason for hiding this comment

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

this exposes the full queries to this package, which IMO is not neccessary. as we usually define a Querier interface.


-- deposit_outpoints is a concatenated list of outpoints that are used for
-- this withdrawal. The list has the format txid1:idx;txid2:idx;...
deposit_outpoints TEXT NOT NULL,
Copy link
Member

Choose a reason for hiding this comment

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

could it make sense to really sqlize this? and reference the db deposit id?
So add a table with:
ID, withdrawal_id REFRERNCES withdrawals.id(or tx_id), deposit_id REFERENCES(deposits.deposit_id)
I noticed we don't do the same in static loop ins, but it would allow for more interesting queries i feel.

Copy link
Member

Choose a reason for hiding this comment

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

+1

}

// CreateWithdrawal creates a static address withdrawal record in the database.
func (s *SqlStore) CreateWithdrawal(ctx context.Context, tx *wire.MsgTx,
Copy link
Member

Choose a reason for hiding this comment

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

I propose adding a light unit test for future regressions.

Copy link
Member

Choose a reason for hiding this comment

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

+1

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.

Really nice feature, added a couple of comments/suggestions.

-- withdrawals stores finalized static address withdrawals.
CREATE TABLE IF NOT EXISTS withdrawals (
-- id is the auto-incrementing primary key for a withdrawal.
id INTEGER PRIMARY KEY,
Copy link
Member

Choose a reason for hiding this comment

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

I think it'd be nice to add an initiated_at column to this table, so that we can then filter on that on the cli too.


-- deposit_outpoints is a concatenated list of outpoints that are used for
-- this withdrawal. The list has the format txid1:idx;txid2:idx;...
deposit_outpoints TEXT NOT NULL,
Copy link
Member

Choose a reason for hiding this comment

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

+1


-- confirmation_height is the block height at which the withdrawal was
-- first confirmed.
confirmation_height BIGINT NOT NULL
Copy link
Member

Choose a reason for hiding this comment

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

Should this be allowed to be NULL until the withdrawal confirms?

m.mu.Lock()
delete(m.finalizedWithdrawalTxns, txHash)
m.mu.Unlock()

// Persist info about the finalized withdrawal.
err = m.cfg.Store.CreateWithdrawal(
Copy link
Member

Choose a reason for hiding this comment

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

It'd be nicer to add the withdrawal at the time it is requested then later on set it to confirmed.

}

// CreateWithdrawal creates a static address withdrawal record in the database.
func (s *SqlStore) CreateWithdrawal(ctx context.Context, tx *wire.MsgTx,
Copy link
Member

Choose a reason for hiding this comment

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

+1

@bhandras bhandras removed the request for review from starius May 20, 2025 11:43
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