@@ -10,10 +10,10 @@ import (
1010 "github.com/onflow/flow-go/storage"
1111)
1212
13- // IndexNewBlock indexes a new block and updates the parent-child relationship in the block children index.
14- // This function creates an empty children index for the new block and adds the new block to the parent's children list.
13+ // IndexNewBlock populates the parent-child index for block, by adding the given blockID to the set of children of its parent.
1514//
1615// CAUTION:
16+ // - This function should only be used for KNOWN BLOCKs (neither existence of the block nor its parent is verified here)
1717// - The caller must acquire the [storage.LockInsertBlock] and hold it until the database write has been committed.
1818//
1919// Expected error returns during normal operations:
@@ -26,10 +26,11 @@ func IndexNewBlock(lctx lockctx.Proof, rw storage.ReaderBatchWriter, blockID flo
2626 return indexBlockByParent (rw , blockID , parentID )
2727}
2828
29- // IndexNewClusterBlock indexes a new cluster block and updates the parent-child relationship in the block children index.
30- // This function creates an empty children index for the new cluster block and adds the new block to the parent's children list .
29+ // IndexNewClusterBlock populates the parent-child index for cluster blocks, aka collections, by adding the given
30+ // blockID to the set of children of its parent.
3131//
3232// CAUTION:
33+ // - This function should only be used for KNOWN BLOCKs (neither existence of the block nor its parent is verified here)
3334// - The caller must acquire the [storage.LockInsertOrFinalizeClusterBlock] and hold it until the database write has been committed.
3435//
3536// Expected error returns during normal operations:
@@ -57,18 +58,15 @@ func indexBlockByParent(rw storage.ReaderBatchWriter, blockID flow.Identifier, p
5758 storage .ErrAlreadyExists )
5859 }
5960
60- // Step 2: adding the second index for the parent block
61- // if the parent block is zero, for instance root block has no parent,
62- // then no need to add index for it
63- // useful to skip for cluster root block which has no parent
61+ // By convention, the parentID being [flow.ZeroID] means that the block has no parent.
62+ // This is the case for genesis blocks and cluster root blocks. In this case, there
63+ // is no parent, whose child we can index.
6464 if parentID == flow .ZeroID {
6565 return nil
6666 }
6767
68- // if the parent block is not zero, depending on whether the parent block has
69- // children or not, we will either update the index or insert the index:
70- // when parent block doesn't exist, we will insert the block children.
71- // when parent block exists already, we will update the block children,
68+ // If the parent block is not zero, depending on whether the parent block has
69+ // children or not, we will either update the index or insert the index.
7270 var childrenIDs flow.IdentifierList
7371 err = RetrieveBlockChildren (rw .GlobalReader (), parentID , & childrenIDs )
7472 if err != nil {
@@ -98,7 +96,7 @@ func indexBlockByParent(rw storage.ReaderBatchWriter, blockID flow.Identifier, p
9896
9997// RetrieveBlockChildren retrieves the list of child block IDs for the specified parent block.
10098//
101- // Expected errors during normal operations:
99+ // No error returns expected during normal operations.
102100// It returns [storage.ErrNotFound] if the block has no children.
103101// Note, this would mean either the block does not exist or the block exists but has no children.
104102// The caller has to check if the block exists by other means if needed.
0 commit comments