github.com/MetalBlockchain/metalgo@v1.11.9/snow/consensus/snowball/flat.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  	"github.com/MetalBlockchain/metalgo/ids"
     8  	"github.com/MetalBlockchain/metalgo/utils/bag"
     9  )
    10  
    11  var _ Consensus = (*Flat)(nil)
    12  
    13  func NewFlat(factory Factory, params Parameters, choice ids.ID) Consensus {
    14  	return &Flat{
    15  		Nnary:  factory.NewNnary(params, choice),
    16  		params: params,
    17  	}
    18  }
    19  
    20  // Flat is a naive implementation of a multi-choice snow instance
    21  type Flat struct {
    22  	// wraps the n-nary snow logic
    23  	Nnary
    24  
    25  	// params contains all the configurations of a snow instance
    26  	params Parameters
    27  }
    28  
    29  func (f *Flat) RecordPoll(votes bag.Bag[ids.ID]) bool {
    30  	pollMode, numVotes := votes.Mode()
    31  	f.Nnary.RecordPoll(numVotes, pollMode)
    32  	return numVotes >= f.params.AlphaPreference
    33  }