-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expose confirmation count for pending 'channel open' transactions #9677
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
Expose confirmation count for pending 'channel open' transactions #9677
Conversation
Important Review skippedAuto reviews are limited to specific labels. 🏷️ Labels to auto review (1)
Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
43bc2b9
to
0e4bc79
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
providing some initial comments. will test further.
0e4bc79
to
161d639
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took a deeper look at manager_test
and have a few questions.
funding/manager_test.go
Outdated
// We send two notifications: | ||
// 1. The first adds the SCID to the database, allowing calculation of | ||
// the number of confirmations before the channel is fully opened. | ||
// 2. The second marks the channel as open. | ||
alice.mockNotifier.oneConfChannel <- &chainntnfs.TxConfirmation{ | ||
Tx: fundingTx, | ||
} | ||
bob.mockNotifier.oneConfChannel <- &chainntnfs.TxConfirmation{ | ||
Tx: fundingTx, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works, but this doesn't reflect the actual open channel process, right? Have you considered sending the channel confirmation after the transaction confirmation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I didn't quite understand what you meant. My understanding is that if we wait until the transaction is confirmed (after 3 or 6 blocks, etc.), then by the time we mark the channel as confirmed, it will already be open. Also, since we need the details of the SCID, we have to mark the channel as confirmed (after 1 block) even before the transaction is fully confirmed. Am I thinking in the right direction, or is there anything I should read first to better align my thoughts with your points?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meaning that you are sending the confirmation tx event twice to Alice and Bob funding managers. I'm not sure if this is happening during the normal workflow when a channel is opening.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meaning that you are sending the confirmation tx event twice to Alice and Bob funding managers. I'm not sure if this is happening during the normal workflow when a channel is opening.
Ok, so what I understand is that in a normal, real-world workflow, whenever a confirmation tx notification is registered, the notification is sent to all the goroutines that registered for it as soon as the block is mined. However, since this is a unit test, I need to explicitly send the confirmation tx event twice.
Have you considered sending the channel confirmation after the transaction confirmation?
Since we need the details of the SCID, we have to mark the channel as confirmed (after one block) even before the transaction is fully confirmed.
Also, if I send the goroutine for channel confirmation after the transaction confirmation, I still need to send the confirmation tx event twice because of the select statement:
- If one or more of the communications can proceed, a single one that can proceed is chosen via a uniform pseudo-random selection.
See: https://go.dev/ref/spec#Select_statements
To avoid flaky tests, I send the confirmation tx event twice.
I hope this is the correct way of handling the process. Please suggest any better method you have in mind.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree this testHarness could be better mocked, however both nodes need to receive the confirmation to finally set the channel to active.
Tho this changes with my proposal so I am not going to review this for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested three scenarios:
- Regular channel, default confirmations required for active is 3.
confirmations_until_active
value inpendingchannels
response tracks, until the channel is active. Test pass. - Wumbo channel, default confirmations required for active is 6.
confirmations_until_active
value inpendingchannels
response tracks, until the channel is active. Test pass. - Updated the node config with
bitcoin.defaultchanconfs=4
.confirmations_until_active
value inpendingchannels
response doesn't track. It still starts off with a value of 3 (should start with 4) and channels gets active after 3 confirmations. Test fail.
Don't think that the issue with last scenario has been introduced with this change. But it would be good to investigate further why the setting in config is not having any bearing on the default behavior.
I checked this locally and it works for me. I have also added an itest for this case. Not entirely sure, but it seems like you might have missed what So:
|
Good clarification. Tested again by updating the peer's setting and was able to get the correct values for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work. tAck.
Code review needs approval from two other devs.
cc: @kaloudis would you like to test this pr and provide some feedback?
161d639
to
8a13679
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for picking this issue up 👍.
Nice work so far, the direction is the right one, left some comments for you.
funding/manager.go
Outdated
// database once the channel opening transaction receives one | ||
// confirmation. This enables us to calculate the number of | ||
// confirmations before the pending channel becomes active. | ||
if !ch.IsZeroConf() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not necessary, for can use the function waitForFundingConfirmation
to update the short channel id.
itest/lnd_open_channel_test.go
Outdated
|
||
// ConfirmationsUntilActive field should decrease as each block is | ||
// mined until the required number of confirmations is reached. Let's | ||
// mine a few empty blocks and verify the value of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should mine normal blocks here, because there is no tx in the mempool anyways ?
itest/lnd_open_channel_test.go
Outdated
// mined until the required number of confirmations is reached. Let's | ||
// mine a few empty blocks and verify the value of | ||
// ConfirmationsUntilActive at each step. | ||
for i := int32(1); i < numConfs; i++ { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think for these cases a reverse loop fits better:
// we could also decrease the numConfs immediately when confirming the tx above which is maybe even better.
for i := numConfs-1; i > 0; i-- {
expectedConfirmationsLeft := i
8a13679
to
675a709
Compare
lnrpc/lightning.proto
Outdated
// | ||
// "Active" here means both channel peers have the channel marked OPEN | ||
// and can immediately start using it. For public channels, this does | ||
// not imply a channel_announcement has been gossiped—it only becomes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: gossiped-it => gossiped. It ...
itest/lnd_open_channel_test.go
Outdated
@@ -877,6 +877,114 @@ func testFundingExpiryBlocksOnPending(ht *lntest.HarnessTest) { | |||
ht.MineBlocksAndAssertNumTxes(1, 1) | |||
} | |||
|
|||
// testConfirmationsUntilActiveOnPending verifies that as a channel status |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: testConfirmationsUntilActiveOnPending => testPendingChannelConfirmationUntilActive verifies the value for the rpc filed ConfirmationUntilActive
decreases as expected as soon as blocks are confirmed.
itest/lnd_open_channel_test.go
Outdated
) | ||
|
||
// Mine the first block containing the funding transaction, This | ||
// confirms the funding transaction but does not change the channel |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: confirms the funding transaction but the channel should still remain pending ...
channeldb/channel_test.go
Outdated
require.NoError(t, err, "unable to mark channel's confirmation height") | ||
|
||
// Ensure the channel remains pending after confirmation. | ||
require.True(t, pendingChannels[0].IsPending, "channel should remain "+ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: Not sure if this case here makes sense, because the confirmation height is not related to the pending status directly.
channeldb/channel_test.go
Outdated
) | ||
|
||
// Confirm the channel remains pending after refresh. | ||
require.True(t, channelState.IsPending, "channel should remain "+ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for finalizing this PR, had some final nits.
/gemini review |
There was a problem hiding this 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 introduces a mechanism to track the confirmation count for pending channels, exposing this information via the PendingChannels
RPC. This is achieved by persisting the confirmation height of the funding transaction and modifying the chain notifier to provide more detailed transaction updates. The changes are well-tested, including new unit and integration tests that cover the new functionality and edge cases like reorgs. My review includes a suggestion to refactor a duplicated code block for better maintainability and a fix for a minor bug in a new test case.
5b96614
to
ec35671
Compare
should I add an itest for this? I'm not sure if there's a way to do it in itest, but I can check/implement if possible. |
I don't think it is super important for this feature, however if you are interested you can look at |
while working on this, I found a critical bug (in this PR) that occurs during a reorg -- the |
Perfect, also a reminder to always test ! So let's fix the problem can you push the itest. |
I think we just need to make a litter change here:
|
@NishantBansal2003 please be aware that we prioritized this for LND20, are you able to fix the underlying issue in the next days ? Otherwise we move it into LND 21 |
Oops, apologies, everything is done locally, only my testing remains. I will test and push by the end of today (IST timezone) |
ec35671
to
2a7fc27
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pending CI, otherwise excellent work, LGTM 🎉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re-ACK, thank you for adding the reorg itest 🙏
itest/lnd_open_channel_test.go
Outdated
// Cleanup by mining the remaining blocks to reach the required number | ||
// of confirmations, then closing the channel. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: comment doesn't reflect the behavior
// Because as soon as a new block is connected which has the | ||
// transaction included again we preemptively read the buffered | ||
// channel. | ||
select { | ||
case ntfn.Event.NegativeConf <- int32(n.reorgDepth): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this doesn't block because we will only send on the channel once on reorg of the funding tx's block and it will be emptied by ConnectTip
-> handleConfDetailsAtTip
In this commit, we send the reorg notification even when the transaction has not yet reached the required confirmations, in case the caller is interested in knowing about it. Signed-off-by: Nishant Bansal <[email protected]>
Enhance the ConfirmationEvent's Updates channel by including the BlockHeight alongside NumConfsLeft. Signed-off-by: Nishant Bansal <[email protected]>
Add the MarkConfirmationHeight method to the OpenChannel struct to record the block height at which the funding transaction was first confirmed. Also, introduce the ConfirmationHeight field to persist this information in the database. Signed-off-by: Nishant Bansal <[email protected]>
This change ensures that a channel's ConfirmationHeight is recorded in the database once its funding transaction receives its initial confirmation. By doing so, we establish a reliable reference point to monitor the channel's progress toward the required confirmation depth. Signed-off-by: Nishant Bansal <[email protected]>
Introduce ConfirmationsUntilActive and ConfirmationHeight in PendingChannelsResponse_PendingChannel. ConfirmationsUntilActive indicates the remaining confirmations needed for the channel to become active. If the funding transaction is unconfirmed, ConfirmationsUntilActive defaults to the total required confirmations (NumConfsRequired). ConfirmationHeight records the block height at which the funding transaction was first confirmed; if unconfirmed, it will be 0. Signed-off-by: Nishant Bansal <[email protected]>
Signed-off-by: Nishant Bansal <[email protected]>
Signed-off-by: Nishant Bansal <[email protected]>
2a7fc27
to
64a841b
Compare
Change Description
Fixes: #9452
This PR enhances the
PendingChannelsResponse_PendingChannel
structure to include theConfirmationsUntilActive
field. This new field provides users with the exact number of confirmations required for a pending channel's transition to an active state.Changes:
Database Update:
The channel's
shortchannelID
is now persisted in the database once its funding transaction receives 1 confirmation. This ensures we have a reference point to track progress toward the required confirmation depth.API Enhancement:
Introduced the
ConfirmationsUntilActive
field in thePendingChannelsResponse_PendingChannel
response. This field indicates the remaining confirmations needed for the channel to become active.ConfirmationsUntilActive
defaults to the total required confirmations (NumConfsRequired
).Steps to Test
itest: itest have been added to validate this new functionality.
Manual Verification: To manually test:
Establish a channel between two peers without confirming the funding transaction.
Execute
lncli pendingchannels
to observe theconfirmations_until_active
field, which should display the remaining confirmations needed for the pending channel to transition to an active state.Pull Request Checklist
Testing
Code Style and Documentation
[skip ci]
in the commit message for small changes.📝 Please see our Contribution Guidelines for further guidance.