-
Notifications
You must be signed in to change notification settings - Fork 177
/
epochs.go
61 lines (52 loc) · 2.77 KB
/
epochs.go
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
package module
import (
"context"
"github.com/onflow/flow-go/consensus/hotstuff/model"
"github.com/onflow/flow-go/state/protocol"
)
// ClusterRootQCVoter is responsible for submitting a vote to the cluster QC
// contract to coordinate generation of a valid root quorum certificate for the
// next epoch.
type ClusterRootQCVoter interface {
// Vote handles the full procedure of generating a vote, submitting it to the epoch
// smart contract, and verifying submission. It is safe to run Vote multiple
// times within a single setup phase.
// Error returns:
// - epochs.ClusterQCNoVoteError if we fail to vote for a benign reason
// - generic error in case of critical unexpected failure
Vote(context.Context, protocol.Epoch) error
}
// QCContractClient enables interacting with the cluster QC aggregator smart
// contract. This contract is deployed to the service account as part of a
// collection of smart contracts that facilitate and manage epoch transitions.
type QCContractClient interface {
// SubmitVote submits the given vote to the cluster QC aggregator smart
// contract. This function returns only once the transaction has been
// processed by the network. An error is returned if the transaction has
// failed and should be re-submitted.
// Error returns:
// - network.TransientError for any errors from the underlying client, if the retry period has been exceeded
// - errTransactionExpired if the transaction has expired
// - errTransactionReverted if the transaction execution reverted
// - generic error in case of unexpected critical failure
SubmitVote(ctx context.Context, vote *model.Vote) error
// Voted returns true if we have successfully submitted a vote to the
// cluster QC aggregator smart contract for the current epoch.
// Error returns:
// - network.TransientError for any errors from the underlying Flow client
// - generic error in case of unexpected critical failures
Voted(ctx context.Context) (bool, error)
}
// EpochLookup enables looking up epochs by view.
// CAUTION: EpochLookup should only be used for querying the previous, current, or next epoch.
type EpochLookup interface {
// EpochForViewWithFallback returns the counter of the epoch that the input view belongs to.
// If epoch fallback has been triggered, returns the last committed epoch counter
// in perpetuity for any inputs beyond the last committed epoch view range.
// For example, if we trigger epoch fallback during epoch 10, and reach the final
// view of epoch 10 before epoch 11 has finished being setup, this function will
// return 10 even for input views beyond the final view of epoch 10.
//
// Returns model.ErrViewForUnknownEpoch if the input does not fall within the range of a known epoch.
EpochForViewWithFallback(view uint64) (epochCounter uint64, err error)
}