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
1 change: 1 addition & 0 deletions src/.clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Checks: '
-*,
bugprone-argument-comment,
modernize-use-nullptr,
readability-const-return-type,
readability-redundant-declaration,
readability-redundant-string-init,
'
Expand Down
28 changes: 14 additions & 14 deletions src/arith_uint256.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ class base_uint

explicit base_uint(const std::string& str);

const base_uint operator~() const
base_uint operator~() const
{
base_uint ret;
for (int i = 0; i < WIDTH; i++)
ret.pn[i] = ~pn[i];
return ret;
}

const base_uint operator-() const
base_uint operator-() const
{
base_uint ret;
for (int i = 0; i < WIDTH; i++)
Expand Down Expand Up @@ -171,7 +171,7 @@ class base_uint
return *this;
}

const base_uint operator++(int)
base_uint operator++(int)
{
// postfix operator
const base_uint ret = *this;
Expand All @@ -188,7 +188,7 @@ class base_uint
return *this;
}

const base_uint operator--(int)
base_uint operator--(int)
{
// postfix operator
const base_uint ret = *this;
Expand All @@ -199,16 +199,16 @@ class base_uint
int CompareTo(const base_uint& b) const;
bool EqualTo(uint64_t b) const;

friend inline const base_uint operator+(const base_uint& a, const base_uint& b) { return base_uint(a) += b; }
friend inline const base_uint operator-(const base_uint& a, const base_uint& b) { return base_uint(a) -= b; }
friend inline const base_uint operator*(const base_uint& a, const base_uint& b) { return base_uint(a) *= b; }
friend inline const base_uint operator/(const base_uint& a, const base_uint& b) { return base_uint(a) /= b; }
friend inline const base_uint operator|(const base_uint& a, const base_uint& b) { return base_uint(a) |= b; }
friend inline const base_uint operator&(const base_uint& a, const base_uint& b) { return base_uint(a) &= b; }
friend inline const base_uint operator^(const base_uint& a, const base_uint& b) { return base_uint(a) ^= b; }
friend inline const base_uint operator>>(const base_uint& a, int shift) { return base_uint(a) >>= shift; }
friend inline const base_uint operator<<(const base_uint& a, int shift) { return base_uint(a) <<= shift; }
friend inline const base_uint operator*(const base_uint& a, uint32_t b) { return base_uint(a) *= b; }
friend inline base_uint operator+(const base_uint& a, const base_uint& b) { return base_uint(a) += b; }
friend inline base_uint operator-(const base_uint& a, const base_uint& b) { return base_uint(a) -= b; }
friend inline base_uint operator*(const base_uint& a, const base_uint& b) { return base_uint(a) *= b; }
friend inline base_uint operator/(const base_uint& a, const base_uint& b) { return base_uint(a) /= b; }
friend inline base_uint operator|(const base_uint& a, const base_uint& b) { return base_uint(a) |= b; }
friend inline base_uint operator&(const base_uint& a, const base_uint& b) { return base_uint(a) &= b; }
friend inline base_uint operator^(const base_uint& a, const base_uint& b) { return base_uint(a) ^= b; }
friend inline base_uint operator>>(const base_uint& a, int shift) { return base_uint(a) >>= shift; }
friend inline base_uint operator<<(const base_uint& a, int shift) { return base_uint(a) <<= shift; }
friend inline base_uint operator*(const base_uint& a, uint32_t b) { return base_uint(a) *= b; }
friend inline bool operator==(const base_uint& a, const base_uint& b) { return memcmp(a.pn, b.pn, sizeof(a.pn)) == 0; }
friend inline bool operator!=(const base_uint& a, const base_uint& b) { return memcmp(a.pn, b.pn, sizeof(a.pn)) != 0; }
friend inline bool operator>(const base_uint& a, const base_uint& b) { return a.CompareTo(b) > 0; }
Expand Down
2 changes: 1 addition & 1 deletion src/bench/gcs_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <bench/bench.h>
#include <blockfilter.h>

static const GCSFilter::ElementSet GenerateGCSTestElements()
static GCSFilter::ElementSet GenerateGCSTestElements()
{
GCSFilter::ElementSet elements;

Expand Down
2 changes: 2 additions & 0 deletions src/core_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ void ScriptToUniv(const CScript& script, UniValue& out, bool include_hex, bool i

void TxToUniv(const CTransaction& tx, const uint256& block_hash, UniValue& entry, bool include_hex, int serialize_flags, const CTxUndo* txundo, TxVerbosity verbosity, const CSpentIndexTxInfo* ptxSpentInfo)
{
CHECK_NONFATAL(verbosity >= TxVerbosity::SHOW_DETAILS);

uint256 txid = tx.GetHash();
entry.pushKV("txid", txid.GetHex());
// Transaction version is actually unsigned in consensus checks, just signed in memory,
Expand Down
2 changes: 1 addition & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ void SetupServerArgs(ArgsManager& argsman)
argsman.AddArg("-rest", strprintf("Accept public REST requests (default: %u)", DEFAULT_REST_ENABLE), ArgsManager::ALLOW_ANY, OptionsCategory::RPC);
argsman.AddArg("-rpcallowip=<ip>", "Allow JSON-RPC connections from specified source. Valid values for <ip> are a single IP (e.g. 1.2.3.4), a network/netmask (e.g. 1.2.3.4/255.255.255.0), a network/CIDR (e.g. 1.2.3.4/24), all ipv4 (0.0.0.0/0), or all ipv6 (::/0). This option can be specified multiple times", ArgsManager::ALLOW_ANY, OptionsCategory::RPC);
argsman.AddArg("-rpcauth=<userpw>", "Username and HMAC-SHA-256 hashed password for JSON-RPC connections. The field <userpw> comes in the format: <USERNAME>:<SALT>$<HASH>. A canonical python script is included in share/rpcuser. The client then connects normally using the rpcuser=<USERNAME>/rpcpassword=<PASSWORD> pair of arguments. This option can be specified multiple times", ArgsManager::ALLOW_ANY | ArgsManager::SENSITIVE, OptionsCategory::RPC);
argsman.AddArg("-rpcbind=<addr>[:port]", "Bind to given address to listen for JSON-RPC connections. Do not expose the RPC server to untrusted networks such as the public internet! This option is ignored unless -rpcallowip is also passed. Port is optional and overrides -rpcport. Use [host]:port notation for IPv6. This option can be specified multiple times (default: 127.0.0.1 and ::1 i.e., localhost, or if -rpcallowip has been specified, 0.0.0.0 and :: i.e., all addresses)", ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY | ArgsManager::SENSITIVE, OptionsCategory::RPC);
argsman.AddArg("-rpcbind=<addr>[:port]", "Bind to given address to listen for JSON-RPC connections. Do not expose the RPC server to untrusted networks such as the public internet! This option is ignored unless -rpcallowip is also passed. Port is optional and overrides -rpcport. Use [host]:port notation for IPv6. This option can be specified multiple times (default: 127.0.0.1 and ::1 i.e., localhost, or if -rpcallowip has been specified, 0.0.0.0 and :: i.e., all addresses)", ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, OptionsCategory::RPC);
argsman.AddArg("-rpccookiefile=<loc>", "Location of the auth cookie. Relative paths will be prefixed by a net-specific datadir location. (default: data dir)", ArgsManager::ALLOW_ANY, OptionsCategory::RPC);
argsman.AddArg("-rpcexternaluser=<users>", "List of comma-separated usernames for JSON-RPC external connections", ArgsManager::ALLOW_ANY | ArgsManager::SENSITIVE, OptionsCategory::RPC);
argsman.AddArg("-rpcexternalworkqueue=<n>", strprintf("Set the depth of the work queue to service external RPC calls (default: %d)", DEFAULT_HTTP_WORKQUEUE), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::RPC);
Expand Down
3 changes: 2 additions & 1 deletion src/llmq/quorums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,8 @@ PeerMsgRet CQuorumManager::ProcessMessage(CNode& pfrom, CConnman& connman, const
break;
}
request.SetError(nError);
CDataStream ssResponse(SER_NETWORK, pfrom.GetCommonVersion(), request, body);
CDataStream ssResponse{SER_NETWORK, pfrom.GetCommonVersion()};
ssResponse << request << body;
connman.PushMessage(&pfrom, CNetMsgMaker(pfrom.GetCommonVersion()).Make(NetMsgType::QDATA, ssResponse));
return ret;
};
Expand Down
4 changes: 2 additions & 2 deletions src/qt/optionsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

const char *DEFAULT_GUI_PROXY_HOST = "127.0.0.1";

static const QString GetDefaultProxyAddress();
static QString GetDefaultProxyAddress();

OptionsModel::OptionsModel(QObject *parent, bool resetSettings) :
QAbstractListModel(parent)
Expand Down Expand Up @@ -405,7 +405,7 @@ static void SetProxySetting(QSettings &settings, const QString &name, const Prox
settings.setValue(name, QString{ip_port.ip + QLatin1Char(':') + ip_port.port});
}

static const QString GetDefaultProxyAddress()
static QString GetDefaultProxyAddress()
{
return QString("%1:%2").arg(DEFAULT_GUI_PROXY_HOST).arg(DEFAULT_GUI_PROXY_PORT);
}
Expand Down
6 changes: 2 additions & 4 deletions src/qt/rpcconsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -826,10 +826,8 @@ void RPCConsole::addWallet(WalletModel * const walletModel)
// use name for text and wallet model for internal data object (to allow to move to a wallet id later)
ui->WalletSelector->addItem(walletModel->getDisplayName(), QVariant::fromValue(walletModel));
if (ui->WalletSelector->count() == 2) {
if (!isVisible()) {
// First wallet added, set to default so long as the window isn't presently visible (and potentially in use)
ui->WalletSelector->setCurrentIndex(1);
}
// First wallet added, set to default to match wallet RPC behavior
ui->WalletSelector->setCurrentIndex(1);
// The only loaded wallet
ui->btn_rescan1->setEnabled(true);
ui->btn_rescan2->setEnabled(true);
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static Mutex cs_blockchange;
static std::condition_variable cond_blockchange;
static CUpdatedBlock latestblock GUARDED_BY(cs_blockchange);

extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, const CTxMemPool& mempool, const CChainState& active_chainstate, const llmq::CChainLocksHandler& clhandler, const llmq::CInstantSendManager& isman, UniValue& entry);
extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, const CTxMemPool& mempool, const CChainState& active_chainstate, const llmq::CChainLocksHandler& clhandler, const llmq::CInstantSendManager& isman, UniValue& entry, TxVerbosity verbosity = TxVerbosity::SHOW_DETAILS);

/* Calculate the difficulty for a given block index.
*/
Expand Down
34 changes: 11 additions & 23 deletions src/rpc/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -741,9 +741,7 @@ static RPCHelpMan setban()
throw std::runtime_error(help.ToString());
}
const NodeContext& node = EnsureAnyNodeContext(request.context);
if (!node.banman) {
throw JSONRPCError(RPC_DATABASE_ERROR, "Error: Ban database not loaded");
}
BanMan& banman = EnsureBanman(node);

CSubNet subNet;
CNetAddr netAddr;
Expand All @@ -766,7 +764,7 @@ static RPCHelpMan setban()

if (strCommand == "add")
{
if (isSubnet ? node.banman->IsBanned(subNet) : node.banman->IsBanned(netAddr)) {
if (isSubnet ? banman.IsBanned(subNet) : banman.IsBanned(netAddr)) {
throw JSONRPCError(RPC_CLIENT_NODE_ALREADY_ADDED, "Error: IP/Subnet already banned");
}

Expand All @@ -779,20 +777,20 @@ static RPCHelpMan setban()
absolute = true;

if (isSubnet) {
node.banman->Ban(subNet, banTime, absolute);
banman.Ban(subNet, banTime, absolute);
if (node.connman) {
node.connman->DisconnectNode(subNet);
}
} else {
node.banman->Ban(netAddr, banTime, absolute);
banman.Ban(netAddr, banTime, absolute);
if (node.connman) {
node.connman->DisconnectNode(netAddr);
}
}
}
else if(strCommand == "remove")
{
if (!( isSubnet ? node.banman->Unban(subNet) : node.banman->Unban(netAddr) )) {
if (!( isSubnet ? banman.Unban(subNet) : banman.Unban(netAddr) )) {
throw JSONRPCError(RPC_CLIENT_INVALID_IP_OR_SUBNET, "Error: Unban failed. Requested address/subnet was not previously manually banned.");
}
}
Expand Down Expand Up @@ -823,14 +821,10 @@ static RPCHelpMan listbanned()
},
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
{

const NodeContext& node = EnsureAnyNodeContext(request.context);
if(!node.banman) {
throw JSONRPCError(RPC_DATABASE_ERROR, "Error: Ban database not loaded");
}
BanMan& banman = EnsureAnyBanman(request.context);

banmap_t banMap;
node.banman->GetBanned(banMap);
banman.GetBanned(banMap);
const int64_t current_time{GetTime()};

UniValue bannedAddresses(UniValue::VARR);
Expand Down Expand Up @@ -864,12 +858,9 @@ static RPCHelpMan clearbanned()
},
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
{
const NodeContext& node = EnsureAnyNodeContext(request.context);
if (!node.banman) {
throw JSONRPCError(RPC_DATABASE_ERROR, "Error: Ban database not loaded");
}
BanMan& banman = EnsureAnyBanman(request.context);

node.banman->ClearBanned();
banman.ClearBanned();

return NullUniValue;
},
Expand All @@ -888,12 +879,9 @@ static RPCHelpMan cleardiscouraged()
},
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
{
const NodeContext& node = EnsureAnyNodeContext(request.context);
if (!node.banman) {
throw JSONRPCError(RPC_DATABASE_ERROR, "Error: Ban database not loaded");
}
BanMan& banman = EnsureAnyBanman(request.context);

node.banman->ClearDiscouraged();
banman.ClearDiscouraged();

return NullUniValue;
},
Expand Down
6 changes: 3 additions & 3 deletions src/rpc/rawtransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ using node::GetTransaction;
using node::NodeContext;
using node::PSBTAnalysis;

void TxToJSON(const CTransaction& tx, const uint256 hashBlock, const CTxMemPool& mempool, const CChainState& active_chainstate, const llmq::CChainLocksHandler& clhandler, const llmq::CInstantSendManager& isman, UniValue& entry)
void TxToJSON(const CTransaction& tx, const uint256 hashBlock, const CTxMemPool& mempool, const CChainState& active_chainstate, const llmq::CChainLocksHandler& clhandler, const llmq::CInstantSendManager& isman, UniValue& entry, TxVerbosity verbosity = TxVerbosity::SHOW_DETAILS)
{
CHECK_NONFATAL(verbosity >= TxVerbosity::SHOW_DETAILS);
LOCK(::cs_main);

// Call into TxToUniv() in bitcoin-common to decode the transaction hex.
//
// Blockchain contextual information (confirmations and blocktime) is not
Expand Down Expand Up @@ -102,7 +102,7 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, const CTxMemPool
txSpentInfoPtr = &txSpentInfo;
}

TxToUniv(tx, /*block_hash=*/uint256(), entry, /*include_hex=*/true, /*serialize_flags=*/0, /*txundo=*/nullptr, TxVerbosity::SHOW_DETAILS, txSpentInfoPtr);
TxToUniv(tx, /*block_hash=*/uint256(), entry, /*include_hex=*/true, /*serialize_flags=*/0, /*txundo=*/nullptr, verbosity, txSpentInfoPtr);

bool chainLock = false;
if (!hashBlock.IsNull()) {
Expand Down
15 changes: 15 additions & 0 deletions src/rpc/server_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <rpc/server_util.h>

#include <banman.h>
#include <net_processing.h>
#include <node/context.h>
#include <policy/fees.h>
Expand Down Expand Up @@ -56,6 +57,20 @@ CTxMemPool& EnsureAnyMemPool(const CoreContext& context)
return EnsureMemPool(EnsureAnyNodeContext(context));
}


BanMan& EnsureBanman(const NodeContext& node)
{
if (!node.banman) {
throw JSONRPCError(RPC_DATABASE_ERROR, "Error: Ban database not loaded");
}
return *node.banman;
}

BanMan& EnsureAnyBanman(const CoreContext& context)
{
return EnsureBanman(EnsureAnyNodeContext(context));
}

ArgsManager& EnsureArgsman(const NodeContext& node)
{
if (!node.args) {
Expand Down
3 changes: 3 additions & 0 deletions src/rpc/server_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class CConnman;
class CTxMemPool;
class ChainstateManager;
class PeerManager;
class BanMan;
struct LLMQContext;
namespace node {
struct NodeContext;
Expand All @@ -21,6 +22,8 @@ struct NodeContext;
node::NodeContext& EnsureAnyNodeContext(const CoreContext& context);
CTxMemPool& EnsureMemPool(const node::NodeContext& node);
CTxMemPool& EnsureAnyMemPool(const CoreContext& context);
BanMan& EnsureBanman(const node::NodeContext& node);
BanMan& EnsureAnyBanman(const CoreContext& context);
ArgsManager& EnsureArgsman(const node::NodeContext& node);
ArgsManager& EnsureAnyArgsman(const CoreContext& context);
ChainstateManager& EnsureChainman(const node::NodeContext& node);
Expand Down
6 changes: 3 additions & 3 deletions src/script/descriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1253,17 +1253,17 @@ DescriptorCache DescriptorCache::MergeAndDiff(const DescriptorCache& other)
return diff;
}

const ExtPubKeyMap DescriptorCache::GetCachedParentExtPubKeys() const
ExtPubKeyMap DescriptorCache::GetCachedParentExtPubKeys() const
{
return m_parent_xpubs;
}

const std::unordered_map<uint32_t, ExtPubKeyMap> DescriptorCache::GetCachedDerivedExtPubKeys() const
std::unordered_map<uint32_t, ExtPubKeyMap> DescriptorCache::GetCachedDerivedExtPubKeys() const
{
return m_derived_xpubs;
}

const ExtPubKeyMap DescriptorCache::GetCachedLastHardenedExtPubKeys() const
ExtPubKeyMap DescriptorCache::GetCachedLastHardenedExtPubKeys() const
{
return m_last_hardened_xpubs;
}
6 changes: 3 additions & 3 deletions src/script/descriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ class DescriptorCache {
bool GetCachedLastHardenedExtPubKey(uint32_t key_exp_pos, CExtPubKey& xpub) const;

/** Retrieve all cached parent xpubs */
const ExtPubKeyMap GetCachedParentExtPubKeys() const;
ExtPubKeyMap GetCachedParentExtPubKeys() const;
/** Retrieve all cached derived xpubs */
const std::unordered_map<uint32_t, ExtPubKeyMap> GetCachedDerivedExtPubKeys() const;
std::unordered_map<uint32_t, ExtPubKeyMap> GetCachedDerivedExtPubKeys() const;
/** Retrieve all cached last hardened xpubs */
const ExtPubKeyMap GetCachedLastHardenedExtPubKeys() const;
ExtPubKeyMap GetCachedLastHardenedExtPubKeys() const;

/** Combine another DescriptorCache into this one.
* Returns a cache containing the items from the other cache unknown to current cache
Expand Down
7 changes: 0 additions & 7 deletions src/streams.h
Original file line number Diff line number Diff line change
Expand Up @@ -362,13 +362,6 @@ class CDataStream : public DataStream
nType{nTypeIn},
nVersion{nVersionIn} {}

template <typename... Args>
CDataStream(int nTypeIn, int nVersionIn, Args&&... args)
: nType{nTypeIn},
nVersion{nVersionIn}
{
::SerializeMany(*this, std::forward<Args>(args)...);
}

void SetType(int n) { nType = n; }
int GetType() const { return nType; }
Expand Down
2 changes: 1 addition & 1 deletion src/test/fuzz/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void CallOneOf(FuzzedDataProvider& fuzzed_data_provider, Callables... callables)
template <typename Collection>
auto& PickValue(FuzzedDataProvider& fuzzed_data_provider, Collection& col)
{
const auto sz = col.size();
auto sz{col.size()};
assert(sz >= 1);
auto it = col.begin();
std::advance(it, fuzzed_data_provider.ConsumeIntegralInRange<decltype(sz)>(0, sz - 1));
Expand Down
3 changes: 2 additions & 1 deletion src/test/serialize_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,8 @@ BOOST_AUTO_TEST_CASE(class_methods)
BOOST_CHECK(methodtest2 == methodtest3);
BOOST_CHECK(methodtest3 == methodtest4);

CDataStream ss2(SER_DISK, PROTOCOL_VERSION, intval, boolval, stringval, charstrval, txval);
CDataStream ss2{SER_DISK, PROTOCOL_VERSION};
ss2 << intval << boolval << stringval << charstrval << txval;
ss2 >> methodtest3;
BOOST_CHECK(methodtest3 == methodtest4);
{
Expand Down
2 changes: 1 addition & 1 deletion src/test/versionbits_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/* Define a virtual block time, one block per 10 minutes after Nov 14 2014, 0:55:36am */
static int32_t TestTime(int nHeight) { return 1415926536 + 600 * nHeight; }

static const std::string StateName(ThresholdState state)
static std::string StateName(ThresholdState state)
{
switch (state) {
case ThresholdState::DEFINED: return "DEFINED";
Expand Down
2 changes: 1 addition & 1 deletion src/txmempool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1739,7 +1739,7 @@ void CTxMemPool::SetIsLoaded(bool loaded)
}


const std::string RemovalReasonToString(const MemPoolRemovalReason& r) noexcept
std::string RemovalReasonToString(const MemPoolRemovalReason& r) noexcept
{
switch (r) {
case MemPoolRemovalReason::EXPIRY: return "expiry";
Expand Down
Loading
Loading