Modernize codebase: C++17, remove Tor v2, add embedded Tor scaffold, IBD speedups

- Replace ~290 BOOST_FOREACH with C++11 range-for across 41+ files
- Replace boost::assign::map_list_of with C++11 brace initialization
- Remove PAIRTYPE macro (no longer needed without BOOST_FOREACH)
- Guard OpenSSL locking callbacks for 3.x (no-ops in >= 1.1.0)
- Fix Qt deprecated APIs for Qt6 compat (QStyleOptionViewItemV4, setResizeMode)
- Add openssl_compat.h version string wrapper
- Enable C++17 in makefile.unix and triangles-qt.pro

- Delete 163 dead Tor v2 source files (~150K lines removed)
- Add embedded Tor scaffold (tor_embedded.h/cpp) using tor_api.h
- Add build-libtor.sh helper and CODEX-TOR-GUIDE.md
- Update makefile.unix and .pro with USE_TOR_EMBEDDED optional flag
- Fallback to external tor_process when not compiled with libtor

- IBD pipeline refill: 100 -> 1000 blocks
- Send/recv buffer limits: unlimited -> 100MB/32MB
- Orphan block cap: unlimited -> 750 with random eviction
- Socket poll: 10ms -> 1ms during IBD
- Message handler sleep: 10ms -> 1ms during IBD
- Stall detection timeout: 5s -> 2s

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-19 01:51:15 -07:00
parent 0beca5d801
commit 383a3b8b02
235 changed files with 1325 additions and 151064 deletions
+52 -52
View File
@@ -225,7 +225,7 @@ bool CWallet::Unlock(const SecureString& strWalletPassphrase)
{
LOCK(cs_wallet);
BOOST_FOREACH(const MasterKeyMap::value_type& pMasterKey, mapMasterKeys)
for (const MasterKeyMap::value_type& pMasterKey : mapMasterKeys)
{
if(!crypter.SetKeyFromPassphrase(strWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod))
return false;
@@ -251,7 +251,7 @@ bool CWallet::ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase,
CCrypter crypter;
CKeyingMaterial vMasterKey;
BOOST_FOREACH(MasterKeyMap::value_type& pMasterKey, mapMasterKeys)
for (MasterKeyMap::value_type& pMasterKey : mapMasterKeys)
{
if(!crypter.SetKeyFromPassphrase(strOldWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod))
return false;
@@ -457,7 +457,7 @@ CWallet::TxItems CWallet::OrderedTxItems(std::list<CAccountingEntry>& acentries,
}
acentries.clear();
walletdb.ListAccountCreditDebit(strAccount, acentries);
BOOST_FOREACH(CAccountingEntry& entry, acentries)
for (CAccountingEntry& entry : acentries)
{
txOrdered.insert(make_pair(entry.nOrderPos, TxPair((CWalletTx*)0, &entry)));
}
@@ -472,7 +472,7 @@ void CWallet::WalletUpdateSpent(const CTransaction &tx, bool fBlock)
// restored from backup or the user making copies of wallet.dat.
{
LOCK(cs_wallet);
BOOST_FOREACH(const CTxIn& txin, tx.vin)
for (const CTxIn& txin : tx.vin)
{
map<uint256, CWalletTx>::iterator mi = mapWallet.find(txin.prevout.hash);
if (mi != mapWallet.end())
@@ -496,7 +496,7 @@ void CWallet::WalletUpdateSpent(const CTransaction &tx, bool fBlock)
map<uint256, CWalletTx>::iterator mi = mapWallet.find(hash);
CWalletTx& wtx = (*mi).second;
BOOST_FOREACH(const CTxOut& txout, tx.vout)
for (const CTxOut& txout : tx.vout)
{
if (IsMine(txout))
{
@@ -514,7 +514,7 @@ void CWallet::MarkDirty()
{
{
LOCK(cs_wallet);
BOOST_FOREACH(PAIRTYPE(const uint256, CWalletTx)& item, mapWallet)
for (auto& item : mapWallet)
item.second.MarkDirty();
}
}
@@ -616,7 +616,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn)
if (vchDefaultKey.IsValid()) {
CScript scriptDefaultKey;
scriptDefaultKey.SetDestination(vchDefaultKey.GetID());
BOOST_FOREACH(const CTxOut& txout, wtx.vout)
for (const CTxOut& txout : wtx.vout)
{
if (txout.scriptPubKey == scriptDefaultKey)
{
@@ -807,7 +807,7 @@ void CWalletTx::GetAmounts(list<pair<CTxDestination, int64_t> >& listReceived,
}
// Sent/received.
BOOST_FOREACH(const CTxOut& txout, vout)
for (const CTxOut& txout : vout)
{
// Skip special stake out
if (txout.scriptPubKey.empty())
@@ -860,13 +860,13 @@ void CWalletTx::GetAccountAmounts(const string& strAccount, int64_t& nReceived,
if (strAccount == strSentAccount)
{
BOOST_FOREACH(const PAIRTYPE(CTxDestination,int64_t)& s, listSent)
for (const auto& s : listSent)
nSent += s.second;
nFee = allFee;
}
{
LOCK(pwallet->cs_wallet);
BOOST_FOREACH(const PAIRTYPE(CTxDestination,int64_t)& r, listReceived)
for (const auto& r : listReceived)
{
if (pwallet->mapAddressBook.count(r.first))
{
@@ -890,7 +890,7 @@ void CWalletTx::AddSupportingTransactions(CTxDB& txdb)
if (SetMerkleBranch() < COPY_DEPTH)
{
vector<uint256> vWorkQueue;
BOOST_FOREACH(const CTxIn& txin, vin)
for (const CTxIn& txin : vin)
vWorkQueue.push_back(txin.prevout.hash);
// This critsect is OK because txdb is already open
@@ -910,7 +910,7 @@ void CWalletTx::AddSupportingTransactions(CTxDB& txdb)
if (mi != pwallet->mapWallet.end())
{
tx = (*mi).second;
BOOST_FOREACH(const CMerkleTx& txWalletPrev, (*mi).second.vtxPrev)
for (const CMerkleTx& txWalletPrev : (*mi).second.vtxPrev)
mapWalletPrev[txWalletPrev.GetHash()] = &txWalletPrev;
}
else if (mapWalletPrev.count(hash))
@@ -932,7 +932,7 @@ void CWalletTx::AddSupportingTransactions(CTxDB& txdb)
if (nDepth < COPY_DEPTH)
{
BOOST_FOREACH(const CTxIn& txin, tx.vin)
for (const CTxIn& txin : tx.vin)
vWorkQueue.push_back(txin.prevout.hash);
}
}
@@ -971,7 +971,7 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate)
CBlock block;
block.ReadFromDisk(pindex, true);
BOOST_FOREACH(CTransaction& tx, block.vtx)
for (CTransaction& tx : block.vtx)
{
if (AddToWalletIfInvolvingMe(tx, &block, fUpdate))
ret++;
@@ -1005,7 +1005,7 @@ bool CWallet::ScanForWalletTransactionsFromIndex(CBlockIndex* pindexStart, bool
CTxDB txdb("r");
set<uint256> setSeedTxIds;
BOOST_FOREACH(const CKeyID& keyId, setKeys)
for (const CKeyID& keyId : setKeys)
{
vector<uint256> vTxIds;
if (!txdb.GetAddressTxIds(ADDR_TYPE_P2PKH, keyId, nStartHeight, nBestHeight, vTxIds))
@@ -1013,7 +1013,7 @@ bool CWallet::ScanForWalletTransactionsFromIndex(CBlockIndex* pindexStart, bool
setSeedTxIds.insert(vTxIds.begin(), vTxIds.end());
}
BOOST_FOREACH(const CScriptID& scriptId, setScripts)
for (const CScriptID& scriptId : setScripts)
{
vector<uint256> vTxIds;
if (!txdb.GetAddressTxIds(ADDR_TYPE_P2SH, scriptId, nStartHeight, nBestHeight, vTxIds))
@@ -1022,7 +1022,7 @@ bool CWallet::ScanForWalletTransactionsFromIndex(CBlockIndex* pindexStart, bool
}
vector<IndexedWalletTx> vOrderedSeedTxs;
BOOST_FOREACH(const uint256& hashTx, setSeedTxIds)
for (const uint256& hashTx : setSeedTxIds)
{
CTransaction tx;
CTxIndex txindex;
@@ -1037,7 +1037,7 @@ bool CWallet::ScanForWalletTransactionsFromIndex(CBlockIndex* pindexStart, bool
deque<uint256> vWorkQueue;
set<uint256> setQueuedTxs;
BOOST_FOREACH(const IndexedWalletTx& indexedTx, vOrderedSeedTxs)
for (const IndexedWalletTx& indexedTx : vOrderedSeedTxs)
{
bool fExists = false;
{
@@ -1150,7 +1150,7 @@ void CWallet::ReacceptWalletTransactions()
vector<CDiskTxPos> vMissingTx;
{
LOCK(cs_wallet);
BOOST_FOREACH(PAIRTYPE(const uint256, CWalletTx)& item, mapWallet)
for (auto& item : mapWallet)
{
if (fShutdown)
break;
@@ -1211,7 +1211,7 @@ void CWallet::ReacceptWalletTransactions()
void CWalletTx::RelayWalletTransaction(CTxDB& txdb)
{
BOOST_FOREACH(const CMerkleTx& tx, vtxPrev)
for (const CMerkleTx& tx : vtxPrev)
{
if (!(tx.IsCoinBase() || tx.IsCoinStake()))
{
@@ -1265,7 +1265,7 @@ void CWallet::ResendWalletTransactions(bool fForce)
LOCK(cs_wallet);
// Sort them in chronological order
multimap<unsigned int, CWalletTx*> mapSorted;
BOOST_FOREACH(PAIRTYPE(const uint256, CWalletTx)& item, mapWallet)
for (auto& item : mapWallet)
{
CWalletTx& wtx = item.second;
// Don't rebroadcast until it's had plenty of time that
@@ -1273,7 +1273,7 @@ void CWallet::ResendWalletTransactions(bool fForce)
if (fForce || nTimeBestReceived - (int64_t)wtx.nTimeReceived > 5 * 60)
mapSorted.insert(make_pair(wtx.nTimeReceived, &wtx));
}
BOOST_FOREACH(PAIRTYPE(const unsigned int, CWalletTx*)& item, mapSorted)
for (auto& item : mapSorted)
{
CWalletTx& wtx = *item.second;
if (wtx.CheckTransaction())
@@ -1479,7 +1479,7 @@ bool CWallet::SelectCoinsMinConf(int64_t nTargetValue, unsigned int nSpendTime,
random_shuffle(vCoins.begin(), vCoins.end(), GetRandInt);
BOOST_FOREACH(COutput output, vCoins)
for (COutput output : vCoins)
{
const CWalletTx *pcoin = output.tx;
@@ -1579,7 +1579,7 @@ bool CWallet::SelectCoins(int64_t nTargetValue, unsigned int nSpendTime, set<pai
// coin control -> return all selected outputs (we want all selected to go into the transaction for sure)
if (coinControl && coinControl->HasSelected())
{
BOOST_FOREACH(const COutput& out, vCoins)
for (const COutput& out : vCoins)
{
nValueRet += out.tx->vout[out.i].nValue;
setCoinsRet.insert(make_pair(out.tx, out.i));
@@ -1601,7 +1601,7 @@ bool CWallet::SelectCoinsSimple(int64_t nTargetValue, unsigned int nSpendTime, i
setCoinsRet.clear();
nValueRet = 0;
BOOST_FOREACH(COutput output, vCoins)
for (COutput output : vCoins)
{
const CWalletTx *pcoin = output.tx;
int i = output.i;
@@ -1639,7 +1639,7 @@ bool CWallet::SelectCoinsSimple(int64_t nTargetValue, unsigned int nSpendTime, i
bool CWallet::CreateTransaction(const vector<pair<CScript, int64_t> >& vecSend, CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, const CCoinControl* coinControl)
{
int64_t nValue = 0;
BOOST_FOREACH (const PAIRTYPE(CScript, int64_t)& s, vecSend)
for (const auto& s : vecSend)
{
if (nValue < 0)
return false;
@@ -1665,7 +1665,7 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, int64_t> >& vecSend,
int64_t nTotalValue = nValue + nFeeRet;
double dPriority = 0;
// vouts to the payees
BOOST_FOREACH (const PAIRTYPE(CScript, int64_t)& s, vecSend)
for (const auto& s : vecSend)
wtxNew.vout.push_back(CTxOut(s.second, s.first));
// Choose coins to use
@@ -1673,7 +1673,7 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, int64_t> >& vecSend,
int64_t nValueIn = 0;
if (!SelectCoins(nTotalValue, wtxNew.nTime, setCoins, nValueIn, coinControl))
return false;
BOOST_FOREACH(PAIRTYPE(const CWalletTx*, unsigned int) pcoin, setCoins)
for (auto pcoin : setCoins)
{
int64_t nCredit = pcoin.first->vout[pcoin.second].nValue;
dPriority += (double)nCredit * pcoin.first->GetDepthInMainChain();
@@ -1736,12 +1736,12 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, int64_t> >& vecSend,
reservekey.ReturnKey();
// Fill vin
BOOST_FOREACH(const PAIRTYPE(const CWalletTx*,unsigned int)& coin, setCoins)
for (const auto& coin : setCoins)
wtxNew.vin.push_back(CTxIn(coin.first->GetHash(),coin.second));
// Sign
int nIn = 0;
BOOST_FOREACH(const PAIRTYPE(const CWalletTx*,unsigned int)& coin, setCoins)
for (const auto& coin : setCoins)
if (!SignSignature(*this, *coin.first, wtxNew, nIn++))
return false;
@@ -1827,7 +1827,7 @@ bool CWallet::GetStakeWeight(const CKeyStore& keystore, uint64_t& nMinWeight, ui
return false;
CTxDB txdb("r");
BOOST_FOREACH(PAIRTYPE(const CWalletTx*, unsigned int) pcoin, setCoins)
for (auto pcoin : setCoins)
{
CTxIndex txindex;
{
@@ -1896,7 +1896,7 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int
int64_t nCredit = 0;
CScript scriptPubKeyKernel;
CTxDB txdb("r");
BOOST_FOREACH(PAIRTYPE(const CWalletTx*, unsigned int) pcoin, setCoins)
for (auto pcoin : setCoins)
{
CTxIndex txindex;
{
@@ -2003,7 +2003,7 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int
return false;
}
BOOST_FOREACH(PAIRTYPE(const CWalletTx*, unsigned int) pcoin, setCoins)
for (auto pcoin : setCoins)
{
// Attempt to add more inputs
// Only add coins of the same key/address as kernel
@@ -2059,7 +2059,7 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int
// Sign
int nIn = 0;
BOOST_FOREACH(const CWalletTx* pcoin, vwtxPrev)
for (const CWalletTx* pcoin : vwtxPrev)
{
if (!SignSignature(*this, *pcoin, txNew, nIn++))
return error("CreateCoinStake : failed to sign coinstake");
@@ -2082,7 +2082,7 @@ bool CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey)
if (!mapNarr.empty())
{
BOOST_FOREACH(const PAIRTYPE(string,string)& item, mapNarr)
for (const auto& item : mapNarr)
wtxNew.mapValue[item.first] = item.second;
};
@@ -2104,7 +2104,7 @@ bool CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey)
// Mark old coins as spent
set<CWalletTx*> setCoins;
BOOST_FOREACH(const CTxIn& txin, wtxNew.vin)
for (const CTxIn& txin : wtxNew.vin)
{
CWalletTx &coin = mapWallet[txin.prevout.hash];
coin.BindWallet(this);
@@ -2330,7 +2330,7 @@ bool CWallet::NewKeyPool()
{
LOCK(cs_wallet);
CWalletDB walletdb(strWalletFile);
BOOST_FOREACH(int64_t nIndex, setKeyPool)
for (int64_t nIndex : setKeyPool)
walletdb.ErasePool(nIndex);
setKeyPool.clear();
@@ -2487,7 +2487,7 @@ std::map<CTxDestination, int64_t> CWallet::GetAddressBalances()
{
LOCK(cs_wallet);
BOOST_FOREACH(PAIRTYPE(uint256, CWalletTx) walletEntry, mapWallet)
for (auto walletEntry : mapWallet)
{
CWalletTx *pcoin = &walletEntry.second;
@@ -2526,14 +2526,14 @@ set< set<CTxDestination> > CWallet::GetAddressGroupings()
set< set<CTxDestination> > groupings;
set<CTxDestination> grouping;
BOOST_FOREACH(PAIRTYPE(uint256, CWalletTx) walletEntry, mapWallet)
for (auto walletEntry : mapWallet)
{
CWalletTx *pcoin = &walletEntry.second;
if (pcoin->vin.size() > 0 && IsMine(pcoin->vin[0]))
{
// group all input addresses with each other
BOOST_FOREACH(CTxIn txin, pcoin->vin)
for (CTxIn txin : pcoin->vin)
{
CTxDestination address;
if(!ExtractDestination(mapWallet[txin.prevout.hash].vout[txin.prevout.n].scriptPubKey, address))
@@ -2542,7 +2542,7 @@ set< set<CTxDestination> > CWallet::GetAddressGroupings()
}
// group change with input addresses
BOOST_FOREACH(CTxOut txout, pcoin->vout)
for (CTxOut txout : pcoin->vout)
if (IsChange(txout))
{
CWalletTx tx = mapWallet[pcoin->vin[0].prevout.hash];
@@ -2570,18 +2570,18 @@ set< set<CTxDestination> > CWallet::GetAddressGroupings()
set< set<CTxDestination>* > uniqueGroupings; // a set of pointers to groups of addresses
map< CTxDestination, set<CTxDestination>* > setmap; // map addresses to the unique group containing it
BOOST_FOREACH(set<CTxDestination> grouping, groupings)
for (set<CTxDestination> grouping : groupings)
{
// make a set of all the groups hit by this new group
set< set<CTxDestination>* > hits;
map< CTxDestination, set<CTxDestination>* >::iterator it;
BOOST_FOREACH(CTxDestination address, grouping)
for (CTxDestination address : grouping)
if ((it = setmap.find(address)) != setmap.end())
hits.insert((*it).second);
// merge all hit groups into a new single group and delete old groups
set<CTxDestination>* merged = new set<CTxDestination>(grouping);
BOOST_FOREACH(set<CTxDestination>* hit, hits)
for (set<CTxDestination>* hit : hits)
{
merged->insert(hit->begin(), hit->end());
uniqueGroupings.erase(hit);
@@ -2590,12 +2590,12 @@ set< set<CTxDestination> > CWallet::GetAddressGroupings()
uniqueGroupings.insert(merged);
// update setmap
BOOST_FOREACH(CTxDestination element, *merged)
for (CTxDestination element : *merged)
setmap[element] = merged;
}
set< set<CTxDestination> > ret;
BOOST_FOREACH(set<CTxDestination>* uniqueGrouping, uniqueGroupings)
for (set<CTxDestination>* uniqueGrouping : uniqueGroupings)
{
ret.insert(*uniqueGrouping);
delete uniqueGrouping;
@@ -2618,7 +2618,7 @@ void CWallet::FixSpentCoins(int& nMismatchFound, int64_t& nBalanceInQuestion, bo
vCoins.push_back(&(*it).second);
CTxDB txdb("r");
BOOST_FOREACH(CWalletTx* pcoin, vCoins)
for (CWalletTx* pcoin : vCoins)
{
// Find the corresponding transaction index
CTxIndex txindex;
@@ -2661,7 +2661,7 @@ void CWallet::DisableTransaction(const CTransaction &tx)
return; // only disconnecting coinstake requires marking input unspent
LOCK(cs_wallet);
BOOST_FOREACH(const CTxIn& txin, tx.vin)
for (const CTxIn& txin : tx.vin)
{
map<uint256, CWalletTx>::iterator mi = mapWallet.find(txin.prevout.hash);
if (mi != mapWallet.end())
@@ -2717,7 +2717,7 @@ void CWallet::GetAllReserveKeys(set<CKeyID>& setAddress) const
CWalletDB walletdb(strWalletFile);
LOCK2(cs_main, cs_wallet);
BOOST_FOREACH(const int64_t& id, setKeyPool)
for (const int64_t& id : setKeyPool)
{
CKeyPool keypool;
if (!walletdb.ReadPool(id, keypool))
@@ -2754,7 +2754,7 @@ void CWallet::GetKeyBirthTimes(std::map<CKeyID, int64_t> &mapKeyBirth) const {
std::map<CKeyID, CBlockIndex*> mapKeyFirstBlock;
std::set<CKeyID> setKeys;
GetKeys(setKeys);
BOOST_FOREACH(const CKeyID &keyid, setKeys) {
for (const CKeyID &keyid : setKeys) {
if (mapKeyBirth.count(keyid) == 0)
mapKeyFirstBlock[keyid] = pindexMax;
}
@@ -2773,10 +2773,10 @@ void CWallet::GetKeyBirthTimes(std::map<CKeyID, int64_t> &mapKeyBirth) const {
if (blit != mapBlockIndex.end() && blit->second->IsInMainChain()) {
// ... which are already in a block
int nHeight = blit->second->nHeight;
BOOST_FOREACH(const CTxOut &txout, wtx.vout) {
for (const CTxOut &txout : wtx.vout) {
// iterate over all their outputs
::ExtractAffectedKeys(*this, txout.scriptPubKey, vAffected);
BOOST_FOREACH(const CKeyID &keyid, vAffected) {
for (const CKeyID &keyid : vAffected) {
// ... and all their affected keys
std::map<CKeyID, CBlockIndex*>::iterator rit = mapKeyFirstBlock.find(keyid);
if (rit != mapKeyFirstBlock.end() && nHeight < rit->second->nHeight)