Skip to content

Commit f828e92

Browse files
authored
Merge pull request #69 from getamis/feature/round_robin_proposer
consensus/pbft: round robin proposer selection
2 parents 81f08f1 + 022b65f commit f828e92

File tree

5 files changed

+20
-10
lines changed

5 files changed

+20
-10
lines changed

consensus/pbft/core/core.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ func (c *core) startNewRound(newView *pbft.View, roundChange bool) {
181181
c.current = newSnapshot(newView, c.backend.Validators())
182182

183183
// Calculate new proposer
184-
//c.backend.Validators().CalcProposer(c.proposerSeed())
184+
c.backend.Validators().CalcProposer(c.proposerSeed())
185185
c.waitingForRoundChange = false
186186
c.setState(StateAcceptRequest)
187187
if roundChange {

consensus/pbft/core/handler.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,16 @@ func (c *core) Start(lastSequence *big.Int, lastProposer common.Address) error {
2828
// initial last commit sequence and proposer
2929
c.lastProposer = lastProposer
3030

31-
// Tests will handle events itself, so we have to make subscribeEvents()
32-
// be able to call in test.
33-
c.subscribeEvents()
34-
35-
go c.handleEvents()
36-
3731
c.startNewRound(&pbft.View{
3832
Sequence: new(big.Int).Add(lastSequence, common.Big1),
3933
Round: common.Big0,
4034
}, false)
4135

36+
// Tests will handle events itself, so we have to make subscribeEvents()
37+
// be able to call in test.
38+
c.subscribeEvents()
39+
go c.handleEvents()
40+
4241
return nil
4342
}
4443

consensus/pbft/core/preprepare.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func (c *core) sendPreprepare(request *pbft.Request) {
2626
logger := c.logger.New("state", c.state)
2727
curView := c.currentView()
2828

29-
if c.isPrimary() {
29+
if c.current.sequence.Cmp(request.Proposal.Number()) == 0 && c.isPrimary() {
3030
preprepare, err := Encode(&pbft.Preprepare{
3131
View: curView,
3232
Proposal: request.Proposal,

consensus/pbft/core/types.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
package core
1818

1919
import (
20+
"fmt"
2021
"io"
2122
"math/big"
2223

23-
"gopkg.in/karalabe/cookiejar.v2/collections/prque"
24-
2524
"github.com/ethereum/go-ethereum/common"
2625
"github.com/ethereum/go-ethereum/consensus/pbft"
2726
"github.com/ethereum/go-ethereum/rlp"
27+
"gopkg.in/karalabe/cookiejar.v2/collections/prque"
2828
)
2929

3030
type Engine interface {
@@ -156,6 +156,10 @@ func (m *message) Decode(val interface{}) error {
156156
return rlp.DecodeBytes(m.Msg, val)
157157
}
158158

159+
func (m *message) String() string {
160+
return fmt.Sprintf("{Code: %v, Address: %v}", m.Code, m.Address.Hex())
161+
}
162+
159163
// ==============================================
160164
//
161165
// helper functions

consensus/pbft/types.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package pbft
1818

1919
import (
20+
"fmt"
2021
"io"
2122
"math/big"
2223

@@ -45,6 +46,8 @@ type Proposal interface {
4546
EncodeRLP(w io.Writer) error
4647

4748
DecodeRLP(s *rlp.Stream) error
49+
50+
String() string
4851
}
4952

5053
type Request struct {
@@ -137,3 +140,7 @@ func (b *Subject) DecodeRLP(s *rlp.Stream) error {
137140
b.View, b.Digest = subject.View, subject.Digest
138141
return nil
139142
}
143+
144+
func (b *Subject) String() string {
145+
return fmt.Sprintf("{View: %v, Digest: %v}", b.View, b.Digest.Hex())
146+
}

0 commit comments

Comments
 (0)