Skip to content

Commit 1e694a5

Browse files
Merge #6779: backport: trivial batch 380
bf27280 fix: compilation errors in bitcoin#27069 backport (pasta) 67a651a Merge bitcoin#26829: init: Remove unnecessary sensitive flag from rpcbind (PastaBot) e7d44c5 Merge bitcoin#26974: refactor: rpc: set TxToJSON default verbosity to SHOW_DETAILS (PastaBot) 5e6e706 Merge bitcoin#26935: refactor: Fix clang-tidy readability-const-return-type violations (PastaBot) 5e10d4e Merge bitcoin-core/gui#695: Fix misleading RPC console wallet message (PastaBot) b79770c Merge bitcoin#26992: refactor: Remove unused CDataStream SerializeMany constructor (PastaBot) 8ea6753 Merge bitcoin#27069: net: add `Ensure{any}Banman` (PastaBot) Pull request description: ## Issue being fixed or feature implemented Batch of trivial backports ## What was done? See commits ## How Has This Been Tested? CI ## Breaking Changes ## Checklist: _Go over all the following points, and put an `x` in all the boxes that apply._ - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_ ACKs for top commit: UdjinM6: utACK bf27280 Tree-SHA512: bbdf5e82076c63f0ef2d17aa55ff1f972c459e8ec7bd34aa3658a0453655f61506b93123fbf0f0c795e65ba72ff05d74beab6bf33dfce259e71c81c407e5694d
2 parents b0b0ad6 + bf27280 commit 1e694a5

33 files changed

+91
-86
lines changed

src/.clang-tidy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Checks: '
22
-*,
33
bugprone-argument-comment,
44
modernize-use-nullptr,
5+
readability-const-return-type,
56
readability-redundant-declaration,
67
readability-redundant-string-init,
78
'

src/arith_uint256.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ class base_uint
5858

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

61-
const base_uint operator~() const
61+
base_uint operator~() const
6262
{
6363
base_uint ret;
6464
for (int i = 0; i < WIDTH; i++)
6565
ret.pn[i] = ~pn[i];
6666
return ret;
6767
}
6868

69-
const base_uint operator-() const
69+
base_uint operator-() const
7070
{
7171
base_uint ret;
7272
for (int i = 0; i < WIDTH; i++)
@@ -171,7 +171,7 @@ class base_uint
171171
return *this;
172172
}
173173

174-
const base_uint operator++(int)
174+
base_uint operator++(int)
175175
{
176176
// postfix operator
177177
const base_uint ret = *this;
@@ -188,7 +188,7 @@ class base_uint
188188
return *this;
189189
}
190190

