-
Notifications
You must be signed in to change notification settings - Fork 661
/
convincer.go
49 lines (41 loc) · 1.18 KB
/
convincer.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
// Copyright (C) 2019-2021, 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/consensus/snowman"
"github.com/ava-labs/avalanchego/snow/engine/common"
"github.com/ava-labs/avalanchego/utils/wrappers"
)
// convincer sends chits to [vdr] once all its dependencies are met
type convincer struct {
consensus snowman.Consensus
sender common.Sender
vdr ids.NodeID
requestID uint32
sent bool
abandoned bool
deps ids.Set
errs *wrappers.Errs
}
func (c *convincer) Dependencies() ids.Set { return c.deps }
// Mark that a dependency has been met
func (c *convincer) Fulfill(id ids.ID) {
c.deps.Remove(id)
c.Update()
}
// Abandon this attempt to send chits.
func (c *convincer) Abandon(ids.ID) {
c.abandoned = true
c.Update()
}
func (c *convincer) Update() {
if c.sent || c.errs.Errored() || (!c.abandoned && c.deps.Len() != 0) {
return
}
c.sent = true
// TODO: once everyone supports ChitsV2 - we should be sending that message
// type here.
pref := []ids.ID{c.consensus.Preference()}
c.sender.SendChits(c.vdr, c.requestID, pref)
}