github.com/koko1123/flow-go-1@v0.29.6/model/cluster/payload.go (about) 1 package cluster 2 3 import ( 4 "github.com/koko1123/flow-go-1/model/fingerprint" 5 "github.com/koko1123/flow-go-1/model/flow" 6 ) 7 8 // Payload is the payload for blocks in collection node cluster consensus. 9 // It contains only a single collection. 10 type Payload struct { 11 12 // Collection is the collection being created. 13 Collection flow.Collection 14 15 // ReferenceBlockID is the ID of a reference block on the main chain. It 16 // is defined as the ID of the reference block with the lowest height 17 // from all transactions within the collection. 18 // 19 // This determines when the collection expires, using the same expiry rules 20 // as transactions. It is also used as the reference point for committee 21 // state (staking, etc.) when validating the containing block. 22 // 23 // The root block of a cluster chain has an empty reference block ID, as it 24 // is created in advance of its members (necessarily) being authorized network 25 // members. It is invalid for any non-root block to have an empty reference 26 // block ID. 27 ReferenceBlockID flow.Identifier 28 } 29 30 // EmptyPayload returns a payload with an empty collection and the given 31 // reference block ID. 32 func EmptyPayload(refID flow.Identifier) Payload { 33 return PayloadFromTransactions(refID) 34 } 35 36 // PayloadFromTransactions creates a payload given a reference block ID and a 37 // list of transaction hashes. 38 func PayloadFromTransactions(refID flow.Identifier, transactions ...*flow.TransactionBody) Payload { 39 // avoid a nil transaction list 40 if len(transactions) == 0 { 41 transactions = []*flow.TransactionBody{} 42 } 43 return Payload{ 44 Collection: flow.Collection{ 45 Transactions: transactions, 46 }, 47 ReferenceBlockID: refID, 48 } 49 } 50 51 // Hash returns the hash of the payload. 52 func (p Payload) Hash() flow.Identifier { 53 return flow.MakeID(p) 54 } 55 56 func (p Payload) Fingerprint() []byte { 57 return fingerprint.Fingerprint(struct { 58 Collection []byte 59 ReferenceBlockID flow.Identifier 60 }{ 61 Collection: p.Collection.Fingerprint(), 62 ReferenceBlockID: p.ReferenceBlockID, 63 }) 64 }