Skip to content
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

Do not enforce new reserved value in PSBT midstep #5539

Conversation

Kixunil
Copy link
Contributor

@Kixunil Kixunil commented Jul 17, 2021

This change avoids enforcing new reserved value when PSBT funding is not
finished yet as new inputs and outputs may still be added that could
change the outcome of the check.

This originally failed in the scenario when funding a channel from
external wallet and depositing to on-chain wallet was done
simultaneously in a single transaction. If such transaction confirms
then reserved UTXO is guaranteed to be available but the check didn't
take it into account.

The enforcement still occurs in the final step of PSBT funding flow, so
it is safe. It also occurs in case of non-PSBT funding.

This partially fixes #5363 (comment)
For full fix it'd be great to be able to optionally avoid anchor commitments (to improve privacy).

I will look at tests later, I mainly wanted to get initial feedback on this. If anyone would like to help with writing tests I'd be happy to accept. :)

Pull Request Checklist

  • If this is your first time contributing, we recommend you read the Code
    Contribution Guidelines
  • All changes are Go version 1.12 compliant
  • The code being submitted is commented according to Code Documentation and Commenting
  • For new code: Code is accompanied by tests which exercise both
    the positive and negative (error paths) conditions (if applicable)
  • For bug fixes: Code is accompanied by new tests which trigger
    the bug being fixed to prevent regressions
  • Any new logging statements use an appropriate subsystem and
    logging level
  • Code has been formatted with go fmt
  • Protobuf files (lnrpc/**/*.proto) have been formatted with
    make rpc-format and compiled with make rpc
  • New configuration flags have been added to sample-lnd.conf
  • For code and documentation: lines are wrapped at 80 characters
    (the tab character should be counted as 8 characters, not 4, as some IDEs do
    per default)
  • Running make check does not fail any tests
  • Running go vet does not report any issues
  • Running make lint does not report any new issues that did not
    already exist
  • All commits build properly and pass tests. Only in exceptional
    cases it can be justifiable to violate this condition. In that case, the
    reason should be stated in the commit message.
  • Commits have a logical structure according to Ideal Git Commit Structure

Kixunil added a commit to Kixunil/loptos that referenced this pull request Jul 17, 2021
This allows adding additional funds to the wallet in the channel open
transaction which may be required to reserve funds for anchor
commitments.

This needs lightningnetwork/lnd#5539 to work
with an empty LND wallet.
@Kixunil
Copy link
Contributor Author

Kixunil commented Aug 5, 2021

Ping, could someone check if this is at least going in the right direction?

@guggero guggero added anchors funding Related to the opening of new channels with funding transactions on the blockchain psbt labels Aug 9, 2021
Copy link
Collaborator

@guggero guggero left a comment

Choose a reason for hiding this comment

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

The PR must've slipped below the radar, sorry for the delay.
I think this is going into the right direction. Especially when reading that comment I think that was the intended behavior from the beginning but a refactor/fix somehow changed it.

This should be covered by an integration test I think, just to make sure nothing else in the funding flow breaks.

