-
Notifications
You must be signed in to change notification settings - Fork 206
Expand file tree
/
Copy pathepoch_protocol_state.go
More file actions
64 lines (57 loc) · 3.81 KB
/
epoch_protocol_state.go
File metadata and controls
64 lines (57 loc) · 3.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package storage
import (
"github.com/jordanschalm/lockctx"
"github.com/onflow/flow-go/model/flow"
)
// EpochProtocolStateEntries represents persistent, fork-aware storage for the Epoch-related
// sub-state of the overall of the overall Protocol State (KV Store).
type EpochProtocolStateEntries interface {
// BatchStore persists the given epoch protocol state entry as part of a DB batch. Per convention, the identities in
// the flow.MinEpochStateEntry must be in canonical order for the current and next epoch (if present), otherwise an
// exception is returned.
//
// CAUTION: The caller must ensure `epochProtocolStateID` is a collision-resistant hash of the provided
// `epochProtocolStateEntry`! This method silently overrides existing data, which is safe only if for the same
// key, we always write the same value.
//
// No errors are expected during normal operation.
BatchStore(w Writer, epochProtocolStateID flow.Identifier, epochProtocolStateEntry *flow.MinEpochStateEntry) error
// BatchIndex persists the specific map entry in the node's database.
// In a nutshell, we want to maintain a map from `blockID` to `epochStateEntry`, where `blockID` references the
// block that _proposes_ the referenced epoch protocol state entry.
// Protocol convention:
// - Consider block B, whose ingestion might potentially lead to an updated protocol state. For example,
// the protocol state changes if we seal some execution results emitting service events.
// - For the key `blockID`, we use the identity of block B which _proposes_ this Protocol State. As value,
// the hash of the resulting protocol state at the end of processing B is to be used.
// - IMPORTANT: The protocol state requires confirmation by a QC and will only become active at the child block,
// _after_ validating the QC.
//
// CAUTION:
// - The caller must acquire the lock [storage.LockInsertBlock] and hold it until the database write has been committed.
// - OVERWRITES existing data (potential for data corruption):
// The lock proof serves as a reminder that the CALLER is responsible to ensure that the DEDUPLICATION CHECK is done elsewhere
// ATOMICALLY within this write operation. Currently it's done by operation.InsertHeader where it performs a check
// to ensure the blockID is new, therefore any data indexed by this blockID is new as well.
//
// Expected errors during normal operations:
// No expected errors during normal operations.
BatchIndex(lctx lockctx.Proof, rw ReaderBatchWriter, blockID flow.Identifier, epochProtocolStateID flow.Identifier) error
// ByID returns the flow.RichEpochStateEntry by its ID.
// Expected errors during normal operations:
// - storage.ErrNotFound if no epoch state entry with the given Identifier is known.
ByID(id flow.Identifier) (*flow.RichEpochStateEntry, error)
// ByBlockID retrieves the flow.RichEpochStateEntry that the block with the given ID proposes.
// CAUTION: this protocol state requires confirmation by a QC and will only become active at the child block,
// _after_ validating the QC. Protocol convention:
// - Consider block B, whose ingestion might potentially lead to an updated protocol state. For example,
// the protocol state changes if we seal some execution results emitting service events.
// - For the key `blockID`, we use the identity of block B which _proposes_ this Protocol State. As value,
// the hash of the resulting protocol state at the end of processing B is to be used.
// - CAUTION: The protocol state requires confirmation by a QC and will only become active at the child block,
// _after_ validating the QC.
//
// Expected errors during normal operations:
// - storage.ErrNotFound if no epoch state entry has been indexed for the given block.
ByBlockID(blockID flow.Identifier) (*flow.RichEpochStateEntry, error)
}