-
Notifications
You must be signed in to change notification settings - Fork 175
/
payload.go
70 lines (62 loc) · 2.37 KB
/
payload.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package cluster
import (
"github.com/onflow/flow-go/model/fingerprint"
"github.com/onflow/flow-go/model/flow"
)
// Payload is the payload for blocks in collection node cluster consensus.
// It contains only a single collection.
type Payload struct {
// Collection is the collection being created.
Collection flow.Collection
// ReferenceBlockID is the ID of a reference block on the main chain. It
// is defined as the ID of the reference block with the lowest height
// from all transactions within the collection. If the collection is empty,
// the proposer may choose any reference block, so long as it is finalized
// and within the epoch the cluster is associated with. If a cluster was
// assigned for epoch E, then all of its reference blocks must have a view
// in the range [E.FirstView, E.FinalView]. However, if epoch fallback is
// triggered in epoch E, then any reference block with view ≥ E.FirstView
// may be used.
//
// This determines when the collection expires, using the same expiry rules
// as transactions. It is also used as the reference point for committee
// state (staking, etc.) when validating the containing block.
//
// The root block of a cluster chain has an empty reference block ID, as it
// is created in advance of its members (necessarily) being authorized network
// members. It is invalid for any non-root block to have an empty reference
// block ID.
ReferenceBlockID flow.Identifier
}
// EmptyPayload returns a payload with an empty collection and the given
// reference block ID.
func EmptyPayload(refID flow.Identifier) Payload {
return PayloadFromTransactions(refID)
}
// PayloadFromTransactions creates a payload given a reference block ID and a
// list of transaction hashes.
func PayloadFromTransactions(refID flow.Identifier, transactions ...*flow.TransactionBody) Payload {
// avoid a nil transaction list
if len(transactions) == 0 {
transactions = []*flow.TransactionBody{}
}
return Payload{
Collection: flow.Collection{
Transactions: transactions,
},
ReferenceBlockID: refID,
}
}
// Hash returns the hash of the payload.
func (p Payload) Hash() flow.Identifier {
return flow.MakeID(p)
}
func (p Payload) Fingerprint() []byte {
return fingerprint.Fingerprint(struct {
Collection []byte
ReferenceBlockID flow.Identifier
}{
Collection: p.Collection.Fingerprint(),
ReferenceBlockID: p.ReferenceBlockID,
})
}