-
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
base: master
Are you sure you want to change the base?
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 👍
channeldb/channel_test.go
Outdated
// TestPendingChannelConfirmation verifies that the confirmed state is updated | ||
// upon calling MarkConfirmedScid and that Refresh updates the in-memory state | ||
// of another OpenChannel to reflect a preceding call to MarkConfirmedScid on | ||
// a different OpenChannel. |
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: Two sentences improve the readability.
// TestOpeningChannelTxConfirmation verifies that calling MarkConfirmedScid
// correctly updates the confirmed state. It also ensures that calling Refresh
// on a different OpenChannel updates its in-memory state to reflect the prior
// MarkConfirmedScid call.
rpcserver.go
Outdated
@@ -3919,6 +3919,27 @@ func (r *rpcServer) fetchPendingOpenChannels() (pendingOpenChannels, error) { | |||
pendingChan.BroadcastHeight() | |||
fundingExpiryBlocks := int32(maxFundingHeight) - currentHeight | |||
|
|||
// ConfirmationUntilConfirmed is the number of blocks remaining |
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: referring to the variable 'ConfirmationUntilConfirmed' but at this point of the code you are using 'remainingConfs'.
rpcserver.go
Outdated
// confirmation height. This is calculated as distance from the | ||
// current block height to the block height where the funding | ||
// transaction is located + required number of confirmations. |
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.
The comment doesn't accurately reflect what the code does. Please review and clarify it. The code itself looks correct.
rpcserver.go
Outdated
CommitFee: int64(localCommitment. | ||
CommitFee), | ||
FeePerKw: int64(localCommitment. | ||
FeePerKw), |
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.
You don't need to split each one into two lines.
channeldb/channel.go
Outdated
// MarkConfirmedScid updates the channel's ShortChannelID after the channel | ||
// has been confirmed but before it is fully opened. |
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 it’s more accurate to say that the channel opening tx gets one confirmation, rather than calling it a channel confirmation.
channeldb/channel_test.go
Outdated
@@ -978,6 +978,81 @@ func TestChannelStateTransition(t *testing.T) { | |||
require.Empty(t, fwdPkgs, "no forwarding packages should exist") | |||
} | |||
|
|||
// TestPendingChannelConfirmation verifies that the confirmed state is updated |
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 that TestOpeningChannelTxConfirmation
might be more accurate for the name of the test as we are not testing the Channel confirmation, but its funding tx confirmation.
funding/manager.go
Outdated
errorChan := make(chan error, 1) | ||
|
||
// If the channel is not a zero-conf channel, we add the SCID to the | ||
// database once the channel is confirmed but not fully opened. This |
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 it’s more accurate to say that the channel opening tx gets one confirmation, rather than say that channel is confirmed.
funding/manager.go
Outdated
// The fundingManager is shutting down, and will resume wait on | ||
// startup. | ||
return nil, ErrFundingManagerShuttingDown | ||
// If the channel confirmation is handled successfully, |
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 it’s more accurate to say that the channel opening tx gets one confirmation, rather than calling it a channel confirmation.
funding/manager.go
Outdated
@@ -3075,6 +3100,87 @@ func makeFundingScript(channel *channeldb.OpenChannel) ([]byte, error) { | |||
return input.WitnessScriptHash(multiSigScript) | |||
} | |||
|
|||
// handleChannelConfirmation manages the confirmation process of a channel's |
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.
Maybe change the name of the function to handleOpenChanTxConfirmation
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.
lnrpc/lightning.proto
Outdated
// The number of blocks remaining before the pending channel open | ||
// transaction is fully confirmed. A value of 0 indicates that the | ||
// transaction has reached the required number of confirmations. | ||
int32 confirmation_until_confirmed = 7; |
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 variable should be named confirmations_until_active
instead, since what we are tracking is channel status change from 'pending' to 'active'
lnrpc/lightning.proto
Outdated
@@ -2847,6 +2847,11 @@ message PendingChannelsResponse { | |||
// very likely canceled the funding and the channel will never become | |||
// fully operational. | |||
int32 funding_expiry_blocks = 3; | |||
|
|||
// The number of blocks remaining before the pending channel open | |||
// transaction is fully confirmed. A value of 0 indicates that the |
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.
its really the number of blocks remaining before the channel status is 'active', not really "full confirmed". Important to distinguish between transaction confirmations and channel status.
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.
channeldb/channel_test.go
Outdated
FundingBroadcastHeight, "broadcast height mismatch") | ||
|
||
confirmedScid := lnwire.ShortChannelID{ | ||
BlockHeight: 5, |
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: since the opening tx was broadcast at broadcastHeight, we could confirm it at broadcastHeight + 1.
It’s not mandatory and doesn’t change the test behavior, but I think it makes the test a bit more elegant. 😉
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.
Done👍
funding/manager_test.go
Outdated
sixConfChannel: make(chan *chainntnfs.TxConfirmation, 1), | ||
sixConfChannel: make(chan *chainntnfs.TxConfirmation, 6), |
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.
Can you explain the reasoning behind this change?
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.
Based on their names, I initially thought it was a typo; however, I'm not sure if it serves a specific purpose. If the naming is indeed intentional, could you explain why both oneConfChannel
and sixConfChannel
are the same(just for my understanding)?
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.
The make(..., 6) call here is only sizing the buffer, but the test doesn't actually need a buffer of size 6. The name sixConfChannel refers to the event (i.e., sixth confirmation received), not the buffer size.
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, understood. I have reverted this change. PTAL
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
@NishantBansal2003, remember to re-request review from reviewers when ready |
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.
FeePerKw: int64(localCommitment. | ||
FeePerKw), | ||
FundingExpiryBlocks: fundingExpiryBlocks, | ||
ConfirmationsUntilActive: remainingConfs, |
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 also add the confirmation height here.
require.Equal(ht, numConfs, ht.AssertNumPendingOpenChannels(alice, | ||
1)[0].ConfirmationsUntilActive) |
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: Not necessary this line, I mean we are mining an empty block.
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
funding/manager.go
Outdated
// channel fires before Updates. When multiple cases in | ||
// a select are ready, Go makes a uniform pseudo-random | ||
// choice between them. | ||
if completeChan.ConfirmationHeight == 0 { |
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.
hmm I am not really a fan of catching raise condition like this, probably we need to change the design a bit to avoid this case.
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.
What do you think about this instead:
// Monitor the confirmation event for the funding transaction. And
// return when the funding tx has received the required number of
// confirmations.
for {
select {
case updDetails := <-confNtfn.Updates:
log.Tracef("funding tx %s received a confirmation, %d "+
" number of confirmations still required", txid,
updDetails.NumConfsLeft)
// Handle first confirmation of the funding transaction.
if updDetails.NumConfsLeft ==
uint32(completeChan.NumConfsRequired-1) {
log.Infof("funding tx %s received first "+
"confirmation", txid)
err := completeChan.MarkConfirmationHeight(
updDetails.BlockHeight,
)
if err != nil {
log.Errorf("failed to mark "+
"confirmation height: %v", err)
return
}
}
// If we haven't reached final confirmation, continue
// waiting for confirmations.
if updDetails.NumConfsLeft > 0 {
continue
}
log.Infof("funding tx %s received all confirmations",
txid)
// We've reached final confirmation. Wait for the the
// confirmation event to trigger and then send the
// result to the confirmation channel.
err := f.handleFinalConfirmation(
confNtfn, confChan, completeChan,
)
if err != nil {
log.Errorf("failed to handle final "+
"confirmation: %v", err)
}
return
case <-confNtfn.NegativeConf:
log.Warnf("funding tx %s was reorged out; channel "+
"point: %s", txid, completeChan.FundingOutpoint)
// Reset the confirmation height to 0 because the
// funding transaction was reorged out.
err := completeChan.MarkConfirmationHeight(uint32(0))
if err != nil {
log.Errorf("failed to update state for "+
"ChannelPoint(%v): %v",
completeChan.FundingOutpoint, err)
return
}
case <-cancelChan:
log.Warnf("canceled waiting for funding confirmation, "+
"stopping funding flow for ChannelPoint(%v)",
completeChan.FundingOutpoint)
return
case <-f.quit:
log.Warnf("fundingManager shutting down, stopping "+
"funding flow for ChannelPoint(%v)",
completeChan.FundingOutpoint)
return
}
}
}
// handleFinalConfirmation is a helper function that listens for the final
// confirmation event and sends the final confirmation to the confirmation
// channel which was provided by the caller.
func (f *Manager) handleFinalConfirmation(
confNtfn *chainntnfs.ConfirmationEvent,
confChan chan<- *confirmedChannel,
completeChan *channeldb.OpenChannel) error {
select {
case confDetails, ok := <-confNtfn.Confirmed:
if !ok {
return fmt.Errorf("confirmation channel closed " +
"unexpectedly")
}
// Send the result to the confirmation channel.
shortChanID := lnwire.ShortChannelID{
BlockHeight: confDetails.BlockHeight,
TxIndex: confDetails.TxIndex,
TxPosition: uint16(completeChan.FundingOutpoint.Index),
}
if !fn.SendOrQuit(confChan, &confirmedChannel{
shortChanID: shortChanID,
fundingTx: confDetails.Tx,
}, f.quit) {
return fmt.Errorf("failed to send confirmation")
}
return nil
case <-f.quit:
return fmt.Errorf("fundingManager shutting down")
}
}
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 way we avoid this race condition of 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.
I was thinking we don’t need this case (though I tried running the code with it and ran into issues because the confirmation notification was sent before anyone was listening, causing a block). We only really need this case when numConfs
is 1, which leads to two scenarios:
- The transaction isn’t confirmed yet, so we’ll have
ConfirmationsUntilActive = 1
andConfirmationHeight = 0
. - The transaction is already confirmed, meaning the channel is no longer pending (it’s active).
In either case, we don’t need to persist the confirmation height in the database. wdyt?
So I’m going to remove the code that marks ConfirmationHeight
in the database in the Confirmed
case of that select
.
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.
hmm but we still want our channel struct to have the correct blockheight for this case, so I don't recommend neglecting this case. Normally it should not block because the confirmed is a buffered channel, can you be more specific which test made problems ?
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.
Normally it should not block because the confirmed is a buffered channel, can you be more specific which test made problems
The TestFundingManagerNormalWorkflow
unit test in manager_test.go
is failing on this code.
I think it’s because we never send any update notifications—we only send the chainntnfs.TxConfirmation
notification (So I don’t think there’s an issue with the code; we just need to update the test, and I’ll do that now).
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 ...
rpcserver.go
Outdated
// getRemainingConfs calculates how many blocks remain until the funding | ||
// transaction reaches the required confirmation height. If the funding | ||
// transaction has received at least one confirmation(i.e. its block height is | ||
// known), then confirmationHeight is calculated as: funding transaction block | ||
// height + required number of confirmations - 1 (subtracting 1 because one | ||
// confirmation is already achieved). | ||
// remainingConfs is computed as the difference between confirmationHeight and | ||
// currentHeight, but is never less than zero. | ||
// | ||
// If the funding transaction hasn't been confirmed, remainingConfs is set to | ||
// the total number of confirmations required. | ||
func getRemainingConfs(pendingChan *channeldb.OpenChannel, | ||
currentHeight uint32) uint32 { | ||
|
||
var remainingConfs uint32 | ||
openTxBlockHeight := pendingChan.ConfirmationHeight | ||
|
||
if openTxBlockHeight > 0 { | ||
confirmationHeight := openTxBlockHeight + | ||
uint32(pendingChan.NumConfsRequired) - 1 | ||
remainingConfs = max(0, confirmationHeight-currentHeight) | ||
} else { | ||
// If the funding transaction is not confirmed yet,then | ||
// remainingConfs will always be NumConfsRequired. | ||
remainingConfs = uint32(pendingChan.NumConfsRequired) | ||
} | ||
|
||
return remainingConfs | ||
} | ||
|
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 find this code part lacks a bit readability what about this ?
// calcRemainingConfs calculates how many more confirmations are needed for a
// pending channel to be fully confirmed. It takes into account:
// 1. The current blockchain height
// 2. The block height at which the funding transaction was first confirmed
// 3. The total number of confirmations required for the channel.
func calcRemainingConfs(pendingChan *channeldb.OpenChannel,
currentHeight uint32) uint32 {
// If the funding transaction hasn't been confirmed yet,
// we need all the required confirmations
if pendingChan.ConfirmationHeight == 0 {
return uint32(pendingChan.NumConfsRequired)
}
// Calculate the target height at which the channel will be fully
// confirmed. The -1 is because the confirmation height of the first
// confirmation has to be taken into account.
targetConfirmationHeight := pendingChan.ConfirmationHeight +
uint32(pendingChan.NumConfsRequired) - 1
// In case the current height is already past the target, return 0. This
// should never happen because the channel should already be moved from
// pending to open state but we handle this case in case of timing
// issues.
if currentHeight >= targetConfirmationHeight {
return 0
}
return targetConfirmationHeight - currentHeight
}
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.
Apologies for writing unreadable code. I’ll try to follow good practices and learn from the codebase. I’m sorry for wasting your time, especially after you shared so many code patches.
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.
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]>
675a709
to
882e0ce
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 think we are close 🤝, tho the unit-test failures seem to be related to this change?
currentHeight uint32) uint32 { | ||
|
||
// If the funding transaction hasn't been confirmed yet, | ||
// we need all the required confirmations |
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: missing point at the end.
) | ||
|
||
// Since we want Bob's channels to require more than 1 on-chain | ||
// confirmation before active, we will launch Bob with the custom |
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: before becoming active ...
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.