Store block on disk. If dbp is non-nullptr, the file is known to already reside on disk */
| 835 | |
| 836 | /** Store block on disk. If dbp is non-nullptr, the file is known to already reside on disk */ |
| 837 | FlatFilePos BlockManager::SaveBlockToDisk(const CBlock& block, int nHeight, CChain& active_chain, const CChainParams& chainparams, const FlatFilePos* dbp) |
| 838 | { |
| 839 | unsigned int nBlockSize = ::GetSerializeSize(block, CLIENT_VERSION); |
| 840 | FlatFilePos blockPos; |
| 841 | if (dbp != nullptr) { |
| 842 | blockPos = *dbp; |
| 843 | } |
| 844 | if (!FindBlockPos(blockPos, nBlockSize + 8, nHeight, active_chain, block.GetBlockTime(), dbp != nullptr)) { |
| 845 | error("%s: FindBlockPos failed", __func__); |
| 846 | return FlatFilePos(); |
| 847 | } |
| 848 | if (dbp == nullptr) { |
| 849 | if (!WriteBlockToDisk(block, blockPos, chainparams.MessageStart())) { |
| 850 | AbortNode("Failed to write block"); |
| 851 | return FlatFilePos(); |
| 852 | } |
| 853 | } |
| 854 | return blockPos; |
| 855 | } |
| 856 | |
| 857 | struct CImportingNow { |
| 858 | CImportingNow() |
no test coverage detected