Skip to content

Commit

Permalink
Add Support DGW3.
Browse files Browse the repository at this point in the history
  • Loading branch information
Reecoin authored and Reecoin committed Jun 20, 2016
1 parent 0627343 commit 7542ba4
Show file tree
Hide file tree
Showing 8 changed files with 343 additions and 30 deletions.
260 changes: 260 additions & 0 deletions Reecoin-qt.pro.user

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/bitcoinrpc.cpp
Expand Up @@ -42,7 +42,7 @@ void ThreadRPCServer3(void* parg);

static inline unsigned short GetDefaultRPCPort()
{
return GetBoolArg("-testnet", false) ? 11385 : 11939;
return GetBoolArg("-testnet", false) ? 11385 : 11627;
}

Object JSONRPCError(int code, const string& message)
Expand Down
2 changes: 1 addition & 1 deletion src/clientversion.h
Expand Up @@ -9,7 +9,7 @@
#define CLIENT_VERSION_MAJOR 1
#define CLIENT_VERSION_MINOR 0
#define CLIENT_VERSION_REVISION 0
#define CLIENT_VERSION_BUILD 2
#define CLIENT_VERSION_BUILD 3

// Converts the parameter X to a string after macro replacement on X has been performed.
// Don't merge these into one macro!
Expand Down
19 changes: 0 additions & 19 deletions src/clientversion.h~

This file was deleted.

83 changes: 78 additions & 5 deletions src/main.cpp
Expand Up @@ -1128,14 +1128,87 @@ static unsigned int GetNextTargetRequiredV2(const CBlockIndex* pindexLast, bool
return bnNew.GetCompact();
}

unsigned int GetNextTargetRequired(const CBlockIndex* pindexLast, bool fProofOfStake)

//// START DGW3
unsigned int static DarkGravityWave3(const CBlockIndex* pindexLast, const CBlock *pblock) {
/* current difficulty formula, darkcoin - DarkGravity v3, written by Evan Duffield - evan@darkcoin.io */
const CBlockIndex *BlockLastSolved = pindexLast;
const CBlockIndex *BlockReading = pindexLast;
const CBlock *BlockCreating = pblock;
BlockCreating = BlockCreating;
int64_t nActualTimespan = 0;
int64_t LastBlockTime = 0;
int64_t PastBlocksMin = 24;
int64_t PastBlocksMax = 24;
int64_t CountBlocks = 0;
CBigNum PastDifficultyAverage;
CBigNum PastDifficultyAveragePrev;

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

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

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

if(LastBlockTime > 0){
int64_t Diff = (LastBlockTime - BlockReading->GetBlockTime());
nActualTimespan += Diff;
}
LastBlockTime = BlockReading->GetBlockTime();

if (BlockReading->pprev == NULL) { assert(BlockReading); break; }
BlockReading = BlockReading->pprev;
}

CBigNum bnNew(PastDifficultyAverage);

int64_t nTargetTimespan = CountBlocks*nTargetSpacing;

if (nActualTimespan < nTargetTimespan/3)
nActualTimespan = nTargetTimespan/3;
if (nActualTimespan > nTargetTimespan*3)
nActualTimespan = nTargetTimespan*3;

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

// debug print
printf("DarkGravityWave3 RETARGET\n");
printf("nTargetTimespan = %"PRId64" nActualTimespan = %"PRId64"\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();
}



/// END DGW3



unsigned int GetNextTargetRequired(const CBlockIndex* pindexLast, bool fProofOfStake,const CBlock *pblock)
{
if ((pindexLast->nHeight < 10000) || (pindexLast->nHeight > 50000 && pindexLast->nHeight < 60000))
return GetNextTargetRequiredV1(pindexLast, fProofOfStake);
if ((pindexLast->nHeight < 44000) )
{return GetNextTargetRequiredV1(pindexLast, fProofOfStake);}
else
return GetNextTargetRequiredV2(pindexLast, fProofOfStake);
{ return DarkGravityWave3(pindexLast,pblock);}
}


bool CheckProofOfWork(uint256 hash, unsigned int nBits)
{
CBigNum bnTarget;
Expand Down Expand Up @@ -2171,7 +2244,7 @@ bool CBlock::AcceptBlock()
return DoS(100, error("AcceptBlock() : reject proof-of-work at height %d", nHeight));
*/
// Check proof-of-work or proof-of-stake
if (nBits != GetNextTargetRequired(pindexPrev, IsProofOfStake()))
if (nBits != GetNextTargetRequired(pindexPrev, IsProofOfStake(),this))
return DoS(100, error("AcceptBlock() : incorrect %s", IsProofOfWork() ? "proof-of-work" : "proof-of-stake"));

// Check timestamp against prev
Expand Down
2 changes: 1 addition & 1 deletion src/main.h
Expand Up @@ -111,7 +111,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle);
bool LoadExternalBlockFile(FILE* fileIn);

bool CheckProofOfWork(uint256 hash, unsigned int nBits);
unsigned int GetNextTargetRequired(const CBlockIndex* pindexLast, bool fProofOfStake);
unsigned int GetNextTargetRequired(const CBlockIndex* pindexLast, bool fProofOfStake,const CBlock* pblock);
int64_t GetProofOfWorkReward(int64_t nFees, unsigned int nHeight);
int64_t GetProofOfStakeReward(int64_t nCoinAge, int64_t nFees);
unsigned int ComputeMinWork(unsigned int nBase, int64_t nTime);
Expand Down
3 changes: 1 addition & 2 deletions src/miner.cpp
Expand Up @@ -162,8 +162,7 @@ CBlock* CreateNewBlock(CWallet* pwallet, bool fProofOfStake, int64_t* pFees)
int64_t nMinTxFee = MIN_TX_FEE;
if (mapArgs.count("-mintxfee"))
ParseMoney(mapArgs["-mintxfee"], nMinTxFee);

pblock->nBits = GetNextTargetRequired(pindexPrev, fProofOfStake);
pblock->nBits = GetNextTargetRequired(pindexPrev, fProofOfStake, pblock.get());

// Collect memory pool transactions into the block
int64_t nFees = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/protocol.h
Expand Up @@ -18,7 +18,7 @@
extern bool fTestNet;
static inline unsigned short GetDefaultPort(const bool testnet = fTestNet)
{
return testnet ? 12385 : 11390;
return testnet ? 12385 : 11697;
}


Expand Down

0 comments on commit 7542ba4

Please sign in to comment.