Skip to content

Commit 7f58fad

Browse files
committed
clarified method naming
1 parent 272dc65 commit 7f58fad

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

storage/operation/headers.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func BlockExists(r storage.Reader, blockID flow.Identifier) (bool, error) {
124124
return KeyExists(r, MakePrefix(codeHeader, blockID))
125125
}
126126

127-
// IndexCollectionGuaranteeByBlock produces a mapping from collection ID to the block ID containing this collection.
127+
// IndexBlockContainingCollection produces a mapping from collection ID to the block ID containing this collection.
128128
//
129129
// CAUTION:
130130
// - The caller must acquire the lock ??? and hold it until the database write has been committed.
@@ -137,12 +137,21 @@ func BlockExists(r storage.Reader, blockID flow.Identifier) (bool, error) {
137137
//
138138
// Expected errors during normal operations:
139139
// TODO: return [storage.ErrAlreadyExists] or [storage.ErrDataMismatch]
140-
func IndexCollectionGuaranteeByBlock(w storage.Writer, collID flow.Identifier, blockID flow.Identifier) error {
140+
func IndexBlockContainingCollection(w storage.Writer, collID flow.Identifier, blockID flow.Identifier) error {
141141
return UpsertByKey(w, MakePrefix(codeCollectionBlock, collID), blockID)
142142
}
143143

144-
// LookupCollectionGuaranteeByBlock looks up a block by a collection within that block.
145-
func LookupCollectionGuaranteeByBlock(r storage.Reader, collID flow.Identifier, blockID *flow.Identifier) error {
144+
// LookupBlockContainingCollection retrieves the block containing the collection with the given ID.
145+
//
146+
// CAUTION: A collection can be included in multiple *unfinalized* blocks. However, the implementation
147+
// assumes a one-to-one map from collection ID to a *single* block ID. This holds for FINALIZED BLOCKS ONLY
148+
// *and* only in the ABSENCE of BYZANTINE collector CLUSTERS (which the mature protocol must tolerate).
149+
// Hence, this function should be treated as a temporary solution, which requires generalization
150+
// (one-to-many mapping) for soft finality and the mature protocol.
151+
//
152+
// Expected errors during normal operations:
153+
// - [storage.ErrNotFound] if no block is known that contains the specified collection ID.
154+
func LookupBlockContainingCollection(r storage.Reader, collID flow.Identifier, blockID *flow.Identifier) error {
146155
return RetrieveByKey(r, MakePrefix(codeCollectionBlock, collID), blockID)
147156
}
148157

storage/operation/headers_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ func TestHeaderIDIndexByCollectionID(t *testing.T) {
5555
collectionGuaranteeID := unittest.IdentifierFixture()
5656

5757
err := db.WithReaderBatchWriter(func(rw storage.ReaderBatchWriter) error {
58-
return operation.IndexCollectionGuaranteeByBlock(rw.Writer(), collectionGuaranteeID, headerID)
58+
return operation.IndexBlockContainingCollection(rw.Writer(), collectionGuaranteeID, headerID)
5959
})
6060
require.NoError(t, err)
6161

6262
actualID := &flow.Identifier{}
63-
err = operation.LookupCollectionGuaranteeByBlock(db.Reader(), collectionGuaranteeID, actualID)
63+
err = operation.LookupBlockContainingCollection(db.Reader(), collectionGuaranteeID, actualID)
6464
require.NoError(t, err)
6565
assert.Equal(t, headerID, *actualID)
6666
})

storage/store/blocks.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ func (b *Blocks) ByCollectionID(collID flow.Identifier) (*flow.Block, error) {
196196
return nil, fmt.Errorf("could not look up guarantee: %w", err)
197197
}
198198
var blockID flow.Identifier
199-
err = operation.LookupCollectionGuaranteeByBlock(b.db.Reader(), guarantee.ID(), &blockID)
199+
err = operation.LookupBlockContainingCollection(b.db.Reader(), guarantee.ID(), &blockID)
200200
if err != nil {
201201
return nil, fmt.Errorf("could not look up block: %w", err)
202202
}
@@ -216,7 +216,7 @@ func (b *Blocks) ByCollectionID(collID flow.Identifier) (*flow.Block, error) {
216216
func (b *Blocks) IndexBlockForCollectionGuarantees(blockID flow.Identifier, guaranteeIDs []flow.Identifier) error {
217217
return b.db.WithReaderBatchWriter(func(rw storage.ReaderBatchWriter) error {
218218
for _, guaranteeID := range guaranteeIDs {
219-
err := operation.IndexCollectionGuaranteeByBlock(rw.Writer(), guaranteeID, blockID)
219+
err := operation.IndexBlockContainingCollection(rw.Writer(), guaranteeID, blockID)
220220
if err != nil {
221221
return fmt.Errorf("could not index collection block (%x): %w", guaranteeID, err)
222222
}

0 commit comments

Comments
 (0)