| 625 | } |
| 626 | |
| 627 | bool 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 | |
| 682 | bool BlockManager::FindUndoPos(BlockValidationState& state, int nFile, FlatFilePos& pos, unsigned int nAddSize) |
| 683 | { |
nothing calls this directly
no test coverage detected