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.

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