-
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
Merged
yyforyongyu
merged 7 commits into
lightningnetwork:master
from
NishantBansal2003:conf-count
Sep 11, 2025
+2,928
−2,151
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
aa9c327
chainntnfs: signal reorg notification before required confirmations
NishantBansal2003 7bc6331
chainntnfs: notify BlockHeight in Updates event
NishantBansal2003 222f49c
channeldb: add MarkConfirmationHeight to OpenChannel
NishantBansal2003 ede08a8
funding: persist ConfirmationHeight upon first funding confirmation
NishantBansal2003 5fd42ac
lnrpc+rpcserver: add ConfirmationsUntilActive and ConfirmationHeight
NishantBansal2003 8f62efb
itest: add test for ConfirmationsUntilActive and ConfirmationHeight
NishantBansal2003 64a841b
docs: add release notes
NishantBansal2003 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -947,8 +947,12 @@ func (n *TxNotifier) dispatchConfDetails( | |
|
|
||
| // We'll send a 0 value to the Updates channel, | ||
| // indicating that the transaction/output script has already | ||
| // been confirmed. | ||
| err := n.notifyNumConfsLeft(ntfn, 0) | ||
| // been confirmed, and include the block height at which the | ||
| // transaction was included. | ||
| err := n.notifyNumConfsLeft(ntfn, TxUpdateInfo{ | ||
| NumConfsLeft: 0, | ||
| BlockHeight: details.BlockHeight, | ||
| }) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
@@ -977,7 +981,10 @@ func (n *TxNotifier) dispatchConfDetails( | |
| // confirmations are left for the transaction/output script to | ||
| // be confirmed. | ||
| numConfsLeft := confHeight - n.currentHeight | ||
| err := n.notifyNumConfsLeft(ntfn, numConfsLeft) | ||
| err := n.notifyNumConfsLeft(ntfn, TxUpdateInfo{ | ||
| NumConfsLeft: numConfsLeft, | ||
| BlockHeight: details.BlockHeight, | ||
| }) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
@@ -1731,7 +1738,10 @@ func (n *TxNotifier) NotifyHeight(height uint32) error { | |
| for confRequest := range confRequests { | ||
| confSet := n.confNotifications[confRequest] | ||
| for _, ntfn := range confSet.ntfns { | ||
| txConfHeight := confSet.details.BlockHeight + | ||
| // blockHeight is the height of the block which | ||
| // contains the transaction. | ||
| blockHeight := confSet.details.BlockHeight | ||
| txConfHeight := blockHeight + | ||
| ntfn.NumConfirmations - 1 | ||
| numConfsLeft := txConfHeight - height | ||
|
|
||
|
|
@@ -1744,7 +1754,10 @@ func (n *TxNotifier) NotifyHeight(height uint32) error { | |
| continue | ||
| } | ||
|
|
||
| err := n.notifyNumConfsLeft(ntfn, numConfsLeft) | ||
| err := n.notifyNumConfsLeft(ntfn, TxUpdateInfo{ | ||
| NumConfsLeft: numConfsLeft, | ||
| BlockHeight: blockHeight, | ||
| }) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
@@ -2011,6 +2024,20 @@ func (n *TxNotifier) dispatchConfReorg(ntfn *ConfNtfn, | |
| if !ntfn.dispatched { | ||
| confHeight := heightDisconnected + ntfn.NumConfirmations - 1 | ||
| ntfnSet, exists := n.ntfnsByConfirmHeight[confHeight] | ||
|
|
||
| // We also signal the reorg to the notifier in case the | ||
| // subscriber is also interested in the reorgs before the | ||
| // transaction received its required confirmation. | ||
| // | ||
| // 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): | ||
|
Comment on lines
+2032
to
+2036
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| case <-n.quit: | ||
| return ErrTxNotifierExiting | ||
| } | ||
|
|
||
| if exists { | ||
| delete(ntfnSet, ntfn) | ||
| } | ||
|
|
@@ -2099,25 +2126,28 @@ func (n *TxNotifier) TearDown() { | |
| } | ||
|
|
||
| // notifyNumConfsLeft sends the number of confirmations left to the | ||
| // notification subscriber through the Event.Updates channel. | ||
| // notification subscriber through the Event.Updates channel, along with the | ||
| // block height in which the transaction was included. | ||
| // | ||
| // NOTE: must be used with the TxNotifier's lock held. | ||
| func (n *TxNotifier) notifyNumConfsLeft(ntfn *ConfNtfn, num uint32) error { | ||
| func (n *TxNotifier) notifyNumConfsLeft(ntfn *ConfNtfn, | ||
| info TxUpdateInfo) error { | ||
|
|
||
| // If the number left is no less than the recorded value, we can skip | ||
| // sending it as it means this same value has already been sent before. | ||
| if num >= ntfn.numConfsLeft { | ||
| if info.NumConfsLeft >= ntfn.numConfsLeft { | ||
| Log.Debugf("Skipped dispatched update (numConfsLeft=%v) for "+ | ||
| "request %v conf_id=%v", num, ntfn.ConfRequest, | ||
| ntfn.ConfID) | ||
| "request %v conf_id=%v", info.NumConfsLeft, | ||
| ntfn.ConfRequest, ntfn.ConfID) | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // Update the number of confirmations left to the notification. | ||
| ntfn.numConfsLeft = num | ||
| ntfn.numConfsLeft = info.NumConfsLeft | ||
|
|
||
| select { | ||
| case ntfn.Event.Updates <- num: | ||
| case ntfn.Event.Updates <- info: | ||
| case <-n.quit: | ||
| return ErrTxNotifierExiting | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.