Skip to content

Conversation

@jtimon
Copy link
Contributor

@jtimon jtimon commented Oct 29, 2014

It is built on top of #5170, replaces #4506 and continues #4377.

src/pow.h Outdated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: these

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain the nit a little bit more?

@sipa
Copy link
Member

sipa commented Nov 3, 2014

utACK, apart from the above nits.

@jtimon
Copy link
Contributor Author

jtimon commented Nov 3, 2014

Added commit to correct nits (plus fix a missing include).

@jtimon
Copy link
Contributor Author

jtimon commented Nov 14, 2014

ping

@jtimon
Copy link
Contributor Author

jtimon commented Nov 21, 2014

Rebased for clarity after #5170 being merged.
Nit fixes squashed too.

@jtimon
Copy link
Contributor Author

jtimon commented Nov 26, 2014

Needed rebase.

@jaromil
Copy link
Contributor

jaromil commented Dec 15, 2014

This definitely makes the code more readable, it rebases on 0.10 without problems and its the sort of change that helps to isolate and track pow related operations. It adds the following functions to pow.h:

bool CheckChallenge(const CBlockHeader& block, const CBlockIndex& indexLast);
void ResetChallenge(CBlockHeader& block, const CBlockIndex& indexLast);

/** Avoid using these functions when possible */
double GetChallengeDifficulty(const CBlockIndex* blockindex);
std::string GetChallengeStr(const CBlockIndex& block);
std::string GetChallengeStrHex(const CBlockIndex& block);
uint32_t GetNonce(const CBlockHeader& block);
void SetNonce(CBlockHeader& block, uint32_t nNonce);

It may be desirable to add to the comment: brief reason why to avoid those functions and a mention where they are currently called (rpcblockchain.cpp and rpcmining.cpp).

@petertodd
Copy link
Contributor

NACK

"more readable" is not a good justification to be messing around with this code. If anything, I'd argue it makes the code less readable as what it's actually doing has been obscured by more layers of abstraction.

@jaromil
Copy link
Contributor

jaromil commented Dec 15, 2014

Well, it introduces the Challenge term on check/reset block-index operations which seems more readable to me compared to the if checks. It also does so keeping block as first argument for all new functions, consistent with other existing calls like CheckBlockHeader. At last it introduces get/set function wrappers to operations accessing the nonce. I think this is an improvement and should be merged. I'm not sure what do you mean by abstraction: that has a particular meaning in C++ and I see no real abstraction introduced and even on the linguistic level the function names are good explanations for what they do.

@jtimon
Copy link
Contributor Author

jtimon commented Jan 7, 2015

Closing for now, at least until #5599 has been merged (if it gets merged) and I can propose something more complete.
For those interested, this is the patch I intend to maintain permanently (to make sure nNonce and nBits are not used directly out of pow.o): https://github.com/jtimon/bitcoin/tree/noproof

@jtimon jtimon closed this Jan 7, 2015
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
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.

5 participants