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.

1234 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
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
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
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
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. func (conR *ConsensusReactor) queryMaj23Routine(peer *p2p.Peer, ps *PeerState) {
  527. log := log.New("peer", peer)
  528. OUTER_LOOP:
  529. for {
  530. // Manage disconnects from self or peer.
  531. if !peer.IsRunning() || !conR.IsRunning() {
  532. log.Notice(Fmt("Stopping queryMaj23Routine for %v.", peer))
  533. return
  534. }
  535. // Maybe send Height/Round/Prevotes
  536. {
  537. rs := conR.conS.GetRoundState()
  538. prs := ps.GetRoundState()
  539. if rs.Height == prs.Height {
  540. if maj23, ok := rs.Votes.Prevotes(prs.Round).TwoThirdsMajority(); ok {
  541. peer.TrySend(StateChannel, struct{ ConsensusMessage }{&VoteSetMaj23Message{
  542. Height: prs.Height,
  543. Round: prs.Round,
  544. Type: types.VoteTypePrevote,
  545. BlockID: maj23,
  546. }})
  547. time.Sleep(peerQueryMaj23SleepDuration)
  548. }
  549. }
  550. }
  551. // Maybe send Height/Round/Precommits
  552. {
  553. rs := conR.conS.GetRoundState()
  554. prs := ps.GetRoundState()
  555. if rs.Height == prs.Height {
  556. if maj23, ok := rs.Votes.Precommits(prs.Round).TwoThirdsMajority(); ok {
  557. peer.TrySend(StateChannel, struct{ ConsensusMessage }{&VoteSetMaj23Message{
  558. Height: prs.Height,
  559. Round: prs.Round,
  560. Type: types.VoteTypePrecommit,
  561. BlockID: maj23,
  562. }})
  563. time.Sleep(peerQueryMaj23SleepDuration)
  564. }
  565. }
  566. }
  567. // Maybe send Height/Round/ProposalPOL
  568. {
  569. rs := conR.conS.GetRoundState()
  570. prs := ps.GetRoundState()
  571. if rs.Height == prs.Height && prs.ProposalPOLRound >= 0 {
  572. if maj23, ok := rs.Votes.Prevotes(prs.ProposalPOLRound).TwoThirdsMajority(); ok {
  573. peer.TrySend(StateChannel, struct{ ConsensusMessage }{&VoteSetMaj23Message{
  574. Height: prs.Height,
  575. Round: prs.ProposalPOLRound,
  576. Type: types.VoteTypePrevote,
  577. BlockID: maj23,
  578. }})
  579. time.Sleep(peerQueryMaj23SleepDuration)
  580. }
  581. }
  582. }
  583. // Little point sending LastCommitRound/LastCommit,
  584. // These are fleeting and non-blocking.
  585. // Maybe send Height/CatchupCommitRound/CatchupCommit.
  586. {
  587. prs := ps.GetRoundState()
  588. if prs.CatchupCommitRound != -1 && 0 < prs.Height && prs.Height <= conR.conS.blockStore.Height() {
  589. commit := conR.conS.LoadCommit(prs.Height)
  590. peer.TrySend(StateChannel, struct{ ConsensusMessage }{&VoteSetMaj23Message{
  591. Height: prs.Height,
  592. Round: commit.Round(),
  593. Type: types.VoteTypePrecommit,
  594. BlockID: commit.BlockID,
  595. }})
  596. time.Sleep(peerQueryMaj23SleepDuration)
  597. }
  598. }
  599. time.Sleep(peerQueryMaj23SleepDuration)
  600. continue OUTER_LOOP
  601. }
  602. }
  603. func (conR *ConsensusReactor) String() string {
  604. return conR.StringIndented("")
  605. }
  606. func (conR *ConsensusReactor) StringIndented(indent string) string {
  607. s := "ConsensusReactor{\n"
  608. s += indent + " " + conR.conS.StringIndented(indent+" ") + "\n"
  609. for _, peer := range conR.Switch.Peers().List() {
  610. ps := peer.Data.Get(types.PeerStateKey).(*PeerState)
  611. s += indent + " " + ps.StringIndented(indent+" ") + "\n"
  612. }
  613. s += indent + "}"
  614. return s
  615. }
  616. //-----------------------------------------------------------------------------
  617. // Read only when returned by PeerState.GetRoundState().
  618. type PeerRoundState struct {
  619. Height int // Height peer is at
  620. Round int // Round peer is at, -1 if unknown.
  621. Step RoundStepType // Step peer is at
  622. StartTime time.Time // Estimated start of round 0 at this height
  623. Proposal bool // True if peer has proposal for this round
  624. ProposalBlockPartsHeader types.PartSetHeader //
  625. ProposalBlockParts *BitArray //
  626. ProposalPOLRound int // Proposal's POL round. -1 if none.
  627. ProposalPOL *BitArray // nil until ProposalPOLMessage received.
  628. Prevotes *BitArray // All votes peer has for this round
  629. Precommits *BitArray // All precommits peer has for this round
  630. LastCommitRound int // Round of commit for last height. -1 if none.
  631. LastCommit *BitArray // All commit precommits of commit for last height.
  632. CatchupCommitRound int // Round that we have commit for. Not necessarily unique. -1 if none.
  633. CatchupCommit *BitArray // All commit precommits peer has for this height & CatchupCommitRound
  634. }
  635. func (prs PeerRoundState) String() string {
  636. return prs.StringIndented("")
  637. }
  638. func (prs PeerRoundState) StringIndented(indent string) string {
  639. return fmt.Sprintf(`PeerRoundState{
  640. %s %v/%v/%v @%v
  641. %s Proposal %v -> %v
  642. %s POL %v (round %v)
  643. %s Prevotes %v
  644. %s Precommits %v
  645. %s LastCommit %v (round %v)
  646. %s Catchup %v (round %v)
  647. %s}`,
  648. indent, prs.Height, prs.Round, prs.Step, prs.StartTime,
  649. indent, prs.ProposalBlockPartsHeader, prs.ProposalBlockParts,
  650. indent, prs.ProposalPOL, prs.ProposalPOLRound,
  651. indent, prs.Prevotes,
  652. indent, prs.Precommits,
  653. indent, prs.LastCommit, prs.LastCommitRound,
  654. indent, prs.CatchupCommit, prs.CatchupCommitRound,
  655. indent)
  656. }
  657. //-----------------------------------------------------------------------------
  658. var (
  659. ErrPeerStateHeightRegression = errors.New("Error peer state height regression")
  660. ErrPeerStateInvalidStartTime = errors.New("Error peer state invalid startTime")
  661. )
  662. type PeerState struct {
  663. Peer *p2p.Peer
  664. mtx sync.Mutex
  665. PeerRoundState
  666. }
  667. func NewPeerState(peer *p2p.Peer) *PeerState {
  668. return &PeerState{
  669. Peer: peer,
  670. PeerRoundState: PeerRoundState{
  671. Round: -1,
  672. ProposalPOLRound: -1,
  673. LastCommitRound: -1,
  674. CatchupCommitRound: -1,
  675. },
  676. }
  677. }
  678. // Returns an atomic snapshot of the PeerRoundState.
  679. // There's no point in mutating it since it won't change PeerState.
  680. func (ps *PeerState) GetRoundState() *PeerRoundState {
  681. ps.mtx.Lock()
  682. defer ps.mtx.Unlock()
  683. prs := ps.PeerRoundState // copy
  684. return &prs
  685. }
  686. // Returns an atomic snapshot of the PeerRoundState's height
  687. // used by the mempool to ensure peers are caught up before broadcasting new txs
  688. func (ps *PeerState) GetHeight() int {
  689. ps.mtx.Lock()
  690. defer ps.mtx.Unlock()
  691. return ps.PeerRoundState.Height
  692. }
  693. func (ps *PeerState) SetHasProposal(proposal *types.Proposal) {
  694. ps.mtx.Lock()
  695. defer ps.mtx.Unlock()
  696. if ps.Height != proposal.Height || ps.Round != proposal.Round {
  697. return
  698. }
  699. if ps.Proposal {
  700. return
  701. }
  702. ps.Proposal = true
  703. ps.ProposalBlockPartsHeader = proposal.BlockPartsHeader
  704. ps.ProposalBlockParts = NewBitArray(proposal.BlockPartsHeader.Total)
  705. ps.ProposalPOLRound = proposal.POLRound
  706. ps.ProposalPOL = nil // Nil until ProposalPOLMessage received.
  707. }
  708. func (ps *PeerState) SetHasProposalBlockPart(height int, round int, index int) {
  709. ps.mtx.Lock()
  710. defer ps.mtx.Unlock()
  711. if ps.Height != height || ps.Round != round {
  712. return
  713. }
  714. ps.ProposalBlockParts.SetIndex(index, true)
  715. }
  716. // Convenience function to send vote to peer.
  717. // Returns true if vote was sent.
  718. func (ps *PeerState) PickSendVote(votes types.VoteSetReader) (ok bool) {
  719. if vote, ok := ps.PickVoteToSend(votes); ok {
  720. msg := &VoteMessage{vote}
  721. ps.Peer.Send(VoteChannel, struct{ ConsensusMessage }{msg})
  722. return true
  723. }
  724. return false
  725. }
  726. // votes: Must be the correct Size() for the Height().
  727. func (ps *PeerState) PickVoteToSend(votes types.VoteSetReader) (vote *types.Vote, ok bool) {
  728. ps.mtx.Lock()
  729. defer ps.mtx.Unlock()
  730. if votes.Size() == 0 {
  731. return nil, false
  732. }
  733. height, round, type_, size := votes.Height(), votes.Round(), votes.Type(), votes.Size()
  734. // Lazily set data using 'votes'.
  735. if votes.IsCommit() {
  736. ps.ensureCatchupCommitRound(height, round, size)
  737. }
  738. ps.ensureVoteBitArrays(height, size)
  739. psVotes := ps.getVoteBitArray(height, round, type_)
  740. if psVotes == nil {
  741. return nil, false // Not something worth sending
  742. }
  743. if index, ok := votes.BitArray().Sub(psVotes).PickRandom(); ok {
  744. ps.setHasVote(height, round, type_, index)
  745. return votes.GetByIndex(index), true
  746. }
  747. return nil, false
  748. }
  749. func (ps *PeerState) getVoteBitArray(height, round int, type_ byte) *BitArray {
  750. if !types.IsVoteTypeValid(type_) {
  751. PanicSanity("Invalid vote type")
  752. }
  753. if ps.Height == height {
  754. if ps.Round == round {
  755. switch type_ {
  756. case types.VoteTypePrevote:
  757. return ps.Prevotes
  758. case types.VoteTypePrecommit:
  759. return ps.Precommits
  760. }
  761. }
  762. if ps.CatchupCommitRound == round {
  763. switch type_ {
  764. case types.VoteTypePrevote:
  765. return nil
  766. case types.VoteTypePrecommit:
  767. return ps.CatchupCommit
  768. }
  769. }
  770. if ps.ProposalPOLRound == round {
  771. switch type_ {
  772. case types.VoteTypePrevote:
  773. return ps.ProposalPOL
  774. case types.VoteTypePrecommit:
  775. return nil
  776. }
  777. }
  778. return nil
  779. }
  780. if ps.Height == height+1 {
  781. if ps.LastCommitRound == round {
  782. switch type_ {
  783. case types.VoteTypePrevote:
  784. return nil
  785. case types.VoteTypePrecommit:
  786. return ps.LastCommit
  787. }
  788. }
  789. return nil
  790. }
  791. return nil
  792. }
  793. // 'round': A round for which we have a +2/3 commit.
  794. func (ps *PeerState) ensureCatchupCommitRound(height, round int, numValidators int) {
  795. if ps.Height != height {
  796. return
  797. }
  798. /*
  799. NOTE: This is wrong, 'round' could change.
  800. e.g. if orig round is not the same as block LastCommit round.
  801. if ps.CatchupCommitRound != -1 && ps.CatchupCommitRound != round {
  802. PanicSanity(Fmt("Conflicting CatchupCommitRound. Height: %v, Orig: %v, New: %v", height, ps.CatchupCommitRound, round))
  803. }
  804. */
  805. if ps.CatchupCommitRound == round {
  806. return // Nothing to do!
  807. }
  808. ps.CatchupCommitRound = round
  809. if round == ps.Round {
  810. ps.CatchupCommit = ps.Precommits
  811. } else {
  812. ps.CatchupCommit = NewBitArray(numValidators)
  813. }
  814. }
  815. // NOTE: It's important to make sure that numValidators actually matches
  816. // what the node sees as the number of validators for height.
  817. func (ps *PeerState) EnsureVoteBitArrays(height int, numValidators int) {
  818. ps.mtx.Lock()
  819. defer ps.mtx.Unlock()
  820. ps.ensureVoteBitArrays(height, numValidators)
  821. }
  822. func (ps *PeerState) ensureVoteBitArrays(height int, numValidators int) {
  823. if ps.Height == height {
  824. if ps.Prevotes == nil {
  825. ps.Prevotes = NewBitArray(numValidators)
  826. }
  827. if ps.Precommits == nil {
  828. ps.Precommits = NewBitArray(numValidators)
  829. }
  830. if ps.CatchupCommit == nil {
  831. ps.CatchupCommit = NewBitArray(numValidators)
  832. }
  833. if ps.ProposalPOL == nil {
  834. ps.ProposalPOL = NewBitArray(numValidators)
  835. }
  836. } else if ps.Height == height+1 {
  837. if ps.LastCommit == nil {
  838. ps.LastCommit = NewBitArray(numValidators)
  839. }
  840. }
  841. }
  842. func (ps *PeerState) SetHasVote(vote *types.Vote) {
  843. ps.mtx.Lock()
  844. defer ps.mtx.Unlock()
  845. ps.setHasVote(vote.Height, vote.Round, vote.Type, vote.ValidatorIndex)
  846. }
  847. func (ps *PeerState) setHasVote(height int, round int, type_ byte, index int) {
  848. log := log.New("peer", ps.Peer, "peerRound", ps.Round, "height", height, "round", round)
  849. log.Debug("setHasVote(LastCommit)", "lastCommit", ps.LastCommit, "index", index)
  850. // NOTE: some may be nil BitArrays -> no side effects.
  851. ps.getVoteBitArray(height, round, type_).SetIndex(index, true)
  852. }
  853. func (ps *PeerState) ApplyNewRoundStepMessage(msg *NewRoundStepMessage) {
  854. ps.mtx.Lock()
  855. defer ps.mtx.Unlock()
  856. // Ignore duplicates or decreases
  857. if CompareHRS(msg.Height, msg.Round, msg.Step, ps.Height, ps.Round, ps.Step) <= 0 {
  858. return
  859. }
  860. // Just remember these values.
  861. psHeight := ps.Height
  862. psRound := ps.Round
  863. //psStep := ps.Step
  864. psCatchupCommitRound := ps.CatchupCommitRound
  865. psCatchupCommit := ps.CatchupCommit
  866. startTime := time.Now().Add(-1 * time.Duration(msg.SecondsSinceStartTime) * time.Second)
  867. ps.Height = msg.Height
  868. ps.Round = msg.Round
  869. ps.Step = msg.Step
  870. ps.StartTime = startTime
  871. if psHeight != msg.Height || psRound != msg.Round {
  872. ps.Proposal = false
  873. ps.ProposalBlockPartsHeader = types.PartSetHeader{}
  874. ps.ProposalBlockParts = nil
  875. ps.ProposalPOLRound = -1
  876. ps.ProposalPOL = nil
  877. // We'll update the BitArray capacity later.
  878. ps.Prevotes = nil
  879. ps.Precommits = nil
  880. }
  881. if psHeight == msg.Height && psRound != msg.Round && msg.Round == psCatchupCommitRound {
  882. // Peer caught up to CatchupCommitRound.
  883. // Preserve psCatchupCommit!
  884. // NOTE: We prefer to use prs.Precommits if
  885. // pr.Round matches pr.CatchupCommitRound.
  886. ps.Precommits = psCatchupCommit
  887. }
  888. if psHeight != msg.Height {
  889. // Shift Precommits to LastCommit.
  890. if psHeight+1 == msg.Height && psRound == msg.LastCommitRound {
  891. ps.LastCommitRound = msg.LastCommitRound
  892. ps.LastCommit = ps.Precommits
  893. } else {
  894. ps.LastCommitRound = msg.LastCommitRound
  895. ps.LastCommit = nil
  896. }
  897. // We'll update the BitArray capacity later.
  898. ps.CatchupCommitRound = -1
  899. ps.CatchupCommit = nil
  900. }
  901. }
  902. func (ps *PeerState) ApplyCommitStepMessage(msg *CommitStepMessage) {
  903. ps.mtx.Lock()
  904. defer ps.mtx.Unlock()
  905. if ps.Height != msg.Height {
  906. return
  907. }
  908. ps.ProposalBlockPartsHeader = msg.BlockPartsHeader
  909. ps.ProposalBlockParts = msg.BlockParts
  910. }
  911. func (ps *PeerState) ApplyProposalPOLMessage(msg *ProposalPOLMessage) {
  912. ps.mtx.Lock()
  913. defer ps.mtx.Unlock()
  914. if ps.Height != msg.Height {
  915. return
  916. }
  917. if ps.ProposalPOLRound != msg.ProposalPOLRound {
  918. return
  919. }
  920. // TODO: Merge onto existing ps.ProposalPOL?
  921. // We might have sent some prevotes in the meantime.
  922. ps.ProposalPOL = msg.ProposalPOL
  923. }
  924. func (ps *PeerState) ApplyHasVoteMessage(msg *HasVoteMessage) {
  925. ps.mtx.Lock()
  926. defer ps.mtx.Unlock()
  927. if ps.Height != msg.Height {
  928. return
  929. }
  930. ps.setHasVote(msg.Height, msg.Round, msg.Type, msg.Index)
  931. }
  932. // The peer has responded with a bitarray of votes that it has
  933. // of the corresponding BlockID.
  934. // ourVotes: BitArray of votes we have for msg.BlockID
  935. // NOTE: if ourVotes is nil (e.g. msg.Height < rs.Height),
  936. // we conservatively overwrite ps's votes w/ msg.Votes.
  937. func (ps *PeerState) ApplyVoteSetBitsMessage(msg *VoteSetBitsMessage, ourVotes *BitArray) {
  938. ps.mtx.Lock()
  939. defer ps.mtx.Unlock()
  940. votes := ps.getVoteBitArray(msg.Height, msg.Round, msg.Type)
  941. if votes != nil {
  942. if ourVotes == nil {
  943. votes.Update(msg.Votes)
  944. } else {
  945. otherVotes := votes.Sub(ourVotes)
  946. hasVotes := otherVotes.Or(msg.Votes)
  947. votes.Update(hasVotes)
  948. }
  949. }
  950. }
  951. func (ps *PeerState) String() string {
  952. return ps.StringIndented("")
  953. }
  954. func (ps *PeerState) StringIndented(indent string) string {
  955. return fmt.Sprintf(`PeerState{
  956. %s Key %v
  957. %s PRS %v
  958. %s}`,
  959. indent, ps.Peer.Key,
  960. indent, ps.PeerRoundState.StringIndented(indent+" "),
  961. indent)
  962. }
  963. //-----------------------------------------------------------------------------
  964. // Messages
  965. const (
  966. msgTypeNewRoundStep = byte(0x01)
  967. msgTypeCommitStep = byte(0x02)
  968. msgTypeProposal = byte(0x11)
  969. msgTypeProposalPOL = byte(0x12)
  970. msgTypeBlockPart = byte(0x13) // both block & POL
  971. msgTypeVote = byte(0x14)
  972. msgTypeHasVote = byte(0x15)
  973. msgTypeVoteSetMaj23 = byte(0x16)
  974. msgTypeVoteSetBits = byte(0x17)
  975. )
  976. type ConsensusMessage interface{}
  977. var _ = wire.RegisterInterface(
  978. struct{ ConsensusMessage }{},
  979. wire.ConcreteType{&NewRoundStepMessage{}, msgTypeNewRoundStep},
  980. wire.ConcreteType{&CommitStepMessage{}, msgTypeCommitStep},
  981. wire.ConcreteType{&ProposalMessage{}, msgTypeProposal},
  982. wire.ConcreteType{&ProposalPOLMessage{}, msgTypeProposalPOL},
  983. wire.ConcreteType{&BlockPartMessage{}, msgTypeBlockPart},
  984. wire.ConcreteType{&VoteMessage{}, msgTypeVote},
  985. wire.ConcreteType{&HasVoteMessage{}, msgTypeHasVote},
  986. wire.ConcreteType{&VoteSetMaj23Message{}, msgTypeVoteSetMaj23},
  987. wire.ConcreteType{&VoteSetBitsMessage{}, msgTypeVoteSetBits},
  988. )
  989. // TODO: check for unnecessary extra bytes at the end.
  990. func DecodeMessage(bz []byte) (msgType byte, msg ConsensusMessage, err error) {
  991. msgType = bz[0]
  992. n := new(int)
  993. r := bytes.NewReader(bz)
  994. msg = wire.ReadBinary(struct{ ConsensusMessage }{}, r, maxConsensusMessageSize, n, &err).(struct{ ConsensusMessage }).ConsensusMessage
  995. return
  996. }
  997. //-------------------------------------
  998. // For every height/round/step transition
  999. type NewRoundStepMessage struct {
  1000. Height int
  1001. Round int
  1002. Step RoundStepType
  1003. SecondsSinceStartTime int
  1004. LastCommitRound int
  1005. }
  1006. func (m *NewRoundStepMessage) String() string {
  1007. return fmt.Sprintf("[NewRoundStep H:%v R:%v S:%v LCR:%v]",
  1008. m.Height, m.Round, m.Step, m.LastCommitRound)
  1009. }
  1010. //-------------------------------------
  1011. type CommitStepMessage struct {
  1012. Height int
  1013. BlockPartsHeader types.PartSetHeader
  1014. BlockParts *BitArray
  1015. }
  1016. func (m *CommitStepMessage) String() string {
  1017. return fmt.Sprintf("[CommitStep H:%v BP:%v BA:%v]", m.Height, m.BlockPartsHeader, m.BlockParts)
  1018. }
  1019. //-------------------------------------
  1020. type ProposalMessage struct {
  1021. Proposal *types.Proposal
  1022. }
  1023. func (m *ProposalMessage) String() string {
  1024. return fmt.Sprintf("[Proposal %v]", m.Proposal)
  1025. }
  1026. //-------------------------------------
  1027. type ProposalPOLMessage struct {
  1028. Height int
  1029. ProposalPOLRound int
  1030. ProposalPOL *BitArray
  1031. }
  1032. func (m *ProposalPOLMessage) String() string {
  1033. return fmt.Sprintf("[ProposalPOL H:%v POLR:%v POL:%v]", m.Height, m.ProposalPOLRound, m.ProposalPOL)
  1034. }
  1035. //-------------------------------------
  1036. type BlockPartMessage struct {
  1037. Height int
  1038. Round int
  1039. Part *types.Part
  1040. }
  1041. func (m *BlockPartMessage) String() string {
  1042. return fmt.Sprintf("[BlockPart H:%v R:%v P:%v]", m.Height, m.Round, m.Part)
  1043. }
  1044. //-------------------------------------
  1045. type VoteMessage struct {
  1046. Vote *types.Vote
  1047. }
  1048. func (m *VoteMessage) String() string {
  1049. return fmt.Sprintf("[Vote %v]", m.Vote)
  1050. }
  1051. //-------------------------------------
  1052. type HasVoteMessage struct {
  1053. Height int
  1054. Round int
  1055. Type byte
  1056. Index int
  1057. }
  1058. func (m *HasVoteMessage) String() string {
  1059. return fmt.Sprintf("[HasVote VI:%v V:{%v/%02d/%v} VI:%v]", m.Index, m.Height, m.Round, m.Type, m.Index)
  1060. }
  1061. //-------------------------------------
  1062. type VoteSetMaj23Message struct {
  1063. Height int
  1064. Round int
  1065. Type byte
  1066. BlockID types.BlockID
  1067. }
  1068. func (m *VoteSetMaj23Message) String() string {
  1069. return fmt.Sprintf("[VSM23 %v/%02d/%v %v]", m.Height, m.Round, m.Type, m.BlockID)
  1070. }
  1071. //-------------------------------------
  1072. type VoteSetBitsMessage struct {
  1073. Height int
  1074. Round int
  1075. Type byte
  1076. BlockID types.BlockID
  1077. Votes *BitArray
  1078. }
  1079. func (m *VoteSetBitsMessage) String() string {
  1080. return fmt.Sprintf("[VSB %v/%02d/%v %v %v]", m.Height, m.Round, m.Type, m.BlockID, m.Votes)
  1081. }