@@ -53,10 +53,6 @@ bool CBlockIndexHeightOnlyComparator::operator()(const CBlockIndex* pa, const CB
53
53
return pa->nHeight < pb->nHeight ;
54
54
}
55
55
56
- static FILE* OpenUndoFile (const FlatFilePos& pos, bool fReadOnly = false );
57
- static FlatFileSeq BlockFileSeq ();
58
- static FlatFileSeq UndoFileSeq ();
59
-
60
56
std::vector<CBlockIndex*> BlockManager::GetAllBlockIndices ()
61
57
{
62
58
AssertLockHeld (cs_main);
@@ -423,7 +419,7 @@ const CBlockIndex* BlockManager::GetFirstStoredBlock(const CBlockIndex& start_bl
423
419
// rev files since they'll be rewritten by the reindex anyway. This ensures that m_blockfile_info
424
420
// is in sync with what's actually on disk by the time we start downloading, so that pruning
425
421
// works correctly.
426
- void CleanupBlockRevFiles ()
422
+ void BlockManager:: CleanupBlockRevFiles () const
427
423
{
428
424
std::map<std::string, fs::path> mapBlockFiles;
429
425
@@ -467,7 +463,7 @@ CBlockFileInfo* BlockManager::GetBlockFileInfo(size_t n)
467
463
return &m_blockfile_info.at (n);
468
464
}
469
465
470
- static bool UndoWriteToDisk (const CBlockUndo& blockundo, FlatFilePos& pos, const uint256& hashBlock, const CMessageHeader::MessageStartChars& messageStart)
466
+ bool BlockManager:: UndoWriteToDisk (const CBlockUndo& blockundo, FlatFilePos& pos, const uint256& hashBlock, const CMessageHeader::MessageStartChars& messageStart) const
471
467
{
472
468
// Open history file to append
473
469
AutoFile fileout{OpenUndoFile (pos)};
@@ -496,9 +492,9 @@ static bool UndoWriteToDisk(const CBlockUndo& blockundo, FlatFilePos& pos, const
496
492
return true ;
497
493
}
498
494
499
- bool UndoReadFromDisk (CBlockUndo& blockundo, const CBlockIndex* pindex)
495
+ bool BlockManager:: UndoReadFromDisk (CBlockUndo& blockundo, const CBlockIndex& index) const
500
496
{
501
- const FlatFilePos pos{WITH_LOCK (::cs_main, return pindex-> GetUndoPos ())};
497
+ const FlatFilePos pos{WITH_LOCK (::cs_main, return index. GetUndoPos ())};
502
498
503
499
if (pos.IsNull ()) {
504
500
return error (" %s: no undo data available" , __func__);
@@ -514,7 +510,7 @@ bool UndoReadFromDisk(CBlockUndo& blockundo, const CBlockIndex* pindex)
514
510
uint256 hashChecksum;
515
511
HashVerifier verifier{filein}; // Use HashVerifier as reserializing may lose data, c.f. commit d342424301013ec47dc146a4beb49d5c9319d80a
516
512
try {
517
- verifier << pindex-> pprev ->GetBlockHash ();
513
+ verifier << index. pprev ->GetBlockHash ();
518
514
verifier >> blockundo;
519
515
filein >> hashChecksum;
520
516
} catch (const std::exception& e) {
@@ -570,7 +566,7 @@ uint64_t BlockManager::CalculateCurrentUsage()
570
566
return retval;
571
567
}
572
568
573
- void UnlinkPrunedFiles (const std::set<int >& setFilesToPrune)
569
+ void BlockManager:: UnlinkPrunedFiles (const std::set<int >& setFilesToPrune) const
574
570
{
575
571
std::error_code ec;
576
572
for (std::set<int >::iterator it = setFilesToPrune.begin (); it != setFilesToPrune.end (); ++it) {
@@ -583,28 +579,28 @@ void UnlinkPrunedFiles(const std::set<int>& setFilesToPrune)
583
579
}
584
580
}
585
581
586
- static FlatFileSeq BlockFileSeq ()
582
+ FlatFileSeq BlockManager:: BlockFileSeq () const
587
583
{
588
584
return FlatFileSeq (gArgs .GetBlocksDirPath (), " blk" , gArgs .GetBoolArg (" -fastprune" , false ) ? 0x4000 /* 16kb */ : BLOCKFILE_CHUNK_SIZE);
589
585
}
590
586
591
- static FlatFileSeq UndoFileSeq ()
587
+ FlatFileSeq BlockManager:: UndoFileSeq () const
592
588
{
593
589
return FlatFileSeq (gArgs .GetBlocksDirPath (), " rev" , UNDOFILE_CHUNK_SIZE);
594
590
}
595
591
596
- FILE* OpenBlockFile (const FlatFilePos& pos, bool fReadOnly )
592
+ FILE* BlockManager:: OpenBlockFile (const FlatFilePos& pos, bool fReadOnly ) const
597
593
{
598
594
return BlockFileSeq ().Open (pos, fReadOnly );
599
595
}
600
596
601
597
/* * Open an undo file (rev?????.dat) */
602
- static FILE* OpenUndoFile (const FlatFilePos& pos, bool fReadOnly )
598
+ FILE* BlockManager:: OpenUndoFile (const FlatFilePos& pos, bool fReadOnly ) const
603
599
{
604
600
return UndoFileSeq ().Open (pos, fReadOnly );
605
601
}
606
602
607
- fs::path GetBlockPosFilename (const FlatFilePos& pos)
603
+ fs::path BlockManager:: GetBlockPosFilename (const FlatFilePos& pos) const
608
604
{
609
605
return BlockFileSeq ().FileName (pos);
610
606
}
@@ -697,7 +693,7 @@ bool BlockManager::FindUndoPos(BlockValidationState& state, int nFile, FlatFileP
697
693
return true ;
698
694
}
699
695
700
- static bool WriteBlockToDisk (const CBlock& block, FlatFilePos& pos, const CMessageHeader::MessageStartChars& messageStart)
696
+ bool BlockManager:: WriteBlockToDisk (const CBlock& block, FlatFilePos& pos, const CMessageHeader::MessageStartChars& messageStart) const
701
697
{
702
698
// Open history file to append
703
699
CAutoFile fileout (OpenBlockFile (pos), SER_DISK, CLIENT_VERSION);
@@ -750,7 +746,7 @@ bool BlockManager::WriteUndoDataForBlock(const CBlockUndo& blockundo, BlockValid
750
746
return true ;
751
747
}
752
748
753
- bool ReadBlockFromDisk (CBlock& block, const FlatFilePos& pos, const Consensus::Params& consensusParams)
749
+ bool BlockManager:: ReadBlockFromDisk (CBlock& block, const FlatFilePos& pos) const
754
750
{
755
751
block.SetNull ();
756
752
@@ -768,33 +764,33 @@ bool ReadBlockFromDisk(CBlock& block, const FlatFilePos& pos, const Consensus::P
768
764
}
769
765
770
766
// Check the header
771
- if (!CheckProofOfWork (block.GetHash (), block.nBits , consensusParams )) {
767
+ if (!CheckProofOfWork (block.GetHash (), block.nBits , GetConsensus () )) {
772
768
return error (" ReadBlockFromDisk: Errors in block header at %s" , pos.ToString ());
773
769
}
774
770
775
771
// Signet only: check block solution
776
- if (consensusParams .signet_blocks && !CheckSignetBlockSolution (block, consensusParams )) {
772
+ if (GetConsensus () .signet_blocks && !CheckSignetBlockSolution (block, GetConsensus () )) {
777
773
return error (" ReadBlockFromDisk: Errors in block solution at %s" , pos.ToString ());
778
774
}
779
775
780
776
return true ;
781
777
}
782
778
783
- bool ReadBlockFromDisk (CBlock& block, const CBlockIndex* pindex, const Consensus::Params& consensusParams)
779
+ bool BlockManager:: ReadBlockFromDisk (CBlock& block, const CBlockIndex& index) const
784
780
{
785
- const FlatFilePos block_pos{WITH_LOCK (cs_main, return pindex-> GetBlockPos ())};
781
+ const FlatFilePos block_pos{WITH_LOCK (cs_main, return index. GetBlockPos ())};
786
782
787
- if (!ReadBlockFromDisk (block, block_pos, consensusParams )) {
783
+ if (!ReadBlockFromDisk (block, block_pos)) {
788
784
return false ;
789
785
}
790
- if (block.GetHash () != pindex-> GetBlockHash ()) {
786
+ if (block.GetHash () != index. GetBlockHash ()) {
791
787
return error (" ReadBlockFromDisk(CBlock&, CBlockIndex*): GetHash() doesn't match index for %s at %s" ,
792
- pindex-> ToString (), block_pos.ToString ());
788
+ index. ToString (), block_pos.ToString ());
793
789
}
794
790
return true ;
795
791
}
796
792
797
- bool ReadRawBlockFromDisk (std::vector<uint8_t >& block, const FlatFilePos& pos, const CMessageHeader::MessageStartChars& message_start)
793
+ bool BlockManager:: ReadRawBlockFromDisk (std::vector<uint8_t >& block, const FlatFilePos& pos, const CMessageHeader::MessageStartChars& message_start) const
798
794
{
799
795
FlatFilePos hpos = pos;
800
796
hpos.nPos -= 8 ; // Seek back 8 bytes for meta header
@@ -888,10 +884,10 @@ void ThreadImport(ChainstateManager& chainman, std::vector<fs::path> vImportFile
888
884
std::multimap<uint256, FlatFilePos> blocks_with_unknown_parent;
889
885
while (true ) {
890
886
FlatFilePos pos (nFile, 0 );
891
- if (!fs::exists (GetBlockPosFilename (pos))) {
887
+ if (!fs::exists (chainman. m_blockman . GetBlockPosFilename (pos))) {
892
888
break ; // No block files left to reindex
893
889
}
894
- FILE* file = OpenBlockFile (pos, true );
890
+ FILE* file = chainman. m_blockman . OpenBlockFile (pos, true );
895
891
if (!file) {
896
892
break ; // This error is logged in OpenBlockFile
897
893
}
0 commit comments