MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / SaveBlockToDisk

Function SaveBlockToDisk

src/validation.cpp:3680–3696  ·  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

3678
3679/** Store block on disk. If dbp is non-nullptr, the file is known to already reside on disk */
3680static CDiskBlockPos SaveBlockToDisk(const CBlock& block, int nHeight, const CChainParams& chainparams, const CDiskBlockPos* dbp) {
3681 unsigned int nBlockSize = ::GetSerializeSize(block, SER_DISK, CLIENT_VERSION);
3682 CDiskBlockPos blockPos;
3683 if (dbp != nullptr)
3684 blockPos = *dbp;
3685 if (!FindBlockPos(blockPos, nBlockSize+8, nHeight, block.GetBlockTime(), dbp != nullptr)) {
3686 error("%s: FindBlockPos failed", __func__);
3687 return CDiskBlockPos();
3688 }
3689 if (dbp == nullptr) {
3690 if (!WriteBlockToDisk(block, blockPos, chainparams.MessageStart())) {
3691 AbortNode("Failed to write block");
3692 return CDiskBlockPos();
3693 }
3694 }
3695 return blockPos;
3696}
3697
3698/** Store block on disk. If dbp is non-nullptr, the file is known to already reside on disk */
3699bool CChainState::AcceptBlock(const std::shared_ptr<const CBlock>& pblock, CValidationState& state, const CChainParams& chainparams, CBlockIndex** ppindex, bool fRequested, const CDiskBlockPos* dbp, bool* fNewBlock)

Callers 2

AcceptBlockMethod · 0.85
LoadGenesisBlockMethod · 0.85

Calls 7

GetSerializeSizeFunction · 0.85
FindBlockPosFunction · 0.85
errorFunction · 0.85
CDiskBlockPosClass · 0.85
WriteBlockToDiskFunction · 0.85
AbortNodeFunction · 0.85
GetBlockTimeMethod · 0.45

Tested by

no test coverage detected