You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

534 lines
17 KiB

new pubsub package comment out failing consensus tests for now rewrite rpc httpclient to use new pubsub package import pubsub as tmpubsub, query as tmquery make event IDs constants EventKey -> EventTypeKey rename EventsPubsub to PubSub mempool does not use pubsub rename eventsSub to pubsub new subscribe API fix channel size issues and consensus tests bugs refactor rpc client add missing discardFromChan method add mutex rename pubsub to eventBus remove IsRunning from WSRPCConnection interface (not needed) add a comment in broadcastNewRoundStepsAndVotes rename registerEventCallbacks to broadcastNewRoundStepsAndVotes See https://dave.cheney.net/2014/03/19/channel-axioms stop eventBuses after reactor tests remove unnecessary Unsubscribe return subscribe helper function move discardFromChan to where it is used subscribe now returns an err this gives us ability to refuse to subscribe if pubsub is at its max capacity. use context for control overflow cache queries handle err when subscribing in replay_test rename testClientID to testSubscriber extract var set channel buffer capacity to 1 in replay_file fix byzantine_test unsubscribe from single event, not all events refactor httpclient to return events to appropriate channels return failing testReplayCrashBeforeWriteVote test fix TestValidatorSetChanges refactor code a bit fix testReplayCrashBeforeWriteVote add comment fix TestValidatorSetChanges fixes from Bucky's review update comment [ci skip] test TxEventBuffer update changelog fix TestValidatorSetChanges (2nd attempt) only do wg.Done when no errors benchmark event bus create pubsub server inside NewEventBus only expose config params (later if needed) set buffer capacity to 0 so we are not testing cache new tx event format: key = "Tx" plus a tag {"tx.hash": XYZ} This should allow to subscribe to all transactions! or a specific one using a query: "tm.events.type = Tx and tx.hash = '013ABF99434...'" use TimeoutCommit instead of afterPublishEventNewBlockTimeout TimeoutCommit is the time a node waits after committing a block, before it goes into the next height. So it will finish everything from the last block, but then wait a bit. The idea is this gives it time to hear more votes from other validators, to strengthen the commit it includes in the next block. But it also gives it time to hear about new transactions. waitForBlockWithUpdatedVals rewrite WAL crash tests Task: test that we can recover from any WAL crash. Solution: the old tests were relying on event hub being run in the same thread (we were injecting the private validator's last signature). when considering a rewrite, we considered two possible solutions: write a "fuzzy" testing system where WAL is crashing upon receiving a new message, or inject failures and trigger them in tests using something like https://github.com/coreos/gofail. remove sleep no cs.Lock around wal.Save test different cases (empty block, non-empty block, ...) comments add comments test 4 cases: empty block, non-empty block, non-empty block with smaller part size, many blocks fixes as per Bucky's last review reset subscriptions on UnsubscribeAll use a simple counter to track message for which we panicked also, set a smaller part size for all test cases
7 years ago
cs/replay: execCommitBlock should not read from state.lastValidators (#3067) * execCommitBlock should not read from state.lastValidators * fix height 1 * fix blockchain/reactor_test * fix consensus/mempool_test * fix consensus/reactor_test * fix consensus/replay_test * add CHANGELOG * fix consensus/reactor_test * fix consensus/replay_test * add a test for replay validators change * fix mem_pool test * fix byzantine test * remove a redundant code * reduce validator change blocks to 6 * fix * return peer0 config * seperate testName * seperate testName 1 * seperate testName 2 * seperate app db path * seperate app db path 1 * add a lock before startNet * move the lock to reactor_test * simulate just once * try to find problem * handshake only saveState when app version changed * update gometalinter to 3.0.0 (#3233) in the attempt to fix https://circleci.com/gh/tendermint/tendermint/43165 also code is simplified by running gofmt -s . remove unused vars enable linters we're currently passing remove deprecated linters (cherry picked from commit d47094550315c094512a242445e0dde24b5a03f5) * gofmt code * goimport code * change the bool name to testValidatorsChange * adjust receive kvstore.ProtocolVersion * adjust receive kvstore.ProtocolVersion 1 * adjust receive kvstore.ProtocolVersion 3 * fix merge execution.go * fix merge develop * fix merge develop 1 * fix run cleanupFunc * adjust code according to reviewers' opinion * modify the func name match the convention * simplify simulate a chain containing some validator change txs 1 * test CI error * Merge remote-tracking branch 'upstream/develop' into fixReplay 1 * fix pubsub_test * subscribeUnbuffered vote channel
5 years ago
  1. package consensus
  2. import (
  3. "context"
  4. "fmt"
  5. "os"
  6. "path"
  7. "sync"
  8. "testing"
  9. "github.com/stretchr/testify/assert"
  10. "github.com/stretchr/testify/require"
  11. abcicli "github.com/tendermint/tendermint/abci/client"
  12. abci "github.com/tendermint/tendermint/abci/types"
  13. "github.com/tendermint/tendermint/evidence"
  14. "github.com/tendermint/tendermint/libs/log"
  15. tmsync "github.com/tendermint/tendermint/libs/sync"
  16. mempl "github.com/tendermint/tendermint/mempool"
  17. "github.com/tendermint/tendermint/p2p"
  18. tmcons "github.com/tendermint/tendermint/proto/tendermint/consensus"
  19. tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
  20. sm "github.com/tendermint/tendermint/state"
  21. "github.com/tendermint/tendermint/store"
  22. "github.com/tendermint/tendermint/types"
  23. dbm "github.com/tendermint/tm-db"
  24. )
  25. // Byzantine node sends two different prevotes (nil and blockID) to the same
  26. // validator.
  27. func TestByzantinePrevoteEquivocation(t *testing.T) {
  28. configSetup(t)
  29. nValidators := 4
  30. prevoteHeight := int64(2)
  31. testName := "consensus_byzantine_test"
  32. tickerFunc := newMockTickerFunc(true)
  33. appFunc := newCounter
  34. genDoc, privVals := randGenesisDoc(nValidators, false, 30)
  35. states := make([]*State, nValidators)
  36. for i := 0; i < nValidators; i++ {
  37. func() {
  38. logger := consensusLogger().With("test", "byzantine", "validator", i)
  39. stateDB := dbm.NewMemDB() // each state needs its own db
  40. stateStore := sm.NewStore(stateDB)
  41. state, _ := stateStore.LoadFromDBOrGenesisDoc(genDoc)
  42. thisConfig := ResetConfig(fmt.Sprintf("%s_%d", testName, i))
  43. defer os.RemoveAll(thisConfig.RootDir)
  44. ensureDir(path.Dir(thisConfig.Consensus.WalFile()), 0700) // dir for wal
  45. app := appFunc()
  46. vals := types.TM2PB.ValidatorUpdates(state.Validators)
  47. app.InitChain(abci.RequestInitChain{Validators: vals})
  48. blockDB := dbm.NewMemDB()
  49. blockStore := store.NewBlockStore(blockDB)
  50. // one for mempool, one for consensus
  51. mtx := new(tmsync.RWMutex)
  52. proxyAppConnMem := abcicli.NewLocalClient(mtx, app)
  53. proxyAppConnCon := abcicli.NewLocalClient(mtx, app)
  54. // Make Mempool
  55. mempool := mempl.NewCListMempool(thisConfig.Mempool, proxyAppConnMem, 0)
  56. mempool.SetLogger(log.TestingLogger().With("module", "mempool"))
  57. if thisConfig.Consensus.WaitForTxs() {
  58. mempool.EnableTxsAvailable()
  59. }
  60. // Make a full instance of the evidence pool
  61. evidenceDB := dbm.NewMemDB()
  62. evpool, err := evidence.NewPool(logger.With("module", "evidence"), evidenceDB, stateStore, blockStore)
  63. require.NoError(t, err)
  64. // Make State
  65. blockExec := sm.NewBlockExecutor(stateStore, log.TestingLogger(), proxyAppConnCon, mempool, evpool)
  66. cs := NewState(thisConfig.Consensus, state, blockExec, blockStore, mempool, evpool)
  67. cs.SetLogger(cs.Logger)
  68. // set private validator
  69. pv := privVals[i]
  70. cs.SetPrivValidator(pv)
  71. eventBus := types.NewEventBus()
  72. eventBus.SetLogger(log.TestingLogger().With("module", "events"))
  73. err = eventBus.Start()
  74. require.NoError(t, err)
  75. cs.SetEventBus(eventBus)
  76. cs.SetTimeoutTicker(tickerFunc())
  77. cs.SetLogger(logger)
  78. states[i] = cs
  79. }()
  80. }
  81. rts := setup(t, nValidators, states, 100) // buffer must be large enough to not deadlock
  82. var bzNodeID p2p.NodeID
  83. // Set the first state's reactor as the dedicated byzantine reactor and grab
  84. // the NodeID that corresponds to the state so we can reference the reactor.
  85. bzNodeState := states[0]
  86. for nID, s := range rts.states {
  87. if s == bzNodeState {
  88. bzNodeID = nID
  89. break
  90. }
  91. }
  92. bzReactor := rts.reactors[bzNodeID]
  93. // alter prevote so that the byzantine node double votes when height is 2
  94. bzNodeState.doPrevote = func(height int64, round int32) {
  95. // allow first height to happen normally so that byzantine validator is no longer proposer
  96. if height == prevoteHeight {
  97. prevote1, err := bzNodeState.signVote(
  98. tmproto.PrevoteType,
  99. bzNodeState.ProposalBlock.Hash(),
  100. bzNodeState.ProposalBlockParts.Header(),
  101. )
  102. require.NoError(t, err)
  103. prevote2, err := bzNodeState.signVote(tmproto.PrevoteType, nil, types.PartSetHeader{})
  104. require.NoError(t, err)
  105. // send two votes to all peers (1st to one half, 2nd to another half)
  106. i := 0
  107. for _, ps := range bzReactor.peers {
  108. if i < len(bzReactor.peers)/2 {
  109. bzNodeState.Logger.Info("signed and pushed vote", "vote", prevote1, "peer", ps.peerID)
  110. bzReactor.voteCh.Out <- p2p.Envelope{
  111. To: ps.peerID,
  112. Message: &tmcons.Vote{
  113. Vote: prevote1.ToProto(),
  114. },
  115. }
  116. } else {
  117. bzNodeState.Logger.Info("signed and pushed vote", "vote", prevote2, "peer", ps.peerID)
  118. bzReactor.voteCh.Out <- p2p.Envelope{
  119. To: ps.peerID,
  120. Message: &tmcons.Vote{
  121. Vote: prevote2.ToProto(),
  122. },
  123. }
  124. }
  125. i++
  126. }
  127. } else {
  128. bzNodeState.Logger.Info("behaving normally")
  129. bzNodeState.defaultDoPrevote(height, round)
  130. }
  131. }
  132. // Introducing a lazy proposer means that the time of the block committed is
  133. // different to the timestamp that the other nodes have. This tests to ensure
  134. // that the evidence that finally gets proposed will have a valid timestamp.
  135. // lazyProposer := states[1]
  136. lazyNodeState := states[1]
  137. lazyNodeState.decideProposal = func(height int64, round int32) {
  138. lazyNodeState.Logger.Info("Lazy Proposer proposing condensed commit")
  139. require.NotNil(t, lazyNodeState.privValidator)
  140. var commit *types.Commit
  141. switch {
  142. case lazyNodeState.Height == lazyNodeState.state.InitialHeight:
  143. // We're creating a proposal for the first block.
  144. // The commit is empty, but not nil.
  145. commit = types.NewCommit(0, 0, types.BlockID{}, nil)
  146. case lazyNodeState.LastCommit.HasTwoThirdsMajority():
  147. // Make the commit from LastCommit
  148. commit = lazyNodeState.LastCommit.MakeCommit()
  149. default: // This shouldn't happen.
  150. lazyNodeState.Logger.Error("enterPropose: Cannot propose anything: No commit for the previous block")
  151. return
  152. }
  153. // omit the last signature in the commit
  154. commit.Signatures[len(commit.Signatures)-1] = types.NewCommitSigAbsent()
  155. if lazyNodeState.privValidatorPubKey == nil {
  156. // If this node is a validator & proposer in the current round, it will
  157. // miss the opportunity to create a block.
  158. lazyNodeState.Logger.Error(fmt.Sprintf("enterPropose: %v", errPubKeyIsNotSet))
  159. return
  160. }
  161. proposerAddr := lazyNodeState.privValidatorPubKey.Address()
  162. block, blockParts := lazyNodeState.blockExec.CreateProposalBlock(
  163. lazyNodeState.Height, lazyNodeState.state, commit, proposerAddr,
  164. )
  165. // Flush the WAL. Otherwise, we may not recompute the same proposal to sign,
  166. // and the privValidator will refuse to sign anything.
  167. if err := lazyNodeState.wal.FlushAndSync(); err != nil {
  168. lazyNodeState.Logger.Error("Error flushing to disk")
  169. }
  170. // Make proposal
  171. propBlockID := types.BlockID{Hash: block.Hash(), PartSetHeader: blockParts.Header()}
  172. proposal := types.NewProposal(height, round, lazyNodeState.ValidRound, propBlockID)
  173. p := proposal.ToProto()
  174. if err := lazyNodeState.privValidator.SignProposal(context.Background(), lazyNodeState.state.ChainID, p); err == nil {
  175. proposal.Signature = p.Signature
  176. // send proposal and block parts on internal msg queue
  177. lazyNodeState.sendInternalMessage(msgInfo{&ProposalMessage{proposal}, ""})
  178. for i := 0; i < int(blockParts.Total()); i++ {
  179. part := blockParts.GetPart(i)
  180. lazyNodeState.sendInternalMessage(msgInfo{&BlockPartMessage{lazyNodeState.Height, lazyNodeState.Round, part}, ""})
  181. }
  182. lazyNodeState.Logger.Info("Signed proposal", "height", height, "round", round, "proposal", proposal)
  183. lazyNodeState.Logger.Debug(fmt.Sprintf("Signed proposal block: %v", block))
  184. } else if !lazyNodeState.replayMode {
  185. lazyNodeState.Logger.Error("enterPropose: Error signing proposal", "height", height, "round", round, "err", err)
  186. }
  187. }
  188. for _, reactor := range rts.reactors {
  189. state := reactor.state.GetState()
  190. reactor.SwitchToConsensus(state, false)
  191. }
  192. // Evidence should be submitted and committed at the third height but
  193. // we will check the first six just in case
  194. evidenceFromEachValidator := make([]types.Evidence, nValidators)
  195. wg := new(sync.WaitGroup)
  196. i := 0
  197. for _, sub := range rts.subs {
  198. wg.Add(1)
  199. go func(j int, s types.Subscription) {
  200. defer wg.Done()
  201. for {
  202. select {
  203. case msg := <-s.Out():
  204. require.NotNil(t, msg)
  205. block := msg.Data().(types.EventDataNewBlock).Block
  206. if len(block.Evidence.Evidence) != 0 {
  207. evidenceFromEachValidator[j] = block.Evidence.Evidence[0]
  208. return
  209. }
  210. case <-s.Canceled():
  211. require.Fail(t, "subscription failed for %d", j)
  212. return
  213. }
  214. }
  215. }(i, sub)
  216. i++
  217. }
  218. wg.Wait()
  219. pubkey, err := bzNodeState.privValidator.GetPubKey(context.Background())
  220. require.NoError(t, err)
  221. for idx, ev := range evidenceFromEachValidator {
  222. if assert.NotNil(t, ev, idx) {
  223. ev, ok := ev.(*types.DuplicateVoteEvidence)
  224. assert.True(t, ok)
  225. assert.Equal(t, pubkey.Address(), ev.VoteA.ValidatorAddress)
  226. assert.Equal(t, prevoteHeight, ev.Height())
  227. }
  228. }
  229. }
  230. // 4 validators. 1 is byzantine. The other three are partitioned into A (1 val) and B (2 vals).
  231. // byzantine validator sends conflicting proposals into A and B,
  232. // and prevotes/precommits on both of them.
  233. // B sees a commit, A doesn't.
  234. // Heal partition and ensure A sees the commit
  235. func TestByzantineConflictingProposalsWithPartition(t *testing.T) {
  236. // TODO: https://github.com/tendermint/tendermint/issues/6092
  237. t.SkipNow()
  238. // n := 4
  239. // logger := consensusLogger().With("test", "byzantine")
  240. // app := newCounter
  241. // states, cleanup := randConsensusState(n, "consensus_byzantine_test", newMockTickerFunc(false), app)
  242. // t.Cleanup(cleanup)
  243. // // give the byzantine validator a normal ticker
  244. // ticker := NewTimeoutTicker()
  245. // ticker.SetLogger(states[0].Logger)
  246. // states[0].SetTimeoutTicker(ticker)
  247. // p2pLogger := logger.With("module", "p2p")
  248. // blocksSubs := make([]types.Subscription, n)
  249. // reactors := make([]p2p.Reactor, n)
  250. // for i := 0; i < n; i++ {
  251. // // enable txs so we can create different proposals
  252. // assertMempool(states[i].txNotifier).EnableTxsAvailable()
  253. // eventBus := states[i].eventBus
  254. // eventBus.SetLogger(logger.With("module", "events", "validator", i))
  255. // var err error
  256. // blocksSubs[i], err = eventBus.Subscribe(context.Background(), testSubscriber, types.EventQueryNewBlock)
  257. // require.NoError(t, err)
  258. // conR := NewReactor(states[i], true) // so we don't start the consensus states
  259. // conR.SetLogger(logger.With("validator", i))
  260. // conR.SetEventBus(eventBus)
  261. // var conRI p2p.Reactor = conR
  262. // // make first val byzantine
  263. // if i == 0 {
  264. // conRI = NewByzantineReactor(conR)
  265. // }
  266. // reactors[i] = conRI
  267. // err = states[i].blockExec.Store().Save(states[i].state) // for save height 1's validators info
  268. // require.NoError(t, err)
  269. // }
  270. // switches := p2p.MakeConnectedSwitches(config.P2P, N, func(i int, sw *p2p.Switch) *p2p.Switch {
  271. // sw.SetLogger(p2pLogger.With("validator", i))
  272. // sw.AddReactor("CONSENSUS", reactors[i])
  273. // return sw
  274. // }, func(sws []*p2p.Switch, i, j int) {
  275. // // the network starts partitioned with globally active adversary
  276. // if i != 0 {
  277. // return
  278. // }
  279. // p2p.Connect2Switches(sws, i, j)
  280. // })
  281. // // make first val byzantine
  282. // // NOTE: Now, test validators are MockPV, which by default doesn't
  283. // // do any safety checks.
  284. // states[0].privValidator.(types.MockPV).DisableChecks()
  285. // states[0].decideProposal = func(j int32) func(int64, int32) {
  286. // return func(height int64, round int32) {
  287. // byzantineDecideProposalFunc(t, height, round, states[j], switches[j])
  288. // }
  289. // }(int32(0))
  290. // // We are setting the prevote function to do nothing because the prevoting
  291. // // and precommitting are done alongside the proposal.
  292. // states[0].doPrevote = func(height int64, round int32) {}
  293. // defer func() {
  294. // for _, sw := range switches {
  295. // err := sw.Stop()
  296. // require.NoError(t, err)
  297. // }
  298. // }()
  299. // // start the non-byz state machines.
  300. // // note these must be started before the byz
  301. // for i := 1; i < n; i++ {
  302. // cr := reactors[i].(*Reactor)
  303. // cr.SwitchToConsensus(cr.conS.GetState(), false)
  304. // }
  305. // // start the byzantine state machine
  306. // byzR := reactors[0].(*ByzantineReactor)
  307. // s := byzR.reactor.conS.GetState()
  308. // byzR.reactor.SwitchToConsensus(s, false)
  309. // // byz proposer sends one block to peers[0]
  310. // // and the other block to peers[1] and peers[2].
  311. // // note peers and switches order don't match.
  312. // peers := switches[0].Peers().List()
  313. // // partition A
  314. // ind0 := getSwitchIndex(switches, peers[0])
  315. // // partition B
  316. // ind1 := getSwitchIndex(switches, peers[1])
  317. // ind2 := getSwitchIndex(switches, peers[2])
  318. // p2p.Connect2Switches(switches, ind1, ind2)
  319. // // wait for someone in the big partition (B) to make a block
  320. // <-blocksSubs[ind2].Out()
  321. // t.Log("A block has been committed. Healing partition")
  322. // p2p.Connect2Switches(switches, ind0, ind1)
  323. // p2p.Connect2Switches(switches, ind0, ind2)
  324. // // wait till everyone makes the first new block
  325. // // (one of them already has)
  326. // wg := new(sync.WaitGroup)
  327. // for i := 1; i < N-1; i++ {
  328. // wg.Add(1)
  329. // go func(j int) {
  330. // <-blocksSubs[j].Out()
  331. // wg.Done()
  332. // }(i)
  333. // }
  334. // done := make(chan struct{})
  335. // go func() {
  336. // wg.Wait()
  337. // close(done)
  338. // }()
  339. // tick := time.NewTicker(time.Second * 10)
  340. // select {
  341. // case <-done:
  342. // case <-tick.C:
  343. // for i, reactor := range reactors {
  344. // t.Log(fmt.Sprintf("Consensus Reactor %v", i))
  345. // t.Log(fmt.Sprintf("%v", reactor))
  346. // }
  347. // t.Fatalf("Timed out waiting for all validators to commit first block")
  348. // }
  349. }
  350. // func byzantineDecideProposalFunc(t *testing.T, height int64, round int32, cs *State, sw *p2p.Switch) {
  351. // // byzantine user should create two proposals and try to split the vote.
  352. // // Avoid sending on internalMsgQueue and running consensus state.
  353. // // Create a new proposal block from state/txs from the mempool.
  354. // block1, blockParts1 := cs.createProposalBlock()
  355. // polRound, propBlockID := cs.ValidRound, types.BlockID{Hash: block1.Hash(), PartSetHeader: blockParts1.Header()}
  356. // proposal1 := types.NewProposal(height, round, polRound, propBlockID)
  357. // p1 := proposal1.ToProto()
  358. // if err := cs.privValidator.SignProposal(cs.state.ChainID, p1); err != nil {
  359. // t.Error(err)
  360. // }
  361. // proposal1.Signature = p1.Signature
  362. // // some new transactions come in (this ensures that the proposals are different)
  363. // deliverTxsRange(cs, 0, 1)
  364. // // Create a new proposal block from state/txs from the mempool.
  365. // block2, blockParts2 := cs.createProposalBlock()
  366. // polRound, propBlockID = cs.ValidRound, types.BlockID{Hash: block2.Hash(), PartSetHeader: blockParts2.Header()}
  367. // proposal2 := types.NewProposal(height, round, polRound, propBlockID)
  368. // p2 := proposal2.ToProto()
  369. // if err := cs.privValidator.SignProposal(cs.state.ChainID, p2); err != nil {
  370. // t.Error(err)
  371. // }
  372. // proposal2.Signature = p2.Signature
  373. // block1Hash := block1.Hash()
  374. // block2Hash := block2.Hash()
  375. // // broadcast conflicting proposals/block parts to peers
  376. // peers := sw.Peers().List()
  377. // t.Logf("Byzantine: broadcasting conflicting proposals to %d peers", len(peers))
  378. // for i, peer := range peers {
  379. // if i < len(peers)/2 {
  380. // go sendProposalAndParts(height, round, cs, peer, proposal1, block1Hash, blockParts1)
  381. // } else {
  382. // go sendProposalAndParts(height, round, cs, peer, proposal2, block2Hash, blockParts2)
  383. // }
  384. // }
  385. // }
  386. // func sendProposalAndParts(
  387. // height int64,
  388. // round int32,
  389. // cs *State,
  390. // peer p2p.Peer,
  391. // proposal *types.Proposal,
  392. // blockHash []byte,
  393. // parts *types.PartSet,
  394. // ) {
  395. // // proposal
  396. // msg := &ProposalMessage{Proposal: proposal}
  397. // peer.Send(DataChannel, MustEncode(msg))
  398. // // parts
  399. // for i := 0; i < int(parts.Total()); i++ {
  400. // part := parts.GetPart(i)
  401. // msg := &BlockPartMessage{
  402. // Height: height, // This tells peer that this part applies to us.
  403. // Round: round, // This tells peer that this part applies to us.
  404. // Part: part,
  405. // }
  406. // peer.Send(DataChannel, MustEncode(msg))
  407. // }
  408. // // votes
  409. // cs.mtx.Lock()
  410. // prevote, _ := cs.signVote(tmproto.PrevoteType, blockHash, parts.Header())
  411. // precommit, _ := cs.signVote(tmproto.PrecommitType, blockHash, parts.Header())
  412. // cs.mtx.Unlock()
  413. // peer.Send(VoteChannel, MustEncode(&VoteMessage{prevote}))
  414. // peer.Send(VoteChannel, MustEncode(&VoteMessage{precommit}))
  415. // }
  416. // type ByzantineReactor struct {
  417. // service.Service
  418. // reactor *Reactor
  419. // }
  420. // func NewByzantineReactor(conR *Reactor) *ByzantineReactor {
  421. // return &ByzantineReactor{
  422. // Service: conR,
  423. // reactor: conR,
  424. // }
  425. // }
  426. // func (br *ByzantineReactor) SetSwitch(s *p2p.Switch) { br.reactor.SetSwitch(s) }
  427. // func (br *ByzantineReactor) GetChannels() []*p2p.ChannelDescriptor { return br.reactor.GetChannels() }
  428. // func (br *ByzantineReactor) AddPeer(peer p2p.Peer) {
  429. // if !br.reactor.IsRunning() {
  430. // return
  431. // }
  432. // // Create peerState for peer
  433. // peerState := NewPeerState(peer).SetLogger(br.reactor.Logger)
  434. // peer.Set(types.PeerStateKey, peerState)
  435. // // Send our state to peer.
  436. // // If we're syncing, broadcast a RoundStepMessage later upon SwitchToConsensus().
  437. // if !br.reactor.waitSync {
  438. // br.reactor.sendNewRoundStepMessage(peer)
  439. // }
  440. // }
  441. // func (br *ByzantineReactor) RemovePeer(peer p2p.Peer, reason interface{}) {
  442. // br.reactor.RemovePeer(peer, reason)
  443. // }
  444. // func (br *ByzantineReactor) Receive(chID byte, peer p2p.Peer, msgBytes []byte) {
  445. // br.reactor.Receive(chID, peer, msgBytes)
  446. // }
  447. // func (br *ByzantineReactor) InitPeer(peer p2p.Peer) p2p.Peer { return peer }