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.

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