@@ -500,6 +500,11 @@ static RPCHelpMan getaddressutxos()
500500 throw JSONRPCError (RPC_MISC_ERROR, " Address index is not enabled. Start with -addressindex to enable." );
501501 }
502502
503+ const IndexSummary summary = g_addressindex->GetSummary ();
504+ if (!summary.synced ) {
505+ throw JSONRPCError (RPC_MISC_ERROR, strprintf (" Address index is syncing. Current height: %d" , summary.best_block_height ));
506+ }
507+
503508 std::vector<CAddressUnspentIndexEntry> unspentOutputs;
504509
505510 for (const auto & address : addresses) {
@@ -587,6 +592,12 @@ static RPCHelpMan getaddressdeltas()
587592 if (!g_addressindex) {
588593 throw JSONRPCError (RPC_MISC_ERROR, " Address index is not enabled. Start with -addressindex to enable." );
589594 }
595+
596+ const IndexSummary summary = g_addressindex->GetSummary ();
597+ if (!summary.synced ) {
598+ throw JSONRPCError (RPC_MISC_ERROR, strprintf (" Address index is syncing. Current height: %d" , summary.best_block_height ));
599+ }
600+
590601 for (const auto & address : addresses) {
591602 if (start <= 0 || end <= 0 ) { start = 0 ; end = 0 ; }
592603 if (!g_addressindex->GetAddressIndex (address.first , address.second ,
@@ -654,21 +665,22 @@ static RPCHelpMan getaddressbalance()
654665 if (!g_addressindex) {
655666 throw JSONRPCError (RPC_MISC_ERROR, " Address index is not enabled. Start with -addressindex to enable." );
656667 }
668+
669+ // Check sync status first to return a clear error message
670+ // Use the index's best block height instead of chain tip to avoid inconsistency
671+ const IndexSummary summary = g_addressindex->GetSummary ();
672+ if (!summary.synced ) {
673+ throw JSONRPCError (RPC_MISC_ERROR, strprintf (" Address index is syncing. Current height: %d" , summary.best_block_height ));
674+ }
675+ int nHeight = summary.best_block_height ;
676+
657677 for (const auto & address : addresses) {
658678 if (!g_addressindex->GetAddressIndex (address.first , address.second , addressIndex,
659679 /* start=*/ 0 , /* end=*/ 0 )) {
660680 throw JSONRPCError (RPC_INVALID_ADDRESS_OR_KEY, " No information available for address" );
661681 }
662682 }
663683
664- // Use the index's best block height instead of chain tip to avoid inconsistency
665- // The async index may be behind the chain tip during sync
666- IndexSummary summary = g_addressindex->GetSummary ();
667- if (!summary.synced ) {
668- throw JSONRPCError (RPC_INTERNAL_ERROR, " Address index not yet synced" );
669- }
670- int nHeight = summary.best_block_height ;
671-
672684
673685 CAmount balance = 0 ;
674686 CAmount balance_spendable = 0 ;
@@ -742,6 +754,12 @@ static RPCHelpMan getaddresstxids()
742754 if (!g_addressindex) {
743755 throw JSONRPCError (RPC_MISC_ERROR, " Address index is not enabled. Start with -addressindex to enable." );
744756 }
757+
758+ const IndexSummary summary = g_addressindex->GetSummary ();
759+ if (!summary.synced ) {
760+ throw JSONRPCError (RPC_MISC_ERROR, strprintf (" Address index is syncing. Current height: %d" , summary.best_block_height ));
761+ }
762+
745763 for (const auto & address : addresses) {
746764 if (start <= 0 || end <= 0 ) { start = 0 ; end = 0 ; }
747765 if (!g_addressindex->GetAddressIndex (address.first , address.second ,
@@ -824,7 +842,7 @@ static RPCHelpMan getspentinfo()
824842 CSpentIndexValue value;
825843 bool found = false ;
826844
827- // Check the async index first
845+ // Check the async index first (may return false if still syncing)
828846 if (g_spentindex->GetSpentInfo (key, value)) {
829847 found = true ;
830848 }
@@ -844,6 +862,10 @@ static RPCHelpMan getspentinfo()
844862 }
845863
846864 if (!found) {
865+ const IndexSummary summary = g_spentindex->GetSummary ();
866+ if (!summary.synced ) {
867+ throw JSONRPCError (RPC_MISC_ERROR, strprintf (" Unable to get spent info. Spent index is syncing, current height: %d" , summary.best_block_height ));
868+ }
847869 throw JSONRPCError (RPC_INVALID_ADDRESS_OR_KEY, " Unable to get spent info" );
848870 }
849871
0 commit comments