Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14864746
D12510.id36364.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
9 KB
Subscribers
None
D12510.id36364.diff
View Options
diff --git a/src/node/blockstorage.h b/src/node/blockstorage.h
--- a/src/node/blockstorage.h
+++ b/src/node/blockstorage.h
@@ -62,6 +62,14 @@
friend CChainState;
private:
+ void FlushBlockFile(bool fFinalize = false, bool finalize_undo = false);
+ void FlushUndoFile(int block_file, bool finalize = false);
+ bool FindBlockPos(FlatFilePos &pos, unsigned int nAddSize,
+ unsigned int nHeight, CChain &active_chain,
+ uint64_t nTime, bool fKnown);
+ bool FindUndoPos(BlockValidationState &state, int nFile, FlatFilePos &pos,
+ unsigned int nAddSize);
+
/**
* Calculate the block/rev files to delete based on height specified
* by user with RPC command pruneblockchain
@@ -134,6 +142,23 @@
CBlockIndex *LookupBlockIndex(const BlockHash &hash) const
EXCLUSIVE_LOCKS_REQUIRED(cs_main);
+ /** Get block file info entry for one block file */
+ CBlockFileInfo *GetBlockFileInfo(size_t n);
+
+ bool WriteUndoDataForBlock(const CBlockUndo &blockundo,
+ BlockValidationState &state, CBlockIndex *pindex,
+ const CChainParams &chainparams);
+
+ FlatFilePos SaveBlockToDisk(const CBlock &block, int nHeight,
+ CChain &active_chain,
+ const CChainParams &chainparams,
+ const FlatFilePos *dbp);
+
+ /**
+ * Calculate the amount of disk space the block & undo files currently use
+ */
+ uint64_t CalculateCurrentUsage();
+
//! Returns last CBlockIndex* that is a checkpoint
CBlockIndex *GetLastCheckpoint(const CCheckpointData &data)
EXCLUSIVE_LOCKS_REQUIRED(cs_main);
@@ -151,12 +176,6 @@
/** Translation to a filesystem path. */
fs::path GetBlockPosFilename(const FlatFilePos &pos);
-/** Get block file info entry for one block file */
-CBlockFileInfo *GetBlockFileInfo(size_t n);
-
-/** Calculate the amount of disk space the block & undo files currently use */
-uint64_t CalculateCurrentUsage();
-
/**
* Actually unlink the specified files
*/
@@ -168,14 +187,6 @@
bool ReadBlockFromDisk(CBlock &block, const CBlockIndex *pindex,
const Consensus::Params &consensusParams);
bool UndoReadFromDisk(CBlockUndo &blockundo, const CBlockIndex *pindex);
-bool WriteUndoDataForBlock(const CBlockUndo &blockundo,
- BlockValidationState &state, CBlockIndex *pindex,
- const CChainParams &chainparams);
-
-FlatFilePos SaveBlockToDisk(const CBlock &block, int nHeight,
- CChain &active_chain,
- const CChainParams &chainparams,
- const FlatFilePos *dbp);
void ThreadImport(const Config &config, ChainstateManager &chainman,
std::vector<fs::path> vImportFiles, const ArgsManager &args);
diff --git a/src/node/blockstorage.cpp b/src/node/blockstorage.cpp
--- a/src/node/blockstorage.cpp
+++ b/src/node/blockstorage.cpp
@@ -518,7 +518,7 @@
FormatISO8601DateTime(nTimeFirst), FormatISO8601DateTime(nTimeLast));
}
-CBlockFileInfo *GetBlockFileInfo(size_t n) {
+CBlockFileInfo *BlockManager::GetBlockFileInfo(size_t n) {
LOCK(cs_LastBlockFile);
return &vinfoBlockFile.at(n);
@@ -586,7 +586,7 @@
return true;
}
-static void FlushUndoFile(int block_file, bool finalize = false) {
+void BlockManager::FlushUndoFile(int block_file, bool finalize) {
FlatFilePos undo_pos_old(block_file, vinfoBlockFile[block_file].nUndoSize);
if (!UndoFileSeq().Flush(undo_pos_old, finalize)) {
AbortNode("Flushing undo file to disk failed. This is likely the "
@@ -594,7 +594,7 @@
}
}
-void FlushBlockFile(bool fFinalize = false, bool finalize_undo = false) {
+void BlockManager::FlushBlockFile(bool fFinalize, bool finalize_undo) {
LOCK(cs_LastBlockFile);
FlatFilePos block_pos_old(nLastBlockFile,
vinfoBlockFile[nLastBlockFile].nSize);
@@ -610,7 +610,7 @@
}
}
-uint64_t CalculateCurrentUsage() {
+uint64_t BlockManager::CalculateCurrentUsage() {
LOCK(cs_LastBlockFile);
uint64_t retval = 0;
@@ -655,8 +655,9 @@
return BlockFileSeq().FileName(pos);
}
-bool FindBlockPos(FlatFilePos &pos, unsigned int nAddSize, unsigned int nHeight,
- CChain &active_chain, uint64_t nTime, bool fKnown = false) {
+bool BlockManager::FindBlockPos(FlatFilePos &pos, unsigned int nAddSize,
+ unsigned int nHeight, CChain &active_chain,
+ uint64_t nTime, bool fKnown) {
LOCK(cs_LastBlockFile);
unsigned int nFile = fKnown ? pos.nFile : nLastBlockFile;
@@ -718,8 +719,8 @@
return true;
}
-static bool FindUndoPos(BlockValidationState &state, int nFile,
- FlatFilePos &pos, unsigned int nAddSize) {
+bool BlockManager::FindUndoPos(BlockValidationState &state, int nFile,
+ FlatFilePos &pos, unsigned int nAddSize) {
pos.nFile = nFile;
LOCK(cs_LastBlockFile);
@@ -766,9 +767,10 @@
return true;
}
-bool WriteUndoDataForBlock(const CBlockUndo &blockundo,
- BlockValidationState &state, CBlockIndex *pindex,
- const CChainParams &chainparams) {
+bool BlockManager::WriteUndoDataForBlock(const CBlockUndo &blockundo,
+ BlockValidationState &state,
+ CBlockIndex *pindex,
+ const CChainParams &chainparams) {
// Write undo information to disk
if (pindex->GetUndoPos().IsNull()) {
FlatFilePos _pos;
@@ -855,10 +857,10 @@
* Store block on disk. If dbp is non-nullptr, the file is known to already
* reside on disk.
*/
-FlatFilePos SaveBlockToDisk(const CBlock &block, int nHeight,
- CChain &active_chain,
- const CChainParams &chainparams,
- const FlatFilePos *dbp) {
+FlatFilePos BlockManager::SaveBlockToDisk(const CBlock &block, int nHeight,
+ CChain &active_chain,
+ const CChainParams &chainparams,
+ const FlatFilePos *dbp) {
unsigned int nBlockSize = ::GetSerializeSize(block, CLIENT_VERSION);
FlatFilePos blockPos;
if (dbp != nullptr) {
diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp
--- a/src/rpc/blockchain.cpp
+++ b/src/rpc/blockchain.cpp
@@ -1875,7 +1875,8 @@
obj.pushKV("initialblockdownload",
active_chainstate.IsInitialBlockDownload());
obj.pushKV("chainwork", tip->nChainWork.GetHex());
- obj.pushKV("size_on_disk", CalculateCurrentUsage());
+ obj.pushKV("size_on_disk",
+ chainman.m_blockman.CalculateCurrentUsage());
obj.pushKV("pruned", fPruneMode);
if (fPruneMode) {
diff --git a/src/validation.cpp b/src/validation.cpp
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -2166,7 +2166,7 @@
return true;
}
- if (!WriteUndoDataForBlock(blockundo, state, pindex, m_params)) {
+ if (!m_blockman.WriteUndoDataForBlock(blockundo, state, pindex, m_params)) {
return false;
}
@@ -2314,7 +2314,7 @@
// First make sure all block and undo data is flushed to
// disk.
- FlushBlockFile();
+ m_blockman.FlushBlockFile();
}
// Then update all block file information (which may refer to
// block and undo files).
@@ -4421,8 +4421,8 @@
*fNewBlock = true;
}
try {
- FlatFilePos blockPos =
- SaveBlockToDisk(block, pindex->nHeight, m_chain, m_params, dbp);
+ FlatFilePos blockPos{m_blockman.SaveBlockToDisk(
+ block, pindex->nHeight, m_chain, m_params, dbp)};
if (blockPos.IsNull()) {
state.Error(strprintf(
"%s: Failed to find position to write new block to disk",
@@ -4973,8 +4973,8 @@
try {
const CBlock &block = m_params.GenesisBlock();
- FlatFilePos blockPos =
- SaveBlockToDisk(block, 0, m_chain, m_params, nullptr);
+ FlatFilePos blockPos{
+ m_blockman.SaveBlockToDisk(block, 0, m_chain, m_params, nullptr)};
if (blockPos.IsNull()) {
return error("%s: writing genesis block to disk failed", __func__);
}
diff --git a/src/wallet/test/wallet_tests.cpp b/src/wallet/test/wallet_tests.cpp
--- a/src/wallet/test/wallet_tests.cpp
+++ b/src/wallet/test/wallet_tests.cpp
@@ -78,7 +78,9 @@
BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup) {
// Cap last block file size, and mine new block in a new block file.
CBlockIndex *oldTip = m_node.chainman->ActiveTip();
- GetBlockFileInfo(oldTip->GetBlockPos().nFile)->nSize = MAX_BLOCKFILE_SIZE;
+ WITH_LOCK(::cs_main, m_node.chainman->m_blockman
+ .GetBlockFileInfo(oldTip->GetBlockPos().nFile)
+ ->nSize = MAX_BLOCKFILE_SIZE);
CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey()));
CBlockIndex *newTip = m_node.chainman->ActiveTip();
@@ -192,7 +194,9 @@
BOOST_FIXTURE_TEST_CASE(importmulti_rescan, TestChain100Setup) {
// Cap last block file size, and mine new block in a new block file.
CBlockIndex *oldTip = m_node.chainman->ActiveTip();
- GetBlockFileInfo(oldTip->GetBlockPos().nFile)->nSize = MAX_BLOCKFILE_SIZE;
+ WITH_LOCK(::cs_main, m_node.chainman->m_blockman
+ .GetBlockFileInfo(oldTip->GetBlockPos().nFile)
+ ->nSize = MAX_BLOCKFILE_SIZE);
CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey()));
CBlockIndex *newTip = m_node.chainman->ActiveTip();
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, May 20, 22:07 (20 h, 40 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5863023
Default Alt Text
D12510.id36364.diff (9 KB)
Attached To
D12510: Move functions to BlockManager
Event Timeline
Log In to Comment