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

     1  package model
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/koko1123/flow-go-1/model/flow"
     7  )
     8  
     9  // Block is the HotStuff algorithm's concept of a block, which - in the bigger picture - corresponds
    10  // to the block header.
    11  type Block struct {
    12  	View        uint64
    13  	BlockID     flow.Identifier
    14  	ProposerID  flow.Identifier
    15  	QC          *flow.QuorumCertificate
    16  	PayloadHash flow.Identifier
    17  	Timestamp   time.Time
    18  }
    19  
    20  // BlockFromFlow converts a flow header to a hotstuff block.
    21  func BlockFromFlow(header *flow.Header, parentView uint64) *Block {
    22  
    23  	qc := flow.QuorumCertificate{
    24  		BlockID:       header.ParentID,
    25  		View:          parentView,
    26  		SignerIndices: header.ParentVoterIndices,
    27  		SigData:       header.ParentVoterSigData,
    28  	}
    29  
    30  	block := Block{
    31  		BlockID:     header.ID(),
    32  		View:        header.View,
    33  		QC:          &qc,
    34  		ProposerID:  header.ProposerID,
    35  		PayloadHash: header.PayloadHash,
    36  		Timestamp:   header.Timestamp,
    37  	}
    38  
    39  	return &block
    40  }
    41  
    42  // GenesisBlockFromFlow returns a HotStuff block model representing a genesis
    43  // block based on the given header.
    44  func GenesisBlockFromFlow(header *flow.Header) *Block {
    45  	genesis := &Block{
    46  		BlockID:     header.ID(),
    47  		View:        header.View,
    48  		ProposerID:  header.ProposerID,
    49  		QC:          nil,
    50  		PayloadHash: header.PayloadHash,
    51  		Timestamp:   header.Timestamp,
    52  	}
    53  	return genesis
    54  }