Skip to content

minor: nits #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: limitpool
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include <vector>

#undef foreach
#include <boost/foreach.hpp>

struct CDiskBlockPos
Expand Down
1 change: 1 addition & 0 deletions src/coins.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <assert.h>
#include <stdint.h>

#undef foreach
#include <boost/foreach.hpp>
#include <boost/unordered_map.hpp>

Expand Down
1 change: 1 addition & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ std::string HelpMessage(HelpMessageMode mode)
strUsage += HelpMessageOpt("-dbcache=<n>", strprintf(_("Set database cache size in megabytes (%d to %d, default: %d)"), nMinDbCache, nMaxDbCache, nDefaultDbCache));
strUsage += HelpMessageOpt("-loadblock=<file>", _("Imports blocks from external blk000??.dat file") + " " + _("on startup"));
strUsage += HelpMessageOpt("-maxorphantx=<n>", strprintf(_("Keep at most <n> unconnectable transactions in memory (default: %u)"), DEFAULT_MAX_ORPHAN_TRANSACTIONS));
strUsage += HelpMessageOpt("-maxmempool=<n>", strprintf(_("Keep the transaction memory pool below <n> megabytes (default: %u)"), DEFAULT_MAX_MEMPOOL_SIZE));
strUsage += HelpMessageOpt("-par=<n>", strprintf(_("Set the number of script verification threads (%u to %d, 0 = auto, <0 = leave that many cores free, default: %d)"),
-GetNumCores(), MAX_SCRIPTCHECK_THREADS, DEFAULT_SCRIPTCHECK_THREADS));
#ifndef WIN32
Expand Down
47 changes: 35 additions & 12 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ bool AddOrphanTx(const CTransaction& tx, NodeId peer)
unsigned int sz = tx.GetSerializeSize(SER_NETWORK, CTransaction::CURRENT_VERSION);
if (sz > 5000)
{
LogPrint("mempool", "ignoring large orphan tx (size: %u, hash: %s)\n", sz, hash.ToString());
LogPrint("orphan", "ignoring large orphan tx (size: %u, hash: %s)\n", sz, hash.ToString());
return false;
}

Expand All @@ -552,7 +552,7 @@ bool AddOrphanTx(const CTransaction& tx, NodeId peer)
BOOST_FOREACH(const CTxIn& txin, tx.vin)
mapOrphanTransactionsByPrev[txin.prevout.hash].insert(hash);

LogPrint("mempool", "stored orphan tx %s (mapsz %u prevsz %u)\n", hash.ToString(),
LogPrint("orphan", "stored orphan tx %s (mapsz %u prevsz %u)\n", hash.ToString(),
mapOrphanTransactions.size(), mapOrphanTransactionsByPrev.size());
return true;
}
Expand Down Expand Up @@ -587,7 +587,7 @@ void EraseOrphansFor(NodeId peer)
++nErased;
}
}
if (nErased > 0) LogPrint("mempool", "Erased %d orphan tx from peer %d\n", nErased, peer);
if (nErased > 0) LogPrint("orphan", "Erased %d orphan tx from peer %d\n", nErased, peer);
}


Expand Down Expand Up @@ -859,22 +859,39 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
CTxMemPoolEntry entry(tx, nFees, GetTime(), dPriority, chainActive.Height(), mempool.HasNoInputsOf(tx));
unsigned int nSize = entry.GetTxSize();

// Try to make space in mempool
std::set<uint256> protect;
BOOST_FOREACH(const CTxIn& in, tx.vin) {
protect.insert(in.prevout.hash);
}
std::set<uint256> stagedelete;
CAmount nFeesDeleted = 0;
size_t nSizeDeleted = 0;
if (!mempool.StageTrimToSize(GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000, nFees, entry.GetFeeRate(), protect, stagedelete, nFeesDeleted, nSizeDeleted)) {
return state.DoS(0, false, REJECT_INSUFFICIENTFEE, "mempool-full");
}

if ((double)nFeesDeleted * nSize > (double)nFees * nSizeDeleted) {
// The new transaction's feerate is below that of the replaced transactions.
return state.DoS(0, false, REJECT_INSUFFICIENTFEE, "mempool-full-no-improve");
}

