github.com/MetalBlockchain/metalgo@v1.11.9/snow/consensus/snowball/nnary_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 (
     7  	"fmt"
     8  
     9  	"github.com/MetalBlockchain/metalgo/ids"
    10  )
    11  
    12  func newNnarySlush(choice ids.ID) nnarySlush {
    13  	return nnarySlush{
    14  		preference: choice,
    15  	}
    16  }
    17  
    18  // nnarySlush is the implementation of a slush instance with an unbounded number
    19  // of choices
    20  type nnarySlush struct {
    21  	// preference is the choice that last had a successful poll. Unless there
    22  	// hasn't been a successful poll, in which case it is the initially provided
    23  	// choice.
    24  	preference ids.ID
    25  }
    26  
    27  func (sl *nnarySlush) Preference() ids.ID {
    28  	return sl.preference
    29  }
    30  
    31  func (sl *nnarySlush) RecordSuccessfulPoll(choice ids.ID) {
    32  	sl.preference = choice
    33  }
    34  
    35  func (sl *nnarySlush) String() string {
    36  	return fmt.Sprintf("SL(Preference = %s)", sl.preference)
    37  }