Skip to content

Commit

Permalink
v1.4.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphire-pt committed Jan 12, 2021
1 parent b3e329c commit 22ed043
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 48 deletions.
4 changes: 2 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ dnl require autoconf 2.60 (AS_ECHO/AS_ECHO_N)
AC_PREREQ([2.60])
define(_CLIENT_VERSION_MAJOR, 1)
define(_CLIENT_VERSION_MINOR, 4)
define(_CLIENT_VERSION_REVISION, 0)
define(_CLIENT_VERSION_BUILD, 1)
define(_CLIENT_VERSION_REVISION, 1)
define(_CLIENT_VERSION_BUILD, 0)
define(_CLIENT_VERSION_RC, 0)
define(_CLIENT_VERSION_IS_RELEASE, true)
define(_COPYRIGHT_YEAR, 2020)
Expand Down
6 changes: 6 additions & 0 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ class CMainParams : public CChainParams
consensus.nStakeMinAge = 60 * 60;
consensus.nStakeMinDepth = 60;
consensus.nStakeMinDepthV2 = 600;
consensus.nTargetTimespan = 40 * 60;
consensus.nTargetTimespanV2 = 30 * 60;
consensus.nTargetSpacing = 1 * 60;
consensus.nTimeSlotLength = 15;

Expand Down Expand Up @@ -279,6 +281,8 @@ class CTestNetParams : public CMainParams
consensus.nStakeMinAge = 60 * 60;
consensus.nStakeMinDepth = 60;
consensus.nStakeMinDepthV2 = 600;
consensus.nTargetTimespan = 40 * 60;
consensus.nTargetTimespanV2 = 30 * 60;
consensus.nTargetSpacing = 1 * 60;
consensus.nTimeSlotLength = 15;

Expand Down Expand Up @@ -425,6 +429,8 @@ class CRegTestParams : public CTestNetParams
consensus.nProposalEstablishmentTime = 60 * 5; // at least 5 min old to make it into a budget
consensus.nStakeMinAge = 0;
consensus.nStakeMinDepth = 2;
consensus.nTargetTimespan = 40 * 60;
consensus.nTargetTimespanV2 = 30 * 60;
consensus.nTargetSpacing = 1 * 60;
consensus.nTimeSlotLength = 15;

