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

funding: wait for coinbase maturity before sending channel_ready #7925

Merged
merged 3 commits into from Oct 5, 2023

Conversation

Crypt-iQ
Copy link
Collaborator

No description provided.

@Crypt-iQ Crypt-iQ added the funding Related to the opening of new channels with funding transactions on the blockchain label Aug 25, 2023
Copy link
Collaborator

@morehouse morehouse left a comment

Choose a reason for hiding this comment

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

Needs a test.

funding/manager.go Outdated Show resolved Hide resolved
@saubyk saubyk added this to the v0.18.0 milestone Aug 30, 2023
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.

Needs a release notes entry, otherwise this looks good.

funding/manager.go Outdated Show resolved Hide resolved
funding/manager.go Outdated Show resolved Hide resolved
funding/manager.go Outdated Show resolved Hide resolved
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 🎉

Copy link
Collaborator

@morehouse morehouse left a comment

Choose a reason for hiding this comment

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

This seems like a corner case we should add a test for.

@Crypt-iQ Crypt-iQ force-pushed the funding_maturity branch 3 times, most recently from 782863c to d525d90 Compare September 11, 2023 16:59
Comment on lines +4924 to +4929
// Send along the oneConfChannel again and then assert that the open
// event is sent. This serves as the 100 block + MinAcceptDepth
// confirmation.
alice.mockNotifier.oneConfChannel <- &chainntnfs.TxConfirmation{
Tx: fundingTx,
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This mock test does exercise the new code, but it's brittle. It does not actually test that coinbase maturity has been reached or that the channel can be closed immediately after channel_ready.

I think an itest is needed to properly test what we want.

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 test this in an itest, this needs to use the psbt flow and bitcoind as a miner to generate directly to the p2wsh via generatetoaddress. However, we use btcd as itest miner which doesn't have a generatetoaddress analog. We can't stop btcd and change the --miningaddr flag because the itests are parallel and another test may be using the miner. This unit test isn't ideal, but does give some coverage. I have also tested this on my machine several times with psbt's and bitcoind and verified that the channel was unusable until after 100+min depth confs. Unfortunately, I don't have time to change btcd's code to add the generatetoaddress rpc so I think this is the best we can do right now

funding/manager.go Outdated Show resolved Hide resolved
Comment on lines +4927 to +4933
alice.mockNotifier.oneConfChannel <- &chainntnfs.TxConfirmation{
Tx: fundingTx,
}

bob.mockNotifier.oneConfChannel <- &chainntnfs.TxConfirmation{
Tx: fundingTx,
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is revealing to me that theres some structural issues with the mock notifier. It makes some assumptions about the number of confirmations with the different channels and hardcodes the 6 conf case which doesn't make a tremendous amount of sense to me. Although that issue precedes this one, this change makes it clear that this test setup is improperly designed. At minimum it seems like the two channel setup might want to track 1. whether the tx has been mined, and 2. whether it has achieved the minimum depth.

I don't have any specific guidance on how to rectify this but I wanted to raise the issue in case others had some input on how to deal with it.

This is needed so that the next commit can create a ShimIntent
without having to export the ShimIntent's fields.
This tests that the funding manager doesn't immediately consider
a coinbase transaction that is also a funding transaction usable
until the maturity has been reached.
@lightninglabs-deploy
Copy link

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

@guggero guggero merged commit 31ba616 into lightningnetwork:master Oct 5, 2023
22 of 25 checks passed
@Crypt-iQ Crypt-iQ deleted the funding_maturity branch October 5, 2023 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
funding Related to the opening of new channels with funding transactions on the blockchain no-changelog
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

6 participants