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

     1  package hotstuff
     2  
     3  import (
     4  	"github.com/koko1123/flow-go-1/consensus/hotstuff/model"
     5  	"github.com/koko1123/flow-go-1/module"
     6  )
     7  
     8  // BlockSigner abstracts the implementation of how a signature of a block or a vote is produced
     9  // and stored in a stateful crypto object for aggregation.
    10  // The VoteAggregator implements both the VoteAggregator interface and the BlockSigner interface so that
    11  // the EventHandler could use the VoteAggregator interface to sign a Block, and Voter/BlockProducer can use
    12  // the BlockSigner interface to create vote.
    13  // When `CreateVote` is called, it internally creates stateful VoteCollector object, which also has the ability
    14  // to verify the block and generate the vote signature.
    15  // The created vote collector will be added to the vote collectors map. These
    16  // implementation details are abstracted to Voter/BlockProducer.
    17  type BlockSigner interface {
    18  	// CreateVote returns a vote for the given block.
    19  	// It returns:
    20  	//  - (vote, nil) if vote is created
    21  	//  - (nil , module.InvalidBlockError) if the block is invalid.
    22  	CreateVote(*model.Block) (*model.Vote, error)
    23  }
    24  
    25  // VoteAggregator verifies and aggregates votes to build QC.
    26  // When enough votes have been collected, it builds a QC and send it to the EventLoop
    27  // VoteAggregator also detects protocol violation, including invalid votes, double voting etc, and
    28  // notifies a HotStuff consumer for slashing.
    29  type VoteAggregator interface {
    30  	module.ReadyDoneAware
    31  	module.Startable
    32  
    33  	// AddVote verifies and aggregates a vote.
    34  	// The voting block could either be known or unknown.
    35  	// If the voting block is unknown, the vote won't be processed until AddBlock is called with the block.
    36  	// This method can be called concurrently, votes will be queued and processed asynchronously.
    37  	AddVote(vote *model.Vote)
    38  
    39  	// AddBlock notifies the VoteAggregator that it should start processing votes for the given block.
    40  	// AddBlock is a _synchronous_ call (logic is executed by the calling go routine). It also verifies
    41  	// validity of the proposer's vote for its own block.
    42  	// Expected error returns during normal operations:
    43  	// * model.InvalidBlockError if the proposer's vote for its own block is invalid
    44  	// * mempool.DecreasingPruningHeightError if the block's view has already been pruned
    45  	AddBlock(block *model.Proposal) error
    46  
    47  	// InvalidBlock notifies the VoteAggregator about an invalid proposal, so that it
    48  	// can process votes for the invalid block and slash the voters. Expected error
    49  	// returns during normal operations:
    50  	// * mempool.DecreasingPruningHeightError if proposal's view has already been pruned
    51  	InvalidBlock(block *model.Proposal) error
    52  
    53  	// PruneUpToView deletes all votes _below_ to the given view, as well as
    54  	// related indices. We only retain and process whose view is equal or larger
    55  	// than `lowestRetainedView`. If `lowestRetainedView` is smaller than the
    56  	// previous value, the previous value is kept and the method call is a NoOp.
    57  	PruneUpToView(view uint64)
    58  }