CZindexStats
This commit is contained in:
20
src/main.cpp
20
src/main.cpp
@@ -609,9 +609,9 @@ bool CZindexDB::Read(CZindexStats& zstats)
|
||||
CDataStream ssZstats(vchData, SER_DISK, CLIENT_VERSION);
|
||||
|
||||
// verify stored checksum matches input data
|
||||
uint256 hashTmp = Hash(ssPeers.begin(), ssPeers.end());
|
||||
uint256 hashTmp = Hash(ssZstats.begin(), ssZstats.end());
|
||||
if (hashIn != hashTmp)
|
||||
return error("%s: Checksum mismatch, data corrupted", __func__);
|
||||
return error("%s: zstats Checksum mismatch, data corrupted", __func__);
|
||||
|
||||
unsigned char pchMsgTmp[4];
|
||||
try {
|
||||
@@ -622,10 +622,9 @@ bool CZindexDB::Read(CZindexStats& zstats)
|
||||
if (memcmp(pchMsgTmp, Params().MessageStart(), sizeof(pchMsgTmp)))
|
||||
return error("%s: Invalid network magic number", __func__);
|
||||
|
||||
// de-serialize address data into one CAddrMan object
|
||||
ssZstats >> addr;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
// de-serialize data into one CZindexStats object
|
||||
ssZstats >> zstats;
|
||||
} catch (const std::exception& e) {
|
||||
return error("%s: Deserialize or I/O error - %s", __func__, e.what());
|
||||
}
|
||||
|
||||
@@ -646,9 +645,16 @@ bool CZindexDB::Write(const CZindexStats& zstats)
|
||||
uint256 hash = Hash(ssZstats.begin(), ssZstats.end());
|
||||
ssZstats << hash;
|
||||
|
||||
// open temp output file, and associate with CAutoFile
|
||||
boost::filesystem::path pathTmp = GetDataDir() / tmpfn;
|
||||
FILE *file = fopen(pathTmp.string().c_str(), "wb");
|
||||
CAutoFile fileout(file, SER_DISK, CLIENT_VERSION);
|
||||
if (fileout.IsNull())
|
||||
return error("%s: Failed to open file %s", __func__, pathTmp.string());
|
||||
|
||||
// Write and commit header, data
|
||||
try {
|
||||
fileout << ssPeers;
|
||||
fileout << ssZstats;
|
||||
} catch (const std::exception& e) {
|
||||
return error("%s: Serialize or I/O error - %s", __func__, e.what());
|
||||
}
|
||||
|
||||
104
src/main.h
104
src/main.h
@@ -950,14 +950,114 @@ std::pair<std::map<CBlockIndex*, std::list<CTransaction>>, uint64_t> DrainRecent
|
||||
void SetChainNotifiedSequence(uint64_t recentlyConflictedSequence);
|
||||
bool ChainIsFullyNotified();
|
||||
|
||||
class CZindexStats
|
||||
{
|
||||
//private:
|
||||
public:
|
||||
int64_t nHeight;
|
||||
int64_t nChainTx;
|
||||
int64_t nChainNotarizations;
|
||||
int64_t nChainPayments;
|
||||
int64_t nChainShieldedTx;
|
||||
int64_t nChainShieldedOutputs;
|
||||
int64_t nChainShieldedSpends;
|
||||
int64_t nChainFullyShieldedTx;
|
||||
int64_t nChainShieldingPayments;
|
||||
int64_t nChainShieldedPayments;
|
||||
int64_t nChainFullyShieldedPayments;
|
||||
int64_t nChainDeshieldingTx;
|
||||
int64_t nChainDeshieldingPayments;
|
||||
int64_t nChainShieldingTx;
|
||||
|
||||
size_t Height() const
|
||||
{
|
||||
return nHeight;
|
||||
}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
LOCK(cs_main);
|
||||
nChainTx=0;
|
||||
nChainNotarizations=0;
|
||||
nChainPayments=0;
|
||||
nChainShieldedTx=0;
|
||||
nChainShieldedOutputs=0;
|
||||
nChainShieldedSpends=0;
|
||||
nChainFullyShieldedTx=0;
|
||||
nChainShieldingPayments=0;
|
||||
nChainShieldedPayments=0;
|
||||
nChainFullyShieldedPayments=0;
|
||||
nChainDeshieldingTx=0;
|
||||
nChainDeshieldingPayments=0;
|
||||
nChainShieldingTx=0;
|
||||
}
|
||||
|
||||
CZindexStats()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
~CZindexStats()
|
||||
{
|
||||
}
|
||||
|
||||
template<typename Stream> void Serialize(Stream &s) const
|
||||
{
|
||||
LOCK(cs_main);
|
||||
|
||||
// So we can detect a new version and force a rescan
|
||||
unsigned char nVersion = 1;
|
||||
s << nVersion;
|
||||
s << nHeight;
|
||||
s << nChainTx;
|
||||
s << nChainNotarizations;
|
||||
s << nChainPayments;
|
||||
s << nChainShieldedTx;
|
||||
s << nChainShieldedOutputs;
|
||||
s << nChainShieldedSpends;
|
||||
s << nChainFullyShieldedTx;
|
||||
s << nChainShieldingPayments;
|
||||
s << nChainShieldedPayments;
|
||||
s << nChainFullyShieldedPayments;
|
||||
s << nChainDeshieldingTx;
|
||||
s << nChainDeshieldingPayments;
|
||||
s << nChainShieldingTx;
|
||||
}
|
||||
|
||||
template<typename Stream> void Unserialize(Stream& s)
|
||||
{
|
||||
LOCK(cs_main);
|
||||
|
||||
Clear();
|
||||
unsigned char nVersion;
|
||||
s >> nVersion;
|
||||
s >> nHeight;
|
||||
s >> nChainTx;
|
||||
s >> nChainNotarizations;
|
||||
s >> nChainPayments;
|
||||
s >> nChainShieldedTx;
|
||||
s >> nChainShieldedOutputs;
|
||||
s >> nChainShieldedSpends;
|
||||
s >> nChainFullyShieldedTx;
|
||||
s >> nChainShieldingPayments;
|
||||
s >> nChainShieldedPayments;
|
||||
s >> nChainFullyShieldedPayments;
|
||||
s >> nChainDeshieldingTx;
|
||||
s >> nChainDeshieldingPayments;
|
||||
s >> nChainShieldingTx;
|
||||
}
|
||||
};
|
||||
|
||||
// Wrapper for zindex.dat stats
|
||||
class CZindexDB
|
||||
{
|
||||
private:
|
||||
boost::filesystem::path pathAddr;
|
||||
public:
|
||||
CZindexDB();
|
||||
bool Write(const CZindexDB& addr);
|
||||
bool Read(CZindexDB& addr);
|
||||
bool Write(const CZindexStats& zstats);
|
||||
bool Read(CZindexStats& zstats);
|
||||
};
|
||||
|
||||
|
||||
#endif // HUSH_MAIN_H
|
||||
|
||||
@@ -106,6 +106,7 @@ static CNode* pnodeLocalHost = NULL;
|
||||
uint64_t nLocalHostNonce = 0;
|
||||
static std::vector<ListenSocket> vhListenSocket;
|
||||
CAddrMan addrman;
|
||||
CZindexStats zstats;
|
||||
int nMaxConnections = DEFAULT_MAX_PEER_CONNECTIONS;
|
||||
bool fAddressesInitialized = false;
|
||||
std::string strSubVersion;
|
||||
@@ -1410,7 +1411,7 @@ void DumpZindexStats()
|
||||
CZindexDB zdb;
|
||||
zdb.Write(zstats);
|
||||
|
||||
LogPrintf("Flushed %d items to zindex.dat %dms\n", zstats.size(), GetTimeMillis() - nStart);
|
||||
LogPrintf("Flushed stats at height %li to zindex.dat %dms\n", zstats.Height(), GetTimeMillis() - nStart);
|
||||
}
|
||||
|
||||
void static ProcessOneShot()
|
||||
@@ -1934,7 +1935,7 @@ void StartNode(boost::thread_group& threadGroup, CScheduler& scheduler)
|
||||
// TODO: move invalid files out of the way?
|
||||
}
|
||||
}
|
||||
LogPrintf("Loaded %i items from zindex.dat %dms\n", zstats.size(), GetTimeMillis() - nStart);
|
||||
LogPrintf("Loaded stats at height %li from zindex.dat %dms\n", zstats.Height(), GetTimeMillis() - nStart);
|
||||
}
|
||||
|
||||
uiInterface.InitMessage(_("Loading addresses..."));
|
||||
@@ -1995,7 +1996,7 @@ void StartNode(boost::thread_group& threadGroup, CScheduler& scheduler)
|
||||
scheduler.scheduleEvery(&DumpAddresses, DUMP_ADDRESSES_INTERVAL);
|
||||
|
||||
// Dump zindex stats
|
||||
scheduler.scheduleEvery(&DumpZstats, DUMP_ZINDEX_INTERVAL);
|
||||
scheduler.scheduleEvery(&DumpZindexStats, DUMP_ZINDEX_INTERVAL);
|
||||
}
|
||||
|
||||
bool StopNode()
|
||||
|
||||
Reference in New Issue
Block a user