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

     1  package model
     2  
     3  import (
     4  	"github.com/onflow/flow-go/model/flow"
     5  )
     6  
     7  // Proposal represent a new proposed block within HotStuff (and thus a
     8  // a header in the bigger picture), signed by the proposer.
     9  type Proposal struct {
    10  	Block      *Block
    11  	SigData    []byte
    12  	LastViewTC *flow.TimeoutCertificate
    13  }
    14  
    15  // ProposerVote extracts the proposer vote from the proposal
    16  func (p *Proposal) ProposerVote() *Vote {
    17  	vote := Vote{
    18  		View:     p.Block.View,
    19  		BlockID:  p.Block.BlockID,
    20  		SignerID: p.Block.ProposerID,
    21  		SigData:  p.SigData,
    22  	}
    23  	return &vote
    24  }
    25  
    26  // ProposalFromFlow turns a flow header into a hotstuff block type.
    27  func ProposalFromFlow(header *flow.Header) *Proposal {
    28  	proposal := Proposal{
    29  		Block:      BlockFromFlow(header),
    30  		SigData:    header.ProposerSigData,
    31  		LastViewTC: header.LastViewTC,
    32  	}
    33  	return &proposal
    34  }
    35  
    36  // ProposalToFlow turns a block proposal into a flow header.
    37  func ProposalToFlow(proposal *Proposal) *flow.Header {
    38  
    39  	block := proposal.Block
    40  	header := &flow.Header{
    41  		ParentID:           block.QC.BlockID,
    42  		PayloadHash:        block.PayloadHash,
    43  		Timestamp:          block.Timestamp,
    44  		View:               block.View,
    45  		ParentView:         block.QC.View,
    46  		ParentVoterIndices: block.QC.SignerIndices,
    47  		ParentVoterSigData: block.QC.SigData,
    48  		ProposerID:         block.ProposerID,
    49  		ProposerSigData:    proposal.SigData,
    50  		LastViewTC:         proposal.LastViewTC,
    51  	}
    52  
    53  	return header
    54  }