forked from ava-labs/avalanchego
-
Notifications
You must be signed in to change notification settings - Fork 4
/
consensus.go
63 lines (49 loc) · 1.89 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
// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package snowman
import (
"context"
"time"
"github.com/MetalBlockchain/metalgo/api/health"
"github.com/MetalBlockchain/metalgo/ids"
"github.com/MetalBlockchain/metalgo/snow"
"github.com/MetalBlockchain/metalgo/snow/consensus/snowball"
"github.com/MetalBlockchain/metalgo/utils/bag"
)
// Consensus represents a general snowman instance that can be used directly to
// process a series of dependent operations.
type Consensus interface {
health.Checker
// Takes in the context, snowball parameters, and the last accepted block.
Initialize(
ctx *snow.ConsensusContext,
params snowball.Parameters,
lastAcceptedID ids.ID,
lastAcceptedHeight uint64,
lastAcceptedTime time.Time,
) error
// Returns the number of blocks processing
NumProcessing() int
// Adds a new decision. Assumes the dependency has already been added.
// Returns if a critical error has occurred.
Add(context.Context, Block) error
// Decided returns true if the block has been decided.
Decided(Block) bool
// Processing returns true if the block ID is currently processing.
Processing(ids.ID) bool
// IsPreferred returns true if the block is currently on the preferred
// chain.
IsPreferred(Block) bool
// Returns the ID and height of the last accepted decision.
LastAccepted() (ids.ID, uint64)
// Returns the ID of the tail of the strongly preferred sequence of
// decisions.
Preference() ids.ID
// Returns the ID of the strongly preferred decision with the provided
// height. Only the last accepted decision and processing decisions are
// tracked.
PreferenceAtHeight(height uint64) (ids.ID, bool)
// RecordPoll collects the results of a network poll. Assumes all decisions
// have been previously added. Returns if a critical error has occurred.
RecordPoll(context.Context, bag.Bag[ids.ID]) error
}