Skip to content

Commit 276e73a

Browse files
committed
update comments
1 parent 75c573a commit 276e73a

File tree

5 files changed

+15
-27
lines changed

5 files changed

+15
-27
lines changed

storage/epoch_protocol_state.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,11 @@ type EpochProtocolStateEntries interface {
3434
//
3535
// CAUTION:
3636
// - The caller must acquire the lock [storage.LockInsertBlock] and hold it until the database write has been committed.
37-
// - OVERWRITES existing data (potential for data corruption):
38-
// This method silently overrides existing data without any sanity checks whether data for the same key already exits.
39-
// Note that the Flow protocol mandates that for a previously persisted key, the data is never changed to a different
40-
// value. Changing data could cause the node to publish inconsistent data and to be slashed, or the protocol to be
41-
// compromised as a whole. This method does not contain any safeguards to prevent such data corruption. The lock proof
42-
// serves as a reminder that the CALLER is responsible to ensure that the DEDUPLICATION CHECK is done elsewhere
43-
// ATOMICALLY with this write operation.
37+
// - The lock proof serves as a reminder that the CALLER is responsible to ensure that the operation.InsertHeader is
38+
// done ATOMICALLY with this write operation.
4439
//
4540
// Expected errors during normal operations:
46-
// - [storage.ErrDataMismatch] if a _different_ KV store for the given stateID has already been persisted
41+
// - [storage.ErrAlreadyExists] if a KV store for the given blockID has already been indexed
4742
BatchIndex(lctx lockctx.Proof, rw ReaderBatchWriter, blockID flow.Identifier, epochProtocolStateID flow.Identifier) error
4843

4944
// ByID returns the flow.RichEpochStateEntry by its ID.

storage/operation/epoch_protocol_state.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,9 @@ func RetrieveEpochProtocolState(r storage.Reader, entryID flow.Identifier, entry
2828
// CAUTION:
2929
// - The caller must acquire the lock [storage.LockInsertBlock] and hold it until the database write has been committed.
3030
// - OVERWRITES existing data (potential for data corruption):
31-
// This method silently overrides existing data without any sanity checks whether data for the same key already exits.
32-
// Note that the Flow protocol mandates that for a previously persisted key, the data is never changed to a different
33-
// value. Changing data could cause the node to publish inconsistent data and to be slashed, or the protocol to be
34-
// compromised as a whole. This method does not contain any safeguards to prevent such data corruption. The lock proof
35-
// serves as a reminder that the CALLER is responsible to ensure that the DEDUPLICATION CHECK is done elsewhere
36-
// ATOMICALLY with this write operation.
31+
// The lock proof serves as a reminder that the CALLER is responsible to ensure that the DEDUPLICATION CHECK is done elsewhere
32+
// ATOMICALLY within this write operation. Currently it's done by operation.InsertHeader where it performs a check
33+
// to ensure the blockID is new, therefore any data indexed by this blockID is new as well.
3734
//
3835
// No error returns are expected during normal operation.
3936
func IndexEpochProtocolState(lctx lockctx.Proof, w storage.Writer, blockID flow.Identifier, epochProtocolStateEntryID flow.Identifier) error {

storage/operation/protocol_kv_store.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
1718
func 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

storage/store/proposal_signatures.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ func newProposalSignatures(collector module.CacheMetrics, db storage.DB) *propos
4747
// CAUTION:
4848
// - The caller must acquire either the lock [storage.LockInsertBlock] or [storage.LockInsertOrFinalizeClusterBlock]
4949
// but not both and hold the lock until the database write has been committed.
50-
// - OVERWRITES existing data (potential for data corruption):
51-
// The lock proof serves as a reminder that the CALLER is responsible to ensure that the DEDUPLICATION CHECK
50+
// - The lock proof serves as a reminder that the CALLER is responsible to ensure that the DEDUPLICATION CHECK
5251
// is done elsewhere ATOMICALLY with this write operation. It is intended that this function is called only for new
5352
// blocks, i.e. no signature was previously persisted for it.
5453
//

storage/store/protocol_kv_store.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,6 @@ func (s *ProtocolKVStore) BatchStore(rw storage.ReaderBatchWriter, stateID flow.
104104
//
105105
// CAUTION:
106106
// - The caller must acquire the lock [storage.LockInsertBlock] and hold it until the database write has been committed.
107-
// - OVERWRITES existing data (potential for data corruption):
108-
// This method silently overrides existing data without any sanity checks whether data for the same key already exits.
109-
// Note that the Flow protocol mandates that for a previously persisted key, the data is never changed to a different
110-
// value. Changing data could cause the node to publish inconsistent data and to be slashed, or the protocol to be
111-
// compromised as a whole. This method does not contain any safeguards to prevent such data corruption. The lock proof
112-
// serves as a reminder that the CALLER is responsible to ensure that the DEDUPLICATION CHECK is done elsewhere
113-
// ATOMICALLY with this write operation.
114107
//
115108
// Expected errors during normal operations:
116109
// - [storage.ErrAlreadyExist] if a KV store for the given blockID has already been indexed.

0 commit comments

Comments
 (0)