Skip to content

Commit c59b4de

Browse files
committed
minor struct goDocs
1 parent 5a83763 commit c59b4de

File tree

6 files changed

+36
-13
lines changed

6 files changed

+36
-13
lines changed

engine/execution/state/state.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,12 @@ func (s *state) saveExecutionResults(
413413
return fmt.Errorf("can not retrieve chunk data packs: %w", err)
414414
}
415415

416+
// Within the following `Store` call, the chunk data packs themselves are going to be persisted into their
417+
// dedicated database. However, we have not yet persisted that this execution node is committing to the
418+
// result represented by the chunk data packs. Populating the index from chunk ID to chunk data pack ID
419+
// in the protocol database (signifying the node's slashable commitment to the respective result) is
420+
// done by the functor returned by `Store`. The functor's is invoked as part of the atomic batch update
421+
// of the protocol database below.
416422
storeFunc, err := s.chunkDataPacks.Store(chunks)
417423
if err != nil {
418424
return fmt.Errorf("can not store chunk data packs for block ID: %v: %w", blockID, err)
@@ -427,9 +433,11 @@ func (s *state) saveExecutionResults(
427433
// This design guarantees consistency in two scenarios:
428434
//
429435
// Case 1: If the batch update is interrupted, the mapping has not yet been saved.
430-
// Later, if we attempt to store another execution result that references a
431-
// different chunk data pack but the same chunk ID, there is no conflict,
432-
// because no previous mapping exists.
436+
// Later, if we attempt to store another execution result that references a different
437+
// chunk data pack but the same chunk ID, there is no conflict, because no previous mapping
438+
// exists. By convention, a node should only share information once it has persisted its
439+
// commitment in the database. Therefore, if the database write was interrupted, none of the
440+
// information is stored and no binding commitment to a different result could have been made.
433441
//
434442
// Case 2: If the batch update succeeds, the mapping is saved. Later, if we
435443
// attempt to store another execution result that references a different
@@ -484,7 +492,6 @@ func (s *state) saveExecutionResults(
484492
return nil
485493
})
486494
})
487-
488495
}
489496

