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.

1237 lines
36 KiB

10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
10 years ago
10 years ago
10 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
8 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. package consensus
  2. import (
  3. "bytes"
  4. "errors"
  5. "fmt"
  6. "reflect"
  7. "sync"
  8. "time"
  9. . "github.com/tendermint/go-common"
  10. "github.com/tendermint/go-p2p"
  11. "github.com/tendermint/go-wire"
  12. sm "github.com/tendermint/tendermint/state"
  13. "github.com/tendermint/tendermint/types"
  14. )
  15. const (
  16. StateChannel = byte(0x20)
  17. DataChannel = byte(0x21)
  18. VoteChannel = byte(0x22)
  19. VoteSetBitsChannel = byte(0x23)
  20. peerGossipSleepDuration = 100 * time.Millisecond // Time to sleep if there's nothing to send.
  21. peerQueryMaj23SleepDuration = 2 * time.Second // Time to sleep after each VoteSetMaj23Message sent
  22. maxConsensusMessageSize = 1048576 // 1MB; NOTE: keep in sync with types.PartSet sizes.
  23. )
  24. //-----------------------------------------------------------------------------
  25. type ConsensusReactor struct {
  26. p2p.BaseReactor // BaseService + p2p.Switch
  27. conS *ConsensusState
  28. fastSync bool
  29. evsw types.EventSwitch
  30. }
  31. func NewConsensusReactor(consensusState *ConsensusState, fastSync bool) *ConsensusReactor {
  32. conR := &ConsensusReactor{
  33. conS: consensusState,
  34. fastSync: fastSync,
  35. }
  36. conR.BaseReactor = *p2p.NewBaseReactor(log, "ConsensusReactor", conR)
  37. return conR
  38. }
  39. func (conR *ConsensusReactor) OnStart() error {
  40. log.Notice("ConsensusReactor ", "fastSync", conR.fastSync)
  41. conR.BaseReactor.OnStart()
  42. // callbacks for broadcasting new steps and votes to peers
  43. // upon their respective events (ie. uses evsw)
  44. conR.registerEventCallbacks()
  45. if !conR.fastSync {
  46. _, err := conR.conS.Start()
  47. if err != nil {
  48. return err
  49. }
  50. }
  51. return nil
  52. }
  53. func (conR *ConsensusReactor) OnStop() {
  54. conR.BaseReactor.OnStop()
  55. conR.conS.Stop()
  56. }
  57. // Switch from the fast_sync to the consensus:
  58. // reset the state, turn off fast_sync, start the consensus-state-machine
  59. func (conR *ConsensusReactor) SwitchToConsensus(state *sm.State) {
  60. log.Notice("SwitchToConsensus")
  61. conR.conS.reconstructLastCommit(state)
  62. // NOTE: The line below causes broadcastNewRoundStepRoutine() to
  63. // broadcast a NewRoundStepMessage.
  64. conR.conS.updateToState(state)
  65. conR.fastSync = false
  66. conR.conS.Start()
  67. }
  68. // Implements Reactor
  69. func (conR *ConsensusReactor) GetChannels() []*p2p.ChannelDescriptor {
  70. // TODO optimize
  71. return []*p2p.ChannelDescriptor{
  72. &p2p.ChannelDescriptor{
  73. ID: StateChannel,
  74. Priority: 5,
  75. SendQueueCapacity: 100,
  76. },
  77. &p2p.ChannelDescriptor{
  78. ID: DataChannel, // maybe split between gossiping current block and catchup stuff
  79. Priority: 10, // once we gossip the whole block there's nothing left to send until next height or round
  80. SendQueueCapacity: 100,
  81. RecvBufferCapacity: 50 * 4096,
  82. },
  83. &p2p.ChannelDescriptor{
  84. ID: VoteChannel,
  85. Priority: 5,
  86. SendQueueCapacity: 100,
  87. RecvBufferCapacity: 100 * 100,
  88. },
  89. &p2p.ChannelDescriptor{
  90. ID: VoteSetBitsChannel,
  91. Priority: 1,
  92. SendQueueCapacity: 2,
  93. RecvBufferCapacity: 1024,
  94. },
  95. }
  96. }
  97. // Implements Reactor
  98. func (conR *ConsensusReactor) AddPeer(peer *p2p.Peer) {
  99. if !conR.IsRunning() {
  100. return
  101. }
  102. // Create peerState for peer
  103. peerState := NewPeerState(peer)
  104. peer.Data.Set(types.PeerStateKey, peerState)
  105. // Begin routines for this peer.
  106. go conR.gossipDataRoutine(peer, peerState)
  107. go conR.gossipVotesRoutine(peer, peerState)
  108. go conR.queryMaj23Routine(peer, peerState)
  109. // Send our state to peer.
  110. // If we're fast_syncing, broadcast a RoundStepMessage later upon SwitchToConsensus().
  111. if !conR.fastSync {
  112. conR.sendNewRoundStepMessage(peer)
  113. }
  114. }
  115. // Implements Reactor
  116. func (conR *ConsensusReactor) RemovePeer(peer *p2p.Peer, reason interface{}) {
  117. if !conR.IsRunning() {
  118. return
  119. }
  120. // TODO
  121. //peer.Data.Get(PeerStateKey).(*PeerState).Disconnect()
  122. }
  123. // Implements Reactor
  124. // NOTE: We process these messages even when we're fast_syncing.
  125. // Messages affect either a peer state or the consensus state.
  126. // Peer state updates can happen in parallel, but processing of
  127. // proposals, block parts, and votes are ordered by the receiveRoutine
  128. // NOTE: blocks on consensus state for proposals, block parts, and votes
  129. func (conR *ConsensusReactor) Receive(chID byte, src *p2p.Peer, msgBytes []byte) {
  130. if !conR.IsRunning() {
  131. log.Debug("Receive", "src", src, "chId", chID, "bytes", msgBytes)
  132. return
  133. }
  134. _, msg, err := DecodeMessage(msgBytes)
  135. if err != nil {
  136. log.Warn("Error decoding message", "src", src, "chId", chID, "msg", msg, "error", err, "bytes", msgBytes)
  137. // TODO punish peer?
  138. return
  139. }
  140. log.Debug("Receive", "src", src, "chId", chID, "msg", msg)
  141. // Get peer states
  142. ps := src.Data.Get(types.PeerStateKey).(*PeerState)
  143. switch chID {
  144. case StateChannel:
  145. switch msg := msg.(type) {
  146. case *NewRoundStepMessage:
  147. ps.ApplyNewRoundStepMessage(msg)
  148. case *CommitStepMessage:
  149. ps.ApplyCommitStepMessage(msg)
  150. case *HasVoteMessage:
  151. ps.ApplyHasVoteMessage(msg)
  152. case *VoteSetMaj23Message:
  153. cs := conR.conS
  154. cs.mtx.Lock()
  155. height, votes := cs.Height, cs.Votes
  156. cs.mtx.Unlock()
  157. if height != msg.Height {
  158. return
  159. }
  160. // Peer claims to have a maj23 for some BlockID at H,R,S,
  161. votes.SetPeerMaj23(msg.Round, msg.Type, ps.Peer.Key, msg.BlockID)
  162. // Respond with a VoteSetBitsMessage showing which votes we have.
  163. // (and consequently shows which we don't have)
  164. var ourVotes *BitArray
  165. switch msg.Type {
  166. case types.VoteTypePrevote:
  167. ourVotes = votes.Prevotes(msg.Round).BitArrayByBlockID(msg.BlockID)
  168. case types.VoteTypePrecommit:
  169. ourVotes = votes.Precommits(msg.Round).BitArrayByBlockID(msg.BlockID)
  170. default:
  171. log.Warn("Bad VoteSetBitsMessage field Type")
  172. return
  173. }
  174. src.TrySend(VoteSetBitsChannel, struct{ ConsensusMessage }{&VoteSetBitsMessage{
  175. Height: msg.Height,
  176. Round: msg.Round,
  177. Type: msg.Type,
  178. BlockID: msg.BlockID,
  179. Votes: ourVotes,
  180. }})
  181. default:
  182. log.Warn(Fmt("Unknown message type %v", reflect.TypeOf(msg)))
  183. }
  184. case DataChannel:
  185. if conR.fastSync {
  186. log.Warn("Ignoring message received during fastSync", "msg", msg)
  187. return
  188. }
  189. switch msg := msg.(type) {
  190. case *ProposalMessage:
  191. ps.SetHasProposal(msg.Proposal)
  192. conR.conS.peerMsgQueue <- msgInfo{msg, src.Key}
  193. case *ProposalPOLMessage:
  194. ps.ApplyProposalPOLMessage(msg)
  195. case *BlockPartMessage:
  196. ps.SetHasProposalBlockPart(msg.Height, msg.Round, msg.Part.Index)
  197. conR.conS.peerMsgQueue <- msgInfo{msg, src.Key}
  198. default:
  199. log.Warn(Fmt("Unknown message type %v", reflect.TypeOf(msg)))
  200. }
  201. case VoteChannel:
  202. if conR.fastSync {
  203. log.Warn("Ignoring message received during fastSync", "msg", msg)
  204. return
  205. }
  206. switch msg := msg.(type) {
  207. case *VoteMessage:
  208. cs := conR.conS
  209. cs.mtx.Lock()
  210. height, valSize, lastCommitSize := cs.Height, cs.Validators.Size(), cs.LastCommit.Size()
  211. cs.mtx.Unlock()
  212. ps.EnsureVoteBitArrays(height, valSize)
  213. ps.EnsureVoteBitArrays(height-1, lastCommitSize)
  214. ps.SetHasVote(msg.Vote)
  215. conR.conS.peerMsgQueue <- msgInfo{msg, src.Key}
  216. default:
  217. // don't punish (leave room for soft upgrades)
  218. log.Warn(Fmt("Unknown message type %v", reflect.TypeOf(msg)))
  219. }
  220. case VoteSetBitsChannel:
  221. if conR.fastSync {
  222. log.Warn("Ignoring message received during fastSync", "msg", msg)
  223. return
  224. }
  225. switch msg := msg.(type) {
  226. case *VoteSetBitsMessage:
  227. cs := conR.conS
  228. cs.mtx.Lock()
  229. height, votes := cs.Height, cs.Votes
  230. cs.mtx.Unlock()
  231. if height == msg.Height {
  232. var ourVotes *BitArray
  233. switch msg.Type {
  234. case types.VoteTypePrevote:
  235. ourVotes = votes.Prevotes(msg.Round).BitArrayByBlockID(msg.BlockID)
  236. case types.VoteTypePrecommit:
  237. ourVotes = votes.Precommits(msg.Round).BitArrayByBlockID(msg.BlockID)
  238. default:
  239. log.Warn("Bad VoteSetBitsMessage field Type")
  240. return
  241. }
  242. ps.ApplyVoteSetBitsMessage(msg, ourVotes)
  243. } else {
  244. ps.ApplyVoteSetBitsMessage(msg, nil)
  245. }
  246. default:
  247. // don't punish (leave room for soft upgrades)
  248. log.Warn(Fmt("Unknown message type %v", reflect.TypeOf(msg)))
  249. }
  250. default:
  251. log.Warn(Fmt("Unknown chId %X", chID))
  252. }
  253. if err != nil {
  254. log.Warn("Error in Receive()", "error", err)
  255. }
  256. }
  257. // implements events.Eventable
  258. func (conR *ConsensusReactor) SetEventSwitch(evsw types.EventSwitch) {
  259. conR.evsw = evsw
  260. conR.conS.SetEventSwitch(evsw)
  261. }
  262. //--------------------------------------
  263. // Listens for new steps and votes,
  264. // broadcasting the result to peers
  265. func (conR *ConsensusReactor) registerEventCallbacks() {
  266. types.AddListenerForEvent(conR.evsw, "conR", types.EventStringNewRoundStep(), func(data types.TMEventData) {
  267. rs := data.(types.EventDataRoundState).RoundState.(*RoundState)
  268. conR.broadcastNewRoundStep(rs)
  269. })
  270. types.AddListenerForEvent(conR.evsw, "conR", types.EventStringVote(), func(data types.TMEventData) {
  271. edv := data.(types.EventDataVote)
  272. conR.broadcastHasVoteMessage(edv.Vote)
  273. })
  274. }
  275. func (conR *ConsensusReactor) broadcastNewRoundStep(rs *RoundState) {
  276. nrsMsg, csMsg := makeRoundStepMessages(rs)
  277. if nrsMsg != nil {
  278. conR.Switch.Broadcast(StateChannel, struct{ ConsensusMessage }{nrsMsg})
  279. }
  280. if csMsg != nil {
  281. conR.Switch.Broadcast(StateChannel, struct{ ConsensusMessage }{csMsg})
  282. }
  283. }
  284. // Broadcasts HasVoteMessage to peers that care.
  285. func (conR *ConsensusReactor) broadcastHasVoteMessage(vote *types.Vote) {
  286. msg := &HasVoteMessage{
  287. Height: vote.Height,
  288. Round: vote.Round,
  289. Type: vote.Type,
  290. Index: vote.ValidatorIndex,
  291. }
  292. conR.Switch.Broadcast(StateChannel, struct{ ConsensusMessage }{msg})
  293. /*
  294. // TODO: Make this broadcast more selective.
  295. for _, peer := range conR.Switch.Peers().List() {
  296. ps := peer.Data.Get(PeerStateKey).(*PeerState)
  297. prs := ps.GetRoundState()
  298. if prs.Height == vote.Height {
  299. // TODO: Also filter on round?
  300. peer.TrySend(StateChannel, struct{ ConsensusMessage }{msg})
  301. } else {
  302. // Height doesn't match
  303. // TODO: check a field, maybe CatchupCommitRound?
  304. // TODO: But that requires changing the struct field comment.
  305. }
  306. }
  307. */
  308. }
  309. func makeRoundStepMessages(rs *RoundState) (nrsMsg *NewRoundStepMessage, csMsg *CommitStepMessage) {
  310. nrsMsg = &NewRoundStepMessage{
  311. Height: rs.Height,
  312. Round: rs.Round,
  313. Step: rs.Step,
  314. SecondsSinceStartTime: int(time.Now().Sub(rs.StartTime).Seconds()),
  315. LastCommitRound: rs.LastCommit.Round(),
  316. }
  317. if rs.Step == RoundStepCommit {
  318. csMsg = &CommitStepMessage{
  319. Height: rs.Height,
  320. BlockPartsHeader: rs.ProposalBlockParts.Header(),
  321. BlockParts: rs.ProposalBlockParts.BitArray(),
  322. }
  323. }
  324. return
  325. }
  326. func (conR *ConsensusReactor) sendNewRoundStepMessage(peer *p2p.Peer) {
  327. rs := conR.conS.GetRoundState()
  328. nrsMsg, csMsg := makeRoundStepMessages(rs)
  329. if nrsMsg != nil {
  330. peer.Send(StateChannel, struct{ ConsensusMessage }{nrsMsg})
  331. }
  332. if csMsg != nil {
  333. peer.Send(StateChannel, struct{ ConsensusMessage }{csMsg})
  334. }
  335. }
  336. func (conR *ConsensusReactor) gossipDataRoutine(peer *p2p.Peer, ps *PeerState) {
  337. log := log.New("peer", peer)
  338. OUTER_LOOP:
  339. for {
  340. // Manage disconnects from self or peer.
  341. if !peer.IsRunning() || !conR.IsRunning() {
  342. log.Notice(Fmt("Stopping gossipDataRoutine for %v.", peer))
  343. return
  344. }
  345. rs := conR.conS.GetRoundState()
  346. prs := ps.GetRoundState()
  347. // Send proposal Block parts?
  348. if rs.ProposalBlockParts.HasHeader(prs.ProposalBlockPartsHeader) {
  349. //log.Info("ProposalBlockParts matched", "blockParts", prs.ProposalBlockParts)
  350. if index, ok := rs.ProposalBlockParts.BitArray().Sub(prs.ProposalBlockParts.Copy()).PickRandom(); ok {
  351. part := rs.ProposalBlockParts.GetPart(index)
  352. msg := &BlockPartMessage{
  353. Height: rs.Height, // This tells peer that this part applies to us.
  354. Round: rs.Round, // This tells peer that this part applies to us.
  355. Part: part,
  356. }
  357. peer.Send(DataChannel, struct{ ConsensusMessage }{msg})
  358. ps.SetHasProposalBlockPart(prs.Height, prs.Round, index)
  359. continue OUTER_LOOP
  360. }
  361. }
  362. // If the peer is on a previous height, help catch up.
  363. if (0 < prs.Height) && (prs.Height < rs.Height) {
  364. //log.Info("Data catchup", "height", rs.Height, "peerHeight", prs.Height, "peerProposalBlockParts", prs.ProposalBlockParts)
  365. if index, ok := prs.ProposalBlockParts.Not().PickRandom(); ok {
  366. // Ensure that the peer's PartSetHeader is correct
  367. blockMeta := conR.conS.blockStore.LoadBlockMeta(prs.Height)
  368. if blockMeta == nil {
  369. log.Warn("Failed to load block meta", "peer height", prs.Height, "our height", rs.Height, "blockstore height", conR.conS.blockStore.Height(), "pv", conR.conS.privValidator)
  370. time.Sleep(peerGossipSleepDuration)
  371. continue OUTER_LOOP
  372. } else if !blockMeta.PartsHeader.Equals(prs.ProposalBlockPartsHeader) {
  373. log.Info("Peer ProposalBlockPartsHeader mismatch, sleeping",
  374. "peerHeight", prs.Height, "blockPartsHeader", blockMeta.PartsHeader, "peerBlockPartsHeader", prs.ProposalBlockPartsHeader)
  375. time.Sleep(peerGossipSleepDuration)
  376. continue OUTER_LOOP
  377. }
  378. // Load the part
  379. part := conR.conS.blockStore.LoadBlockPart(prs.Height, index)
  380. if part == nil {
  381. log.Warn("Could not load part", "index", index,
  382. "peerHeight", prs.Height, "blockPartsHeader", blockMeta.PartsHeader, "peerBlockPartsHeader", prs.ProposalBlockPartsHeader)
  383. time.Sleep(peerGossipSleepDuration)
  384. continue OUTER_LOOP
  385. }
  386. // Send the part
  387. msg := &BlockPartMessage{
  388. Height: prs.Height, // Not our height, so it doesn't matter.
  389. Round: prs.Round, // Not our height, so it doesn't matter.
  390. Part: part,
  391. }
  392. peer.Send(DataChannel, struct{ ConsensusMessage }{msg})
  393. ps.SetHasProposalBlockPart(prs.Height, prs.Round, index)
  394. continue OUTER_LOOP
  395. } else {
  396. //log.Info("No parts to send in catch-up, sleeping")
  397. time.Sleep(peerGossipSleepDuration)
  398. continue OUTER_LOOP
  399. }
  400. }
  401. // If height and round don't match, sleep.
  402. if (rs.Height != prs.Height) || (rs.Round != prs.Round) {
  403. //log.Info("Peer Height|Round mismatch, sleeping", "peerHeight", prs.Height, "peerRound", prs.Round, "peer", peer)
  404. time.Sleep(peerGossipSleepDuration)
  405. continue OUTER_LOOP
  406. }
  407. // By here, height and round match.
  408. // Proposal block parts were already matched and sent if any were wanted.
  409. // (These can match on hash so the round doesn't matter)
  410. // Now consider sending other things, like the Proposal itself.
  411. // Send Proposal && ProposalPOL BitArray?
  412. if rs.Proposal != nil && !prs.Proposal {
  413. // Proposal: share the proposal metadata with peer.
  414. {
  415. msg := &ProposalMessage{Proposal: rs.Proposal}
  416. peer.Send(DataChannel, struct{ ConsensusMessage }{msg})
  417. ps.SetHasProposal(rs.Proposal)
  418. }
  419. // ProposalPOL: lets peer know which POL votes we have so far.
  420. // Peer must receive ProposalMessage first.
  421. // rs.Proposal was validated, so rs.Proposal.POLRound <= rs.Round,
  422. // so we definitely have rs.Votes.Prevotes(rs.Proposal.POLRound).
  423. if 0 <= rs.Proposal.POLRound {
  424. msg := &ProposalPOLMessage{
  425. Height: rs.Height,
  426. ProposalPOLRound: rs.Proposal.POLRound,
  427. ProposalPOL: rs.Votes.Prevotes(rs.Proposal.POLRound).BitArray(),
  428. }
  429. peer.Send(DataChannel, struct{ ConsensusMessage }{msg})
  430. }
  431. continue OUTER_LOOP
  432. }
  433. // Nothing to do. Sleep.
  434. time.Sleep(peerGossipSleepDuration)
  435. continue OUTER_LOOP
  436. }
  437. }
  438. func (conR *ConsensusReactor) gossipVotesRoutine(peer *p2p.Peer, ps *PeerState) {
  439. log := log.New("peer", peer)
  440. // Simple hack to throttle logs upon sleep.
  441. var sleeping = 0
  442. OUTER_LOOP:
  443. for {
  444. // Manage disconnects from self or peer.
  445. if !peer.IsRunning() || !conR.IsRunning() {
  446. log.Notice(Fmt("Stopping gossipVotesRoutine for %v.", peer))
  447. return
  448. }
  449. rs := conR.conS.GetRoundState()
  450. prs := ps.GetRoundState()
  451. switch sleeping {
  452. case 1: // First sleep
  453. sleeping = 2
  454. case 2: // No more sleep
  455. sleeping = 0
  456. }
  457. //log.Debug("gossipVotesRoutine", "rsHeight", rs.Height, "rsRound", rs.Round,
  458. // "prsHeight", prs.Height, "prsRound", prs.Round, "prsStep", prs.Step)
  459. // If height matches, then send LastCommit, Prevotes, Precommits.
  460. if rs.Height == prs.Height {
  461. // If there are lastCommits to send...
  462. if prs.Step == RoundStepNewHeight {
  463. if ps.PickSendVote(rs.LastCommit) {
  464. log.Debug("Picked rs.LastCommit to send")
  465. continue OUTER_LOOP
  466. }
  467. }
  468. // If there are prevotes to send...
  469. if prs.Step <= RoundStepPrevote && prs.Round != -1 && prs.Round <= rs.Round {
  470. if ps.PickSendVote(rs.Votes.Prevotes(prs.Round)) {
  471. log.Debug("Picked rs.Prevotes(prs.Round) to send")
  472. continue OUTER_LOOP
  473. }
  474. }
  475. // If there are precommits to send...
  476. if prs.Step <= RoundStepPrecommit && prs.Round != -1 && prs.Round <= rs.Round {
  477. if ps.PickSendVote(rs.Votes.Precommits(prs.Round)) {
  478. log.Debug("Picked rs.Precommits(prs.Round) to send")
  479. continue OUTER_LOOP
  480. }
  481. }
  482. // If there are POLPrevotes to send...
  483. if prs.ProposalPOLRound != -1 {
  484. if polPrevotes := rs.Votes.Prevotes(prs.ProposalPOLRound); polPrevotes != nil {
  485. if ps.PickSendVote(polPrevotes) {
  486. log.Debug("Picked rs.Prevotes(prs.ProposalPOLRound) to send")
  487. continue OUTER_LOOP
  488. }
  489. }
  490. }
  491. }
  492. // Special catchup logic.
  493. // If peer is lagging by height 1, send LastCommit.
  494. if prs.Height != 0 && rs.Height == prs.Height+1 {
  495. if ps.PickSendVote(rs.LastCommit) {
  496. log.Debug("Picked rs.LastCommit to send")
  497. continue OUTER_LOOP
  498. }
  499. }
  500. // Catchup logic
  501. // If peer is lagging by more than 1, send Commit.
  502. if prs.Height != 0 && rs.Height >= prs.Height+2 {
  503. // Load the block commit for prs.Height,
  504. // which contains precommit signatures for prs.Height.
  505. commit := conR.conS.blockStore.LoadBlockCommit(prs.Height)
  506. log.Info("Loaded BlockCommit for catch-up", "height", prs.Height, "commit", commit)
  507. if ps.PickSendVote(commit) {
  508. log.Debug("Picked Catchup commit to send")
  509. continue OUTER_LOOP
  510. }
  511. }
  512. if sleeping == 0 {
  513. // We sent nothing. Sleep...
  514. sleeping = 1
  515. log.Debug("No votes to send, sleeping", "peer", peer,
  516. "localPV", rs.Votes.Prevotes(rs.Round).BitArray(), "peerPV", prs.Prevotes,
  517. "localPC", rs.Votes.Precommits(rs.Round).BitArray(), "peerPC", prs.Precommits)
  518. } else if sleeping == 2 {
  519. // Continued sleep...
  520. sleeping = 1
  521. }
  522. time.Sleep(peerGossipSleepDuration)
  523. continue OUTER_LOOP
  524. }
  525. }
  526. // NOTE: `queryMaj23Routine` has a simple crude design since it only comes
  527. // into play for liveness when there's a signature DDoS attack happening.
  528. func (conR *ConsensusReactor) queryMaj23Routine(peer *p2p.Peer, ps *PeerState) {
  529. log := log.New("peer", peer)
  530. OUTER_LOOP:
  531. for {
  532. // Manage disconnects from self or peer.
  533. if !peer.IsRunning() || !conR.IsRunning() {
  534. log.Notice(Fmt("Stopping queryMaj23Routine for %v.", peer))
  535. return
  536. }
  537. // Maybe send Height/Round/Prevotes
  538. {
  539. rs := conR.conS.GetRoundState()
  540. prs := ps.GetRoundState()
  541. if rs.Height == prs.Height {
  542. if maj23, ok := rs.Votes.Prevotes(prs.Round).TwoThirdsMajority(); ok {
  543. peer.TrySend(StateChannel, struct{ ConsensusMessage }{&VoteSetMaj23Message{
  544. Height: prs.Height,
  545. Round: prs.Round,
  546. Type: types.VoteTypePrevote,
  547. BlockID: maj23,
  548. }})
  549. time.Sleep(peerQueryMaj23SleepDuration)
  550. }
  551. }
  552. }
  553. // Maybe send Height/Round/Precommits
  554. {
  555. rs := conR.conS.GetRoundState()
  556. prs := ps.GetRoundState()
  557. if rs.Height == prs.Height {
  558. if maj23, ok := rs.Votes.Precommits(prs.Round).TwoThirdsMajority(); ok {
  559. peer.TrySend(StateChannel, struct{ ConsensusMessage }{&VoteSetMaj23Message{
  560. Height: prs.Height,
  561. Round: prs.Round,
  562. Type: types.VoteTypePrecommit,
  563. BlockID: maj23,
  564. }})
  565. time.Sleep(peerQueryMaj23SleepDuration)
  566. }
  567. }
  568. }
  569. // Maybe send Height/Round/ProposalPOL
  570. {
  571. rs := conR.conS.GetRoundState()
  572. prs := ps.GetRoundState()
  573. if rs.Height == prs.Height && prs.ProposalPOLRound >= 0 {
  574. if maj23, ok := rs.Votes.Prevotes(prs.ProposalPOLRound).TwoThirdsMajority(); ok {
  575. peer.TrySend(StateChannel, struct{ ConsensusMessage }{&VoteSetMaj23Message{
  576. Height: prs.Height,
  577. Round: prs.ProposalPOLRound,
  578. Type: types.VoteTypePrevote,
  579. BlockID: maj23,
  580. }})
  581. time.Sleep(peerQueryMaj23SleepDuration)
  582. }
  583. }
  584. }
  585. // Little point sending LastCommitRound/LastCommit,
  586. // These are fleeting and non-blocking.
  587. // Maybe send Height/CatchupCommitRound/CatchupCommit.
  588. {
  589. prs := ps.GetRoundState()
  590. if prs.CatchupCommitRound != -1 && 0 < prs.Height && prs.Height <= conR.conS.blockStore.Height() {
  591. commit := conR.conS.LoadCommit(prs.Height)
  592. peer.TrySend(StateChannel, struct{ ConsensusMessage }{&VoteSetMaj23Message{
  593. Height: prs.Height,
  594. Round: commit.Round(),
  595. Type: types.VoteTypePrecommit,
  596. BlockID: commit.BlockID,
  597. }})
  598. time.Sleep(peerQueryMaj23SleepDuration)
  599. }
  600. }
  601. time.Sleep(peerQueryMaj23SleepDuration)
  602. continue OUTER_LOOP
  603. }
  604. }
  605. func (conR *ConsensusReactor) String() string {
  606. // better not to access shared variables
  607. return "ConsensusReactor" // conR.StringIndented("")
  608. }
  609. func (conR *ConsensusReactor) StringIndented(indent string) string {
  610. s := "ConsensusReactor{\n"
  611. s += indent + " " + conR.conS.StringIndented(indent+" ") + "\n"
  612. for _, peer := range conR.Switch.Peers().List() {
  613. ps := peer.Data.Get(types.PeerStateKey).(*PeerState)
  614. s += indent + " " + ps.StringIndented(indent+" ") + "\n"
  615. }
  616. s += indent + "}"
  617. return s
  618. }
  619. //-----------------------------------------------------------------------------
  620. // Read only when returned by PeerState.GetRoundState().
  621. type PeerRoundState struct {
  622. Height int // Height peer is at
  623. Round int // Round peer is at, -1 if unknown.
  624. Step RoundStepType // Step peer is at
  625. StartTime time.Time // Estimated start of round 0 at this height
  626. Proposal bool // True if peer has proposal for this round
  627. ProposalBlockPartsHeader types.PartSetHeader //
  628. ProposalBlockParts *BitArray //
  629. ProposalPOLRound int // Proposal's POL round. -1 if none.
  630. ProposalPOL *BitArray // nil until ProposalPOLMessage received.
  631. Prevotes *BitArray // All votes peer has for this round
  632. Precommits *BitArray // All precommits peer has for this round
  633. LastCommitRound int // Round of commit for last height. -1 if none.
  634. LastCommit *BitArray // All commit precommits of commit for last height.
  635. CatchupCommitRound int // Round that we have commit for. Not necessarily unique. -1 if none.
  636. CatchupCommit *BitArray // All commit precommits peer has for this height & CatchupCommitRound
  637. }
  638. func (prs PeerRoundState) String() string {
  639. return prs.StringIndented("")
  640. }
  641. func (prs PeerRoundState) StringIndented(indent string) string {
  642. return fmt.Sprintf(`PeerRoundState{
  643. %s %v/%v/%v @%v
  644. %s Proposal %v -> %v
  645. %s POL %v (round %v)
  646. %s Prevotes %v
  647. %s Precommits %v
  648. %s LastCommit %v (round %v)
  649. %s Catchup %v (round %v)
  650. %s}`,
  651. indent, prs.Height, prs.Round, prs.Step, prs.StartTime,
  652. indent, prs.ProposalBlockPartsHeader, prs.ProposalBlockParts,
  653. indent, prs.ProposalPOL, prs.ProposalPOLRound,
  654. indent, prs.Prevotes,
  655. indent, prs.Precommits,
  656. indent, prs.LastCommit, prs.LastCommitRound,
  657. indent, prs.CatchupCommit, prs.CatchupCommitRound,
  658. indent)
  659. }
  660. //-----------------------------------------------------------------------------
  661. var (
  662. ErrPeerStateHeightRegression = errors.New("Error peer state height regression")
  663. ErrPeerStateInvalidStartTime = errors.New("Error peer state invalid startTime")
  664. )
  665. type PeerState struct {
  666. Peer *p2p.Peer
  667. mtx sync.Mutex
  668. PeerRoundState
  669. }
  670. func NewPeerState(peer *p2p.Peer) *PeerState {
  671. return &PeerState{
  672. Peer: peer,
  673. PeerRoundState: PeerRoundState{
  674. Round: -1,
  675. ProposalPOLRound: -1,
  676. LastCommitRound: -1,
  677. CatchupCommitRound: -1,
  678. },
  679. }
  680. }
  681. // Returns an atomic snapshot of the PeerRoundState.
  682. // There's no point in mutating it since it won't change PeerState.
  683. func (ps *PeerState) GetRoundState() *PeerRoundState {
  684. ps.mtx.Lock()
  685. defer ps.mtx.Unlock()
  686. prs := ps.PeerRoundState // copy
  687. return &prs
  688. }
  689. // Returns an atomic snapshot of the PeerRoundState's height
  690. // used by the mempool to ensure peers are caught up before broadcasting new txs
  691. func (ps *PeerState) GetHeight() int {
  692. ps.mtx.Lock()
  693. defer ps.mtx.Unlock()
  694. return ps.PeerRoundState.Height
  695. }
  696. func (ps *PeerState) SetHasProposal(proposal *types.Proposal) {
  697. ps.mtx.Lock()
  698. defer ps.mtx.Unlock()
  699. if ps.Height != proposal.Height || ps.Round != proposal.Round {
  700. return
  701. }
  702. if ps.Proposal {
  703. return
  704. }
  705. ps.Proposal = true
  706. ps.ProposalBlockPartsHeader = proposal.BlockPartsHeader
  707. ps.ProposalBlockParts = NewBitArray(proposal.BlockPartsHeader.Total)
  708. ps.ProposalPOLRound = proposal.POLRound
  709. ps.ProposalPOL = nil // Nil until ProposalPOLMessage received.
  710. }
  711. func (ps *PeerState) SetHasProposalBlockPart(height int, round int, index int) {
  712. ps.mtx.Lock()
  713. defer ps.mtx.Unlock()
  714. if ps.Height != height || ps.Round != round {
  715. return
  716. }
  717. ps.ProposalBlockParts.SetIndex(index, true)
  718. }
  719. // Convenience function to send vote to peer.
  720. // Returns true if vote was sent.
  721. func (ps *PeerState) PickSendVote(votes types.VoteSetReader) (ok bool) {
  722. if vote, ok := ps.PickVoteToSend(votes); ok {
  723. msg := &VoteMessage{vote}
  724. ps.Peer.Send(VoteChannel, struct{ ConsensusMessage }{msg})
  725. return true
  726. }
  727. return false
  728. }
  729. // votes: Must be the correct Size() for the Height().
  730. func (ps *PeerState) PickVoteToSend(votes types.VoteSetReader) (vote *types.Vote, ok bool) {
  731. ps.mtx.Lock()
  732. defer ps.mtx.Unlock()
  733. if votes.Size() == 0 {
  734. return nil, false
  735. }
  736. height, round, type_, size := votes.Height(), votes.Round(), votes.Type(), votes.Size()
  737. // Lazily set data using 'votes'.
  738. if votes.IsCommit() {
  739. ps.ensureCatchupCommitRound(height, round, size)
  740. }
  741. ps.ensureVoteBitArrays(height, size)
  742. psVotes := ps.getVoteBitArray(height, round, type_)
  743. if psVotes == nil {
  744. return nil, false // Not something worth sending
  745. }
  746. if index, ok := votes.BitArray().Sub(psVotes).PickRandom(); ok {
  747. ps.setHasVote(height, round, type_, index)
  748. return votes.GetByIndex(index), true
  749. }
  750. return nil, false
  751. }
  752. func (ps *PeerState) getVoteBitArray(height, round int, type_ byte) *BitArray {
  753. if !types.IsVoteTypeValid(type_) {
  754. PanicSanity("Invalid vote type")
  755. }
  756. if ps.Height == height {
  757. if ps.Round == round {
  758. switch type_ {
  759. case types.VoteTypePrevote:
  760. return ps.Prevotes
  761. case types.VoteTypePrecommit:
  762. return ps.Precommits
  763. }
  764. }
  765. if ps.CatchupCommitRound == round {
  766. switch type_ {
  767. case types.VoteTypePrevote:
  768. return nil
  769. case types.VoteTypePrecommit:
  770. return ps.CatchupCommit
  771. }
  772. }
  773. if ps.ProposalPOLRound == round {
  774. switch type_ {
  775. case types.VoteTypePrevote:
  776. return ps.ProposalPOL
  777. case types.VoteTypePrecommit:
  778. return nil
  779. }
  780. }
  781. return nil
  782. }
  783. if ps.Height == height+1 {
  784. if ps.LastCommitRound == round {
  785. switch type_ {
  786. case types.VoteTypePrevote:
  787. return nil
  788. case types.VoteTypePrecommit:
  789. return ps.LastCommit
  790. }
  791. }
  792. return nil
  793. }
  794. return nil
  795. }
  796. // 'round': A round for which we have a +2/3 commit.
  797. func (ps *PeerState) ensureCatchupCommitRound(height, round int, numValidators int) {
  798. if ps.Height != height {
  799. return
  800. }
  801. /*
  802. NOTE: This is wrong, 'round' could change.
  803. e.g. if orig round is not the same as block LastCommit round.
  804. if ps.CatchupCommitRound != -1 && ps.CatchupCommitRound != round {
  805. PanicSanity(Fmt("Conflicting CatchupCommitRound. Height: %v, Orig: %v, New: %v", height, ps.CatchupCommitRound, round))
  806. }
  807. */
  808. if ps.CatchupCommitRound == round {
  809. return // Nothing to do!
  810. }
  811. ps.CatchupCommitRound = round
  812. if round == ps.Round {
  813. ps.CatchupCommit = ps.Precommits
  814. } else {
  815. ps.CatchupCommit = NewBitArray(numValidators)
  816. }
  817. }
  818. // NOTE: It's important to make sure that numValidators actually matches
  819. // what the node sees as the number of validators for height.
  820. func (ps *PeerState) EnsureVoteBitArrays(height int, numValidators int) {
  821. ps.mtx.Lock()
  822. defer ps.mtx.Unlock()
  823. ps.ensureVoteBitArrays(height, numValidators)
  824. }
  825. func (ps *PeerState) ensureVoteBitArrays(height int, numValidators int) {
  826. if ps.Height == height {
  827. if ps.Prevotes == nil {
  828. ps.Prevotes = NewBitArray(numValidators)
  829. }
  830. if ps.Precommits == nil {
  831. ps.Precommits = NewBitArray(numValidators)
  832. }
  833. if ps.CatchupCommit == nil {
  834. ps.CatchupCommit = NewBitArray(numValidators)
  835. }
  836. if ps.ProposalPOL == nil {
  837. ps.ProposalPOL = NewBitArray(numValidators)
  838. }
  839. } else if ps.Height == height+1 {
  840. if ps.LastCommit == nil {
  841. ps.LastCommit = NewBitArray(numValidators)
  842. }
  843. }
  844. }
  845. func (ps *PeerState) SetHasVote(vote *types.Vote) {
  846. ps.mtx.Lock()
  847. defer ps.mtx.Unlock()
  848. ps.setHasVote(vote.Height, vote.Round, vote.Type, vote.ValidatorIndex)
  849. }
  850. func (ps *PeerState) setHasVote(height int, round int, type_ byte, index int) {
  851. log := log.New("peer", ps.Peer, "peerRound", ps.Round, "height", height, "round", round)
  852. log.Debug("setHasVote(LastCommit)", "lastCommit", ps.LastCommit, "index", index)
  853. // NOTE: some may be nil BitArrays -> no side effects.
  854. ps.getVoteBitArray(height, round, type_).SetIndex(index, true)
  855. }
  856. func (ps *PeerState) ApplyNewRoundStepMessage(msg *NewRoundStepMessage) {
  857. ps.mtx.Lock()
  858. defer ps.mtx.Unlock()
  859. // Ignore duplicates or decreases
  860. if CompareHRS(msg.Height, msg.Round, msg.Step, ps.Height, ps.Round, ps.Step) <= 0 {
  861. return
  862. }
  863. // Just remember these values.
  864. psHeight := ps.Height
  865. psRound := ps.Round
  866. //psStep := ps.Step
  867. psCatchupCommitRound := ps.CatchupCommitRound
  868. psCatchupCommit := ps.CatchupCommit
  869. startTime := time.Now().Add(-1 * time.Duration(msg.SecondsSinceStartTime) * time.Second)
  870. ps.Height = msg.Height
  871. ps.Round = msg.Round
  872. ps.Step = msg.Step
  873. ps.StartTime = startTime
  874. if psHeight != msg.Height || psRound != msg.Round {
  875. ps.Proposal = false
  876. ps.ProposalBlockPartsHeader = types.PartSetHeader{}
  877. ps.ProposalBlockParts = nil
  878. ps.ProposalPOLRound = -1
  879. ps.ProposalPOL = nil
  880. // We'll update the BitArray capacity later.
  881. ps.Prevotes = nil
  882. ps.Precommits = nil
  883. }
  884. if psHeight == msg.Height && psRound != msg.Round && msg.Round == psCatchupCommitRound {
  885. // Peer caught up to CatchupCommitRound.
  886. // Preserve psCatchupCommit!
  887. // NOTE: We prefer to use prs.Precommits if
  888. // pr.Round matches pr.CatchupCommitRound.
  889. ps.Precommits = psCatchupCommit
  890. }
  891. if psHeight != msg.Height {
  892. // Shift Precommits to LastCommit.
  893. if psHeight+1 == msg.Height && psRound == msg.LastCommitRound {
  894. ps.LastCommitRound = msg.LastCommitRound
  895. ps.LastCommit = ps.Precommits
  896. } else {
  897. ps.LastCommitRound = msg.LastCommitRound
  898. ps.LastCommit = nil
  899. }
  900. // We'll update the BitArray capacity later.
  901. ps.CatchupCommitRound = -1
  902. ps.CatchupCommit = nil
  903. }
  904. }
  905. func (ps *PeerState) ApplyCommitStepMessage(msg *CommitStepMessage) {
  906. ps.mtx.Lock()
  907. defer ps.mtx.Unlock()
  908. if ps.Height != msg.Height {
  909. return
  910. }
  911. ps.ProposalBlockPartsHeader = msg.BlockPartsHeader
  912. ps.ProposalBlockParts = msg.BlockParts
  913. }
  914. func (ps *PeerState) ApplyProposalPOLMessage(msg *ProposalPOLMessage) {
  915. ps.mtx.Lock()
  916. defer ps.mtx.Unlock()
  917. if ps.Height != msg.Height {
  918. return
  919. }
  920. if ps.ProposalPOLRound != msg.ProposalPOLRound {
  921. return
  922. }
  923. // TODO: Merge onto existing ps.ProposalPOL?
  924. // We might have sent some prevotes in the meantime.
  925. ps.ProposalPOL = msg.ProposalPOL
  926. }
  927. func (ps *PeerState) ApplyHasVoteMessage(msg *HasVoteMessage) {
  928. ps.mtx.Lock()
  929. defer ps.mtx.Unlock()
  930. if ps.Height != msg.Height {
  931. return
  932. }
  933. ps.setHasVote(msg.Height, msg.Round, msg.Type, msg.Index)
  934. }
  935. // The peer has responded with a bitarray of votes that it has
  936. // of the corresponding BlockID.
  937. // ourVotes: BitArray of votes we have for msg.BlockID
  938. // NOTE: if ourVotes is nil (e.g. msg.Height < rs.Height),
  939. // we conservatively overwrite ps's votes w/ msg.Votes.
  940. func (ps *PeerState) ApplyVoteSetBitsMessage(msg *VoteSetBitsMessage, ourVotes *BitArray) {
  941. ps.mtx.Lock()
  942. defer ps.mtx.Unlock()
  943. votes := ps.getVoteBitArray(msg.Height, msg.Round, msg.Type)
  944. if votes != nil {
  945. if ourVotes == nil {
  946. votes.Update(msg.Votes)
  947. } else {
  948. otherVotes := votes.Sub(ourVotes)
  949. hasVotes := otherVotes.Or(msg.Votes)
  950. votes.Update(hasVotes)
  951. }
  952. }
  953. }
  954. func (ps *PeerState) String() string {
  955. return ps.StringIndented("")
  956. }
  957. func (ps *PeerState) StringIndented(indent string) string {
  958. return fmt.Sprintf(`PeerState{
  959. %s Key %v
  960. %s PRS %v
  961. %s}`,
  962. indent, ps.Peer.Key,
  963. indent, ps.PeerRoundState.StringIndented(indent+" "),
  964. indent)
  965. }
  966. //-----------------------------------------------------------------------------
  967. // Messages
  968. const (
  969. msgTypeNewRoundStep = byte(0x01)
  970. msgTypeCommitStep = byte(0x02)
  971. msgTypeProposal = byte(0x11)
  972. msgTypeProposalPOL = byte(0x12)
  973. msgTypeBlockPart = byte(0x13) // both block & POL
  974. msgTypeVote = byte(0x14)
  975. msgTypeHasVote = byte(0x15)
  976. msgTypeVoteSetMaj23 = byte(0x16)
  977. msgTypeVoteSetBits = byte(0x17)
  978. )
  979. type ConsensusMessage interface{}
  980. var _ = wire.RegisterInterface(
  981. struct{ ConsensusMessage }{},
  982. wire.ConcreteType{&NewRoundStepMessage{}, msgTypeNewRoundStep},
  983. wire.ConcreteType{&CommitStepMessage{}, msgTypeCommitStep},
  984. wire.ConcreteType{&ProposalMessage{}, msgTypeProposal},
  985. wire.ConcreteType{&ProposalPOLMessage{}, msgTypeProposalPOL},
  986. wire.ConcreteType{&BlockPartMessage{}, msgTypeBlockPart},
  987. wire.ConcreteType{&VoteMessage{}, msgTypeVote},
  988. wire.ConcreteType{&HasVoteMessage{}, msgTypeHasVote},
  989. wire.ConcreteType{&VoteSetMaj23Message{}, msgTypeVoteSetMaj23},
  990. wire.ConcreteType{&VoteSetBitsMessage{}, msgTypeVoteSetBits},
  991. )
  992. // TODO: check for unnecessary extra bytes at the end.
  993. func DecodeMessage(bz []byte) (msgType byte, msg ConsensusMessage, err error) {
  994. msgType = bz[0]
  995. n := new(int)
  996. r := bytes.NewReader(bz)
  997. msg = wire.ReadBinary(struct{ ConsensusMessage }{}, r, maxConsensusMessageSize, n, &err).(struct{ ConsensusMessage }).ConsensusMessage
  998. return
  999. }
  1000. //-------------------------------------
  1001. // For every height/round/step transition
  1002. type NewRoundStepMessage struct {
  1003. Height int
  1004. Round int
  1005. Step RoundStepType
  1006. SecondsSinceStartTime int
  1007. LastCommitRound int
  1008. }
  1009. func (m *NewRoundStepMessage) String() string {
  1010. return fmt.Sprintf("[NewRoundStep H:%v R:%v S:%v LCR:%v]",
  1011. m.Height, m.Round, m.Step, m.LastCommitRound)
  1012. }
  1013. //-------------------------------------
  1014. type CommitStepMessage struct {
  1015. Height int
  1016. BlockPartsHeader types.PartSetHeader
  1017. BlockParts *BitArray
  1018. }
  1019. func (m *CommitStepMessage) String() string {
  1020. return fmt.Sprintf("[CommitStep H:%v BP:%v BA:%v]", m.Height, m.BlockPartsHeader, m.BlockParts)
  1021. }
  1022. //-------------------------------------
  1023. type ProposalMessage struct {
  1024. Proposal *types.Proposal
  1025. }
  1026. func (m *ProposalMessage) String() string {
  1027. return fmt.Sprintf("[Proposal %v]", m.Proposal)
  1028. }
  1029. //-------------------------------------
  1030. type ProposalPOLMessage struct {
  1031. Height int
  1032. ProposalPOLRound int
  1033. ProposalPOL *BitArray
  1034. }
  1035. func (m *ProposalPOLMessage) String() string {
  1036. return fmt.Sprintf("[ProposalPOL H:%v POLR:%v POL:%v]", m.Height, m.ProposalPOLRound, m.ProposalPOL)
  1037. }
  1038. //-------------------------------------
  1039. type BlockPartMessage struct {
  1040. Height int
  1041. Round int
  1042. Part *types.Part
  1043. }
  1044. func (m *BlockPartMessage) String() string {
  1045. return fmt.Sprintf("[BlockPart H:%v R:%v P:%v]", m.Height, m.Round, m.Part)
  1046. }
  1047. //-------------------------------------
  1048. type VoteMessage struct {
  1049. Vote *types.Vote
  1050. }
  1051. func (m *VoteMessage) String() string {
  1052. return fmt.Sprintf("[Vote %v]", m.Vote)
  1053. }
  1054. //-------------------------------------
  1055. type HasVoteMessage struct {
  1056. Height int
  1057. Round int
  1058. Type byte
  1059. Index int
  1060. }
  1061. func (m *HasVoteMessage) String() string {
  1062. return fmt.Sprintf("[HasVote VI:%v V:{%v/%02d/%v} VI:%v]", m.Index, m.Height, m.Round, m.Type, m.Index)
  1063. }
  1064. //-------------------------------------
  1065. type VoteSetMaj23Message struct {
  1066. Height int
  1067. Round int
  1068. Type byte
  1069. BlockID types.BlockID
  1070. }
  1071. func (m *VoteSetMaj23Message) String() string {
  1072. return fmt.Sprintf("[VSM23 %v/%02d/%v %v]", m.Height, m.Round, m.Type, m.BlockID)
  1073. }
  1074. //-------------------------------------
  1075. type VoteSetBitsMessage struct {
  1076. Height int
  1077. Round int
  1078. Type byte
  1079. BlockID types.BlockID
  1080. Votes *BitArray
  1081. }
  1082. func (m *VoteSetBitsMessage) String() string {
  1083. return fmt.Sprintf("[VSB %v/%02d/%v %v %v]", m.Height, m.Round, m.Type, m.BlockID, m.Votes)
  1084. }