Skip to content

Commit

Permalink
Multiple Changes for Hard Fork
Browse files Browse the repository at this point in the history
PastDrift and FutureDrift will only allow 15 mins.
GetStakeMin/MaxAge will take nTime parm for fork switch
nCoinbaseMaturityMultipiler changed to 4,000
Added Checkpoints
  • Loading branch information
Tranz5 committed Jun 1, 2014
1 parent 1461f28 commit 8ee2471
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 28 deletions.
5 changes: 2 additions & 3 deletions src/checkpoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ namespace Checkpoints
( 48000, uint256("0x00000000118a5a2e08bdd44410dcd4ff9a89d70d8a080e5e502cc72840af5021"))
( 136822, uint256("0x0000000013cee700df4937ad60f2de34ac48f95e36471f259f5b1e8a3421764b"))
( 339056, uint256("0x0000000179b03ebb5b11e0c56cd75a9e11467a4a6c591888955de25828171685"))


( 477014, uint256("0x000000001d39ad6c2e61c4d62e823cf521e6e62cc0dcffd3af1c12e2fd6bd283"))
;

static MapCheckpoints mapCheckpointsTestnet =
Expand Down Expand Up @@ -353,7 +352,7 @@ namespace Checkpoints
assert(mapBlockIndex.count(hashSyncCheckpoint));
const CBlockIndex* pindexSync = mapBlockIndex[hashSyncCheckpoint];
return (nBestHeight >= pindexSync->nHeight + nCoinbaseMaturity ||
pindexSync->GetBlockTime() + GetStakeMinAge() < GetAdjustedTime());
pindexSync->GetBlockTime() + GetStakeMinAge(pindexSync->GetBlockTime()) < GetAdjustedTime());

}

Expand Down
17 changes: 10 additions & 7 deletions src/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ static std::map<int, unsigned int> mapStakeModifierCheckpoints =
( 0, 0x0e00670bu )
( 48000, 0x8274b4fcu )
( 136822, 0xaafc7a2du )
( 477014, 0xd36de126 )


;

// Get time weight
Expand All @@ -31,10 +34,10 @@ int64 GetWeight(int64 nIntervalBeginning, int64 nIntervalEnd)
// this change increases active coins participating the hash and helps
// to secure the network when proof-of-stake difficulty is low

if ( GetAdjustedTime() > VERSION2_SWITCH_TIME )
return min(nIntervalEnd - nIntervalBeginning - GetStakeMinAge(), (int64)GetStakeMaxAge());
if ( nIntervalEnd > VERSION2_SWITCH_TIME )
return min(nIntervalEnd - nIntervalBeginning - GetStakeMinAge(nIntervalEnd), (int64)GetStakeMaxAge(nIntervalEnd));
else
return min(nIntervalEnd - nIntervalBeginning, (int64)GetStakeMaxAge()) - GetStakeMinAge();
return min(nIntervalEnd - nIntervalBeginning, (int64)GetStakeMaxAge(nIntervalEnd)) - GetStakeMinAge(nIntervalEnd);
}

