-
Notifications
You must be signed in to change notification settings - Fork 669
/
consensus.go
77 lines (60 loc) · 2.91 KB
/
consensus.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright (C) 2019-2022, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package avalanche
import (
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow"
"github.com/ava-labs/avalanchego/snow/consensus/snowstorm"
)
// TODO: Implement pruning of accepted decisions.
// To perfectly preserve the protocol, this implementation will need to store
// the hashes of all accepted decisions. It is possible to add a heuristic that
// removes sufficiently old decisions. However, that will need to be analyzed to
// ensure safety. It is doable with a weak syncrony assumption.
// Consensus represents a general avalanche instance that can be used directly
// to process a series of partially ordered elements.
type Consensus interface {
// Takes in alpha, beta1, beta2, the accepted frontier, the join statuses,
// the mutation statuses, and the consumer statuses. If accept or reject is
// called, the status maps should be immediately updated accordingly.
// Assumes each element in the accepted frontier will return accepted from
// the join status map.
Initialize(*snow.ConsensusContext, Parameters, []Vertex) error
// Returns the parameters that describe this avalanche instance
Parameters() Parameters
// Returns the number of vertices processing
NumProcessing() int
// Returns true if the transaction is virtuous.
// That is, no transaction has been added that conflicts with it
IsVirtuous(snowstorm.Tx) bool
// Adds a new decision. Assumes the dependencies have already been added.
// Assumes that mutations don't conflict with themselves. Returns if a
// critical error has occurred.
Add(Vertex) error
// VertexIssued returns true iff Vertex has been added
VertexIssued(Vertex) bool
// TxIssued returns true if a vertex containing this transaction has been added
TxIssued(snowstorm.Tx) bool
// Returns the set of transaction IDs that are virtuous but not contained in
// any preferred vertices.
Orphans() ids.Set
// Returns a set of vertex IDs that were virtuous at the last update.
Virtuous() ids.Set
// Returns a set of vertex IDs that are preferred
Preferences() ids.Set
// RecordPoll collects the results of a network poll. If a result has not
// been added, the result is dropped. Returns if a critical error has
// occurred.
RecordPoll(ids.UniqueBag) error
// Quiesce is guaranteed to return true if the instance is finalized. It
// may, but doesn't need to, return true if all processing vertices are
// rogue. It must return false if there is a virtuous vertex that is still
// processing.
Quiesce() bool
// Finalized returns true if all transactions that have been added have been
// finalized. Note, it is possible that after returning finalized, a new
// decision may be added such that this instance is no longer finalized.
Finalized() bool
// HealthCheck returns information about the consensus health.
HealthCheck() (interface{}, error)
}