Skip to content

chainntnfs: validate conf/spend ntfn registration parameters #3405

Merged
Roasbeef merged 9 commits into
lightningnetwork:masterfrom
wpaulino:chainrpc-sane-defaults
Aug 26, 2019
Merged

chainntnfs: validate conf/spend ntfn registration parameters #3405
Roasbeef merged 9 commits into
lightningnetwork:masterfrom
wpaulino:chainrpc-sane-defaults

Conversation

@wpaulino

Copy link
Copy Markdown
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
Comment thread lnrpc/chainrpc/chainnotifer_server.go Outdated
Comment thread lnrpc/chainrpc/chainnotifer_server.go Outdated
Comment thread lnrpc/chainrpc/chainnotifer_server.go Outdated
Comment thread chainntnfs/txnotifier.go Outdated
@wpaulino wpaulino changed the title chainrpc: default to one confirmation and require height hints chainntnfs: validate conf/spend ntfn registration parameters Aug 16, 2019
Comment thread chainntnfs/txnotifier.go Outdated
@wpaulino

Copy link
Copy Markdown
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.

@wpaulino wpaulino requested a review from joostjager August 19, 2019 20:46

@cfromknecht cfromknecht left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM 🥓

Comment thread lnrpc/walletrpc/walletkit_server.go Outdated
@wpaulino wpaulino requested a review from Roasbeef as a code owner August 22, 2019 00:31
@wpaulino wpaulino requested review from cfromknecht and joostjager and removed request for Roasbeef August 22, 2019 00:31

@joostjager joostjager left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread chainntnfs/txnotifier.go Outdated
Comment thread chainntnfs/bitcoindnotify/bitcoind.go Outdated
Comment thread chainntnfs/bitcoindnotify/bitcoind.go Outdated
Comment thread chainntnfs/btcdnotify/btcd.go Outdated
Comment thread chainntnfs/neutrinonotify/neutrino.go Outdated

Copy link
Copy Markdown
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?

Comment thread chainntnfs/txnotifier.go Outdated
Comment thread lnwallet/btcwallet/signer.go Outdated
Comment thread lnwallet/btcwallet/signer.go Outdated

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

Comment thread sweep/walletsweep.go Outdated
Comment thread lnrpc/walletrpc/walletkit_server.go Outdated
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.
@wpaulino wpaulino requested a review from joostjager August 22, 2019 20:52

@cfromknecht cfromknecht left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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