forked from UASF/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 2
Minimum viable PoW change #5
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
Open
luke-jr
wants to merge
11
commits into
BitcoinHardfork:0.14-uasf_backup_hardfork
Choose a base branch
from
luke-jr:0.14-bak_hf-minimum
base: 0.14-uasf_backup_hardfork
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2413416
chainparams: Define (unset) hardfork time
luke-jr aa4293d
consensus/params: PowAlgorithmForTime method
luke-jr 5e76297
validation: Forbid reversal of PoW change
luke-jr b2900b9
pow: GetNextWorkRequired: Refactor so all non-limit answers go throug…
luke-jr 00e215f
pow: GetNextWorkRequired: Adjust difficulty for first non-SHA2 block
luke-jr 607a72b
CBlockHeader::GetHash: Check with consensus parameters for PoW algo t…
luke-jr 05fc4ab
chainparams: Define (unset) PoW change hardfork param
luke-jr 39b96dd
chainparams: Rotating PoW algorithm for regtest
luke-jr c251fab
test_framework: powhash abstraction
luke-jr 93add2b
test_framework: Adapt powhash to rotating regtest PoW
luke-jr 65d8845
GetEarliestNextBlockTime replaces GetMedianTimePast only for minimum …
luke-jr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,8 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead | |
| if (pindexLast == NULL) | ||
| return nProofOfWorkLimit; | ||
|
|
||
| uint32_t nBits; | ||
|
|
||
| // Only change once per difficulty adjustment interval | ||
| if ((pindexLast->nHeight+1) % params.DifficultyAdjustmentInterval() != 0) | ||
| { | ||
|
|
@@ -30,23 +32,38 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead | |
| return nProofOfWorkLimit; | ||
| else | ||
| { | ||
| // Return the last non-special-min-difficulty-rules-block | ||
| // Look back to the last non-special-min-difficulty-rules-block | ||
| const CBlockIndex* pindex = pindexLast; | ||
| while (pindex->pprev && pindex->nHeight % params.DifficultyAdjustmentInterval() != 0 && pindex->nBits == nProofOfWorkLimit) | ||
| pindex = pindex->pprev; | ||
| return pindex->nBits; | ||
| nBits = pindex->nBits; | ||
| } | ||
| } else { | ||
| nBits = pindexLast->nBits; | ||
| } | ||
| return pindexLast->nBits; | ||
| } else { | ||
| // Go back by what we want to be 14 days worth of blocks | ||
| int nHeightFirst = pindexLast->nHeight - (params.DifficultyAdjustmentInterval()-1); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (nit) Would this be more readable as |
||
| assert(nHeightFirst >= 0); | ||
| const CBlockIndex* pindexFirst = pindexLast->GetAncestor(nHeightFirst); | ||
| assert(pindexFirst); | ||
|
|
||
| nBits = CalculateNextWorkRequired(pindexLast, pindexFirst->GetBlockTime(), params); | ||
| } | ||
|
|
||
| // Go back by what we want to be 14 days worth of blocks | ||
| int nHeightFirst = pindexLast->nHeight - (params.DifficultyAdjustmentInterval()-1); | ||
| assert(nHeightFirst >= 0); | ||
| const CBlockIndex* pindexFirst = pindexLast->GetAncestor(nHeightFirst); | ||
| assert(pindexFirst); | ||
| if (params.PowAlgorithmForTime(pblock->nTime) != params.PowAlgorithmForTime(pindexLast->nTime)) { | ||
| // Adjust target for PoW change | ||
| arith_uint256 bnNew; | ||
| bnNew.SetCompact(nBits); | ||
| bnNew <<= params.nPowChangeTargetShift; | ||
| const arith_uint256 bnPowLimit = UintToArith256(params.powLimit); | ||
| if (bnNew > bnPowLimit) { | ||
| bnNew = bnPowLimit; | ||
| } | ||
| nBits = bnNew.GetCompact(); | ||
| } | ||
|
|
||
| return CalculateNextWorkRequired(pindexLast, pindexFirst->GetBlockTime(), params); | ||
| return nBits; | ||
| } | ||
|
|
||
| unsigned int CalculateNextWorkRequired(const CBlockIndex* pindexLast, int64_t nFirstBlockTime, const Consensus::Params& params) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
(nit) May be more readable as
nTryTime = (nMinTime + nMaxTime) / 2;