(t *testing.T)
| 15 | ) |
| 16 | |
| 17 | func TestReactorInvalidPrecommit(t *testing.T) { |
| 18 | config := configSetup(t) |
| 19 | |
| 20 | n := 4 |
| 21 | states, cleanup := randConsensusState(t, |
| 22 | config, n, "consensus_reactor_test", |
| 23 | newMockTickerFunc(true), newKVStore) |
| 24 | t.Cleanup(cleanup) |
| 25 | |
| 26 | for i := 0; i < 4; i++ { |
| 27 | ticker := NewTimeoutTicker() |
| 28 | ticker.SetLogger(states[i].Logger) |
| 29 | states[i].SetTimeoutTicker(ticker) |
| 30 | } |
| 31 | |
| 32 | rts := setup(t, n, states, 100) // buffer must be large enough to not deadlock |
| 33 | |
| 34 | for _, reactor := range rts.reactors { |
| 35 | state := reactor.state.GetState() |
| 36 | reactor.SwitchToConsensus(state, false) |
| 37 | } |
| 38 | |
| 39 | // this val sends a random precommit at each height |
| 40 | node := rts.network.RandomNode() |
| 41 | |
| 42 | byzState := rts.states[node.NodeID] |
| 43 | byzReactor := rts.reactors[node.NodeID] |
| 44 | |
| 45 | // Update the doPrevote function to just send a valid precommit for a random |
| 46 | // block and otherwise disable the priv validator. |
| 47 | byzState.mtx.Lock() |
| 48 | privVal := byzState.privValidator |
| 49 | byzState.doPrevote = func(height int64, round int32) { |
| 50 | invalidDoPrevoteFunc(t, height, round, byzState, byzReactor, privVal) |
| 51 | } |
| 52 | byzState.mtx.Unlock() |
| 53 | |
| 54 | // wait for a bunch of blocks |
| 55 | // |
| 56 | // TODO: Make this tighter by ensuring the halt happens by block 2. |
| 57 | var wg sync.WaitGroup |
| 58 | for i := 0; i < 10; i++ { |
| 59 | for _, sub := range rts.subs { |
| 60 | wg.Add(1) |
| 61 | |
| 62 | go func(s types.Subscription) { |
| 63 | <-s.Out() |
| 64 | wg.Done() |
| 65 | }(sub) |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | wg.Wait() |
| 70 | } |
| 71 | |
| 72 | func invalidDoPrevoteFunc(t *testing.T, height int64, round int32, cs *State, r *Reactor, pv types.PrivValidator) { |
| 73 | // routine to: |
nothing calls this directly
no test coverage detected
searching dependent graphs…