Skip to content

Commit

Permalink
Merge pull request #1 from Mullick/master
Browse files Browse the repository at this point in the history
Clean Up Attempted Roll back fix
  • Loading branch information
Mullick committed Oct 3, 2013
2 parents f31b5bc + d0a52f4 commit 4049511
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 107 deletions.
9 changes: 2 additions & 7 deletions src/checkpoints.cpp
Expand Up @@ -26,12 +26,7 @@ namespace Checkpoints
boost::assign::map_list_of
( 0, hashGenesisBlockOfficial )
( 10000, uint256("0x00000000e10b86df1661adddae0037d2f120a496e667e10ebba5836043b843ee"))
( 20000, uint256("0x00000000fdde5ff56cf619c993640701681b3ba6699913d4ab9b67d7c8511abd"))
( 30000, uint256("0x000000002d4fd94c4a03843db4a0d1c74bedb516a8b00012203349dcca44c822"))
( 40000, uint256("0x00000000aac1de6db3746877bf18c9fc91e955c23644d8dec1a7284f99859390"))
( 50000, uint256("0x00000000870f44afba14190d06e5f3ac0a65c85718761b25b22cced0b6dd53aa"))
( 70000, uint256("0x00000000200ca81c63b4726c29e45cc2c2015a7498afa7b8405ddb97ac23370a"))
( 85000, uint256("0x000000004c976873bee5190e5efeb044447abe66255c8212ed265f72305c11cb"))
( 105003, uint256("0x0000000063981b611290df911aacd4a563008781050a9f4dea4b4987bacbd26b"))
;

static MapCheckpoints mapCheckpointsTestnet =
Expand Down Expand Up @@ -370,7 +365,7 @@ namespace Checkpoints
}

// ppcoin: sync-checkpoint master key
const std::string CSyncCheckpoint::strMasterPubKey = "0400cab128b9f39a3eaa888aa7777644fa1808662195edcf2d4671b1cce76868b7f2f588a9dfad5753be3cd6b8e9518be439c936e2bad93a25bb6d32300fab41c3";
const std::string CSyncCheckpoint::strMasterPubKey = "0410c0ba75d801eab7fb95d571cb8458318be18ca0139e5a6c836b044e030e6b7d1a4953220ab348e9c9c790e8f175312797ac8e09831ea5b31350dde58bbe2595";

std::string CSyncCheckpoint::strMasterPrivKey = "";

Expand Down
1 change: 1 addition & 0 deletions src/kernel.cpp
Expand Up @@ -20,6 +20,7 @@ unsigned int nModifierInterval = MODIFIER_INTERVAL;
static std::map<int, unsigned int> mapStakeModifierCheckpoints =
boost::assign::map_list_of
( 0, 0x0e00670bu )
( 105003, 0x9dfdaf60u )
;

// Get the last stake modifier and its generation time from a given block
Expand Down
131 changes: 92 additions & 39 deletions src/main.cpp
Expand Up @@ -14,8 +14,7 @@
#include <boost/algorithm/string/replace.hpp>
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/uniform_int_distribution.hpp>


using namespace std;
using namespace boost;
Expand All @@ -42,8 +41,8 @@ static CBigNum bnProofOfStakeLimit(~uint256(0) >> 20);
static CBigNum bnProofOfWorkLimitTestNet(~uint256(0) >> 16);
static CBigNum bnProofOfStakeLimitTestNet(~uint256(0) >> 20);

unsigned int nStakeMinAge = 60 * 60 * 24 * 30; // minimum age for coin age: 7d
unsigned int nStakeMaxAge = 60 * 60 * 24 * 60; // stake age of full weight: 30d
unsigned int nStakeMinAge = 60 * 60 * 24 * 30; // minimum age for coin age: 30d
unsigned int nStakeMaxAge = 60 * 60 * 24 * 60; // stake age of full weight: 60d
unsigned int nStakeTargetSpacing = 30; // 30 sec block spacing

int64 nChainStartTime = 1376792367;
Expand Down Expand Up @@ -936,17 +935,8 @@ uint256 WantedByOrphan(const CBlock* pblockOrphan)
}



int generateMTRandom(unsigned int s, int range)
{
random::mt19937 gen(s);
random::uniform_int_distribution<> dist(1, range);
return dist(gen);
}


