diff options
| author | coblee <[email protected]> | 2011-10-09 20:46:21 -1000 |
|---|---|---|
| committer | Ross Nicoll <[email protected]> | 2021-05-20 20:50:57 +0100 |
| commit | a3e518670c22e1ab338ccdf7d852e1a7b1201f92 (patch) | |
| tree | a7f36050887b08085a709987d1b7be7834b20821 /src | |
| parent | Merge pull request #1927 from rnicoll/1.21-max-money (diff) | |
| download | discoin-a3e518670c22e1ab338ccdf7d852e1a7b1201f92.tar.xz discoin-a3e518670c22e1ab338ccdf7d852e1a7b1201f92.zip | |
Litecoin: Fix zeitgeist2 attack thanks to Lolcust and ArtForz. This fixes an issue where a 51% attack can change difficulty at will. Go back the full period unless it's the first retarget after genesis.
Diffstat (limited to 'src')
| -rw-r--r-- | src/pow.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/pow.cpp b/src/pow.cpp index 1414d3756..70c61e77d 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -37,8 +37,14 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead return pindexLast->nBits; } + // Litecoin: This fixes an issue where a 51% attack can change difficulty at will. + // Go back the full period unless it's the first retarget after genesis. Code courtesy of Art Forz + int blockstogoback = params.DifficultyAdjustmentInterval()-1; + if ((pindexLast->nHeight+1) != params.DifficultyAdjustmentInterval()) + blockstogoback = params.DifficultyAdjustmentInterval(); + // Go back by what we want to be 14 days worth of blocks - int nHeightFirst = pindexLast->nHeight - (params.DifficultyAdjustmentInterval()-1); + int nHeightFirst = pindexLast->nHeight - blockstogoback; assert(nHeightFirst >= 0); const CBlockIndex* pindexFirst = pindexLast->GetAncestor(nHeightFirst); assert(pindexFirst); |