-
Notifications
You must be signed in to change notification settings - Fork 660
/
flat.go
44 lines (33 loc) · 1.02 KB
/
flat.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
// Copyright (C) 2019-2022, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package snowball
import (
"github.com/ava-labs/avalanchego/ids"
)
var (
_ Factory = &FlatFactory{}
_ Consensus = &Flat{}
)
// FlatFactory implements Factory by returning a flat struct
type FlatFactory struct{}
func (FlatFactory) New() Consensus { return &Flat{} }
// Flat is a naive implementation of a multi-choice snowball instance
type Flat struct {
// wraps the n-nary snowball logic
nnarySnowball
// params contains all the configurations of a snowball instance
params Parameters
}
func (f *Flat) Initialize(params Parameters, choice ids.ID) {
f.nnarySnowball.Initialize(params.BetaVirtuous, params.BetaRogue, choice)
f.params = params
}
func (f *Flat) Parameters() Parameters { return f.params }
func (f *Flat) RecordPoll(votes ids.Bag) bool {
if pollMode, numVotes := votes.Mode(); numVotes >= f.params.Alpha {
f.RecordSuccessfulPoll(pollMode)
return true
}
f.RecordUnsuccessfulPoll()
return false
}