Skip to content

Commit

Permalink
Merge bitcoin/bitcoin#25699: scripted-diff: Replace NullUniValue with…
Browse files Browse the repository at this point in the history
… UniValue::VNULL

fa28d0f scripted-diff: Replace NullUniValue with UniValue::VNULL (MacroFake)
fa96210 fuzz: refactor: Replace NullUniValue with UniValue{} (MacroFake)

Pull request description:

  This refactor is needed to disable the (potentially expensive for large json) UniValue copy constructors.

ACKs for top commit:
  fanquake:
    ACK fa28d0f

Tree-SHA512: 7d4204cce0a6fc4ecda96973de77d15b7e4c7caa3e0e890e1f5b9a4b9ace8b240b1f7565d6ab586e168a5fa1201b6c60a924868ef34d6abfbfd8ab7f0f99fbc7
  • Loading branch information
fanquake committed Jul 26, 2022
2 parents 6078f91 + fa28d0f commit a65f6d8
Show file tree
Hide file tree
Showing 13 changed files with 92 additions and 92 deletions.
14 changes: 7 additions & 7 deletions src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ static RPCHelpMan syncwithvalidationinterfacequeue()
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
{
SyncWithValidationInterfaceQueue();
return NullUniValue;
return UniValue::VNULL;
},
};
}
Expand Down Expand Up @@ -1056,11 +1056,11 @@ static RPCHelpMan gettxout()
LOCK(mempool.cs);
CCoinsViewMemPool view(coins_view, mempool);
if (!view.GetCoin(out, coin) || mempool.isSpent(out)) {
return NullUniValue;
return UniValue::VNULL;
}
} else {
if (!coins_view->GetCoin(out, coin)) {
return NullUniValue;
return UniValue::VNULL;
}
}

Expand Down Expand Up @@ -1498,7 +1498,7 @@ static RPCHelpMan preciousblock()
throw JSONRPCError(RPC_DATABASE_ERROR, state.ToString());
}

return NullUniValue;
return UniValue::VNULL;
},
};
}
Expand Down Expand Up @@ -1539,7 +1539,7 @@ static RPCHelpMan invalidateblock()
throw JSONRPCError(RPC_DATABASE_ERROR, state.ToString());
}

return NullUniValue;
return UniValue::VNULL;
},
};
}
Expand Down Expand Up @@ -1579,7 +1579,7 @@ static RPCHelpMan reconsiderblock()
throw JSONRPCError(RPC_DATABASE_ERROR, state.ToString());
}

return NullUniValue;
return UniValue::VNULL;
},
};
}
Expand Down Expand Up @@ -2098,7 +2098,7 @@ static RPCHelpMan scantxoutset()
CoinsViewScanReserver reserver;
if (reserver.reserve()) {
// no scan in progress
return NullUniValue;
return UniValue::VNULL;
}
result.pushKV("progress", g_scan_progress.load());
return result;
Expand Down
4 changes: 2 additions & 2 deletions src/rpc/mining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ static RPCHelpMan prioritisetransaction()
static UniValue BIP22ValidationResult(const BlockValidationState& state)
{
if (state.IsValid())
return NullUniValue;
return UniValue::VNULL;

if (state.IsError())
throw JSONRPCError(RPC_VERIFY_ERROR, state.ToString());
Expand Down Expand Up @@ -1040,7 +1040,7 @@ static RPCHelpMan submitheader()

BlockValidationState state;
chainman.ProcessNewBlockHeaders({h}, state);
if (state.IsValid()) return NullUniValue;
if (state.IsValid()) return UniValue::VNULL;
if (state.IsError()) {
throw JSONRPCError(RPC_VERIFY_ERROR, state.ToString());
}
Expand Down
12 changes: 6 additions & 6 deletions src/rpc/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ static RPCHelpMan ping()

// Request that each node send a ping during next message processing pass
peerman.SendPings();
return NullUniValue;
return UniValue::VNULL;
},
};
}
Expand Down Expand Up @@ -304,7 +304,7 @@ static RPCHelpMan addnode()
{
CAddress addr;
connman.OpenNetworkConnection(addr, false, nullptr, strNode.c_str(), ConnectionType::MANUAL);
return NullUniValue;
return UniValue::VNULL;
}

if (strCommand == "add")
Expand All @@ -320,7 +320,7 @@ static RPCHelpMan addnode()
}
}

return NullUniValue;
return UniValue::VNULL;
},
};
}
Expand Down Expand Up @@ -423,7 +423,7 @@ static RPCHelpMan disconnectnode()
throw JSONRPCError(RPC_CLIENT_NODE_NOT_CONNECTED, "Node not found in connected nodes");
}

return NullUniValue;
return UniValue::VNULL;
},
};
}
Expand Down Expand Up @@ -745,7 +745,7 @@ static RPCHelpMan setban()
throw JSONRPCError(RPC_CLIENT_INVALID_IP_OR_SUBNET, "Error: Unban failed. Requested address/subnet was not previously manually banned.");
}
}
return NullUniValue;
return UniValue::VNULL;
},
};
}
Expand Down Expand Up @@ -819,7 +819,7 @@ static RPCHelpMan clearbanned()

node.banman->ClearBanned();

return NullUniValue;
return UniValue::VNULL;
},
};
}
Expand Down
6 changes: 3 additions & 3 deletions src/rpc/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static RPCHelpMan setmocktime()
}
}

