Reading a block from disk does not require cs_main, so it can be removed or held shorter in functions that read from disk.
This is the first commit stolen from #11913 without rebase or otherwise touching it.
Reading a block from disk does not require cs_main, so it can be removed or held shorter in functions that read from disk.
This is the first commit stolen from #11913 without rebase or otherwise touching it.
What happens if pruning removes the block while we're reading it?
<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--174a7506f384e20aa4161008e828411d-->
Reviewers, this pull request conflicts with the following ones:
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.
So in that case pruning would succeed and in that case LGTM.
If fs::remove throws then the process terminates, otherwise CBlockIndex state turns wrong — which would require restart to fix?
I'll try to reproduce.
178 | @@ -179,6 +179,7 @@ UniValue getrawtransaction(const JSONRPCRequest& request) 179 | if (!GetTransaction(hash, tx, Params().GetConsensus(), hash_block, true, blockindex)) { 180 | std::string errmsg; 181 | if (blockindex) { 182 | + LOCK(cs_main);
Note: it looks like adding this lock here is just a bugfix, and not directly related to the other changes.
It seems there is a race condition if the block is pruned after GetBlockPos is called and before the block file is actually opened:
On unix it should be sufficient to just hold onto cs_main until after the block file is opened but before it is read, but on windows I'm not sure.
<!--cf906140f33d8803c4a75a2196329ecb-->Needs rebase