490497
func (s *state) UpdateLastExecutedBlock(ctx context.Context, executedID flow.Identifier) error {

model/flow/chunk.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ func (ch *Chunk) ID() Identifier {
129129
return MakeID(ch)
130130
}
131131

132+
// ChunkDataPackHeader is a reduced representation of ChunkDataPack. In a nutshell, we substitute
133+
// the larger [ChunkDataPack.Proof] and [ChunkDataPack.Collection] with their collision-resistant hashes.
134+
// Note, ChunkDataPackHeader.ID() is the same as ChunkDataPack.ID().
135+
//
136+
//structwrite:immutable - mutations allowed only within the constructor
132137
type ChunkDataPackHeader struct {
133138
ChunkID Identifier // ID of the chunk this data pack is for
134139
StartState StateCommitment // commitment for starting state
@@ -141,6 +146,8 @@ type ChunkDataPackHeader struct {
141146
ExecutionDataRoot BlockExecutionDataRoot
142147
}
143148

149+
// NewChunkDataPackHeader instantiates an "immutable" ChunkDataPackHeader.
150+
// The `CollectionID` field is set to [flow.ZeroID] for system chunks.
144151
func NewChunkDataPackHeader(ChunkID Identifier, StartState StateCommitment, ProofID Identifier, CollectionID Identifier, ExecutionDataRoot BlockExecutionDataRoot) *ChunkDataPackHeader {
145152
return &ChunkDataPackHeader{
146153
ChunkID: ChunkID,
@@ -197,8 +204,9 @@ type ChunkDataPack struct {
197204
// a trusted ChunkDataPack using NewChunkDataPack constructor.
198205
type UntrustedChunkDataPack ChunkDataPack
199206

200-
// NewChunkDataPack returns an initialized chunk data pack.
201-
// Construction ChunkDataPack allowed only within the constructor.
207+
// FromUntrustedChunkDataPack converts a chunk data pack from an untrusted source
208+
// into its canonical representation. Here, basic structural validation is performed.
209+
// Construction of ChunkDataPacks is ONLY allowed via THIS CONSTRUCTOR.
202210
//
203211
// All errors indicate a valid ChunkDataPack cannot be constructed from the input.
204212
func FromUntrustedChunkDataPack(untrusted UntrustedChunkDataPack) (*ChunkDataPack, error) {
@@ -231,6 +239,8 @@ func FromUntrustedChunkDataPack(untrusted UntrustedChunkDataPack) (*ChunkDataPac
231239
), nil
232240
}
233241

242+
// NewChunkDataPack instantiates an "immutable" ChunkDataPack.
243+
// The `collection` field is set to `nil` for system chunks.
234244
func NewChunkDataPack(chunkID Identifier, startState StateCommitment, proof StorageProof, collection *Collection, executionDataRoot BlockExecutionDataRoot) *ChunkDataPack {
235245
return &ChunkDataPack{
236246
ChunkID: chunkID,

storage/chunk_data_packs_stored.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ type StoredChunkDataPacks interface {
2929
BatchRemove(chunkDataPackIDs []flow.Identifier, rw ReaderBatchWriter) error
3030
}
3131

32-
// StoredChunkDataPack is an in-storage representation of chunk data pack.
33-
// Its prime difference is instead of an actual collection, it keeps a collection ID hence relying on maintaining
34-
// the collection on a secondary storage.
32+
// StoredChunkDataPack is an in-storage representation of chunk data pack. Its prime difference is instead of an
33+
// actual collection, it keeps a collection ID hence relying on maintaining the collection on a secondary storage.
34+
// Note, StoredChunkDataPack.ID() is the same as ChunkDataPack.ID()
3535
//
3636
//structwrite:immutable - mutations allowed only within the constructor
3737
type StoredChunkDataPack struct {
@@ -42,6 +42,8 @@ type StoredChunkDataPack struct {
4242
ExecutionDataRoot flow.BlockExecutionDataRoot
4343
}
4444

45+
// NewStoredChunkDataPack instantiates an "immutable" [StoredChunkDataPack].
46+
// The `collectionID` field is set to [flow.ZeroID] for system chunks.
4547
func NewStoredChunkDataPack(
4648
chunkID flow.Identifier,
4749
startState flow.StateCommitment,
@@ -63,6 +65,8 @@ func (s *StoredChunkDataPack) IsSystemChunk() bool {
6365
return s.CollectionID == flow.ZeroID
6466
}
6567

68+
// ToStoredChunkDataPack converts the given Chunk Data Pack to its reduced representation.
69+
// (Collections are stored separately and don't need to be included again here).
6670
func ToStoredChunkDataPack(c *flow.ChunkDataPack) *StoredChunkDataPack {
6771
collectionID := flow.ZeroID
6872
if c.Collection != nil {
@@ -78,8 +82,7 @@ func ToStoredChunkDataPack(c *flow.ChunkDataPack) *StoredChunkDataPack {
7882
}
7983

8084
// ToStoredChunkDataPacks converts the given Chunk Data Packs to their reduced representation.
81-
// This is useful for reducing storage consumption, by avoiding repeated storage of the full collections
82-
// (stored individually anyway).
85+
// (Collections are stored separately and don't need to be included again here).
8386
func ToStoredChunkDataPacks(cs []*flow.ChunkDataPack) []*StoredChunkDataPack {
8487
scs := make([]*StoredChunkDataPack, 0, len(cs))
8588
for _, c := range cs {

storage/store/chunk_data_packs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ func (ch *ChunkDataPacks) ByChunkID(chunkID flow.Identifier) (*flow.ChunkDataPac
271271
return nil, fmt.Errorf("cannot retrieve stored chunk data pack %x for chunk %x: %w", chunkDataPackID, chunkID, err)
272272
}
273273

274-
var collection *flow.Collection
274+
var collection *flow.Collection // nil by default, which only represents system chunk
275275
if schdp.CollectionID != flow.ZeroID {
276276
collection, err = ch.collections.ByID(schdp.CollectionID)
277277
if err != nil {

storage/store/chunk_data_packs_stored.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import (
1010
"github.com/onflow/flow-go/storage/operation"
1111
)
1212

13+
// StoredChunkDataPacks represents persistent storage for chunk data packs.
14+
// It works with the reduced representation `StoredChunkDataPack` for chunk data packs,
15+
// where instead of the full collection data, only the collection's hash (ID) is contained.
1316
type StoredChunkDataPacks struct {
1417
db storage.DB
1518
byIDCache *Cache[flow.Identifier, *storage.StoredChunkDataPack]

storage/store/chunk_data_packs_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func TestChunkDataPacks_Store(t *testing.T) {
4141
require.Equal(t, chunkDataPack, stored, "mismatched chunk data pack at index %d", i)
4242
}
4343

44-
// Store again is idemopotent
44+
// Store again is idempotent
4545
storeFunc, err = chunkDataPackStore.Store(chunkDataPacks)
4646
if err != nil {
4747
return err

0 commit comments

Comments
 (0)