Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

practicalswift
Copy link
Contributor

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 :-)

@promag
Copy link
Member

promag commented Apr 5, 2018

Heh you don't waste time do you?

Concept ACK.

Maybe add a comment in LookupBlockIndex about GetBlockIndex and vice-versa?

@practicalswift
Copy link
Contributor Author

@promag Good point. Fixed! Please re-review :-)

Copy link
Member

@promag promag left a 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
Copy link
Member

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.
Copy link
Member

@promag promag Apr 5, 2018

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
@practicalswift
Copy link
Contributor Author

@promag Much better! Thanks. Updated. Please re-review :-)

@promag
Copy link
Member

promag commented Apr 6, 2018

utACK 23f1760.

Nit, commit message could be shorter.

@TheBlueMatt
Copy link
Contributor

Why would we want this? It looks like just needless additional interfaces and code duplication for nothing more than an assert. NACK without justification.

@promag
Copy link
Member

promag commented Apr 17, 2018

@TheBlueMatt yes, nothing more than that. You probably prefer #12782.

@practicalswift
Copy link
Contributor Author

Closing since lack of consensus ACK :-)

@practicalswift
Copy link
Contributor Author

@TheBlueMatt A simple assert(…) was originally suggested: see PR #12782 :-)

@practicalswift practicalswift deleted the GetBlockIndex branch April 10, 2021 19:34
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants