-
Notifications
You must be signed in to change notification settings - Fork 670
/
snowman_block.go
58 lines (47 loc) · 1.57 KB
/
snowman_block.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
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package snowman
import (
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow/choices"
"github.com/ava-labs/avalanchego/snow/consensus/snowball"
)
// Tracks the state of a snowman block
type snowmanBlock struct {
// pointer to the snowman instance this node is managed by
sm Consensus
// block that this node contains. For the genesis, this value will be nil
blk Block
// shouldFalter is set to true if this node, and all its descendants received
// less than Alpha votes
shouldFalter bool
// sb is the snowball instance used to decided which child is the canonical
// child of this block. If this node has not had a child issued under it,
// this value will be nil
sb snowball.Consensus
// children is the set of blocks that have been issued that name this block
// as their parent. If this node has not had a child issued under it, this value
// will be nil
children map[ids.ID]Block
}
func (n *snowmanBlock) AddChild(child Block) {
childID := child.ID()
// if the snowball instance is nil, this is the first child. So the instance
// should be initialized.
if n.sb == nil {
n.sb = &snowball.Tree{}
n.sb.Initialize(n.sm.Parameters(), childID)
n.children = make(map[ids.ID]Block)
} else {
n.sb.Add(childID)
}
n.children[childID] = child
}
func (n *snowmanBlock) Accepted() bool {
// if the block is nil, then this is the genesis which is defined as
// accepted
if n.blk == nil {
return true
}
return n.blk.Status() == choices.Accepted
}