@@ -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