@@ -11,7 +11,8 @@ import (
1111)
1212
1313// InsertProtocolKVStore inserts a protocol KV store by protocol kv store ID.
14- // The caller must ensure the protocolKVStoreID is the hash of the given kvStore,
14+ // This function can be called, and does not require the caller to hold any lock proof,
15+ // but the caller must ensure the protocolKVStoreID is the hash of the given kvStore,
1516// This is currently true, see makeVersionedModelID in state/protocol/protocol_state/kvstore/models.go
1617// No expected error returns during normal operations.
1718func InsertProtocolKVStore (rw storage.ReaderBatchWriter , protocolKVStoreID flow.Identifier , kvStore * flow.PSKeyValueStoreData ) error {
@@ -27,9 +28,12 @@ func RetrieveProtocolKVStore(r storage.Reader, protocolKVStoreID flow.Identifier
2728
2829// IndexProtocolKVStore indexes a protocol KV store by block ID.
2930//
30- // CAUTION: To prevent data corruption, we need to guarantee atomicity of existence-check and the subsequent
31- // database write. Hence, we require the caller to acquire [storage.LockInsertBlock] and hold it until the
32- // database write has been committed.
31+ // CAUTION:
32+ // - The caller must acquire the lock [storage.LockInsertBlock] and hold it until the database write has been committed.
33+ // - OVERWRITES existing data (potential for data corruption):
34+ // The lock proof serves as a reminder that the CALLER is responsible to ensure that the DEDUPLICATION CHECK is done elsewhere
35+ // ATOMICALLY within this write operation. Currently it's done by operation.InsertHeader where it performs a check
36+ // to ensure the blockID is new, therefore any data indexed by this blockID is new as well.
3337//
3438// Expected error returns during normal operations:
3539// - [storage.ErrAlreadyExists] if a KV store for the given blockID has already been indexed
0 commit comments