191-
const base_uint operator--(int)
191+
base_uint operator--(int)
192192
{
193193
// postfix operator
194194
const base_uint ret = *this;
@@ -199,16 +199,16 @@ class base_uint
199199
int CompareTo(const base_uint& b) const;
200200
bool EqualTo(uint64_t b) const;
201201

202-
friend inline const base_uint operator+(const base_uint& a, const base_uint& b) { return base_uint(a) += b; }
203-
friend inline const base_uint operator-(const base_uint& a, const base_uint& b) { return base_uint(a) -= b; }
204-
friend inline const base_uint operator*(const base_uint& a, const base_uint& b) { return base_uint(a) *= b; }
205-
friend inline const base_uint operator/(const base_uint& a, const base_uint& b) { return base_uint(a) /= b; }
206-
friend inline const base_uint operator|(const base_uint& a, const base_uint& b) { return base_uint(a) |= b; }
207-
friend inline const base_uint operator&(const base_uint& a, const base_uint& b) { return base_uint(a) &= b; }
208-
friend inline const base_uint operator^(const base_uint& a, const base_uint& b) { return base_uint(a) ^= b; }
209-
friend inline const base_uint operator>>(const base_uint& a, int shift) { return base_uint(a) >>= shift; }
210-
friend inline const base_uint operator<<(const base_uint& a, int shift) { return base_uint(a) <<= shift; }
211-
friend inline const base_uint operator*(const base_uint& a, uint32_t b) { return base_uint(a) *= b; }
202+
friend inline base_uint operator+(const base_uint& a, const base_uint& b) { return base_uint(a) += b; }
203+
friend inline base_uint operator-(const base_uint& a, const base_uint& b) { return base_uint(a) -= b; }
204+
friend inline base_uint operator*(const base_uint& a, const base_uint& b) { return base_uint(a) *= b; }
205+
friend inline base_uint operator/(const base_uint& a, const base_uint& b) { return base_uint(a) /= b; }
206+
friend inline base_uint operator|(const base_uint& a, const base_uint& b) { return base_uint(a) |= b; }
207+
friend inline base_uint operator&(const base_uint& a, const base_uint& b) { return base_uint(a) &= b; }
208+
friend inline base_uint operator^(const base_uint& a, const base_uint& b) { return base_uint(a) ^= b; }
209+
friend inline base_uint operator>>(const base_uint& a, int shift) { return base_uint(a) >>= shift; }
210+
friend inline base_uint operator<<(const base_uint& a, int shift) { return base_uint(a) <<= shift; }
211+
friend inline base_uint operator*(const base_uint& a, uint32_t b) { return base_uint(a) *= b; }
212212
friend inline bool operator==(const base_uint& a, const base_uint& b) { return memcmp(a.pn, b.pn, sizeof(a.pn)) == 0; }
213213
friend inline bool operator!=(const base_uint& a, const base_uint& b) { return memcmp(a.pn, b.pn, sizeof(a.pn)) != 0; }
214214
friend inline bool operator>(const base_uint& a, const base_uint& b) { return a.CompareTo(b) > 0; }

src/bench/gcs_filter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <bench/bench.h>
66
#include <blockfilter.h>
77

8-
static const GCSFilter::ElementSet GenerateGCSTestElements()
8+
static GCSFilter::ElementSet GenerateGCSTestElements()
99
{
1010
GCSFilter::ElementSet elements;
1111

src/core_write.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ void ScriptToUniv(const CScript& script, UniValue& out, bool include_hex, bool i
180180

181181
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)
182182
{
183+
CHECK_NONFATAL(verbosity >= TxVerbosity::SHOW_DETAILS);
184+
183185
uint256 txid = tx.GetHash();
184186
entry.pushKV("txid", txid.GetHex());
185187
// Transaction version is actually unsigned in consensus checks, just signed in memory,

src/init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ void SetupServerArgs(ArgsManager& argsman)
758758
argsman.AddArg("-rest", strprintf("Accept public REST requests (default: %u)", DEFAULT_REST_ENABLE), ArgsManager::ALLOW_ANY, OptionsCategory::RPC);
759759
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);
760760
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);
761-
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);
761+
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);
762762
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);
763763
argsman.AddArg("-rpcexternaluser=<users>", "List of comma-separated usernames for JSON-RPC external connections", ArgsManager::ALLOW_ANY | ArgsManager::SENSITIVE, OptionsCategory::RPC);
764764
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);

src/llmq/quorums.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,8 @@ PeerMsgRet CQuorumManager::ProcessMessage(CNode& pfrom, CConnman& connman, const
741741
break;
742742
}
743743
request.SetError(nError);
744-
CDataStream ssResponse(SER_NETWORK, pfrom.GetCommonVersion(), request, body);
744+
CDataStream ssResponse{SER_NETWORK, pfrom.GetCommonVersion()};
745+
ssResponse << request << body;
745746
connman.PushMessage(&pfrom, CNetMsgMaker(pfrom.GetCommonVersion()).Make(NetMsgType::QDATA, ssResponse));
746747
return ret;
747748
};

src/qt/optionsmodel.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
const char *DEFAULT_GUI_PROXY_HOST = "127.0.0.1";
3535

36-
static const QString GetDefaultProxyAddress();
36+
static QString GetDefaultProxyAddress();
3737

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

408-
static const QString GetDefaultProxyAddress()
408+
static QString GetDefaultProxyAddress()
409409
{
410410
return QString("%1:%2").arg(DEFAULT_GUI_PROXY_HOST).arg(DEFAULT_GUI_PROXY_PORT);
411411
}

src/qt/rpcconsole.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -826,10 +826,8 @@ void RPCConsole::addWallet(WalletModel * const walletModel)
826826
// use name for text and wallet model for internal data object (to allow to move to a wallet id later)
827827
ui->WalletSelector->addItem(walletModel->getDisplayName(), QVariant::fromValue(walletModel));
828828
if (ui->WalletSelector->count() == 2) {
829-
if (!isVisible()) {
830-
// First wallet added, set to default so long as the window isn't presently visible (and potentially in use)
831-
ui->WalletSelector->setCurrentIndex(1);
832-
}
829+
// First wallet added, set to default to match wallet RPC behavior
830+
ui->WalletSelector->setCurrentIndex(1);
833831
// The only loaded wallet
834832
ui->btn_rescan1->setEnabled(true);
835833
ui->btn_rescan2->setEnabled(true);

src/rpc/blockchain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ static Mutex cs_blockchange;
8181
static std::condition_variable cond_blockchange;
8282
static CUpdatedBlock latestblock GUARDED_BY(cs_blockchange);
8383

84-
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);
84+
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);
8585

