-
Notifications
You must be signed in to change notification settings - Fork 662
/
convincer.go
46 lines (38 loc) · 1.08 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
// Copyright (C) 2019-2021, 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/consensus/avalanche"
"github.com/ava-labs/avalanchego/snow/engine/common"
"github.com/ava-labs/avalanchego/utils/wrappers"
)
// convincer sends chits to [vdr] after its dependencies are met.
type convincer struct {
consensus avalanche.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
c.sender.SendChits(c.vdr, c.requestID, c.consensus.Preferences().List())
}