// If no chanFunder was provided, then we'll assume the default
// assembler, which is backed by the wallet's internal coin selection.
if req.ChanFunder == nil {
enforceNewReservedValue = true
Copy link
Collaborator

Choose a reason for hiding this comment

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

There are three types of ChanFunder: PSBT, canned (used for Pool) and the wallet assembler. We only want to skip this check for the wallet assembler. So I think we should use the default value true and only disable it for the PSBT funder (with a type check).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure I understood you correctly, so I added another commit. Is that what you had in mind?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, this is what I meant. But it should be done in the same commit.

lnwallet/wallet.go Show resolved Hide resolved
@Kixunil
Copy link
Contributor Author

Kixunil commented Aug 9, 2021

I agree it should have test. Unfortunately I have literally zero experience with writing tests in Go and LND. If you could give me a few bullet points on where to put it and how to structure it that'd be very helpful.

@guggero guggero self-requested a review August 9, 2021 12:52
@guggero
Copy link
Collaborator

guggero commented Aug 11, 2021

See lntest/itest/lnd_psbt_test.go, there we already have a test that asserts the default PSBT channel funding flow. We could add an additional test that makes sure the reserves are checked in the correct step. Or extend the existing test with some additional checks.

@Kixunil
Copy link
Contributor Author

Kixunil commented Aug 11, 2021

I looked into it and it seems rpctest.Harness doesn't have public methods for creating and broadcasting transactions separately. It seems it could be solved by adding CreateTransaction and SendRawTransaction that'd pass arguments to the internal wallet.

Should I file a PR against https://github.com/btcsuite/btcd/ first or is there some other process I should follow?

That wouldn't help and I think it's not needed. We can use a third node to fund PSBT.

@Kixunil
Copy link
Contributor Author

Kixunil commented Aug 11, 2021

Is there a way to run a specific test only? The tests are slow and failing for what seem to be unrelated reasons, so I'd like to focus on getting this working.

@Kixunil Kixunil force-pushed the no-psbt-midstep-enforce-new-reserved-value branch from b5cd0b7 to 5695a4b Compare August 11, 2021 14:10
@guggero
Copy link
Collaborator

guggero commented Aug 11, 2021

https://github.com/lightningnetwork/lnd/blob/master/docs/MAKEFILE.md#itest

@Kixunil
Copy link
Contributor Author

Kixunil commented Sep 20, 2021

Strangely when I wrote my test, I tried to check if it actually fails without the change and it didn't. I couldn't figure out why and then life dragged me into bunch of other things. I still intend to try resolve this but if someone can help that'd be appreciated.

@Kixunil Kixunil force-pushed the no-psbt-midstep-enforce-new-reserved-value branch from 5695a4b to f4841b4 Compare November 22, 2021 08:05
@Kixunil
Copy link
Contributor Author

Kixunil commented Nov 22, 2021

Figured it out - forgot to enable anchors 🤦‍♂️

I rebased the changes and added the test which fails before the fix and passes after the fix. I only need to add release notes, but I don't know which version. Would it be possible to add this to point release, please? I was originally hoping to get this into 0.14...

@guggero guggero added this to the v0.14.1 milestone Nov 22, 2021
@guggero
Copy link
Collaborator

guggero commented Nov 22, 2021

Let's try with 0.14.1.

@guggero guggero self-requested a review November 22, 2021 08:58
@Kixunil Kixunil force-pushed the no-psbt-midstep-enforce-new-reserved-value branch from 4de952a to e7b35ed Compare November 22, 2021 09:39
@Kixunil Kixunil force-pushed the no-psbt-midstep-enforce-new-reserved-value branch from e7b35ed to c3f36ec Compare November 22, 2021 09:50
@Kixunil Kixunil force-pushed the no-psbt-midstep-enforce-new-reserved-value branch from c3f36ec to 632c54a Compare November 22, 2021 10:11
@Kixunil Kixunil force-pushed the no-psbt-midstep-enforce-new-reserved-value branch from 632c54a to 91fed51 Compare November 22, 2021 11:10
@Kixunil
Copy link
Contributor Author

Kixunil commented Nov 23, 2021

LOL, was looking at test and thinking why they don't run yet. :D Done.

@Kixunil Kixunil force-pushed the no-psbt-midstep-enforce-new-reserved-value branch from 1c92ec3 to 2964679 Compare November 23, 2021 19:48
@Kixunil
Copy link
Contributor Author

Kixunil commented Nov 23, 2021

Looks like same unrelated/flakes again.

@Kixunil Kixunil force-pushed the no-psbt-midstep-enforce-new-reserved-value branch from 2964679 to b6d720d Compare November 25, 2021 18:23
@Kixunil
Copy link
Contributor Author

Kixunil commented Nov 25, 2021

Updated release notes version to 0.14.2

@guggero guggero modified the milestones: v0.14.1, v0.14.2 Nov 29, 2021
Copy link
Collaborator

@guggero guggero left a comment

Choose a reason for hiding this comment

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

LGTM 🎉

@guggero guggero requested a review from Crypt-iQ November 29, 2021 11:34
@Kixunil Kixunil force-pushed the no-psbt-midstep-enforce-new-reserved-value branch from b6d720d to 77e2315 Compare December 3, 2021 13:57
@Kixunil
Copy link
Contributor Author

Kixunil commented Dec 3, 2021

Rebased

@Crypt-iQ Crypt-iQ removed their request for review December 3, 2021 20:34
@Kixunil Kixunil force-pushed the no-psbt-midstep-enforce-new-reserved-value branch from 77e2315 to cf65ee7 Compare December 9, 2021 23:08
@Kixunil Kixunil force-pushed the no-psbt-midstep-enforce-new-reserved-value branch from cf65ee7 to d1bf897 Compare December 9, 2021 23:21
This change avoids enforcing new reserved value when PSBT funding is not
finished yet as new inputs and outputs may still be added that could
change the outcome of the check.

This originally failed in the scenario when funding a channel from
external wallet *and depositing to on-chain wallet* was done
simultaneously in a single transaction. If such transaction confirms
then reserved UTXO is guaranteed to be available but the check didn't
take it into account.

The enforcement still occurs in the final step of PSBT funding flow, so
it is safe. It also occurs in case of non-PSBT funding.
This adds an integration test that makes sure channel can be funded from
empty wallet using PSBT if the funding transaction contains an output
belonging to the wallet, satisfying the reserve.
@Kixunil Kixunil force-pushed the no-psbt-midstep-enforce-new-reserved-value branch from d1bf897 to 333fe39 Compare December 9, 2021 23:23
Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

LGTM 🎎

@Kixunil
Copy link
Contributor Author

Kixunil commented Dec 10, 2021

Unrelated test failures again.

@guggero guggero merged commit 1ccd037 into lightningnetwork:master Dec 10, 2021
@Kixunil Kixunil deleted the no-psbt-midstep-enforce-new-reserved-value branch December 10, 2021 12:49
Roasbeef pushed a commit to Roasbeef/lnd that referenced this pull request Jan 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
anchors funding Related to the opening of new channels with funding transactions on the blockchain psbt
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants