Skip to content

Conversation

@kallewoof
Copy link
Contributor

This is a refactoring that will make #13756 a lot cleaner and straight-forward, since it adds another combination to the pile (watch-only * spendable * reused).

It's also a nice change in general.

@kallewoof kallewoof force-pushed the cachable-accounts branch 2 times, most recently from 46f3146 to e831a26 Compare April 10, 2019 02:49
@kallewoof kallewoof force-pushed the cachable-accounts branch 2 times, most recently from 749787c to 17d2688 Compare April 10, 2019 04:38
Copy link
Contributor

Choose a reason for hiding this comment

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

I know it seems obvious now, but it would probably help future readers a bit to comment the fact that these correspond to the four values of isminetype. (Or you could add ISMINE_ENUM_ELEMENTS or the like and use that instead of the constant 4.)

In fact, actually, after studying the code -- we aren't really using a bitfield of IsMine types here. Only ISMINE_SPENDABLE and ISMINE_WATCHONLY are valid. Neither ISMINE_NO nor ISMINE_ALL are things we would ever want to cache here. Although I see that in #13756 you are maybe making more use of the fact that this is a bitfield, and I haven't read that one, so I assume that informs your choices here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, there is a tiny bit of waste due to ISMINE_NO and _ALL, and yep I am preparing to use this more extensively for the avoid_reuse feature in #13756. I could make a "bridge" that makes use of these more efficiently, but I kind of enjoy the simplicity of the direct mapping.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should add that I adopted the ISMINE_ENUM_ELEMENTS idea.

@kallewoof
Copy link
Contributor Author

@gwillen Thank you for reviewing! I have addressed your comments, I believe.

@DrahtBot
Copy link
Contributor

DrahtBot commented Apr 10, 2019

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #13756 (wallet: "avoid_reuse" wallet flag for improved privacy by kallewoof)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@laanwj
Copy link
Member

laanwj commented Apr 10, 2019

Concept ACK! this groups similar functionality together making it, overall, easier to understand.
I was afraid for a bit with the word "accounts" though (having just finally deprecated that).

@kallewoof
Copy link
Contributor Author

Thanks for review @promag. I believe I addressed all your comments.

@kallewoof
Copy link
Contributor Author

@laanwj Maybe I should have picked a different name! I think "account" works in this case, though... :)

@kallewoof kallewoof force-pushed the cachable-accounts branch 2 times, most recently from 27e9469 to 3b9a9a4 Compare April 10, 2019 10:09
@laanwj
Copy link
Member

laanwj commented Apr 10, 2019

@laanwj Maybe I should have picked a different name! I think "account" works in this case, though... :)

Yes to be clear it was not a suggestion to change it 🙂 Would only have been a potential concern if it would end up in the RPC API.

@gwillen
Copy link
Contributor

gwillen commented Apr 10, 2019

utACK 3b9a9a4

@kallewoof kallewoof force-pushed the cachable-accounts branch 2 times, most recently from 1eb132e to d9c7ec9 Compare April 11, 2019 14:30
@kallewoof
Copy link
Contributor Author

@promag @MarcoFalke Thank you for the review! I believe I addressed all your feedback.

Copy link
Contributor

@promag promag left a comment

Choose a reason for hiding this comment

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

utACK fda0ade00739f30bdfa9d576371a350c1c4ade5f.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Since CachableAccount members are public you could ditch Reset and call m_cached.reset() directly. Otherwise you could make members private and add IsCached(), Get() and Type() accessors.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think leaving it public is ok, but I can be convinced to make it private. For now, I made Reset inline, which basically has the same effect as what you are suggesting without exposing too many innards.

Copy link
Contributor

@meshcollider meshcollider left a comment

Choose a reason for hiding this comment

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

utACK 1603501, I like this cleanup :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Why not simplify to just return GetCachable(m_credit_immature, ISMINE_SPENDABLE, !fUseCache);? (same in GetImmatureWatchOnlyCredit)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point! Fixed.

@promag
Copy link
Contributor

promag commented Apr 15, 2019

