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.

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