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
11 changes: 0 additions & 11 deletions src/bloom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,6 @@ CBloomFilter::CBloomFilter(const unsigned int nElements, const double nFPRate, c
{
}

// Private constructor used by CRollingBloomFilter
CBloomFilter::CBloomFilter(const unsigned int nElements, const double nFPRate, const unsigned int nTweakIn) :
vData((unsigned int)(-1 / LN2SQUARED * nElements * log(nFPRate)) / 8),
isFull(false),
isEmpty(true),
nHashFuncs((unsigned int)(vData.size() * 8 / nElements * LN2)),
nTweak(nTweakIn),
nFlags(BLOOM_UPDATE_NONE)
{
}

inline unsigned int CBloomFilter::Hash(unsigned int nHashNum, const std::vector<unsigned char>& vDataToHash) const
{
// 0xFBA4C795 chosen as it guarantees a reasonable bit difference between nHashNum values.
Expand Down
4 changes: 0 additions & 4 deletions src/bloom.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ class CBloomFilter

unsigned int Hash(unsigned int nHashNum, const std::vector<unsigned char>& vDataToHash) const;

// Private constructor for CRollingBloomFilter, no restrictions on size
CBloomFilter(const unsigned int nElements, const double nFPRate, const unsigned int nTweak);
friend class CRollingBloomFilter;

// Check matches for arbitrary script data elements
bool CheckScript(const CScript& script) const;
// Check additional matches for special transactions
Expand Down
2 changes: 1 addition & 1 deletion src/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ void BCLog::Logger::ShrinkDebugFile()
size_t log_size = 0;
try {
log_size = fs::file_size(m_file_path);
} catch (boost::filesystem::filesystem_error &) {}
} catch (const fs::filesystem_error&) {}

// If debug.log file is more than 10% bigger the RECENT_DEBUG_HISTORY_SIZE
// trim it down by saving only the last RECENT_DEBUG_HISTORY_SIZE bytes
Expand Down
13 changes: 0 additions & 13 deletions src/rpc/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1137,18 +1137,6 @@ static UniValue echo(const JSONRPCRequest& request)
return request.params;
}

static UniValue getinfo_deprecated(const JSONRPCRequest& request)
{
throw JSONRPCError(RPC_METHOD_NOT_FOUND,
"getinfo\n"
"\nThis call was removed in version 0.16.0. Use the appropriate fields from:\n"
"- getblockchaininfo: blocks, difficulty, chain\n"
"- getnetworkinfo: version, protocolversion, timeoffset, connections, proxy, relayfee, warnings\n"
"- getwalletinfo: balance, coinjoin_balance, keypoololdest, keypoolsize, paytxfee, unlocked_until, walletversion\n"
"\ndash-cli has the option -getinfo to collect and format these in the old format."
);
}

static const CRPCCommand commands[] =
{ // category name actor (function) argNames
// --------------------- ------------------------ ----------------------- ----------
Expand Down Expand Up @@ -1176,7 +1164,6 @@ static const CRPCCommand commands[] =
{ "hidden", "setmocktime", &setmocktime, {"timestamp"}},
{ "hidden", "echo", &echo, {"arg0","arg1","arg2","arg3","arg4","arg5","arg6","arg7","arg8","arg9"}},
{ "hidden", "echojson", &echo, {"arg0","arg1","arg2","arg3","arg4","arg5","arg6","arg7","arg8","arg9"}},
{ "hidden", "getinfo", &getinfo_deprecated, {}},
{ "hidden", "mnauth", &mnauth, {"nodeId", "proTxHash", "publicKey"}},
};

Expand Down
6 changes: 3 additions & 3 deletions src/wallet/rpcdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -874,15 +874,15 @@ UniValue dumpwallet(const JSONRPCRequest& request)

EnsureWalletIsUnlocked(pwallet);

boost::filesystem::path filepath = request.params[0].get_str();
filepath = boost::filesystem::absolute(filepath);
fs::path filepath = request.params[0].get_str();
filepath = fs::absolute(filepath);

