@@ -496,11 +496,13 @@ Value getchaintips(const Array& params, bool fHelp)
496
496
" \" height\" : xxxx, (numeric) height of the chain tip\n "
497
497
" \" hash\" : \" xxxx\" , (string) block hash of the tip\n "
498
498
" \" branchlen\" : 0 (numeric) zero for main chain\n "
499
+ " \" status\" : \" active\" (string) \" active\" for the main chain\n "
499
500
" },\n "
500
501
" {\n "
501
502
" \" height\" : xxxx,\n "
502
503
" \" hash\" : \" xxxx\" ,\n "
503
504
" \" branchlen\" : 1 (numeric) length of branch connecting the tip to the main chain\n "
505
+ " \" status\" : \" xxxx\" (string) status of the chain (active, valid-fork, valid-headers, headers-only, invalid)\n "
504
506
" }\n "
505
507
" ]\n "
506
508
" \n Examples:\n "
@@ -521,6 +523,9 @@ Value getchaintips(const Array& params, bool fHelp)
521
523
setTips.erase (pprev);
522
524
}
523
525
526
+ // Always report the currently active tip.
527
+ setTips.insert (chainActive.Tip ());
528
+
524
529
/* Construct the output array. */
525
530
Array res;
526
531
BOOST_FOREACH (const CBlockIndex* block, setTips)
@@ -532,6 +537,28 @@ Value getchaintips(const Array& params, bool fHelp)
532
537
const int branchLen = block->nHeight - chainActive.FindFork (block)->nHeight ;
533
538
obj.push_back (Pair (" branchlen" , branchLen));
534
539
540
+ string status;
541
+ if (chainActive.Contains (block)) {
542
+ // This block is part of the currently active chain.
543
+ status = " active" ;
544
+ } else if (block->nStatus & BLOCK_FAILED_MASK) {
545
+ // This block or one of its ancestors is invalid.
546
+ status = " invalid" ;
547
+ } else if (block->nChainTx == 0 ) {
548
+ // This block cannot be connected because full block data for it or one of its parents is missing.
549
+ status = " headers-only" ;
550
+ } else if (block->IsValid (BLOCK_VALID_SCRIPTS)) {
551
+ // This block is fully validated, but no longer part of the active chain. It was probably the active block once, but was reorganized.
552
+ status = " valid-fork" ;
553
+ } else if (block->IsValid (BLOCK_VALID_TREE)) {
554
+ // The headers for this block are valid, but it has not been validated. It was probably never part of the most-work chain.
555
+ status = " valid-headers" ;
556
+ } else {
557
+ // No clue.
558
+ status = " unknown" ;
559
+ }
560
+ obj.push_back (Pair (" status" , status));
561
+
535
562
res.push_back (obj);
536
563
}
537
564
0 commit comments