Skip to content

Conversation

@aalness
Copy link
Contributor

@aalness aalness commented Jan 22, 2014

lockunspent will now validate all of the provided outputs are
both unspent and belong to the local wallet.

The operation is now also atomic.

Fix for #2667

@laanwj
Copy link
Member

laanwj commented Jan 23, 2014

@aalness Removed the offtopic replies here, sorry for continuing them. I was lost in a maze of twisty github issues all alike...

Edit: I also took the liberty to clarify your pull request title somewhat.

Copy link

Choose a reason for hiding this comment

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

Can you use 4-space indentation here also below throw please.

@Diapolo
Copy link

Diapolo commented Jan 23, 2014

Does this change require any changes in the GUI coin-control code or do we directly benefit from this change?

@aalness
Copy link
Contributor Author

aalness commented Jan 23, 2014

Good question. At first read, it looks like the coin-control GUI could theoretically by-pass this new check and lock an unlockable coin. This could be confusing to an RPC user. eg. GUI user locks an unlockable coin, RPC user sees it in the output for listlockunspent and when they try to unlock it via lockunspent it fails due to the coin being unlockable.

@laanwj
Copy link
Member

laanwj commented Jan 24, 2014

But does the GUI allow it? I think it's pretty locked down in that regard, showing only coins that can be spent (and thus locked). But I may be wrong.

@cozz
Copy link
Contributor

cozz commented Jan 24, 2014

Havent tested, but I agree with @laanwj. You check 4 conditions (mapwallet output.n !ispent ismine), coin control calls AvailableCoins, checking the same but even more conditions.
So it should never be possible to lock an unlockable coin in the GUI.

I also suggest:

  • The condition when unlocking a coin could simply be, if it is already locked or not. It should always be possible to unlock a coin, if the coin appears in listlockunspent.
  • rename your function IsLockableCoin to IsAvailableCoin.
    This way the function can also be used in the future for other stuff.
  • make this function IsAvailableCoin very similar to wallet->AvailableCoins, so that it is easy to maintain (I mean the conditions if(!FinalTx...) etc.)
  • put the function below AvailableCoins

This would be consistent with the GUI, checking the same conditions.

@aalness
Copy link
Contributor Author

aalness commented Jan 24, 2014

Ah, good feedback @cozz. Will make those changes. Thanks.

lockunspent will now validate all of the provided outputs are
both unspent and belong to the local wallet.

The operation is now also atomic.
@aalness
Copy link
Contributor Author

aalness commented Jan 25, 2014

@cozz I incorporated your feedback but note the semantic implication:

lockunspent lock=true for an already locked coin would now throw an error.
lockunspent unlock=true for an already unlocked coin would now throw an error.

Previously, the behavior was:

lockunspent lock=true for an already locked coin returns true.
lockunspent unlock=true for an already unlocked coin would return true.

I think a case could be made for either behavior but I want to point it out in case this violates a convention I'm unaware of. Or if it's particularly distasteful to anyone.

@cozz
Copy link
Contributor

cozz commented Jan 25, 2014

@aalness yes, maybe in the case "lockunspent lock=true for an already locked coin",
show a different error message like "coin already locked". But throw an error is fine with me.

Code looks good, not sure what the core devs opinion is on this. So lets wait for another opinion here...

Copy link
Member

Choose a reason for hiding this comment

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

So now we have coin.IsAvailable as well as CWallet::IsAvailableCoin? I think that's a bit confusing.

@cozz
Copy link
Contributor

cozz commented Jan 25, 2014

@laanwj yes, so maybe not touch AvailableCoins at all. And just introduce 1 new function IsAvailableCoin, duplicating all the necessary logic. Just like IsLockableCoin before. Thats what I meant initially. Would also be easier to review and to compare. What do you think?

@aalness
Copy link
Contributor Author

aalness commented Jan 25, 2014

@laanwj yeah, that's fair. It bothered me slightly too, although, it seemed to be a bit of an existing convention to call a CWalletTx a "coin" or "pcoin". Do you think it would be less confusing to simply change the variable to "wtx"? Can you think of a better way to describe a transaction in this state, as opposed to "available"? Or would you just prefer that I remove the method altogether?

@cozz I do like the property that IsAvailableCoin and AvailableCoins now share the same exact code. It seems like a stronger guarantee that the GUI and listunspent stay consistent with lockunspent.

@luke-jr
Copy link
Member

luke-jr commented Feb 21, 2014

@aalness Needs rebase

@BitcoinPullTester
Copy link

Automatic sanity-testing: FAILED MERGE, see http://jenkins.bluematt.me/pull-tester/p3574_74ad5868245790c1f6c712c6afaa0d76398d2d7d/ for test log.

This pull does not merge cleanly onto current master
This test script verifies pulls every time they are updated. It, however, dies sometimes and fails to test properly. If you are waiting on a test, please check timestamps to verify that the test.log is moving at http://jenkins.bluematt.me/pull-tester/current/
Contact BlueMatt on freenode if something looks broken.

@laanwj
Copy link
Member

laanwj commented Jun 24, 2014

Closing this pull as it appears to be inactive. If you intend to resume working on this, let me know.

@laanwj laanwj closed this Jun 24, 2014
laanwj added a commit that referenced this pull request Nov 16, 2017
28f8b66 Diagnose unsuitable outputs in lockunspent(). (Eelis)

Pull request description:

  Fixes #2667.

  This is a simplified version of pull request #3574, which was abandoned by its author.

  I added some tests as well.

Tree-SHA512: e63e00dec8b1b232079380183805cb0b0b18c78ea6bea769837949aab984689d7f68b2ccfe66b1873517b040b9e616ce0eb058575c3d4382aa8c26eebcf1f14e
PastaPastaPasta referenced this pull request in PastaPastaPasta/dash Jan 29, 2020
28f8b66 Diagnose unsuitable outputs in lockunspent(). (Eelis)

Pull request description:

  Fixes dashpay#2667.

  This is a simplified version of pull request dashpay#3574, which was abandoned by its author.

  I added some tests as well.

Tree-SHA512: e63e00dec8b1b232079380183805cb0b0b18c78ea6bea769837949aab984689d7f68b2ccfe66b1873517b040b9e616ce0eb058575c3d4382aa8c26eebcf1f14e
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants