Skip to content

Commit 58e3f1e

Browse files
authored
Merge pull request #94 from renproject/feat/remove-signature
Remove signature from messages
2 parents 23c9928 + c629d83 commit 58e3f1e

File tree

8 files changed

+131
-184
lines changed

8 files changed

+131
-184
lines changed

process/message.go

+27-46
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,24 @@ import (
77
"github.com/renproject/surge"
88
)
99

10+
type MessageType int8
11+
12+
const (
13+
MessageTypePropose MessageType = 1
14+
MessageTypePrevote MessageType = 2
15+
MessageTypePrecommit MessageType = 3
16+
)
17+
1018
// A Propose message is sent by the proposer Process at most once per Round. The
1119
// Scheduler interfaces determines which Process is the proposer at any given
1220
// Height and Round.
1321
type Propose struct {
14-
Height Height `json:"height"`
15-
Round Round `json:"round"`
16-
ValidRound Round `json:"validRound"`
17-
Value Value `json:"value"`
18-
From id.Signatory `json:"from"`
19-
Signature id.Signature `json:"signature"`
22+
Height Height `json:"height"`
23+
Round Round `json:"round"`
24+
ValidRound Round `json:"validRound"`
25+
Value Value `json:"value"`
26+
27+
From id.Signatory `json:"from"`
2028
}
2129

2230
// NewProposeHash receives fields of a propose message and hashes the message
@@ -65,8 +73,7 @@ func (propose Propose) SizeHint() int {
6573
surge.SizeHint(propose.Round) +
6674
surge.SizeHint(propose.ValidRound) +
6775
surge.SizeHint(propose.Value) +
68-
surge.SizeHint(propose.From) +
69-
surge.SizeHint(propose.Signature)
76+
surge.SizeHint(propose.From)
7077
}
7178

7279
// Marshal this message into binary.
@@ -91,10 +98,6 @@ func (propose Propose) Marshal(buf []byte, rem int) ([]byte, int, error) {
9198
if err != nil {
9299
return buf, rem, fmt.Errorf("marshaling from=%v: %v", propose.From, err)
93100
}
94-
buf, rem, err = surge.Marshal(propose.Signature, buf, rem)
95-
if err != nil {
96-
return buf, rem, fmt.Errorf("marshaling signature=%v: %v", propose.Signature, err)
97-
}
98101
return buf, rem, nil
99102
}
100103

@@ -120,10 +123,6 @@ func (propose *Propose) Unmarshal(buf []byte, rem int) ([]byte, int, error) {
120123
if err != nil {
121124
return buf, rem, fmt.Errorf("unmarshaling from: %v", err)
122125
}
123-
buf, rem, err = surge.Unmarshal(&propose.Signature, buf, rem)
124-
if err != nil {
125-
return buf, rem, fmt.Errorf("unmarshaling signature: %v", err)
126-
}
127126
return buf, rem, nil
128127
}
129128

