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.

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