// Don't accept it if it can't get into a block
CAmount txMinFee = GetMinRelayFee(tx, nSize, true);
if (fLimitFree && nFees < txMinFee)
if (fLimitFree && nFees - nFeesDeleted < txMinFee)
return state.DoS(0, error("AcceptToMemoryPool: not enough fees %s, %d < %d",
hash.ToString(), nFees, txMinFee),
REJECT_INSUFFICIENTFEE, "insufficient fee");

// Require that free transactions have sufficient priority to be mined in the next block.
if (GetBoolArg("-relaypriority", true) && nFees < ::minRelayTxFee.GetFee(nSize) && !AllowFree(view.GetPriority(tx, chainActive.Height() + 1))) {
if (GetBoolArg("-relaypriority", true) && nFees - nFeesDeleted < ::minRelayTxFee.GetFee(nSize) && !AllowFree(view.GetPriority(tx, chainActive.Height() + 1))) {
return state.DoS(0, false, REJECT_INSUFFICIENTFEE, "insufficient priority");
}

// Continuously rate-limit free (really, very-low-fee) transactions
// This mitigates 'penny-flooding' -- sending thousands of free transactions just to
// be annoying or make others' transactions take longer to confirm.
if (fLimitFree && nFees < ::minRelayTxFee.GetFee(nSize))
if (fLimitFree && nFees - nFeesDeleted < ::minRelayTxFee.GetFee(nSize))
{
static CCriticalSection csFreeLimiter;
static double dFreeCount;
Expand All @@ -891,8 +908,8 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
if (dFreeCount >= GetArg("-limitfreerelay", 15)*10*1000)
return state.DoS(0, error("AcceptToMemoryPool: free transaction rejected by rate limiter"),
REJECT_INSUFFICIENTFEE, "rate limited free transaction");
LogPrint("mempool", "Rate limit dFreeCount: %g => %g\n", dFreeCount, dFreeCount+nSize);
dFreeCount += nSize;
LogPrint("mempool", "Rate limit dFreeCount: %g => %g\n", dFreeCount, dFreeCount+nSize+nSizeDeleted);
dFreeCount += nSize+nSizeDeleted;
}

if (fRejectAbsurdFee && nFees > ::minRelayTxFee.GetFee(nSize) * 10000)
Expand Down Expand Up @@ -921,6 +938,12 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
return error("AcceptToMemoryPool: BUG! PLEASE REPORT THIS! ConnectInputs failed against MANDATORY but not STANDARD flags %s", hash.ToString());
}

// Make actually space
if (!stagedelete.empty()) {
LogPrint("mempool", "Removing %u transactions (%d fees, %d bytes) from the mempool to make space for %s\n", stagedelete.size(), nFeesDeleted, nSizeDeleted, tx.GetHash().ToString());
pool.RemoveStaged(stagedelete);
}

