gecko/snow/consensus/snowball/unary_snowball.go

51 lines
1.2 KiB
Go
Raw Normal View History

2020-03-10 12:20:34 -07:00
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package snowball
import (
"fmt"
)
// unarySnowball is the implementation of a unary snowball instance
type unarySnowball struct {
// wrap the unary snowflake logic
unarySnowflake
2020-03-10 12:20:34 -07:00
// numSuccessfulPolls tracks the total number of successful network polls
numSuccessfulPolls int
}
// RecordSuccessfulPoll implements the UnarySnowball interface
func (sb *unarySnowball) RecordSuccessfulPoll() {
sb.numSuccessfulPolls++
sb.unarySnowflake.RecordSuccessfulPoll()
2020-03-10 12:20:34 -07:00
}
// Extend implements the UnarySnowball interface
func (sb *unarySnowball) Extend(beta int, choice int) BinarySnowball {
bs := &binarySnowball{
binarySnowflake: binarySnowflake{
binarySlush: binarySlush{preference: choice},
2020-06-16 11:17:47 -07:00
confidence: sb.confidence,
beta: beta,
finalized: sb.Finalized(),
2020-03-10 12:20:34 -07:00
},
preference: choice,
2020-03-10 12:20:34 -07:00
}
2020-03-10 13:10:53 -07:00
bs.numSuccessfulPolls[choice] = sb.numSuccessfulPolls
2020-03-10 12:20:34 -07:00
return bs
}
// Clone implements the UnarySnowball interface
func (sb *unarySnowball) Clone() UnarySnowball {
newSnowball := *sb
return &newSnowball
2020-03-10 12:20:34 -07:00
}
func (sb *unarySnowball) String() string {
return fmt.Sprintf("SB(NumSuccessfulPolls = %d, %s)",
2020-03-10 12:20:34 -07:00
sb.numSuccessfulPolls,
&sb.unarySnowflake)
2020-03-10 12:20:34 -07:00
}