Continue proof of work encapsulation #5171
pull jtimon wants to merge 6 commits into bitcoin:master from jtimon:pow4 changing 7 files +72 −32-
jtimon commented at 8:21 pm on October 29, 2014: contributor
-
in src/pow.h: in a91c09e045 outdated
23-uint256 GetProofIncrement(unsigned int nBits); 24+uint256 GetBlockProof(const CBlockIndex& block); 25+bool CheckChallenge(const CBlockHeader& block, const CBlockIndex& indexLast); 26+void ResetChallenge(CBlockHeader& block, const CBlockIndex& indexLast); 27+ 28+/** Avoid using this functions when possible */
sipa commented at 6:41 pm on November 3, 2014:Nit: these
jtimon commented at 7:05 pm on November 3, 2014:Can you explain the nit a little bit more?in src/pow.h: in a91c09e045 outdated
24+uint256 GetBlockProof(const CBlockIndex& block); 25+bool CheckChallenge(const CBlockHeader& block, const CBlockIndex& indexLast); 26+void ResetChallenge(CBlockHeader& block, const CBlockIndex& indexLast); 27+ 28+/** Avoid using this functions when possible */ 29+double GetChallengeDouble(const CBlockIndex* blockindex);
sipa commented at 6:42 pm on November 3, 2014:Nit: call it GetChallengeDifficulty? It’s a well-defined number.
jtimon commented at 7:05 pm on November 3, 2014:Ok, GetChallengeDifficulty it is.
jtimon commented at 7:07 pm on November 3, 2014:ops, sorry, s/this/these, got itsipa commented at 6:56 pm on November 3, 2014: memberutACK, apart from the above nits.jtimon commented at 7:14 pm on November 3, 2014: contributorAdded commit to correct nits (plus fix a missing include).jtimon commented at 2:47 pm on November 14, 2014: contributorpingjtimon force-pushed on Nov 21, 2014Hide GetNextWorkRequired() c3ee304478Implement GetChallengeDouble(CBlockIndex) (Move 2 direct accesses to proof.nBits to pow) 7067ed1c52GetChallengeStr(CBlockIndex) 8732d1c213GetChallengeStrHex(CBlockIndex) 678ef3046dGetNonce(CBlockHeader) 2b378502dcSetNonce(CBlockHeader) 6f72b8e366jtimon force-pushed on Nov 26, 2014jtimon commented at 11:37 am on November 26, 2014: contributorNeeded rebase.laanwj added the label Improvement on Dec 5, 2014jaromil commented at 1:02 pm on December 15, 2014: contributorThis 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:
0bool CheckChallenge(const CBlockHeader& block, const CBlockIndex& indexLast); 1void ResetChallenge(CBlockHeader& block, const CBlockIndex& indexLast); 2 3/** Avoid using these functions when possible */ 4double GetChallengeDifficulty(const CBlockIndex* blockindex); 5std::string GetChallengeStr(const CBlockIndex& block); 6std::string GetChallengeStrHex(const CBlockIndex& block); 7uint32_t GetNonce(const CBlockHeader& block); 8void 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 commented at 1:28 pm on December 15, 2014: contributorNACK
“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 commented at 2:51 pm on December 15, 2014: contributorWell, it introduces theChallenge
term on check/reset block-index operations which seems more readable to me compared to theif
checks. It also does so keepingblock
as first argument for all new functions, consistent with other existing calls likeCheckBlockHeader
. At last it introduces get/set function wrappers to operations accessing thenonce
. 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 commented at 8:23 pm on January 7, 2015: contributorClosing 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/noproofjtimon closed this on Jan 7, 2015
MarcoFalke locked this on Sep 8, 2021Labels
Refactoring
github-metadata-mirror
This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-11-17 09:12 UTC
This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-11-17 09:12 UTC
This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me
More mirrored repositories can be found on mirror.b10c.me