/* Prevent arbitrary files from being overwritten. There have been reports
* that users have overwritten wallet files this way:
* https://github.com/bitcoin/bitcoin/issues/9934
* It may also avoid other security issues.
*/
if (boost::filesystem::exists(filepath)) {
Comment thread
Munkybooty marked this conversation as resolved.
Outdated
if (fs::exists(filepath)) {
throw JSONRPCError(RPC_INVALID_PARAMETER, filepath.string() + " already exists. If you are sure this is what you want, move it out of the way first");
}

Expand Down
4 changes: 2 additions & 2 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1785,7 +1785,7 @@ static void ListTransactions(CWallet * const pwallet, const CWalletTx& wtx, cons
{
if (wtx.GetDepthInMainChain() < 1)
entry.pushKV("category", "orphan");
else if (wtx.GetBlocksToMaturity() > 0)
else if (wtx.IsImmatureCoinBase())
entry.pushKV("category", "immature");
else
entry.pushKV("category", "generate");
Expand Down Expand Up @@ -2098,7 +2098,7 @@ static UniValue listaccounts(const JSONRPCRequest& request)
std::list<COutputEntry> listReceived;
std::list<COutputEntry> listSent;
int nDepth = wtx.GetDepthInMainChain();
if (wtx.GetBlocksToMaturity() > 0 || nDepth < 0)
if (wtx.IsImmatureCoinBase() || nDepth < 0)
continue;
wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount, includeWatchonly);
mapAccountBalances[strSentAccount] -= nFee;
Expand Down
21 changes: 12 additions & 9 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2347,7 +2347,7 @@ CAmount CWalletTx::GetDebit(const isminefilter& filter) const
CAmount CWalletTx::GetCredit(const isminefilter& filter) const
{
// Must wait until coinbase is safely deep enough in the chain before valuing it
if (IsCoinBase() && GetBlocksToMaturity() > 0)
if (IsImmatureCoinBase())
return 0;

CAmount credit = 0;
Expand Down Expand Up @@ -2379,8 +2379,7 @@ CAmount CWalletTx::GetCredit(const isminefilter& filter) const

CAmount CWalletTx::GetImmatureCredit(bool fUseCache) const
{
if (IsCoinBase() && GetBlocksToMaturity() > 0 && IsInMainChain())
{
if (IsImmatureCoinBase() && IsInMainChain()) {
if (fUseCache && fImmatureCreditCached)
return nImmatureCreditCached;
nImmatureCreditCached = pwallet->GetCredit(*tx, ISMINE_SPENDABLE);
Expand All @@ -2397,7 +2396,7 @@ CAmount CWalletTx::GetAvailableCredit(bool fUseCache, const isminefilter& filter
return 0;

// Must wait until coinbase is safely deep enough in the chain before valuing it
if (IsCoinBase() && GetBlocksToMaturity() > 0)
if (IsImmatureCoinBase())
return 0;

CAmount* cache = nullptr;
Expand Down Expand Up @@ -2438,8 +2437,7 @@ CAmount CWalletTx::GetAvailableCredit(bool fUseCache, const isminefilter& filter

CAmount CWalletTx::GetImmatureWatchOnlyCredit(const bool fUseCache) const
{
if (IsCoinBase() && GetBlocksToMaturity() > 0 && IsInMainChain())
{
if (IsImmatureCoinBase() && IsInMainChain()) {
if (fUseCache && fImmatureWatchCreditCached)
return nImmatureWatchCreditCached;
nImmatureWatchCreditCached = pwallet->GetCredit(*tx, ISMINE_WATCH_ONLY);
Expand Down Expand Up @@ -2848,7 +2846,7 @@ CAmount CWallet::GetLegacyBalance(const isminefilter& filter, int minDepth, cons
for (const auto& entry : mapWallet) {
const CWalletTx& wtx = entry.second;
const int depth = wtx.GetDepthInMainChain();
if (depth < 0 || !CheckFinalTx(*wtx.tx) || wtx.GetBlocksToMaturity() > 0) {
if (depth < 0 || !CheckFinalTx(*wtx.tx) || wtx.IsImmatureCoinBase()) {
continue;
}

Expand Down Expand Up @@ -2908,7 +2906,7 @@ void CWallet::AvailableCoins(std::vector<COutput> &vCoins, bool fOnlySafe, const
if (!CheckFinalTx(*pcoin->tx))
continue;

if (pcoin->IsCoinBase() && pcoin->GetBlocksToMaturity() > 0)
if (pcoin->IsImmatureCoinBase())
continue;

int nDepth = pcoin->GetDepthInMainChain();
Expand Down Expand Up @@ -4455,7 +4453,7 @@ std::map<CTxDestination, CAmount> CWallet::GetAddressBalances()
if (!pcoin->IsTrusted())
continue;

if (pcoin->IsCoinBase() && pcoin->GetBlocksToMaturity() > 0)
if (pcoin->IsImmatureCoinBase())
continue;

int nDepth = pcoin->GetDepthInMainChain();
Expand Down Expand Up @@ -5549,6 +5547,11 @@ int CMerkleTx::GetBlocksToMaturity() const
return std::max(0, (COINBASE_MATURITY+1) - chain_depth);
}

bool CMerkleTx::IsImmatureCoinBase() const
{
// note GetBlocksToMaturity is 0 for non-coinbase tx
return GetBlocksToMaturity() > 0;
}

bool CWalletTx::AcceptToMemoryPool(const CAmount& nAbsurdFee, CValidationState& state)
{
Expand Down
7 changes: 7 additions & 0 deletions src/wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,20 @@ class CMerkleTx
bool IsInMainChain() const { return GetDepthInMainChain() > 0; }
bool IsLockedByInstantSend() const;
bool IsChainLocked() const;

/**
* @return number of blocks to maturity for this transaction:
* 0 : is not a coinbase transaction, or is a mature coinbase transaction
* >0 : is a coinbase transaction which matures in this many blocks
*/
int GetBlocksToMaturity() const;
bool hashUnset() const { return (hashBlock.IsNull() || hashBlock == ABANDON_HASH); }
bool isAbandoned() const { return (hashBlock == ABANDON_HASH); }
void setAbandoned() { hashBlock = ABANDON_HASH; }

const uint256& GetHash() const { return tx->GetHash(); }
bool IsCoinBase() const { return tx->IsCoinBase(); }
bool IsImmatureCoinBase() const;
};

//Get the marginal bytes of spending the specified output
Expand Down
3 changes: 2 additions & 1 deletion src/wallet/walletdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,8 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
return false;
}
}
else if (strType != "bestblock" && strType != "bestblock_nomerkle"){
else if (strType != "bestblock" && strType != "bestblock_nomerkle" &&
strType != "minversion"){
wss.m_unknown_records++;
}
} catch (...)
Expand Down
4 changes: 2 additions & 2 deletions test/functional/feature_blocksdir.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ def run_test(self):
assert not os.path.isdir(os.path.join(self.nodes[0].datadir, "blocks"))
shutil.rmtree(self.nodes[0].datadir)
initialize_datadir(self.options.tmpdir, 0, self.chain)
self.log.info("Starting with non exiting blocksdir ...")
self.log.info("Starting with nonexistent blocksdir ...")
blocksdir_path = os.path.join(self.options.tmpdir, 'blocksdir')
self.nodes[0].assert_start_raises_init_error(["-blocksdir=" + blocksdir_path], 'Error: Specified blocks directory "' +
blocksdir_path + '" does not exist.')
os.mkdir(blocksdir_path)
self.log.info("Starting with exiting blocksdir ...")
self.log.info("Starting with existing blocksdir ...")
self.start_node(0, ["-blocksdir=" + blocksdir_path])
self.log.info("mining blocks..")
self.nodes[0].generate(10)
Expand Down