// miner's coin base reward based on nBits
int64 GetProofOfWorkReward(int nHeight, int64 nFees, uint256 prevHash)
int64 GetProofOfWorkReward(unsigned int nHeight)
{
int64 nSubsidy = 0 * COIN;

Expand All @@ -957,14 +947,14 @@ int64 GetProofOfWorkReward(int nHeight, int64 nFees, uint256 prevHash)

nSubsidy >>= (nHeight / 100000);

return nSubsidy + nFees;
return nSubsidy;
}

// miner's coin stake reward based on nBits and coin age spent (coin-days)
int64 GetProofOfStakeReward(int64 nCoinAge, unsigned int nBits, unsigned int nTime)
{
int64 nRewardCoinYear;

{
CBigNum bnRewardCoinYearLimit = MAX_MINT_PROOF_OF_STAKE; // Base stake mint rate, 100% year interest
CBigNum bnTarget;
bnTarget.SetCompact(nBits);
Expand Down Expand Up @@ -993,25 +983,33 @@ int64 GetProofOfStakeReward(int64 nCoinAge, unsigned int nBits, unsigned int nTi
}

nRewardCoinYear = bnUpperBound.getuint64();
nRewardCoinYear = min((nRewardCoinYear / CENT) * CENT, MAX_MINT_PROOF_OF_STAKE);

if (nTime > REWARD_FIX_SWITCH_TIME)
nRewardCoinYear = min(nRewardCoinYear, MAX_MINT_PROOF_OF_STAKE);
else
nRewardCoinYear = min((nRewardCoinYear / CENT) * CENT, MAX_MINT_PROOF_OF_STAKE);
}


int64 nSubsidy = nCoinAge * 33 / (365 * 33 + 8) * nRewardCoinYear;

if (nTime > REWARD_FIX_SWITCH_TIME)
nSubsidy = (nCoinAge * 33 * nRewardCoinYear) / (365 * 33 + 8) ;
else
nSubsidy = nCoinAge * 33 / (365 * 33 + 8) * nRewardCoinYear;

if (fDebug && GetBoolArg("-printcreation"))
printf("GetProofOfStakeReward(): create=%s nCoinAge=%"PRI64d" nBits=%d\n", FormatMoney(nSubsidy).c_str(), nCoinAge, nBits);
return nSubsidy;
}

static const int64 nTargetTimespan = 15 * 60; // 15 mins
static const int64 nTargetTimespan = 15 * 60; // 15 minutes
static const int64 nTargetSpacingWorkMax = 12 * nStakeTargetSpacing; // 6 mins

// maximum nBits value could possible be required nTime after
//
// minimum amount of work that could possibly be required nTime after
// minimum work required was nBase
//
unsigned int ComputeMinWork(unsigned int nBase, int64 nTime)
unsigned int ComputeMaxBits(CBigNum bnTargetLimit, unsigned int nBase, int64 nTime)
{
CBigNum bnTargetLimit = bnProofOfWorkLimit;

CBigNum bnResult;
bnResult.SetCompact(nBase);
bnResult *= 2;
Expand All @@ -1026,6 +1024,26 @@ unsigned int ComputeMinWork(unsigned int nBase, int64 nTime)
return bnResult.GetCompact();
}

//
// minimum amount of work that could possibly be required nTime after
// minimum proof-of-work required was nBase
//
unsigned int ComputeMinWork(unsigned int nBase, int64 nTime)
{
return ComputeMaxBits(bnProofOfWorkLimit, nBase, nTime);
}

//
// minimum amount of stake that could possibly be required nTime after
// minimum proof-of-stake required was nBase
//
unsigned int ComputeMinStake(unsigned int nBase, int64 nTime, unsigned int nBlockTime)
{
return ComputeMaxBits(bnProofOfStakeLimit, nBase, nTime);
}



