github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/consensus/hotstuff/forks/blockcontainer.go (about) 1 package forks 2 3 import ( 4 "github.com/onflow/flow-go/consensus/hotstuff/model" 5 "github.com/onflow/flow-go/model/flow" 6 "github.com/onflow/flow-go/module/forest" 7 ) 8 9 // BlockContainer wraps a block proposal to implement forest.Vertex 10 // so the proposal can be stored in forest.LevelledForest 11 type BlockContainer model.Block 12 13 var _ forest.Vertex = (*BlockContainer)(nil) 14 15 func ToBlockContainer2(block *model.Block) *BlockContainer { return (*BlockContainer)(block) } 16 func (b *BlockContainer) Block() *model.Block { return (*model.Block)(b) } 17 18 // Functions implementing forest.Vertex 19 func (b *BlockContainer) VertexID() flow.Identifier { return b.BlockID } 20 func (b *BlockContainer) Level() uint64 { return b.View } 21 22 func (b *BlockContainer) Parent() (flow.Identifier, uint64) { 23 // Caution: not all blocks have a QC for the parent, such as the spork root blocks. 24 // Per API contract, we are obliged to return a value to prevent panics during logging. 25 // (see vertex `forest.VertexToString` method). 26 if b.QC == nil { 27 return flow.ZeroID, 0 28 } 29 return b.QC.BlockID, b.QC.View 30 }