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

wallet: accept account argument for all covenant makers and verify account ownership during coin selection #233

Merged
merged 6 commits into from
Mar 26, 2020

Conversation

pinheadmz
Copy link
Member

@pinheadmz pinheadmz commented Aug 1, 2019

Closes #231

Adds new method hasCoinByAccount(acct, hash, index) to txdb which
returns true if the coin (hash, index) is owned by account (number).
Adds this check to wallet.makeReveal() to prevent BIDs from other
wallet accounts being included as inputs to a new REVEAL TX from a
specific account.

TODO:

  • Put the test double-reveal-test.js in a more appropriate place... (auction-test? wallet-test?)
  • Finish the auction process in the test, make sure the same bug doesn't throw during any other auction or name-ownership function like UPDATE, REGISTER. etc...
  • Ensure RPC and HTTP APIs pass account parameters

@codecov-io
Copy link

codecov-io commented Aug 1, 2019

Codecov Report

Merging #233 into master will increase coverage by 0.61%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #233      +/-   ##
==========================================
+ Coverage   60.35%   60.96%   +0.61%     
==========================================
  Files         129      129              
  Lines       34677    34728      +51     
  Branches     5862     5894      +32     
==========================================
+ Hits        20929    21172     +243     
+ Misses      13748    13556     -192     
Impacted Files Coverage Δ
lib/wallet/txdb.js 83.32% <100.00%> (+4.43%) ⬆️
lib/wallet/wallet.js 69.30% <100.00%> (+7.08%) ⬆️
lib/primitives/mtx.js 68.63% <0.00%> (+0.24%) ⬆️
lib/wallet/walletdb.js 77.98% <0.00%> (+0.32%) ⬆️
lib/covenants/namedelta.js 86.06% <0.00%> (+0.99%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 489d3f7...7fc2345. Read the comment docs.

lib/wallet/txdb.js Outdated Show resolved Hide resolved
lib/wallet/wallet.js Outdated Show resolved Hide resolved
@pinheadmz pinheadmz changed the title wallet: check account ownership of bid TX when making reveal TX wallet: check account ownership of bid Coin when making reveal TX Aug 1, 2019
@pinheadmz
Copy link
Member Author

  • Calling this test wallet-accounts-reveal-test and keeping it in its own file for now

  • Running test past the REVEAL point doesn't seem necessary - at that point only one coin owns a name, so there wouldn't be conflicting account issues.

  • RPC and HTTP API endpoints are now covered.

@pinheadmz pinheadmz marked this pull request as ready for review August 2, 2019 00:04
lib/wallet/wallet.js Outdated Show resolved Hide resolved
@pinheadmz
Copy link
Member Author

Updated to cover sending UPDATE from specified account

@tynes
Copy link
Contributor

tynes commented Aug 7, 2019

@wi-ski Do these changes fix any issues you are seeing?

@wi-ski
Copy link
Contributor

wi-ski commented Aug 9, 2019

@tynes - Yes sir they do.

@wi-ski
Copy link
Contributor

wi-ski commented Aug 9, 2019

Awesome job @pinheadmz 👏

@pinheadmz pinheadmz changed the title wallet: check account ownership of bid Coin when making reveal TX wallet: check account ownership of bid & name when making reveal / update TXs Aug 9, 2019
@wi-ski
Copy link
Contributor

wi-ski commented Feb 6, 2020

@tynes @pinheadmz - Dusting off this set of changes :) Is there any chance these are still ok? Happy to take them over the line.

@wi-ski
Copy link
Contributor

wi-ski commented Mar 17, 2020

@chjj @boymanjor @pinheadmz @tynes - Can we please get eyes on these changes?

@pinheadmz
Copy link
Member Author

rebase to 5c09c70
rebase on master, update resource serialization used in test.

@wi-ski
Copy link
Contributor

wi-ski commented Mar 17, 2020

@pinheadmz - Hey! Ty so much for making these changes <3

