-
Notifications
You must be signed in to change notification settings - Fork 38.7k
WIP: Allow wallet key import RPCs to track TxOut amounts on -prune nodes (on top of #9306) #9137
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
Conversation
src/primitives/transaction.cpp
Outdated
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.
Hmm... this would result in not longer coupling the hash with the data-structure. This can result in difficult states for future changes.
Would a new primitive (maybe CIncompleteTransaction or similar) make more sense?
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.
I don't know if @sipa's suggestion of making a new CTransaction constructor that accepts a hash would sufficiently address your concern. (It would not eliminate the risk that some code could make a seemingly harmless UpdateHash() call on the wallet transaction and overwrite the correct hash).
Personally, the way I would go about this would be to change CWalletTx not to inherit from CMerkleTx, and instead just contain either a variant<CMerkleTx, CCoins> or an optional<CMerkleTx> member. I can try this in a separate PR (since would create a lot of unrelated code churn in the wallet) if you are amenable to the idea.
src/wallet/wallet.cpp
Outdated
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.
Would there be a better way to keep the wallet separated from the UTXO set?
During wallet creation (init.cpp) it could pass-in a lambda that would take care about finding the corresponding CCoins.
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.
Sounds good, will change.
|
Conceptual questions:
Things that would need to be done: |
|
Thinking more about the above, this is not useful advice. I said it in response to seeing the suggestion of a CIncompleteTransaction, assuming we were calling SetHash after it became complete. What we want here is a hash that does travel with the transaction, and is complete. I don't think it needs to break CTransaction's immutability, though. What about a constructor to CTransaction that takes a CMutableTransaction and a hash? |
src/wallet/rpcdump.cpp
Outdated
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.
Shouldn't there be some way to scan for UTXOs on non-pruned nodes?
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.
I could definitely add it as another option to the RPC. I guess the benefit to the RPC caller would be that if they're importing a key which they already know is unspent, calling ScanForWalletUTXOs would be faster than calling ScanForWalletTransactions?
src/wallet/wallet.cpp
Outdated
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.
These errors leave much to be desired...
|
Thanks @jonasschnelli, I am planning to get to the various todos you mentioned. The one I might like to know more about is "Visual attribution in the GUI." Do you have any thoughts on what this should look like? And what would be the reasons for making the distinction? E.g. are there particular wallet features or RPC calls that won't work with incomplete transaction data? (Asking because I actually haven't used the wallet UI very much myself yet.) |
|
@ryanofsky: I think the GUI stuff can be done in a separate PR after this has been merged. |
|
Thanks @jonasschnelli, that makes sense. I still would appreciate knowing any thoughts you may have on the GUI implementation either here or in the original issue #8497. |
|
I'm working on a series of changes to the serialization code, the result of which will be that CTransaction is fully immutable, so UpdateHash will go away. |
src/wallet/wallet.cpp
Outdated
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.
Won't this miss unconfirmed TXOs?
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.
This doesn't deal with unconfirmed TXOs, but neither does ScanForWalletTransactions, which this is just intended to be a lightweight fallback for.
I don't know the wallet code well enough to know how it does deal with unconfirmed TXOs, but I expect that if there are issues tracking them, they would be orthogonal to this change.
37a31b2 to
a5b980f
Compare
daa3954 to
4c84290
Compare
|
This is better tested now and ready to be reviewed and merged. There are a few extra things that could be done based on comments above, but they don't necessarily have to be part of this PR:
|
4c84290 to
454c314
Compare
|
Added test code to |
454c314 to
4139b8f
Compare
|
Updated to fix conflicts after #8580 merge. |
Change CCoinsViewCache::Cursor() method to return a cursor yielding the latest CCoins entries, instead of just previous entries prior to the last cache flush. The CCoinsViewCache::Cursor method is not currently used. This change just enables new features that rely on scanning the UXTO set to work correctly (for example bitcoin#9152, which adds a sweepprivkeys RPC, and bitcoin#9137, which improves handling of imported keys for nodes with pruning enabled.)
Allow importprivkey, importaddress, importpubkey, and importmulti RPCs to be called with rescan=True option on nodes with pruned blockchains (started with -prune option). Instead of returning errors, the RPCs will now look for transactions spending to the key in the UTXO database, and display them in the wallet. Because the UTXO database doesn't store full transaction information (it discards TxIns) this change introduces a new "fIncomplete" CWalletTx member to distinguish these from normal wallet transactions. This change makes the -prune mode usable with wallets that need to import keys after the initial sync. Fixes bitcoin#8497.
Change CCoinsViewCache::Cursor() method to return a cursor yielding the latest CCoins entries, instead of just previous entries prior to the last cache flush. The CCoinsViewCache::Cursor method is not currently used. This change just enables new features that rely on scanning the UXTO set to work correctly (for example bitcoin#9152, which adds a sweepprivkeys RPC, and bitcoin#9137, which improves handling of imported keys for nodes with pruning enabled.)
4139b8f to
b26a64c
Compare
efc18dd to
9a3a749
Compare
|
rescan=true and importing pruned things are not the same though. Rescan makes sure you get the historical transactions and a utxo scan doesn't. I think we may want to track a global state for a wallet that indicates if it believes its history is complete or not, and report that. (e.g. in the GUI there could be a bar at the top of the transaction list "some historical transactions may be missing") |
9a3a749 to
63d11c8
Compare
|
Having a gui indication of an incomplete historical transaction list seems like a good idea with this change, but it would probably also be a good idea without this change. (The transaction list will be incomplete now if you import with a key without rescanning, or if you use the removeprunedfunds API.) The goal of this change is to make possible to see and spend balances after importing keys on |
|
I do think it would be a good idea not overload to the meaning of |
408e3e7 to
a63ec0e
Compare
Make CCoinsViewCache::Cursor() return latest data Change CCoinsViewCache::Cursor() method to return a cursor yielding the latest CCoins entries, instead of just previous entries prior to the last cache flush. The CCoinsViewCache::Cursor method is not currently used. This change just enables new features that rely on scanning the UXTO set to work correctly (for example bitcoin#9152, which adds a sweepprivkeys RPC, and bitcoin#9137, which improves handling of imported keys for nodes with pruning enabled.)
Make CCoinsViewCache::Cursor() return latest data Change CCoinsViewCache::Cursor() method to return a cursor yielding the latest CCoins entries, instead of just previous entries prior to the last cache flush. The CCoinsViewCache::Cursor method is not currently used. This change just enables new features that rely on scanning the UXTO set to work correctly (for example bitcoin#9152, which adds a sweepprivkeys RPC, and bitcoin#9137, which improves handling of imported keys for nodes with pruning enabled.)
Make CCoinsViewCache::Cursor() return latest data Change CCoinsViewCache::Cursor() method to return a cursor yielding the latest CCoins entries, instead of just previous entries prior to the last cache flush. The CCoinsViewCache::Cursor method is not currently used. This change just enables new features that rely on scanning the UXTO set to work correctly (for example bitcoin#9152, which adds a sweepprivkeys RPC, and bitcoin#9137, which improves handling of imported keys for nodes with pruning enabled.)
Change CCoinsViewCache::Cursor() method to return a cursor yielding the latest CCoins entries, instead of just previous entries prior to the last cache flush. The CCoinsViewCache::Cursor method is not currently used. This change just enables new features that rely on scanning the UXTO set to work correctly (for example bitcoin#9152, which adds a sweepprivkeys RPC, and bitcoin#9137, which improves handling of imported keys for nodes with pruning enabled.)
Change CCoinsViewCache::Cursor() method to return a cursor yielding the latest CCoins entries, instead of just previous entries prior to the last cache flush. The CCoinsViewCache::Cursor method is not currently used. This change just enables new features that rely on scanning the UXTO set to work correctly (for example bitcoin#9152, which adds a sweepprivkeys RPC, and bitcoin#9137, which improves handling of imported keys for nodes with pruning enabled.)
|
Haven't worked on this in a while. Will close and reopen if I make more more progress. |
|
This is a feature I'd love to see added. I've been following the progress in this and related issues and PRs. Regarding the most recent comments, I think it would make sense to leave rescan=true as is, and have rescan=utxo only check an address or key against the utxo set and not do a full rescan for historical transactions. I'm new to contributing to this project but let me know if I can help with testing or anything for this PR. Or, @ryanofsky, if you don't feel like you'll be revisiting this issue in the foreseeable future maybe I can try to pick up where you left off. Thanks. |
|
@sangaman, it'd be great if you want to pick this up. As mentioned in my last update I haven't worked on this on a while and don't have plans to continue at the moment. |
Allow importprivkey, importaddress, importpubkey, and importmulti RPCs to be
called with rescan=True option on nodes with pruned blockchains (started with
-prune option). Instead of returning errors, the RPCs will now look for
transactions spending to the key in the UTXO database, and display them in the
wallet.
Because the UTXO database doesn't store full transaction information (it
discards TxIns) this change introduces a new "fIncomplete" CWalletTx member to
distinguish these from normal wallet transactions.
This change makes the -prune mode usable with wallets that need to import keys
after the initial sync.
Fixes #8497.