Skip to content

Commit 30d95ee

Browse files
committed
commend cleanup and removal of bloating white spaces
1 parent f53da97 commit 30d95ee

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

storage/procedure/children.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111
"github.com/onflow/flow-go/storage/operation"
1212
)
1313

14-
// IndexNewBlock and IndexNewClusterBlock will add parent-child index for the new block.
15-
// - Each block has a parent, we use this parent-child relationship to build a reverse index
14+
// IndexNewBlock will add parent-child index for the new block.
15+
// - Each block that we ingest has a parent, we use this parent-child relationship to build a reverse index
1616
// for looking up children blocks for a given block. This is useful for forks recovery
1717
// where we want to find all the pending children blocks for the lastest finalized block.
1818
//
@@ -33,6 +33,20 @@ func IndexNewBlock(lctx lockctx.Proof, rw storage.ReaderBatchWriter, blockID flo
3333
return insertNewBlock(lctx, rw, blockID, parentID)
3434
}
3535

36+
// IndexNewClusterBlock will add parent-child index for the new block.
37+
// - Each block that we ingest has a parent, we use this parent-child relationship to build a reverse index
38+
// for looking up children blocks for a given block. This is useful for forks recovery
39+
// where we want to find all the pending children blocks for the lastest finalized block.
40+
//
41+
// When adding parent-child index for a new block, we will update two indexes:
42+
// 1. Per protocol convention, blocks must be ingested in "ancestors-first" order. Hence,
43+
// if a block is new (needs to be verified, to avoid state corruption in case of repeated
44+
// calls), its set of persisted children is empty at the time of insertion.
45+
// 2. Since the parent block has this new block as a child, we add to the parent block's children.
46+
// There are two special cases for (2):
47+
// - If the parent block is zero (i.e. genesis block), then we don't need to add this index.
48+
// - If the parent block doesn't exist, then we will index the new block as the only child
49+
// of the parent anyway. This is useful for bootstrapping nodes with truncated history.
3650
func IndexNewClusterBlock(lctx lockctx.Proof, rw storage.ReaderBatchWriter, blockID flow.Identifier, parentID flow.Identifier) error {
3751
if !lctx.HoldsLock(storage.LockInsertOrFinalizeClusterBlock) {
3852
return fmt.Errorf("missing required lock: %s", storage.LockInsertOrFinalizeClusterBlock)

storage/procedure/cluster.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@ func InsertClusterBlock(lctx lockctx.Proof, rw storage.ReaderBatchWriter, propos
5858
return fmt.Errorf("could not insert proposer signature: %w", err)
5959
}
6060

61-
// since InsertHeader already checks for duplicates, we can safely
62-
// assume that the block header is new and there is no existing index
63-
// for other data related to this block ID.
64-
6561
// insert the block payload
6662
err = InsertClusterPayload(lctx, rw, blockID, &proposal.Block.Payload)
6763
if err != nil {
@@ -102,7 +98,6 @@ func RetrieveClusterBlock(r storage.Reader, blockID flow.Identifier, block *clus
10298
if err != nil {
10399
return fmt.Errorf("could not build cluster block: %w", err)
104100
}
105-
106101
*block = *newBlock
107102

108103
return nil
@@ -212,7 +207,7 @@ func InsertClusterPayload(lctx lockctx.Proof, rw storage.ReaderBatchWriter, bloc
212207
// Here, we persist a reduced representation of the collection, only listing the constituent transactions by their hashes.
213208
light := payload.Collection.Light()
214209
writer := rw.Writer()
215-
err = operation.UpsertCollection(writer, light) // keyed by content hash so no lock needed
210+
err = operation.UpsertCollection(writer, light) // collection is keyed by content hash, hence no overwrite protection is needed
216211
if err != nil {
217212
return fmt.Errorf("could not insert payload collection: %w", err)
218213
}
@@ -285,7 +280,6 @@ func RetrieveClusterPayload(r storage.Reader, blockID flow.Identifier, payload *
285280
if err != nil {
286281
return fmt.Errorf("could not build the payload: %w", err)
287282
}
288-
289283
*payload = *newPayload
290284

291285
return nil

0 commit comments

Comments
 (0)