// Store transaction in memory
pool.addUnchecked(hash, entry, !IsInitialBlockDownload());
}
Expand Down Expand Up @@ -4240,7 +4263,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
continue;
if (AcceptToMemoryPool(mempool, stateDummy, orphanTx, true, &fMissingInputs2))
{
LogPrint("mempool", " accepted orphan tx %s\n", orphanHash.ToString());
LogPrint("orphan", " accepted orphan tx %s\n", orphanHash.ToString());
RelayTransaction(orphanTx);
vWorkQueue.push_back(orphanHash);
vEraseQueue.push_back(orphanHash);
Expand All @@ -4253,11 +4276,11 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
// Punish peer that gave us an invalid orphan tx
Misbehaving(fromPeer, nDos);
setMisbehaving.insert(fromPeer);
LogPrint("mempool", " invalid orphan tx %s\n", orphanHash.ToString());
LogPrint("orphan", " invalid orphan tx %s\n", orphanHash.ToString());
}
// Has inputs but not accepted to mempool
// Probably non-standard or insufficient fee/priority
LogPrint("mempool", " removed orphan tx %s\n", orphanHash.ToString());
LogPrint("orphan", " removed orphan tx %s\n", orphanHash.ToString());
vEraseQueue.push_back(orphanHash);
}
mempool.check(pcoinsTip);
Expand All @@ -4275,7 +4298,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
unsigned int nMaxOrphanTx = (unsigned int)std::max((int64_t)0, GetArg("-maxorphantx", DEFAULT_MAX_ORPHAN_TRANSACTIONS));
unsigned int nEvicted = LimitOrphanTxSize(nMaxOrphanTx);
if (nEvicted > 0)
LogPrint("mempool", "mapOrphan overflow, removed %u tx\n", nEvicted);
LogPrint("orphan", "mapOrphan overflow, removed %u tx\n", nEvicted);
} else if (pfrom->fWhitelisted) {
// Always relay transactions received from whitelisted peers, even
// if they are already in the mempool (allowing the node to function
Expand Down
2 changes: 2 additions & 0 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ struct CNodeStateStats;
static const bool DEFAULT_ALERTS = true;
/** Default for -maxorphantx, maximum number of orphan transactions kept in memory */
static const unsigned int DEFAULT_MAX_ORPHAN_TRANSACTIONS = 100;
/** Default for -maxmempool, maximum megabytes of mempool memory usage */
static const unsigned int DEFAULT_MAX_MEMPOOL_SIZE = 300;
/** The maximum size of a blk?????.dat file (since 0.8) */
static const unsigned int MAX_BLOCKFILE_SIZE = 0x8000000; // 128 MiB
/** The pre-allocation chunk size for blk?????.dat files (since 0.8) */
Expand Down
13 changes: 13 additions & 0 deletions src/memusage.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <set>
#include <vector>

#undef foreach
#include <boost/foreach.hpp>
#include <boost/unordered_set.hpp>
#include <boost/unordered_map.hpp>
Expand Down Expand Up @@ -104,6 +105,12 @@ static inline size_t DynamicUsage(const std::set<X>& s)
return MallocUsage(sizeof(stl_tree_node<X>)) * s.size();
}

template<typename X>
static inline size_t IncrementalDynamicUsage(const std::set<X>& s)
{
return MallocUsage(sizeof(stl_tree_node<X>));
}

template<typename X>
static inline size_t RecursiveDynamicUsage(const std::set<X>& v)
{
Expand All @@ -120,6 +127,12 @@ static inline size_t DynamicUsage(const std::map<X, Y>& m)
return MallocUsage(sizeof(stl_tree_node<std::pair<const X, Y> >)) * m.size();
}

template<typename X, typename Y>
static inline size_t IncrementalDynamicUsage(const std::map<X, Y>& m)
{
return MallocUsage(sizeof(stl_tree_node<std::pair<const X, Y> >));
}

template<typename X, typename Y>
static inline size_t RecursiveDynamicUsage(const std::map<X, Y>& v)
{
Expand Down
9 changes: 5 additions & 4 deletions src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "pow.h"
#include "primitives/transaction.h"
#include "timedata.h"
#include "txmempool.h"
#include "util.h"
#include "utilmoneystr.h"
#include "validationinterface.h"
Expand Down Expand Up @@ -148,10 +149,10 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
// This vector will be sorted into a priority queue:
vector<TxPriority> vecPriority;
vecPriority.reserve(mempool.mapTx.size());
for (map<uint256, CTxMemPoolEntry>::iterator mi = mempool.mapTx.begin();
for (CTxMemPool::indexed_transaction_set::iterator mi = mempool.mapTx.begin();
mi != mempool.mapTx.end(); ++mi)
{
const CTransaction& tx = mi->second.GetTx();
const CTransaction& tx = mi->GetTx();
if (tx.IsCoinBase() || !IsFinalTx(tx, nHeight, pblock->nTime))
continue;

Expand Down Expand Up @@ -186,7 +187,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
}
mapDependers[txin.prevout.hash].push_back(porphan);
porphan->setDependsOn.insert(txin.prevout.hash);
nTotalIn += mempool.mapTx[txin.prevout.hash].GetTx().vout[txin.prevout.n].nValue;
nTotalIn += mempool.mapTx.find(txin.prevout.hash)->GetTx().vout[txin.prevout.n].nValue;
continue;
}
const CCoins* coins = view.AccessCoins(txin.prevout.hash);
Expand Down Expand Up @@ -216,7 +217,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
porphan->feeRate = feeRate;
}
else
vecPriority.push_back(TxPriority(dPriority, feeRate, &mi->second.GetTx()));
vecPriority.push_back(TxPriority(dPriority, feeRate, &(mi->GetTx())));
}

