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

chainntnfs: validate conf/spend ntfn registration parameters #3405

Merged
merged 9 commits into from
Aug 26, 2019

Conversation

wpaulino
Copy link
Contributor

A height hint not being set would cause lnd to scan for the confirmation/spend of a txid/outpoint/address from genesis.

The number of confirmations not being set within a confirmation request would cause the internal TxNotifier to deadlock when dispatching updates. To prevent this, we default to dispatching a notification upon one confirmation.

Fixes #3398.

@wpaulino wpaulino added rpc Related to the RPC interface v0.8.0 bug fix labels Aug 15, 2019
@wpaulino wpaulino added this to the 0.8.0 milestone Aug 15, 2019
@wpaulino wpaulino requested a review from halseth as a code owner August 15, 2019 23:25
@wpaulino wpaulino requested review from cfromknecht and joostjager and removed request for halseth August 15, 2019 23:26
lnrpc/chainrpc/chainnotifer_server.go Outdated Show resolved Hide resolved
lnrpc/chainrpc/chainnotifer_server.go Outdated Show resolved Hide resolved
lnrpc/chainrpc/chainnotifer_server.go Outdated Show resolved Hide resolved
chainntnfs/txnotifier.go Show resolved Hide resolved
@wpaulino wpaulino changed the title chainrpc: default to one confirmation and require height hints chainntnfs: validate conf/spend ntfn registration parameters Aug 16, 2019
@wpaulino
Copy link
Contributor Author

As a result of having the validation checks being done at the chain notifier level, a bug was discovered with the BumpFee RPC that would cause us to scan the chain from genesis due to a 0 height hint. See the relevant commit for more details.

Copy link
Contributor

@cfromknecht cfromknecht 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
Contributor

@joostjager joostjager left a comment

Choose a reason for hiding this comment

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

This pr did get quite out of hand. I didn't expect the move of subscription logic to txNotifier to involve so many changed lines of code. To me the end result looks definitely like an improvement. I hope you found it worthwhile to do. I left some non-blocking comments.

chainntnfs/txnotifier.go Outdated Show resolved Hide resolved
chainntnfs/bitcoindnotify/bitcoind.go Show resolved Hide resolved
chainntnfs/bitcoindnotify/bitcoind.go Show resolved Hide resolved
chainntnfs/btcdnotify/btcd.go Show resolved Hide resolved
@@ -690,9 +677,12 @@ func (n *NeutrinoNotifier) RegisterSpendNtfn(outpoint *wire.OutPoint,
//
// We'll update our filter first to ensure we can immediately detect the
// spend at tip.
if outpoint == nil {
outpoint = &chainntnfs.ZeroOutPoint
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Do this as first thing in this function, so that txNotifier.RegisterSpend can accept it as a value parameter?

chainntnfs/txnotifier.go Outdated Show resolved Hide resolved
lnwallet/btcwallet/signer.go Show resolved Hide resolved
err)
}
confs := int64(0)
if txDetail.Block.Height != -1 {
Copy link
Contributor

Choose a reason for hiding this comment

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

-1 means unconfirmed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah that's what's returned by the underlying call for unconfirmed transactions.

Copy link
Contributor

Choose a reason for hiding this comment

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

const unconfirmed = -1 would be nice

sweep/walletsweep.go Show resolved Hide resolved
lnrpc/walletrpc/walletkit_server.go Outdated Show resolved Hide resolved
A height hint not being set would cause lnd to scan for the
confirmation/spend of a txid/outpoint/address from genesis.

The number of confirmations not being set within a confirmation request
would cause the internal TxNotifier to deadlock when dispatching
updates.
This prevents a deadlock while tearing down the TxNotifier if it's
currently blocked delivering a notification. By closing the quit chan
first, we ensure blocked sends/reads can exit and allow the TxNotifier
to proceed tearing down.
These fields are only relevant for spent transaction outputs.
The cache wasn't really serving a purpose as FetchInputInfo isn't known
to be a hot path. Also, with a planned addition of returning the
confirmation status of an output within FetchInputInfo in a later
commit, caching won't be useful as we'll have to go to disk anyway to
determine the confirmation status.
We already have all of the information required for the outputs from the
ListUnspent method.
In this commit, we address an issue that would cause us to scan from the
genesis block for the spend of an output that we wish to use to raise
the fee of a transaction through CPFP. This was due to setting a 0
height hint when constructing the input required by the sweeper and was
discovered due to the recently added validation checks at the chain
notifier level. We'll now use the current height as the height hint
instead as the sweeper will end up creating a new transaction that
spends the input.
Copy link
Contributor

@cfromknecht cfromknecht left a comment

Choose a reason for hiding this comment

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

LGTM 👌 nice to see chainntnfs getting some more love!

@Roasbeef Roasbeef merged commit 3868bdc into lightningnetwork:master Aug 26, 2019
@wpaulino wpaulino deleted the chainrpc-sane-defaults branch August 26, 2019 23:27
@alexbosworth
Copy link
Contributor

I see an issue here where I get this error when trying to restore an SCB

2 UNKNOWN: unable to unpack chan backup: a height hint greater than 0 must be provided

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug fix rpc Related to the RPC interface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LND 100% CPU Won't gracefully shutdown
5 participants