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.

535 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
8 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
6 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. tmsync "github.com/tendermint/tendermint/internal/libs/sync"
  15. "github.com/tendermint/tendermint/internal/test/factory"
  16. "github.com/tendermint/tendermint/libs/log"
  17. mempoolv0 "github.com/tendermint/tendermint/mempool/v0"
  18. "github.com/tendermint/tendermint/p2p"
  19. tmcons "github.com/tendermint/tendermint/proto/tendermint/consensus"
  20. tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
  21. sm "github.com/tendermint/tendermint/state"
  22. "github.com/tendermint/tendermint/store"
  23. "github.com/tendermint/tendermint/types"
  24. dbm "github.com/tendermint/tm-db"
  25. )
  26. // Byzantine node sends two different prevotes (nil and blockID) to the same
  27. // validator.
  28. func TestByzantinePrevoteEquivocation(t *testing.T) {
  29. config := configSetup(t)
  30. nValidators := 4
  31. prevoteHeight := int64(2)
  32. testName := "consensus_byzantine_test"
  33. tickerFunc := newMockTickerFunc(true)
  34. appFunc := newCounter
  35. genDoc, privVals := factory.RandGenesisDoc(config, nValidators, false, 30)
  36. states := make([]*State, nValidators)
  37. for i := 0; i < nValidators; i++ {
  38. func() {
  39. logger := consensusLogger().With("test", "byzantine", "validator", i)
  40. stateDB := dbm.NewMemDB() // each state needs its own db
  41. stateStore := sm.NewStore(stateDB)
  42. state, _ := stateStore.LoadFromDBOrGenesisDoc(genDoc)
  43. thisConfig := ResetConfig(fmt.Sprintf("%s_%d", testName, i))
  44. defer os.RemoveAll(thisConfig.RootDir)
  45. ensureDir(path.Dir(thisConfig.Consensus.WalFile()), 0700) // dir for wal
  46. app := appFunc()
  47. vals := types.TM2PB.ValidatorUpdates(state.Validators)
  48. app.InitChain(abci.RequestInitChain{Validators: vals})
  49. blockDB := dbm.NewMemDB()
  50. blockStore := store.NewBlockStore(blockDB)
  51. // one for mempool, one for consensus
  52. mtx := new(tmsync.RWMutex)
  53. proxyAppConnMem := abcicli.NewLocalClient(mtx, app)
  54. proxyAppConnCon := abcicli.NewLocalClient(mtx, app)
  55. // Make Mempool
  56. mempool := mempoolv0.NewCListMempool(thisConfig.Mempool, proxyAppConnMem, 0)
  57. mempool.SetLogger(log.TestingLogger().With("module", "mempool"))
  58. if thisConfig.Consensus.WaitForTxs() {
  59. mempool.EnableTxsAvailable()
  60. }
  61. // Make a full instance of the evidence pool
  62. evidenceDB := dbm.NewMemDB()
  63. evpool, err := evidence.NewPool(logger.With("module", "evidence"), evidenceDB, stateStore, blockStore)
  64. require.NoError(t, err)
  65. // Make State
  66. blockExec := sm.NewBlockExecutor(stateStore, log.TestingLogger(), proxyAppConnCon, mempool, evpool)
  67. cs := NewState(thisConfig.Consensus, state, blockExec, blockStore, mempool, evpool)
  68. cs.SetLogger(cs.Logger)
  69. // set private validator
  70. pv := privVals[i]
  71. cs.SetPrivValidator(pv)
  72. eventBus := types.NewEventBus()
  73. eventBus.SetLogger(log.TestingLogger().With("module", "events"))
  74. err = eventBus.Start()
  75. require.NoError(t, err)
  76. cs.SetEventBus(eventBus)
  77. cs.SetTimeoutTicker(tickerFunc())
  78. cs.SetLogger(logger)
  79. states[i] = cs
  80. }()
  81. }
  82. rts := setup(t, nValidators, states, 100) // buffer must be large enough to not deadlock
  83. var bzNodeID p2p.NodeID
  84. // Set the first state's reactor as the dedicated byzantine reactor and grab
  85. // the NodeID that corresponds to the state so we can reference the reactor.
  86. bzNodeState := states[0]
  87. for nID, s := range rts.states {
  88. if s == bzNodeState {
  89. bzNodeID = nID
  90. break
  91. }
  92. }
  93. bzReactor := rts.reactors[bzNodeID]
  94. // alter prevote so that the byzantine node double votes when height is 2
  95. bzNodeState.doPrevote = func(height int64, round int32) {
  96. // allow first height to happen normally so that byzantine validator is no longer proposer
  97. if height == prevoteHeight {
  98. prevote1, err := bzNodeState.signVote(
  99. tmproto.PrevoteType,
  100. bzNodeState.ProposalBlock.Hash(),
  101. bzNodeState.ProposalBlockParts.Header(),
  102. )
  103. require.NoError(t, err)
  104. prevote2, err := bzNodeState.signVote(tmproto.PrevoteType, nil, types.PartSetHeader{})
  105. require.NoError(t, err)
  106. // send two votes to all peers (1st to one half, 2nd to another half)
  107. i := 0
  108. for _, ps := range bzReactor.peers {
  109. if i < len(bzReactor.peers)/2 {
  110. bzNodeState.Logger.Info("signed and pushed vote", "vote", prevote1, "peer", ps.peerID)
  111. bzReactor.voteCh.Out <- p2p.Envelope{
  112. To: ps.peerID,
  113. Message: &tmcons.Vote{
  114. Vote: prevote1.ToProto(),
  115. },
  116. }
  117. } else {
  118. bzNodeState.Logger.Info("signed and pushed vote", "vote", prevote2, "peer", ps.peerID)
  119. bzReactor.voteCh.Out <- p2p.Envelope{
  120. To: ps.peerID,
  121. Message: &tmcons.Vote{
  122. Vote: prevote2.ToProto(),
  123. },
  124. }
  125. }
  126. i++
  127. }
  128. } else {
  129. bzNodeState.Logger.Info("behaving normally")
  130. bzNodeState.defaultDoPrevote(height, round)
  131. }
  132. }
  133. // Introducing a lazy proposer means that the time of the block committed is
  134. // different to the timestamp that the other nodes have. This tests to ensure
  135. // that the evidence that finally gets proposed will have a valid timestamp.
  136. // lazyProposer := states[1]
  137. lazyNodeState := states[1]
  138. lazyNodeState.decideProposal = func(height int64, round int32) {
  139. lazyNodeState.Logger.Info("Lazy Proposer proposing condensed commit")
  140. require.NotNil(t, lazyNodeState.privValidator)
  141. var commit *types.Commit
  142. switch {
  143. case lazyNodeState.Height == lazyNodeState.state.InitialHeight:
  144. // We're creating a proposal for the first block.
  145. // The commit is empty, but not nil.
  146. commit = types.NewCommit(0, 0, types.BlockID{}, nil)
  147. case lazyNodeState.LastCommit.HasTwoThirdsMajority():
  148. // Make the commit from LastCommit
  149. commit = lazyNodeState.LastCommit.MakeCommit()
  150. default: // This shouldn't happen.
  151. lazyNodeState.Logger.Error("enterPropose: Cannot propose anything: No commit for the previous block")
  152. return
  153. }
  154. // omit the last signature in the commit
  155. commit.Signatures[len(commit.Signatures)-1] = types.NewCommitSigAbsent()
  156. if lazyNodeState.privValidatorPubKey == nil {
  157. // If this node is a validator & proposer in the current round, it will
  158. // miss the opportunity to create a block.
  159. lazyNodeState.Logger.Error(fmt.Sprintf("enterPropose: %v", errPubKeyIsNotSet))
  160. return
  161. }
  162. proposerAddr := lazyNodeState.privValidatorPubKey.Address()
  163. block, blockParts := lazyNodeState.blockExec.CreateProposalBlock(
  164. lazyNodeState.Height, lazyNodeState.state, commit, proposerAddr,
  165. )
  166. // Flush the WAL. Otherwise, we may not recompute the same proposal to sign,
  167. // and the privValidator will refuse to sign anything.
  168. if err := lazyNodeState.wal.FlushAndSync(); err != nil {
  169. lazyNodeState.Logger.Error("Error flushing to disk")
  170. }
  171. // Make proposal
  172. propBlockID := types.BlockID{Hash: block.Hash(), PartSetHeader: blockParts.Header()}
  173. proposal := types.NewProposal(height, round, lazyNodeState.ValidRound, propBlockID)
  174. p := proposal.ToProto()
  175. if err := lazyNodeState.privValidator.SignProposal(context.Background(), lazyNodeState.state.ChainID, p); err == nil {
  176. proposal.Signature = p.Signature
  177. // send proposal and block parts on internal msg queue
  178. lazyNodeState.sendInternalMessage(msgInfo{&ProposalMessage{proposal}, ""})
  179. for i := 0; i < int(blockParts.Total()); i++ {
  180. part := blockParts.GetPart(i)
  181. lazyNodeState.sendInternalMessage(msgInfo{&BlockPartMessage{lazyNodeState.Height, lazyNodeState.Round, part}, ""})
  182. }
  183. lazyNodeState.Logger.Info("Signed proposal", "height", height, "round", round, "proposal", proposal)
  184. lazyNodeState.Logger.Debug(fmt.Sprintf("Signed proposal block: %v", block))
  185. } else if !lazyNodeState.replayMode {
  186. lazyNodeState.Logger.Error("enterPropose: Error signing proposal", "height", height, "round", round, "err", err)
  187. }
  188. }
  189. for _, reactor := range rts.reactors {
  190. state := reactor.state.GetState()
  191. reactor.SwitchToConsensus(state, false)
  192. }
  193. // Evidence should be submitted and committed at the third height but
  194. // we will check the first six just in case
  195. evidenceFromEachValidator := make([]types.Evidence, nValidators)
  196. wg := new(sync.WaitGroup)
  197. i := 0
  198. for _, sub := range rts.subs {
  199. wg.Add(1)
  200. go func(j int, s types.Subscription) {
  201. defer wg.Done()
  202. for {
  203. select {
  204. case msg := <-s.Out():
  205. require.NotNil(t, msg)
  206. block := msg.Data().(types.EventDataNewBlock).Block
  207. if len(block.Evidence.Evidence) != 0 {
  208. evidenceFromEachValidator[j] = block.Evidence.Evidence[0]
  209. return
  210. }
  211. case <-s.Canceled():
  212. require.Fail(t, "subscription failed for %d", j)
  213. return
  214. }
  215. }
  216. }(i, sub)
  217. i++
  218. }
  219. wg.Wait()
  220. pubkey, err := bzNodeState.privValidator.GetPubKey(context.Background())
  221. require.NoError(t, err)
  222. for idx, ev := range evidenceFromEachValidator {
  223. if assert.NotNil(t, ev, idx) {
  224. ev, ok := ev.(*types.DuplicateVoteEvidence)
  225. assert.True(t, ok)
  226. assert.Equal(t, pubkey.Address(), ev.VoteA.ValidatorAddress)
  227. assert.Equal(t, prevoteHeight, ev.Height())
  228. }
  229. }
  230. }
  231. // 4 validators. 1 is byzantine. The other three are partitioned into A (1 val) and B (2 vals).
  232. // byzantine validator sends conflicting proposals into A and B,
  233. // and prevotes/precommits on both of them.
  234. // B sees a commit, A doesn't.
  235. // Heal partition and ensure A sees the commit
  236. func TestByzantineConflictingProposalsWithPartition(t *testing.T) {
  237. // TODO: https://github.com/tendermint/tendermint/issues/6092
  238. t.SkipNow()
  239. // n := 4
  240. // logger := consensusLogger().With("test", "byzantine")
  241. // app := newCounter
  242. // states, cleanup := randConsensusState(n, "consensus_byzantine_test", newMockTickerFunc(false), app)
  243. // t.Cleanup(cleanup)
  244. // // give the byzantine validator a normal ticker
  245. // ticker := NewTimeoutTicker()
  246. // ticker.SetLogger(states[0].Logger)
  247. // states[0].SetTimeoutTicker(ticker)
  248. // p2pLogger := logger.With("module", "p2p")
  249. // blocksSubs := make([]types.Subscription, n)
  250. // reactors := make([]p2p.Reactor, n)
  251. // for i := 0; i < n; i++ {
  252. // // enable txs so we can create different proposals
  253. // assertMempool(states[i].txNotifier).EnableTxsAvailable()
  254. // eventBus := states[i].eventBus
  255. // eventBus.SetLogger(logger.With("module", "events", "validator", i))
  256. // var err error
  257. // blocksSubs[i], err = eventBus.Subscribe(context.Background(), testSubscriber, types.EventQueryNewBlock)
  258. // require.NoError(t, err)
  259. // conR := NewReactor(states[i], true) // so we don't start the consensus states
  260. // conR.SetLogger(logger.With("validator", i))
  261. // conR.SetEventBus(eventBus)
  262. // var conRI p2p.Reactor = conR
  263. // // make first val byzantine
  264. // if i == 0 {
  265. // conRI = NewByzantineReactor(conR)
  266. // }
  267. // reactors[i] = conRI
  268. // err = states[i].blockExec.Store().Save(states[i].state) // for save height 1's validators info
  269. // require.NoError(t, err)
  270. // }
  271. // switches := p2p.MakeConnectedSwitches(config.P2P, N, func(i int, sw *p2p.Switch) *p2p.Switch {
  272. // sw.SetLogger(p2pLogger.With("validator", i))
  273. // sw.AddReactor("CONSENSUS", reactors[i])
  274. // return sw
  275. // }, func(sws []*p2p.Switch, i, j int) {
  276. // // the network starts partitioned with globally active adversary
  277. // if i != 0 {
  278. // return
  279. // }
  280. // p2p.Connect2Switches(sws, i, j)
  281. // })
  282. // // make first val byzantine
  283. // // NOTE: Now, test validators are MockPV, which by default doesn't
  284. // // do any safety checks.
  285. // states[0].privValidator.(types.MockPV).DisableChecks()
  286. // states[0].decideProposal = func(j int32) func(int64, int32) {
  287. // return func(height int64, round int32) {
  288. // byzantineDecideProposalFunc(t, height, round, states[j], switches[j])
  289. // }
  290. // }(int32(0))
  291. // // We are setting the prevote function to do nothing because the prevoting
  292. // // and precommitting are done alongside the proposal.
  293. // states[0].doPrevote = func(height int64, round int32) {}
  294. // defer func() {
  295. // for _, sw := range switches {
  296. // err := sw.Stop()
  297. // require.NoError(t, err)
  298. // }
  299. // }()
  300. // // start the non-byz state machines.
  301. // // note these must be started before the byz
  302. // for i := 1; i < n; i++ {
  303. // cr := reactors[i].(*Reactor)
  304. // cr.SwitchToConsensus(cr.conS.GetState(), false)
  305. // }
  306. // // start the byzantine state machine
  307. // byzR := reactors[0].(*ByzantineReactor)
  308. // s := byzR.reactor.conS.GetState()
  309. // byzR.reactor.SwitchToConsensus(s, false)
  310. // // byz proposer sends one block to peers[0]
  311. // // and the other block to peers[1] and peers[2].
  312. // // note peers and switches order don't match.
  313. // peers := switches[0].Peers().List()
  314. // // partition A
  315. // ind0 := getSwitchIndex(switches, peers[0])
  316. // // partition B
  317. // ind1 := getSwitchIndex(switches, peers[1])
  318. // ind2 := getSwitchIndex(switches, peers[2])
  319. // p2p.Connect2Switches(switches, ind1, ind2)
  320. // // wait for someone in the big partition (B) to make a block
  321. // <-blocksSubs[ind2].Out()
  322. // t.Log("A block has been committed. Healing partition")
  323. // p2p.Connect2Switches(switches, ind0, ind1)
  324. // p2p.Connect2Switches(switches, ind0, ind2)
  325. // // wait till everyone makes the first new block
  326. // // (one of them already has)
  327. // wg := new(sync.WaitGroup)
  328. // for i := 1; i < N-1; i++ {
  329. // wg.Add(1)
  330. // go func(j int) {
  331. // <-blocksSubs[j].Out()
  332. // wg.Done()
  333. // }(i)
  334. // }
  335. // done := make(chan struct{})
  336. // go func() {
  337. // wg.Wait()
  338. // close(done)
  339. // }()
  340. // tick := time.NewTicker(time.Second * 10)
  341. // select {
  342. // case <-done:
  343. // case <-tick.C:
  344. // for i, reactor := range reactors {
  345. // t.Log(fmt.Sprintf("Consensus Reactor %v", i))
  346. // t.Log(fmt.Sprintf("%v", reactor))
  347. // }
  348. // t.Fatalf("Timed out waiting for all validators to commit first block")
  349. // }
  350. }
  351. // func byzantineDecideProposalFunc(t *testing.T, height int64, round int32, cs *State, sw *p2p.Switch) {
  352. // // byzantine user should create two proposals and try to split the vote.
  353. // // Avoid sending on internalMsgQueue and running consensus state.
  354. // // Create a new proposal block from state/txs from the mempool.
  355. // block1, blockParts1 := cs.createProposalBlock()
  356. // polRound, propBlockID := cs.ValidRound, types.BlockID{Hash: block1.Hash(), PartSetHeader: blockParts1.Header()}
  357. // proposal1 := types.NewProposal(height, round, polRound, propBlockID)
  358. // p1 := proposal1.ToProto()
  359. // if err := cs.privValidator.SignProposal(cs.state.ChainID, p1); err != nil {
  360. // t.Error(err)
  361. // }
  362. // proposal1.Signature = p1.Signature
  363. // // some new transactions come in (this ensures that the proposals are different)
  364. // deliverTxsRange(cs, 0, 1)
  365. // // Create a new proposal block from state/txs from the mempool.
  366. // block2, blockParts2 := cs.createProposalBlock()
  367. // polRound, propBlockID = cs.ValidRound, types.BlockID{Hash: block2.Hash(), PartSetHeader: blockParts2.Header()}
  368. // proposal2 := types.NewProposal(height, round, polRound, propBlockID)
  369. // p2 := proposal2.ToProto()
  370. // if err := cs.privValidator.SignProposal(cs.state.ChainID, p2); err != nil {
  371. // t.Error(err)
  372. // }
  373. // proposal2.Signature = p2.Signature
  374. // block1Hash := block1.Hash()
  375. // block2Hash := block2.Hash()
  376. // // broadcast conflicting proposals/block parts to peers
  377. // peers := sw.Peers().List()
  378. // t.Logf("Byzantine: broadcasting conflicting proposals to %d peers", len(peers))
  379. // for i, peer := range peers {
  380. // if i < len(peers)/2 {
  381. // go sendProposalAndParts(height, round, cs, peer, proposal1, block1Hash, blockParts1)
  382. // } else {
  383. // go sendProposalAndParts(height, round, cs, peer, proposal2, block2Hash, blockParts2)
  384. // }
  385. // }
  386. // }
  387. // func sendProposalAndParts(
  388. // height int64,
  389. // round int32,
  390. // cs *State,
  391. // peer p2p.Peer,
  392. // proposal *types.Proposal,
  393. // blockHash []byte,
  394. // parts *types.PartSet,
  395. // ) {
  396. // // proposal
  397. // msg := &ProposalMessage{Proposal: proposal}
  398. // peer.Send(DataChannel, MustEncode(msg))
  399. // // parts
  400. // for i := 0; i < int(parts.Total()); i++ {
  401. // part := parts.GetPart(i)
  402. // msg := &BlockPartMessage{
  403. // Height: height, // This tells peer that this part applies to us.
  404. // Round: round, // This tells peer that this part applies to us.
  405. // Part: part,
  406. // }
  407. // peer.Send(DataChannel, MustEncode(msg))
  408. // }
  409. // // votes
  410. // cs.mtx.Lock()
  411. // prevote, _ := cs.signVote(tmproto.PrevoteType, blockHash, parts.Header())
  412. // precommit, _ := cs.signVote(tmproto.PrecommitType, blockHash, parts.Header())
  413. // cs.mtx.Unlock()
  414. // peer.Send(VoteChannel, MustEncode(&VoteMessage{prevote}))
  415. // peer.Send(VoteChannel, MustEncode(&VoteMessage{precommit}))
  416. // }
  417. // type ByzantineReactor struct {
  418. // service.Service
  419. // reactor *Reactor
  420. // }
  421. // func NewByzantineReactor(conR *Reactor) *ByzantineReactor {
  422. // return &ByzantineReactor{
  423. // Service: conR,
  424. // reactor: conR,
  425. // }
  426. // }
  427. // func (br *ByzantineReactor) SetSwitch(s *p2p.Switch) { br.reactor.SetSwitch(s) }
  428. // func (br *ByzantineReactor) GetChannels() []*p2p.ChannelDescriptor { return br.reactor.GetChannels() }
  429. // func (br *ByzantineReactor) AddPeer(peer p2p.Peer) {
  430. // if !br.reactor.IsRunning() {
  431. // return
  432. // }
  433. // // Create peerState for peer
  434. // peerState := NewPeerState(peer).SetLogger(br.reactor.Logger)
  435. // peer.Set(types.PeerStateKey, peerState)
  436. // // Send our state to peer.
  437. // // If we're syncing, broadcast a RoundStepMessage later upon SwitchToConsensus().
  438. // if !br.reactor.waitSync {
  439. // br.reactor.sendNewRoundStepMessage(peer)
  440. // }
  441. // }
  442. // func (br *ByzantineReactor) RemovePeer(peer p2p.Peer, reason interface{}) {
  443. // br.reactor.RemovePeer(peer, reason)
  444. // }
  445. // func (br *ByzantineReactor) Receive(chID byte, peer p2p.Peer, msgBytes []byte) {
  446. // br.reactor.Receive(chID, peer, msgBytes)
  447. // }
  448. // func (br *ByzantineReactor) InitPeer(peer p2p.Peer) p2p.Peer { return peer }