Cleanup: drop boost::filesystem/thread/chrono, retire dead code

Migration from boost to std-library equivalents and removal of unreachable
code paths. Touches infrastructure only — no consensus rule or wallet
serialization changes.

Dead code removed:
- IRC bootstrap (irc.cpp/h, 417 lines): orphan from pre-Tor era, no callers.
- Alert system (alert.cpp/h + sendalert RPC + Qt UI signal, ~500 lines):
  retired post-V5 fork; old peers' alert messages now hit the unknown-cmd
  default branch, logged + ignored.
- Legacy P2P handlers in main.cpp: "checkpoint" (already a no-op stub since
  V5 fork master-key removal), "checkorder"/"reply" (2010-era Receive-by-IP
  feature), plus their unused supporting structures (CRequestTracker,
  PushRequest overloads, mapRequests/cs_mapRequests, mapReuseKey).
- Unreachable RPCs clearwallettransactions and scanforalltxns (~175 lines):
  defined in rpcwallet.cpp but never registered in the dispatch table.
- Stale -alertnotify CLI help text (option was advertised but never wired).

boost::filesystem -> std::filesystem (C++17):
- 30 source files, 5 headers. namespace fs = boost::filesystem swapped to
  namespace fs = std::filesystem; boost::filesystem::ifstream/ofstream
  replaced with std::ifstream/ofstream (path-aware in C++17);
  fs::system_complete -> fs::absolute; boost::filesystem::filesystem_error
  -> std::filesystem::filesystem_error.
- Build system: dropped Boost::filesystem from link libs and Boost
  components; PCH includes updated.
- Added explicit <filesystem> includes where types were previously
  available only transitively (db.h, rpcblockchain.cpp).

boost::thread -> std::thread (12 files):
- sync.h CCriticalSection/CWaitableCriticalSection now alias
  std::recursive_mutex/std::mutex. boost::unique_lock and
  boost::condition_variable / boost::mutex::scoped_lock swapped to std
  equivalents; sync.cpp boost::thread_specific_ptr -> thread_local
  std::unique_ptr.
- init.cpp boost::thread_group rewritten as std::vector<std::thread> with
  manual join loop. boost::thread::hardware_concurrency ->
  std::thread::hardware_concurrency.
- main.cpp/wallet.cpp -blocknotify/-walletnotify shell-out threads now use
  std::thread(...).detach() — fixes a latent bug where modern boost::thread
  destructor would call std::terminate on the joinable thread.
- util.cpp NewThread now catches std::system_error.
- No interruption_point/interrupt usage anywhere — pure mechanical swap.

boost::chrono / boost::posix_time -> std::chrono (3 of 5 files):
- util.h: MilliSleep, GetTimeMillis, GetTimeMicros rewritten on std::chrono
  (system_clock for epoch math, sleep_for for delays).
- snapshotnet.cpp: sleep_for swapped.
- DoS_tests.cpp: timing harness uses steady_clock.
- Skipped: rpcdump.cpp (boost::posix_time::time_input_facet has no clean
  std::get_time equivalent) and qt/qtipcserver.cpp (locked to
  boost::posix_time by boost::interprocess::message_queue::timed_receive).

Other housekeeping:
- Dropped unnecessary "using namespace boost;" from txdb-leveldb.cpp,
  txdb-rocksdb.cpp, walletdb.cpp, db.cpp (verified no unqualified boost
  names in those TUs).
- Removed unused extern declaration for clearwallettransactions.

Build fixes for non-unity builds on MinGW64/GCC 15:
- net.cpp: dropped stale #include "irc.h".
- addrman.cpp + main.cpp: explicit <cmath> include for sqrt/pow (was
  arriving transitively via boost headers).
- rpcblockchain.cpp + init.cpp: defensive #undef STRICT/ADVISORY/PERMISSIVE
  since windows.h macros collide with the Checkpoints:: enum values when
  std headers reorder include flow.
- tor_embed_hooks.cpp: triangles_tor_check_interrupted now polls fShutdown
  instead of boost::this_thread::interruption_requested (we never used
  boost interruption — the hook was always effectively a no-op).
- snapshotnet.cpp: fs::remove error handle uses std::error_code.
- serialize.h: added <ios> for std::ios::badbit/failbit (was relying on
  transitive include via boost).