// ppcoin: find last block index up to pindex
const CBlockIndex* GetLastBlockIndex(const CBlockIndex* pindex, bool fProofOfStake)
{
Expand All @@ -1034,9 +1052,9 @@ const CBlockIndex* GetLastBlockIndex(const CBlockIndex* pindex, bool fProofOfSta
return pindex;
}

unsigned int static GetNextTargetRequired(const CBlockIndex* pindexLast, bool fProofOfStake)
unsigned int GetNextTargetRequired(const CBlockIndex* pindexLast, bool fProofOfStake)
{
CBigNum bnTargetLimit = bnProofOfWorkLimit;
CBigNum bnTargetLimit = !fProofOfStake ? bnProofOfWorkLimit : bnProofOfStakeLimit;

if(fProofOfStake)
{
Expand Down Expand Up @@ -1583,15 +1601,6 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck)
return error("ConnectBlock() : UpdateTxIndex failed");
}

uint256 prevHash = 0;
if(pindex->pprev)
{
prevHash = pindex->pprev->GetBlockHash();
// printf("==> Got prevHash = %s\n", prevHash.ToString().c_str());
}

if (vtx[0].GetValueOut() > GetProofOfWorkReward(pindex->nHeight, nFees, prevHash))
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 @@ -2034,7 +2043,7 @@ bool CBlock::CheckBlock(bool fCheckPOW, bool fCheckMerkleRoot) const
// Check coinstake timestamp
if (IsProofOfStake() && !CheckCoinStakeTimestamp(GetBlockTime(), (int64)vtx[1].nTime))
return DoS(50, error("CheckBlock() : coinstake timestamp violation nTimeBlock=%"PRI64d" nTimeTx=%u", GetBlockTime(), vtx[1].nTime));

// Check transactions
BOOST_FOREACH(const CTransaction& tx, vtx)
{
Expand Down Expand Up @@ -2166,6 +2175,26 @@ bool CBlockIndex::IsSuperMajority(int minVersion, const CBlockIndex* pstart, uns
return (nFound >= nRequired);
}

CBigNum CBlockIndex::GetBlockTrust() const
{
CBigNum bnTarget;
bnTarget.SetCompact(nBits);
if (bnTarget <= 0)
return 0;

if (IsProofOfStake())
{
// Return trust score as usual
return (CBigNum(1)<<256) / (bnTarget+1);
}
else
{
// Calculate work amount for block
CBigNum bnPoWTrust = (bnProofOfWorkLimit / (bnTarget+1));
return bnPoWTrust > 1 ? bnPoWTrust : 1;
}
}

bool ProcessBlock(CNode* pfrom, CBlock* pblock)
{
// Check for duplicate
Expand Down Expand Up @@ -2206,7 +2235,12 @@ bool ProcessBlock(CNode* pfrom, CBlock* pblock)
CBigNum bnNewBlock;
bnNewBlock.SetCompact(pblock->nBits);
CBigNum bnRequired;
bnRequired.SetCompact(ComputeMinWork(GetLastBlockIndex(pcheckpoint, pblock->IsProofOfStake())->nBits, deltaTime));

if (pblock->IsProofOfStake())
bnRequired.SetCompact(ComputeMinStake(GetLastBlockIndex(pcheckpoint, true)->nBits, deltaTime, pblock->nTime));
else
bnRequired.SetCompact(ComputeMinWork(GetLastBlockIndex(pcheckpoint, false)->nBits, deltaTime));

if (bnNewBlock > bnRequired)
{
if (pfrom)
Expand Down Expand Up @@ -2511,7 +2545,7 @@ bool LoadBlockIndex(bool fAllowNew)
block.nBits = bnProofOfWorkLimit.GetCompact();
block.nNonce = 93364;

if (true && (block.GetHash() != hashGenesisBlock)) {
if (false && (block.GetHash() != hashGenesisBlock)) {

// This will figure out a valid hash and Nonce if you're
// creating a different genesis block:
Expand Down Expand Up @@ -2858,6 +2892,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
CAddress addrMe;
CAddress addrFrom;
uint64 nNonce = 1;
bool badVersion = false;
vRecv >> pfrom->nVersion >> pfrom->nServices >> nTime >> addrMe;
if (pfrom->nVersion < MIN_PROTO_VERSION)
{
Expand All @@ -2867,6 +2902,24 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
pfrom->fDisconnect = true;
return false;
}


if(nTime < 1380974400)
{
if(pfrom->nVersion < 60000)
badVersion = true;
}
else
{
if(pfrom->nVersion < 70000)
badVersion = true;
}
if(badVersion)
{
printf("partner %s using obsolete version %i; disconnecting\n", pfrom->addr.ToString().c_str(), pfrom->nVersion);
pfrom->fDisconnect = true;
return false;
}

if (pfrom->nVersion == 10300)
pfrom->nVersion = 300;
Expand Down Expand Up @@ -4142,7 +4195,7 @@ CBlock* CreateNewBlock(CWallet* pwallet, bool fProofOfStake)
printf("CreateNewBlock(): total size %"PRI64u"\n", nBlockSize);

if (pblock->IsProofOfWork())
pblock->vtx[0].vout[0].nValue = GetProofOfWorkReward(pindexPrev->nHeight+1, nFees, pindexPrev->GetBlockHash());
pblock->vtx[0].vout[0].nValue = GetProofOfWorkReward(pindexPrev->nHeight+1);

// Fill in header
pblock->hashPrevBlock = pindexPrev->GetBlockHash();
Expand Down
15 changes: 6 additions & 9 deletions src/main.h
Expand Up @@ -40,6 +40,8 @@ static const int64 MAX_MINT_PROOF_OF_STAKE = 0.1 * CENT;

static const int64 MIN_TXOUT_AMOUNT = MIN_TX_FEE;

static const unsigned int REWARD_FIX_SWITCH_TIME = 1381363200; // 10 Oct 2013 00:00:00

inline bool MoneyRange(int64 nValue) { return (nValue >= 0 && nValue <= MAX_MONEY); }
// Threshold for nLockTime: below this value it is interpreted as block number, otherwise as UNIX timestamp.
static const unsigned int LOCKTIME_THRESHOLD = 500000000; // Tue Nov 5 00:53:20 1985 UTC
Expand Down Expand Up @@ -113,9 +115,10 @@ void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int&
void FormatHashBuffers(CBlock* pblock, char* pmidstate, char* pdata, char* phash1);
bool CheckWork(CBlock* pblock, CWallet& wallet, CReserveKey& reservekey);
bool CheckProofOfWork(uint256 hash, unsigned int nBits);
int64 GetProofOfWorkReward(int nHeight, int64 nFees, uint256 prevHash);
int64 GetProofOfWorkReward(unsigned int nBits);
int64 GetProofOfStakeReward(int64 nCoinAge, unsigned int nBits, unsigned int nTime);
unsigned int ComputeMinWork(unsigned int nBase, int64 nTime);
unsigned int ComputeMinStake(unsigned int nBase, int64 nTime, unsigned int nBlockTime);
int GetNumBlocksOfPeers();
bool IsInitialBlockDownload();
std::string GetWarnings(std::string strFor);
Expand Down Expand Up @@ -1239,14 +1242,8 @@ class CBlockIndex
return (int64)nTime;
}

CBigNum GetBlockTrust() const
{
CBigNum bnTarget;
bnTarget.SetCompact(nBits);
if (bnTarget <= 0)
return 0;
return (IsProofOfStake()? (CBigNum(1)<<256) / (bnTarget+1) : 1);
}
CBigNum GetBlockTrust() const;


bool IsInMainChain() const
{
Expand Down
8 changes: 4 additions & 4 deletions src/qt/forms/overviewpage.ui
Expand Up @@ -105,7 +105,7 @@
<string>Your current balance</string>
</property>
<property name="text">
<string notr="true">0 STR</string>
<string notr="true">0 ADT</string>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
Expand Down Expand Up @@ -134,7 +134,7 @@
<string>Total of coins that was staked, and do not yet count toward the current balance</string>
</property>
<property name="text">
<string notr="true">0 STR</string>
<string notr="true">0 ADT</string>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
Expand Down Expand Up @@ -163,7 +163,7 @@
<string>Total of transactions that have yet to be confirmed, and do not yet count toward the current balance</string>
</property>
<property name="text">
<string notr="true">0 STR</string>
<string notr="true">0 ADT</string>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
Expand All @@ -189,7 +189,7 @@
<string>Mined balance that has not yet matured</string>
</property>
<property name="text">
<string notr="true">0 STR</string>
<string notr="true">0 ADT</string>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
Expand Down
2 changes: 1 addition & 1 deletion src/qt/forms/sendcoinsdialog.ui
Expand Up @@ -149,7 +149,7 @@
<cursorShape>IBeamCursor</cursorShape>
</property>
<property name="text">
<string>123.456 STR</string>
<string>123.456 ADT</string>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
Expand Down

0 comments on commit 4049511

Please sign in to comment.