Skip to content

Commit

Permalink
consensus/istanbul: faulty behavior, always propose
Browse files Browse the repository at this point in the history
  • Loading branch information
markya0616 committed Dec 18, 2017
1 parent c68aedc commit b7c79fb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
6 changes: 3 additions & 3 deletions consensus/istanbul/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const (
NotBroadcast
SendWrongMsg
ModifySig
BeFakeProposer
AlwaysPropose
)

func (f FaultyMode) Uint64() uint64 {
Expand All @@ -50,8 +50,8 @@ func (f FaultyMode) String() string {
return "SendWrongMsg"
case ModifySig:
return "ModifySig"
case BeFakeProposer:
return "BeFakeProposer"
case AlwaysPropose:
return "AlwaysPropose"
default:
return "Undefined"
}
Expand Down
4 changes: 2 additions & 2 deletions consensus/istanbul/core/faulty/faulty.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ func (c *core) modifySig() bool {
return c.config.FaultyMode == istanbul.ModifySig.Uint64() || c.random()
}

func (c *core) beFakeProposer() bool {
return c.config.FaultyMode == istanbul.BeFakeProposer.Uint64() || c.random()
func (c *core) alwaysPropose() bool {
return c.config.FaultyMode == istanbul.AlwaysPropose.Uint64() || c.random()
}
36 changes: 23 additions & 13 deletions consensus/istanbul/core/faulty/preprepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,32 @@ func (c *core) sendPreprepare(request *istanbul.Request) {
logger := c.logger.New("state", c.state)

// If I'm the proposer and I have the same sequence with the proposal
if c.current.Sequence().Cmp(request.Proposal.Number()) == 0 && c.isProposer() {
curView := c.currentView()
preprepare, err := Encode(&istanbul.Preprepare{
View: curView,
Proposal: request.Proposal,
})
if err != nil {
logger.Error("Failed to encode", "view", curView)
if c.current.Sequence().Cmp(request.Proposal.Number()) != 0 || c.isProposer() {
if !c.alwaysPropose() {
return
}

c.broadcast(&message{
Code: msgPreprepare,
Msg: preprepare,
})
logger.Info("Always propose a proposal", "request", request)
}
curView := c.currentView()
preprepare, err := Encode(&istanbul.Preprepare{
View: curView,
Proposal: request.Proposal,
})
if err != nil {
logger.Error("Failed to encode", "view", curView)
return
}

c.broadcast(&message{
Code: msgPreprepare,
Msg: preprepare,
})

logger.Trace("sendPreprepare")
c.broadcast(&message{
Code: msgPreprepare,
Msg: preprepare,
})
}

func (c *core) handlePreprepare(msg *message, src istanbul.Validator) error {
Expand Down

0 comments on commit b7c79fb

Please sign in to comment.