MCPcopy Create free account
hub / github.com/ElementsProject/elements / FindBlockPos

Method FindBlockPos

src/node/blockstorage.cpp:627–680  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

625}
626
627bool BlockManager::FindBlockPos(FlatFilePos& pos, unsigned int nAddSize, unsigned int nHeight, CChain& active_chain, uint64_t nTime, bool fKnown)
628{
629 LOCK(cs_LastBlockFile);
630
631 unsigned int nFile = fKnown ? pos.nFile : m_last_blockfile;
632 if (m_blockfile_info.size() <= nFile) {
633 m_blockfile_info.resize(nFile + 1);
634 }
635
636 bool finalize_undo = false;
637 if (!fKnown) {
638 while (m_blockfile_info[nFile].nSize + nAddSize >= (gArgs.GetBoolArg("-fastprune", false) ? 0x10000 /* 64kb */ : MAX_BLOCKFILE_SIZE)) {
639 // when the undo file is keeping up with the block file, we want to flush it explicitly
640 // when it is lagging behind (more blocks arrive than are being connected), we let the
641 // undo block write case handle it
642 finalize_undo = (m_blockfile_info[nFile].nHeightLast == (unsigned int)active_chain.Tip()->nHeight);
643 nFile++;
644 if (m_blockfile_info.size() <= nFile) {
645 m_blockfile_info.resize(nFile + 1);
646 }
647 }
648 pos.nFile = nFile;
649 pos.nPos = m_blockfile_info[nFile].nSize;
650 }
651
652 if ((int)nFile != m_last_blockfile) {
653 if (!fKnown) {
654 LogPrint(BCLog::BLOCKSTORE, "Leaving block file %i: %s\n", m_last_blockfile, m_blockfile_info[m_last_blockfile].ToString());
655 }
656 FlushBlockFile(!fKnown, finalize_undo);
657 m_last_blockfile = nFile;
658 }
659
660 m_blockfile_info[nFile].AddBlock(nHeight, nTime);
661 if (fKnown) {
662 m_blockfile_info[nFile].nSize = std::max(pos.nPos + nAddSize, m_blockfile_info[nFile].nSize);
663 } else {
664 m_blockfile_info[nFile].nSize += nAddSize;
665 }
666
667 if (!fKnown) {
668 bool out_of_space;
669 size_t bytes_allocated = BlockFileSeq().Allocate(pos, nAddSize, out_of_space);
670 if (out_of_space) {
671 return AbortNode("Disk space is too low!", _("Disk space is too low!"));
672 }
673 if (bytes_allocated != 0 && fPruneMode) {
674 m_check_for_pruning = true;
675 }
676 }
677
678 m_dirty_fileinfo.insert(nFile);
679 return true;
680}
681
682bool BlockManager::FindUndoPos(BlockValidationState& state, int nFile, FlatFilePos& pos, unsigned int nAddSize)
683{

Callers

nothing calls this directly

Calls 11

BlockFileSeqFunction · 0.85
_Function · 0.85
GetBoolArgMethod · 0.80
AddBlockMethod · 0.80
AbortNodeFunction · 0.50
sizeMethod · 0.45
resizeMethod · 0.45
TipMethod · 0.45
ToStringMethod · 0.45
AllocateMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected