11
11
#include < chainparams.h>
12
12
#include < coins.h>
13
13
#include < consensus/validation.h>
14
- #include < crypto/muhash.h>
15
14
#include < core_io.h>
16
15
#include < hash.h>
17
16
#include < index/blockfilterindex.h>
17
+ #include < index/utxosethash.h>
18
18
#include < policy/feerate.h>
19
19
#include < policy/policy.h>
20
20
#include < policy/rbf.h>
@@ -925,14 +925,9 @@ struct CCoinsStats
925
925
CCoinsStats () : nHeight(0 ), nTransactions(0 ), nTransactionOutputs(0 ), nBogoSize(0 ), nDiskSize(0 ), nTotalAmount(0 ) {}
926
926
};
927
927
928
- static void ApplyStats (CCoinsStats &stats, MuHash3072& acc, const COutPoint outpoint, const Coin& coin)
928
+ static void ApplyStats (CCoinsStats &stats, const COutPoint outpoint, const Coin& coin)
929
929
{
930
930
stats.nTransactions ++;
931
- TruncatedSHA512Writer ss (SER_DISK, 0 );
932
- ss << outpoint;
933
- ss << (uint32_t )(coin.nHeight * 2 + coin.fCoinBase );
934
- ss << coin.out ;
935
- acc *= MuHash3072 (ss.GetHash ().begin ());
936
931
stats.nTransactionOutputs ++;
937
932
stats.nTotalAmount += coin.out .nValue ;
938
933
stats.nBogoSize += 32 /* txid */ + 4 /* vout index */ + 4 /* height + coinbase */ + 8 /* amount */ +
@@ -945,28 +940,42 @@ static bool GetUTXOStats(CCoinsView *view, CCoinsStats &stats)
945
940
std::unique_ptr<CCoinsViewCursor> pcursor (view->Cursor ());
946
941
assert (pcursor);
947
942
943
+ uint256 muhash_buf;
944
+ const CBlockIndex* block_index;
948
945
stats.hashBlock = pcursor->GetBestBlock ();
949
946
{
950
947
LOCK (cs_main);
951
- stats. nHeight = LookupBlockIndex (stats.hashBlock )-> nHeight ;
948
+ block_index = LookupBlockIndex (stats.hashBlock );
952
949
}
953
- MuHash3072 acc;
950
+
951
+ stats.nHeight = block_index->nHeight ;
952
+
953
+ bool index_ready = g_utxo_set_hash->BlockUntilSyncedToCurrentChain ();
954
+
955
+ if (!g_utxo_set_hash->LookupHash (block_index, muhash_buf)) {
956
+ int err_code = RPC_MISC_ERROR;
957
+
958
+ if (!index_ready) {
959
+ throw JSONRPCError (err_code, " UTXO set hash is still in the process of being indexed." );
960
+ } else {
961
+ throw JSONRPCError (err_code, " Unable to get UTXO set hash" );
962
+ }
963
+ }
964
+
965
+ stats.muhash = muhash_buf;
966
+
954
967
while (pcursor->Valid ()) {
955
968
boost::this_thread::interruption_point ();
956
969
COutPoint key;
957
970
Coin coin;
958
971
if (pcursor->GetKey (key) && pcursor->GetValue (coin)) {
959
- ApplyStats (stats, acc, key, coin);
972
+ ApplyStats (stats, key, coin);
960
973
} else {
961
974
return error (" %s: unable to read value" , __func__);
962
975
}
963
976
pcursor->Next ();
964
977
}
965
- unsigned char data[384 ];
966
- acc.Finalize (data);
967
- TruncatedSHA512Writer ss (SER_DISK, 0 );
968
- ss << FLATDATA (data);
969
- stats.muhash = ss.GetHash ();
978
+
970
979
stats.nDiskSize = view->EstimateSize ();
971
980
return true ;
972
981
}
0 commit comments