utACK 18f23ae0c5599f2246e58e5293f7426471b73e9c, only change is to use GetCachable in GetImmatureCredit and
GetImmatureWatchOnlyCredit`.

@maflcko
Copy link
Member

maflcko commented Apr 17, 2019

Would be nice if the benchmark could make it in first, so that we are not accidentally regressing on performance.

Copy link
Contributor

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

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

utACK d8fdf6b670e179282faff4ff57e37a6047efac9c. Thanks for the changes!

Would be nice if the benchmark could make it in first, so that we are not accidentally regressing on performance.

I'll review the benchmark, but I'd be pretty surprised if this affects performance significantly, since it is a basically a fancy variable rename, and doesn't really change existing logic.

Copy link
Contributor

Choose a reason for hiding this comment

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

Note: Could add doxygen comment suggested previously #15780 (comment)

//! Cached amount subdivided into watchonly and spendable parts.

Copy link
Contributor Author

@kallewoof kallewoof Apr 18, 2019

Choose a reason for hiding this comment

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

Oops, I missed that part. Thanks, done. (I used /**...*/)

Copy link
Contributor

Choose a reason for hiding this comment

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

Note: Could call this GetAmount instead of GetCachable as suggested previously #15780 (comment) because this returns an amount and now handles caching internally instead of taking a cache reference.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The recalculate bool is for the cache, though. Maybe GetCachableAmount is better. Using that.

@kallewoof kallewoof force-pushed the cachable-accounts branch 2 times, most recently from 1de3ff8 to 46a7d7b Compare April 18, 2019 02:40
Copy link
Contributor

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

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

utACK 46a7d7b1983ebf0a98b96a09d83d9f63ab81dbcc. Just method rename and new code comment since last review.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't want to suggest a change for this PR, since it's good that this just rearranges variables and doesn't change any computation.

But in the future, it seems like IMMATURE_CREDIT could be replaced with CREDIT here without affecting anything, and IMMATURE_CREDIT and AVAILABLE_CREDIT could go away. Unless I'm missing something, it seems like a lot of the previous variables like nImmatureCreditCached were just redundant.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice! That would definitely improve things. I agree that's beyond this PR but will gladly dig into it if nobody else does after merge.

@promag
Copy link
Contributor

promag commented Apr 18, 2019

utACK 46a7d7b.

Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

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

utACK 46a7d7b1983ebf0a98b96a09d83d9f63ab81dbcc

Show signature
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

utACK 46a7d7b1983ebf0a98b96a09d83d9f63ab81dbcc
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUjt+Qv/ZmeTg9qRNFbvQvlhEqwC8YTlz79XldXWXALt5wZpPFVL721OfLpB0Dq3
aGVwaxUsIICmWY7McMpixs/Q563+GX5+mnwAnq7R+lLMfz3ESAqExnfsouxVVdII
PZaNXh9jvXbrDGzz4MkyJKgMa7hx54vcg180wy5MQHCB1DTxT5iDrFeSxVKLlGk2
cQOqqeob93Xa7pABisE7FnCZkPo2YsRJAY8D57XUb+9W3uomJFUlVeJn6UjveMNI
CyHMmO2zmICeWTYdlGn7BcGcEpMUM2zZs3fNgp2AnhixgeSCcL19HPq5kL/ASH7l
ln3uguLDEspSUD7u7vLEoqQcfYT0QO4YwJkhvbFwhKUA2qFvnqQg61bVee+C2fro
RrN2uodY6nhGa55ZtV+JmJDu4FqNqK3sBydGnz7LSGhNcsvJcW7f+DN/YoSssyHK
fpNkz6Wyilsm0i1xw6lZ+XJn8hfk87G6Jvo/D+mK3howtKebC0u7npQ0WGp4N+rF
Amjiv43T
=ONE8
-----END PGP SIGNATURE-----

Copy link
Member

Choose a reason for hiding this comment

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

Could add a comment to say that NO and ALL are never (supposed to be) cached?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, done. I also fixed typo in wallet.cpp#1990 (said "Avoid caching ismine or NONE or all cases" before).

Copy link
Contributor

Choose a reason for hiding this comment

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

The two comments contradict each other:

// NO and ALL are never (supposed to be) cached
// Avoid caching ismine for NO or ALL cases (could remove this check and simplify in the future).

If it's harmful to cache these values, we should drop the second comment and explain the harm. If it's not harmful, we should drop the first comment because it's misleading and irrelevant.

In the future, it would be good to get rid of all unused variables and special cases by switching to a 2 part cache or just caching the 4 parts unconditionally.

@promag
Copy link
Contributor

promag commented Apr 23, 2019

utACK c9e6e7e.

@maflcko
Copy link
Member

maflcko commented Apr 23, 2019

re-utACK c9e6e7e (Only change is comments)

Show signature
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

re-utACK c9e6e7ed79886b702614e627a966fc9a4850f8f0 (Only change is comments)
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUgtWwv+OiZ5fOCqUEVQRgsFHUXeXu+mFPLRT9TMP4HkO/fZbMgFg3gZUAMw9FCV
R8973LZ2iSwK/IpWhrU/VA+jCvgQwIT0RP52qopIJKIb6JN+Bguf9Cw4Dx7nL+2u
P393qaa6KIGcV/9REelCmWyIE3EgTnkTA/AJBAaDqvWqghMQAYrM3r19bDb9dHAe
5Xx+UF/FmmG/3xIuoh6EV75g2njVT/LbXRYYXOwjyF5nFbYN89CkZt1pENmbgF0l
Fw7KRb/4LdhTGP72BIEz5lM645uXDXUZHDxKUWnE18hDP0AU2udGKaa+2vMvhxGh
NmD1+J7/XEvvzpmLI/QhQH20HTQuNgxRVrxApxRWhrNaBcf6GBmF8MjhqX+1ekSL
pSHbt35NfsnPGiwVVenqkBeP8DDt5S7tKioHTLyno7w1XuwOr750q2iCPo0ECVj+
3NXrmd/3kCM86CKn6l0p2EiuqpGs88Gb0asHL7P1nWN2BNnMGz1lss3U448uSHFa
ealUr82R
=9v90
-----END PGP SIGNATURE-----

Copy link
Contributor

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

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

utACK c9e6e7e. Just comment changes since last review.

Copy link
Contributor

Choose a reason for hiding this comment

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

The two comments contradict each other:

// NO and ALL are never (supposed to be) cached
// Avoid caching ismine for NO or ALL cases (could remove this check and simplify in the future).

If it's harmful to cache these values, we should drop the second comment and explain the harm. If it's not harmful, we should drop the first comment because it's misleading and irrelevant.

In the future, it would be good to get rid of all unused variables and special cases by switching to a 2 part cache or just caching the 4 parts unconditionally.

@laanwj laanwj merged commit c9e6e7e into bitcoin:master Apr 23, 2019
laanwj added a commit that referenced this pull request Apr 23, 2019
…alues

c9e6e7e wallet: add cachable amounts for caching credit/debit values (Karl-Johan Alm)

Pull request description:

  This is a refactoring that will make #13756 a lot cleaner and straight-forward, since it adds another combination to the pile (watch-only * spendable * reused).

  It's also a nice change in general.

Tree-SHA512: 6c876d58bbffd5cb85ef632dea4fd6afed163904bbde5efdb307fa119af178ed3cb5df047255da7e9a9136fed876922f1116fce61a3710f308c72275f9b7d18b
@kallewoof kallewoof deleted the cachable-accounts branch April 23, 2019 22:38
meshcollider added a commit that referenced this pull request Jun 18, 2019
5ebc6b0 bitcoind: update -avoidpartialspends description to account for auto-enable for avoid_reuse wallets (Karl-Johan Alm)
ada258f doc: release notes for avoid_reuse (Karl-Johan Alm)
2766955 wallet: enable avoid_partial_spends by default if avoid_reuse is set (Karl-Johan Alm)
8f2e208 test: add test for avoidreuse feature (Karl-Johan Alm)
0bdfbd3 wallet/rpc: add 'avoid_reuse' option to RPC commands (Karl-Johan Alm)
f904723 wallet/rpc: add setwalletflag RPC and MUTABLE_WALLET_FLAGS (Karl-Johan Alm)
8247a0d wallet: enable avoid_reuse feature (Karl-Johan Alm)
eec1566 wallet: avoid reuse flags (Karl-Johan Alm)
5892809 wallet: make IsWalletFlagSet() const (Karl-Johan Alm)
129a5ba wallet: rename g_known_wallet_flags constant to KNOWN_WALLET_FLAGS (Karl-Johan Alm)

Pull request description:

  Add a new wallet flag called `avoid_reuse` which, when enabled, will keep track of when a specific destination has been spent from, and will actively "blacklist" any new UTXOs which send to an already-spent-from destination.

  This improves privacy, as a payer could otherwise begin tracking a payee's wallet by regularly peppering a known UTXO with dust outputs, which would then be scooped up and used in payments by the payee, allowing the payer to map out (1) the inputs owned by the payee and (2) the destinations to which the payee is making payments.

  This replaces #10386 and together with the (now merged) #12257 it addresses #10065 in full. The concerns raised in #10386 (comment) are also addressed due to #12257.

  ~~Note: this builds on top of #15780.~~ (merged)

ACKs for commit 5ebc6b:
  jnewbery:
    ACK 5ebc6b0
  laanwj:
    Concept and code-review ACK 5ebc6b0
  meshcollider:
    Code review ACK 5ebc6b0
  achow101:
    ACK 5ebc6b0 modulo above nits

Tree-SHA512: fdef45826af544cbbb45634ac367852cc467ec87081d86d08b53ca849e588617e9a0a255b7e7bb28692d15332de58d6c3d274ac003355220e4213d7d9070742e
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jun 19, 2019
…rivacy

5ebc6b0 bitcoind: update -avoidpartialspends description to account for auto-enable for avoid_reuse wallets (Karl-Johan Alm)
ada258f doc: release notes for avoid_reuse (Karl-Johan Alm)
2766955 wallet: enable avoid_partial_spends by default if avoid_reuse is set (Karl-Johan Alm)
8f2e208 test: add test for avoidreuse feature (Karl-Johan Alm)
0bdfbd3 wallet/rpc: add 'avoid_reuse' option to RPC commands (Karl-Johan Alm)
f904723 wallet/rpc: add setwalletflag RPC and MUTABLE_WALLET_FLAGS (Karl-Johan Alm)
8247a0d wallet: enable avoid_reuse feature (Karl-Johan Alm)
eec1566 wallet: avoid reuse flags (Karl-Johan Alm)
5892809 wallet: make IsWalletFlagSet() const (Karl-Johan Alm)
129a5ba wallet: rename g_known_wallet_flags constant to KNOWN_WALLET_FLAGS (Karl-Johan Alm)

Pull request description:

  Add a new wallet flag called `avoid_reuse` which, when enabled, will keep track of when a specific destination has been spent from, and will actively "blacklist" any new UTXOs which send to an already-spent-from destination.

  This improves privacy, as a payer could otherwise begin tracking a payee's wallet by regularly peppering a known UTXO with dust outputs, which would then be scooped up and used in payments by the payee, allowing the payer to map out (1) the inputs owned by the payee and (2) the destinations to which the payee is making payments.

  This replaces bitcoin#10386 and together with the (now merged) bitcoin#12257 it addresses bitcoin#10065 in full. The concerns raised in bitcoin#10386 (comment) are also addressed due to bitcoin#12257.

  ~~Note: this builds on top of bitcoin#15780.~~ (merged)

ACKs for commit 5ebc6b:
  jnewbery:
    ACK 5ebc6b0
  laanwj:
    Concept and code-review ACK 5ebc6b0
  meshcollider:
    Code review ACK bitcoin@5ebc6b0
  achow101:
    ACK 5ebc6b0 modulo above nits

Tree-SHA512: fdef45826af544cbbb45634ac367852cc467ec87081d86d08b53ca849e588617e9a0a255b7e7bb28692d15332de58d6c3d274ac003355220e4213d7d9070742e
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jun 4, 2020
…t values

Summary:
bitcoin/bitcoin@c9e6e7e

---

Backport of Core [[bitcoin/bitcoin#15780 | PR15780]]

Test Plan:
  ninja check-all

Reviewers: #bitcoin_abc, nakihito

Reviewed By: nakihito

Differential Revision: https://reviews.bitcoinabc.org/D6347
furszy added a commit to PIVX-Project/PIVX that referenced this pull request Aug 21, 2020
…values

e02edd3 Cleaning isminetype::ISMINE_SPENDABLE_STAKEABLE. (furszy)
1bf9dc4 wallet: unify GetUnspentCredit with GetCredit (furszy)
9f2ae47 wallet: remove currently unused UpdateAmount method. (furszy)
bef69d3 wallet: add cachable amounts for caching credit/debit values (furszy)
8f2a156 Make IsMine stop distinguishing solvable/unsolvable (furszy)
e541593 Make coincontrol use IsSolvable to determine solvability (furszy)
e1a0cfb Back port of IsSolvable to check scripts solvability. (furszy)

Pull request description:

  Built on top of #1755 and #1666 .

  The goal of this PR has been to improve the `CWalletTx` to be able to add shielded cached balances in a much cleaner way.

  Including the following changes:

  * Adapted IsSolvable function from 0c8ea63 (without the witness check. Only used to check regular outputs to be able to decouple the output solvability from `ismine.h` enum)

  * Solvability decoupled from `ismine.h`. Back ported 6d714c3 and 4e91820 from bitcoin#13142.

  * And lastly, adapted bitcoin#15780 beauty cleanup to our sources.

ACKs for top commit:
  random-zebra:
    utACK e02edd3

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants