Skip to content
Open
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: 2 additions & 0 deletions src/.bear-tidy-config
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
"src/leveldb",
"src/minisketch",
"src/univalue",
"src/bench/nanobench.cpp",
"src/bench/nanobench.h",
"src/secp256k1"
]
},
Expand Down
1 change: 1 addition & 0 deletions src/.clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ bugprone-argument-comment,
bugprone-use-after-move,
misc-unused-using-decls,
modernize-use-default-member-init,
modernize-use-emplace,
modernize-use-nullptr,
performance-for-range-copy,
performance-move-const-arg,
Expand Down
14 changes: 6 additions & 8 deletions src/addrdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,10 @@ void ReadFromStream(AddrMan& addr, CDataStream& ssPeers)
DeserializeDB(ssPeers, addr, false);
}

std::optional<bilingual_str> LoadAddrman(const NetGroupManager& netgroupman, const ArgsManager& args, std::unique_ptr<AddrMan>& addrman)
util::Result<std::unique_ptr<AddrMan>> LoadAddrman(const NetGroupManager& netgroupman, const ArgsManager& args)
{
auto check_addrman = std::clamp<int32_t>(args.GetIntArg("-checkaddrman", DEFAULT_ADDRMAN_CONSISTENCY_CHECKS), 0, 1000000);
addrman = std::make_unique<AddrMan>(netgroupman, /*deterministic=*/false, /*consistency_check_ratio=*/check_addrman);
auto addrman{std::make_unique<AddrMan>(netgroupman, /*deterministic=*/false, /*consistency_check_ratio=*/check_addrman)};

const auto start{SteadyClock::now()};
const auto path_addr{gArgs.GetDataDirNet() / "peers.dat"};
Expand All @@ -208,19 +208,17 @@ std::optional<bilingual_str> LoadAddrman(const NetGroupManager& netgroupman, con
DumpPeerAddresses(args, *addrman);
} catch (const InvalidAddrManVersionError&) {
if (!RenameOver(path_addr, (fs::path)path_addr + ".bak")) {
addrman = nullptr;
return strprintf(_("Failed to rename invalid peers.dat file. Please move or delete it and try again."));
return util::Error{strprintf(_("Failed to rename invalid peers.dat file. Please move or delete it and try again."))};
}
// Addrman can be in an inconsistent state after failure, reset it
addrman = std::make_unique<AddrMan>(netgroupman, /*deterministic=*/false, /*consistency_check_ratio=*/check_addrman);
LogPrintf("Creating new peers.dat because the file version was not compatible (%s). Original backed up to peers.dat.bak\n", fs::quoted(fs::PathToString(path_addr)));
DumpPeerAddresses(args, *addrman);
} catch (const std::exception& e) {
addrman = nullptr;
return strprintf(_("Invalid or corrupt peers.dat (%s). If you believe this is a bug, please report it to %s. As a workaround, you can move the file (%s) out of the way (rename, move, or delete) to have a new one created on the next start."),
e.what(), PACKAGE_BUGREPORT, fs::quoted(fs::PathToString(path_addr)));
return util::Error{strprintf(_("Invalid or corrupt peers.dat (%s). If you believe this is a bug, please report it to %s. As a workaround, you can move the file (%s) out of the way (rename, move, or delete) to have a new one created on the next start."),
e.what(), PACKAGE_BUGREPORT, fs::quoted(fs::PathToString(path_addr)))};
}
return std::nullopt;
return std::move(addrman); // std::move should be unneccessary but is temporarily needed to work around clang bug (https://github.com/bitcoin/bitcoin/pull/25977#issuecomment-1561270092)
}

void DumpAnchors(const fs::path& anchors_db_path, const std::vector<CAddress>& anchors)
Expand Down
3 changes: 2 additions & 1 deletion src/addrdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <fs.h>
#include <net_types.h> // For banmap_t
#include <univalue.h>
#include <util/result.h>

#include <memory>
#include <optional>
Expand Down Expand Up @@ -50,7 +51,7 @@ class CBanDB
};

/** Returns an error string on failure */
std::optional<bilingual_str> LoadAddrman(const NetGroupManager& netgroupman, const ArgsManager& args, std::unique_ptr<AddrMan>& addrman);
util::Result<std::unique_ptr<AddrMan>> LoadAddrman(const NetGroupManager& netgroupman, const ArgsManager& args);

