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

Method SaveBlockToDisk

src/node/blockstorage.cpp:837–855  ·  view source on GitHub ↗

Store block on disk. If dbp is non-nullptr, the file is known to already reside on disk */

Source from the content-addressed store, hash-verified

835
836/** Store block on disk. If dbp is non-nullptr, the file is known to already reside on disk */
837FlatFilePos 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
857struct CImportingNow {
858 CImportingNow()

Callers 2

AcceptBlockMethod · 0.80
LoadGenesisBlockMethod · 0.80

Calls 6

GetSerializeSizeFunction · 0.85
errorFunction · 0.85
WriteBlockToDiskFunction · 0.85
FlatFilePosClass · 0.70
AbortNodeFunction · 0.50
GetBlockTimeMethod · 0.45

Tested by

no test coverage detected