@@ -133,11 +132,11 @@ func (propose *Propose) Unmarshal(buf []byte, rem int) ([]byte, int, error) {
133132
// there are many other conditions which can cause a Process to Prevote. See the
134133
// Process for more information.
135134
type Prevote struct {
136-
Height Height `json:"height"`
137-
Round Round `json:"round"`
138-
Value Value `json:"value"`
139-
From id.Signatory `json:"from"`
140-
Signature id.Signature `json:"signature"`
135+
Height Height `json:"height"`
136+
Round Round `json:"round"`
137+
Value Value `json:"value"`
138+
139+
From id.Signatory `json:"from"`
141140
}
142141

143142
// NewPrevoteHash receives fields of a prevote message and hashes the message
@@ -180,8 +179,7 @@ func (prevote Prevote) SizeHint() int {
180179
return surge.SizeHint(prevote.Height) +
181180
surge.SizeHint(prevote.Round) +
182181
surge.SizeHint(prevote.Value) +
183-
surge.SizeHint(prevote.From) +
184-
surge.SizeHint(prevote.Signature)
182+
surge.SizeHint(prevote.From)
185183
}
186184

187185
// Marshal this message into binary.
@@ -202,10 +200,6 @@ func (prevote Prevote) Marshal(buf []byte, rem int) ([]byte, int, error) {
202200
if err != nil {
203201
return buf, rem, fmt.Errorf("marshaling from=%v: %v", prevote.From, err)
204202
}
205-
buf, rem, err = surge.Marshal(prevote.Signature, buf, rem)
206-
if err != nil {
207-
return buf, rem, fmt.Errorf("marshaling signature=%v: %v", prevote.Signature, err)
208-
}
209203
return buf, rem, nil
210204
}
211205

@@ -227,10 +221,6 @@ func (prevote *Prevote) Unmarshal(buf []byte, rem int) ([]byte, int, error) {
227221
if err != nil {
228222
return buf, rem, fmt.Errorf("unmarshaling from: %v", err)
229223
}
230-
buf, rem, err = surge.Unmarshal(&prevote.Signature, buf, rem)
231-
if err != nil {
232-
return buf, rem, fmt.Errorf("unmarshaling signature: %v", err)
233-
}
234224
return buf, rem, nil
235225
}
236226

@@ -240,11 +230,11 @@ func (prevote *Prevote) Unmarshal(buf []byte, rem int) ([]byte, int, error) {
240230
// progress to the next Height. However, there are many other conditions which
241231
// can cause a Process to Precommit. See the Process for more information.
242232
type Precommit struct {
243-
Height Height `json:"height"`
244-
Round Round `json:"round"`
245-
Value Value `json:"value"`
246-
From id.Signatory `json:"from"`
247-
Signature id.Signature `json:"signature"`
233+
Height Height `json:"height"`
234+
Round Round `json:"round"`
235+
Value Value `json:"value"`
236+
237+
From id.Signatory `json:"from"`
248238
}
249239

250240
// NewPrecommitHash receives fields of a precommit message and hashes the message
@@ -287,8 +277,7 @@ func (precommit Precommit) SizeHint() int {
287277
return surge.SizeHint(precommit.Height) +
288278
surge.SizeHint(precommit.Round) +
289279
surge.SizeHint(precommit.Value) +
290-
surge.SizeHint(precommit.From) +
291-
surge.SizeHint(precommit.Signature)
280+
surge.SizeHint(precommit.From)
292281
}
293282

294283
// Marshal this message into binary.
@@ -309,10 +298,6 @@ func (precommit Precommit) Marshal(buf []byte, rem int) ([]byte, int, error) {
309298
if err != nil {
310299
return buf, rem, fmt.Errorf("marshaling from=%v: %v", precommit.From, err)
311300
}
312-
buf, rem, err = surge.Marshal(precommit.Signature, buf, rem)
313-
if err != nil {
314-
return buf, rem, fmt.Errorf("marshaling signature=%v: %v", precommit.Signature, err)
315-
}
316301
return buf, rem, nil
317302
}
318303

@@ -334,9 +319,5 @@ func (precommit *Precommit) Unmarshal(buf []byte, rem int) ([]byte, int, error)
334319
if err != nil {
335320
return buf, rem, fmt.Errorf("unmarshaling from: %v", err)
336321
}
337-
buf, rem, err = surge.Unmarshal(&precommit.Signature, buf, rem)
338-
if err != nil {
339-
return buf, rem, fmt.Errorf("unmarshaling signature: %v", err)
340-
}
341322
return buf, rem, nil
342323
}

process/message_test.go

+9-12
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,13 @@ var _ = Describe("Propose", func() {
3030
r := rand.New(rand.NewSource(time.Now().UnixNano()))
3131

3232
It("should equal itself", func() {
33-
f := func(height process.Height, round, validRound process.Round, value process.Value, from id.Signatory, signature id.Signature) bool {
33+
f := func(height process.Height, round, validRound process.Round, value process.Value, from id.Signatory) bool {
3434
expected := process.Propose{
3535
Height: height,
3636
Round: round,
3737
ValidRound: validRound,
3838
Value: value,
3939
From: from,
40-
Signature: signature,
4140
}
4241
data, err := surge.ToBinary(expected)
4342
Expect(err).ToNot(HaveOccurred())
@@ -222,11 +221,10 @@ var _ = Describe("Prevote", func() {
222221
It("should equal itself", func() {
223222
f := func(height process.Height, round process.Round, value process.Value, from id.Signatory, signature id.Signature) bool {
224223
expected := process.Prevote{
225-
Height: height,
226-
Round: round,
227-
Value: value,
228-
From: from,
229-
Signature: signature,
224+
Height: height,
225+
Round: round,
226+
Value: value,
227+
From: from,
230228
}
231229
data, err := surge.ToBinary(expected)
232230
Expect(err).ToNot(HaveOccurred())
@@ -286,11 +284,10 @@ var _ = Describe("Precommit", func() {
286284
It("should equal itself", func() {
287285
f := func(height process.Height, round process.Round, value process.Value, from id.Signatory, signature id.Signature) bool {
288286
expected := process.Precommit{
289-
Height: height,
290-
Round: round,
291-
Value: value,
292-
From: from,
293-
Signature: signature,
287+
Height: height,
288+
Round: round,
289+
Value: value,
290+
From: from,
294291
}
295292
data, err := surge.ToBinary(expected)
296293
Expect(err).ToNot(HaveOccurred())

process/process.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Package process implements the Byzantine fault tolerant consensus algorithm
22
// described by "The latest gossip of BFT consensus" (Buchman et al.), which can
33
// be found at https://arxiv.org/pdf/1807.04938.pdf. It makes extensive use of
4-
// dependency injection, and concrete implementions must be careful to meet all
4+
// dependency injection, and concrete implementations must be careful to meet all
55
// of the requirements specified by the interface, otherwise the correctness of
66
// the consensus algorithm can be broken.
77
package process
@@ -29,7 +29,7 @@ type Timer interface {
2929
TimeoutPrecommit(Height, Round)
3030
}
3131

32-
// A Scheduler is used to determine which Process should be proposing a Vaue at
32+
// A Scheduler is used to determine which Process should be proposing a Value at
3333
// the given Height and Round. A Scheduler must be derived solely from the
3434
// Height, Round, and Values on which all correct Processes have already
3535
// achieved consensus.
@@ -250,7 +250,7 @@ func (p *Process) Start() {
250250
p.StartRound(0)
251251
}
252252

253-
// StartRound will progress the Process to a new Round. It does not asssume that
253+
// StartRound will progress the Process to a new Round. It does not assume that
254254
// the Height has changed. Since this changes the current Round and the current
255255
// Step, most of the condition methods will be retried at the end (by way of
256256
// defer).
@@ -279,7 +279,7 @@ func (p *Process) StartRound(round Round) {
279279

280280
// Set the state the new round, and set the step to the first step in the
281281
// sequence. We do not have special methods dedicated to change the current
282-
// Roound, or changing the current Step to Proposing, because StartRound is
282+
// Round, or changing the current Step to Proposing, because StartRound is
283283
// the only location where this logic happens.
284284
p.CurrentRound = round
285285
p.CurrentStep = Proposing
@@ -563,7 +563,7 @@ func (p *Process) tryPrecommitUponSufficientPrevotes() {
563563
// method.
564564
defer p.stepToPrecommitting()
565565

566-
// Beacuse the LockedValue and LockedRound have changed, we need to try
566+
// Because the LockedValue and LockedRound have changed, we need to try
567567
// this condition again. We defer this call, so that the once flag is
568568
// set before we exit this method.
569569
defer func() {

process/process_test.go

+8-10
Original file line numberDiff line numberDiff line change
@@ -993,20 +993,18 @@ var _ = Describe("Process", func() {
993993
switch r.Int() % 2 {
994994
case 0:
995995
msg := process.Prevote{
996-
Height: currentHeight,
997-
Round: futureRound,
998-
From: id.NewPrivKey().Signatory(),
999-
Value: processutil.RandomGoodValue(r),
1000-
Signature: id.Signature{},
996+
Height: currentHeight,
997+
Round: futureRound,
998+
From: id.NewPrivKey().Signatory(),
999+
Value: processutil.RandomGoodValue(r),
10011000
}
10021001
messages = append(messages, msg)
10031002
case 1:
10041003
msg := process.Precommit{
1005-
Height: currentHeight,
1006-
Round: futureRound,
1007-
From: id.NewPrivKey().Signatory(),
1008-
Value: processutil.RandomGoodValue(r),
1009-
Signature: id.Signature{},
1004+
Height: currentHeight,
1005+
Round: futureRound,
1006+
From: id.NewPrivKey().Signatory(),
1007+
Value: processutil.RandomGoodValue(r),
10101008
}
10111009
messages = append(messages, msg)
10121010
}

0 commit comments

Comments
 (0)