-
Notifications
You must be signed in to change notification settings - Fork 36.2k
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
Add GetBlockIndex(const uint256& hash) for when the caller assumes that the block index exists for the given block hash #12897
Conversation
d97fe13
to
aa2df10
Compare
Heh you don't waste time do you? Concept ACK. Maybe add a comment in |
aa2df10
to
fa0b317
Compare
@promag Good point. Fixed! Please re-review :-) |
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.
Alternative docblock.
src/validation.h
Outdated
@@ -430,13 +430,26 @@ class CVerifyDB { | |||
/** Replay blocks that aren't fully applied to the database. */ | |||
bool ReplayBlocks(const CChainParams& params, CCoinsView* view); | |||
|
|||
// GetBlockIndex(...) should be used instead if the caller assumes that the |
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.
Maybe improve a bit:
/** Find and retrieve the block index for the given block hash.
* The caller must check if the block index is valid. If the block index
* always exists then use GetBlockIndex instead.
* Call with cs_main held.
*
* @param[in] hash The block hash
* @return The block index pointer if found, nullptr otherwise
* @see GetBlockIndex
*/
src/validation.h
Outdated
inline CBlockIndex* LookupBlockIndex(const uint256& hash) | ||
{ | ||
AssertLockHeld(cs_main); | ||
BlockMap::const_iterator it = mapBlockIndex.find(hash); | ||
return it == mapBlockIndex.end() ? nullptr : it->second; | ||
} | ||
|
||
// The caller knows if the block index exists for the given block hash. |
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.
/** Retrieve the block index for the given block hash.
* The block index must exists otherwise an assertion fails. If the block index
* can not exist then use LookupBlockIndex instead.
* Call with cs_main held.
*
* @param[in] hash The block hash
* @return The block index pointer
* @see LookupBlockIndex
*/
…e block index exists for the given block hash
fa0b317
to
23f1760
Compare
@promag Much better! Thanks. Updated. Please re-review :-) |
utACK 23f1760. Nit, commit message could be shorter. |
Why would we want this? It looks like just needless additional interfaces and code duplication for nothing more than an assert. NACK without justification. |
@TheBlueMatt yes, nothing more than that. You probably prefer #12782. |
Closing since lack of consensus ACK :-) |
@TheBlueMatt A simple |
Add
GetBlockIndex(const uint256& hash)
for when the caller assumes that the block index exists for the given block hash. As suggested by @promag in #12782.Rationale: Explicit is better than implicit. Especially for assumptions :-)