-
Notifications
You must be signed in to change notification settings - Fork 179
/
block.go
54 lines (46 loc) · 1.26 KB
/
block.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
package model
import (
"time"
"github.com/onflow/flow-go/model/flow"
)
// Block is the HotStuff algorithm's concept of a block, which - in the bigger picture - corresponds
// to the block header.
type Block struct {
View uint64
BlockID flow.Identifier
ProposerID flow.Identifier
QC *flow.QuorumCertificate
PayloadHash flow.Identifier
Timestamp time.Time
}
// BlockFromFlow converts a flow header to a hotstuff block.
func BlockFromFlow(header *flow.Header, parentView uint64) *Block {
qc := flow.QuorumCertificate{
BlockID: header.ParentID,
View: parentView,
SignerIDs: header.ParentVoterIDs,
SigData: header.ParentVoterSigData,
}
block := Block{
BlockID: header.ID(),
View: header.View,
QC: &qc,
ProposerID: header.ProposerID,
PayloadHash: header.PayloadHash,
Timestamp: header.Timestamp,
}
return &block
}
// GenesisBlockFromFlow returns a HotStuff block model representing a genesis
// block based on the given header.
func GenesisBlockFromFlow(header *flow.Header) *Block {
genesis := &Block{
BlockID: header.ID(),
View: header.View,
ProposerID: header.ProposerID,
QC: nil,
PayloadHash: header.PayloadHash,
Timestamp: header.Timestamp,
}
return genesis
}