github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/module/hotstuff.go (about)

     1  package module
     2  
     3  import (
     4  	"github.com/onflow/flow-go/consensus/hotstuff/model"
     5  )
     6  
     7  // HotStuff defines the interface for the core HotStuff algorithm. It includes
     8  // a method to start the event loop, and utilities to submit block proposals
     9  // received from other replicas.
    10  //
    11  // TODO:
    12  //
    13  //	HotStuff interface could extend HotStuffFollower. Thereby, we can
    14  //	utilize the optimized catchup mode from the follower also for the
    15  //	consensus participant.
    16  type HotStuff interface {
    17  	ReadyDoneAware
    18  	Startable
    19  
    20  	// SubmitProposal submits a new block proposal to the HotStuff event loop.
    21  	// This method blocks until the proposal is accepted to the event queue.
    22  	//
    23  	// Block proposals must be submitted in order and only if they extend a
    24  	// block already known to HotStuff core.
    25  	SubmitProposal(proposal *model.Proposal)
    26  }
    27  
    28  // HotStuffFollower is run by non-consensus nodes to observe the block chain
    29  // and make local determination about block finalization. While the process of
    30  // reaching consensus (incl. guaranteeing its safety and liveness) is very intricate,
    31  // the criteria to confirm that consensus has been reached are relatively straight
    32  // forward. Each non-consensus node can simply observe the blockchain and determine
    33  // locally which blocks have been finalized without requiring additional information
    34  // from the consensus nodes.
    35  //
    36  // In contrast to an active HotStuff participant, the HotStuffFollower does not validate
    37  // block payloads. This greatly reduces the amount of CPU and memory that it consumes.
    38  // Essentially, the consensus participants exhaustively verify the entire block including
    39  // the payload and only vote for the block if it is valid. The consensus committee
    40  // aggregates votes from a supermajority of participants to a Quorum Certificate [QC].
    41  // Thereby, it is guaranteed that only valid blocks get certified (receive a QC).
    42  // By only consuming certified blocks, the HotStuffFollower can be sure of their
    43  // correctness and omit the heavy payload verification.
    44  // There is no disbenefit for nodes to wait for a QC (included in child blocks), because
    45  // all nodes other than consensus generally require the Source Of Randomness included in
    46  // QCs to process the block in the first place.
    47  //
    48  // The central purpose of the HotStuffFollower is to inform other components within the
    49  // node about finalization of blocks.
    50  //
    51  // Notes:
    52  //   - HotStuffFollower internally prunes blocks below the last finalized view.
    53  //   - HotStuffFollower does not handle disconnected blocks. For each input block,
    54  //     we require that the parent was previously added (unless the parent's view
    55  //     is _below_ the latest finalized view).
    56  type HotStuffFollower interface {
    57  	ReadyDoneAware
    58  	Startable
    59  
    60  	// AddCertifiedBlock appends the given certified block to the tree of pending
    61  	// blocks and updates the latest finalized block (if finalization progressed).
    62  	// Unless the parent is below the pruning threshold (latest finalized view), we
    63  	// require that the parent has previously been added.
    64  	//
    65  	// Notes:
    66  	//  - Under normal operations, this method is non-blocking. The follower internally
    67  	//    queues incoming blocks and processes them in its own worker routine. However,
    68  	//    when the inbound queue is full, we block until there is space in the queue. This
    69  	//    behaviour is intentional, because we cannot drop blocks (otherwise, we would
    70  	//    cause disconnected blocks). Instead we simply block the compliance layer to
    71  	//    avoid any pathological edge cases.
    72  	//  - Blocks whose views are below the latest finalized view are dropped.
    73  	//  - Inputs are idempotent (repetitions are no-ops).
    74  	AddCertifiedBlock(certifiedBlock *model.CertifiedBlock)
    75  }