@@ -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 ,
@@ -820,6 +838,11 @@ static RPCHelpMan getspentinfo()
820838 throw JSONRPCError (RPC_MISC_ERROR, " Spent index is not enabled. Start with -spentindex to enable." );
821839 }
822840
841+ const IndexSummary summary = g_spentindex->GetSummary ();
842+ if (!summary.synced ) {
843+ throw JSONRPCError (RPC_MISC_ERROR, strprintf (" Spent index is syncing. Current height: %d" , summary.best_block_height ));
844+ }
845+
823846 CSpentIndexKey key (txid, outputIndex);
824847 CSpentIndexValue value;
825848 bool found = false ;
0 commit comments