forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: allow manipulation of CoinJoin salt using RPC #6093
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| New functionality | ||
| ----------- | ||
|
|
||
| - A new RPC command, `coinjoinsalt`, allows for manipulating a CoinJoin salt stored in a wallet. `coinjoinsalt get` will fetch an existing salt, `coinjoinsalt set` will allow setting a custom salt and `coinjoinsalt generate` will set a random hash as the new salt. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1448,6 +1448,15 @@ int CWallet::GetCappedOutpointCoinJoinRounds(const COutPoint& outpoint) const | |
| return realCoinJoinRounds > CCoinJoinClientOptions::GetRounds() ? CCoinJoinClientOptions::GetRounds() : realCoinJoinRounds; | ||
| } | ||
|
|
||
| void CWallet::ClearCoinJoinRoundsCache() | ||
| { | ||
| LOCK(cs_wallet); | ||
| mapOutpointRoundsCache.clear(); | ||
| MarkDirty(); | ||
| // Notify UI | ||
| NotifyTransactionChanged(uint256::ONE, CT_UPDATED); | ||
|
||
| } | ||
|
|
||
| bool CWallet::IsDenominated(const COutPoint& outpoint) const | ||
| { | ||
| LOCK(cs_wallet); | ||
|
|
@@ -2757,21 +2766,34 @@ const CTxOut& CWallet::FindNonChangeParentOutput(const CTransaction& tx, int out | |
| return ptx->vout[n]; | ||
| } | ||
|
|
||
| void CWallet::InitCoinJoinSalt() | ||
| const uint256& CWallet::GetCoinJoinSalt() | ||
| { | ||
| if (nCoinJoinSalt.IsNull()) { | ||
| InitCJSaltFromDb(); | ||
| } | ||
| return nCoinJoinSalt; | ||
| } | ||
|
|
||
| void CWallet::InitCJSaltFromDb() | ||
| { | ||
| // Avoid fetching it multiple times | ||
| assert(nCoinJoinSalt.IsNull()); | ||
|
|
||
| WalletBatch batch(GetDatabase()); | ||
| if (!batch.ReadCoinJoinSalt(nCoinJoinSalt) && batch.ReadCoinJoinSalt(nCoinJoinSalt, true)) { | ||
| // Migrate salt stored with legacy key | ||
| batch.WriteCoinJoinSalt(nCoinJoinSalt); | ||
| } | ||
| } | ||
|
|
||
| while (nCoinJoinSalt.IsNull()) { | ||
| // We never generated/saved it | ||
| nCoinJoinSalt = GetRandHash(); | ||
| batch.WriteCoinJoinSalt(nCoinJoinSalt); | ||
| bool CWallet::SetCoinJoinSalt(const uint256& cj_salt) | ||
| { | ||
| WalletBatch batch(GetDatabase()); | ||
| // Only store new salt in CWallet if database write is successful | ||
| if (batch.WriteCoinJoinSalt(cj_salt)) { | ||
| nCoinJoinSalt = cj_salt; | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| struct CompareByPriority | ||
|
|
@@ -3942,11 +3964,14 @@ DBErrors CWallet::LoadWallet(bool& fFirstRunRet) | |
| } | ||
| } | ||
|
|
||
| InitCoinJoinSalt(); | ||
|
|
||
| if (nLoadWalletRet != DBErrors::LOAD_OK) | ||
| return nLoadWalletRet; | ||
|
|
||
| /* If the CoinJoin salt is not set, try to set a new random hash as the salt */ | ||
| if (GetCoinJoinSalt().IsNull() && !SetCoinJoinSalt(GetRandHash())) { | ||
| return DBErrors::LOAD_FAIL; | ||
| } | ||
|
|
||
| return DBErrors::LOAD_OK; | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nit: maybe give little more details how possible to use it?