Skip to content

Commit

Permalink
Merge pull request #182 from RavenProject/dwg-sync-fix
Browse files Browse the repository at this point in the history
Dwg sync fix
  • Loading branch information
TronBlack authored Aug 3, 2018
2 parents c2dab48 + f000fcc commit 1a30524
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ dnl require autoconf 2.60 (AS_ECHO/AS_ECHO_N)
AC_PREREQ([2.60])
define(_CLIENT_VERSION_MAJOR, 2)
define(_CLIENT_VERSION_MINOR, 0)
define(_CLIENT_VERSION_REVISION, 1)
define(_CLIENT_VERSION_REVISION, 2)
define(_CLIENT_VERSION_BUILD, 0)
define(_CLIENT_VERSION_IS_RELEASE, true)
define(_COPYRIGHT_YEAR, 2018)
Expand Down
37 changes: 32 additions & 5 deletions src/pow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "uint256.h"
#include "util.h"
#include "validation.h"
#include "chainparams.h"
#include "tinyformat.h"

unsigned int static DarkGravityWave(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params) {
/* current difficulty formula, dash - DarkGravity v3, written by Evan Duffield - [email protected] */
Expand Down Expand Up @@ -123,16 +125,19 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
int dgw = DarkGravityWave(pindexLast, pblock, params);
int btc = GetNextWorkRequiredBTC(pindexLast, pblock, params);
int64_t nPrevBlockTime = (pindexLast->pprev ? pindexLast->pprev->GetBlockTime() : pindexLast->GetBlockTime());
if (AreAssetsDeployed()) {
LogPrintf("Block %s: found next work required using DGW: [%s] (BTC would have been [%s]\t(%+d)\t(%0.3f%%)\t(%s sec))\n",
pindexLast->nHeight, dgw, btc, btc - dgw, (float)(btc - dgw) * 100.0 / (float)dgw, pindexLast->GetBlockTime() - nPrevBlockTime);

int version = (pblock->nVersion & 0xF0000000) >> 28;
if (version >= 3 && !CheckPOWHeightAssets(pindexLast->nHeight + 1)) {
LogPrint(BCLog::NET, "Block %s - version: %s: found next work required using DGW: [%s] (BTC would have been [%s]\t(%+d)\t(%0.3f%%)\t(%s sec))\n",
pindexLast->nHeight, pblock->nVersion, dgw, btc, btc - dgw, (float)(btc - dgw) * 100.0 / (float)dgw, pindexLast->GetBlockTime() - nPrevBlockTime);
return dgw;
}
else {
LogPrintf("Block %s: found next work required using BTC: [%s] (DGW would have been [%s]\t(%+d)\t(%0.3f%%)\t(%s sec))\n",
pindexLast->nHeight, btc, dgw, dgw - btc, (float)(dgw - btc) * 100.0 / (float)btc, pindexLast->GetBlockTime() - nPrevBlockTime);
LogPrint(BCLog::NET, "Block %s - version: %s: found next work required using BTC: [%s] (DGW would have been [%s]\t(%+d)\t(%0.3f%%)\t(%s sec))\n",
pindexLast->nHeight, pblock->nVersion, btc, dgw, dgw - btc, (float)(dgw - btc) * 100.0 / (float)btc, pindexLast->GetBlockTime() - nPrevBlockTime);
return btc;
}

}

unsigned int CalculateNextWorkRequired(const CBlockIndex* pindexLast, int64_t nFirstBlockTime, const Consensus::Params& params)
Expand Down Expand Up @@ -178,3 +183,25 @@ bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params&

return true;
}

// Used to determine if one of these block heights is failing the check because these were mined with block version of 3 before RIP2 was active.
bool CheckPOWHeightAssets(const int height)
{
if (Params().NetworkIDString() == "test") {
return (height == 319456 ||
height == 319468 ||
height == 319469 ||
height == 319494 ||
height == 319500 ||
height == 319501 ||
height == 319502 ||
height == 319520 ||
height == 319522 ||
height == 319532 ||
height == 319533);
} else {
return false;
}


}
1 change: 1 addition & 0 deletions src/pow.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class uint256;

unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params&);
unsigned int CalculateNextWorkRequired(const CBlockIndex* pindexLast, int64_t nFirstBlockTime, const Consensus::Params&);
bool CheckPOWHeightAssets(const int height);

/** Check whether a block hash satisfies the proof-of-work requirement specified by nBits */
bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params&);
Expand Down
2 changes: 1 addition & 1 deletion src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3359,7 +3359,7 @@ bool CheckBlock(const CBlock& block, CValidationState& state, const Consensus::P
for (const auto& tx : block.vtx)
if (!CheckTransaction(*tx, state, passets, false))
return state.Invalid(false, state.GetRejectCode(), state.GetRejectReason(),
strprintf("Transaction check failed (tx hash %s) %s", tx->GetHash().ToString(), state.GetDebugMessage()));
strprintf("Transaction check failed (tx hash %s) %s %s", tx->GetHash().ToString(), state.GetDebugMessage(), state.GetRejectReason()));

unsigned int nSigOps = 0;
for (const auto& tx : block.vtx)
Expand Down

0 comments on commit 1a30524

Please sign in to comment.