Break circular dependency main ↔ txdb
Break the circular dependency between main and txdb by: - Moving `CBlockFileInfo` from `main.h` to `chain.h`. I think this makes sense, as the other block-file stuff is there too. - Moving `CDiskTxPos` from `main.h` to `txdb.h`. This type seems specific to txdb. - Pass a functor `insertBlockIndex` to `LoadBlockIndexGuts`. This leaves it up to the caller how to insert block indices.
This commit is contained in:
79
src/main.h
79
src/main.h
@@ -307,30 +307,6 @@ struct CNodeStateStats {
|
||||
std::vector<int> vHeightInFlight;
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
@@ -469,61 +445,6 @@ bool DisconnectBlock(const CBlock& block, CValidationState& state, const CBlockI
|
||||
/** 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);
|
||||
|
||||
|
||||
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 */
|
||||
class CVerifyDB {
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user