rpc: Remove cs_main lock from blockToJSON and blockheaderToJSON#12151
rpc: Remove cs_main lock from blockToJSON and blockheaderToJSON#12151maflcko merged 3 commits intobitcoin:masterfrom
Conversation
a40e35a to
b1950e4
Compare
1aeee56 to
f88df2e
Compare
TheBlueMatt
left a comment
There was a problem hiding this comment.
Generally wouldn't bother too much reducing cs_main scope when its really a trivial amount of time running with cs_main held, though I agree in the context of #11913 it makes sense to not lock cs_main and then unlock, then re-lock it there.
src/rpc/blockchain.cpp
Outdated
There was a problem hiding this comment.
Why? You can just do a GetAncestor for blockindex->nHeight here, no?
There was a problem hiding this comment.
This way you get next of blockindex.
There was a problem hiding this comment.
Ohoh, sorry, missed its use in blockheaderToJSON.
There was a problem hiding this comment.
This confused me for a minute too. Maybe could rename function to something like ComputeNextBlockAndDepth to mention the next part.
There was a problem hiding this comment.
Can do, WDYT about returning std::pair<int, const CBlockIndex*>?
There was a problem hiding this comment.
I can add a comment there too explaning the height + 1 and ->pprev == blockindex.
There was a problem hiding this comment.
Renamed to ComputeNextBlockAndDepth as per @ryanofsky suggestion.
src/rpc/blockchain.cpp
Outdated
There was a problem hiding this comment.
No need to change these unless you're gonna actually kill the cs_main held for the whole time, I'd think, no (and little reason to, its not like its being held for an extended period)?
There was a problem hiding this comment.
This moves up tip variable declared below.
|
Best reviewed commit by commit |
f88df2e to
8ca0981
Compare
promag
left a comment
There was a problem hiding this comment.
Changed the order in the signature and forgot to change callers.
8ca0981 to
f6d175d
Compare
|
Fixed @TheBlueMatt and @jimpo comments, thanks. |
ryanofsky
left a comment
There was a problem hiding this comment.
utACK f6d175ddc97a0d2b2614b44ddb9efbebf8d6eec5
src/rpc/blockchain.cpp
Outdated
There was a problem hiding this comment.
This confused me for a minute too. Maybe could rename function to something like ComputeNextBlockAndDepth to mention the next part.
1e6f7f7 to
2925d3b
Compare
|
Rebased mainly due to recent change from Also reworded to replace prefix |
|
Needs rebase if still relevant |
2925d3b to
1a6b13c
Compare
|
Rebased. @MarcoFalke like @TheBlueMatt said above:
I'd say at least let's wait for that. |
|
needs rebase |
|
Rebased. |
1a6b13c to
77d51a6
Compare
ryanofsky
left a comment
There was a problem hiding this comment.
utACK 77d51a68108e282856d9894d41e8a600dba78dd8. No changes since last review other than rebase and removing std::move.
77d51a6 to
e20f745
Compare
ryanofsky
left a comment
There was a problem hiding this comment.
utACK e20f745d9b279de9e43994505731658f0f3582fa, just whitespace fix since last review
jimpo
left a comment
There was a problem hiding this comment.
I think you can stop passing tip to GetDifficulty in most places.
e20f745 to
00755e5
Compare
| { | ||
| return 1.0; | ||
| } | ||
| assert(blockindex); |
There was a problem hiding this comment.
In rpc code, assert should be replaced with throw JSONRPCError?
There was a problem hiding this comment.
I don't think this is a usage error, should be a programatic error?
There was a problem hiding this comment.
I guess you could avoid the assert by passing in a const reference?
There was a problem hiding this comment.
Sure but out of scope here and I'm happy to submit that refactor in a separate PR.
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsNo conflicts as of last run. |
|
utACK b9f226b |
…ockheaderToJSON b9f226b rpc: Remove cs_main lock from blockToJSON and blockHeaderToJSON (João Barbosa) 343b98c rpc: Specify chain tip instead of chain in GetDifficulty (João Barbosa) 54dc13b rpc: Fix SoftForkMajorityDesc and SoftForkDesc signatures (João Barbosa) Pull request description: Motivated by bitcoin#11913 (comment), this pull makes `blockToJSON` and `blockheaderToJSON` free of `cs_main` locks. Locking `cs_main` was required to access `chainActive` in order to check if the block was in the chain and to retrieve the next block index. With the this approach, `CBlockIndex::GetAncestor()` is used in a way to check if the block belongs to the specified chain tip and, at the same time, get the next block index. Tree-SHA512: a6720ace0182c19033bbed1a404f729d793574db8ab16e0966ffe412145611e32c30aaab02975d225df6d439d7b9ef2070e732b16137a902b0293c8cddfeb85f
zcash: cherry picked from commit 54dc13b zcash: bitcoin/bitcoin#12151
zcash: cherry picked from commit 343b98c zcash: bitcoin/bitcoin#12151
zcash: cherry picked from commit b9f226b zcash: bitcoin/bitcoin#12151
zcash: cherry picked from commit 54dc13b zcash: bitcoin/bitcoin#12151
zcash: cherry picked from commit 343b98c zcash: bitcoin/bitcoin#12151
zcash: cherry picked from commit b9f226b zcash: bitcoin/bitcoin#12151
…ockheaderToJSON b9f226b rpc: Remove cs_main lock from blockToJSON and blockHeaderToJSON (João Barbosa) 343b98c rpc: Specify chain tip instead of chain in GetDifficulty (João Barbosa) 54dc13b rpc: Fix SoftForkMajorityDesc and SoftForkDesc signatures (João Barbosa) Pull request description: Motivated by bitcoin#11913 (comment), this pull makes `blockToJSON` and `blockheaderToJSON` free of `cs_main` locks. Locking `cs_main` was required to access `chainActive` in order to check if the block was in the chain and to retrieve the next block index. With the this approach, `CBlockIndex::GetAncestor()` is used in a way to check if the block belongs to the specified chain tip and, at the same time, get the next block index. Tree-SHA512: a6720ace0182c19033bbed1a404f729d793574db8ab16e0966ffe412145611e32c30aaab02975d225df6d439d7b9ef2070e732b16137a902b0293c8cddfeb85f
…ockheaderToJSON b9f226b rpc: Remove cs_main lock from blockToJSON and blockHeaderToJSON (João Barbosa) 343b98c rpc: Specify chain tip instead of chain in GetDifficulty (João Barbosa) 54dc13b rpc: Fix SoftForkMajorityDesc and SoftForkDesc signatures (João Barbosa) Pull request description: Motivated by bitcoin#11913 (comment), this pull makes `blockToJSON` and `blockheaderToJSON` free of `cs_main` locks. Locking `cs_main` was required to access `chainActive` in order to check if the block was in the chain and to retrieve the next block index. With the this approach, `CBlockIndex::GetAncestor()` is used in a way to check if the block belongs to the specified chain tip and, at the same time, get the next block index. Tree-SHA512: a6720ace0182c19033bbed1a404f729d793574db8ab16e0966ffe412145611e32c30aaab02975d225df6d439d7b9ef2070e732b16137a902b0293c8cddfeb85f
Motivated by #11913 (comment), this pull makes
blockToJSONandblockheaderToJSONfree ofcs_mainlocks.Locking
cs_mainwas required to accesschainActivein order to check if the block was in the chain and to retrieve the next block index.With the this approach,
CBlockIndex::GetAncestor()is used in a way to check if the block belongs to the specified chain tip and, at the same time, get the next block index.