github.com/MetalBlockchain/metalgo@v1.11.9/snow/consensus/snowball/binary_slush.go (about) 1 // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package snowball 5 6 import "fmt" 7 8 func newBinarySlush(choice int) binarySlush { 9 return binarySlush{ 10 preference: choice, 11 } 12 } 13 14 // binarySlush is the implementation of a binary slush instance 15 type binarySlush struct { 16 // preference is the choice that last had a successful poll. Unless there 17 // hasn't been a successful poll, in which case it is the initially provided 18 // choice. 19 preference int 20 } 21 22 func (sl *binarySlush) Preference() int { 23 return sl.preference 24 } 25 26 func (sl *binarySlush) RecordSuccessfulPoll(choice int) { 27 sl.preference = choice 28 } 29 30 func (sl *binarySlush) String() string { 31 return fmt.Sprintf("SL(Preference = %d)", sl.preference) 32 }