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.

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