github.com/koko1123/flow-go-1@v0.29.6/consensus/vote_aggregator.go (about)

     1  package consensus
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/gammazero/workerpool"
     7  	"github.com/rs/zerolog"
     8  
     9  	"github.com/koko1123/flow-go-1/consensus/hotstuff"
    10  	"github.com/koko1123/flow-go-1/consensus/hotstuff/notifications/pubsub"
    11  	"github.com/koko1123/flow-go-1/consensus/hotstuff/voteaggregator"
    12  	"github.com/koko1123/flow-go-1/consensus/hotstuff/votecollector"
    13  )
    14  
    15  // NewVoteAggregator creates new VoteAggregator and recover the Forks' state with all pending block
    16  func NewVoteAggregator(
    17  	log zerolog.Logger,
    18  	lowestRetainedView uint64,
    19  	notifier hotstuff.Consumer,
    20  	voteProcessorFactory hotstuff.VoteProcessorFactory,
    21  	distributor *pubsub.FinalizationDistributor,
    22  ) (hotstuff.VoteAggregator, error) {
    23  
    24  	createCollectorFactoryMethod := votecollector.NewStateMachineFactory(log, notifier, voteProcessorFactory.Create)
    25  	voteCollectors := voteaggregator.NewVoteCollectors(log, lowestRetainedView, workerpool.New(4), createCollectorFactoryMethod)
    26  
    27  	// initialize the vote aggregator
    28  	aggregator, err := voteaggregator.NewVoteAggregator(log, notifier, lowestRetainedView, voteCollectors)
    29  	if err != nil {
    30  		return nil, fmt.Errorf("could not create vote aggregator: %w", err)
    31  	}
    32  	distributor.AddOnBlockFinalizedConsumer(aggregator.OnFinalizedBlock)
    33  
    34  	return aggregator, nil
    35  }