// Collect transactions into block
Expand Down
1 change: 1 addition & 0 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <arpa/inet.h>
#endif

#undef foreach
#include <boost/filesystem/path.hpp>
#include <boost/foreach.hpp>
#include <boost/signals2/signal.hpp>
Expand Down
2 changes: 1 addition & 1 deletion src/qt/addressbookpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ void AddressBookPage::done(int retval)
// Figure out which address was selected, and return it
QModelIndexList indexes = table->selectionModel()->selectedRows(AddressTableModel::Address);

foreach (const QModelIndex& index, indexes) {
Q_FOREACH (const QModelIndex& index, indexes) {
QVariant address = table->model()->data(index);
returnValue = address.toString();
}
Expand Down
6 changes: 3 additions & 3 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ void BitcoinGUI::dropEvent(QDropEvent *event)
{
if(event->mimeData()->hasUrls())
{
foreach(const QUrl &uri, event->mimeData()->urls())
Q_FOREACH(const QUrl &uri, event->mimeData()->urls())
{
emit receivedURI(uri.toString());
}
Expand Down Expand Up @@ -1050,7 +1050,7 @@ UnitDisplayStatusBarControl::UnitDisplayStatusBarControl() :
QList<BitcoinUnits::Unit> units = BitcoinUnits::availableUnits();
int max_width = 0;
const QFontMetrics fm(font());
foreach (const BitcoinUnits::Unit unit, units)
Q_FOREACH (const BitcoinUnits::Unit unit, units)
{
max_width = qMax(max_width, fm.width(BitcoinUnits::name(unit)));
}
Expand All @@ -1069,7 +1069,7 @@ void UnitDisplayStatusBarControl::mousePressEvent(QMouseEvent *event)
void UnitDisplayStatusBarControl::createContextMenu()
{
menu = new QMenu();
foreach(BitcoinUnits::Unit u, BitcoinUnits::availableUnits())
Q_FOREACH(BitcoinUnits::Unit u, BitcoinUnits::availableUnits())
{
QAction *menuAction = new QAction(QString(BitcoinUnits::name(u)), this);
menuAction->setData(QVariant(u));
Expand Down
2 changes: 1 addition & 1 deletion src/qt/coincontroldialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
CAmount nPayAmount = 0;
bool fDust = false;
CMutableTransaction txDummy;
foreach(const CAmount &amount, CoinControlDialog::payAmounts)
Q_FOREACH(const CAmount &amount, CoinControlDialog::payAmounts)
{
nPayAmount += amount;

Expand Down
2 changes: 1 addition & 1 deletion src/qt/optionsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) :
/* Display elements init */
QDir translations(":translations");
ui->lang->addItem(QString("(") + tr("default") + QString(")"), QVariant(""));
foreach(const QString &langStr, translations.entryList())
Q_FOREACH(const QString &langStr, translations.entryList())
{
QLocale locale(langStr);

Expand Down
10 changes: 5 additions & 5 deletions src/qt/paymentserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ void PaymentServer::LoadRootCAs(X509_STORE* _store)
int nRootCerts = 0;
const QDateTime currentTime = QDateTime::currentDateTime();

foreach (const QSslCertificate& cert, certList) {
Q_FOREACH (const QSslCertificate& cert, certList) {
// Don't log NULL certificates
if (cert.isNull())
continue;
Expand Down Expand Up @@ -269,7 +269,7 @@ void PaymentServer::ipcParseCommandLine(int argc, char* argv[])
bool PaymentServer::ipcSendCommandLine()
{
bool fResult = false;
foreach (const QString& r, savedPaymentRequests)
Q_FOREACH (const QString& r, savedPaymentRequests)
{
QLocalSocket* socket = new QLocalSocket();
socket->connectToServer(ipcServerName(), QIODevice::WriteOnly);
Expand Down Expand Up @@ -394,7 +394,7 @@ void PaymentServer::uiReady()
initNetManager();

saveURIs = false;
foreach (const QString& s, savedPaymentRequests)
Q_FOREACH (const QString& s, savedPaymentRequests)
{
handleURIOrFile(s);
}
Expand Down Expand Up @@ -562,7 +562,7 @@ bool PaymentServer::processPaymentRequest(const PaymentRequestPlus& request, Sen
QList<std::pair<CScript, CAmount> > sendingTos = request.getPayTo();
QStringList addresses;

foreach(const PAIRTYPE(CScript, CAmount)& sendingTo, sendingTos) {
Q_FOREACH(const PAIRTYPE(CScript, CAmount)& sendingTo, sendingTos) {
// Extract and check destination addresses
CTxDestination dest;
if (ExtractDestination(sendingTo.first, dest)) {
Expand Down Expand Up @@ -750,7 +750,7 @@ void PaymentServer::reportSslErrors(QNetworkReply* reply, const QList<QSslError>
Q_UNUSED(reply);

QString errString;
foreach (const QSslError& err, errs) {
Q_FOREACH (const QSslError& err, errs) {
qWarning() << "PaymentServer::reportSslErrors: " << err;
errString += err.errorString() + "\n";
}
Expand Down
4 changes: 2 additions & 2 deletions src/qt/peertablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class PeerTablePriv
#if QT_VERSION >= 0x040700
cachedNodeStats.reserve(vNodes.size());
#endif
foreach (CNode* pnode, vNodes)
Q_FOREACH (CNode* pnode, vNodes)
{
CNodeCombinedStats stats;
stats.nodeStateStats.nMisbehavior = 0;
Expand Down Expand Up @@ -92,7 +92,7 @@ class PeerTablePriv
// build index map
mapNodeRows.clear();
int row = 0;
foreach (const CNodeCombinedStats& stats, cachedNodeStats)
Q_FOREACH (const CNodeCombinedStats& stats, cachedNodeStats)
mapNodeRows.insert(std::pair<NodeId, int>(stats.nodeStats.nodeid, row++));
}

Expand Down
2 changes: 1 addition & 1 deletion src/qt/receivecoinsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ void ReceiveCoinsDialog::on_showRequestButton_clicked()
return;
QModelIndexList selection = ui->recentRequestsView->selectionModel()->selectedRows();

foreach (const QModelIndex& index, selection) {
Q_FOREACH (const QModelIndex& index, selection) {
on_recentRequestsView_doubleClicked(index);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/qt/rpcconsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ bool parseCommandLine(std::vector<std::string> &args, const std::string &strComm
STATE_ESCAPE_DOUBLEQUOTED
} state = STATE_EATING_SPACES;
std::string curarg;
foreach(char ch, strCommand)
Q_FOREACH(char ch, strCommand)
{
switch(state)
{
Expand Down
4 changes: 2 additions & 2 deletions src/qt/sendcoinsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ void SendCoinsDialog::on_sendButton_clicked()

// Format confirmation message
QStringList formatted;
foreach(const SendCoinsRecipient &rcp, currentTransaction.getRecipients())
Q_FOREACH(const SendCoinsRecipient &rcp, currentTransaction.getRecipients())
{
// generate bold amount string
QString amount = "<b>" + BitcoinUnits::formatHtmlWithUnit(model->getOptionsModel()->getDisplayUnit(), rcp.amount);
Expand Down Expand Up @@ -305,7 +305,7 @@ void SendCoinsDialog::on_sendButton_clicked()
questionString.append("<hr />");
CAmount totalAmount = currentTransaction.getTotalTransactionAmount() + txFee;
QStringList alternativeUnits;
foreach(BitcoinUnits::Unit u, BitcoinUnits::availableUnits())
Q_FOREACH(BitcoinUnits::Unit u, BitcoinUnits::availableUnits())
{
if(u != model->getOptionsModel()->getDisplayUnit())
alternativeUnits.append(BitcoinUnits::formatHtmlWithUnit(u, totalAmount));
Expand Down
Loading