-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
lnd: use change output index from authoring TX to check reserved value #5665
lnd: use change output index from authoring TX to check reserved value #5665
Conversation
rpcserver.go
Outdated
// If the reserved value was invalidated we make sure to explicitly | ||
// check if a change output was undetected but that would leave | ||
// sufficient funds for the reserved value. | ||
case lnwallet.ErrReservedValueInvalidated: |
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 about moving this into CheckReservedValueTx
(passing the full authored tx, etc?). This way we can more easily write additional unit tests for this, and also ensure that all other callers also get this fix.
Thinking about it more, we can likely put this behind an additional function (or modify the existing one) that is used to check if a transaction contains a change address or not.
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 function CheckReservedValueTx
now also takes an optional parameter ChangeIndex
to explicitly define a change output (in addition to the check for internal wallet addresses that are being watched).
This check is currently also used when sweeping coins from the wallet. However, in that case a change address is created by calling NewAddress
, which will immediately add it as being watched regardless if the sweeping being successful or not. This could now potentially be re-factored to instead add a change without adding it to the wallet, see if it succeeds by explicitly setting the change index, and then retrospectively adding it the wallet. This would be similar to how sending coins works right now.
13e2250
to
df7731e
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.
LGTM 🍉
Only some small code style nits
Also needs a release notes update |
df7731e
to
a8bb3ed
Compare
Thanks @Roasbeef, I have addressed your last issues! |
Needs a rebase then this should be g2g, thanks for working on this! |
a8bb3ed
to
1d84c1d
Compare
Rebased |
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.
Nice fix, LGTM 💯
Description
Currently a whole UTXO is reserved when anchor-channels is used. This means that if the node has a single UTXO, it cannot be spend even if a change output would leave sufficient funds for the reserve in the wallet.
This PR makes use of the returned
txauthor.AuthoredTx
struct that contains a field for an eventual change index. The reason that this is not automatically detected by theCheckReservedValueTx
function is because the authored transaction is created in dry-run, meaning it does not add the used change output to the wallet to watch for.This PR hence assumes that the change index from the authored transaction returned by
WalletController.CreateSimpleTx
will indeed be a change output controlled by the wallet.Fixes #5648