Skip to content

Commit

Permalink
KGW Added , Tweaked , Version Bumps Added
Browse files Browse the repository at this point in the history
KGW Added , Tweaked , Version Bumps Added HARD FORK AT 40,000
  • Loading branch information
sherlockcoin committed Mar 17, 2014
1 parent 710722a commit 86f5961
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 77 deletions.
2 changes: 1 addition & 1 deletion 42-qt.pro
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
TEMPLATE = app
TARGET =
VERSION = 0.6.4.5
VERSION = 0.7.0.0
INCLUDEPATH += src src/json src/qt
DEFINES += QT_GUI BOOST_THREAD_USE_LIB BOOST_SPIRIT_THREADSAFE USE_IPV6 __NO_SYSTEM_INCLUDES
CONFIG += no_include_pwd
Expand Down
6 changes: 3 additions & 3 deletions share/setup.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SetCompressor /SOLID lzma

# General Symbol Definitions
!define REGKEY "SOFTWARE\$(^Name)"
!define VERSION 0.6.3
!define VERSION 0.7.0.0
!define COMPANY "Litecoin project"
!define URL http://www.litecoin.org/

Expand Down Expand Up @@ -45,13 +45,13 @@ Var StartMenuGroup
!insertmacro MUI_LANGUAGE English

# Installer attributes
OutFile litecoin-0.6.3-win32-setup.exe
OutFile litecoin-0.7.0.0-win32-setup.exe
InstallDir $PROGRAMFILES\Litecoin
CRCCheck on
XPStyle on
BrandingText " "
ShowInstDetails show
VIProductVersion 0.6.3.0
VIProductVersion 0.7.0.0
VIAddVersionKey ProductName Litecoin
VIAddVersionKey ProductVersion "${VERSION}"
VIAddVersionKey CompanyName "${COMPANY}"
Expand Down
5 changes: 3 additions & 2 deletions src/checkpoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ namespace Checkpoints
static MapCheckpoints mapCheckpoints =
boost::assign::map_list_of
( 0, uint256("0x38071cd415decbe206c9cce527b2b1f90791cf6ab4df0c0c13665931b9a6ae1d"))
( 65, uint256("0x814d4d4cfa47d712a3d0e3670ef5af75581a62b6fc0dfb94e71d5f7b1572d71a"))
;
( 65, uint256("0x814d4d4cfa47d712a3d0e3670ef5af75581a62b6fc0dfb94e71d5f7b1572d71a"))
( 35028, uint256("0x48f925e4bcc75b04612624ed0011c7d3c2ed39601b111c2030d2561b4bb0b10b"))
;

