rpc: Serialize in getblock without cs_main
This commit is contained in:
parent
fa1c3591ad
commit
fab00a5cb9
1 changed files with 16 additions and 8 deletions
|
@ -93,6 +93,7 @@ static int ComputeNextBlockAndDepth(const CBlockIndex* tip, const CBlockIndex* b
|
||||||
|
|
||||||
UniValue blockheaderToJSON(const CBlockIndex* tip, const CBlockIndex* blockindex)
|
UniValue blockheaderToJSON(const CBlockIndex* tip, const CBlockIndex* blockindex)
|
||||||
{
|
{
|
||||||
|
// Serialize passed information without accessing chain state of the active chain!
|
||||||
UniValue result(UniValue::VOBJ);
|
UniValue result(UniValue::VOBJ);
|
||||||
result.pushKV("hash", blockindex->GetBlockHash().GetHex());
|
result.pushKV("hash", blockindex->GetBlockHash().GetHex());
|
||||||
const CBlockIndex* pnext;
|
const CBlockIndex* pnext;
|
||||||
|
@ -119,6 +120,7 @@ UniValue blockheaderToJSON(const CBlockIndex* tip, const CBlockIndex* blockindex
|
||||||
|
|
||||||
UniValue blockToJSON(const CBlock& block, const CBlockIndex* tip, const CBlockIndex* blockindex, bool txDetails)
|
UniValue blockToJSON(const CBlock& block, const CBlockIndex* tip, const CBlockIndex* blockindex, bool txDetails)
|
||||||
{
|
{
|
||||||
|
// Serialize passed information without accessing chain state of the active chain!
|
||||||
UniValue result(UniValue::VOBJ);
|
UniValue result(UniValue::VOBJ);
|
||||||
result.pushKV("hash", blockindex->GetBlockHash().GetHex());
|
result.pushKV("hash", blockindex->GetBlockHash().GetHex());
|
||||||
const CBlockIndex* pnext;
|
const CBlockIndex* pnext;
|
||||||
|
@ -882,8 +884,6 @@ static UniValue getblock(const JSONRPCRequest& request)
|
||||||
throw std::runtime_error(help.ToString());
|
throw std::runtime_error(help.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
LOCK(cs_main);
|
|
||||||
|
|
||||||
uint256 hash(ParseHashV(request.params[0], "blockhash"));
|
uint256 hash(ParseHashV(request.params[0], "blockhash"));
|
||||||
|
|
||||||
int verbosity = 1;
|
int verbosity = 1;
|
||||||
|
@ -894,12 +894,20 @@ static UniValue getblock(const JSONRPCRequest& request)
|
||||||
verbosity = request.params[1].get_bool() ? 1 : 0;
|
verbosity = request.params[1].get_bool() ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CBlockIndex* pblockindex = LookupBlockIndex(hash);
|
CBlock block;
|
||||||
if (!pblockindex) {
|
const CBlockIndex* pblockindex;
|
||||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
|
const CBlockIndex* tip;
|
||||||
}
|
{
|
||||||
|
LOCK(cs_main);
|
||||||
|
pblockindex = LookupBlockIndex(hash);
|
||||||
|
tip = chainActive.Tip();
|
||||||
|
|
||||||
const CBlock block = GetBlockChecked(pblockindex);
|
if (!pblockindex) {
|
||||||
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
block = GetBlockChecked(pblockindex);
|
||||||
|
}
|
||||||
|
|
||||||
if (verbosity <= 0)
|
if (verbosity <= 0)
|
||||||
{
|
{
|
||||||
|
@ -909,7 +917,7 @@ static UniValue getblock(const JSONRPCRequest& request)
|
||||||
return strHex;
|
return strHex;
|
||||||
}
|
}
|
||||||
|
|
||||||
return blockToJSON(block, chainActive.Tip(), pblockindex, verbosity >= 2);
|
return blockToJSON(block, tip, pblockindex, verbosity >= 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct CCoinsStats
|
struct CCoinsStats
|
||||||
|
|
Loading…
Add table
Reference in a new issue