Skip to content

Commit

Permalink
doc: Improve doc for functions involved in saving blocks to disk
Browse files Browse the repository at this point in the history
In particular, document the flat file positions expected and
returned by functions better.

Co-authored-by: Ryan Ofsky <ryan@ofsky.org>
  • Loading branch information
mzumsande and ryanofsky committed May 10, 2024
1 parent 0d114e3 commit f90098e
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/node/blockstorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ class BlockManager
/** Return false if undo file flushing fails. */
[[nodiscard]] bool FlushUndoFile(int block_file, bool finalize = false);

/**
* The nAddSize argument passed to this function should include not just the size of the serialized CBlock, but the also size of
* separator fields which are written before it by WriteBlockToDisk (BLOCK_SERIALIZATION_HEADER_SIZE).
*/
[[nodiscard]] bool FindBlockPos(FlatFilePos& pos, unsigned int nAddSize, unsigned int nHeight, uint64_t nTime, bool fKnown);
[[nodiscard]] bool FlushChainstateBlockFile(int tip_height);
bool FindUndoPos(BlockValidationState& state, int nFile, FlatFilePos& pos, unsigned int nAddSize);
Expand All @@ -164,6 +168,12 @@ class BlockManager

AutoFile OpenUndoFile(const FlatFilePos& pos, bool fReadOnly = false) const;

/**
* Write a block to disk. The pos argument passed to this function is modified by this call. Before this call, it should
* point to an unused file location where separator fields will be written followed by the serialized CBlock data.
* After this call, it will point to the beginning of the serialized CBlock data, after the separator fields
* (BLOCK_SERIALIZATION_HEADER_SIZE)
*/
bool WriteBlockToDisk(const CBlock& block, FlatFilePos& pos) const;
bool UndoWriteToDisk(const CBlockUndo& blockundo, FlatFilePos& pos, const uint256& hashBlock) const;

Expand Down Expand Up @@ -312,7 +322,17 @@ class BlockManager
bool WriteUndoDataForBlock(const CBlockUndo& blockundo, BlockValidationState& state, CBlockIndex& block)
EXCLUSIVE_LOCKS_REQUIRED(::cs_main);

/** Store block on disk. If dbp is not nullptr, then it provides the known position of the block within a block file on disk. */
/** Store block on disk and update block file statistics.
* During reindex, only the block file statistics is updated.
* In that case, dbp is not nullptr and provides the known position of the block within a block file on disk.
*
* @param[in] block the block to be stored
* @param[in] nHeight the height of the block
*
* @returns in case of success, the position to which the block was written to
* in case of an error, an empty FlatFilePos
*/

FlatFilePos SaveBlockToDisk(const CBlock& block, int nHeight, const FlatFilePos* dbp);

/** Whether running in -prune mode. */
Expand Down

0 comments on commit f90098e

Please sign in to comment.