Copy link
Contributor

@boymanjor boymanjor left a comment

Choose a reason for hiding this comment

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

@pinheadmz I left some comments.

lib/wallet/wallet.js Show resolved Hide resolved
test/wallet-accounts-auction-test.js Outdated Show resolved Hide resolved
@pinheadmz
Copy link
Member Author

I added account support for reveal and redeem, as well as update. I started having second thoughts about how to approach this for owned names: update, register, transfer, finalize, revoke, since once a name is owned, there is only one account that can send the covenant anyway.

I was thinking maybe those calls should just not accept an account argument and when it comes to filling the mtx, those calls should just force a account = null to avoid the "preferred inputs error".

But now I think we should still do this (and I'll have to add 3-4 more commits to this PR) and here's why: a user may want the account that owns a name to ALSO pay the mining fee. This and related coin-selection / privacy between accounts reasons.

SO for update, etc. we will still accept an account parameter but only TWO options are available: the account that owns the name, or null (fee will be paid by any coin in the wallet, and change always goes to default account). If the wrong account is given, that'll be an error.

@chjj
Copy link
Contributor

chjj commented Mar 19, 2020

In the future we should consider adding an account index for bids.

@pinheadmz
Copy link
Member Author

@chjj yeah some users with lots of activity are reporting long processing time generate REVEALs

@pinheadmz pinheadmz changed the title wallet: check account ownership of bid & name when making reveal / update TXs wallet: accept account argument for all covenant makers and verify account ownership during coin selection Mar 20, 2020
Adds new method hasCoinByAccount(acct, hash, index) to txdb which
returns true if the coin (hash, index) is owned by account (number).
Adds this check to wallet.makeReveal() to prevent BIDs from other
wallet accounts being included as inputs to a new REVEAL TX from a
specific account.
@pinheadmz
Copy link
Member Author

@chjj @boymanjor @wi-ski
Thanks for bearing with me on this reviewers. I think we're ready for a final pass here. ALL covenant types are now accounted for (we'll need to update the docs to indicate that account is an option). Tests were majorly refactored and simplified.

@pinheadmz
Copy link
Member Author

@boymanjor we have a non-deterministic test in Auction RPC, care to re-run CI build? Everything passes locally for me.

@wi-ski
Copy link
Contributor

wi-ski commented Mar 21, 2020

@pinheadmz - Wowza. You're a beast. Thank you for hacking at this.

@chjj's comment inspired me to investigate intro-ing account indices to bid layouts - this: https://github.com/pinheadmz/hsd/pull/2/files

☝️ Is this in the right 'spirit' for adding an account index for bids? Meaning - appending a new int here? If so, can keep pulling that thread.

Im new to LevelDB and the greater-than/less-than mechanics for iterators are not entirely clear to me yet.

@wi-ski
Copy link
Contributor

wi-ski commented Mar 21, 2020

That PR is targeting these changes *

@pinheadmz
Copy link
Member Author

@wi-ski I think the idea behind indexing bids is not just adding an integer to the bids in layout, but adding a new index entirely like tx by account but for bids. A PR would also include implantation throughout txdb and wallet to read, write, and search by that index.

@wi-ski
Copy link
Contributor

wi-ski commented Mar 21, 2020

Ok - My wishful thinking was wishful. 🙃

@pinheadmz
Copy link
Member Author

@wi-ski I encourage you to continue looking into this problem! The goal would be: when the wallet goes to make a reveal, instead of iterating through every bid in the wallet, it just looks for the bids in the specified account… How could this be accomplished? 🤔

@wi-ski
Copy link
Contributor

wi-ski commented Mar 24, 2020

Yes sir, Ill continue poking 🤔

@wi-ski
Copy link
Contributor

wi-ski commented Mar 24, 2020

Ty for the guidance

@boymanjor boymanjor merged commit 46af401 into handshake-org:master Mar 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"Could not resolve preferred inputs." Error when calling "sendreveal"
6 participants