I don't expect a measurable performance improvement from this, but result seems more readable too.
Use GetAncestor to compute new target #5948
pull sipa wants to merge 1 commits into bitcoin:master from sipa:fastpow changing 1 files +3 −3-
sipa commented at 6:15 PM on March 26, 2015: member
-
Trivial optimization: use GetAncestor to compute new target 1cc0e96e9c
-
in src/pow.cpp:None in 1cc0e96e9c
41 | @@ -42,9 +42,9 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead 42 | } 43 | 44 | // Go back by what we want to be 14 days worth of blocks 45 | - const CBlockIndex* pindexFirst = pindexLast; 46 | - for (int i = 0; pindexFirst && i < params.DifficultyAdjustmentInterval()-1; i++) 47 | - pindexFirst = pindexFirst->pprev; 48 | + int nHeightFirst = pindexLast->nHeight - (params.DifficultyAdjustmentInterval()-1); 49 | + assert(nHeightFirst >= 0);
laanwj commented at 7:57 AM on March 27, 2015:Looks good to me. This assert could even be left out as GetAncestor already returns NULL for heights
<0.
sipa commented at 6:14 PM on March 27, 2015:To mimick the exact old code, it would need to be nHeightFirst = std::max(0, pindex->nHeight - (... - 1));. I added the assert to be sure for now that dropping the std::max is safe (which it should be afaict).
laanwj commented at 11:21 AM on April 1, 2015:OK, fair enough
laanwj added the label Improvement on Mar 27, 2015laanwj commented at 11:23 AM on April 1, 2015: memberGoing to test this on my test node.
laanwj commented at 10:50 AM on April 6, 2015: memberTested ACK
sipa merged this on Apr 7, 2015sipa closed this on Apr 7, 2015sipa referenced this in commit b36f1ce87e on Apr 7, 2015MarcoFalke locked this on Sep 8, 2021Labels
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: 2026-04-19 09:15 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: 2026-04-19 09:15 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