@@ -5,7 +5,16 @@ import (
55 "github.com/onflow/flow-go/model/flow"
66)
77
8- // Forks maintains an in-memory data-structure of all proposals whose view-number is larger or equal to
8+ // FinalityProof represents a finality proof for a Block. By convention, a FinalityProof
9+ // is immutable. Finality in Jolteon/HotStuff is determined by the 2-chain rule:
10+ //
11+ // There exists a _certified_ block C, such that Block.View + 1 = C.View
12+ type FinalityProof struct {
13+ Block * model.Block
14+ CertifiedChild model.CertifiedBlock
15+ }
16+
17+ // Forks maintains an in-memory data-structure of all blocks whose view-number is larger or equal to
918// the latest finalized block. The latest finalized block is defined as the finalized block with the largest view number.
1019// When adding blocks, Forks automatically updates its internal state (including finalized blocks).
1120// Furthermore, blocks whose view number is smaller than the latest finalized block are pruned automatically.
@@ -16,29 +25,71 @@ import (
1625// and ignore the block.
1726type Forks interface {
1827
19- // GetProposalsForView returns all BlockProposals at the given view number.
20- GetProposalsForView (view uint64 ) []* model.Proposal
28+ // GetBlocksForView returns all known blocks for the given view
29+ GetBlocksForView (view uint64 ) []* model.Block
2130
22- // GetProposal returns (BlockProposal, true) if the block with the specified
23- // id was found (nil, false) otherwise.
24- GetProposal ( id flow.Identifier ) (* model.Proposal , bool )
31+ // GetBlock returns (BlockProposal, true) if the block with the specified
32+ // id was found and (nil, false) otherwise.
33+ GetBlock ( blockID flow.Identifier ) (* model.Block , bool )
2534
2635 // FinalizedView returns the largest view number where a finalized block is known
2736 FinalizedView () uint64
2837
2938 // FinalizedBlock returns the finalized block with the largest view number
3039 FinalizedBlock () * model.Block
3140
32- // NewestView returns the largest view number of all proposals that were added to Forks.
33- NewestView () uint64
34-
35- // AddProposal adds the block proposal to Forks. This might cause an update of the finalized block
36- // and pruning of older blocks.
37- // Handles duplicated addition of blocks (at the potential cost of additional computation time).
38- // PREREQUISITE:
39- // Forks must be able to connect `proposal` to its latest finalized block
40- // (without missing interim ancestors). Otherwise, an exception is raised.
41- // Expected errors during normal operations:
42- // * model.ByzantineThresholdExceededError - new block results in conflicting finalized blocks
43- AddProposal (proposal * model.Proposal ) error
41+ // FinalityProof returns the latest finalized block and a certified child from
42+ // the subsequent view, which proves finality.
43+ // CAUTION: method returns (nil, false), when Forks has not yet finalized any
44+ // blocks beyond the finalized root block it was initialized with.
45+ FinalityProof () (* FinalityProof , bool )
46+
47+ // AddProposal appends the given block to the tree of pending
48+ // blocks and updates the latest finalized block (if applicable). Unless the parent is
49+ // below the pruning threshold (latest finalized view), we require that the parent is
50+ // already stored in Forks. Calling this method with previously processed blocks
51+ // leaves the consensus state invariant (though, it will potentially cause some
52+ // duplicate processing).
53+ // Notes:
54+ // - Method `AddCertifiedBlock(..)` should be used preferably, if a QC certifying
55+ // `block` is already known. This is generally the case for the consensus follower.
56+ // Method `AddProposal` is intended for active consensus participants, which fully
57+ // validate blocks (incl. payload), i.e. QCs are processed as part of validated proposals.
58+ //
59+ // Possible error returns:
60+ // - model.MissingBlockError if the parent does not exist in the forest (but is above
61+ // the pruned view). From the perspective of Forks, this error is benign (no-op).
62+ // - model.InvalidBlockError if the block is invalid (see `Forks.EnsureBlockIsValidExtension`
63+ // for details). From the perspective of Forks, this error is benign (no-op). However, we
64+ // assume all blocks are fully verified, i.e. they should satisfy all consistency
65+ // requirements. Hence, this error is likely an indicator of a bug in the compliance layer.
66+ // - model.ByzantineThresholdExceededError if conflicting QCs or conflicting finalized
67+ // blocks have been detected (violating a foundational consensus guarantees). This
68+ // indicates that there are 1/3+ Byzantine nodes (weighted by stake) in the network,
69+ // breaking the safety guarantees of HotStuff (or there is a critical bug / data
70+ // corruption). Forks cannot recover from this exception.
71+ // - All other errors are potential symptoms of bugs or state corruption.
72+ AddProposal (proposal * model.Block ) error
73+
74+ // AddCertifiedBlock appends the given certified block to the tree of pending
75+ // blocks and updates the latest finalized block (if finalization progressed).
76+ // Unless the parent is below the pruning threshold (latest finalized view), we
77+ // require that the parent is already stored in Forks. Calling this method with
78+ // previously processed blocks leaves the consensus state invariant (though,
79+ // it will potentially cause some duplicate processing).
80+ //
81+ // Possible error returns:
82+ // - model.MissingBlockError if the parent does not exist in the forest (but is above
83+ // the pruned view). From the perspective of Forks, this error is benign (no-op).
84+ // - model.InvalidBlockError if the block is invalid (see `Forks.EnsureBlockIsValidExtension`
85+ // for details). From the perspective of Forks, this error is benign (no-op). However, we
86+ // assume all blocks are fully verified, i.e. they should satisfy all consistency
87+ // requirements. Hence, this error is likely an indicator of a bug in the compliance layer.
88+ // - model.ByzantineThresholdExceededError if conflicting QCs or conflicting finalized
89+ // blocks have been detected (violating a foundational consensus guarantees). This
90+ // indicates that there are 1/3+ Byzantine nodes (weighted by stake) in the network,
91+ // breaking the safety guarantees of HotStuff (or there is a critical bug / data
92+ // corruption). Forks cannot recover from this exception.
93+ // - All other errors are potential symptoms of bugs or state corruption.
94+ AddCertifiedBlock (certifiedBlock * model.CertifiedBlock ) error
4495}
0 commit comments