mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 20:12:57 +01:00
Merge #7815: Break circular dependency main ↔ txdb
99e7075
Break circular dependency main ↔ txdb (Wladimir J. van der Laan)
This commit is contained in:
parent
2e54bd2e8c
commit
abaf524f0c
54
src/chain.h
54
src/chain.h
@ -14,6 +14,60 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
class CBlockFileInfo
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
unsigned int nBlocks; //!< number of blocks stored in file
|
||||||
|
unsigned int nSize; //!< number of used bytes of block file
|
||||||
|
unsigned int nUndoSize; //!< number of used bytes in the undo file
|
||||||
|
unsigned int nHeightFirst; //!< lowest height of block in file
|
||||||
|
unsigned int nHeightLast; //!< highest height of block in file
|
||||||
|
uint64_t nTimeFirst; //!< earliest time of block in file
|
||||||
|
uint64_t nTimeLast; //!< latest time of block in file
|
||||||
|
|
||||||
|
ADD_SERIALIZE_METHODS;
|
||||||
|
|
||||||
|
template <typename Stream, typename Operation>
|
||||||
|
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
||||||
|
READWRITE(VARINT(nBlocks));
|
||||||
|
READWRITE(VARINT(nSize));
|
||||||
|
READWRITE(VARINT(nUndoSize));
|
||||||
|
READWRITE(VARINT(nHeightFirst));
|
||||||
|
READWRITE(VARINT(nHeightLast));
|
||||||
|
READWRITE(VARINT(nTimeFirst));
|
||||||
|
READWRITE(VARINT(nTimeLast));
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetNull() {
|
||||||
|
nBlocks = 0;
|
||||||
|
nSize = 0;
|
||||||
|
nUndoSize = 0;
|
||||||
|
nHeightFirst = 0;
|
||||||
|
nHeightLast = 0;
|
||||||
|
nTimeFirst = 0;
|
||||||
|
nTimeLast = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
CBlockFileInfo() {
|
||||||
|
SetNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string ToString() const;
|
||||||
|
|
||||||
|
/** update statistics (does not update nSize) */
|
||||||
|
void AddBlock(unsigned int nHeightIn, uint64_t nTimeIn) {
|
||||||
|
if (nBlocks==0 || nHeightFirst > nHeightIn)
|
||||||
|
nHeightFirst = nHeightIn;
|
||||||
|
if (nBlocks==0 || nTimeFirst > nTimeIn)
|
||||||
|
nTimeFirst = nTimeIn;
|
||||||
|
nBlocks++;
|
||||||
|
if (nHeightIn > nHeightLast)
|
||||||
|
nHeightLast = nHeightIn;
|
||||||
|
if (nTimeIn > nTimeLast)
|
||||||
|
nTimeLast = nTimeIn;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
struct CDiskBlockPos
|
struct CDiskBlockPos
|
||||||
{
|
{
|
||||||
int nFile;
|
int nFile;
|
||||||
|
@ -5,10 +5,8 @@
|
|||||||
|
|
||||||
#include "txdb.h"
|
#include "txdb.h"
|
||||||
|
|
||||||
#include "chain.h"
|
|
||||||
#include "chainparams.h"
|
#include "chainparams.h"
|
||||||
#include "hash.h"
|
#include "hash.h"
|
||||||
#include "validation.h"
|
|
||||||
#include "pow.h"
|
#include "pow.h"
|
||||||
#include "uint256.h"
|
#include "uint256.h"
|
||||||
|
|
||||||
@ -305,7 +303,7 @@ bool CBlockTreeDB::ReadFlag(const std::string &name, bool &fValue) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CBlockTreeDB::LoadBlockIndexGuts()
|
bool CBlockTreeDB::LoadBlockIndexGuts(boost::function<CBlockIndex*(const uint256&)> insertBlockIndex)
|
||||||
{
|
{
|
||||||
boost::scoped_ptr<CDBIterator> pcursor(NewIterator());
|
boost::scoped_ptr<CDBIterator> pcursor(NewIterator());
|
||||||
|
|
||||||
@ -319,8 +317,8 @@ bool CBlockTreeDB::LoadBlockIndexGuts()
|
|||||||
CDiskBlockIndex diskindex;
|
CDiskBlockIndex diskindex;
|
||||||
if (pcursor->GetValue(diskindex)) {
|
if (pcursor->GetValue(diskindex)) {
|
||||||
// Construct block index object
|
// Construct block index object
|
||||||
CBlockIndex* pindexNew = InsertBlockIndex(diskindex.GetBlockHash());
|
CBlockIndex* pindexNew = insertBlockIndex(diskindex.GetBlockHash());
|
||||||
pindexNew->pprev = InsertBlockIndex(diskindex.hashPrev);
|
pindexNew->pprev = insertBlockIndex(diskindex.hashPrev);
|
||||||
pindexNew->nHeight = diskindex.nHeight;
|
pindexNew->nHeight = diskindex.nHeight;
|
||||||
pindexNew->nFile = diskindex.nFile;
|
pindexNew->nFile = diskindex.nFile;
|
||||||
pindexNew->nDataPos = diskindex.nDataPos;
|
pindexNew->nDataPos = diskindex.nDataPos;
|
||||||
|
36
src/txdb.h
36
src/txdb.h
@ -8,15 +8,19 @@
|
|||||||
|
|
||||||
#include "coins.h"
|
#include "coins.h"
|
||||||
#include "dbwrapper.h"
|
#include "dbwrapper.h"
|
||||||
|
#include "chain.h"
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
class CBlockFileInfo;
|
#include <boost/function.hpp>
|
||||||
|
|
||||||
class CBlockIndex;
|
class CBlockIndex;
|
||||||
struct CDiskTxPos;
|
class CCoinsViewDBCursor;
|
||||||
|
class uint256;
|
||||||
|
|
||||||
struct CAddressUnspentKey;
|
struct CAddressUnspentKey;
|
||||||
struct CAddressUnspentValue;
|
struct CAddressUnspentValue;
|
||||||
struct CAddressIndexKey;
|
struct CAddressIndexKey;
|
||||||
@ -26,7 +30,6 @@ struct CTimestampIndexKey;
|
|||||||
struct CTimestampIndexIteratorKey;
|
struct CTimestampIndexIteratorKey;
|
||||||
struct CSpentIndexKey;
|
struct CSpentIndexKey;
|
||||||
struct CSpentIndexValue;
|
struct CSpentIndexValue;
|
||||||
class uint256;
|
|
||||||
|
|
||||||
//! -dbcache default (MiB)
|
//! -dbcache default (MiB)
|
||||||
static const int64_t nDefaultDbCache = 100;
|
static const int64_t nDefaultDbCache = 100;
|
||||||
@ -35,7 +38,30 @@ static const int64_t nMaxDbCache = sizeof(void*) > 4 ? 16384 : 1024;
|
|||||||
//! min. -dbcache in (MiB)
|
//! min. -dbcache in (MiB)
|
||||||
static const int64_t nMinDbCache = 4;
|
static const int64_t nMinDbCache = 4;
|
||||||
|
|
||||||
class CCoinsViewDBCursor;
|
struct CDiskTxPos : public CDiskBlockPos
|
||||||
|
{
|
||||||
|
unsigned int nTxOffset; // after header
|
||||||
|
|
||||||
|
ADD_SERIALIZE_METHODS;
|
||||||
|
|
||||||
|
template <typename Stream, typename Operation>
|
||||||
|
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
||||||
|
READWRITE(*(CDiskBlockPos*)this);
|
||||||
|
READWRITE(VARINT(nTxOffset));
|
||||||
|
}
|
||||||
|
|
||||||
|
CDiskTxPos(const CDiskBlockPos &blockIn, unsigned int nTxOffsetIn) : CDiskBlockPos(blockIn.nFile, blockIn.nPos), nTxOffset(nTxOffsetIn) {
|
||||||
|
}
|
||||||
|
|
||||||
|
CDiskTxPos() {
|
||||||
|
SetNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetNull() {
|
||||||
|
CDiskBlockPos::SetNull();
|
||||||
|
nTxOffset = 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/** CCoinsView backed by the coin database (chainstate/) */
|
/** CCoinsView backed by the coin database (chainstate/) */
|
||||||
class CCoinsViewDB : public CCoinsView
|
class CCoinsViewDB : public CCoinsView
|
||||||
@ -104,7 +130,7 @@ public:
|
|||||||
bool ReadTimestampIndex(const unsigned int &high, const unsigned int &low, std::vector<uint256> &vect);
|
bool ReadTimestampIndex(const unsigned int &high, const unsigned int &low, std::vector<uint256> &vect);
|
||||||
bool WriteFlag(const std::string &name, bool fValue);
|
bool WriteFlag(const std::string &name, bool fValue);
|
||||||
bool ReadFlag(const std::string &name, bool &fValue);
|
bool ReadFlag(const std::string &name, bool &fValue);
|
||||||
bool LoadBlockIndexGuts();
|
bool LoadBlockIndexGuts(boost::function<CBlockIndex*(const uint256&)> insertBlockIndex);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BITCOIN_TXDB_H
|
#endif // BITCOIN_TXDB_H
|
||||||
|
@ -3701,7 +3701,7 @@ CBlockIndex * InsertBlockIndex(uint256 hash)
|
|||||||
bool static LoadBlockIndexDB()
|
bool static LoadBlockIndexDB()
|
||||||
{
|
{
|
||||||
const CChainParams& chainparams = Params();
|
const CChainParams& chainparams = Params();
|
||||||
if (!pblocktree->LoadBlockIndexGuts())
|
if (!pblocktree->LoadBlockIndexGuts(InsertBlockIndex))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
boost::this_thread::interruption_point();
|
boost::this_thread::interruption_point();
|
||||||
|
@ -583,30 +583,6 @@ struct CAddressIndexIteratorHeightKey {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CDiskTxPos : public CDiskBlockPos
|
|
||||||
{
|
|
||||||
unsigned int nTxOffset; // after header
|
|
||||||
|
|
||||||
ADD_SERIALIZE_METHODS;
|
|
||||||
|
|
||||||
template <typename Stream, typename Operation>
|
|
||||||
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
|
||||||
READWRITE(*(CDiskBlockPos*)this);
|
|
||||||
READWRITE(VARINT(nTxOffset));
|
|
||||||
}
|
|
||||||
|
|
||||||
CDiskTxPos(const CDiskBlockPos &blockIn, unsigned int nTxOffsetIn) : CDiskBlockPos(blockIn.nFile, blockIn.nPos), nTxOffset(nTxOffsetIn) {
|
|
||||||
}
|
|
||||||
|
|
||||||
CDiskTxPos() {
|
|
||||||
SetNull();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetNull() {
|
|
||||||
CDiskBlockPos::SetNull();
|
|
||||||
nTxOffset = 0;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -752,61 +728,6 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIn
|
|||||||
/** Check a block is completely valid from start to finish (only works on top of our current best block, with cs_main held) */
|
/** Check a block is completely valid from start to finish (only works on top of our current best block, with cs_main held) */
|
||||||
bool TestBlockValidity(CValidationState& state, const CChainParams& chainparams, const CBlock& block, CBlockIndex* pindexPrev, bool fCheckPOW = true, bool fCheckMerkleRoot = true);
|
bool TestBlockValidity(CValidationState& state, const CChainParams& chainparams, const CBlock& block, CBlockIndex* pindexPrev, bool fCheckPOW = true, bool fCheckMerkleRoot = true);
|
||||||
|
|
||||||
|
|
||||||
class CBlockFileInfo
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
unsigned int nBlocks; //! number of blocks stored in file
|
|
||||||
unsigned int nSize; //! number of used bytes of block file
|
|
||||||
unsigned int nUndoSize; //! number of used bytes in the undo file
|
|
||||||
unsigned int nHeightFirst; //! lowest height of block in file
|
|
||||||
unsigned int nHeightLast; //! highest height of block in file
|
|
||||||
uint64_t nTimeFirst; //! earliest time of block in file
|
|
||||||
uint64_t nTimeLast; //! latest time of block in file
|
|
||||||
|
|
||||||
ADD_SERIALIZE_METHODS;
|
|
||||||
|
|
||||||
template <typename Stream, typename Operation>
|
|
||||||
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
|
||||||
READWRITE(VARINT(nBlocks));
|
|
||||||
READWRITE(VARINT(nSize));
|
|
||||||
READWRITE(VARINT(nUndoSize));
|
|
||||||
READWRITE(VARINT(nHeightFirst));
|
|
||||||
READWRITE(VARINT(nHeightLast));
|
|
||||||
READWRITE(VARINT(nTimeFirst));
|
|
||||||
READWRITE(VARINT(nTimeLast));
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetNull() {
|
|
||||||
nBlocks = 0;
|
|
||||||
nSize = 0;
|
|
||||||
nUndoSize = 0;
|
|
||||||
nHeightFirst = 0;
|
|
||||||
nHeightLast = 0;
|
|
||||||
nTimeFirst = 0;
|
|
||||||
nTimeLast = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
CBlockFileInfo() {
|
|
||||||
SetNull();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string ToString() const;
|
|
||||||
|
|
||||||
/** update statistics (does not update nSize) */
|
|
||||||
void AddBlock(unsigned int nHeightIn, uint64_t nTimeIn) {
|
|
||||||
if (nBlocks==0 || nHeightFirst > nHeightIn)
|
|
||||||
nHeightFirst = nHeightIn;
|
|
||||||
if (nBlocks==0 || nTimeFirst > nTimeIn)
|
|
||||||
nTimeFirst = nTimeIn;
|
|
||||||
nBlocks++;
|
|
||||||
if (nHeightIn > nHeightLast)
|
|
||||||
nHeightLast = nHeightIn;
|
|
||||||
if (nTimeIn > nTimeLast)
|
|
||||||
nTimeLast = nTimeIn;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/** RAII wrapper for VerifyDB: Verify consistency of the block and coin databases */
|
/** RAII wrapper for VerifyDB: Verify consistency of the block and coin databases */
|
||||||
class CVerifyDB {
|
class CVerifyDB {
|
||||||
public:
|
public:
|
||||||
|
Loading…
Reference in New Issue
Block a user