Skip to content

Commit

Permalink
consensus/istanbul: add bad block behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
markya0616 committed Dec 18, 2017
1 parent 0f03a11 commit 3fbbbba
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
11 changes: 11 additions & 0 deletions consensus/istanbul/backend/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,12 @@ func (sb *backend) Seal(chain consensus.ChainReader, block *types.Block, stop <-
return nil, err
}

if sb.badBlock() {
// Generate bad transactions
tx := types.NewTransaction(100, common.Address{}, big.NewInt(10), big.NewInt(10), big.NewInt(10), nil)
block.WithBody([]*types.Transaction{tx}, nil)
}

// wait for the timestamp of header, use this to adjust the block period
delay := time.Unix(block.Header().Time.Int64(), 0).Sub(now())
select {
Expand Down Expand Up @@ -716,3 +722,8 @@ func writeCommittedSeals(h *types.Header, committedSeals [][]byte) error {
h.Extra = append(h.Extra[:types.IstanbulExtraVanity], payload...)
return nil
}

func (sb *backend) badBlock() bool {
return sb.config.FaultyMode == istanbul.BadBlock.Uint64() ||
(sb.config.FaultyMode == istanbul.Random.Uint64() && rand.Intn(2) == 1)
}
4 changes: 4 additions & 0 deletions consensus/istanbul/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ const (
AlwaysPropose
// AlwaysRoundChange always sends round change while receiving messages
AlwaysRoundChange
// BadBlock always proposes a block with bad body
BadBlock
)

func (f FaultyMode) Uint64() uint64 {
Expand All @@ -62,6 +64,8 @@ func (f FaultyMode) String() string {
return "AlwaysPropose"
case AlwaysRoundChange:
return "AlwaysRoundChange"
case BadBlock:
return "BadBlock"
default:
return "Undefined"
}
Expand Down

0 comments on commit 3fbbbba

Please sign in to comment.