-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Avoid permanent cs_main/cs_wallet lock during RescanFromTime #11281
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
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8d0b610
Avoid pemanent cs_main/cs_wallet lock during wallet rescans
jonasschnelli dbf8556
Add RAII wallet rescan reserver
jonasschnelli bc356b4
Make sure WalletRescanReserver has successfully reserved the rescan
jonasschnelli ccd8ef6
Reduce cs_main lock in ReadBlockFromDisk, only read GetBlockPos under…
jonasschnelli 7f81250
Mention that other RPC calls report keys as "imported" while txns are…
jonasschnelli 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
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
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 |
---|---|---|
|
@@ -3398,10 +3398,19 @@ UniValue rescanblockchain(const JSONRPCRequest& request) | |
); | ||
} | ||
|
||
LOCK2(cs_main, pwallet->cs_wallet); | ||
WalletRescanReserver reserver(pwallet); | ||
if (!reserver.reserve()) { | ||
throw JSONRPCError(RPC_WALLET_ERROR, "Wallet is currently rescanning. Abort existing rescan or wait."); | ||
} | ||
|
||
CBlockIndex *pindexStart = chainActive.Genesis(); | ||
CBlockIndex *pindexStart = nullptr; | ||
CBlockIndex *pindexStop = nullptr; | ||
CBlockIndex *pChainTip = nullptr; | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you meant to put a LOCK(cs_main) at the top of this scope? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh. Indeed! Added. Fixed. |
||
LOCK(cs_main); | ||
pindexStart = chainActive.Genesis(); | ||
pChainTip = chainActive.Tip(); | ||
|
||
if (!request.params[0].isNull()) { | ||
pindexStart = chainActive[request.params[0].get_int()]; | ||
if (!pindexStart) { | ||
|
@@ -3418,10 +3427,12 @@ UniValue rescanblockchain(const JSONRPCRequest& request) | |
throw JSONRPCError(RPC_INVALID_PARAMETER, "stop_height must be greater then start_height"); | ||
} | ||
} | ||
} | ||
|
||
// We can't rescan beyond non-pruned blocks, stop and throw an error | ||
if (fPruneMode) { | ||
CBlockIndex *block = pindexStop ? pindexStop : chainActive.Tip(); | ||
LOCK(cs_main); | ||
CBlockIndex *block = pindexStop ? pindexStop : pChainTip; | ||
while (block && block->nHeight >= pindexStart->nHeight) { | ||
if (!(block->nStatus & BLOCK_HAVE_DATA)) { | ||
throw JSONRPCError(RPC_MISC_ERROR, "Can't rescan beyond pruned data. Use RPC call getblockchaininfo to determine your pruned height."); | ||
|
@@ -3430,18 +3441,17 @@ UniValue rescanblockchain(const JSONRPCRequest& request) | |
} | ||
} | ||
|
||
CBlockIndex *stopBlock = pwallet->ScanForWalletTransactions(pindexStart, pindexStop, true); | ||
CBlockIndex *stopBlock = pwallet->ScanForWalletTransactions(pindexStart, pindexStop, reserver, true); | ||
if (!stopBlock) { | ||
if (pwallet->IsAbortingRescan()) { | ||
throw JSONRPCError(RPC_MISC_ERROR, "Rescan aborted."); | ||
} | ||
// if we got a nullptr returned, ScanForWalletTransactions did rescan up to the requested stopindex | ||
stopBlock = pindexStop ? pindexStop : chainActive.Tip(); | ||
stopBlock = pindexStop ? pindexStop : pChainTip; | ||
} | ||
else { | ||
throw JSONRPCError(RPC_MISC_ERROR, "Rescan failed. Potentially corrupted data files."); | ||
} | ||
|
||
UniValue response(UniValue::VOBJ); | ||
response.pushKV("start_height", pindexStart->nHeight); | ||
response.pushKV("stop_height", stopBlock->nHeight); | ||
|
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
Oops, something went wrong.
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.
This line didn't make it into the new rebase, I believe.
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.
Oh. Yes. Thanks Will fix
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.
Fixed.
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: Why'd you move it up in the function instead of keeping its position?