Skip to content

Commit a0e0d8d

Browse files
author
Alexander Hentschel
committed
documented storage abstraction storage.ResultApprovals
1 parent 914f353 commit a0e0d8d

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

storage/approvals.go

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,39 @@ import (
44
"github.com/onflow/flow-go/model/flow"
55
)
66

7+
// ResultApprovals implements persistent storage for result approvals.
8+
// Implementations of this interface must be concurrency safe.
9+
//
10+
// CAUTION suitable only for _Verification Nodes_ for persisting their _own_ approvals!
11+
// - In general, the Flow protocol requires multiple approvals for the same chunk from different
12+
// verification nodes. In other words, there are multiple different approvals for the same chunk.
13+
// - Internally, ResultApprovals populates an index from Executed Chunk ➜ ResultApproval. This is
14+
// *only safe* for Verification Nodes when tracking their own approvals (for the same ExecutionResult,
15+
// a Verifier will always produce the same approval)
716
type ResultApprovals interface {
817

9-
// Store stores a ResultApproval
18+
// Store stores a ResultApproval by its ID.
1019
Store(result *flow.ResultApproval) error
1120

12-
// Index indexes a ResultApproval by result ID and chunk index
21+
// Index indexes a ResultApproval by result ID and chunk index.
22+
//
23+
// CAUTION: the Flow protocol requires multiple approvals for the same chunk from different verification
24+
// nodes. In other words, there are multiple different approvals for the same chunk. Therefore, the index
25+
// Executed Chunk ➜ ResultApproval ID (populated here) is *only safe* to be used by Verification Nodes
26+
// for tracking their own approvals.
27+
//
28+
// For the same ExecutionResult, a Verifier will always produce the same approval. Therefore, this operation
29+
// is idempotent, i.e. repeated calls with the *same inputs* are equivalent to just calling the method once;
30+
// still the method succeeds on each call. However, when attempting to index *different* ResultApproval IDs
31+
// for the same key (resultID, chunkIndex) this method returns an exception, as this should never happen for
32+
// a correct Verification Node indexing its own approvals.
1333
Index(resultID flow.Identifier, chunkIndex uint64, approvalID flow.Identifier) error
1434

15-
// ByID retrieves a ResultApproval by its ID
35+
// ByID retrieves a ResultApproval by its ID.
36+
// Returns `storage.ErrNotFound` if no Approval with the given ID has been stored.
1637
ByID(approvalID flow.Identifier) (*flow.ResultApproval, error)
1738

18-
// ByChunk retrieves a ResultApproval by result ID and chunk index
39+
// ByChunk retrieves a ResultApproval by result ID and chunk index.
40+
// Returns `storage.ErrNotFound` if no Approval for the given key (resultID, chunkIndex) has been stored.
1941
ByChunk(resultID flow.Identifier, chunkIndex uint64) (*flow.ResultApproval, error)
2042
}

0 commit comments

Comments
 (0)