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.

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