Auto merge of #3106 - braddmiller:3046-mergetoaddress-concurrent, r=str4d

Add Note Locking to z_mergetoaddress

Adds note locking to `z_mergetoaddress` allowing it to be invoked multiple times before previous `z_mergetoaddress` operations have finished.

Reference issue [#3046](https://github.com/zcash/zcash/issues/3046)

Co-authored-by: Eirik Ogilvie-Wigley <eirik@z.cash>
This commit is contained in:
Homu
2018-03-30 14:29:17 -07:00
6 changed files with 132 additions and 7 deletions

View File

@@ -3443,6 +3443,42 @@ void CWallet::ListLockedCoins(std::vector<COutPoint>& vOutpts)
}
}
// Note Locking Operations
void CWallet::LockNote(JSOutPoint& output)
{
AssertLockHeld(cs_wallet); // setLockedNotes
setLockedNotes.insert(output);
}
void CWallet::UnlockNote(JSOutPoint& output)
{
AssertLockHeld(cs_wallet); // setLockedNotes
setLockedNotes.erase(output);
}
void CWallet::UnlockAllNotes()
{
AssertLockHeld(cs_wallet); // setLockedNotes
setLockedNotes.clear();
}
bool CWallet::IsLockedNote(uint256 hash, size_t js, uint8_t n) const
{
AssertLockHeld(cs_wallet); // setLockedNotes
JSOutPoint outpt(hash, js, n);
return (setLockedNotes.count(outpt) > 0);
}
std::vector<JSOutPoint> CWallet::ListLockedNotes()
{
AssertLockHeld(cs_wallet); // setLockedNotes
std::vector<JSOutPoint> vOutpts(setLockedNotes.begin(), setLockedNotes.end());
return vOutpts;
}
/** @} */ // end of Actions
class CAffectedKeysVisitor : public boost::static_visitor<void> {
@@ -3731,6 +3767,11 @@ void CWallet::GetFilteredNotes(
if (ignoreUnspendable && !HaveSpendingKey(pa)) {
continue;
}
// skip locked notes
if (IsLockedNote(jsop.hash, jsop.js, jsop.n)) {
continue;
}
int i = jsop.js; // Index into CTransaction.vjoinsplit
int j = jsop.n; // Index into JSDescription.ciphertexts