Skip to content

Commit

Permalink
consensus/istanbul: faulty behavior, always send round change
Browse files Browse the repository at this point in the history
  • Loading branch information
markya0616 committed Dec 18, 2017
1 parent 671e1d1 commit 0f03a11
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion consensus/istanbul/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type FaultyMode uint64
const (
// Disabled disables the faulty mode
Disabled FaultyMode = iota
// Random selects one attack randomly
// Random attacks randomly
Random
// NotBroadcast doesn't broadcast any messages to other validators
NotBroadcast
Expand All @@ -38,6 +38,8 @@ const (
ModifySig
// AlwaysPropose always proposes a proposal to validators
AlwaysPropose
// AlwaysRoundChange always sends round change while receiving messages
AlwaysRoundChange
)

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

func (c *core) alwaysRoundChange() bool {
return c.config.FaultyMode == istanbul.AlwaysRoundChange.Uint64() || c.random()
}
5 changes: 5 additions & 0 deletions consensus/istanbul/core/faulty/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ func (c *core) handleCheckedMsg(msg *message, src istanbul.Validator) error {
return err
}

if msg.Code != msgRoundChange && c.alwaysRoundChange() {
logger.Info("Send faulty round change", "round", c.current.Round().Uint64())
c.sendNextRoundChange()
return nil
}
switch msg.Code {
case msgPreprepare:
return testBacklog(c.handlePreprepare(msg, src))
Expand Down

0 comments on commit 0f03a11

Please sign in to comment.