From 4f6b3161b2dc18c9a3d4143d63fbbd0737296eb0 Mon Sep 17 00:00:00 2001 From: Sunny King Date: Sun, 16 Sep 2012 15:53:17 +0100 Subject: [PATCH] PPCoin: Track coinstake search interval in RPC command 'getdifficulty' --- src/bitcoinrpc.cpp | 1 + src/main.cpp | 13 +++++++++---- src/main.h | 1 + src/wallet.cpp | 4 ++-- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 3e32295..63375fe 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -288,6 +288,7 @@ Value getdifficulty(const Array& params, bool fHelp) Object obj; obj.push_back(Pair("proof-of-work", GetDifficulty())); obj.push_back(Pair("proof-of-stake", GetDifficulty(GetLastBlockIndex(pindexBest, true)))); + obj.push_back(Pair("search-interval", (int)nLastCoinStakeSearchInterval)); return obj; } diff --git a/src/main.cpp b/src/main.cpp index 2d5ee04..cb85469 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3598,6 +3598,7 @@ public: uint64 nLastBlockTx = 0; uint64 nLastBlockSize = 0; +int64 nLastCoinStakeSearchInterval = 0; // CreateNewBlock: // fProofOfStake: try (best effort) to make a proof-of-stake block @@ -3629,12 +3630,16 @@ CBlock* CreateNewBlock(CWallet* pwallet, bool fProofOfStake) pblock->nBits = GetNextTargetRequired(pindexPrev, true); CTransaction txCoinStake; int64 nSearchTime = GetAdjustedTime(); - if (pwallet->CreateCoinStake(*pwallet, pblock->nBits, nSearchTime-nLastCoinStakeSearchTime, txCoinStake)) + if (nSearchTime > nLastCoinStakeSearchTime) { - pblock->vtx.push_back(txCoinStake); - pblock->vtx[0].vout[0].SetEmpty(); + if (pwallet->CreateCoinStake(*pwallet, pblock->nBits, nSearchTime-nLastCoinStakeSearchTime, txCoinStake)) + { + pblock->vtx.push_back(txCoinStake); + pblock->vtx[0].vout[0].SetEmpty(); + } + nLastCoinStakeSearchInterval = nSearchTime - nLastCoinStakeSearchTime; + nLastCoinStakeSearchTime = nSearchTime; } - nLastCoinStakeSearchTime = nSearchTime; } pblock->nBits = GetNextTargetRequired(pindexPrev, pblock->IsProofOfStake()); diff --git a/src/main.h b/src/main.h index ab4026a..2cde696 100644 --- a/src/main.h +++ b/src/main.h @@ -72,6 +72,7 @@ extern CBlockIndex* pindexBest; extern unsigned int nTransactionsUpdated; extern uint64 nLastBlockTx; extern uint64 nLastBlockSize; +extern int64 nLastCoinStakeSearchInterval; extern const std::string strMessageMagic; extern double dHashesPerSec; extern int64 nHPSTimerStart; diff --git a/src/wallet.cpp b/src/wallet.cpp index de203bc..be75141 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -1254,7 +1254,7 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int CBigNum bnCoinDay = CBigNum(nValueIn) * min(txNew.nTime-pcoin.first->nTime, (unsigned int)STAKE_MAX_AGE) / COIN / (24 * 60 * 60); bool fKernelFound = false; - for (int n=0; n<5 && !fKernelFound; n++) + for (int n=0; n nBalance - nReserveBalance) -- 1.7.1