/**
* Dump the anchor IP address database (anchors.dat)
Expand Down
4 changes: 2 additions & 2 deletions src/bench/wallet_loading.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ static void BenchUnloadWallet(std::shared_ptr<CWallet>&& wallet)
static void AddTx(CWallet& wallet)
{
CMutableTransaction mtx;
mtx.vout.push_back({COIN, GetScriptForDestination(*Assert(wallet.GetNewDestination("")))});
mtx.vin.push_back(CTxIn());
mtx.vout.emplace_back(COIN, GetScriptForDestination(*Assert(wallet.GetNewDestination(""))));
mtx.vin.emplace_back();

wallet.AddToWallet(MakeTransactionRef(mtx), TxStateInactive{});
}
Expand Down
2 changes: 1 addition & 1 deletion src/external_signer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ bool ExternalSigner::Enumerate(const std::string& command, std::vector<ExternalS
if (model_field.isStr() && model_field.getValStr() != "") {
name += model_field.getValStr();
}
signers.push_back(ExternalSigner(command, chain, fingerprintStr, name));
signers.emplace_back(command, chain, fingerprintStr, name);
}
return true;
}
Expand Down
12 changes: 6 additions & 6 deletions src/httpserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ static bool ClientAllowed(const CNetAddr& netaddr)
static bool InitHTTPAllowList()
{
rpc_allow_subnets.clear();
rpc_allow_subnets.push_back(CSubNet{LookupHost("127.0.0.1", false).value(), 8}); // always allow IPv4 local subnet
rpc_allow_subnets.push_back(CSubNet{LookupHost("::1", false).value()}); // always allow IPv6 localhost
rpc_allow_subnets.emplace_back(LookupHost("127.0.0.1", false).value(), 8); // always allow IPv4 local subnet
rpc_allow_subnets.emplace_back(LookupHost("::1", false).value()); // always allow IPv6 localhost
for (const std::string& strAllow : gArgs.GetArgs("-rpcallowip")) {
const CSubNet subnet{LookupSubNet(strAllow)};
if (!subnet.IsValid()) {
Expand Down Expand Up @@ -330,8 +330,8 @@ static bool HTTPBindAddresses(struct evhttp* http)

// Determine what addresses to bind to
if (!(gArgs.IsArgSet("-rpcallowip") && gArgs.IsArgSet("-rpcbind"))) { // Default to loopback if not allowing external IPs
endpoints.push_back(std::make_pair("::1", http_port));
endpoints.push_back(std::make_pair("127.0.0.1", http_port));
endpoints.emplace_back("::1", http_port);
endpoints.emplace_back("127.0.0.1", http_port);
if (gArgs.IsArgSet("-rpcallowip")) {
LogPrintf("WARNING: option -rpcallowip was specified without -rpcbind; this doesn't usually make sense\n");
}
Expand All @@ -343,7 +343,7 @@ static bool HTTPBindAddresses(struct evhttp* http)
uint16_t port{http_port};
std::string host;
SplitHostPort(strRPCBind, port, host);
endpoints.push_back(std::make_pair(host, port));
endpoints.emplace_back(host, port);
}
} else { // No specific bind address specified, bind to any
endpoints.push_back(std::make_pair("::", http_port));
Expand Down Expand Up @@ -706,7 +706,7 @@ void RegisterHTTPHandler(const std::string &prefix, bool exactMatch, const HTTPR
{
LogPrint(BCLog::HTTP, "Registering HTTP handler for %s (exactmatch %d)\n", prefix, exactMatch);
LOCK(g_httppathhandlers_mutex);
pathHandlers.push_back(HTTPPathHandler(prefix, exactMatch, handler));
pathHandlers.emplace_back(prefix, exactMatch, handler);
}

void UnregisterHTTPHandler(const std::string &prefix, bool exactMatch)
Expand Down
6 changes: 3 additions & 3 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1652,9 +1652,9 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
// Initialize addrman
assert(!node.addrman);
uiInterface.InitMessage(_("Loading P2P addresses…").translated);
if (const auto error{LoadAddrman(*node.netgroupman, args, node.addrman)}) {
return InitError(*error);
}
auto addrman{LoadAddrman(*node.netgroupman, args)};
if (!addrman) return InitError(util::ErrorString(addrman));
node.addrman = std::move(*addrman);
}

std::string sem_str = args.GetArg("-socketevents", DEFAULT_SOCKETEVENTS);
Expand Down
14 changes: 7 additions & 7 deletions src/net_permissions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ bool TryParsePermissionFlags(const std::string& str, NetPermissionFlags& output,
std::vector<std::string> NetPermissions::ToStrings(NetPermissionFlags flags)
{
std::vector<std::string> strings;
if (NetPermissions::HasFlag(flags, NetPermissionFlags::BloomFilter)) strings.push_back("bloomfilter");
if (NetPermissions::HasFlag(flags, NetPermissionFlags::NoBan)) strings.push_back("noban");
if (NetPermissions::HasFlag(flags, NetPermissionFlags::ForceRelay)) strings.push_back("forcerelay");
if (NetPermissions::HasFlag(flags, NetPermissionFlags::Relay)) strings.push_back("relay");
if (NetPermissions::HasFlag(flags, NetPermissionFlags::Mempool)) strings.push_back("mempool");
if (NetPermissions::HasFlag(flags, NetPermissionFlags::Download)) strings.push_back("download");
if (NetPermissions::HasFlag(flags, NetPermissionFlags::Addr)) strings.push_back("addr");
if (NetPermissions::HasFlag(flags, NetPermissionFlags::BloomFilter)) strings.emplace_back("bloomfilter");
if (NetPermissions::HasFlag(flags, NetPermissionFlags::NoBan)) strings.emplace_back("noban");
if (NetPermissions::HasFlag(flags, NetPermissionFlags::ForceRelay)) strings.emplace_back("forcerelay");
if (NetPermissions::HasFlag(flags, NetPermissionFlags::Relay)) strings.emplace_back("relay");
if (NetPermissions::HasFlag(flags, NetPermissionFlags::Mempool)) strings.emplace_back("mempool");
if (NetPermissions::HasFlag(flags, NetPermissionFlags::Download)) strings.emplace_back("download");
if (NetPermissions::HasFlag(flags, NetPermissionFlags::Addr)) strings.emplace_back("addr");
return strings;
}

Expand Down
14 changes: 7 additions & 7 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2799,7 +2799,7 @@ void PeerManagerImpl::ProcessGetBlockData(CNode& pfrom, Peer& peer, const CInv&
// and we want it right after the last block so they don't
// wait for other stuff first.
std::vector<CInv> vInv;
vInv.push_back(CInv(MSG_BLOCK, m_chainman.ActiveChain().Tip()->GetBlockHash()));
vInv.emplace_back(MSG_BLOCK, m_chainman.ActiveChain().Tip()->GetBlockHash());
m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::INV, vInv));
peer.m_continuation_block.SetNull();
}
Expand Down Expand Up @@ -3199,7 +3199,7 @@ void PeerManagerImpl::HeadersDirectFetchBlocks(CNode& pfrom, const Peer& peer, c
// Can't download any more from this peer
break;
}
vGetData.push_back(CInv(MSG_BLOCK, pindex->GetBlockHash()));
vGetData.emplace_back(MSG_BLOCK, pindex->GetBlockHash());
BlockRequested(pfrom.GetId(), *pindex);
LogPrint(BCLog::NET, "Requesting block %s from peer=%d\n",
pindex->GetBlockHash().ToString(), pfrom.GetId());
Expand Down Expand Up @@ -4616,7 +4616,7 @@ void PeerManagerImpl::ProcessMessage(
const auto send_headers = [this /* for m_connman */, &hashStop, &pindex, &nodestate, &pfrom, &msgMaker](auto msg_type_internal, auto& v_headers, auto callback) {
int nLimit = GetHeadersLimit(pfrom, msg_type_internal == NetMsgType::HEADERS2);
for (; pindex; pindex = m_chainman.ActiveChain().Next(pindex)) {
v_headers.push_back(callback(pindex));
v_headers.emplace_back(callback(pindex));

if (--nLimit <= 0 || pindex->GetBlockHash() == hashStop)
break;
Expand Down Expand Up @@ -6167,14 +6167,14 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
}
if (fFoundStartingHeader) {
// add this to the headers message
vHeaders.push_back(pindex->GetBlockHeader());
vHeaders.emplace_back(pindex->GetBlockHeader());
} else if (PeerHasHeader(&state, pindex)) {
continue; // keep looking for the first new block
} else if (pindex->pprev == nullptr || PeerHasHeader(&state, pindex->pprev) || isPrevDevnetGenesisBlock) {
// Peer doesn't have this header but they do have the prior one.
// Start sending headers.
fFoundStartingHeader = true;
vHeaders.push_back(pindex->GetBlockHeader());
vHeaders.emplace_back(pindex->GetBlockHeader());
} else {
// Peer doesn't have this header or the prior one -- nothing will
// connect, so bail out.
Expand Down Expand Up @@ -6282,7 +6282,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)

// Add blocks
for (const uint256& hash : peer->m_blocks_for_inv_relay) {
vInv.push_back(CInv(MSG_BLOCK, hash));
vInv.emplace_back(MSG_BLOCK, hash);
if (vInv.size() == MAX_INV_SZ) {
m_connman.PushMessage(pto, msgMaker.Make(NetMsgType::INV, vInv));
vInv.clear();
Expand Down Expand Up @@ -6527,7 +6527,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
NodeId staller = -1;
FindNextBlocksToDownload(*peer, MAX_BLOCKS_IN_TRANSIT_PER_PEER - state.nBlocksInFlight, vToDownload, staller);
for (const CBlockIndex *pindex : vToDownload) {
vGetData.push_back(CInv(MSG_BLOCK, pindex->GetBlockHash()));
vGetData.emplace_back(MSG_BLOCK, pindex->GetBlockHash());
BlockRequested(pto->GetId(), *pindex);
LogPrint(BCLog::NET, "Requesting block %s (%d) peer=%d\n", pindex->GetBlockHash().ToString(),
pindex->nHeight, pto->GetId());
Expand Down
2 changes: 1 addition & 1 deletion src/node/blockstorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ bool BlockManager::WriteBlockIndexDB()
std::vector<std::pair<int, const CBlockFileInfo*>> vFiles;
vFiles.reserve(m_dirty_fileinfo.size());
for (std::set<int>::iterator it = m_dirty_fileinfo.begin(); it != m_dirty_fileinfo.end();) {
vFiles.push_back(std::make_pair(*it, &m_blockfile_info[*it]));
vFiles.emplace_back(*it, &m_blockfile_info[*it]);
m_dirty_fileinfo.erase(it++);
}
std::vector<const CBlockIndex*> vBlocks;
Expand Down
8 changes: 4 additions & 4 deletions src/qt/rpcconsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class PeerIdViewDelegate : public QStyledItemDelegate
bool RPCConsole::RPCParseCommandLine(interfaces::Node* node, std::string &strResult, const std::string &strCommand, const bool fExecute, std::string * const pstrFilteredOut, const WalletModel* wallet_model)
{
std::vector< std::vector<std::string> > stack;
stack.push_back(std::vector<std::string>());
stack.emplace_back();

enum CmdParseState
{
Expand Down Expand Up @@ -212,7 +212,7 @@ bool RPCConsole::RPCParseCommandLine(interfaces::Node* node, std::string &strRes
}
// Make sure stack is not empty before adding something
if (stack.empty()) {
stack.push_back(std::vector<std::string>());
stack.emplace_back();
}
stack.back().push_back(strArg);
};
Expand All @@ -221,7 +221,7 @@ bool RPCConsole::RPCParseCommandLine(interfaces::Node* node, std::string &strRes
if (nDepthInsideSensitive) {
if (!--nDepthInsideSensitive) {
assert(filter_begin_pos);
filter_ranges.push_back(std::make_pair(filter_begin_pos, chpos));
filter_ranges.emplace_back(filter_begin_pos, chpos);
filter_begin_pos = 0;
}
}
Expand Down Expand Up @@ -321,7 +321,7 @@ bool RPCConsole::RPCParseCommandLine(interfaces::Node* node, std::string &strRes
if (nDepthInsideSensitive) {
++nDepthInsideSensitive;
}
stack.push_back(std::vector<std::string>());
stack.emplace_back();
}

// don't allow commands after executed commands on baselevel
Expand Down
2 changes: 1 addition & 1 deletion src/rest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ static bool rest_getutxos(const CoreContext& context, HTTPRequest* req, const st
return RESTERR(req, HTTP_BAD_REQUEST, "Parse error");

txid.SetHex(strTxid);
vOutPoints.push_back(COutPoint(txid, (uint32_t)nOutput));
vOutPoints.emplace_back(txid, (uint32_t)nOutput);
}

if (vOutPoints.size() > 0)
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2192,7 +2192,7 @@ static RPCHelpMan getblockstats()

CAmount feerate = tx_size ? txfee / tx_size : 0;
if (do_feerate_percentiles) {
feerate_array.emplace_back(std::make_pair(feerate, tx_size));
feerate_array.emplace_back(feerate, tx_size);
}
maxfeerate = std::max(maxfeerate, feerate);
minfeerate = std::min(minfeerate, feerate);
Expand Down
8 changes: 4 additions & 4 deletions src/rpc/rawtransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1650,10 +1650,10 @@ static RPCHelpMan createpsbt()
PartiallySignedTransaction psbtx;
psbtx.tx = rawTx;
for (unsigned int i = 0; i < rawTx.vin.size(); ++i) {
psbtx.inputs.push_back(PSBTInput());
psbtx.inputs.emplace_back();
}
for (unsigned int i = 0; i < rawTx.vout.size(); ++i) {
psbtx.outputs.push_back(PSBTOutput());
psbtx.outputs.emplace_back();
}

// Serialize the PSBT
Expand Down Expand Up @@ -1707,10 +1707,10 @@ static RPCHelpMan converttopsbt()
PartiallySignedTransaction psbtx;
psbtx.tx = tx;
for (unsigned int i = 0; i < tx.vin.size(); ++i) {
psbtx.inputs.push_back(PSBTInput());
psbtx.inputs.emplace_back();
}
for (unsigned int i = 0; i < tx.vout.size(); ++i) {
psbtx.outputs.push_back(PSBTOutput());
psbtx.outputs.emplace_back();
}

// Serialize the PSBT
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ std::string CRPCTable::help(const std::string& strCommand, const JSONRPCRequest&
std::vector<std::pair<std::string, const CRPCCommand*> > vCommands;

for (const auto& entry : mapCommands)
vCommands.push_back(make_pair(entry.second.front()->category + entry.first, entry.second.front()));
vCommands.emplace_back(entry.second.front()->category + entry.first, entry.second.front());
sort(vCommands.begin(), vCommands.end());

JSONRPCRequest jreq = helpreq;
Expand Down
8 changes: 4 additions & 4 deletions src/script/sign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ static bool SignStep(const SigningProvider& provider, const BaseSignatureCreator
case TxoutType::SCRIPTHASH: {
uint160 h160{vSolutions[0]};
if (GetCScript(provider, sigdata, CScriptID{h160}, scriptRet)) {
ret.push_back(std::vector<unsigned char>(scriptRet.begin(), scriptRet.end()));
ret.emplace_back(scriptRet.begin(), scriptRet.end());
return true;
}
// Could not find redeemScript, add to missing
Expand All @@ -146,7 +146,7 @@ static bool SignStep(const SigningProvider& provider, const BaseSignatureCreator
}
case TxoutType::MULTISIG: {
size_t required = vSolutions.front()[0];
ret.push_back(valtype()); // workaround CHECKMULTISIG bug
ret.emplace_back(); // workaround CHECKMULTISIG bug
for (size_t i = 1; i < vSolutions.size() - 1; ++i) {
CPubKey pubkey = CPubKey(vSolutions[i]);
// We need to always call CreateSig in order to fill sigdata with all
Expand All @@ -160,7 +160,7 @@ static bool SignStep(const SigningProvider& provider, const BaseSignatureCreator
}
bool ok = ret.size() == required + 1;
for (size_t i = 0; i + ret.size() < required + 1; ++i) {
ret.push_back(valtype());
ret.emplace_back();
}
return ok;
}
Expand Down Expand Up @@ -207,7 +207,7 @@ bool ProduceSignature(const SigningProvider& provider, const BaseSignatureCreato
}

if (P2SH) {
result.push_back(std::vector<unsigned char>(subscript.begin(), subscript.end()));
result.emplace_back(subscript.begin(), subscript.end());
}
sigdata.scriptSig = PushAll(result);

Expand Down
4 changes: 2 additions & 2 deletions src/test/addrman_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ BOOST_AUTO_TEST_CASE(addrman_simple)
// Test: reset addrman and test AddrMan::Add multiple addresses works as expected
addrman = std::make_unique<AddrMan>(EMPTY_NETGROUPMAN, DETERMINISTIC, GetCheckRatio(m_node));
std::vector<CAddress> vAddr;
vAddr.push_back(CAddress(ResolveService("250.1.1.3", 8333), NODE_NONE));
vAddr.push_back(CAddress(ResolveService("250.1.1.4", 8333), NODE_NONE));
vAddr.emplace_back(ResolveService("250.1.1.3", 8333), NODE_NONE);
vAddr.emplace_back(ResolveService("250.1.1.4", 8333), NODE_NONE);
BOOST_CHECK(addrman->Add(vAddr, source));
BOOST_CHECK(addrman->Size() >= 1);
}
Expand Down
Loading
Loading