bool CheckBlock(int nHeight, const uint256& hash)
{
Expand Down
201 changes: 133 additions & 68 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -834,12 +834,8 @@ static const int64 nDiffChangeTarget = 600000;

int64 static GetBlockValue(int nHeight, int64 nFees)
{
int64 nSubsidy = 0.000042 * COIN;
if(nHeight < 990382) // stops generation of more coins
{
nSubsidy = 0.000042 * COIN;
}
if(nHeight < 419)
int64 nSubsidy = 0.000042 * COIN;
if(nHeight < 419)
{
nSubsidy = 0.0000001 * COIN;
}
Expand All @@ -863,9 +859,9 @@ int64 static GetBlockValue(int nHeight, int64 nFees)
{
nSubsidy = 0.00042 * COIN;
}
if(nHeight >= 990382) // stops generation of more coins
{
nSubsidy = 0 * COIN;
if(nHeight == 4242424)
{
nSubsidy = 0.00042 * COIN;
}
return nSubsidy + nFees;
}
Expand Down Expand Up @@ -914,51 +910,43 @@ unsigned int ComputeMinWork(unsigned int nBase, int64 nTime)
return bnResult.GetCompact();
}

unsigned int static GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlock *pblock)
unsigned int static GetNextWorkRequired_V1(const CBlockIndex* pindexLast, const CBlock *pblock)
{
unsigned int nProofOfWorkLimit = bnProofOfWorkLimit.GetCompact();

int nHeight = pindexLast->nHeight + 1;
bool fNewDifficultyProtocol = (nHeight >= nDiffChangeTarget || fTestNet);
int blockstogoback = 0;
//set default to pre-v6.4.3 patch values
int64 retargetTimespan = nTargetTimespan;
int64 retargetSpacing = nTargetSpacing;
int64 retargetInterval = nInterval;
// Genesis block
if (pindexLast == NULL) return nProofOfWorkLimit;
if (pindexLast == NULL)
return nProofOfWorkLimit;

//if patch v6.4.3 changes are in effect for block num, alter retarget values
if(fNewDifficultyProtocol) {
retargetTimespan = nTargetTimespanRe;
retargetSpacing = nTargetSpacingRe;
retargetInterval = nIntervalRe;
}

// Only change once per interval
if ((pindexLast->nHeight+1) % retargetInterval != 0){
// Special difficulty rule for testnet:
if (fTestNet){
// If the new block's timestamp is more than 2* 10 minutes
// then allow mining of a min-difficulty block.
if (pblock->nTime > pindexLast->nTime + retargetSpacing*2)
return nProofOfWorkLimit;
else {
// Return the last non-special-min-difficulty-rules-block
const CBlockIndex* pindex = pindexLast;
while (pindex->pprev && pindex->nHeight % retargetInterval != 0 && pindex->nBits == nProofOfWorkLimit)
pindex = pindex->pprev;
return pindex->nBits;
}
}
return pindexLast->nBits;
if ((pindexLast->nHeight+1) % nInterval != 0)
{
// Special difficulty rule for testnet:
if (fTestNet)
{
// If the new block's timestamp is more than 2* 10 minutes
// then allow mining of a min-difficulty block.
if (pblock->nTime > pindexLast->nTime + nTargetSpacing*2)
return nProofOfWorkLimit;
else
{
// Return the last non-special-min-difficulty-rules-block
const CBlockIndex* pindex = pindexLast;
while (pindex->pprev && pindex->nHeight % nInterval != 0 && pindex->nBits == nProofOfWorkLimit)
pindex = pindex->pprev;
return pindex->nBits;
}
}

return pindexLast->nBits;
}

// 42: 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
blockstogoback = retargetInterval-1;
if ((pindexLast->nHeight+1) != retargetInterval) blockstogoback = retargetInterval;

int blockstogoback = nInterval-1;
if ((pindexLast->nHeight+1) != nInterval)
blockstogoback = nInterval;

// Go back by what we want to be 14 days worth of blocks
const CBlockIndex* pindexFirst = pindexLast;
for (int i = 0; pindexFirst && i < blockstogoback; i++)
Expand All @@ -968,40 +956,117 @@ unsigned int static GetNextWorkRequired(const CBlockIndex* pindexLast, const CBl
// Limit adjustment step
int64 nActualTimespan = pindexLast->GetBlockTime() - pindexFirst->GetBlockTime();
printf(" nActualTimespan = %"PRI64d" before bounds\n", nActualTimespan);
if (nActualTimespan < nTargetTimespan/4)
nActualTimespan = nTargetTimespan/4;
if (nActualTimespan > nTargetTimespan*4)
nActualTimespan = nTargetTimespan*4;



// Retarget
CBigNum bnNew;
bnNew.SetCompact(pindexLast->nBits);

// thanks to RealSolid for this code
if(fNewDifficultyProtocol) {
if (nActualTimespan < (retargetTimespan - (retargetTimespan/10)) ) nActualTimespan = (retargetTimespan - (retargetTimespan/10));
if (nActualTimespan > (retargetTimespan + (retargetTimespan/10)) ) nActualTimespan = (retargetTimespan + (retargetTimespan/10));
}
else {
if (nActualTimespan < retargetTimespan/4) nActualTimespan = retargetTimespan/4;
if (nActualTimespan > retargetTimespan*4) nActualTimespan = retargetTimespan*4;
}

// Retarget
bnNew *= nActualTimespan;
bnNew /= retargetTimespan;
bnNew /= nTargetTimespan;

if (bnNew > bnProofOfWorkLimit)
bnNew = bnProofOfWorkLimit;

/// debug print
printf("GetNextWorkRequired RETARGET \n");
printf("retargetTimespan = %"PRI64d" nActualTimespan = %"PRI64d"\n", retargetTimespan, nActualTimespan);
printf("GetNextWorkRequired RETARGET\n");
printf("nTargetTimespan = %"PRI64d" nActualTimespan = %"PRI64d"\n", nTargetTimespan, nActualTimespan);
printf("Before: %08x %s\n", pindexLast->nBits, CBigNum().SetCompact(pindexLast->nBits).getuint256().ToString().c_str());
printf("After: %08x %s\n", bnNew.GetCompact(), bnNew.getuint256().ToString().c_str());


if (bnNew > bnProofOfWorkLimit)
bnNew = bnProofOfWorkLimit;
return bnNew.GetCompact();
}

unsigned int static KimotoGravityWell(const CBlockIndex* pindexLast, const CBlock *pblock, uint64 TargetBlocksSpacingSeconds, uint64 PastBlocksMin, uint64 PastBlocksMax) {
/* current difficulty formula, kimoto gravity well */
const CBlockIndex *BlockLastSolved = pindexLast;
const CBlockIndex *BlockReading = pindexLast;
const CBlock *BlockCreating = pblock;
BlockCreating = BlockCreating;
uint64 PastBlocksMass = 0;
int64 PastRateActualSeconds = 0;
int64 PastRateTargetSeconds = 0;
double PastRateAdjustmentRatio = double(1);
CBigNum PastDifficultyAverage;
CBigNum PastDifficultyAveragePrev;
double EventHorizonDeviation;
double EventHorizonDeviationFast;
double EventHorizonDeviationSlow;

if (BlockLastSolved == NULL || BlockLastSolved->nHeight == 0 || (uint64)BlockLastSolved->nHeight < PastBlocksMin) { return bnProofOfWorkLimit.GetCompact(); }

for (unsigned int i = 1; BlockReading && BlockReading->nHeight > 0; i++) {
if (PastBlocksMax > 0 && i > PastBlocksMax) { break; }
PastBlocksMass++;

if (i == 1) { PastDifficultyAverage.SetCompact(BlockReading->nBits); }
else { PastDifficultyAverage = ((CBigNum().SetCompact(BlockReading->nBits) - PastDifficultyAveragePrev) / i) + PastDifficultyAveragePrev; }
PastDifficultyAveragePrev = PastDifficultyAverage;

PastRateActualSeconds = BlockLastSolved->GetBlockTime() - BlockReading->GetBlockTime();
PastRateTargetSeconds = TargetBlocksSpacingSeconds * PastBlocksMass;
PastRateAdjustmentRatio = double(1);
if (PastRateActualSeconds < 0) { PastRateActualSeconds = 0; }
if (PastRateActualSeconds != 0 && PastRateTargetSeconds != 0) {
PastRateAdjustmentRatio = double(PastRateTargetSeconds) / double(PastRateActualSeconds);
}
EventHorizonDeviation = 1 + (0.7084 * pow((double(PastBlocksMass)/double(42)), -1.228));
EventHorizonDeviationFast = EventHorizonDeviation;
EventHorizonDeviationSlow = 1 / EventHorizonDeviation;

if (PastBlocksMass >= PastBlocksMin) {
if ((PastRateAdjustmentRatio <= EventHorizonDeviationSlow) || (PastRateAdjustmentRatio >= EventHorizonDeviationFast)) { assert(BlockReading); break; }
}
if (BlockReading->pprev == NULL) { assert(BlockReading); break; }
BlockReading = BlockReading->pprev;
}

CBigNum bnNew(PastDifficultyAverage);
if (PastRateActualSeconds != 0 && PastRateTargetSeconds != 0) {
bnNew *= PastRateActualSeconds;
bnNew /= PastRateTargetSeconds;
}
if (bnNew > bnProofOfWorkLimit) { bnNew = bnProofOfWorkLimit; }

/// debug print
printf("Difficulty Retarget - Kimoto Gravity Well\n");
printf("PastRateAdjustmentRatio = %g\n", PastRateAdjustmentRatio);
printf("Before: %08x %s\n", BlockLastSolved->nBits, CBigNum().SetCompact(BlockLastSolved->nBits).getuint256().ToString().c_str());
printf("After: %08x %s\n", bnNew.GetCompact(), bnNew.getuint256().ToString().c_str());

return bnNew.GetCompact();
}

unsigned int static GetNextWorkRequired_V2(const CBlockIndex* pindexLast, const CBlock *pblock)
{
static const int64 BlocksTargetSpacing = .7 * 60; // 30 seconds
unsigned int TimeDaySeconds = 60 * 60 * 24;
int64 PastSecondsMin = TimeDaySeconds * 0.021;
int64 PastSecondsMax = TimeDaySeconds * 0.06;
uint64 PastBlocksMin = PastSecondsMin / BlocksTargetSpacing;
uint64 PastBlocksMax = PastSecondsMax / BlocksTargetSpacing;

return KimotoGravityWell(pindexLast, pblock, BlocksTargetSpacing, PastBlocksMin, PastBlocksMax);
}

return bnNew.GetCompact();
unsigned int static GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlock *pblock)
{
int DiffMode = 1;
if (fTestNet) {
if (pindexLast->nHeight+1 >= 50) { DiffMode = 2; }
}
else {
if (pindexLast->nHeight+1 >= 40000) { DiffMode = 2; }
}

if (DiffMode == 1) { return GetNextWorkRequired_V1(pindexLast, pblock); }
else if (DiffMode == 2) { return GetNextWorkRequired_V2(pindexLast, pblock); }
return GetNextWorkRequired_V2(pindexLast, pblock);
}


bool CheckProofOfWork(uint256 hash, unsigned int nBits)
{
CBigNum bnTarget;
Expand Down Expand Up @@ -1474,7 +1539,7 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex)
}

if (vtx[0].GetValueOut() > GetBlockValue(pindex->nHeight, nFees))
return DoS(100, error("ConnectBlock() : coinbase pays too much (actual=%"PRI64d" vs limit=%"PRI64d")", vtx[0].GetValueOut(), GetBlockValue(pindex->nHeight, nFees)));
return false;

// Update block index on disk without changing it in memory.
// The memory index structure will be changed after the db commits.
Expand Down Expand Up @@ -3900,4 +3965,4 @@ void GenerateBitcoins(bool fGenerate, CWallet* pwallet)
Sleep(10);
}
}
}
}
6 changes: 3 additions & 3 deletions src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

// These need to be macro's, as version.cpp's voodoo requires it
#define CLIENT_VERSION_MAJOR 0
#define CLIENT_VERSION_MINOR 6
#define CLIENT_VERSION_REVISION 4
#define CLIENT_VERSION_BUILD 6
#define CLIENT_VERSION_MINOR 7
#define CLIENT_VERSION_REVISION 0
#define CLIENT_VERSION_BUILD 0

static const int CLIENT_VERSION =
1000000 * CLIENT_VERSION_MAJOR
Expand Down

0 comments on commit 86f5961

Please sign in to comment.