-
Notifications
You must be signed in to change notification settings - Fork 0
/
structs.go
157 lines (132 loc) · 3.36 KB
/
structs.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package qbft
type Block struct {
RoundNumber uint64
Height uint64
Proposer NodeID
Body []byte
}
func (b *Block) Copy() *Block {
bb := new(Block)
*bb = *b
bb.Body = append(bb.Body, b.Body...)
return b
}
type NodeID string
// -- containers --
type Proposal struct {
Height uint64
Round uint64
Digest []byte
}
type Prepare struct {
Height uint64
Round uint64
Digest []byte
}
type Commit struct {
Height uint64
Round uint64
CommitSeal []byte
Digest []byte
}
type RoundChange struct {
Height uint64
Round uint64
PreparedCertificate []SignedContainer // Prepare + Proposal
}
type UnsignedPayload struct {
RoundChange *RoundChange
Commit *Commit
Prepare *Prepare
Proposal *Proposal
}
type SignedContainer struct {
UnsignedPayload UnsignedPayload
Signature []byte
// sender field is derived from the signature
// and the unsigned payload
sender NodeID
}
// -- transport messages --
type ProposalMessage struct {
Payload SignedContainer // SignedProposal
ProposedBlock *Block
RoundChangeCertificate []*RoundChangeMessage
}
type PrepareMessage struct {
Payload SignedContainer // SignedPrepare
}
type CommitMessage struct {
Payload SignedContainer // SignedCommit
}
type RoundChangeMessage struct {
Payload SignedContainer // SignedRoundChange
LatestProposedBlock *Block
}
type NewBlockMessage struct {
Block []byte
}
type QBFTMessagePayload struct {
ProposalMessage *ProposalMessage
PrepareMessage *PrepareMessage
CommitMessage *CommitMessage
RoundChangeMessage *RoundChangeMessage
NewBlockMessage *NewBlockMessage
}
func (q *QBFTMessagePayload) Round() uint64 {
if q.ProposalMessage != nil {
return q.ProposalMessage.Payload.UnsignedPayload.Proposal.Round
} else if q.PrepareMessage != nil {
return q.PrepareMessage.Payload.UnsignedPayload.Prepare.Round
} else if q.CommitMessage != nil {
return q.CommitMessage.Payload.UnsignedPayload.Commit.Round
} else if q.RoundChangeMessage != nil {
return q.RoundChangeMessage.Payload.UnsignedPayload.RoundChange.Round
} else if q.NewBlockMessage != nil {
panic("TODO")
}
panic("TODO")
}
func (q *QBFTMessagePayload) Height() uint64 {
if q.ProposalMessage != nil {
return q.ProposalMessage.Payload.UnsignedPayload.Proposal.Height
} else if q.PrepareMessage != nil {
return q.PrepareMessage.Payload.UnsignedPayload.Prepare.Height
} else if q.CommitMessage != nil {
return q.CommitMessage.Payload.UnsignedPayload.Commit.Height
} else if q.RoundChangeMessage != nil {
return q.RoundChangeMessage.Payload.UnsignedPayload.RoundChange.Height
} else if q.NewBlockMessage != nil {
panic("TODO")
}
panic("TODO")
}
func (q *QBFTMessagePayload) typ() string {
if q.ProposalMessage != nil {
return "proposal"
} else if q.PrepareMessage != nil {
return "prepare"
} else if q.CommitMessage != nil {
return "commit"
} else if q.RoundChangeMessage != nil {
return "round-change"
} else if q.NewBlockMessage != nil {
return "new-block"
}
return ""
}
type QBFTMessageWithRecipient struct {
Message QBFTMessagePayload
Sender NodeID
}
// SealedProposal represents the sealed proposal model
type SealedProposal struct {
Block *Block
CommittedSeals []CommittedSeal
}
type CommittedSeal struct {
// Signature value
Signature []byte
// Node that signed
NodeID NodeID
}