Getchaintips error checks
This commit is contained in:
@@ -1055,7 +1055,9 @@ UniValue getchaintips(const UniValue& params, bool fHelp)
|
|||||||
setTips.insert(item.second);
|
setTips.insert(item.second);
|
||||||
BOOST_FOREACH(const PAIRTYPE(const uint256, CBlockIndex*)& item, mapBlockIndex)
|
BOOST_FOREACH(const PAIRTYPE(const uint256, CBlockIndex*)& item, mapBlockIndex)
|
||||||
{
|
{
|
||||||
const CBlockIndex* pprev = item.second->pprev;
|
const CBlockIndex* pprev=0;
|
||||||
|
if ( item.second != 0 )
|
||||||
|
pprev = item.second->pprev;
|
||||||
if (pprev)
|
if (pprev)
|
||||||
setTips.erase(pprev);
|
setTips.erase(pprev);
|
||||||
}
|
}
|
||||||
@@ -1064,38 +1066,40 @@ UniValue getchaintips(const UniValue& params, bool fHelp)
|
|||||||
setTips.insert(chainActive.Tip());
|
setTips.insert(chainActive.Tip());
|
||||||
|
|
||||||
/* Construct the output array. */
|
/* Construct the output array. */
|
||||||
UniValue res(UniValue::VARR);
|
UniValue res(UniValue::VARR); CBlockIndex *forked;
|
||||||
BOOST_FOREACH(const CBlockIndex* block, setTips)
|
BOOST_FOREACH(const CBlockIndex* block, setTips)
|
||||||
{
|
{
|
||||||
UniValue obj(UniValue::VOBJ);
|
UniValue obj(UniValue::VOBJ);
|
||||||
obj.push_back(Pair("height", block->nHeight));
|
obj.push_back(Pair("height", block->nHeight));
|
||||||
obj.push_back(Pair("hash", block->phashBlock->GetHex()));
|
obj.push_back(Pair("hash", block->phashBlock->GetHex()));
|
||||||
|
forked = chainActive.FindFork(block);
|
||||||
const int branchLen = block->nHeight - chainActive.FindFork(block)->nHeight;
|
if ( forked != 0 )
|
||||||
obj.push_back(Pair("branchlen", branchLen));
|
{
|
||||||
|
const int branchLen = block->nHeight - forked->nHeight;
|
||||||
string status;
|
obj.push_back(Pair("branchlen", branchLen));
|
||||||
if (chainActive.Contains(block)) {
|
|
||||||
// This block is part of the currently active chain.
|
string status;
|
||||||
status = "active";
|
if (chainActive.Contains(block)) {
|
||||||
} else if (block->nStatus & BLOCK_FAILED_MASK) {
|
// This block is part of the currently active chain.
|
||||||
// This block or one of its ancestors is invalid.
|
status = "active";
|
||||||
status = "invalid";
|
} else if (block->nStatus & BLOCK_FAILED_MASK) {
|
||||||
} else if (block->nChainTx == 0) {
|
// This block or one of its ancestors is invalid.
|
||||||
// This block cannot be connected because full block data for it or one of its parents is missing.
|
status = "invalid";
|
||||||
status = "headers-only";
|
} else if (block->nChainTx == 0) {
|
||||||
} else if (block->IsValid(BLOCK_VALID_SCRIPTS)) {
|
// This block cannot be connected because full block data for it or one of its parents is missing.
|
||||||
// This block is fully validated, but no longer part of the active chain. It was probably the active block once, but was reorganized.
|
status = "headers-only";
|
||||||
status = "valid-fork";
|
} else if (block->IsValid(BLOCK_VALID_SCRIPTS)) {
|
||||||
} else if (block->IsValid(BLOCK_VALID_TREE)) {
|
// This block is fully validated, but no longer part of the active chain. It was probably the active block once, but was reorganized.
|
||||||
// The headers for this block are valid, but it has not been validated. It was probably never part of the most-work chain.
|
status = "valid-fork";
|
||||||
status = "valid-headers";
|
} else if (block->IsValid(BLOCK_VALID_TREE)) {
|
||||||
} else {
|
// The headers for this block are valid, but it has not been validated. It was probably never part of the most-work chain.
|
||||||
// No clue.
|
status = "valid-headers";
|
||||||
status = "unknown";
|
} else {
|
||||||
|
// No clue.
|
||||||
|
status = "unknown";
|
||||||
|
}
|
||||||
|
obj.push_back(Pair("status", status));
|
||||||
}
|
}
|
||||||
obj.push_back(Pair("status", status));
|
|
||||||
|
|
||||||
res.push_back(obj);
|
res.push_back(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user