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

     1  package messages
     2  
     3  import (
     4  	"github.com/onflow/flow-go/model/flow"
     5  )
     6  
     7  // UntrustedExecutionResult is a duplicate of flow.ExecutionResult used within
     8  // untrusted messages. It exists only to provide a memory-safe structure for
     9  // decoding messages and should be replaced in the future by updating the core
    10  // flow.ExecutionResult type.
    11  // Deprecated: Please update flow.ExecutionResult to use []flow.Chunk, then
    12  // replace instances of this type with flow.ExecutionResult
    13  type UntrustedExecutionResult struct {
    14  	PreviousResultID flow.Identifier
    15  	BlockID          flow.Identifier
    16  	Chunks           []flow.Chunk
    17  	ServiceEvents    flow.ServiceEventList
    18  	ExecutionDataID  flow.Identifier
    19  }
    20  
    21  // ToInternal returns the internal representation of the type.
    22  func (ur *UntrustedExecutionResult) ToInternal() *flow.ExecutionResult {
    23  	result := flow.ExecutionResult{
    24  		PreviousResultID: ur.PreviousResultID,
    25  		BlockID:          ur.BlockID,
    26  		Chunks:           make(flow.ChunkList, 0, len(ur.Chunks)),
    27  		ServiceEvents:    ur.ServiceEvents,
    28  		ExecutionDataID:  ur.ExecutionDataID,
    29  	}
    30  	for _, chunk := range ur.Chunks {
    31  		chunk := chunk
    32  		result.Chunks = append(result.Chunks, &chunk)
    33  	}
    34  	return &result
    35  }
    36  
    37  // UntrustedExecutionResultFromInternal converts the internal flow.ExecutionResult representation
    38  // to the representation used in untrusted messages.
    39  func UntrustedExecutionResultFromInternal(internal *flow.ExecutionResult) UntrustedExecutionResult {
    40  	result := UntrustedExecutionResult{
    41  		PreviousResultID: internal.PreviousResultID,
    42  		BlockID:          internal.BlockID,
    43  		ServiceEvents:    internal.ServiceEvents,
    44  		ExecutionDataID:  internal.ExecutionDataID,
    45  	}
    46  	for _, chunk := range internal.Chunks {
    47  		result.Chunks = append(result.Chunks, *chunk)
    48  	}
    49  	return result
    50  }
    51  
    52  // UntrustedBlockPayload is a duplicate of flow.Payload used within
    53  // untrusted messages. It exists only to provide a memory-safe structure for
    54  // decoding messages and should be replaced in the future by updating the core
    55  // flow.Payload type.
    56  // Deprecated: Please update flow.Payload to use []flow.Guarantee etc., then
    57  // replace instances of this type with flow.Payload
    58  type UntrustedBlockPayload struct {
    59  	Guarantees      []flow.CollectionGuarantee
    60  	Seals           []flow.Seal
    61  	Receipts        []flow.ExecutionReceiptMeta
    62  	Results         []UntrustedExecutionResult
    63  	ProtocolStateID flow.Identifier
    64  }
    65  
    66  // UntrustedBlock is a duplicate of flow.Block used within
    67  // untrusted messages. It exists only to provide a memory-safe structure for
    68  // decoding messages and should be replaced in the future by updating the core
    69  // flow.Block type.
    70  // Deprecated: Please update flow.Payload to use []flow.Guarantee etc., then
    71  // replace instances of this type with flow.Block
    72  type UntrustedBlock struct {
    73  	Header  flow.Header
    74  	Payload UntrustedBlockPayload
    75  }
    76  
    77  // ToInternal returns the internal representation of the type.
    78  func (ub *UntrustedBlock) ToInternal() *flow.Block {
    79  	block := flow.Block{
    80  		Header: &ub.Header,
    81  		Payload: &flow.Payload{
    82  			ProtocolStateID: ub.Payload.ProtocolStateID,
    83  		},
    84  	}
    85  	for _, guarantee := range ub.Payload.Guarantees {
    86  		guarantee := guarantee
    87  		block.Payload.Guarantees = append(block.Payload.Guarantees, &guarantee)
    88  	}
    89  	for _, seal := range ub.Payload.Seals {
    90  		seal := seal
    91  		block.Payload.Seals = append(block.Payload.Seals, &seal)
    92  	}
    93  	for _, receipt := range ub.Payload.Receipts {
    94  		receipt := receipt
    95  		block.Payload.Receipts = append(block.Payload.Receipts, &receipt)
    96  	}
    97  	for _, result := range ub.Payload.Results {
    98  		result := result
    99  		block.Payload.Results = append(block.Payload.Results, result.ToInternal())
   100  	}
   101  
   102  	return &block
   103  }
   104  
   105  // UntrustedBlockFromInternal converts the internal flow.Block representation
   106  // to the representation used in untrusted messages.
   107  func UntrustedBlockFromInternal(flowBlock *flow.Block) UntrustedBlock {
   108  	block := UntrustedBlock{
   109  		Header: *flowBlock.Header,
   110  		Payload: UntrustedBlockPayload{
   111  			ProtocolStateID: flowBlock.Payload.ProtocolStateID,
   112  		},
   113  	}
   114  	for _, guarantee := range flowBlock.Payload.Guarantees {
   115  		block.Payload.Guarantees = append(block.Payload.Guarantees, *guarantee)
   116  	}
   117  	for _, seal := range flowBlock.Payload.Seals {
   118  		block.Payload.Seals = append(block.Payload.Seals, *seal)
   119  	}
   120  	for _, receipt := range flowBlock.Payload.Receipts {
   121  		block.Payload.Receipts = append(block.Payload.Receipts, *receipt)
   122  	}
   123  	for _, result := range flowBlock.Payload.Results {
   124  		block.Payload.Results = append(block.Payload.Results, UntrustedExecutionResultFromInternal(result))
   125  	}
   126  	return block
   127  }
   128  
   129  // BlockProposal is part of the consensus protocol and represents the leader
   130  // of a consensus round pushing a new proposal to the network.
   131  type BlockProposal struct {
   132  	Block UntrustedBlock
   133  }
   134  
   135  func NewBlockProposal(internal *flow.Block) *BlockProposal {
   136  	return &BlockProposal{
   137  		Block: UntrustedBlockFromInternal(internal),
   138  	}
   139  }
   140  
   141  // BlockVote is part of the consensus protocol and represents a consensus node
   142  // voting on the proposal of the leader of a given round.
   143  type BlockVote struct {
   144  	BlockID flow.Identifier
   145  	View    uint64
   146  	SigData []byte
   147  }
   148  
   149  // TimeoutObject is part of the consensus protocol and represents a consensus node
   150  // timing out in given round. Contains a sequential number for deduplication purposes.
   151  type TimeoutObject struct {
   152  	TimeoutTick uint64
   153  	View        uint64
   154  	NewestQC    *flow.QuorumCertificate
   155  	LastViewTC  *flow.TimeoutCertificate
   156  	SigData     []byte
   157  }