Note: unity builds currently fail on this branch due to std::byte (C++17)
colliding with COM 'byte' typedef from shlobj.h when 'using namespace std;'
from earlier files in the unity slice leaks into util.cpp's parse of
shlobj.h. Build with -DENABLE_UNITY_BUILD=OFF (the default).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-26 15:10:40 -07:00
parent 2b5471283e
commit 2ba0ecf428
60 changed files with 382 additions and 1639 deletions
-11
View File
@@ -1,11 +0,0 @@
{
"permissions": {
"allow": [
"Bash(C:/msys64/msys2_shell.cmd -mingw64 -defterm -no-start -here -c \"ls /mingw64/lib/libboost_system* 2>/dev/null\")",
"Bash(git tag:*)"
],
"additionalDirectories": [
"C:\\msys64\\mingw64\\bin"
]
}
}
+3
View File
@@ -1,3 +1,6 @@
# Per-user Claude Code settings (machine-specific paths/permissions)
.claude/
# Build artifacts
*.o
*.exe
+1 -1
View File
@@ -72,7 +72,7 @@ include(AddCompilerFlags)
# ── Find required dependencies ──
find_package(OpenSSL REQUIRED)
find_package(Boost 1.71 REQUIRED COMPONENTS
filesystem program_options thread chrono
program_options thread chrono
)
if(BUILD_TESTS)
find_package(Boost REQUIRED COMPONENTS unit_test_framework)
+6 -8
View File
@@ -38,13 +38,11 @@ target_include_directories(json_compat INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/js
# EXCLUDES init.cpp, wallet.cpp (QT_GUI-conditional), noui.cpp (target-specific)
# ═══════════════════════════════════════════════════════════════════════════════
set(CORE_SOURCES
alert.cpp
addrman.cpp
bootstrap.cpp
checkpoints.cpp
crypter.cpp
db.cpp
irc.cpp
key.cpp
keystore.cpp
main.cpp
@@ -74,6 +72,7 @@ set(CORE_SOURCES
rpcsmessage.cpp
zmqpublishnotifier.cpp
txdb-base.cpp
txdb-factory.cpp
txdb-leveldb.cpp
utxosnapshot.cpp
snapshotnet.cpp
@@ -120,7 +119,6 @@ target_link_libraries(triangles_common PUBLIC
leveldb_bundled
OpenSSL::SSL
OpenSSL::Crypto
Boost::filesystem
Boost::program_options
Boost::thread
Boost::chrono
@@ -217,11 +215,11 @@ target_precompile_headers(triangles_common PRIVATE
"$<$<COMPILE_LANGUAGE:CXX>:<cstring$<ANGLE-R>>"
"$<$<COMPILE_LANGUAGE:CXX>:<memory$<ANGLE-R>>"
"$<$<COMPILE_LANGUAGE:CXX>:<functional$<ANGLE-R>>"
"$<$<COMPILE_LANGUAGE:CXX>:<boost/filesystem.hpp$<ANGLE-R>>"
"$<$<COMPILE_LANGUAGE:CXX>:<boost/filesystem/fstream.hpp$<ANGLE-R>>"
"$<$<COMPILE_LANGUAGE:CXX>:<boost/thread.hpp$<ANGLE-R>>"
"$<$<COMPILE_LANGUAGE:CXX>:<boost/thread/mutex.hpp$<ANGLE-R>>"
"$<$<COMPILE_LANGUAGE:CXX>:<boost/thread/condition_variable.hpp$<ANGLE-R>>"
"$<$<COMPILE_LANGUAGE:CXX>:<filesystem$<ANGLE-R>>"
"$<$<COMPILE_LANGUAGE:CXX>:<fstream$<ANGLE-R>>"
"$<$<COMPILE_LANGUAGE:CXX>:<thread$<ANGLE-R>>"
"$<$<COMPILE_LANGUAGE:CXX>:<mutex$<ANGLE-R>>"
"$<$<COMPILE_LANGUAGE:CXX>:<condition_variable$<ANGLE-R>>"
"$<$<COMPILE_LANGUAGE:CXX>:<boost/algorithm/string.hpp$<ANGLE-R>>"
"$<$<COMPILE_LANGUAGE:CXX>:<openssl/sha.h$<ANGLE-R>>"
"$<$<COMPILE_LANGUAGE:CXX>:<openssl/crypto.h$<ANGLE-R>>"
+2
View File
@@ -4,6 +4,8 @@
#include "addrman.h"
#include <cmath>
using namespace std;
int CAddrInfo::GetTriedBucket(const std::vector<unsigned char> &nKey) const
-276
View File
@@ -1,276 +0,0 @@
//
// Alert system
//
#include <algorithm>
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <map>
#include "alert.h"
#include "key.h"
#include "net.h"
#include "sync.h"
#include "ui_interface.h"
using namespace std;
map<uint256, CAlert> mapAlerts;
CCriticalSection cs_mapAlerts;
// Alert keys disabled for decentralization - v5 hard fork
static const char* pszMainKey = "";
// TestNet alerts pubKey
static const char* pszTestKey = "";
void CUnsignedAlert::SetNull()
{
nVersion = 1;
nRelayUntil = 0;
nExpiration = 0;
nID = 0;
nCancel = 0;
setCancel.clear();
nMinVer = 0;
nMaxVer = 0;
setSubVer.clear();
nPriority = 0;
strComment.clear();
strStatusBar.clear();
strReserved.clear();
}
std::string CUnsignedAlert::ToString() const
{
std::string strSetCancel;
for (int n : setCancel)
strSetCancel += strprintf("%d ", n);
std::string strSetSubVer;
for (std::string str : setSubVer)
strSetSubVer += "\"" + str + "\" ";
return strprintf(
"CAlert(\n"
" nVersion = %d\n"
" nRelayUntil = %" PRId64 "\n"
" nExpiration = %" PRId64 "\n"
" nID = %d\n"
" nCancel = %d\n"
" setCancel = %s\n"
" nMinVer = %d\n"
" nMaxVer = %d\n"
" setSubVer = %s\n"
" nPriority = %d\n"
" strComment = \"%s\"\n"
" strStatusBar = \"%s\"\n"
")\n",
nVersion,
nRelayUntil,
nExpiration,
nID,
nCancel,
strSetCancel.c_str(),
nMinVer,
nMaxVer,
strSetSubVer.c_str(),
nPriority,
strComment.c_str(),
strStatusBar.c_str());
}
void CUnsignedAlert::print() const
{
printf("%s", ToString().c_str());
}
void CAlert::SetNull()
{
CUnsignedAlert::SetNull();
vchMsg.clear();
vchSig.clear();
}
bool CAlert::IsNull() const
{
return (nExpiration == 0);
}
uint256 CAlert::GetHash() const
{
return Hash(this->vchMsg.begin(), this->vchMsg.end());
}
bool CAlert::IsInEffect() const
{
return (GetAdjustedTime() < nExpiration);
}
bool CAlert::Cancels(const CAlert& alert) const
{
if (!IsInEffect())
return false; // this was a no-op before 31403
return (alert.nID <= nCancel || setCancel.count(alert.nID));
}
bool CAlert::AppliesTo(int nVersion, std::string strSubVerIn) const
{
// TODO: rework for client-version-embedded-in-strSubVer ?
return (IsInEffect() &&
nMinVer <= nVersion && nVersion <= nMaxVer &&
(setSubVer.empty() || setSubVer.count(strSubVerIn)));
}
bool CAlert::AppliesToMe() const
{
return AppliesTo(PROTOCOL_VERSION, FormatSubVersion(CLIENT_NAME, CLIENT_VERSION, std::vector<std::string>()));
}
bool CAlert::RelayTo(CNode* pnode) const
{
if (!IsInEffect())
return false;
// returns true if wasn't already contained in the set
if (pnode->setKnown.insert(GetHash()).second)
{
if (AppliesTo(pnode->nVersion, pnode->strSubVer) ||
AppliesToMe() ||
GetAdjustedTime() < nRelayUntil)
{
pnode->PushMessage("alert", *this);
return true;
}
}
return false;
}
bool CAlert::CheckSignature() const
{
// Alert key system disabled for decentralization - v5 hard fork
const char* pszKey = fTestNet ? pszTestKey : pszMainKey;
if (pszKey[0] == '\0')
return false; // No alerts accepted without a valid key
CKey key;
if (!key.SetPubKey(ParseHex(pszKey)))
return error("CAlert::CheckSignature() : SetPubKey failed");
if (!key.Verify(Hash(vchMsg.begin(), vchMsg.end()), vchSig))
return error("CAlert::CheckSignature() : verify signature failed");
// Now unserialize the data
CDataStream sMsg(vchMsg, SER_NETWORK, PROTOCOL_VERSION);
sMsg >> *(CUnsignedAlert*)this;
return true;
}
CAlert CAlert::getAlertByHash(const uint256 &hash)
{
CAlert retval;
{
LOCK(cs_mapAlerts);
map<uint256, CAlert>::iterator mi = mapAlerts.find(hash);
if(mi != mapAlerts.end())
retval = mi->second;
}
return retval;
}
bool CAlert::ProcessAlert(bool fThread)
{
if (!CheckSignature())
return false;
if (!IsInEffect())
return false;
// alert.nID=max is reserved for if the alert key is
// compromised. It must have a pre-defined message,
// must never expire, must apply to all versions,
// and must cancel all previous
// alerts or it will be ignored (so an attacker can't
// send an "everything is OK, don't panic" version that
// cannot be overridden):
int maxInt = std::numeric_limits<int>::max();
if (nID == maxInt)
{
if (!(
nExpiration == maxInt &&
nCancel == (maxInt-1) &&
nMinVer == 0 &&
nMaxVer == maxInt &&
setSubVer.empty() &&
nPriority == maxInt &&
strStatusBar == "URGENT: Alert key compromised, upgrade required"
))
return false;
}
{
LOCK(cs_mapAlerts);
// Cancel previous alerts
for (map<uint256, CAlert>::iterator mi = mapAlerts.begin(); mi != mapAlerts.end();)
{
const CAlert& alert = (*mi).second;
if (Cancels(alert))
{
printf("cancelling alert %d\n", alert.nID);
uiInterface.NotifyAlertChanged((*mi).first, CT_DELETED);
mapAlerts.erase(mi++);
}
else if (!alert.IsInEffect())
{
printf("expiring alert %d\n", alert.nID);
uiInterface.NotifyAlertChanged((*mi).first, CT_DELETED);
mapAlerts.erase(mi++);
}
else
mi++;
}
// Check if this alert has been cancelled
for (auto& item : mapAlerts)
{
const CAlert& alert = item.second;
if (alert.Cancels(*this))
{
printf("alert already cancelled by %d\n", alert.nID);
return false;
}
}
// Add to mapAlerts
mapAlerts.insert(make_pair(GetHash(), *this));
// Notify UI and -alertnotify if it applies to me
if(AppliesToMe())
{
uiInterface.NotifyAlertChanged(GetHash(), CT_NEW);
std::string strCmd = GetArg("-alertnotify", "");
if (!strCmd.empty())
{
// Alert text should be plain ascii coming from a trusted source, but to
// be safe we first strip anything not in safeChars, then add single quotes around
// the whole string before passing it to the shell:
std::string singleQuote("'");
// safeChars chosen to allow simple messages/URLs/email addresses, but avoid anything
// even possibly remotely dangerous like & or >
std::string safeChars("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890 .,;_/:?@");
std::string safeStatus;
for (std::string::size_type i = 0; i < strStatusBar.size(); i++)
{
if (safeChars.find(strStatusBar[i]) != std::string::npos)
safeStatus.push_back(strStatusBar[i]);
}
safeStatus = singleQuote+safeStatus+singleQuote;
boost::replace_all(strCmd, "%s", safeStatus);
if (fThread)
boost::thread t(runCommand, strCmd); // thread runs free
else
runCommand(strCmd);
}
}
}
printf("accepted alert %d, AppliesToMe()=%d\n", nID, AppliesToMe());
return true;
}
-104
View File
@@ -1,104 +0,0 @@
// Copyright (c) 2010 Satoshi Nakamoto
// Copyright (c) 2009-2012 The Bitcoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef _TRIANGLESALERT_H_
#define _TRIANGLESALERT_H_ 1
#include <set>
#include <string>
#include "uint256.h"
#include "util.h"
class CNode;
/** Alerts are for notifying old versions if they become too obsolete and
* need to upgrade. The message is displayed in the status bar.
* Alert messages are broadcast as a vector of signed data. Unserializing may
* not read the entire buffer if the alert is for a newer version, but older
* versions can still relay the original data.
*/
class CUnsignedAlert
{
public:
int nVersion;
int64_t nRelayUntil; // when newer nodes stop relaying to newer nodes
int64_t nExpiration;
int nID;
int nCancel;
std::set<int> setCancel;
int nMinVer; // lowest version inclusive
int nMaxVer; // highest version inclusive
std::set<std::string> setSubVer; // empty matches all
int nPriority;
// Actions
std::string strComment;
std::string strStatusBar;
std::string strReserved;
IMPLEMENT_SERIALIZE
(
READWRITE(this->nVersion);
nVersion = this->nVersion;
READWRITE(nRelayUntil);
READWRITE(nExpiration);
READWRITE(nID);
READWRITE(nCancel);
READWRITE(setCancel);
READWRITE(nMinVer);
READWRITE(nMaxVer);
READWRITE(setSubVer);
READWRITE(nPriority);
READWRITE(strComment);
READWRITE(strStatusBar);
READWRITE(strReserved);
)
void SetNull();
std::string ToString() const;
void print() const;
};
/** An alert is a combination of a serialized CUnsignedAlert and a signature. */
class CAlert : public CUnsignedAlert
{
public:
std::vector<unsigned char> vchMsg;
std::vector<unsigned char> vchSig;
CAlert()
{
SetNull();
}
IMPLEMENT_SERIALIZE
(
READWRITE(vchMsg);
READWRITE(vchSig);
)
void SetNull();
bool IsNull() const;
uint256 GetHash() const;
bool IsInEffect() const;
bool Cancels(const CAlert& alert) const;
bool AppliesTo(int nVersion, std::string strSubVerIn) const;
bool AppliesToMe() const;
bool RelayTo(CNode* pnode) const;
bool CheckSignature() const;
bool ProcessAlert(bool fThread = true);
/*
* Get copy of (active) alert object by hash. Returns a null alert if it is not found.
*/
static CAlert getAlertByHash(const uint256 &hash);
};
#endif
+5 -5
View File
@@ -7,7 +7,7 @@
#include <string.h>
#include <string>
#include <boost/thread/mutex.hpp>
#include <mutex>
#include <map>
#ifdef WIN32
@@ -55,7 +55,7 @@ public:
// For all pages in affected range, increase lock count
void LockRange(void *p, size_t size)
{
boost::mutex::scoped_lock lock(mutex);
std::lock_guard<std::mutex> lock(mutex);
if(!size) return;
const size_t base_addr = reinterpret_cast<size_t>(p);
const size_t start_page = base_addr & page_mask;
@@ -78,7 +78,7 @@ public:
// For all pages in affected range, decrease lock count
void UnlockRange(void *p, size_t size)
{
boost::mutex::scoped_lock lock(mutex);
std::lock_guard<std::mutex> lock(mutex);
if(!size) return;
const size_t base_addr = reinterpret_cast<size_t>(p);
const size_t start_page = base_addr & page_mask;
@@ -101,13 +101,13 @@ public:
// Get number of locked pages for diagnostics
int GetLockedPageCount()
{
boost::mutex::scoped_lock lock(mutex);
std::lock_guard<std::mutex> lock(mutex);
return histogram.size();
}
private:
Locker locker;
boost::mutex mutex;
std::mutex mutex;
size_t page_size, page_mask;
// map of page base address to lock count
typedef std::map<size_t,int> Histogram;
+3 -3
View File
@@ -4,8 +4,8 @@
#include "bootstrap.h"
#include "utxosnapshot.h"
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <filesystem>
#include <fstream>
#include <boost/algorithm/string.hpp>
#include <zlib.h>
@@ -37,7 +37,7 @@
extern bool fTestNet;
namespace Checkpoints { bool IsKnownCheckpoint(int nHeight, const uint256& hash); }
namespace fs = boost::filesystem;
namespace fs = std::filesystem;
namespace Bootstrap {
+6 -6
View File
@@ -7,7 +7,7 @@
#include <string>
#include <vector>
#include <functional>
#include <boost/filesystem.hpp>
#include <filesystem>
namespace Bootstrap {
@@ -20,14 +20,14 @@ namespace Bootstrap {
typedef std::function<void(int64_t, int64_t)> ProgressCallback;
// Check if data dir already has blockchain data
bool NeedsBootstrap(const boost::filesystem::path& dataDir);
bool NeedsBootstrap(const std::filesystem::path& dataDir);
// Download a single file via HTTP GET, write to destPath.
// If noProxy is true, bypass Tor SOCKS proxy and connect directly
// (used for clearnet bootstrap downloads).
// If portOverride is set (>0), uses that port instead of the default PORT.
bool DownloadFile(const std::string& host, const std::string& urlPath,
const boost::filesystem::path& destPath,
const std::filesystem::path& destPath,
ProgressCallback progressFn,
std::string& strError,
bool noProxy = false,
@@ -42,7 +42,7 @@ namespace Bootstrap {
// Download bootstrap.tar.gz and extract to dataDir.
// Falls back to filelist.txt + individual file download if tar.gz unavailable.
bool DownloadBootstrap(const std::string& host,
const boost::filesystem::path& dataDir,
const std::filesystem::path& dataDir,
ProgressCallback progressFn,
std::string& strError);
@@ -56,7 +56,7 @@ namespace Bootstrap {
};
// Parse a snapshot.manifest file into a SnapshotManifest struct.
bool ParseManifest(const boost::filesystem::path& manifestPath,
bool ParseManifest(const std::filesystem::path& manifestPath,
SnapshotManifest& manifest,
std::string& strError);
@@ -68,7 +68,7 @@ namespace Bootstrap {
// This is much faster than downloading the full bootstrap archive.
// Returns true if snapshot was downloaded and loaded successfully.
bool DownloadUtxoSnapshot(const std::string& host,
const boost::filesystem::path& dataDir,
const std::filesystem::path& dataDir,
ProgressCallback progressFn,
std::string& strError);
+4 -4
View File
@@ -198,7 +198,7 @@ namespace Checkpoints
bool WriteSyncCheckpoint(const uint256& hashCheckpoint)
{
CTxDB txdb;
auto txdb_holder = MakeChainDB(); CTxDBBase& txdb = *txdb_holder;
txdb.TxnBegin();
if (!txdb.WriteSyncCheckpoint(hashCheckpoint))
{
@@ -224,7 +224,7 @@ namespace Checkpoints
return false;
}
CTxDB txdb;
auto txdb_holder = MakeChainDB(); CTxDBBase& txdb = *txdb_holder;
CBlockIndex* pindexCheckpoint = mapBlockIndex[hashPendingCheckpoint];
if (!pindexCheckpoint->IsInMainChain())
{
@@ -295,7 +295,7 @@ namespace Checkpoints
{
// checkpoint block accepted but not yet in main chain
printf("ResetSyncCheckpoint: SetBestChain to hardened checkpoint %s\n", hash.ToString().c_str());
CTxDB txdb;
auto txdb_holder = MakeChainDB(); CTxDBBase& txdb = *txdb_holder;
CBlock block;
if (!block.ReadFromDisk(mapBlockIndex[hash]))
return error("ResetSyncCheckpoint: ReadFromDisk failed for hardened checkpoint %s", hash.ToString().c_str());
@@ -439,7 +439,7 @@ bool CSyncCheckpoint::ProcessSyncCheckpoint(CNode* pfrom)
if (!Checkpoints::ValidateSyncCheckpoint(hashCheckpoint))
return false;
CTxDB txdb;
auto txdb_holder = MakeChainDB(); CTxDBBase& txdb = *txdb_holder;
CBlockIndex* pindexCheckpoint = mapBlockIndex[hashCheckpoint];
if (!pindexCheckpoint->IsInMainChain())
{
+10 -10
View File
@@ -9,17 +9,17 @@
#include <deque>
#include <vector>
#include <boost/thread/condition_variable.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/thread.hpp>
#include <condition_variable>
#include <mutex>
#include <thread>
template<typename T>
class CCheckQueue
{
private:
boost::mutex mutex;
boost::condition_variable condWorker;
boost::condition_variable condMaster;
std::mutex mutex;
std::condition_variable condWorker;
std::condition_variable condMaster;
std::deque<T> queue;
unsigned int nIdle;
@@ -32,7 +32,7 @@ private:
bool Loop(bool fMaster)
{
boost::unique_lock<boost::mutex> lock(mutex);
std::unique_lock<std::mutex> lock(mutex);
if (!fMaster)
nTotal++;
nIdle++;
@@ -102,7 +102,7 @@ public:
void StartBatch()
{
boost::unique_lock<boost::mutex> lock(mutex);
std::unique_lock<std::mutex> lock(mutex);
fAllOk = true;
nTodo = 0;
}
@@ -112,7 +112,7 @@ public:
if (vChecks.empty())
return;
boost::unique_lock<boost::mutex> lock(mutex);
std::unique_lock<std::mutex> lock(mutex);
for (typename std::vector<T>::iterator it = vChecks.begin(); it != vChecks.end(); ++it)
{
queue.push_back(T());
@@ -132,7 +132,7 @@ public:
void Quit()
{
boost::unique_lock<boost::mutex> lock(mutex);
std::unique_lock<std::mutex> lock(mutex);
fQuit = true;
condWorker.notify_all();
condMaster.notify_all();
+3 -4
View File
@@ -8,16 +8,15 @@
#include "util.h"
#include "main.h"
#include "ui_interface.h"
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <filesystem>
#include <fstream>
#ifndef WIN32
#include "sys/stat.h"
#endif
using namespace std;
using namespace boost;
namespace fs = boost::filesystem;
namespace fs = std::filesystem;
unsigned int nWalletDBUpdated;
+5 -4
View File
@@ -7,6 +7,7 @@
#include "main.h"
#include <filesystem>
#include <map>
#include <string>
#include <vector>
@@ -28,7 +29,7 @@ extern unsigned int nWalletDBUpdated;
void ThreadFlushWalletDB(void* parg);
bool BackupWallet(const CWallet& wallet, const std::string& strDest);
bool AutoBackupWallet(const boost::filesystem::path& walletPath);
bool AutoBackupWallet(const std::filesystem::path& walletPath);
class CDBEnv
@@ -37,7 +38,7 @@ private:
bool fDetachDB;
bool fDbEnvInit;
bool fMockDb;
boost::filesystem::path pathEnv;
std::filesystem::path pathEnv;
std::string strPath;
void EnvShutdown();
@@ -71,7 +72,7 @@ public:
typedef std::pair<std::vector<unsigned char>, std::vector<unsigned char> > KeyValPair;
bool Salvage(std::string strFile, bool fAggressive, std::vector<KeyValPair>& vResult);
bool Open(boost::filesystem::path pathEnv_);
bool Open(std::filesystem::path pathEnv_);
void Close();
void Flush(bool fShutdown);
void CheckpointLSN(std::string strFile);
@@ -317,7 +318,7 @@ public:
class CAddrDB
{
private:
boost::filesystem::path pathAddr;
std::filesystem::path pathAddr;
public:
CAddrDB();
bool Write(const CAddrMan& addr);
+26 -16
View File
@@ -24,10 +24,10 @@
#endif
#include "notificationqueue.h"
#include "addressindex.h"
#include <boost/thread.hpp>
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
// boost/filesystem/convenience.hpp removed in modern Boost; functionality is in filesystem.hpp
#include <thread>
#include <vector>
#include <filesystem>
#include <fstream>
#include <boost/interprocess/sync/file_lock.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <openssl/crypto.h>
@@ -36,10 +36,20 @@
#include <signal.h>
#endif
// Windows.h (transitively included) defines these as macros, clobbering Checkpoints:: enum values.
#ifdef STRICT
#undef STRICT
#endif
#ifdef ADVISORY
#undef ADVISORY
#endif
#ifdef PERMISSIVE
#undef PERMISSIVE
#endif
using namespace std;
using namespace boost;
namespace fs = boost::filesystem;
namespace fs = std::filesystem;
CWallet* pwalletMain;
CClientUIInterface uiInterface;
@@ -54,7 +64,7 @@ enum Checkpoints::CPMode CheckpointsMode;
static CCriticalSection cs_DeferredStartup;
static bool fDeferredStartupRunning = false;
static boost::thread_group* pScriptCheckThreads = NULL;
static std::vector<std::thread>* pScriptCheckThreads = nullptr;
static void ThreadScriptCheck()
{
@@ -223,9 +233,10 @@ void Shutdown(void* parg)
pScriptCheckQueue->Quit();
if (pScriptCheckThreads)
{
pScriptCheckThreads->join_all();
for (std::thread& t : *pScriptCheckThreads)
if (t.joinable()) t.join();
delete pScriptCheckThreads;
pScriptCheckThreads = NULL;
pScriptCheckThreads = nullptr;
}
delete pScriptCheckQueue;
pScriptCheckQueue = NULL;
@@ -250,7 +261,7 @@ void Shutdown(void* parg)
pNotificationQueue = NULL;
}
// CTxDB().Close();
// MakeChainDB()->Close();
bitdb.Flush(false);
bitdb.Flush(true);
fs::remove(GetPidFile());
@@ -469,7 +480,6 @@ std::string HelpMessage()
" -walletnotify=<cmd> " + _("Execute command when a wallet transaction changes (%s in cmd is replaced by TxID)") + "\n" +
" -confchange " + _("Require a confirmations for change (default: 0)") + "\n" +
" -enforcecanonical " + _("Enforce transaction scripts to use canonical PUSH operators (default: 1)") + "\n" +
" -alertnotify=<cmd> " + _("Execute command when a relevant alert is received (%s in cmd is replaced by message)") + "\n" +
" -upgradewallet " + _("Upgrade wallet to latest format") + "\n" +
" -keypool=<n> " + _("Set key pool size to <n> (default: 100)") + "\n" +
" -rescan " + _("Rescan the block chain for missing wallet transactions") + "\n" +
@@ -691,15 +701,15 @@ bool AppInit2()
int nScriptCheckThreads = GetArg("-par", 0);
if (nScriptCheckThreads <= 0)
nScriptCheckThreads = boost::thread::hardware_concurrency();
nScriptCheckThreads = std::thread::hardware_concurrency();
if (nScriptCheckThreads > 16)
nScriptCheckThreads = 16;
if (nScriptCheckThreads > 1)
{
pScriptCheckQueue = new CCheckQueue<CScriptCheck>(32);
pScriptCheckThreads = new boost::thread_group();
pScriptCheckThreads = new std::vector<std::thread>();
for (int i = 0; i < nScriptCheckThreads - 1; ++i)
pScriptCheckThreads->create_thread(&ThreadScriptCheck);
pScriptCheckThreads->emplace_back(&ThreadScriptCheck);
printf("Script verification threads: %d workers + main thread\n", nScriptCheckThreads - 1);
}
@@ -1024,7 +1034,7 @@ bool AppInit2()
if (GetBoolArg("-loadblockindextest"))
{
CTxDB txdb("r");
auto txdb_holder = MakeChainDB("r"); CTxDBBase& txdb = *txdb_holder;
txdb.LoadBlockIndex();
PrintBlockTree();
return false;
@@ -1051,7 +1061,7 @@ bool AppInit2()
// If the block index is empty but blk0001.dat exists (bootstrap download),
// fast-import: build the index directly from the block file without re-writing
// data. Batches LevelDB commits every 200K blocks for speed.
if (nBestHeight == 0 && boost::filesystem::exists(GetDataDir() / "blk0001.dat")
if (nBestHeight == 0 && std::filesystem::exists(GetDataDir() / "blk0001.dat")
&& mapBlockIndex.size() <= 1)
{
uiInterface.InitMessage(_("Importing bootstrap blocks..."));
@@ -1224,7 +1234,7 @@ bool AppInit2()
bool fScannedWithIndex = false;
if (fAddressIndex && !GetBoolArg("-rescan"))
{
CTxDB txdb("r");
auto txdb_holder = MakeChainDB("r"); CTxDBBase& txdb = *txdb_holder;
int nAddressIndexStartHeight = 0;
uint256 hashAddressIndexBestChain = 0;
if (txdb.ReadAddressIndexStartHeight(nAddressIndexStartHeight) &&
-405
View File
@@ -1,405 +0,0 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2012 The Bitcoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "irc.h"
#include "net.h"
#include "strlcpy.h"
#include "base58.h"
using namespace std;
using namespace boost;
int nGotIRCAddresses = 0;
void ThreadIRCSeed2(void* parg);
#pragma pack(push, 1)
struct ircaddr
{
struct in_addr ip;
short port;
};
#pragma pack(pop)
string EncodeAddress(const CService& addr)
{
struct ircaddr tmp;
if (addr.GetInAddr(&tmp.ip))
{
tmp.port = htons(addr.GetPort());
vector<unsigned char> vch(UBEGIN(tmp), UEND(tmp));
return string("u") + EncodeBase58Check(vch);
}
return "";
}
bool DecodeAddress(string str, CService& addr)
{
vector<unsigned char> vch;
if (!DecodeBase58Check(str.substr(1), vch))
return false;
struct ircaddr tmp;
if (vch.size() != sizeof(tmp))
return false;
memcpy(&tmp, &vch[0], sizeof(tmp));
addr = CService(tmp.ip, ntohs(tmp.port));
return true;
}
static bool Send(SOCKET hSocket, const char* pszSend)
{
if (strstr(pszSend, "PONG") != pszSend)
printf("IRC SENDING: %s\n", pszSend);
const char* psz = pszSend;
const char* pszEnd = psz + strlen(psz);
while (psz < pszEnd)
{
int ret = send(hSocket, psz, pszEnd - psz, MSG_NOSIGNAL);
if (ret < 0)
return false;
psz += ret;
}
return true;
}
bool RecvLineIRC(SOCKET hSocket, string& strLine)
{
while (true)
{
bool fRet = RecvLine(hSocket, strLine);
if (fRet)
{
if (fShutdown)
return false;
vector<string> vWords;
ParseString(strLine, ' ', vWords);
if (vWords.size() >= 1 && vWords[0] == "PING")
{
strLine[1] = 'O';
strLine += '\r';
Send(hSocket, strLine.c_str());
continue;
}
}
return fRet;
}
}
int RecvUntil(SOCKET hSocket, const char* psz1, const char* psz2=NULL, const char* psz3=NULL, const char* psz4=NULL)
{
while(true)
{
string strLine;
strLine.reserve(10000);
if (!RecvLineIRC(hSocket, strLine))
return 0;
printf("IRC %s\n", strLine.c_str());
if (psz1 && strLine.find(psz1) != string::npos)
return 1;
if (psz2 && strLine.find(psz2) != string::npos)
return 2;
if (psz3 && strLine.find(psz3) != string::npos)
return 3;
if (psz4 && strLine.find(psz4) != string::npos)
return 4;
}
}
bool Wait(int nSeconds)
{
if (fShutdown)
return false;
printf("IRC waiting %d seconds to reconnect\n", nSeconds);
for (int i = 0; i < nSeconds; i++)
{
if (fShutdown)
return false;
MilliSleep(1000);
}
return true;
}
bool RecvCodeLine(SOCKET hSocket, const char* psz1, string& strRet)
{
strRet.clear();
while (true)
{
string strLine;
if (!RecvLineIRC(hSocket, strLine))
return false;
vector<string> vWords;
ParseString(strLine, ' ', vWords);
if (vWords.size() < 2)
continue;
if (vWords[1] == psz1)
{
printf("IRC %s\n", strLine.c_str());
strRet = strLine;
return true;
}
}
}
bool GetIPFromIRC(SOCKET hSocket, string strMyName, CNetAddr& ipRet)
{
Send(hSocket, strprintf("USERHOST %s\r", strMyName.c_str()).c_str());
string strLine;
if (!RecvCodeLine(hSocket, "302", strLine))
return false;
vector<string> vWords;
ParseString(strLine, ' ', vWords);
if (vWords.size() < 4)
return false;
string str = vWords[3];
if (str.rfind("@") == string::npos)
return false;
string strHost = str.substr(str.rfind("@")+1);
// Hybrid IRC used by lfnet always returns IP when you userhost yourself,
// but in case another IRC is ever used this should work.
printf("GetIPFromIRC() got userhost %s\n", strHost.c_str());
CNetAddr addr(strHost, true);
if (!addr.IsValid())
return false;
ipRet = addr;
return true;
}
void ThreadIRCSeed(void* parg)
{
// Make this thread recognisable as the IRC seeding thread
RenameThread("Triangles-ircseed");
try
{
ThreadIRCSeed2(parg);
}
catch (std::exception& e) {
PrintExceptionContinue(&e, "ThreadIRCSeed()");
} catch (...) {
PrintExceptionContinue(NULL, "ThreadIRCSeed()");
}
printf("ThreadIRCSeed exited\n");
}
void ThreadIRCSeed2(void* parg)
{
// Don't connect to IRC if we won't use IPv4 connections.
if (IsLimited(NET_IPV4))
return;
// ... or if we won't make outbound connections and won't accept inbound ones.
if (mapArgs.count("-connect") && fNoListen)
return;
// ... or if IRC is not enabled.
if (!GetBoolArg("-irc", false))
return;
printf("ThreadIRCSeed started\n");
int nErrorWait = 10;
int nRetryWait = 10;
int nNameRetry = 0;
while (!fShutdown)
{
CService addrConnect("92.243.23.21", 6667); // irc.lfnet.org
CService addrIRC("irc.lfnet.org", 6667, true);
if (addrIRC.IsValid())
addrConnect = addrIRC;
SOCKET hSocket;
if (!ConnectSocket(addrConnect, hSocket))
{
printf("IRC connect failed\n");
nErrorWait = nErrorWait * 11 / 10;
if (Wait(nErrorWait += 60))
continue;
else
return;
}
if (!RecvUntil(hSocket, "Found your hostname", "using your IP address instead", "Couldn't look up your hostname", "ignoring hostname"))
{
closesocket(hSocket);
hSocket = INVALID_SOCKET;
nErrorWait = nErrorWait * 11 / 10;
if (Wait(nErrorWait += 60))
continue;
else
return;
}
CNetAddr addrIPv4("1.2.3.4"); // arbitrary IPv4 address to make GetLocal prefer IPv4 addresses
CService addrLocal;
string strMyName;
// Don't use our IP as our nick if we're not listening
// or if it keeps failing because the nick is already in use.
if (!fNoListen && GetLocal(addrLocal, &addrIPv4) && nNameRetry<3)
strMyName = EncodeAddress(GetLocalAddress(&addrConnect));
if (strMyName == "")
strMyName = strprintf("x%" PRIu64 "", GetRand(1000000000));
Send(hSocket, strprintf("NICK %s\r", strMyName.c_str()).c_str());
Send(hSocket, strprintf("USER %s 8 * : %s\r", strMyName.c_str(), strMyName.c_str()).c_str());
int nRet = RecvUntil(hSocket, " 004 ", " 433 ");
if (nRet != 1)
{
closesocket(hSocket);
hSocket = INVALID_SOCKET;
if (nRet == 2)
{
printf("IRC name already in use\n");
nNameRetry++;
Wait(10);
continue;
}
nErrorWait = nErrorWait * 11 / 10;
if (Wait(nErrorWait += 60))
continue;
else
return;
}
nNameRetry = 0;
MilliSleep(500);
// Get our external IP from the IRC server and re-nick before joining the channel
CNetAddr addrFromIRC;
if (GetIPFromIRC(hSocket, strMyName, addrFromIRC))
{
printf("GetIPFromIRC() returned %s\n", addrFromIRC.ToString().c_str());
// Don't use our IP as our nick if we're not listening
if (!fNoListen && addrFromIRC.IsRoutable())
{
// IRC lets you to re-nick
AddLocal(addrFromIRC, LOCAL_IRC);
strMyName = EncodeAddress(GetLocalAddress(&addrConnect));
Send(hSocket, strprintf("NICK %s\r", strMyName.c_str()).c_str());
}
}
if (fTestNet) {
Send(hSocket, "JOIN #TrianglesTEST\r");
Send(hSocket, "WHO #TrianglesTEST\r");
} else {
// randomly join
// int channel_number = GetRandInt(5);
// Channel number is always 0 for initial release
int channel_number = 0;
Send(hSocket, strprintf("JOIN #Triangles%02d\r", channel_number).c_str());
Send(hSocket, strprintf("WHO #Triangles%02d\r", channel_number).c_str());
}
int64_t nStart = GetTime();
string strLine;
strLine.reserve(10000);
while (!fShutdown && RecvLineIRC(hSocket, strLine))
{
if (strLine.empty() || strLine.size() > 900 || strLine[0] != ':')
continue;
vector<string> vWords;
ParseString(strLine, ' ', vWords);
if (vWords.size() < 2)
continue;
char pszName[10000];
pszName[0] = '\0';
if (vWords[1] == "352" && vWords.size() >= 8)
{
// index 7 is limited to 16 characters
// could get full length name at index 10, but would be different from join messages
strlcpy(pszName, vWords[7].c_str(), sizeof(pszName));
printf("IRC got who\n");
}
if (vWords[1] == "JOIN" && vWords[0].size() > 1)
{
// :username!username@50000007.F000000B.90000002.IP JOIN :#channelname
strlcpy(pszName, vWords[0].c_str() + 1, sizeof(pszName));
if (strchr(pszName, '!'))
*strchr(pszName, '!') = '\0';
printf("IRC got join\n");
}
if (pszName[0] == 'u')
{
CAddress addr;
if (DecodeAddress(pszName, addr))
{
addr.nTime = GetAdjustedTime();
if (addrman.Add(addr, addrConnect, 51 * 60))
printf("IRC got new address: %s\n", addr.ToString().c_str());
nGotIRCAddresses++;
}
else
{
printf("IRC decode failed\n");
}
}
}
closesocket(hSocket);
hSocket = INVALID_SOCKET;
if (GetTime() - nStart > 20 * 60)
{
nErrorWait /= 3;
nRetryWait /= 3;
}
nRetryWait = nRetryWait * 11 / 10;
if (!Wait(nRetryWait += 60))
return;
}
}
#ifdef TEST
int main(int argc, char *argv[])
{
WSADATA wsadata;
if (WSAStartup(MAKEWORD(2,2), &wsadata) != NO_ERROR)
{
printf("Error at WSAStartup()\n");
return false;
}
ThreadIRCSeed(NULL);
WSACleanup();
return 0;
}
#endif
-12
View File
@@ -1,12 +0,0 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2012 The Bitcoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef TRIANGLES_IRC_H
#define TRIANGLES_IRC_H
void ThreadIRCSeed(void* parg);
extern int nGotIRCAddresses;
#endif
+1 -1
View File
@@ -386,7 +386,7 @@ bool CheckProofOfStake(const CTransaction& tx, unsigned int nBits, uint256& hash
const CTxIn& txin = tx.vin[0];
// First try finding the previous transaction in database
CTxDB txdb("r");
auto txdb_holder = MakeChainDB("r"); CTxDBBase& txdb = *txdb_holder;
CTransaction txPrev;
CTxIndex txindex;
if (!txPrev.ReadFromDisk(txdb, txin.prevout, txindex))
+31 -144
View File
@@ -3,9 +3,10 @@
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "alert.h"
#include "checkpoints.h"
#include "db.h"
#include <cmath>
#include "txdb.h"
#include "net.h"
#include "init.h"
@@ -23,13 +24,13 @@
#include <algorithm>
#include <deque>
#include <boost/algorithm/string/replace.hpp>
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <filesystem>
#include <fstream>
using namespace std;
using namespace boost;
namespace fs = boost::filesystem;
namespace fs = std::filesystem;
//
// Global state
@@ -931,7 +932,7 @@ bool CTransaction::ReadFromDisk(CTxDBBase& txdb, COutPoint prevout)
bool CTransaction::ReadFromDisk(COutPoint prevout)
{
CTxDB txdb("r");
auto txdb_holder = MakeChainDB("r"); CTxDBBase& txdb = *txdb_holder;
CTxIndex txindex;
return ReadFromDisk(txdb, prevout, txindex);
}
@@ -1064,7 +1065,7 @@ int CMerkleTx::SetMerkleBranch(const CBlock* pblock)
{
// Load the block this tx is in
CTxIndex txindex;
if (!CTxDB("r").ReadTxIndex(GetHash(), txindex))
if (!MakeChainDB("r")->ReadTxIndex(GetHash(), txindex))
return 0;
if (!blockTmp.ReadFromDisk(txindex.pos.nFile, txindex.pos.nBlockPos))
return 0;
@@ -1487,7 +1488,7 @@ bool CMerkleTx::AcceptToMemoryPool(CTxDBBase& txdb, bool fCheckInputs)
bool CMerkleTx::AcceptToMemoryPool()
{
CTxDB txdb("r");
auto txdb_holder = MakeChainDB("r"); CTxDBBase& txdb = *txdb_holder;
return AcceptToMemoryPool(txdb);
}
@@ -1515,7 +1516,7 @@ bool CWalletTx::AcceptWalletTransaction(CTxDBBase& txdb, bool fCheckInputs)
bool CWalletTx::AcceptWalletTransaction()
{
CTxDB txdb("r");
auto txdb_holder = MakeChainDB("r"); CTxDBBase& txdb = *txdb_holder;
return AcceptWalletTransaction(txdb);
}
@@ -1548,7 +1549,7 @@ bool GetTransaction(const uint256 &hash, CTransaction &tx, uint256 &hashBlock)
return true;
}
}
CTxDB txdb("r");
auto txdb_holder = MakeChainDB("r"); CTxDBBase& txdb = *txdb_holder;
CTxIndex txindex;
if (tx.ReadFromDisk(txdb, COutPoint(hash, 0), txindex))
{
@@ -1837,6 +1838,12 @@ int GetNumBlocksOfPeers()
bool IsInitialBlockDownload()
{
// Bootstrap escape hatch: when the network has stalled and every node
// thinks it is in IBD because the tip is older than 24h, -forcestaking
// lets a single operator mint the first block to unstick the chain.
if (GetBoolArg("-forcestaking", false) && pindexBest != NULL &&
nBestHeight >= Checkpoints::GetTotalBlocksEstimate())
return false;
if (pindexBest == NULL || nBestHeight < Checkpoints::GetTotalBlocksEstimate())
return true;
static int64_t nLastUpdate;
@@ -1858,7 +1865,7 @@ void static InvalidChainFound(CBlockIndex* pindexNew)
if (pindexNew->nChainTrust > nBestInvalidTrust)
{
nBestInvalidTrust = pindexNew->nChainTrust;
CTxDB().WriteBestInvalidTrust(CBigNum(nBestInvalidTrust));
MakeChainDB()->WriteBestInvalidTrust(CBigNum(nBestInvalidTrust));
uiInterface.NotifyBlocksChanged();
}
@@ -1975,8 +1982,12 @@ bool CTransaction::FetchInputs(CTxDBBase& txdb, const MapPrevTx& mapPendingUtxos
}
else
{
// Backfill to UTXO DB for future lookups
txdb.WriteUtxo(prevout.hash, prevout.n, backfill);
// Backfill to UTXO DB for future lookups. Skip the
// write when the handle is read-only (wallet/mempool
// callers open "r"); ConnectBlock will persist it
// later via the writable chain handle.
if (!txdb.IsReadOnly())
txdb.WriteUtxo(prevout.hash, prevout.n, backfill);
inputsRet[prevout] = backfill;
continue;
}
@@ -3041,7 +3052,7 @@ bool CBlock::SetBestChain(CTxDBBase& txdb, CBlockIndex* pindexNew)
if (!fIsInitialDownload && !strCmd.empty())
{
boost::replace_all(strCmd, "%s", hashBestChain.GetHex());
boost::thread t(runCommand, strCmd); // thread runs free
std::thread(runCommand, strCmd).detach(); // thread runs free
}
#ifdef ENABLE_ZMQ
@@ -3171,7 +3182,7 @@ bool CBlock::GetCoinAge(uint64_t& nCoinAge) const
{
nCoinAge = 0;
CTxDB txdb("r");
auto txdb_holder = MakeChainDB("r"); CTxDBBase& txdb = *txdb_holder;
for (const CTransaction& tx : vtx)
{
uint64_t nTxCoinAge;
@@ -3250,7 +3261,7 @@ bool CBlock::AddToBlockIndex(unsigned int nFile, unsigned int nBlockPos, const u
pindexNew->phashBlock = &((*mi).first);
// Write to disk block index
CTxDB txdb;
auto txdb_holder = MakeChainDB(); CTxDBBase& txdb = *txdb_holder;
if (!txdb.TxnBegin())
return false;
txdb.WriteBlockIndex(CDiskBlockIndex(pindexNew));
@@ -3897,7 +3908,7 @@ bool LoadBlockIndex(bool fAllowNew)
//
// Load block index
//
CTxDB txdb("cr+");
auto txdb_holder = MakeChainDB("cr+"); CTxDBBase& txdb = *txdb_holder;
if (!txdb.LoadBlockIndex())
return false;
@@ -4181,7 +4192,7 @@ bool FastImportBlockFile()
LOCK(cs_main);
CAutoFile blkdat(fileIn, SER_DISK, CLIENT_VERSION);
CTxDB txdb;
auto txdb_holder = MakeChainDB(); CTxDBBase& txdb = *txdb_holder;
txdb.TxnBegin();
unsigned int nPos = 0;
@@ -4392,17 +4403,8 @@ bool FastImportBlockFile()
return nLoaded > 0;
}
//////////////////////////////////////////////////////////////////////////////
//
// CAlert
//
extern map<uint256, CAlert> mapAlerts;
extern CCriticalSection cs_mapAlerts;
string GetWarnings(string strFor)
{
int nPriority = 0;
string strStatusBar;
string strRPC;
@@ -4411,33 +4413,11 @@ string GetWarnings(string strFor)
// Misc warnings like out of disk space and clock is wrong
if (strMiscWarning != "")
{
nPriority = 1000;
strStatusBar = strMiscWarning;
}
// triangles: if detected invalid checkpoint enter safe mode
if (Checkpoints::hashInvalidCheckpoint != 0)
{
nPriority = 3000;
strStatusBar = strRPC = _("WARNING: Invalid checkpoint found! Displayed transactions may not be correct! You may need to upgrade, or notify developers.");
}
// Alerts
{
LOCK(cs_mapAlerts);
for (auto& item : mapAlerts)
{
const CAlert& alert = item.second;
if (alert.AppliesToMe() && alert.nPriority > nPriority)
{
nPriority = alert.nPriority;
strStatusBar = alert.strStatusBar;
if (nPriority > 1000)
strRPC = strStatusBar; // triangles: safe mode for high alert
}
}
}
if (strFor == "statusbar")
return strStatusBar;
@@ -4494,7 +4474,6 @@ unsigned char pchMessageStart[4] = { 0x70, 0x35, 0x22, 0x05 };
bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
{
static map<CService, CPubKey> mapReuseKey;
RandAddSeedPerfmon();
if (fDebug)
printf("received: %s (%" PRIszu " bytes)\n", strCommand.c_str(), vRecv.size());
@@ -4629,13 +4608,6 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
fIBD ? "+getheaders" : "", nBestHeight, pfrom->addr.ToString().c_str());
}
// Relay alerts
{
LOCK(cs_mapAlerts);
for (auto& item : mapAlerts)
item.second.RelayTo(pfrom);
}
// Sync checkpoint relay disabled (master key removed in V5 fork).
// Relaying stale checkpoints causes IBD nodes to request far-future blocks.
@@ -4783,7 +4755,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
printf("IBD-DIAG: inv received: %d blocks, %d tx from %s (our height=%d)\n",
nBlockInv, nTxInv, pfrom->addr.ToString().c_str(), nBestHeight);
CTxDB txdb("r");
auto txdb_holder = MakeChainDB("r"); CTxDBBase& txdb = *txdb_holder;
int nNew = 0, nAlready = 0, nAboveBest = 0;
int nFirstInvHeight = -1, nLastInvHeight = -1;
for (unsigned int nInv = 0; nInv < vInv.size(); nInv++)
@@ -4984,13 +4956,6 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
}
}
}
else if (strCommand == "checkpoint")
{
// Sync checkpoint system disabled (master key removed in V5 fork).
// Ignore checkpoint messages — processing them during IBD causes the
// node to request a single far-future block instead of syncing sequentially.
}
else if (strCommand == "getheaders")
{
CBlockLocator locator;
@@ -5129,7 +5094,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
vector<uint256> vWorkQueue;
vector<uint256> vEraseQueue;
CDataStream vMsg(vRecv);
CTxDB txdb("r");
auto txdb_holder = MakeChainDB("r"); CTxDBBase& txdb = *txdb_holder;
CTransaction tx;
vRecv >> tx;
@@ -5502,53 +5467,6 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
}
else if (strCommand == "checkorder")
{
uint256 hashReply;
vRecv >> hashReply;
if (!GetBoolArg("-allowreceivebyip"))
{
pfrom->PushMessage("reply", hashReply, (int)2, string(""));
return true;
}
CWalletTx order;
vRecv >> order;
/// we have a chance to check the order here
// Keep giving the same key to the same ip until they use it
if (!mapReuseKey.count(pfrom->addr))
pwalletMain->GetKeyFromPool(mapReuseKey[pfrom->addr], true);
// Send back approval of order and pubkey to use
CScript scriptPubKey;
scriptPubKey << mapReuseKey[pfrom->addr] << OP_CHECKSIG;
pfrom->PushMessage("reply", hashReply, (int)0, scriptPubKey);
}
else if (strCommand == "reply")
{
uint256 hashReply;
vRecv >> hashReply;
CRequestTracker tracker;
{
LOCK(pfrom->cs_mapRequests);
map<uint256, CRequestTracker>::iterator mi = pfrom->mapRequests.find(hashReply);
if (mi != pfrom->mapRequests.end())
{
tracker = (*mi).second;
pfrom->mapRequests.erase(mi);
}
}
if (!tracker.IsNull())
tracker.fn(tracker.param1, vRecv);
}
else if (strCommand == "ping")
{
if (pfrom->nVersion > BIP0031_VERSION)
@@ -5594,37 +5512,6 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
}
else if (strCommand == "alert")
{
CAlert alert;
vRecv >> alert;
uint256 alertHash = alert.GetHash();
if (pfrom->setKnown.count(alertHash) == 0)
{
if (alert.ProcessAlert())
{
// Relay
pfrom->setKnown.insert(alertHash);
{
LOCK(cs_vNodes);
for (CNode* pnode : vNodes)
alert.RelayTo(pnode);
}
}
else {
// Small DoS penalty so peers that send us lots of
// duplicate/expired/invalid-signature/whatever alerts
// eventually get banned.
// This isn't a Misbehaving(100) (immediate ban) because the
// peer might be an older or different implementation with
// a different signature key, etc.
pfrom->Misbehaving(10);
}
}
}
else if (strCommand == "getwalletaddr")
{
// Peer is requesting our TRI receiving address for onion resolution.
@@ -6212,7 +6099,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
vector<CInv> vGetData;
int64_t nNow = GetTime() * 1000000;
CTxDB txdb("r");
auto txdb_holder = MakeChainDB("r"); CTxDBBase& txdb = *txdb_holder;
// During IBD, send larger getdata batches since PoS blocks are small
// and the bottleneck is round-trip latency, not bandwidth.
unsigned int nGetDataBatchSize = IsInitialBlockDownload() ? 4000 : 1000;
+4 -3
View File
@@ -136,7 +136,7 @@ CBlock* CreateNewBlock(CWallet* pwallet, bool fProofOfStake, int64_t* pFees)
int64_t nFees = 0;
{
LOCK2(cs_main, mempool.cs);
CTxDB txdb("r");
auto txdb_holder = MakeChainDB("r"); CTxDBBase& txdb = *txdb_holder;
// Priority order to process transactions
list<COrphan> vOrphan; // list memory doesn't move
@@ -387,6 +387,7 @@ void StakeMiner(CWallet *pwallet)
RenameThread("Triangles-miner");
bool fTryToSync = true;
bool fForceStaking = GetBoolArg("-forcestaking", false);
while (true)
{
@@ -401,7 +402,7 @@ void StakeMiner(CWallet *pwallet)
return;
}
while (vNodes.empty() || IsInitialBlockDownload())
while (!fForceStaking && (vNodes.empty() || IsInitialBlockDownload()))
{
nLastCoinStakeSearchInterval = 0;
fTryToSync = true;
@@ -410,7 +411,7 @@ void StakeMiner(CWallet *pwallet)
return;
}
if (fTryToSync)
if (fTryToSync && !fForceStaking)
{
fTryToSync = false;
if (vNodes.size() < 2 || nBestHeight < GetNumBlocksOfPeers())
+3 -8
View File
@@ -3,7 +3,6 @@
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "irc.h"
#include "db.h"
#include "net.h"
#include "main.h"
@@ -905,13 +904,9 @@ void ThreadSocketHandler2(void* parg)
TRY_LOCK(pnode->cs_vRecvMsg, lockRecv);
if (lockRecv)
{
TRY_LOCK(pnode->cs_mapRequests, lockReq);
if (lockReq)
{
TRY_LOCK(pnode->cs_inventory, lockInv);
if (lockInv)
fDelete = true;
}
TRY_LOCK(pnode->cs_inventory, lockInv);
if (lockInv)
fDelete = true;
}
}
}
-68
View File
@@ -18,7 +18,6 @@
#include "protocol.h"
#include "addrman.h"
class CRequestTracker;
class CNode;
class CBlockIndex;
bool IsInitialBlockDownload();
@@ -76,25 +75,6 @@ enum
MSG_BLOCK,
};
class CRequestTracker
{
public:
void (*fn)(void*, CDataStream&);
void* param1;
explicit CRequestTracker(void (*fnIn)(void*, CDataStream&)=NULL, void* param1In=NULL)
{
fn = fnIn;
param1 = param1In;
}
bool IsNull()
{
return fn == NULL;
}
};
/** Thread types */
enum threadId
{
@@ -268,8 +248,6 @@ protected:
int nMisbehavior;
public:
std::map<uint256, CRequestTracker> mapRequests;
CCriticalSection cs_mapRequests;
uint256 hashContinue;
CBlockIndex* pindexLastGetBlocksBegin;
uint256 hashLastGetBlocksEnd;
@@ -690,52 +668,6 @@ public:
}
void PushRequest(const char* pszCommand,
void (*fn)(void*, CDataStream&), void* param1)
{
uint256 hashReply;
RAND_bytes((unsigned char*)&hashReply, sizeof(hashReply));
{
LOCK(cs_mapRequests);
mapRequests[hashReply] = CRequestTracker(fn, param1);
}
PushMessage(pszCommand, hashReply);
}
template<typename T1>
void PushRequest(const char* pszCommand, const T1& a1,
void (*fn)(void*, CDataStream&), void* param1)
{
uint256 hashReply;
RAND_bytes((unsigned char*)&hashReply, sizeof(hashReply));
{
LOCK(cs_mapRequests);
mapRequests[hashReply] = CRequestTracker(fn, param1);
}
PushMessage(pszCommand, hashReply, a1);
}
template<typename T1, typename T2>
void PushRequest(const char* pszCommand, const T1& a1, const T2& a2,
void (*fn)(void*, CDataStream&), void* param1)
{
uint256 hashReply;
RAND_bytes((unsigned char*)&hashReply, sizeof(hashReply));
{
LOCK(cs_mapRequests);
mapRequests[hashReply] = CRequestTracker(fn, param1);
}
PushMessage(pszCommand, hashReply, a1, a2);
}
void PushGetBlocks(CBlockIndex* pindexBegin, uint256 hashEnd);
void PushGetHeaders(CBlockIndex* pindexBegin, uint256 hashEnd);
bool IsSubscribed(unsigned int nChannel);
+9 -8
View File
@@ -8,8 +8,9 @@
#include <string>
#include <deque>
#include <vector>
#include <boost/thread/mutex.hpp>
#include <boost/thread/condition_variable.hpp>
#include <chrono>
#include <condition_variable>
#include <mutex>
/**
* Thread-safe notification queue for SSE (Server-Sent Events) clients.
@@ -24,8 +25,8 @@
class CNotificationQueue
{
private:
mutable boost::mutex cs;
boost::condition_variable cond;
mutable std::mutex cs;
std::condition_variable cond;
struct Event {
uint64_t id;
@@ -43,7 +44,7 @@ public:
/** Push a new event. Wakes all waiting SSE clients. */
void Push(const std::string& strData)
{
boost::mutex::scoped_lock lock(cs);
std::unique_lock<std::mutex> lock(cs);
events.push_back(Event{nNextId++, strData});
while (events.size() > MAX_QUEUED_EVENTS)
events.pop_front();
@@ -59,7 +60,7 @@ public:
bool WaitForEvents(uint64_t& nLastId, std::vector<std::string>& vEvents, int nTimeoutMs, const volatile bool& fShutdown)
{
vEvents.clear();
boost::mutex::scoped_lock lock(cs);
std::unique_lock<std::mutex> lock(cs);
// Check for events already in the queue past our read position
bool fHasNew = false;
@@ -75,7 +76,7 @@ public:
if (!fHasNew)
{
// Wait for new events or timeout
cond.timed_wait(lock, boost::posix_time::milliseconds(nTimeoutMs));
cond.wait_for(lock, std::chrono::milliseconds(nTimeoutMs));
}
// Drain all events newer than nLastId
@@ -97,7 +98,7 @@ public:
/** Get the current latest event ID (for clients that want to skip history). */
uint64_t GetLatestId() const
{
boost::mutex::scoped_lock lock(cs);
std::unique_lock<std::mutex> lock(cs);
return nNextId - 1;
}
};
-31
View File
@@ -4,7 +4,6 @@
#include "addresstablemodel.h"
#include "transactiontablemodel.h"
#include "alert.h"
#include "main.h"
#include "ui_interface.h"
@@ -94,25 +93,6 @@ void ClientModel::updateNumConnections(int numConnections)
emit numConnectionsChanged(numConnections);
}
void ClientModel::updateAlert(const QString &hash, int status)
{
// Show error message notification for new alert
if(status == CT_NEW)
{
uint256 hash_256;
hash_256.SetHex(hash.toStdString());
CAlert alert = CAlert::getAlertByHash(hash_256);
if(!alert.IsNull())
{
emit error(tr("Network Alert"), QString::fromStdString(alert.strStatusBar), false);
}
}
// Emit a numBlocksChanged when the status message changes,
// so that the view recomputes and updates the status bar.
emit numBlocksChanged(getNumBlocks(), getNumBlocksOfPeers());
}
double ClientModel::GetDifficulty() const
{
// Floating point number that is a multiple of the minimum difficulty,
@@ -200,21 +180,11 @@ static void NotifyNumConnectionsChanged(ClientModel *clientmodel, int newNumConn
Q_ARG(int, newNumConnections));
}
static void NotifyAlertChanged(ClientModel *clientmodel, const uint256 &hash, ChangeType status)
{
if (fShutdown) return;
OutputDebugStringF("NotifyAlertChanged %s status=%i\n", hash.GetHex().c_str(), status);
QMetaObject::invokeMethod(clientmodel, "updateAlert", Qt::QueuedConnection,
Q_ARG(QString, QString::fromStdString(hash.GetHex())),
Q_ARG(int, status));
}
void ClientModel::subscribeToCoreSignals()
{
// Connect signals to client
uiInterface.NotifyBlocksChanged.connect(boost::bind(NotifyBlocksChanged, this));
uiInterface.NotifyNumConnectionsChanged.connect(boost::bind(NotifyNumConnectionsChanged, this, _1));
uiInterface.NotifyAlertChanged.connect(boost::bind(NotifyAlertChanged, this, _1, _2));
}
void ClientModel::unsubscribeFromCoreSignals()
@@ -222,5 +192,4 @@ void ClientModel::unsubscribeFromCoreSignals()
// Disconnect signals from client
uiInterface.NotifyBlocksChanged.disconnect(boost::bind(NotifyBlocksChanged, this));
uiInterface.NotifyNumConnectionsChanged.disconnect(boost::bind(NotifyNumConnectionsChanged, this, _1));
uiInterface.NotifyAlertChanged.disconnect(boost::bind(NotifyAlertChanged, this, _1, _2));
}
-1
View File
@@ -67,7 +67,6 @@ signals:
public slots:
void updateTimer();
void updateNumConnections(int numConnections);
void updateAlert(const QString &hash, int status);
};
#endif // CLIENTMODEL_H
+22 -22
View File
@@ -20,8 +20,8 @@
#include <QDesktopServices>
#include <QThread>
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <filesystem>
#include <fstream>
#ifdef WIN32
#ifdef _WIN32_WINNT
@@ -240,10 +240,10 @@ bool isObscured(QWidget *w)
void openDebugLogfile()
{
boost::filesystem::path pathDebug = GetDataDir() / "debug.log";
std::filesystem::path pathDebug = GetDataDir() / "debug.log";
/* Open debug.log with the associated application */
if (boost::filesystem::exists(pathDebug))
if (std::filesystem::exists(pathDebug))
QDesktopServices::openUrl(QUrl::fromLocalFile(QString::fromStdString(pathDebug.string())));
}
@@ -272,7 +272,7 @@ bool ToolTipToRichTextFilter::eventFilter(QObject *obj, QEvent *evt)
}
#ifdef WIN32
boost::filesystem::path static StartupShortcutPath()
std::filesystem::path static StartupShortcutPath()
{
return GetSpecialFolderPath(CSIDL_STARTUP) / "triangles.lnk";
}
@@ -280,13 +280,13 @@ boost::filesystem::path static StartupShortcutPath()
bool GetStartOnSystemStartup()
{
// check for triangles.lnk
return boost::filesystem::exists(StartupShortcutPath());
return std::filesystem::exists(StartupShortcutPath());
}
bool SetStartOnSystemStartup(bool fAutoStart)
{
// If the shortcut exists already, remove it for updating
boost::filesystem::remove(StartupShortcutPath());
std::filesystem::remove(StartupShortcutPath());
if (fAutoStart)
{
@@ -343,9 +343,9 @@ bool SetStartOnSystemStartup(bool fAutoStart)
// Follow the Desktop Application Autostart Spec:
// http://standards.freedesktop.org/autostart-spec/autostart-spec-latest.html
boost::filesystem::path static GetAutostartDir()
std::filesystem::path static GetAutostartDir()
{
namespace fs = boost::filesystem;
namespace fs = std::filesystem;
char* pszConfigHome = getenv("XDG_CONFIG_HOME");
if (pszConfigHome) return fs::path(pszConfigHome) / "autostart";
@@ -354,14 +354,14 @@ boost::filesystem::path static GetAutostartDir()
return fs::path();
}
boost::filesystem::path static GetAutostartFilePath()
std::filesystem::path static GetAutostartFilePath()
{
return GetAutostartDir() / "triangles.desktop";
}
bool GetStartOnSystemStartup()
{
boost::filesystem::ifstream optionFile(GetAutostartFilePath());
std::ifstream optionFile(GetAutostartFilePath());
if (!optionFile.good())
return false;
// Scan through file for "Hidden=true":
@@ -381,7 +381,7 @@ bool GetStartOnSystemStartup()
bool SetStartOnSystemStartup(bool fAutoStart)
{
if (!fAutoStart)
boost::filesystem::remove(GetAutostartFilePath());
std::filesystem::remove(GetAutostartFilePath());
else
{
char pszExePath[MAX_PATH+1];
@@ -389,9 +389,9 @@ bool SetStartOnSystemStartup(bool fAutoStart)
if (readlink("/proc/self/exe", pszExePath, sizeof(pszExePath)-1) == -1)
return false;
boost::filesystem::create_directories(GetAutostartDir());
std::filesystem::create_directories(GetAutostartDir());
boost::filesystem::ofstream optionFile(GetAutostartFilePath(), std::ios_base::out|std::ios_base::trunc);
std::ofstream optionFile(GetAutostartFilePath(), std::ios_base::out|std::ios_base::trunc);
if (!optionFile.good())
return false;
// Write a triangles.desktop file to the autostart directory:
@@ -407,15 +407,15 @@ bool SetStartOnSystemStartup(bool fAutoStart)
}
#elif defined(Q_OS_MAC) || defined(MAC_OSX) || defined(__APPLE__)
boost::filesystem::path static GetLaunchAgentsDir()
std::filesystem::path static GetLaunchAgentsDir()
{
const QString homeDir = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
if (homeDir.isEmpty())
return boost::filesystem::path();
return boost::filesystem::path(homeDir.toStdString()) / "Library" / "LaunchAgents";
return std::filesystem::path();
return std::filesystem::path(homeDir.toStdString()) / "Library" / "LaunchAgents";
}
boost::filesystem::path static GetAutostartFilePath()
std::filesystem::path static GetAutostartFilePath()
{
return GetLaunchAgentsDir() / "org.triangles.triangles-qt.plist";
}
@@ -441,7 +441,7 @@ static std::string PlistEscape(const std::string& value)
bool GetStartOnSystemStartup()
{
boost::filesystem::ifstream optionFile(GetAutostartFilePath());
std::ifstream optionFile(GetAutostartFilePath());
if (!optionFile.good())
return false;
@@ -459,16 +459,16 @@ bool GetStartOnSystemStartup()
bool SetStartOnSystemStartup(bool fAutoStart)
{
if (!fAutoStart)
return !boost::filesystem::exists(GetAutostartFilePath()) || boost::filesystem::remove(GetAutostartFilePath());
return !std::filesystem::exists(GetAutostartFilePath()) || std::filesystem::remove(GetAutostartFilePath());
const QString exePath = QApplication::applicationFilePath();
if (exePath.isEmpty())
return false;
const QString workingDir = QFileInfo(exePath).absolutePath();
boost::filesystem::create_directories(GetLaunchAgentsDir());
std::filesystem::create_directories(GetLaunchAgentsDir());
boost::filesystem::ofstream optionFile(GetAutostartFilePath(), std::ios_base::out|std::ios_base::trunc);
std::ofstream optionFile(GetAutostartFilePath(), std::ios_base::out|std::ios_base::trunc);
if (!optionFile.good())
return false;
+10 -10
View File
@@ -14,7 +14,7 @@
#include <QCheckBox>
#include <QApplication>
#include <boost/filesystem.hpp>
#include <filesystem>
#include <set>
@@ -152,28 +152,28 @@ void IntroDialog::on_defaultRadio_toggled(bool checked)
void IntroDialog::updateFreeSpace()
{
QString path = getDataDirectory();
boost::filesystem::path fsPath(path.toStdString());
std::filesystem::path fsPath(path.toStdString());
// Walk up to find an existing parent
try {
while (!fsPath.empty() && !boost::filesystem::exists(fsPath))
while (!fsPath.empty() && !std::filesystem::exists(fsPath))
fsPath = fsPath.parent_path();
if (!fsPath.empty()) {
boost::filesystem::space_info si = boost::filesystem::space(fsPath);
std::filesystem::space_info si = std::filesystem::space(fsPath);
double freeGB = (double)si.available / (1024.0 * 1024.0 * 1024.0);
freeSpaceLabel->setText(tr("Free space: %1 GB").arg(QString::number(freeGB, 'f', 2)));
} else {
freeSpaceLabel->setText(tr("Cannot determine free space"));
}
} catch (const boost::filesystem::filesystem_error &) {
} catch (const std::filesystem::filesystem_error &) {
freeSpaceLabel->setText(tr("Cannot determine free space"));
}
}
bool IntroDialog::pickDataDirectory()
{
namespace fs = boost::filesystem;
namespace fs = std::filesystem;
QSettings settings;
// If -datadir was passed on the command line, skip the dialog entirely
@@ -305,10 +305,10 @@ bool IntroDialog::pickDataDirectory()
return true;
}
static void copyDirectoryRecursive(const boost::filesystem::path& src,
const boost::filesystem::path& dst)
static void copyDirectoryRecursive(const std::filesystem::path& src,
const std::filesystem::path& dst)
{
namespace fs = boost::filesystem;
namespace fs = std::filesystem;
fs::create_directories(dst);
for (fs::directory_iterator it(src), end; it != end; ++it) {
fs::path dstChild = dst / it->path().filename();
@@ -322,7 +322,7 @@ static void copyDirectoryRecursive(const boost::filesystem::path& src,
bool IntroDialog::migrateDataDirectory(const QString& oldPath, const QString& newPath)
{
namespace fs = boost::filesystem;
namespace fs = std::filesystem;
fs::path srcDir(oldPath.toStdString());
fs::path dstDir(newPath.toStdString());
+4 -4
View File
@@ -10,7 +10,7 @@
#include "init.h"
#include "util.h"
#include <boost/filesystem.hpp>
#include <filesystem>
#include <QDir>
#include <QFileDialog>
@@ -374,7 +374,7 @@ void OptionsDialog::on_dataDirBrowseButton_clicked()
void OptionsDialog::updateDataDirFreeSpace()
{
namespace fs = boost::filesystem;
namespace fs = std::filesystem;
QString path = dataDirPath->text();
fs::path fsPath(path.toStdString());
try {
@@ -395,7 +395,7 @@ void OptionsDialog::updateDataDirFreeSpace()
quint64 OptionsDialog::calculateDirSize(const QString& path)
{
namespace fs = boost::filesystem;
namespace fs = std::filesystem;
quint64 totalSize = 0;
try {
for (fs::recursive_directory_iterator it(path.toStdString()), end; it != end; ++it) {
@@ -411,7 +411,7 @@ bool OptionsDialog::handleDataDirChange()
if (m_pendingDataDir.isEmpty() || m_pendingDataDir == m_currentDataDir)
return false;
namespace fs = boost::filesystem;
namespace fs = std::filesystem;
fs::path destPath(m_pendingDataDir.toStdString());
// Check destination is writable
+1 -1
View File
@@ -244,7 +244,7 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx)
strHTML += "<br><b>" + tr("Transaction") + ":</b><br>";
strHTML += GUIUtil::HtmlEscape(wtx.ToString(), true);
CTxDB txdb("r"); // To fetch source txouts
auto txdb_holder = MakeChainDB("r"); CTxDBBase& txdb = *txdb_holder; // To fetch source txouts
strHTML += "<br><b>" + tr("Inputs") + ":</b>";
strHTML += "<ul>";
+1 -1
View File
@@ -145,7 +145,7 @@ int main(int argc, char *argv[])
return 0;
// ... then triangles.conf:
if (!boost::filesystem::is_directory(GetDataDir(false)))
if (!std::filesystem::is_directory(GetDataDir(false)))
{
// This message can not be translated, as translation is not initialized yet
// (which not yet possible because lang=XX can be overridden in triangles.conf in the data directory)
+24 -11
View File
@@ -11,6 +11,19 @@
#include "base58.h"
#include "utxosnapshot.h"
#include <filesystem>
// Windows.h (transitively included) defines these as macros, clobbering Checkpoints:: enum values.
#ifdef STRICT
#undef STRICT
#endif
#ifdef ADVISORY
#undef ADVISORY
#endif
#ifdef PERMISSIVE
#undef PERMISSIVE
#endif
using namespace json_spirit;
using namespace std;
@@ -382,7 +395,7 @@ static int64_t ComputeActiveChainSupplyFromBlocks(const std::vector<CBlockIndex*
nBlocksScanned = 0;
nTransactionsScanned = 0;
CTxDB txdb("r");
auto txdb_holder = MakeChainDB("r"); CTxDBBase& txdb = *txdb_holder;
int64_t nSupply = 0;
for (std::vector<CBlockIndex*>::const_iterator pindexIt = chain.begin(); pindexIt != chain.end(); ++pindexIt)
@@ -458,7 +471,7 @@ Value recalculatesupply(const Array& params, bool fHelp)
if (!pindexBest)
throw runtime_error("recalculatesupply: no best block");
CTxDB txdbRead("r");
auto txdbRead_holder = MakeChainDB("r"); CTxDBBase& txdbRead = *txdbRead_holder;
int nUtxoCount = 0;
int64_t nUtxoSupply = txdbRead.SumUtxoValues(nUtxoCount);
@@ -473,7 +486,7 @@ Value recalculatesupply(const Array& params, bool fHelp)
if (fApply)
{
CTxDB txdbWrite;
auto txdbWrite_holder = MakeChainDB(); CTxDBBase& txdbWrite = *txdbWrite_holder;
int64_t nRunningSupply = 0;
for (std::vector<CBlockIndex*>::const_iterator pindexIt = activeChain.begin(); pindexIt != activeChain.end(); ++pindexIt)
@@ -706,7 +719,7 @@ Value getaddressbalance(const Array& params, bool fHelp)
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address: " + strAddr);
int64_t nBalance = 0;
CTxDB txdb("r");
auto txdb_holder = MakeChainDB("r"); CTxDBBase& txdb = *txdb_holder;
txdb.ReadAddressBalance(nType, hashBytes, nBalance);
nTotalBalance += nBalance;
}
@@ -741,7 +754,7 @@ Value getaddressutxos(const Array& params, bool fHelp)
Array addrArray = find_value(addrObj, "addresses").get_array();
Array result;
CTxDB txdb("r");
auto txdb_holder = MakeChainDB("r"); CTxDBBase& txdb = *txdb_holder;
for (unsigned int i = 0; i < addrArray.size(); i++)
{
@@ -801,7 +814,7 @@ Value getaddresstxids(const Array& params, bool fHelp)
nEndHeight = endVal.get_int();
Array result;
CTxDB txdb("r");
auto txdb_holder = MakeChainDB("r"); CTxDBBase& txdb = *txdb_holder;
// Use a set to deduplicate txids across multiple addresses
std::set<uint256> setTxIds;
@@ -907,7 +920,7 @@ Value invalidateblock(const Array& params, bool fHelp)
if (pindex->IsInMainChain())
{
CTxDB txdb;
auto txdb_holder = MakeChainDB(); CTxDBBase& txdb = *txdb_holder;
if (!txdb.TxnBegin())
throw runtime_error("Failed to begin transaction.");
@@ -976,7 +989,7 @@ Value reconsiderblock(const Array& params, bool fHelp)
if (!block.ReadFromDisk(pindex))
throw runtime_error("Failed to read block from disk.");
CTxDB txdb;
auto txdb_holder = MakeChainDB(); CTxDBBase& txdb = *txdb_holder;
block.SetBestChain(txdb, pindex);
printf("reconsiderblock: reconsidered block %s at height %d, new best height=%d\n",
hash.ToString().c_str(), pindex->nHeight, nBestHeight);
@@ -1016,7 +1029,7 @@ Value dumputxoset(const Array& params, bool fHelp)
if (nHeaders < 100)
throw JSONRPCError(RPC_INVALID_PARAMETER, "nheaders must be at least 100");
boost::filesystem::path destPath(filename);
std::filesystem::path destPath(filename);
std::string strError;
if (!UtxoSnapshot::DumpSnapshot(destPath, nHeaders, strError))
@@ -1024,8 +1037,8 @@ Value dumputxoset(const Array& params, bool fHelp)
// Get file size
int64_t nFileSize = 0;
if (boost::filesystem::exists(destPath))
nFileSize = (int64_t)boost::filesystem::file_size(destPath);
if (std::filesystem::exists(destPath))
nFileSize = (int64_t)std::filesystem::file_size(destPath);
Object result;
result.push_back(Pair("filename", filename));
-66
View File
@@ -6,7 +6,6 @@
#include "net.h"
#include "addrman.h"
#include "trianglesrpc.h"
#include "alert.h"
#include "wallet.h"
#include "db.h"
#include "walletdb.h"
@@ -107,71 +106,6 @@ Value getpeerinfo(const Array& params, bool fHelp)
return ret;
}
extern CCriticalSection cs_mapAlerts;
extern map<uint256, CAlert> mapAlerts;
// triangles: send alert.
// There is a known deadlock situation with ThreadMessageHandler
// ThreadMessageHandler: holds cs_vSend and acquiring cs_main in SendMessages()
// ThreadRPCServer: holds cs_main and acquiring cs_vSend in alert.RelayTo()/PushMessage()/BeginMessage()
Value sendalert(const Array& params, bool fHelp)
{
if (fHelp || params.size() < 6)
throw runtime_error(
"sendalert <message> <privatekey> <minver> <maxver> <priority> <id> [cancelupto]\n"
"<message> is the alert text message\n"
"<privatekey> is hex string of alert master private key\n"
"<minver> is the minimum applicable internal client version\n"
"<maxver> is the maximum applicable internal client version\n"
"<priority> is integer priority number\n"
"<id> is the alert id\n"
"[cancelupto] cancels all alert id's up to this number\n"
"Returns true or false.");
CAlert alert;
CKey key;
alert.strStatusBar = params[0].get_str();
alert.nMinVer = params[2].get_int();
alert.nMaxVer = params[3].get_int();
alert.nPriority = params[4].get_int();
alert.nID = params[5].get_int();
if (params.size() > 6)
alert.nCancel = params[6].get_int();
alert.nVersion = PROTOCOL_VERSION;
alert.nRelayUntil = GetAdjustedTime() + 365*24*60*60;
alert.nExpiration = GetAdjustedTime() + 365*24*60*60;
CDataStream sMsg(SER_NETWORK, PROTOCOL_VERSION);
sMsg << (CUnsignedAlert)alert;
alert.vchMsg = vector<unsigned char>(sMsg.begin(), sMsg.end());
vector<unsigned char> vchPrivKey = ParseHex(params[1].get_str());
key.SetPrivKey(CPrivKey(vchPrivKey.begin(), vchPrivKey.end())); // if key is not correct openssl may crash
if (!key.Sign(Hash(alert.vchMsg.begin(), alert.vchMsg.end()), alert.vchSig))
throw runtime_error(
"Unable to sign alert, check private key?\n");
if(!alert.ProcessAlert())
throw runtime_error(
"Failed to process alert.\n");
// Relay alert
{
LOCK(cs_vNodes);
for (CNode* pnode : vNodes)
alert.RelayTo(pnode);
}
Object result;
result.push_back(Pair("strStatusBar", alert.strStatusBar));
result.push_back(Pair("nVersion", alert.nVersion));
result.push_back(Pair("nMinVer", alert.nMinVer));
result.push_back(Pair("nMaxVer", alert.nMaxVer));
result.push_back(Pair("nPriority", alert.nPriority));
result.push_back(Pair("nID", alert.nID));
if (alert.nCancel > 0)
result.push_back(Pair("nCancel", alert.nCancel));
return result;
}
Value addnode(const Array& params, bool fHelp)
{
+2 -2
View File
@@ -371,7 +371,7 @@ Value signrawtransaction(const Array& params, bool fHelp)
CTransaction tempTx;
MapPrevTx mapPrevTx;
MapPrevTx mapEmpty;
CTxDB txdb("r");
auto txdb_holder = MakeChainDB("r"); CTxDBBase& txdb = *txdb_holder;
bool fInvalid;
// FetchInputs aborts on failure, so we go one at a time.
@@ -548,7 +548,7 @@ Value sendrawtransaction(const Array& params, bool fHelp)
else
{
// push to local node
CTxDB txdb("r");
auto txdb_holder = MakeChainDB("r"); CTxDBBase& txdb = *txdb_holder;
if (!tx.AcceptToMemoryPool(txdb))
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX rejected");
+9 -7
View File
@@ -10,6 +10,8 @@
#include "smessage.h"
#include "init.h" // pwalletMain
#include <filesystem>
using namespace json_spirit;
using namespace std;
@@ -820,10 +822,10 @@ Value smsgbuckets(const Array& params, bool fHelp)
objM.push_back(Pair("hash", sHash));
objM.push_back(Pair("last changed", getTimeString(it->second.timeChanged, cbuf, sizeof(cbuf))));
boost::filesystem::path fullPath = GetDataDir() / "smsgStore" / sFile;
std::filesystem::path fullPath = GetDataDir() / "smsgStore" / sFile;
if (!boost::filesystem::exists(fullPath))
if (!std::filesystem::exists(fullPath))
{
// -- If there is a file for an empty bucket something is wrong.
if (tokenSet.size() == 0)
@@ -835,10 +837,10 @@ Value smsgbuckets(const Array& params, bool fHelp)
try {
uint64_t nFBytes = 0;
nFBytes = boost::filesystem::file_size(fullPath);
nFBytes = std::filesystem::file_size(fullPath);
nBytes += nFBytes;
objM.push_back(Pair("file size", fsReadable(nFBytes)));
} catch (const boost::filesystem::filesystem_error& ex)
} catch (const std::filesystem::filesystem_error& ex)
{
objM.push_back(Pair("file size, error", ex.what()));
};
@@ -871,9 +873,9 @@ Value smsgbuckets(const Array& params, bool fHelp)
std::string sFile = std::to_string(it->first) + "_01.dat";
try {
boost::filesystem::path fullPath = GetDataDir() / "smsgStore" / sFile;
boost::filesystem::remove(fullPath);
} catch (const boost::filesystem::filesystem_error& ex)
std::filesystem::path fullPath = GetDataDir() / "smsgStore" / sFile;
std::filesystem::remove(fullPath);
} catch (const std::filesystem::filesystem_error& ex)
{
//objM.push_back(Pair("file size, error", ex.what()));
printf("Error removing bucket file %s.\n", ex.what());
-178
View File
@@ -1858,181 +1858,3 @@ Value makekeypair(const Array& params, bool fHelp)
result.push_back(Pair("PublicKey", HexStr(key.GetPubKey().Raw())));
return result;
}
Value clearwallettransactions(const Array& params, bool fHelp)
{
if (fHelp || params.size() > 0)
throw runtime_error(
"clearwallettransactions \n"
"delete all transactions from wallet - reload with scanforalltxns\n"
"Warning: Backup your wallet first!");
Object result;
uint32_t nTransactions = 0;
char cbuf[256];
{
LOCK2(cs_main, pwalletMain->cs_wallet);
CWalletDB walletdb(pwalletMain->strWalletFile);
walletdb.TxnBegin();
Dbc* pcursor = walletdb.GetTxnCursor();
if (!pcursor)
throw runtime_error("Cannot get wallet DB cursor");
// RAII guard ensures cursor is closed even on exception
struct CursorGuard {
Dbc* cur;
CursorGuard(Dbc* c) : cur(c) {}
~CursorGuard() { if (cur) cur->close(); }
} cursorGuard(pcursor);
Dbt datKey;
Dbt datValue;
datKey.set_flags(DB_DBT_USERMEM);
datValue.set_flags(DB_DBT_USERMEM);
std::vector<unsigned char> vchKey;
std::vector<unsigned char> vchType;
std::vector<unsigned char> vchKeyData;
std::vector<unsigned char> vchValueData;
vchKeyData.resize(100);
vchValueData.resize(100);
datKey.set_ulen(vchKeyData.size());
datKey.set_data(&vchKeyData[0]);
datValue.set_ulen(vchValueData.size());
datValue.set_data(&vchValueData[0]);
unsigned int fFlags = DB_NEXT; // same as using DB_FIRST for new cursor
while (true)
{
int ret = pcursor->get(&datKey, &datValue, fFlags);
if (ret == ENOMEM
|| ret == DB_BUFFER_SMALL)
{
if (datKey.get_size() > datKey.get_ulen())
{
vchKeyData.resize(datKey.get_size());
datKey.set_ulen(vchKeyData.size());
datKey.set_data(&vchKeyData[0]);
};
if (datValue.get_size() > datValue.get_ulen())
{
vchValueData.resize(datValue.get_size());
datValue.set_ulen(vchValueData.size());
datValue.set_data(&vchValueData[0]);
};
// -- try once more, when DB_BUFFER_SMALL cursor is not expected to move
ret = pcursor->get(&datKey, &datValue, fFlags);
};
if (ret == DB_NOTFOUND)
break;
else
if (datKey.get_data() == NULL || datValue.get_data() == NULL
|| ret != 0)
{
const char* dbErr = db_strerror(ret);
snprintf(cbuf, sizeof(cbuf), "wallet DB error %d, %s", ret, dbErr ? dbErr : "unknown");
throw runtime_error(cbuf);
};
CDataStream ssValue(SER_DISK, CLIENT_VERSION);
ssValue.SetType(SER_DISK);
ssValue.clear();
ssValue.write((char*)datKey.get_data(), datKey.get_size());
ssValue >> vchType;
std::string strType(vchType.begin(), vchType.end());
//printf("strType %s\n", strType.c_str());
if (strType == "tx")
{
uint256 hash;
ssValue >> hash;
if ((ret = pcursor->del(0)) != 0)
{
printf("Delete transaction failed %d, %s\n", ret, db_strerror(ret));
continue;
};
pwalletMain->mapWallet.erase(hash);
try { pwalletMain->NotifyTransactionChanged(pwalletMain, hash, CT_DELETED); }
catch (...) {
printf("clearwallettransactions: NotifyTransactionChanged failed\n");
}
nTransactions++;
};
};
cursorGuard.cur = nullptr; // mark as handled
pcursor->close();
walletdb.TxnCommit();
}
snprintf(cbuf, sizeof(cbuf), "Removed %u transactions.", nTransactions);
result.push_back(Pair("complete", std::string(cbuf)));
result.push_back(Pair("", "Reload with scanforstealthtxns or re-download blockchain."));
return result;
}
Value scanforalltxns(const Array& params, bool fHelp)
{
if (fHelp || params.size() > 1)
throw runtime_error(
"scanforalltxns [fromHeight]\n"
"Scan blockchain for owned transactions.");
Object result;
int32_t nFromHeight = 0;
CBlockIndex *pindex = pindexGenesisBlock;
if (params.size() > 0)
nFromHeight = params[0].get_int();
if (nFromHeight > 0)
{
pindex = mapBlockIndex[hashBestChain];
while (pindex->nHeight > nFromHeight
&& pindex->pprev)
pindex = pindex->pprev;
};
if (pindex == NULL)
throw runtime_error("Genesis Block is not set.");
{
LOCK2(cs_main, pwalletMain->cs_wallet);
pwalletMain->MarkDirty();
pwalletMain->ScanForWalletTransactions(pindex, true);
pwalletMain->ReacceptWalletTransactions();
}
result.push_back(Pair("result", "Scan complete."));
return result;
}
+1
View File
@@ -11,6 +11,7 @@
#include <map>
#include <set>
#include <cassert>
#include <ios>
#include <limits>
#include <stdint.h>
#include <cstring>
+8 -8
View File
@@ -97,7 +97,7 @@ CCriticalSection cs_smsgDB;
leveldb::DB *smsgDB = NULL;
namespace fs = boost::filesystem;
namespace fs = std::filesystem;
namespace
{
@@ -2238,7 +2238,7 @@ bool SecureMsgScanBlock(CBlock& block)
{
LOCK(cs_smsgDB);
CTxDB txdb("r");
auto txdb_holder = MakeChainDB("r"); CTxDBBase& txdb = *txdb_holder;
SecMsgDB addrpkdb;
if (!addrpkdb.Open("cw")
@@ -2277,7 +2277,7 @@ bool ScanChainForPublicKeys(CBlockIndex* pindexStart)
{
LOCK(cs_smsgDB);
CTxDB txdb("r");
auto txdb_holder = MakeChainDB("r"); CTxDBBase& txdb = *txdb_holder;
SecMsgDB addrpkdb;
if (!addrpkdb.Open("cw")
@@ -2472,7 +2472,7 @@ bool SecureMsgScanBuckets()
// -- remove wl file when scanned
try {
fs::remove((*itd).path());
} catch (const boost::filesystem::filesystem_error& ex)
} catch (const std::filesystem::filesystem_error& ex)
{
printf("Error removing wl file %s - %s\n", fileName.c_str(), ex.what());
return 1;
@@ -2552,7 +2552,7 @@ int SecureMsgWalletUnlocked()
printf("Dropping wallet locked file %s, expired.\n", fileName.c_str());
try {
fs::remove((*itd).path());
} catch (const boost::filesystem::filesystem_error& ex)
} catch (const std::filesystem::filesystem_error& ex)
{
printf("Error removing wl file %s - %s\n", fileName.c_str(), ex.what());
return 1;
@@ -2620,7 +2620,7 @@ int SecureMsgWalletUnlocked()
// -- remove wl file when scanned
try {
fs::remove((*itd).path());
} catch (const boost::filesystem::filesystem_error& ex)
} catch (const std::filesystem::filesystem_error& ex)
{
printf("Error removing wl file %s - %s\n", fileName.c_str(), ex.what());
return 1;
@@ -3119,7 +3119,7 @@ int SecureMsgStoreUnscanned(unsigned char *pHeader, unsigned char *pPayload, uin
try {
pathSmsgDir = GetDataDir() / "smsgStore";
fs::create_directory(pathSmsgDir);
} catch (const boost::filesystem::filesystem_error& ex)
} catch (const std::filesystem::filesystem_error& ex)
{
printf("Error: Failed to create directory %s - %s\n", pathSmsgDir.string().c_str(), ex.what());
return 1;
@@ -3209,7 +3209,7 @@ int SecureMsgStore(unsigned char *pHeader, unsigned char *pPayload, uint32_t nPa
try {
pathSmsgDir = GetDataDir() / "smsgStore";
fs::create_directory(pathSmsgDir);
} catch (const boost::filesystem::filesystem_error& ex)
} catch (const std::filesystem::filesystem_error& ex)
{
printf("Error: Failed to create directory %s - %s\n", pathSmsgDir.string().c_str(), ex.what());
return 1;
+7 -7
View File
@@ -15,8 +15,8 @@
#include <openssl/sha.h>
#include <boost/filesystem/fstream.hpp>
#include <boost/thread.hpp>
#include <filesystem>
#include <thread>
#include <algorithm>
#include <atomic>
@@ -27,7 +27,7 @@
#include <mutex>
#include <vector>
namespace fs = boost::filesystem;
namespace fs = std::filesystem;
extern std::vector<CNode*> vNodes;
extern CCriticalSection cs_vNodes;
@@ -353,7 +353,7 @@ bool TryFetchSnapshot(const fs::path& dataDir, int timeoutSec, std::string& strE
g_fetch.success = false;
// Drop bad file so we don't trick later loaders.
CloseDest();
boost::system::error_code ec;
std::error_code ec;
fs::remove(g_fetch.destPath, ec);
}
g_fetch.finished = true;
@@ -362,7 +362,7 @@ bool TryFetchSnapshot(const fs::path& dataDir, int timeoutSec, std::string& strE
}
}
boost::this_thread::sleep_for(boost::chrono::milliseconds(500));
std::this_thread::sleep_for(std::chrono::milliseconds(500));
}
bool ok;
@@ -374,7 +374,7 @@ bool TryFetchSnapshot(const fs::path& dataDir, int timeoutSec, std::string& strE
strError = strprintf("timeout after %d seconds (totalSize=%" PRId64 ", chunks=%" PRIszu ")",
timeoutSec, g_fetch.totalSize, g_fetch.received.size());
CloseDest();
boost::system::error_code ec;
std::error_code ec;
fs::remove(g_fetch.destPath, ec);
}
ok = g_fetch.success;
@@ -420,7 +420,7 @@ static bool ScanLocalSnapshot()
uint256 expectedHash;
if (!Checkpoints::GetSnapshotHash(snapHeight, expectedHash)) return false;
boost::system::error_code ec;
std::error_code ec;
int64_t sz = (int64_t)fs::file_size(g_localPath, ec);
if (ec) return false;
+2 -2
View File
@@ -7,7 +7,7 @@
#include "uint256.h"
#include "serialize.h"
#include <boost/filesystem.hpp>
#include <filesystem>
#include <string>
#include <vector>
@@ -47,7 +47,7 @@ struct AvailableSnapshot
//
// Blocks for up to timeoutSec waiting for peers + transfer. Returns true if a
// verified snapshot was written, false on timeout/no peer/verification fail.
bool TryFetchSnapshot(const boost::filesystem::path& dataDir,
bool TryFetchSnapshot(const std::filesystem::path& dataDir,
int timeoutSec,
std::string& strError);
+3 -3
View File
@@ -48,9 +48,9 @@ private:
typedef std::vector< std::pair<void*, CLockLocation> > LockStack;
static boost::mutex dd_mutex;
static std::mutex dd_mutex;
static std::map<std::pair<void*, void*>, LockStack> lockorders;
static boost::thread_specific_ptr<LockStack> lockstack;
static thread_local std::unique_ptr<LockStack> lockstack;
static void potential_deadlock_detected(const std::pair<void*, void*>& mismatch, const LockStack& s1, const LockStack& s2)
@@ -74,7 +74,7 @@ static void potential_deadlock_detected(const std::pair<void*, void*>& mismatch,
static void push_lock(void* c, const CLockLocation& locklocation, bool fTry)
{
if (lockstack.get() == NULL)
if (!lockstack)
lockstack.reset(new LockStack);
if (fDebug) printf("Locking: %s\n", locklocation.ToString().c_str());
+14 -19
View File
@@ -5,19 +5,14 @@
#ifndef TRIANGLES_SYNC_H
#define TRIANGLES_SYNC_H
#include <boost/thread/mutex.hpp>
#include <boost/thread/recursive_mutex.hpp>
#include <boost/thread/locks.hpp>
#include <boost/thread/condition_variable.hpp>
#include <mutex>
#include <condition_variable>
/** Recursive mutex: supports recursive locking, but no waiting */
typedef std::recursive_mutex CCriticalSection;
/** Wrapped boost mutex: supports recursive locking, but no waiting */
typedef boost::recursive_mutex CCriticalSection;
/** Wrapped boost mutex: supports waiting but not recursive locking */
typedef boost::mutex CWaitableCriticalSection;
/** Plain mutex: supports waiting but not recursive locking */
typedef std::mutex CWaitableCriticalSection;
#ifdef DEBUG_LOCKORDER
void EnterCritical(const char* pszName, const char* pszFile, int nLine, void* cs, bool fTry = false);
@@ -36,7 +31,7 @@ template<typename Mutex>
class CMutexLock
{
private:
boost::unique_lock<Mutex> lock;
std::unique_lock<Mutex> lock;
public:
void Enter(const char* pszName, const char* pszFile, int nLine)
@@ -77,7 +72,7 @@ public:
return lock.owns_lock();
}
CMutexLock(Mutex& mutexIn, const char* pszName, const char* pszFile, int nLine, bool fTry = false) : lock(mutexIn, boost::defer_lock)
CMutexLock(Mutex& mutexIn, const char* pszName, const char* pszFile, int nLine, bool fTry = false) : lock(mutexIn, std::defer_lock)
{
if (fTry)
TryEnter(pszName, pszFile, nLine);
@@ -96,7 +91,7 @@ public:
return lock.owns_lock();
}
boost::unique_lock<Mutex> &GetLock()
std::unique_lock<Mutex> &GetLock()
{
return lock;
}
@@ -123,15 +118,15 @@ typedef CMutexLock<CCriticalSection> CCriticalBlock;
class CSemaphore
{
private:
boost::condition_variable condition;
boost::mutex mutex;
std::condition_variable condition;
std::mutex mutex;
int value;
public:
CSemaphore(int init) : value(init) {}
void wait() {
boost::unique_lock<boost::mutex> lock(mutex);
std::unique_lock<std::mutex> lock(mutex);
while (value < 1) {
condition.wait(lock);
}
@@ -139,7 +134,7 @@ public:
}
bool try_wait() {
boost::unique_lock<boost::mutex> lock(mutex);
std::unique_lock<std::mutex> lock(mutex);
if (value < 1)
return false;
value--;
@@ -148,7 +143,7 @@ public:
void post() {
{
boost::unique_lock<boost::mutex> lock(mutex);
std::unique_lock<std::mutex> lock(mutex);
value++;
}
condition.notify_one();
+7 -9
View File
@@ -3,7 +3,7 @@
//
#include <algorithm>
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <chrono>
#include <boost/test/unit_test.hpp>
#include "main.h"
@@ -249,25 +249,23 @@ BOOST_AUTO_TEST_CASE(DoS_checkSig)
tx.vin[j].prevout.hash = orphans[j].GetHash();
}
// Creating signatures primes the cache:
boost::posix_time::ptime mst1 = boost::posix_time::microsec_clock::local_time();
auto mst1 = std::chrono::steady_clock::now();
for (unsigned int j = 0; j < tx.vin.size(); j++)
BOOST_CHECK(SignSignature(keystore, orphans[j], tx, j));
boost::posix_time::ptime mst2 = boost::posix_time::microsec_clock::local_time();
boost::posix_time::time_duration msdiff = mst2 - mst1;
long nOneValidate = msdiff.total_milliseconds();
auto mst2 = std::chrono::steady_clock::now();
long nOneValidate = std::chrono::duration_cast<std::chrono::milliseconds>(mst2 - mst1).count();
if (fDebug) printf("DoS_Checksig sign: %ld\n", nOneValidate);
// ... now validating repeatedly should be quick:
// 2.8GHz machine, -g build: Sign takes ~760ms,
// uncached Verify takes ~250ms, cached Verify takes ~50ms
// (for 100 single-signature inputs)
mst1 = boost::posix_time::microsec_clock::local_time();
mst1 = std::chrono::steady_clock::now();
for (unsigned int i = 0; i < 5; i++)
for (unsigned int j = 0; j < tx.vin.size(); j++)
BOOST_CHECK(VerifySignature(orphans[j], tx, j, SIGHASH_ALL));
mst2 = boost::posix_time::microsec_clock::local_time();
msdiff = mst2 - mst1;
long nManyValidate = msdiff.total_milliseconds();
mst2 = std::chrono::steady_clock::now();
long nManyValidate = std::chrono::duration_cast<std::chrono::milliseconds>(mst2 - mst1).count();
if (fDebug) printf("DoS_Checksig five: %ld\n", nManyValidate);
BOOST_CHECK_MESSAGE(nManyValidate < nOneValidate, "Signature cache timing failed");
+1 -1
View File
@@ -85,7 +85,7 @@ ParseScript(string s)
Array
read_json(const std::string& filename)
{
namespace fs = boost::filesystem;
namespace fs = std::filesystem;
fs::path testFile = fs::current_path() / "test" / "data" / filename;
#ifdef TEST_DATA_DIR
+6 -7
View File
@@ -7,9 +7,8 @@
#include "anonymize.h"
#include "util.h"
#include <boost/filesystem.hpp>
#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>
#include <thread>
#include <mutex>
#include <string>
#include <cstring>
#include <memory>
@@ -42,10 +41,10 @@ int check_interrupted(
) ? 1 : 0;
}
static boost::mutex initializing;
static std::mutex initializing;
static std::unique_ptr<boost::unique_lock<boost::mutex> > uninitialized(
new boost::unique_lock<boost::mutex>(
static std::unique_ptr<std::unique_lock<std::mutex> > uninitialized(
new std::unique_lock<std::mutex>(
initializing
)
);
@@ -57,5 +56,5 @@ void set_initialized(
void wait_initialized(
) {
boost::unique_lock<boost::mutex> checking(initializing);
std::unique_lock<std::mutex> checking(initializing);
}
+10 -10
View File
@@ -34,7 +34,7 @@
#include <openssl/evp.h>
#include <openssl/rand.h>
#include <openssl/sha.h>
#include <boost/filesystem.hpp>
#include <filesystem>
#include <fstream>
#include <sstream>
#include <set>
@@ -60,12 +60,12 @@ extern CWallet* pwalletMain;
CTorV3Manager* CTorV3Manager::instance = nullptr;
static TorV3Config torV3Config;
static boost::filesystem::path GetBackendHiddenServiceDir(const std::string& torDataDir)
static std::filesystem::path GetBackendHiddenServiceDir(const std::string& torDataDir)
{
return boost::filesystem::path(torDataDir) / "hidden_service";
return std::filesystem::path(torDataDir) / "hidden_service";
}
static bool ReadTrimmedFirstLine(const boost::filesystem::path& path, std::string& valueOut)
static bool ReadTrimmedFirstLine(const std::filesystem::path& path, std::string& valueOut)
{
valueOut.clear();
@@ -573,12 +573,12 @@ bool CTorV3Service::AttachToBackendService(const std::string& torDataDir, int se
port = servicePort;
const boost::filesystem::path serviceDir = GetBackendHiddenServiceDir(torDataDir);
const boost::filesystem::path hostnamePath = serviceDir / "hostname";
const std::filesystem::path serviceDir = GetBackendHiddenServiceDir(torDataDir);
const std::filesystem::path hostnamePath = serviceDir / "hostname";
std::string backendOnion;
for (int waited = 0; waited <= waitSeconds; ++waited) {
if (boost::filesystem::exists(hostnamePath) &&
if (std::filesystem::exists(hostnamePath) &&
ReadTrimmedFirstLine(hostnamePath, backendOnion)) {
break;
}
@@ -616,8 +616,8 @@ bool CTorV3Service::AttachToBackendService(const std::string& torDataDir, int se
// Back up the Tor-generated secret key to wallet.dat so the onion
// identity survives deletion of the tor_data directory.
boost::filesystem::path secretKeyPath = serviceDir / "hs_ed25519_secret_key";
if (boost::filesystem::exists(secretKeyPath)) {
std::filesystem::path secretKeyPath = serviceDir / "hs_ed25519_secret_key";
if (std::filesystem::exists(secretKeyPath)) {
std::ifstream keyFile(secretKeyPath.string().c_str(), std::ios::binary);
if (keyFile.is_open()) {
std::vector<unsigned char> keyData(
@@ -1218,7 +1218,7 @@ bool CTorV3Manager::InitializeTor()
torDataDir = torV3Config.torDataDirectory;
// Create tor data directory
boost::filesystem::create_directories(torDataDir);
std::filesystem::create_directories(torDataDir);
torEnabled = true;
+4 -4
View File
@@ -12,8 +12,8 @@
#include "../util.h"
#include "../net.h"
#include <boost/filesystem.hpp>
#include <boost/thread/thread.hpp>
#include <filesystem>
#include <thread>
#include <fstream>
#include <cstring>
#include <vector>
@@ -35,7 +35,7 @@ extern "C" {
}
#endif
namespace fs = boost::filesystem;
namespace fs = std::filesystem;
// Singleton
CTorEmbedded* CTorEmbedded::instance = nullptr;
@@ -152,7 +152,7 @@ bool CTorEmbedded::Start(int socks, int hsPort, bool enableHiddenService)
running.store(true);
// Launch Tor on a dedicated thread (tor_run_main blocks)
boost::thread torThread(TorThreadFunc, argv);
std::thread torThread(TorThreadFunc, argv);
torThread.detach();
// Wait for SOCKS port to become available (up to 60s)
+1 -1
View File
@@ -35,7 +35,7 @@
#include <unistd.h>
#endif
namespace fs = boost::filesystem;
namespace fs = std::filesystem;
static std::string ReadTailLines(const fs::path& filePath, size_t maxLines)
{
+7 -8
View File
@@ -5,9 +5,8 @@
#include "tor_embed_hooks.h"
#include "util.h"
#include <boost/filesystem.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/thread.hpp>
#include <mutex>
#include <thread>
#include <memory>
#include <string>
@@ -25,13 +24,13 @@ const char* triangles_onion_service_directory()
int triangles_tor_check_interrupted()
{
return boost::this_thread::interruption_requested() ? 1 : 0;
return fShutdown ? 1 : 0;
}
static boost::mutex g_torInitializing;
static std::mutex g_torInitializing;
static std::unique_ptr<boost::unique_lock<boost::mutex> > g_torUninitialized(
new boost::unique_lock<boost::mutex>(g_torInitializing));
static std::unique_ptr<std::unique_lock<std::mutex> > g_torUninitialized(
new std::unique_lock<std::mutex>(g_torInitializing));
void triangles_tor_set_initialized()
{
@@ -40,5 +39,5 @@ void triangles_tor_set_initialized()
void triangles_tor_wait_initialized()
{
boost::unique_lock<boost::mutex> checking(g_torInitializing);
std::unique_lock<std::mutex> checking(g_torInitializing);
}
+4 -13
View File
@@ -18,12 +18,12 @@
#include <boost/asio.hpp>
#include <boost/asio/ip/v6_only.hpp>
#include <boost/bind.hpp>
#include <boost/filesystem.hpp>
#include <filesystem>
#include <boost/iostreams/concepts.hpp>
#include <boost/iostreams/stream.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/asio/ssl.hpp>
#include <boost/filesystem/fstream.hpp>
#include <fstream>
#include <boost/shared_ptr.hpp>
#include <memory>
#include <list>
@@ -34,7 +34,7 @@ using namespace std;
using namespace boost;
using namespace boost::asio;
using namespace json_spirit;
namespace fs = boost::filesystem;
namespace fs = std::filesystem;
void ThreadRPCServer2(void* parg);
@@ -326,7 +326,6 @@ static const CRPCCommand vRPCCommands[] =
{ "repairwallet", &repairwallet, false, true},
{ "resendtx", &resendtx, false, true},
{ "makekeypair", &makekeypair, false, true},
{ "sendalert", &sendalert, false, false},
{ "smsgenable", &smsgenable, false, false},
{ "smsgdisable", &smsgdisable, false, false},
@@ -848,9 +847,7 @@ void ThreadRPCServer2(void* parg)
"rpcpassword=%s\n"
"(you do not need to remember this password)\n"
"The username and password MUST NOT be the same.\n"
"If the file does not exist, create it with owner-readable-only file permissions.\n"
"It is also recommended to set alertnotify so you are notified of problems;\n"
"for example: alertnotify=echo %%s | mail -s \"Triangles Alert\" admin@foo.com\n"),
"If the file does not exist, create it with owner-readable-only file permissions.\n"),
strWhatAmI.c_str(),
GetConfigFile().string().c_str(),
EncodeBase58(&rand_pwd[0],&rand_pwd[0]+32).c_str()),
@@ -1397,12 +1394,6 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector<std::stri
if (strMethod == "walletpassphrase" && n > 2) ConvertTo<bool>(params[2]);
if (strMethod == "listsinceblock" && n > 1) ConvertTo<boost::int64_t>(params[1]);
if (strMethod == "sendalert" && n > 2) ConvertTo<boost::int64_t>(params[2]);
if (strMethod == "sendalert" && n > 3) ConvertTo<boost::int64_t>(params[3]);
if (strMethod == "sendalert" && n > 4) ConvertTo<boost::int64_t>(params[4]);
if (strMethod == "sendalert" && n > 5) ConvertTo<boost::int64_t>(params[5]);
if (strMethod == "sendalert" && n > 6) ConvertTo<boost::int64_t>(params[6]);
if (strMethod == "sendmany" && n > 1) ConvertTo<Object>(params[1]);
if (strMethod == "sendmany" && n > 2) ConvertTo<boost::int64_t>(params[2]);
if (strMethod == "reservebalance" && n > 0) ConvertTo<bool>(params[0]);
-6
View File
@@ -157,8 +157,6 @@ extern json_spirit::Value importwallet(const json_spirit::Array& params, bool fH
extern json_spirit::Value dumpprivkey(const json_spirit::Array& params, bool fHelp); // in rpcdump.cpp
extern json_spirit::Value importprivkey(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value sendalert(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getsubsidy(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getmininginfo(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getstakinginfo(const json_spirit::Array& params, bool fHelp);
@@ -234,10 +232,6 @@ extern json_spirit::Value getaddressbalance(const json_spirit::Array& params, bo
extern json_spirit::Value getaddressutxos(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getaddresstxids(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value clearwallettransactions(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value smsgenable(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value smsgdisable(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value smsglocalkeys(const json_spirit::Array& params, bool fHelp);
+3 -4
View File
@@ -5,9 +5,9 @@
#include <map>
#include <filesystem>
#include <boost/version.hpp>
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <leveldb/env.h>
#include <leveldb/cache.h>
@@ -24,8 +24,7 @@
#include "main.h"
using namespace std;
using namespace boost;
namespace fs = boost::filesystem;
namespace fs = std::filesystem;
leveldb::DB *txdb; // global pointer for LevelDB object instance
+3 -4
View File
@@ -8,9 +8,9 @@
#include <map>
#include <filesystem>
#include <boost/version.hpp>
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <rocksdb/cache.h>
#include <rocksdb/filter_policy.h>
@@ -28,8 +28,7 @@
#include "main.h"
using namespace std;
using namespace boost;
namespace fs = boost::filesystem;
namespace fs = std::filesystem;
// Global pointer for the RocksDB instance, shared across CRocksTxDB instances
// the same way the LevelDB backend shares its txdb singleton.
+20 -1
View File
@@ -1,11 +1,30 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2012 The Bitcoin developers
// Copyright (c) 2026 The Triangles developers
// Distributed under the MIT/X11 software license, see the accompanying
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
#ifndef TRIANGLES_TXDB_H
#define TRIANGLES_TXDB_H
#include "txdb-base.h"
#include "txdb-leveldb.h"
#endif // TRIANGLES_TXDB_H
#ifdef BUILD_ROCKSDB
#include "txdb-rocksdb.h"
#endif
#include <memory>
// Factory: returns a chain-database handle whose concrete backend is chosen
// by the -chaindb command-line argument:
//
// -chaindb=leveldb (default)
// -chaindb=rocksdb (only when built with -DBUILD_ROCKSDB=ON)
//
// Callers receive a CTxDBBase*, so the rest of the codebase stays
// backend-agnostic. Mode strings ("r", "r+", "cr+") match the pre-existing
// CTxDB constructor convention.
std::unique_ptr<CTxDBBase> MakeChainDB(const char* pszMode = "r+");
#endif // TRIANGLES_TXDB_H
-6
View File
@@ -87,12 +87,6 @@ public:
/** Number of network connections changed. */
boost::signals2::signal<void (int newNumConnections)> NotifyNumConnectionsChanged;
/**
* New, updated or cancelled alert.
* @note called with lock cs_mapAlerts held.
*/
boost::signals2::signal<void (const uint256 &hash, ChangeType status)> NotifyAlertChanged;
};
extern CClientUIInterface uiInterface;
+52 -49
View File
@@ -3,32 +3,9 @@
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "util.h"
#include "sync.h"
#include "strlcpy.h"
#include "version.h"
#include "ui_interface.h"
#include <boost/algorithm/string/join.hpp>
// Work around clang compilation problem in Boost 1.46:
// /usr/include/boost/program_options/detail/config_file.hpp:163:17: error: call to function 'to_internal' that is neither visible in the template definition nor found by argument-dependent lookup
// See also: http://stackoverflow.com/questions/10020179/compilation-fail-in-boost-librairies-program-options
// http://clang.debian.net/status.php?version=3.0&key=CANNOT_FIND_FUNCTION
namespace boost {
namespace program_options {
std::string to_internal(const std::string&);
}
}
#include <boost/program_options/detail/config_file.hpp>
#include <boost/program_options/parsers.hpp>
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/thread.hpp>
#include <openssl/crypto.h>
#include <openssl/rand.h>
#include <stdarg.h>
// On Windows, include shell/COM headers FIRST so their `byte` typedef
// is established before any std header pulls in `std::byte` (C++17).
// Otherwise the names collide when COM headers reference `byte`.
#ifdef WIN32
#ifdef _MSC_VER
#pragma warning(disable:4786)
@@ -58,6 +35,32 @@ namespace boost {
#include <execinfo.h>
#endif
#include "util.h"
#include "sync.h"
#include "strlcpy.h"
#include "version.h"
#include "ui_interface.h"
#include <boost/algorithm/string/join.hpp>
// Work around clang compilation problem in Boost 1.46:
// /usr/include/boost/program_options/detail/config_file.hpp:163:17: error: call to function 'to_internal' that is neither visible in the template definition nor found by argument-dependent lookup
// See also: http://stackoverflow.com/questions/10020179/compilation-fail-in-boost-librairies-program-options
// http://clang.debian.net/status.php?version=3.0&key=CANNOT_FIND_FUNCTION
namespace boost {
namespace program_options {
std::string to_internal(const std::string&);
}
}
#include <boost/program_options/detail/config_file.hpp>
#include <boost/program_options/parsers.hpp>
#include <filesystem>
#include <fstream>
#include <thread>
#include <openssl/crypto.h>
#include <openssl/rand.h>
#include <stdarg.h>
using namespace std;
@@ -226,7 +229,7 @@ inline int OutputDebugStringF(const char* pszFormat, ...)
if (!fileout)
{
boost::filesystem::path pathDebug = GetDataDir() / "debug.log";
std::filesystem::path pathDebug = GetDataDir() / "debug.log";
fileout = fopen(pathDebug.string().c_str(), "a");
if (fileout) setbuf(fileout, NULL); // unbuffered
}
@@ -238,14 +241,14 @@ inline int OutputDebugStringF(const char* pszFormat, ...)
// Since the order of destruction of static/global objects is undefined,
// allocate mutexDebugLog on the heap the first time this routine
// is called to avoid crashes during shutdown.
static boost::mutex* mutexDebugLog = NULL;
if (mutexDebugLog == NULL) mutexDebugLog = new boost::mutex();
boost::mutex::scoped_lock scoped_lock(*mutexDebugLog);
static std::mutex* mutexDebugLog = NULL;
if (mutexDebugLog == NULL) mutexDebugLog = new std::mutex();
std::lock_guard<std::mutex> scoped_lock(*mutexDebugLog);
// reopen the log file, if requested
if (fReopenDebugLog) {
fReopenDebugLog = false;
boost::filesystem::path pathDebug = GetDataDir() / "debug.log";
std::filesystem::path pathDebug = GetDataDir() / "debug.log";
if (freopen(pathDebug.string().c_str(),"a",fileout) != NULL)
setbuf(fileout, NULL); // unbuffered
}
@@ -1015,9 +1018,9 @@ void PrintExceptionContinue(std::exception* pex, const char* pszThread)
strMiscWarning = message;
}
boost::filesystem::path GetDefaultDataDir()
std::filesystem::path GetDefaultDataDir()
{
namespace fs = boost::filesystem;
namespace fs = std::filesystem;
// Windows < Vista: C:\Documents and Settings\Username\Application Data\triangles
// Windows >= Vista: C:\Users\Username\AppData\Roaming\triangles
// Mac: ~/Library/Application Support/triangles
@@ -1044,9 +1047,9 @@ boost::filesystem::path GetDefaultDataDir()
#endif
}
const boost::filesystem::path &GetDataDir(bool fNetSpecific)
const std::filesystem::path &GetDataDir(bool fNetSpecific)
{
namespace fs = boost::filesystem;
namespace fs = std::filesystem;
static fs::path pathCached[2];
static CCriticalSection csPathCached;
@@ -1062,7 +1065,7 @@ const boost::filesystem::path &GetDataDir(bool fNetSpecific)
LOCK(csPathCached);
if (mapArgs.count("-datadir")) {
path = fs::system_complete(mapArgs["-datadir"]);
path = fs::absolute(mapArgs["-datadir"]);
if (!fs::is_directory(path)) {
path = "";
return path;
@@ -1079,9 +1082,9 @@ const boost::filesystem::path &GetDataDir(bool fNetSpecific)
return path;
}
boost::filesystem::path GetConfigFile()
std::filesystem::path GetConfigFile()
{
boost::filesystem::path pathConfigFile(GetArg("-conf", "triangles.conf"));
std::filesystem::path pathConfigFile(GetArg("-conf", "triangles.conf"));
if (!pathConfigFile.is_absolute()) pathConfigFile = GetDataDir(false) / pathConfigFile;
return pathConfigFile;
}
@@ -1089,7 +1092,7 @@ boost::filesystem::path GetConfigFile()
void ReadConfigFile(map<string, string>& mapSettingsRet,
map<string, vector<string> >& mapMultiSettingsRet)
{
boost::filesystem::ifstream streamConfig(GetConfigFile());
std::ifstream streamConfig(GetConfigFile());
if (!streamConfig.good())
return; // No triangles.conf file is OK
@@ -1110,15 +1113,15 @@ void ReadConfigFile(map<string, string>& mapSettingsRet,
}
}
boost::filesystem::path GetPidFile()
std::filesystem::path GetPidFile()
{
boost::filesystem::path pathPidFile(GetArg("-pid", "trianglesd.pid"));
std::filesystem::path pathPidFile(GetArg("-pid", "trianglesd.pid"));
if (!pathPidFile.is_absolute()) pathPidFile = GetDataDir() / pathPidFile;
return pathPidFile;
}
#ifndef WIN32
void CreatePidFile(const boost::filesystem::path &path, pid_t pid)
void CreatePidFile(const std::filesystem::path &path, pid_t pid)
{
FILE* file = fopen(path.string().c_str(), "w");
if (file)
@@ -1129,7 +1132,7 @@ void CreatePidFile(const boost::filesystem::path &path, pid_t pid)
}
#endif
bool RenameOver(boost::filesystem::path src, boost::filesystem::path dest)
bool RenameOver(std::filesystem::path src, std::filesystem::path dest)
{
#ifdef WIN32
return MoveFileExA(src.string().c_str(), dest.string().c_str(),
@@ -1153,9 +1156,9 @@ void FileCommit(FILE *fileout)
void ShrinkDebugFile()
{
// Scroll debug.log if it's getting too big
boost::filesystem::path pathLog = GetDataDir() / "debug.log";
std::filesystem::path pathLog = GetDataDir() / "debug.log";
FILE* file = fopen(pathLog.string().c_str(), "r");
if (file && boost::filesystem::file_size(pathLog) > 10 * 1000000)
if (file && std::filesystem::file_size(pathLog) > 10 * 1000000)
{
// Restart the file with some of the end
char pch[200000];
@@ -1291,9 +1294,9 @@ std::string FormatSubVersion(const std::string& name, int nClientVersion, const
}
#ifdef WIN32
boost::filesystem::path GetSpecialFolderPath(int nFolder, bool fCreate)
std::filesystem::path GetSpecialFolderPath(int nFolder, bool fCreate)
{
namespace fs = boost::filesystem;
namespace fs = std::filesystem;
char pszPath[MAX_PATH] = "";
@@ -1339,8 +1342,8 @@ bool NewThread(void(*pfn)(void*), void* parg)
{
try
{
boost::thread(pfn, parg); // thread detaches when out of scope
} catch(boost::thread_resource_error &e) {
std::thread(pfn, parg).detach();
} catch(const std::system_error& e) {
printf("Error creating thread: %s\n", e.what());
return false;
}
+15 -21
View File
@@ -18,11 +18,9 @@
#include <vector>
#include <string>
#include <boost/thread.hpp>
#include <boost/filesystem.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/date_time/gregorian/gregorian_types.hpp>
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <chrono>
#include <thread>
#include <filesystem>
#include <openssl/sha.h>
#include <openssl/ripemd.h>
@@ -107,11 +105,7 @@ T* alignup(T* p)
inline void MilliSleep(int64_t n)
{
#if BOOST_VERSION >= 105000
boost::this_thread::sleep_for(boost::chrono::milliseconds(n));
#else
boost::this_thread::sleep(boost::posix_time::milliseconds(n));
#endif
std::this_thread::sleep_for(std::chrono::milliseconds(n));
}
/* This GNU C extension enables the compiler to check the format string against the parameters provided.
@@ -202,17 +196,17 @@ void ParseParameters(int argc, const char*const argv[]);
bool WildcardMatch(const char* psz, const char* mask);
bool WildcardMatch(const std::string& str, const std::string& mask);
void FileCommit(FILE *fileout);
bool RenameOver(boost::filesystem::path src, boost::filesystem::path dest);
boost::filesystem::path GetDefaultDataDir();
const boost::filesystem::path &GetDataDir(bool fNetSpecific = true);
boost::filesystem::path GetConfigFile();
boost::filesystem::path GetPidFile();
bool RenameOver(std::filesystem::path src, std::filesystem::path dest);
std::filesystem::path GetDefaultDataDir();
const std::filesystem::path &GetDataDir(bool fNetSpecific = true);
std::filesystem::path GetConfigFile();
std::filesystem::path GetPidFile();
#ifndef WIN32
void CreatePidFile(const boost::filesystem::path &path, pid_t pid);
void CreatePidFile(const std::filesystem::path &path, pid_t pid);
#endif
void ReadConfigFile(std::map<std::string, std::string>& mapSettingsRet, std::map<std::string, std::vector<std::string> >& mapMultiSettingsRet);
#ifdef WIN32
boost::filesystem::path GetSpecialFolderPath(int nFolder, bool fCreate = true);
std::filesystem::path GetSpecialFolderPath(int nFolder, bool fCreate = true);
#endif
void ShrinkDebugFile();
int GetRandInt(int nMax);
@@ -343,14 +337,14 @@ inline int64_t GetPerformanceCounter()
inline int64_t GetTimeMillis()
{
return (boost::posix_time::ptime(boost::posix_time::microsec_clock::universal_time()) -
boost::posix_time::ptime(boost::gregorian::date(1970,1,1))).total_milliseconds();
return std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now().time_since_epoch()).count();
}
inline int64_t GetTimeMicros()
{
return (boost::posix_time::ptime(boost::posix_time::microsec_clock::universal_time()) -
boost::posix_time::ptime(boost::gregorian::date(1970,1,1))).total_microseconds();
return std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::system_clock::now().time_since_epoch()).count();
}
inline std::string DateTimeStrFormat(const char* pszFormat, int64_t nTime)
+3 -4
View File
@@ -9,8 +9,7 @@
#include "util.h"
#include "ui_interface.h"
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <filesystem>
#include <leveldb/db.h>
#include <leveldb/write_batch.h>
@@ -23,7 +22,7 @@
#include <algorithm>
#include <cstdio>
namespace fs = boost::filesystem;
namespace fs = std::filesystem;
// Global LevelDB pointer (defined in txdb-leveldb.cpp)
extern leveldb::DB *txdb;
@@ -64,7 +63,7 @@ bool DumpSnapshot(const fs::path& destPath,
// Count UTXOs first
int nUtxoCount = 0;
{
CTxDB txdbRead("r");
auto txdbRead_holder = MakeChainDB("r"); CTxDBBase& txdbRead = *txdbRead_holder;
txdbRead.SumUtxoValues(nUtxoCount);
}
+4 -4
View File
@@ -5,7 +5,7 @@
#define TRIANGLES_UTXOSNAPSHOT_H
#include <string>
#include <boost/filesystem.hpp>
#include <filesystem>
// UTXO snapshot file magic bytes
static const unsigned int UTXO_SNAPSHOT_MAGIC = 0x53585455; // "UTXS" little-endian
@@ -22,7 +22,7 @@ namespace UtxoSnapshot {
// Create a UTXO snapshot from the current chain state.
// Writes last nHeaders block index entries + all UTXOs to destPath.
// Returns true on success, sets strError on failure.
bool DumpSnapshot(const boost::filesystem::path& destPath,
bool DumpSnapshot(const std::filesystem::path& destPath,
unsigned int nHeaders,
std::string& strError);
@@ -30,8 +30,8 @@ namespace UtxoSnapshot {
// Writes block index entries, UTXOs, hashBestChain, and dbformat.
// The LevelDB must NOT be open yet (call before LoadBlockIndex).
// Returns true on success, sets strError on failure.
bool LoadSnapshot(const boost::filesystem::path& snapshotPath,
const boost::filesystem::path& dataDir,
bool LoadSnapshot(const std::filesystem::path& snapshotPath,
const std::filesystem::path& dataDir,
std::string& strError);
} // namespace UtxoSnapshot
+10 -10
View File
@@ -663,7 +663,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn)
if ( !strCmd.empty())
{
boost::replace_all(strCmd, "%s", wtxIn.GetHash().GetHex());
boost::thread t(runCommand, strCmd); // thread runs free
std::thread(runCommand, strCmd).detach(); // thread runs free
}
}
@@ -1041,7 +1041,7 @@ bool CWallet::ScanForWalletTransactionsFromIndex(CBlockIndex* pindexStart, bool
setScripts.insert((*it).first);
}
CTxDB txdb("r");
auto txdb_holder = MakeChainDB("r"); CTxDBBase& txdb = *txdb_holder;
set<uint256> setSeedTxIds;
for (const CKeyID& keyId : setKeys)
@@ -1162,7 +1162,7 @@ int CWallet::ScanForWalletTransaction(const uint256& hashTx)
void CWallet::ReacceptWalletTransactions()
{
CTxDB txdb("r");
auto txdb_holder = MakeChainDB("r"); CTxDBBase& txdb = *txdb_holder;
bool fRepeat = true;
while (fRepeat)
{
@@ -1251,7 +1251,7 @@ void CWalletTx::RelayWalletTransaction(CTxDBBase& txdb)
void CWalletTx::RelayWalletTransaction()
{
CTxDB txdb("r");
auto txdb_holder = MakeChainDB("r"); CTxDBBase& txdb = *txdb_holder;
RelayWalletTransaction(txdb);
}
@@ -1278,7 +1278,7 @@ void CWallet::ResendWalletTransactions(bool fForce)
// Rebroadcast any of our txes that aren't in a block yet
printf("ResendWalletTransactions()\n");
CTxDB txdb("r");
auto txdb_holder = MakeChainDB("r"); CTxDBBase& txdb = *txdb_holder;
{
LOCK(cs_wallet);
// Sort them in chronological order
@@ -1701,7 +1701,7 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, int64_t> >& vecSend,
{
LOCK2(cs_main, cs_wallet);
// txdb must be opened before the mapWallet lock
CTxDB txdb("r");
auto txdb_holder = MakeChainDB("r"); CTxDBBase& txdb = *txdb_holder;
{
nFeeRet = nTransactionFee;
while (true)
@@ -1895,7 +1895,7 @@ bool CWallet::GetStakeWeight(const CKeyStore& keystore, uint64_t& nMinWeight, ui
}
}
CTxDB txdb("r");
auto txdb_holder = MakeChainDB("r"); CTxDBBase& txdb = *txdb_holder;
int64_t nNow = GetTime();
for (auto& sc : vStakeCoins)
{
@@ -1962,7 +1962,7 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int
int64_t nCredit = 0;
CScript scriptPubKeyKernel;
CTxDB txdb("r");
auto txdb_holder = MakeChainDB("r"); CTxDBBase& txdb = *txdb_holder;
for (auto pcoin : setCoins)
{
CTxIndex txindex;
@@ -2104,7 +2104,7 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int
// Calculate coin age reward
{
uint64_t nCoinAge;
CTxDB txdb("r");
auto txdb_holder = MakeChainDB("r"); CTxDBBase& txdb = *txdb_holder;
if (!txNew.GetCoinAge(txdb, nCoinAge))
return error("CreateCoinStake : failed to calculate coin age");
@@ -2689,7 +2689,7 @@ void CWallet::FixSpentCoins(int& nMismatchFound, int64_t& nBalanceInQuestion, bo
for (map<uint256, CWalletTx>::iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
vCoins.push_back(&(*it).second);
CTxDB txdb("r");
auto txdb_holder = MakeChainDB("r"); CTxDBBase& txdb = *txdb_holder;
for (CWalletTx* pcoin : vCoins)
{
uint256 hashTx = pcoin->GetHash();
+2 -3
View File
@@ -5,12 +5,11 @@
#include "walletdb.h"
#include "wallet.h"
#include <filesystem>
#include <boost/version.hpp>
#include <boost/filesystem.hpp>
using namespace std;
using namespace boost;
namespace fs = boost::filesystem;
namespace fs = std::filesystem;
static uint64_t nAccountingEntryNumber = 0;