return NullUniValue;
return UniValue::VNULL;
},
};
}
Expand All @@ -85,7 +85,7 @@ static RPCHelpMan invokedisallowedsyscall()
throw std::runtime_error("invokedisallowedsyscall is used for testing only.");
}
TestDisallowedSandboxCall();
return NullUniValue;
return UniValue::VNULL;
},
};
}
Expand Down Expand Up @@ -118,7 +118,7 @@ static RPCHelpMan mockscheduler()
CHECK_NONFATAL(node_context->scheduler);
node_context->scheduler->MockForward(std::chrono::seconds(delta_seconds));

return NullUniValue;
return UniValue::VNULL;
},
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/fuzz/parse_univalue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ FUZZ_TARGET_INIT(parse_univalue, initialize_parse_univalue)
return ParseNonRFCJSONValue(random_string);
} catch (const std::runtime_error&) {
valid = false;
return NullUniValue;
return UniValue{};
}
}();
if (!valid) {
Expand Down
28 changes: 14 additions & 14 deletions src/wallet/rpc/addresses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ RPCHelpMan getnewaddress()
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
{
std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request);
if (!pwallet) return NullUniValue;
if (!pwallet) return UniValue::VNULL;

LOCK(pwallet->cs_wallet);

Expand Down Expand Up @@ -86,7 +86,7 @@ RPCHelpMan getrawchangeaddress()
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
{
std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request);
if (!pwallet) return NullUniValue;
if (!pwallet) return UniValue::VNULL;

LOCK(pwallet->cs_wallet);

Expand Down Expand Up @@ -131,7 +131,7 @@ RPCHelpMan setlabel()
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
{
std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request);
if (!pwallet) return NullUniValue;
if (!pwallet) return UniValue::VNULL;

LOCK(pwallet->cs_wallet);

Expand All @@ -148,7 +148,7 @@ RPCHelpMan setlabel()
pwallet->SetAddressBook(dest, label, "send");
}

return NullUniValue;
return UniValue::VNULL;
},
};
}
Expand Down Expand Up @@ -181,7 +181,7 @@ RPCHelpMan listaddressgroupings()
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
{
const std::shared_ptr<const CWallet> pwallet = GetWalletForJSONRPCRequest(request);
if (!pwallet) return NullUniValue;
if (!pwallet) return UniValue::VNULL;

// Make sure the results are valid at least up to the most recent block
// the user could have gotten from another RPC command prior to now
Expand Down Expand Up @@ -252,7 +252,7 @@ RPCHelpMan addmultisigaddress()
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
{
std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request);
if (!pwallet) return NullUniValue;
if (!pwallet) return UniValue::VNULL;

LegacyScriptPubKeyMan& spk_man = EnsureLegacyScriptPubKeyMan(*pwallet);

Expand Down Expand Up @@ -327,7 +327,7 @@ RPCHelpMan keypoolrefill()
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
{
std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request);
if (!pwallet) return NullUniValue;
if (!pwallet) return UniValue::VNULL;

if (pwallet->IsLegacy() && pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) {
throw JSONRPCError(RPC_WALLET_ERROR, "Error: Private keys are disabled for this wallet");
Expand All @@ -350,7 +350,7 @@ RPCHelpMan keypoolrefill()
throw JSONRPCError(RPC_WALLET_ERROR, "Error refreshing keypool.");
}

return NullUniValue;
return UniValue::VNULL;
},
};
}
Expand All @@ -374,14 +374,14 @@ RPCHelpMan newkeypool()
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
{
std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request);
if (!pwallet) return NullUniValue;
if (!pwallet) return UniValue::VNULL;

LOCK(pwallet->cs_wallet);

LegacyScriptPubKeyMan& spk_man = EnsureLegacyScriptPubKeyMan(*pwallet, true);
spk_man.NewKeyPool();

return NullUniValue;
return UniValue::VNULL;
},
};
}
Expand Down Expand Up @@ -548,7 +548,7 @@ RPCHelpMan getaddressinfo()
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
{
const std::shared_ptr<const CWallet> pwallet = GetWalletForJSONRPCRequest(request);
if (!pwallet) return NullUniValue;
if (!pwallet) return UniValue::VNULL;

LOCK(pwallet->cs_wallet);

Expand Down Expand Up @@ -658,7 +658,7 @@ RPCHelpMan getaddressesbylabel()
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
{
const std::shared_ptr<const CWallet> pwallet = GetWalletForJSONRPCRequest(request);
if (!pwallet) return NullUniValue;
if (!pwallet) return UniValue::VNULL;

LOCK(pwallet->cs_wallet);

Expand Down Expand Up @@ -721,7 +721,7 @@ RPCHelpMan listlabels()
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
{
const std::shared_ptr<const CWallet> pwallet = GetWalletForJSONRPCRequest(request);
if (!pwallet) return NullUniValue;
if (!pwallet) return UniValue::VNULL;

LOCK(pwallet->cs_wallet);

Expand Down Expand Up @@ -763,7 +763,7 @@ RPCHelpMan walletdisplayaddress()
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
{
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
if (!wallet) return NullUniValue;
if (!wallet) return UniValue::VNULL;
CWallet* const pwallet = wallet.get();

LOCK(pwallet->cs_wallet);
Expand Down
Loading

0 comments on commit a65f6d8

Please sign in to comment.