Expand Down
3 changes: 3 additions & 0 deletions src/consensus/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ struct Params {
int nStakeMinAge;
int nStakeMinDepth;
int nStakeMinDepthV2;
int64_t nTargetTimespan;
int64_t nTargetTimespanV2;
int64_t nTargetSpacing;
int nTimeSlotLength;

Expand All @@ -129,6 +131,7 @@ struct Params {
// Map with network updates
NetworkUpgrade vUpgrades[MAX_NETWORK_UPGRADES];

int64_t TargetTimespan(const bool fV2 = true) const { return fV2 ? nTargetTimespanV2 : nTargetTimespan; }
uint256 ProofOfStakeLimit(const bool fV2) const { return fV2 ? posLimitV2 : posLimitV1; }
bool MoneyRange(const CAmount& nValue) const { return (nValue >= 0 && nValue <= nMaxMoneyOut); }
bool IsTimeProtocolV2(const int nHeight) const { return NetworkUpgradeActive(nHeight, UPGRADE_V4_0); }
Expand Down
8 changes: 4 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6029,12 +6029,12 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR
int ActiveProtocol()
{
// SPORK_14 is used for 70919 (v4.1.1)
if (sporkManager.IsSporkActive(SPORK_14_NEW_PROTOCOL_ENFORCEMENT))
return MIN_PEER_PROTO_VERSION_AFTER_ENFORCEMENT;
// if (sporkManager.IsSporkActive(SPORK_14_NEW_PROTOCOL_ENFORCEMENT))
// return MIN_PEER_PROTO_VERSION_AFTER_ENFORCEMENT;

// SPORK_15 was used for 70918 (v4.0, v4.1.0), commented out now.
//if (sporkManager.IsSporkActive(SPORK_15_NEW_PROTOCOL_ENFORCEMENT_2))
// return MIN_PEER_PROTO_VERSION_AFTER_ENFORCEMENT;
if (sporkManager.IsSporkActive(SPORK_15_NEW_PROTOCOL_ENFORCEMENT_2))
return MIN_PEER_PROTO_VERSION_AFTER_ENFORCEMENT;

return MIN_PEER_PROTO_VERSION_BEFORE_ENFORCEMENT;
}
Expand Down
96 changes: 57 additions & 39 deletions src/pow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,76 +23,94 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
if (Params().IsRegTestNet())
return pindexLast->nBits;

/* current difficulty formula, pivx - DarkGravity v3, written by Evan Duffield - [email protected] */
const CBlockIndex* BlockLastSolved = pindexLast;
const CBlockIndex* BlockReading = pindexLast;
int64_t nActualTimespan = 0;
int64_t LastBlockTime = 0;

int64_t PastBlocksMin = 24;
int64_t PastBlocksMax = 24;
int64_t CountBlocks = 0;
uint256 PastDifficultyAverage;
uint256 PastDifficultyAveragePrev;
const Consensus::Params& consensus = Params().GetConsensus();

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

int nHeight = pindexLast->nHeight + 1;

const bool fTimeV2 = !Params().IsRegTestNet() && consensus.IsTimeProtocolV2(nHeight);

int64_t nTargetSpacing = consensus.nTargetSpacing;
int64_t PastBlocks;

if(nHeight % ((24 * 60 * 60) / nTargetSpacing) == 0) { // 24h interval
PastBlocks = (24 * 60 * 60) / nTargetSpacing;
} else if(nHeight % ((12 * 60 * 60) / nTargetSpacing) == 0) { // 12 h interval
PastBlocks = (12 * 60 * 60) / nTargetSpacing;
} else if(nHeight % ((6 * 60 * 60) / nTargetSpacing) == 0) { // 6 h interval
PastBlocks = (6 * 60 * 60) / nTargetSpacing;
} else if(nHeight % ((3 * 60 * 60) / nTargetSpacing) == 0) { // 3 h interval
PastBlocks = (3 * 60 * 60) / nTargetSpacing;
} else if(nHeight % ((1 * 60 * 60) / nTargetSpacing) == 0) { // 1 h interval
PastBlocks = (1 * 60 * 60) / nTargetSpacing;
} else { // 30 min by default
PastBlocks = (30 * 60) / nTargetSpacing;
}
if (consensus.NetworkUpgradeActive(pindexLast->nHeight + 1, Consensus::UPGRADE_POS)) {
const bool fTimeV2 = !Params().IsRegTestNet() && consensus.IsTimeProtocolV2(pindexLast->nHeight+1);
const uint256& bnTargetLimit = consensus.ProofOfStakeLimit(fTimeV2);
const int64_t& nTargetTimespan = consensus.TargetTimespan(fTimeV2);

if (BlockReading->nHeight < PastBlocks) {
return consensus.powLimit.GetCompact();
int64_t nActualSpacing = 0;
if (pindexLast->nHeight != 0)
nActualSpacing = pindexLast->GetBlockTime() - pindexLast->pprev->GetBlockTime();
if (nActualSpacing < 0)
nActualSpacing = 1;
if (fTimeV2 && nActualSpacing > consensus.nTargetSpacing*10)
nActualSpacing = consensus.nTargetSpacing*10;

// ppcoin: target change every block
// ppcoin: retarget with exponential moving toward target spacing
uint256 bnNew;
bnNew.SetCompact(pindexLast->nBits);

// on first block with V2 time protocol, reduce the difficulty by a factor 16
if (fTimeV2 && !consensus.IsTimeProtocolV2(pindexLast->nHeight))
bnNew <<= 4;

int64_t nInterval = nTargetTimespan / consensus.nTargetSpacing;
bnNew *= ((nInterval - 1) * consensus.nTargetSpacing + nActualSpacing + nActualSpacing);
bnNew /= ((nInterval + 1) * consensus.nTargetSpacing);

if (bnNew <= 0 || bnNew > bnTargetLimit)
bnNew = bnTargetLimit;

return bnNew.GetCompact();
}

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

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

if (LastBlockTime > 0) { // if not the first one
if (LastBlockTime > 0) {
int64_t Diff = (LastBlockTime - BlockReading->GetBlockTime());
nActualTimespan += Diff;
}
LastBlockTime = BlockReading->GetBlockTime();

if (BlockReading->pprev == NULL) { // this shouldn't happen
if (BlockReading->pprev == NULL) {
assert(BlockReading);
break;
}
BlockReading = BlockReading->pprev;
}

uint256 bnNew;
bnNew.SetCompact(pindexLast->nBits);

int64_t nTargetTimespan = PastBlocks * nTargetSpacing;
uint256 bnNew(PastDifficultyAverage);

if (nActualTimespan < nTargetTimespan / 3)
nActualTimespan = nTargetTimespan / 3;
if (nActualTimespan > nTargetTimespan * 3)
nActualTimespan = nTargetTimespan * 3;
int64_t _nTargetTimespan = CountBlocks * consensus.nTargetSpacing;

// on first block with V2 time protocol, reduce the difficulty by a factor 16
if (fTimeV2 && !consensus.IsTimeProtocolV2(pindexLast->nHeight))
bnNew <<= 4;
if (nActualTimespan < _nTargetTimespan / 3)
nActualTimespan = _nTargetTimespan / 3;
if (nActualTimespan > _nTargetTimespan * 3)
nActualTimespan = _nTargetTimespan * 3;

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

if (bnNew > consensus.powLimit) {
bnNew = consensus.powLimit;
Expand Down
2 changes: 1 addition & 1 deletion src/qt/pivx/forms/splash.ui
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@
</string>
</property>
<property name="text">
<string>VERSION 1.4.0.1</string>
<string>VERSION 1.4.1</string>
</property>
<property name="alignment">
<set>Qt::AlignTop|Qt::AlignHCenter</set>
Expand Down
4 changes: 2 additions & 2 deletions src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* network protocol versioning
*/

static const int PROTOCOL_VERSION = 70927;
static const int PROTOCOL_VERSION = 70928;

//! initial proto version, to be increased after version/verack negotiation
static const int INIT_PROTO_VERSION = 209;
Expand All @@ -21,7 +21,7 @@ static const int INIT_PROTO_VERSION = 209;
static const int GETHEADERS_VERSION = 70077;

//! disconnect from peers older than this proto version
static const int MIN_PEER_PROTO_VERSION_BEFORE_ENFORCEMENT = 70926;
static const int MIN_PEER_PROTO_VERSION_BEFORE_ENFORCEMENT = 70927;
static const int MIN_PEER_PROTO_VERSION_AFTER_ENFORCEMENT = PROTOCOL_VERSION;

//! masternodes older than this proto version use old strMessage format for mnannounce
Expand Down

0 comments on commit 22ed043

Please sign in to comment.