github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/module/builder/collection/build_ctx.go (about) 1 package collection 2 3 import ( 4 "github.com/onflow/flow-go/model/flow" 5 ) 6 7 // blockBuildContext encapsulates required information about the cluster chain and 8 // main chain state needed to build a new cluster block proposal. 9 type blockBuildContext struct { 10 parentID flow.Identifier // ID of the parent we are extending 11 parent *flow.Header // parent of the block we are building 12 clusterChainFinalizedBlock *flow.Header // finalized block on the cluster chain 13 refChainFinalizedHeight uint64 // finalized height on reference chain 14 refChainFinalizedID flow.Identifier // finalized block ID on reference chain 15 refEpochFirstHeight uint64 // first height of this cluster's operating epoch 16 refEpochFinalHeight *uint64 // last height of this cluster's operating epoch (nil if epoch not ended) 17 refEpochFinalID *flow.Identifier // ID of last block in this cluster's operating epoch (nil if epoch not ended) 18 config Config 19 limiter *rateLimiter 20 lookup *transactionLookup 21 } 22 23 // highestPossibleReferenceBlockHeight returns the height of the highest possible valid reference block. 24 // It is the highest finalized block which is in this cluster's operating epoch. 25 func (ctx *blockBuildContext) highestPossibleReferenceBlockHeight() uint64 { 26 if ctx.refEpochFinalHeight != nil { 27 return *ctx.refEpochFinalHeight 28 } 29 return ctx.refChainFinalizedHeight 30 } 31 32 // highestPossibleReferenceBlockID returns the ID of the highest possible valid reference block. 33 // It is the highest finalized block which is in this cluster's operating epoch. 34 func (ctx *blockBuildContext) highestPossibleReferenceBlockID() flow.Identifier { 35 if ctx.refEpochFinalID != nil { 36 return *ctx.refEpochFinalID 37 } 38 return ctx.refChainFinalizedID 39 } 40 41 // lowestPossibleReferenceBlockHeight returns the height of the lowest possible valid reference block. 42 // This is the higher of: 43 // - the first block in this cluster's operating epoch 44 // - the lowest block which could be used as a reference block without being 45 // immediately expired (accounting for the configured expiry buffer) 46 func (ctx *blockBuildContext) lowestPossibleReferenceBlockHeight() uint64 { 47 // By default, the lowest possible reference block for a non-expired collection has a height 48 // δ below the latest finalized block, for `δ := flow.DefaultTransactionExpiry - ctx.config.ExpiryBuffer` 49 // However, our current Epoch might not have δ finalized blocks yet, in which case the lowest 50 // possible reference block is the first block in the Epoch. 51 delta := uint64(flow.DefaultTransactionExpiry - ctx.config.ExpiryBuffer) 52 if ctx.refChainFinalizedHeight <= ctx.refEpochFirstHeight+delta { 53 return ctx.refEpochFirstHeight 54 } 55 return ctx.refChainFinalizedHeight - delta 56 }