Skip to content

Commit 629da34

Browse files
committed
storrage.ChunkDataPacks API update
1 parent fe66dd9 commit 629da34

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

storage/chunk_data_packs.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,20 @@ type ChunkDataPacks interface {
2121
// chunk data pack (or it will get slashed). This mapping from chunk ID to the ID of the chunk data pack that the Execution Node
2222
// actually committed to is stored in the protocol database, in the following phase 2.
2323
// - In the second phase, we populate the index mappings from ChunkID to one "distinguished" chunk data pack ID. This mapping
24-
// is stored in the protocol database. Typically, en Execution Node uses this for indexing its own chunk data packs which it
24+
// is stored in the protocol database. Typically, an Execution Node uses this for indexing its own chunk data packs which it
2525
// publicly committed to.
26-
// - This function can approximately be described as an atomic operation. When it completes successfully, either both databases
27-
// have been updated, or neither. However, this is an approximation only, because interim states exist, where the chunk data
28-
// packs already have been stored in the chunk data pack database, but the index mappings do not yet exist.
26+
//
27+
// ATOMICITY:
28+
// [ChunkDataPacks.Store] executes phase 1 immediately, persisting the chunk data packs in their dedicated database. However,
29+
// the index mappings in phase 2 is deferred to the caller, who must invoke the returned functor to perform phase 2. This
30+
// approach has the following benefits:
31+
// - Our API reflects that we are writing to two different databases here, with the chunk data pack database containing largely
32+
// specialized data subject to pruning. In contrast, the protocol database persists the commitments a node make (subject to
33+
// slashing). The caller receives the ability to persist this commitment in the form of the returned functor. The functor
34+
// may be discarded by the caller without corrupting the state (if anything, we have just stored some additional chunk data
35+
// packs).
36+
// - The serialization and storage of the comparatively large chunk data packs is separated from the protocol database writes.
37+
// - The locking duration of the protocol database is reduced.
2938
//
3039
// The Store method returns:
3140
// - func(lctx lockctx.Proof, rw storage.ReaderBatchWriter) error: Function for populating the index mapping from chunkID

storage/store/chunk_data_packs.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,20 @@ func NewChunkDataPacks(collector module.CacheMetrics, db storage.DB, stored stor
9595
// chunk data pack (or it will get slashed). This mapping from chunk ID to the ID of the chunk data pack that the Execution Node
9696
// actually committed to is stored in the protocol database, in the following phase 2.
9797
// - In the second phase, we populate the index mappings from ChunkID to one "distinguished" chunk data pack ID. This mapping
98-
// is stored in the protocol database. Typically, en Execution Node uses this for indexing its own chunk data packs which it
98+
// is stored in the protocol database. Typically, an Execution Node uses this for indexing its own chunk data packs which it
9999
// publicly committed to.
100-
// - This function can approximately be described as an atomic operation. When it completes successfully, either both databases
101-
// have been updated, or neither. However, this is an approximation only, because interim states exist, where the chunk data
102-
// packs already have been stored in the chunk data pack database, but the index mappings do not yet exist.
100+
//
101+
// ATOMICITY:
102+
// [ChunkDataPacks.Store] executes phase 1 immediately, persisting the chunk data packs in their dedicated database. However,
103+
// the index mappings in phase 2 is deferred to the caller, who must invoke the returned functor to perform phase 2. This
104+
// approach has the following benefits:
105+
// - Our API reflects that we are writing to two different databases here, with the chunk data pack database containing largely
106+
// specialized data subject to pruning. In contrast, the protocol database persists the commitments a node make (subject to
107+
// slashing). The caller receives the ability to persist this commitment in the form of the returned functor. The functor
108+
// may be discarded by the caller without corrupting the state (if anything, we have just stored some additional chunk data
109+
// packs).
110+
// - The serialization and storage of the comparatively large chunk data packs is separated from the protocol database writes.
111+
// - The locking duration of the protocol database is reduced.
103112
//
104113
// The Store method returns:
105114
// - func(lctx lockctx.Proof, rw storage.ReaderBatchWriter) error: Function for populating the index mapping from chunkID
@@ -157,7 +166,8 @@ func (ch *ChunkDataPacks) Store(cs []*flow.ChunkDataPack) (
157166
return nil
158167
}
159168

160-
// Return the function that completes the storage process
169+
// Returned Functor: when invoked, will add the deferred storage operations to the provided ReaderBatchWriter
170+
// NOTE: until this functor is called, only the chunk data packs are stored by their respective IDs.
161171
return storeChunkDataPacksFunc, nil
162172
}
163173

0 commit comments

Comments
 (0)