// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
-#include "txdb.h"
+#include "txdb-leveldb.h"
#include "miner.h"
#include "kernel.h"
#include "kernel_worker.h"
-using namespace std;
//////////////////////////////////////////////////////////////////////////////
//
{
public:
CTransaction* ptx;
- set<uint256> setDependsOn;
+ std::set<uint256> setDependsOn;
double dPriority;
double dFeePerKb;
ptx = ptxIn;
dPriority = dFeePerKb = 0;
}
-
- void print() const
- {
- printf("COrphan(hash=%s, dPriority=%.1f, dFeePerKb=%.1f)\n",
- ptx->GetHash().ToString().substr(0,10).c_str(), dPriority, dFeePerKb);
- BOOST_FOREACH(uint256 hash, setDependsOn)
- printf(" setDependsOn %s\n", hash.ToString().substr(0,10).c_str());
- }
};
uint32_t nLastCoinStakeSearchInterval = 0;
// We want to sort transactions by priority and fee, so:
-typedef boost::tuple<double, double, CTransaction*> TxPriority;
+typedef std::tuple<double, double, CTransaction*> TxPriority;
class TxPriorityCompare
{
bool byFee;
{
if (byFee)
{
- if (a.get<1>() == b.get<1>())
- return a.get<0>() < b.get<0>();
- return a.get<1>() < b.get<1>();
+ if (std::get<1>(a) == std::get<1>(b))
+ return std::get<0>(a) < std::get<0>(b);
+ return std::get<1>(a) < std::get<1>(b);
}
else
{
- if (a.get<0>() == b.get<0>())
- return a.get<1>() < b.get<1>();
- return a.get<0>() < b.get<0>();
+ if (std::get<0>(a) == std::get<0>(b))
+ return std::get<1>(a) < std::get<1>(b);
+ return std::get<0>(a) < std::get<0>(b);
}
}
};
// CreateNewBlock: create new block (without proof-of-work/with provided coinstake)
-CBlock* CreateNewBlock(CWallet* pwallet, CTransaction *txCoinStake)
+std::shared_ptr<CBlock> CreateNewBlock(CWallet* pwallet, CTransaction *txCoinStake)
{
- bool fProofOfStake = txCoinStake != NULL;
+ bool fProofOfStake = txCoinStake != nullptr;
// Create new block
- auto_ptr<CBlock> pblock(new CBlock());
+ std::shared_ptr<CBlock> pblock(new CBlock());
if (!pblock.get())
- return NULL;
+ return nullptr;
// Create coinbase tx
CTransaction txCoinBase;
}
// Largest block you're willing to create:
- unsigned int nBlockMaxSize = GetArg("-blockmaxsize", MAX_BLOCK_SIZE_GEN/2);
+ unsigned int nBlockMaxSize = GetArgUInt("-blockmaxsize", MAX_BLOCK_SIZE_GEN/2);
// Limit to betweeen 1K and MAX_BLOCK_SIZE-1K for sanity:
- nBlockMaxSize = std::max((unsigned int)1000, std::min((unsigned int)(MAX_BLOCK_SIZE-1000), nBlockMaxSize));
+ nBlockMaxSize = std::max(1000u, std::min(MAX_BLOCK_SIZE-1000u, nBlockMaxSize));
// How much of the block should be dedicated to high-priority transactions,
// included regardless of the fees they pay
- unsigned int nBlockPrioritySize = GetArg("-blockprioritysize", 27000);
+ unsigned int nBlockPrioritySize = GetArgUInt("-blockprioritysize", 27000);
nBlockPrioritySize = std::min(nBlockMaxSize, nBlockPrioritySize);
// Minimum block size you want to create; block will be filled with free transactions
// until there are no more or the block reaches this size:
- unsigned int nBlockMinSize = GetArg("-blockminsize", 0);
+ unsigned int nBlockMinSize = GetArgUInt("-blockminsize", 0);
nBlockMinSize = std::min(nBlockMaxSize, nBlockMinSize);
// Fee-per-kilobyte amount considered the same as "free"
// 1-satoshi-fee transactions. It should be set above the real
// cost to you of processing a transaction.
int64_t nMinTxFee = MIN_TX_FEE;
- if (mapArgs.count("-mintxfee"))
- ParseMoney(mapArgs["-mintxfee"], nMinTxFee);
+ if (mapArgs.count("-mintxfee")) {
+ bool fResult = ParseMoney(mapArgs["-mintxfee"], nMinTxFee);
+ if (!fResult) // Parse error
+ nMinTxFee = MIN_TX_FEE;
+ }
CBlockIndex* pindexPrev = pindexBest;
CTxDB txdb("r");
// Priority order to process transactions
- list<COrphan> vOrphan; // list memory doesn't move
- map<uint256, vector<COrphan*> > mapDependers;
+ std::list<COrphan> vOrphan; // list memory doesn't move
+ std::map<uint256, std::vector<COrphan*> > mapDependers;
// This vector will be sorted into a priority queue:
- vector<TxPriority> vecPriority;
+ std::vector<TxPriority> vecPriority;
vecPriority.reserve(mempool.mapTx.size());
- for (map<uint256, CTransaction>::iterator mi = mempool.mapTx.begin(); mi != mempool.mapTx.end(); ++mi)
+ for (std::map<uint256, CTransaction>::iterator mi = mempool.mapTx.begin(); mi != mempool.mapTx.end(); ++mi)
{
CTransaction& tx = (*mi).second;
if (tx.IsCoinBase() || tx.IsCoinStake() || !tx.IsFinal())
continue;
- COrphan* porphan = NULL;
+ COrphan* porphan = nullptr;
double dPriority = 0;
int64_t nTotalIn = 0;
bool fMissingInputs = false;
- BOOST_FOREACH(const CTxIn& txin, tx.vin)
+ for (const CTxIn& txin : tx.vin)
{
// Read prev transaction
CTransaction txPrev;
}
// Collect transactions into block
- map<uint256, CTxIndex> mapTestPool;
+ std::map<uint256, CTxIndex> mapTestPool;
uint64_t nBlockSize = 1000;
uint64_t nBlockTx = 0;
int nBlockSigOps = 100;
while (!vecPriority.empty())
{
// Take highest priority transaction off the priority queue:
- double dPriority = vecPriority.front().get<0>();
- double dFeePerKb = vecPriority.front().get<1>();
- CTransaction& tx = *(vecPriority.front().get<2>());
+ double dPriority = std::get<0>(vecPriority.front());
+ double dFeePerKb = std::get<1>(vecPriority.front());
+ CTransaction& tx = *(std::get<2>(vecPriority.front()));
std::pop_heap(vecPriority.begin(), vecPriority.end(), comparer);
vecPriority.pop_back();
// Connecting shouldn't fail due to dependency on other memory pool transactions
// because we're already processing them in order of dependency
- map<uint256, CTxIndex> mapTestPoolTmp(mapTestPool);
+ std::map<uint256, CTxIndex> mapTestPoolTmp(mapTestPool);
MapPrevTx mapInputs;
bool fInvalid;
if (!tx.FetchInputs(txdb, mapTestPoolTmp, false, true, mapInputs, fInvalid))
uint256 hash = tx.GetHash();
if (mapDependers.count(hash))
{
- BOOST_FOREACH(COrphan* porphan, mapDependers[hash])
+ for (COrphan* porphan : mapDependers[hash])
{
if (!porphan->setDependsOn.empty())
{
pblock->hashPrevBlock = pindexPrev->GetBlockHash();
if (!fProofOfStake)
{
- pblock->nTime = max(pindexPrev->GetMedianTimePast()+1, pblock->GetMaxTransactionTime());
- pblock->nTime = max(pblock->GetBlockTime(), PastDrift(pindexPrev->GetBlockTime()));
+ pblock->nTime = std::max(pindexPrev->GetMedianTimePast()+1, pblock->GetMaxTransactionTime());
+ pblock->nTime = std::max(pblock->GetBlockTime(), PastDrift(pindexPrev->GetBlockTime()));
pblock->UpdateTime(pindexPrev);
}
pblock->nNonce = 0;
}
- return pblock.release();
+ return pblock;
}
-void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int& nExtraNonce)
+void IncrementExtraNonce(std::shared_ptr<CBlock>& pblock, CBlockIndex* pindexPrev, unsigned int& nExtraNonce)
{
// Update nExtraNonce
static uint256 hashPrevBlock;
}
-void FormatHashBuffers(CBlock* pblock, char* pmidstate, char* pdata, char* phash1)
+void FormatHashBuffers(const std::shared_ptr<CBlock>& pblock, char* pmidstate, char* pdata, char* phash1)
{
//
// Pre-build hash buffers
}
-bool CheckWork(CBlock* pblock, CWallet& wallet, CReserveKey& reservekey)
+bool CheckWork(const std::shared_ptr<CBlock>& pblock, CWallet& wallet, CReserveKey& reservekey)
{
uint256 hashBlock = pblock->GetHash();
uint256 hashTarget = CBigNum().SetCompact(pblock->nBits).getuint256();
}
// Process this block the same as if we had received it from another node
- if (!ProcessBlock(NULL, pblock))
+ if (!ProcessBlock(nullptr, pblock.get()))
return error("CheckWork() : ProcessBlock, block not accepted");
}
return true;
}
-bool CheckStake(CBlock* pblock, CWallet& wallet)
+bool CheckStake(const std::shared_ptr<CBlock>& pblock, CWallet& wallet)
{
uint256 proofHash = 0, hashTarget = 0;
uint256 hashBlock = pblock->GetHash();
}
// Process this block the same as if we had received it from another node
- if (!ProcessBlock(NULL, pblock))
+ if (!ProcessBlock(nullptr, pblock.get()))
return error("CheckStake() : ProcessBlock, block not accepted");
}
for(CoinsSet::const_iterator pcoin = setCoins.begin(); pcoin != setCoins.end(); pcoin++)
{
- pair<uint256, uint32_t> key = make_pair(pcoin->first->GetHash(), pcoin->second);
+ std::pair<uint256, uint32_t> key = {pcoin->first->GetHash(), pcoin->second};
// Skip existent inputs
if (inputsMap.find(key) != inputsMap.end())
// Trying to parse scriptPubKey
txnouttype whichType;
- vector<valtype> vSolutions;
+ std::vector<valtype> vSolutions;
if (!Solver(pcoin->first->vout[pcoin->second].scriptPubKey, whichType, vSolutions))
continue;
ssKernel << block.nTime << (txindex.pos.nTxPos - txindex.pos.nBlockPos) << pcoin->first->nTime << pcoin->second;
// (txid, vout.n) => (kernel, (tx.nTime, nAmount))
- inputsMap[key] = make_pair(std::vector<unsigned char>(ssKernel.begin(), ssKernel.end()), make_pair(pcoin->first->nTime, pcoin->first->vout[pcoin->second].nValue));
+ inputsMap[key] = {std::vector<unsigned char>(ssKernel.begin(), ssKernel.end()), {pcoin->first->nTime, pcoin->first->vout[pcoin->second].nValue}};
}
nStakeInputsMapSize = inputsMap.size();
std::pair<uint32_t, uint32_t> interval;
interval.first = nSearchTime;
- interval.second = nSearchTime - min(nSearchTime-nLastCoinStakeSearchTime, nMaxStakeSearchInterval);
+ interval.second = nSearchTime - std::min(nSearchTime-nLastCoinStakeSearchTime, nMaxStakeSearchInterval);
// (txid, nout) => (kernel, (tx.nTime, nAmount))
for(MidstateMap::const_iterator input = inputsMap.begin(); input != inputsMap.end(); input++)
// Create new coinstake transaction
if (!pwallet->CreateCoinStake(LuckyInput.first, LuckyInput.second, solution.second, nBits, txCoinStake, key))
{
- string strMessage = _("Warning: Unable to create coinstake transaction, see debug.log for the details. Mining thread has been stopped.");
+ std::string strMessage = _("Warning: Unable to create coinstake transaction, see debug.log for the details. Mining thread has been stopped.");
strMiscWarning = strMessage;
printf("*** %s\n", strMessage.c_str());
}
// Now we have new coinstake, it's time to create the block ...
- CBlock* pblock;
- pblock = CreateNewBlock(pwallet, &txCoinStake);
+ std::shared_ptr<CBlock> pblock = CreateNewBlock(pwallet, &txCoinStake);
if (!pblock)
{
- string strMessage = _("Warning: Unable to allocate memory for the new block object. Mining thread has been stopped.");
+ std::string strMessage = _("Warning: Unable to allocate memory for the new block object. Mining thread has been stopped.");
strMiscWarning = strMessage;
printf("*** %s\n", strMessage.c_str());
// ... and sign it
if (!key.Sign(pblock->GetHash(), pblock->vchBlockSig))
{
- string strMessage = _("Warning: Proof-of-Stake miner is unable to sign the block (locked wallet?). Mining thread has been stopped.");
+ std::string strMessage = _("Warning: Proof-of-Stake miner is unable to sign the block (locked wallet?). Mining thread has been stopped.");
strMiscWarning = strMessage;
printf("*** %s\n", strMessage.c_str());
PrintException(&e, "ThreadStakeMinter()");
} catch (...) {
vnThreadsRunning[THREAD_MINTER]--;
- PrintException(NULL, "ThreadStakeMinter()");
+ PrintException(nullptr, "ThreadStakeMinter()");
}
printf("ThreadStakeMinter exiting, %d threads remaining\n", vnThreadsRunning[THREAD_MINTER]);
}