8686
/* Calculate the difficulty for a given block index.
8787
*/

src/rpc/net.cpp

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -741,9 +741,7 @@ static RPCHelpMan setban()
741741
throw std::runtime_error(help.ToString());
742742
}
743743
const NodeContext& node = EnsureAnyNodeContext(request.context);
744-
if (!node.banman) {
745-
throw JSONRPCError(RPC_DATABASE_ERROR, "Error: Ban database not loaded");
746-
}
744+
BanMan& banman = EnsureBanman(node);
747745

748746
CSubNet subNet;
749747
CNetAddr netAddr;
@@ -766,7 +764,7 @@ static RPCHelpMan setban()
766764

767765
if (strCommand == "add")
768766
{
769-
if (isSubnet ? node.banman->IsBanned(subNet) : node.banman->IsBanned(netAddr)) {
767+
if (isSubnet ? banman.IsBanned(subNet) : banman.IsBanned(netAddr)) {
770768
throw JSONRPCError(RPC_CLIENT_NODE_ALREADY_ADDED, "Error: IP/Subnet already banned");
771769
}
772770

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

781779
if (isSubnet) {
782-
node.banman->Ban(subNet, banTime, absolute);
780+
banman.Ban(subNet, banTime, absolute);
783781
if (node.connman) {
784782
node.connman->DisconnectNode(subNet);
785783
}
786784
} else {
787-
node.banman->Ban(netAddr, banTime, absolute);
785+
banman.Ban(netAddr, banTime, absolute);
788786
if (node.connman) {
789787
node.connman->DisconnectNode(netAddr);
790788
}
791789
}
792790
}
793791
else if(strCommand == "remove")
794792
{
795-
if (!( isSubnet ? node.banman->Unban(subNet) : node.banman->Unban(netAddr) )) {
793+
if (!( isSubnet ? banman.Unban(subNet) : banman.Unban(netAddr) )) {
796794
throw JSONRPCError(RPC_CLIENT_INVALID_IP_OR_SUBNET, "Error: Unban failed. Requested address/subnet was not previously manually banned.");
797795
}
798796
}
@@ -823,14 +821,10 @@ static RPCHelpMan listbanned()
823821
},
824822
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
825823
{
826-
827-
const NodeContext& node = EnsureAnyNodeContext(request.context);
828-
if(!node.banman) {
829-
throw JSONRPCError(RPC_DATABASE_ERROR, "Error: Ban database not loaded");
830-
}
824+
BanMan& banman = EnsureAnyBanman(request.context);
831825

832826
banmap_t banMap;
833-
node.banman->GetBanned(banMap);
827+
banman.GetBanned(banMap);
834828
const int64_t current_time{GetTime()};
835829

836830
UniValue bannedAddresses(UniValue::VARR);
@@ -864,12 +858,9 @@ static RPCHelpMan clearbanned()
864858
},
865859
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
866860
{
867-
const NodeContext& node = EnsureAnyNodeContext(request.context);
868-
if (!node.banman) {
869-
throw JSONRPCError(RPC_DATABASE_ERROR, "Error: Ban database not loaded");
870-
}
861+
BanMan& banman = EnsureAnyBanman(request.context);
871862

872-
node.banman->ClearBanned();
863+
banman.ClearBanned();
873864

874865
return NullUniValue;
875866
},
@@ -888,12 +879,9 @@ static RPCHelpMan cleardiscouraged()
888879
},
889880
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
890881
{
891-
const NodeContext& node = EnsureAnyNodeContext(request.context);
892-
if (!node.banman) {
893-
throw JSONRPCError(RPC_DATABASE_ERROR, "Error: Ban database not loaded");
894-
}
882+
BanMan& banman = EnsureAnyBanman(request.context);
895883

896-
node.banman->ClearDiscouraged();
884+
banman.ClearDiscouraged();
897885

898886
return NullUniValue;
899887
},

0 commit comments

Comments
 (0)