Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ set(WALLET_SOURCES
./src/zpiv/mintpool.cpp
./src/wallet/hdchain.cpp
./src/wallet/rpcdump.cpp
./src/zpiv/deterministicmint.cpp
./src/zpiv/zerocoin.cpp
./src/wallet/scriptpubkeyman.cpp
./src/wallet/rpcwallet.cpp
Expand Down Expand Up @@ -389,7 +388,6 @@ set(COMMON_SOURCES
./src/consensus/tx_verify.cpp
./src/consensus/zerocoin_verify.cpp
./src/primitives/block.cpp
./src/zpiv/deterministicmint.cpp
./src/primitives/transaction.cpp
./src/zpiv/zerocoin.cpp
./src/core_read.cpp
Expand Down
3 changes: 0 additions & 3 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,6 @@ BITCOIN_CORE_H = \
wallet/walletdb.h \
warnings.h \
zpivchain.h \
zpiv/deterministicmint.h \
zpiv/mintpool.h \
zpiv/zerocoin.h \
zpiv/zpos.h \
Expand Down Expand Up @@ -404,7 +403,6 @@ libbitcoin_wallet_a_SOURCES = \
destination_io.cpp \
wallet/wallet.cpp \
wallet/walletdb.cpp \
zpiv/deterministicmint.cpp \
zpiv/zerocoin.cpp \
zpiv/mintpool.cpp \
stakeinput.cpp \
Expand Down Expand Up @@ -497,7 +495,6 @@ libbitcoin_common_a_SOURCES = \
compressor.cpp \
consensus/merkle.cpp \
primitives/block.cpp \
zpiv/deterministicmint.cpp \
primitives/transaction.cpp \
zpiv/zerocoin.cpp \
core_read.cpp \
Expand Down
41 changes: 18 additions & 23 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,9 @@
#include "validationinterface.h"
#include "zpivchain.h"

// Sapling
#include "sapling/sapling_util.h"
#include <librustzcash.h>

#ifdef ENABLE_WALLET
#include "wallet/db.h"
#include "wallet/wallet.h"
#include "wallet/walletdb.h"
#include "wallet/rpcwallet.h"

#endif
Expand Down Expand Up @@ -154,8 +149,7 @@ CClientUIInterface uiInterface; // Declared but not defined in guiinterface.h
// shutdown thing.
//

volatile bool fRequestShutdown = false;
std::atomic<bool> fDumpMempoolLater(false);
std::atomic<bool> fRequestShutdown{false};

void StartShutdown()
{
Expand Down Expand Up @@ -254,7 +248,7 @@ void PrepareShutdown()
DumpBudgets(g_budgetman);
DumpMasternodePayments();
UnregisterNodeSignals(GetNodeSignals());
if (fDumpMempoolLater && gArgs.GetBoolArg("-persistmempool", DEFAULT_PERSIST_MEMPOOL)) {
if (g_is_mempool_loaded && gArgs.GetBoolArg("-persistmempool", DEFAULT_PERSIST_MEMPOOL)) {
DumpMempool();
}

Expand Down Expand Up @@ -368,7 +362,7 @@ void HandleSIGHUP(int)
#ifndef WIN32
static void registerSignalHandler(int signal, void(*handler)(int))
{
struct sigaction sa;
struct sigaction sa{};
sa.sa_handler = handler;
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
Expand Down Expand Up @@ -406,7 +400,7 @@ void OnRPCPreCommand(const CRPCCommand& cmd)
{
// Observe safe mode
std::string strWarning = GetWarnings("rpc");
if (strWarning != "" && !gArgs.GetBoolArg("-disablesafemode", DEFAULT_DISABLE_SAFEMODE) &&
if (!strWarning.empty() && !gArgs.GetBoolArg("-disablesafemode", DEFAULT_DISABLE_SAFEMODE) &&
!cmd.okSafeMode)
throw JSONRPCError(RPC_FORBIDDEN_BY_SAFE_MODE, std::string("Safe mode: ") + strWarning);
}
Expand Down Expand Up @@ -669,9 +663,10 @@ struct CImportingNow {
}
};

void ThreadImport(std::vector<fs::path> vImportFiles)
void ThreadImport(const std::vector<fs::path>& vImportFiles)
{
util::ThreadRename("pivx-loadblk");
ScheduleBatchPriority();

// -reindex
if (fReindex) {
Expand Down Expand Up @@ -711,7 +706,7 @@ void ThreadImport(std::vector<fs::path> vImportFiles)
}

// -loadblock=
for (fs::path& path : vImportFiles) {
for (const fs::path& path : vImportFiles) {
FILE* file = fsbridge::fopen(path, "rb");
if (file) {
CImportingNow imp;
Expand All @@ -729,8 +724,8 @@ void ThreadImport(std::vector<fs::path> vImportFiles)

if (gArgs.GetBoolArg("-persistmempool", DEFAULT_PERSIST_MEMPOOL)) {
LoadMempool();
fDumpMempoolLater = !fRequestShutdown;
}
g_is_mempool_loaded = !fRequestShutdown;
}

/** Sanity checks
Expand All @@ -757,9 +752,9 @@ bool InitSanityCheck(void)

static void LoadSaplingParams()
{
struct timeval tv_start, tv_end;
struct timeval tv_start{}, tv_end{};
float elapsed;
gettimeofday(&tv_start, 0);
gettimeofday(&tv_start, nullptr);

try {
initZKSNARKS();
Expand All @@ -774,7 +769,7 @@ static void LoadSaplingParams()
return;
}

gettimeofday(&tv_end, 0);
gettimeofday(&tv_end, nullptr);
elapsed = float(tv_end.tv_sec-tv_start.tv_sec) + (tv_end.tv_usec-tv_start.tv_usec)/float(1000000);
LogPrintf("Loaded Sapling parameters in %fs seconds.\n", elapsed);
}
Expand Down Expand Up @@ -808,7 +803,7 @@ bool AppInitServers()

// The log was successful, terminate now.
std::terminate();
};
}

namespace { // Variables internal to initialization process only

Expand Down Expand Up @@ -1451,7 +1446,7 @@ bool AppInitMain()
// -noproxy (or -proxy=0) as well as the empty string can be used to not set a proxy, this is the default
std::string proxyArg = gArgs.GetArg("-proxy", "");
SetLimited(NET_TOR);
if (proxyArg != "" && proxyArg != "0") {
if (!proxyArg.empty() && proxyArg != "0") {
CService proxyAddr;
if (!Lookup(proxyArg.c_str(), proxyAddr, 9050, fNameLookup)) {
return UIError(strprintf(_("Lookup(): Invalid -proxy address or hostname: '%s'"), proxyArg));
Expand All @@ -1472,7 +1467,7 @@ bool AppInitMain()
// -noonion (or -onion=0) disables connecting to .onion entirely
// An empty string is used to not override the onion proxy (in which case it defaults to -proxy set above, or none)
std::string onionArg = gArgs.GetArg("-onion", "");
if (onionArg != "") {
if (!onionArg.empty()) {
if (onionArg == "0") { // Handle -noonion/-onion=0
SetLimited(NET_TOR); // set onions as unreachable
} else {
Expand Down Expand Up @@ -1606,7 +1601,7 @@ bool AppInitMain()
sporkManager.LoadSporksFromDB();

uiInterface.InitMessage(_("Loading block index..."));
std::string strBlockIndexError = "";
std::string strBlockIndexError;
if (!LoadBlockIndex(strBlockIndexError)) {
if (ShutdownRequested()) break;
strLoadError = _("Error loading block database");
Expand Down Expand Up @@ -1781,7 +1776,7 @@ bool AppInitMain()

std::vector<fs::path> vImportFiles;
for (const std::string& strFile : gArgs.GetArgs("-loadblock")) {
vImportFiles.push_back(strFile);;
vImportFiles.emplace_back(strFile);
}
threadGroup.create_thread(std::bind(&ThreadImport, vImportFiles));

Expand Down Expand Up @@ -1862,10 +1857,10 @@ bool AppInitMain()
LOCK(pwalletMain->cs_wallet);
LogPrintf("Locking Masternodes:\n");
uint256 mnTxHash;
for (CMasternodeConfig::CMasternodeEntry mne : masternodeConfig.getEntries()) {
for (const CMasternodeConfig::CMasternodeEntry& mne : masternodeConfig.getEntries()) {
LogPrintf(" %s %s\n", mne.getTxHash(), mne.getOutputIndex());
mnTxHash.SetHex(mne.getTxHash());
COutPoint outpoint = COutPoint(mnTxHash, (unsigned int) std::stoul(mne.getOutputIndex().c_str()));
COutPoint outpoint = COutPoint(mnTxHash, (unsigned int) std::stoul(mne.getOutputIndex()));
pwalletMain->LockCoin(outpoint);
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/legacy/validation_zerocoin_legacy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ bool AcceptToMemoryPoolZerocoin(const CTransaction& tx, CAmount& nValueIn, int c
return true;
}

bool DisconnectZerocoinTx(const CTransaction& tx, CAmount& nValueIn, CZerocoinDB* zerocoinDB)
bool DisconnectZerocoinTx(const CTransaction& tx, CZerocoinDB* zerocoinDB)
{
/** UNDO ZEROCOIN DATABASING
* note we only undo zerocoin databasing in the following statement, value to and from PIVX
Expand All @@ -63,11 +63,9 @@ bool DisconnectZerocoinTx(const CTransaction& tx, CAmount& nValueIn, CZerocoinDB
return error("Failed to parse public spend");
}
serial = publicSpend.getCoinSerialNumber();
nValueIn += publicSpend.getDenomination() * COIN;
} else {
libzerocoin::CoinSpend spend = TxInToZerocoinSpend(txin);
serial = spend.getCoinSerialNumber();
nValueIn += spend.getDenomination() * COIN;
}

if (!zerocoinDB->EraseCoinSpend(serial))
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/validation_zerocoin_legacy.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "validationinterface.h"

bool AcceptToMemoryPoolZerocoin(const CTransaction& tx, CAmount& nValueIn, int chainHeight, CValidationState& state, const Consensus::Params& consensus);
bool DisconnectZerocoinTx(const CTransaction& tx, CAmount& nValueIn, CZerocoinDB* zerocoinDB);
bool DisconnectZerocoinTx(const CTransaction& tx, CZerocoinDB* zerocoinDB);
void DataBaseAccChecksum(const CBlockIndex* pindex, bool fWrite);

#endif //VALIDATION_ZEROCOIN_LEGACY_H
1 change: 0 additions & 1 deletion src/stakeinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#include "chain.h"
#include "txdb.h"
#include "zpiv/deterministicmint.h"
#include "wallet/wallet.h"

CPivStake* CPivStake::NewPivStake(const CTxIn& txin)
Expand Down
15 changes: 15 additions & 0 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

#include <algorithm>
#include <fcntl.h>
#include <sched.h>
#include <sys/resource.h>
#include <sys/stat.h>

Expand Down Expand Up @@ -838,3 +839,17 @@ int GetNumCores()
return std::thread::hardware_concurrency();
}


int ScheduleBatchPriority(void)
{
#ifdef SCHED_BATCH
const static sched_param param{.sched_priority = 0};
if (int ret = pthread_setschedparam(0, SCHED_BATCH, &param)) {
LogPrintf("Failed to pthread_setschedparam: %s\n", strerror(errno));
return ret;
}
return 0;
#else
return 1;
#endif
}
9 changes: 9 additions & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,4 +261,13 @@ void TraceThread(const char* name, Callable func)

fs::path AbsPathForConfigVal(const fs::path& path, bool net_specific = true);

/**
* On platforms that support it, tell the kernel the calling thread is
* CPU-intensive and non-interactive. See SCHED_BATCH in sched(7) for details.
*
* @return The return value of sched_setschedule(), or 1 on systems without
* sched_setchedule().
*/
int ScheduleBatchPriority(void);

#endif // BITCOIN_UTIL_H
9 changes: 2 additions & 7 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ int64_t nMaxTipAge = DEFAULT_MAX_TIP_AGE;
CFeeRate minRelayTxFee = CFeeRate(10000);

CTxMemPool mempool(::minRelayTxFee);
std::atomic_bool g_is_mempool_loaded{false};

std::map<uint256, int64_t> mapRejectedBlocks;

Expand Down Expand Up @@ -1252,8 +1253,6 @@ DisconnectResult DisconnectBlock(CBlock& block, const CBlockIndex* pindex, CCoin
bool fClean = true;

CBlockUndo blockUndo;
CAmount nValueOut = 0;
CAmount nValueIn = 0;
CDiskBlockPos pos = pindex->GetUndoPos();
if (pos.IsNull()) {
error("%s: no undo data available", __func__);
Expand All @@ -1273,10 +1272,9 @@ DisconnectResult DisconnectBlock(CBlock& block, const CBlockIndex* pindex, CCoin
for (int i = block.vtx.size() - 1; i >= 0; i--) {
const CTransaction& tx = *block.vtx[i];

if (!DisconnectZerocoinTx(tx, nValueIn, zerocoinDB))
if (!DisconnectZerocoinTx(tx, zerocoinDB))
return DISCONNECT_FAILED;

nValueOut += tx.GetValueOut();
const uint256& hash = tx.GetHash();

// if tx is a budget collateral tx, remove relative object
Expand Down Expand Up @@ -1316,9 +1314,6 @@ DisconnectResult DisconnectBlock(CBlock& block, const CBlockIndex* pindex, CCoin
fClean = fClean && res != DISCONNECT_UNCLEAN;
}
// At this point, all of txundo.vprevout should have been moved out.

if (view.HaveInputs(tx))
nValueIn += view.GetValueIn(tx);
}

const Consensus::Params& consensus = Params().GetConsensus();
Expand Down
1 change: 1 addition & 0 deletions src/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ struct BlockHasher {
extern CScript COINBASE_FLAGS;
extern RecursiveMutex cs_main;
extern CTxMemPool mempool;
extern std::atomic_bool g_is_mempool_loaded;
typedef std::unordered_map<uint256, CBlockIndex*, BlockHasher> BlockMap;
extern BlockMap mapBlockIndex;
extern uint64_t nLastBlockTx;
Expand Down
1 change: 0 additions & 1 deletion src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include <stdint.h>

#include "spork.h"
#include "zpiv/deterministicmint.h"

#include <univalue.h>
#include <iostream>
Expand Down
1 change: 0 additions & 1 deletion src/wallet/walletdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "util.h"
#include "utiltime.h"
#include "wallet/wallet.h"
#include <zpiv/deterministicmint.h>

#include <atomic>
#include <string>
Expand Down
1 change: 0 additions & 1 deletion src/wallet/walletdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class CMasterKey;
class CScript;
class CWallet;
class CWalletTx;
class CDeterministicMint;
class uint160;
class uint256;

Expand Down
44 changes: 0 additions & 44 deletions src/zpiv/deterministicmint.cpp

This file was deleted.

Loading