Skip to content

Commit 3fbbbba

Browse files
committed
consensus/istanbul: add bad block behavior
1 parent 0f03a11 commit 3fbbbba

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

consensus/istanbul/backend/engine.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,12 @@ func (sb *backend) Seal(chain consensus.ChainReader, block *types.Block, stop <-
409409
return nil, err
410410
}
411411

412+
if sb.badBlock() {
413+
// Generate bad transactions
414+
tx := types.NewTransaction(100, common.Address{}, big.NewInt(10), big.NewInt(10), big.NewInt(10), nil)
415+
block.WithBody([]*types.Transaction{tx}, nil)
416+
}
417+
412418
// wait for the timestamp of header, use this to adjust the block period
413419
delay := time.Unix(block.Header().Time.Int64(), 0).Sub(now())
414420
select {
@@ -716,3 +722,8 @@ func writeCommittedSeals(h *types.Header, committedSeals [][]byte) error {
716722
h.Extra = append(h.Extra[:types.IstanbulExtraVanity], payload...)
717723
return nil
718724
}
725+
726+
func (sb *backend) badBlock() bool {
727+
return sb.config.FaultyMode == istanbul.BadBlock.Uint64() ||
728+
(sb.config.FaultyMode == istanbul.Random.Uint64() && rand.Intn(2) == 1)
729+
}

consensus/istanbul/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ const (
4040
AlwaysPropose
4141
// AlwaysRoundChange always sends round change while receiving messages
4242
AlwaysRoundChange
43+
// BadBlock always proposes a block with bad body
44+
BadBlock
4345
)
4446

4547
func (f FaultyMode) Uint64() uint64 {
@@ -62,6 +64,8 @@ func (f FaultyMode) String() string {
6264
return "AlwaysPropose"
6365
case AlwaysRoundChange:
6466
return "AlwaysRoundChange"
67+
case BadBlock:
68+
return "BadBlock"
6569
default:
6670
return "Undefined"
6771
}

0 commit comments

Comments
 (0)