forked from ava-labs/avalanchego
-
Notifications
You must be signed in to change notification settings - Fork 3
/
nnary_slush.go
39 lines (30 loc) · 887 Bytes
/
nnary_slush.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
// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package snowball
import (
"fmt"
"github.com/MetalBlockchain/metalgo/ids"
)
var _ NnarySlush = (*nnarySlush)(nil)
func newNnarySlush(choice ids.ID) nnarySlush {
return nnarySlush{
preference: choice,
}
}
// nnarySlush is the implementation of a slush instance with an unbounded number
// of choices
type nnarySlush struct {
// preference is the choice that last had a successful poll. Unless there
// hasn't been a successful poll, in which case it is the initially provided
// choice.
preference ids.ID
}
func (sl *nnarySlush) Preference() ids.ID {
return sl.preference
}
func (sl *nnarySlush) RecordSuccessfulPoll(choice ids.ID) {
sl.preference = choice
}
func (sl *nnarySlush) String() string {
return fmt.Sprintf("SL(Preference = %s)", sl.preference)
}