// Get the last stake modifier and its generation time from a given block
Expand Down Expand Up @@ -234,7 +237,7 @@ static bool GetKernelStakeModifier(uint256 hashBlockFrom, uint64& nStakeModifier
{
if (!pindex->pnext)
{ // reached best block; may happen if node is behind on block chain
if (fPrintProofOfStake || (pindex->GetBlockTime() + GetStakeMinAge() - nStakeModifierSelectionInterval > GetAdjustedTime()))
if (fPrintProofOfStake || (pindex->GetBlockTime() + GetStakeMinAge(pindex->GetBlockTime()) - nStakeModifierSelectionInterval > GetAdjustedTime()))
return error("GetKernelStakeModifier() : reached best block %s at height %d from block %s",
pindex->GetBlockHash().ToString().c_str(), pindex->nHeight, hashBlockFrom.ToString().c_str());
else
Expand Down Expand Up @@ -281,7 +284,7 @@ bool CheckStakeKernelHash(unsigned int nBits, const CBlock& blockFrom, unsigned

unsigned int nTimeBlockFrom = blockFrom.GetBlockTime();

if (nTimeBlockFrom + GetStakeMinAge() > nTimeTx) // Min age requirement
if (nTimeBlockFrom + GetStakeMinAge(nTimeTx) > nTimeTx) // Min age requirement
return error("CheckStakeKernelHash() : min age violation");

CBigNum bnTargetPerCoinDay;
Expand All @@ -296,9 +299,9 @@ bool CheckStakeKernelHash(unsigned int nBits, const CBlock& blockFrom, unsigned
// to secure the network when proof-of-stake difficulty is low

if (nTimeTx > VERSION2_SWITCH_TIME)
nTimeWeight = min((int64)nTimeTx - txPrev.nTime - GetStakeMinAge(), (int64)GetStakeMaxAge());
nTimeWeight = min((int64)nTimeTx - txPrev.nTime - GetStakeMinAge(nTimeTx), (int64)GetStakeMaxAge(nTimeTx));
else
nTimeWeight = min((int64)nTimeTx - txPrev.nTime, (int64)GetStakeMaxAge()) - GetStakeMinAge();
nTimeWeight = min((int64)nTimeTx - txPrev.nTime, (int64)GetStakeMaxAge(nTimeTx)) - GetStakeMinAge(nTimeTx);

CBigNum bnCoinDayWeight = CBigNum(nValueIn) * nTimeWeight / COIN / (24 * 60 * 60);
targetProofOfStake = CBigNum(bnCoinDayWeight * bnTargetPerCoinDay).getuint256();
Expand Down
17 changes: 8 additions & 9 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ unsigned int nStakeMaxAgeV2 = 60 * 60 * 24 * 45; // stake age of full weight
unsigned int nStakeTargetSpacing = 1 * 60; // 1-minute block spacing
int64 nChainStartTime = 1371910049;
int nCoinbaseMaturity = 5;
//Tranz This will need changed after fork to 15 days
int nCoinbaseMaturityMultipiler = 8000;
int nCoinbaseMaturityMultipiler = 4000;
CBlockIndex* pindexGenesisBlock = NULL;
int nBestHeight = -1;
CBigNum bnBestChainTrust = 0;
Expand Down Expand Up @@ -1097,17 +1096,17 @@ int64 GetProofOfStakeRewardV2(int64 nCoinAge, unsigned int nBits, unsigned int n
return nSubsidy;
}

unsigned int GetStakeMinAge()
unsigned int GetStakeMinAge(unsigned int nTime)
{
if (GetAdjustedTime() > VERSION2_SWITCH_TIME)
if (nTime > VERSION2_SWITCH_TIME)
return nStakeMinAgeV2;
else
return nStakeMinAge;
}

unsigned int GetStakeMaxAge()
unsigned int GetStakeMaxAge(unsigned int nTime)
{
if (GetAdjustedTime() > VERSION2_SWITCH_TIME)
if (nTime > VERSION2_SWITCH_TIME)
return nStakeMaxAgeV2;
else
return nStakeMaxAge;
Expand Down Expand Up @@ -1226,7 +1225,7 @@ unsigned int GetNextTargetRequiredV2(const CBlockIndex* pindexLast, bool fProofO

unsigned int GetNextTargetRequired(const CBlockIndex* pindexLast, bool fProofOfStake)
{
if (GetAdjustedTime() > VERSION2_SWITCH_TIME)
if (pindexLast->nTime > VERSION2_SWITCH_TIME)
return GetNextTargetRequiredV2(pindexLast, fProofOfStake);
else
return GetNextTargetRequiredV1(pindexLast, fProofOfStake);
Expand Down Expand Up @@ -2035,7 +2034,7 @@ bool CTransaction::GetCoinAge(CTxDB& txdb, uint64& nCoinAge) const
CBlock block;
if (!block.ReadFromDisk(txindex.pos.nFile, txindex.pos.nBlockPos, false))
return false; // unable to read block of previous transaction
if (block.GetBlockTime() + GetStakeMinAge() > nTime)
if (block.GetBlockTime() + GetStakeMinAge(nTime) > nTime)
continue; // only count coins meeting min age requirement

int64 nValueIn = txPrev.vout[txin.prevout.n].nValue;
Expand Down Expand Up @@ -3467,7 +3466,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
printf(" getblocks stopping at %d %s\n", pindex->nHeight, pindex->GetBlockHash().ToString().substr(0,20).c_str());
// ppcoin: tell downloading node about the latest block if it's
// without risk being rejected due to stake connection check
if (hashStop != hashBestChain && pindex->GetBlockTime() + GetStakeMinAge() > pindexBest->GetBlockTime())
if (hashStop != hashBestChain && pindex->GetBlockTime() + GetStakeMinAge(pindex->GetBlockTime()) > pindexBest->GetBlockTime())
pfrom->PushInventory(CInv(MSG_BLOCK, hashBestChain));
break;
}
Expand Down
24 changes: 20 additions & 4 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ static const unsigned int VERSION2_SWITCH_TIME = 1404457454; // Fri, 04 Jul 2014






static const int64 MIN_TXOUT_AMOUNT = MIN_TX_FEE;
static const unsigned int PROTOCOL_SWITCH_TIME = 1371686400; // 20 Jun 2013 00:00:00

Expand All @@ -63,8 +66,21 @@ static const int fHaveUPnP = false;
static const uint256 hashGenesisBlockOfficial("0xb70be2c6d7f6dfbb7cc874a6009b14e267b0e0ecb2e725152dd785829216dadd");
static const uint256 hashGenesisBlockTestNet("0x");

inline int64 PastDrift(int64 nTime) { return nTime - 2 * 60 * 60; } // up to 2 hours from the past
inline int64 FutureDrift(int64 nTime) { return nTime + 2 * 60 * 60; } // up to 2 hours from the future
inline int64 PastDrift(int64 nTime)
{
if (nTime > VERSION2_SWITCH_TIME)
return nTime - 15 * 60; // up to 15 minutes from the past
else
return nTime - 2 * 60 * 60; // up to 120 minutes from the past
}

inline int64 FutureDrift(int64 nTime)
{
if (nTime > VERSION2_SWITCH_TIME)
return nTime + 15 * 60; // up to 15 minutes from the future
else
return nTime + 2 * 60 * 60; // up to 120 minutes from the future
}

extern CScript COINBASE_FLAGS;

Expand Down Expand Up @@ -132,8 +148,8 @@ int64 GetProofOfWorkReward(unsigned int nBits);
int64 GetProofOfStakeReward(int64 nCoinAge, unsigned int nBits, unsigned int nTime, bool bCoinYearOnly=false);
int64 GetProofOfStakeRewardV1(int64 nCoinAge, unsigned int nBits, unsigned int nTime, bool bCoinYearOnly=false);
int64 GetProofOfStakeRewardV2(int64 nCoinAge, unsigned int nBits, unsigned int nTime, bool bCoinYearOnly=false);
unsigned int GetStakeMinAge();
unsigned int GetStakeMaxAge();
unsigned int GetStakeMinAge(unsigned int nTime);
unsigned int GetStakeMaxAge(unsigned int nTime);

unsigned int ComputeMinWork(unsigned int nBase, int64 nTime);
unsigned int ComputeMinStake(unsigned int nBase, int64 nTime, unsigned int nBlockTime);
Expand Down
12 changes: 7 additions & 5 deletions src/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1556,6 +1556,7 @@ bool CWallet::GetStakeWeight(const CKeyStore& keystore, uint64& nMinWeight, uint
int64 nBalance = GetBalance();
int64 nReserveBalance = 0;


if (mapArgs.count("-reservebalance") && !ParseMoney(mapArgs["-reservebalance"], nReserveBalance))
{
error("GetStakeWeight : invalid reserve balance amount");
Expand Down Expand Up @@ -1586,7 +1587,8 @@ bool CWallet::GetStakeWeight(const CKeyStore& keystore, uint64& nMinWeight, uint
continue;
}

int64 nTimeWeight = GetWeight((int64)pcoin.first->nTime, (int64)GetTime());
int64 nPcoinTime = pcoin.first->nTime;
int64 nTimeWeight = GetWeight(nPcoinTime, (int64)GetTime());
CBigNum bnCoinDayWeight = CBigNum(pcoin.first->vout[pcoin.second].nValue) * nTimeWeight / COIN / (24 * 60 * 60);

// Weight is greater than zero
Expand All @@ -1596,13 +1598,13 @@ bool CWallet::GetStakeWeight(const CKeyStore& keystore, uint64& nMinWeight, uint
}

// Weight is greater than zero, but the maximum value isn't reached yet
if (nTimeWeight > 0 && nTimeWeight < GetStakeMaxAge())
if (nTimeWeight > 0 && nTimeWeight < GetStakeMaxAge(nPcoinTime))
{
nMinWeight += bnCoinDayWeight.getuint64();
}

// Maximum weight was reached
if (nTimeWeight == GetStakeMaxAge())
if (nTimeWeight == GetStakeMaxAge(nPcoinTime))
{
nMaxWeight += bnCoinDayWeight.getuint64();
}
Expand Down Expand Up @@ -1670,7 +1672,7 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int
}

static int nMaxStakeSearchInterval = 60;
if (block.GetBlockTime() + GetStakeMinAge() > txNew.nTime - nMaxStakeSearchInterval)
if (block.GetBlockTime() + GetStakeMinAge(block.GetBlockTime()) > txNew.nTime - nMaxStakeSearchInterval)
continue; // only count coins meeting min age requirement

bool fKernelFound = false;
Expand Down Expand Up @@ -1774,7 +1776,7 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int
if (pcoin.first->vout[pcoin.second].nValue > nCombineThreshold)
continue;
// Do not add input that is still too young
if (pcoin.first->nTime + GetStakeMaxAge() > txNew.nTime)
if (pcoin.first->nTime + GetStakeMaxAge(pcoin.first->nTime) > txNew.nTime)
continue;
txNew.vin.push_back(CTxIn(pcoin.first->GetHash(), pcoin.second));
nCredit += pcoin.first->vout[pcoin.second].nValue;
Expand Down

0 comments on commit 8ee2471

Please sign in to comment.