consensus: remove rs from handleMsg

This commit is contained in:
Ethan Buchman 2017-07-25 10:52:14 -04:00
parent ecdda69fab
commit cf3abe5096
2 changed files with 13 additions and 7 deletions

View File

@ -82,7 +82,7 @@ func (cs *ConsensusState) readReplayMessage(msgBytes []byte, newStepCh chan inte
"blockID", v.BlockID, "peer", peerKey) "blockID", v.BlockID, "peer", peerKey)
} }
cs.handleMsg(m, cs.RoundState) cs.handleMsg(m)
case timeoutInfo: case timeoutInfo:
cs.Logger.Info("Replay: Timeout", "height", m.Height, "round", m.Round, "step", m.Step, "dur", m.Duration) cs.Logger.Info("Replay: Timeout", "height", m.Height, "round", m.Round, "step", m.Step, "dur", m.Duration)
cs.handleTimeout(m, cs.RoundState) cs.handleTimeout(m, cs.RoundState)

View File

@ -611,7 +611,8 @@ func (cs *ConsensusState) newStep() {
// receiveRoutine handles messages which may cause state transitions. // receiveRoutine handles messages which may cause state transitions.
// it's argument (n) is the number of messages to process before exiting - use 0 to run forever // it's argument (n) is the number of messages to process before exiting - use 0 to run forever
// It keeps the RoundState and is the only thing that updates it. // It keeps the RoundState and is the only thing that updates it.
// Updates (state transitions) happen on timeouts, complete proposals, and 2/3 majorities // Updates (state transitions) happen on timeouts, complete proposals, and 2/3 majorities.
// ConsensusState must be locked before any internal state is updated.
func (cs *ConsensusState) receiveRoutine(maxSteps int) { func (cs *ConsensusState) receiveRoutine(maxSteps int) {
for { for {
if maxSteps > 0 { if maxSteps > 0 {
@ -625,17 +626,19 @@ func (cs *ConsensusState) receiveRoutine(maxSteps int) {
var mi msgInfo var mi msgInfo
select { select {
case rs_ := <-cs.txsAvailable: case <-cs.txsAvailable:
cs.enterPropose(rs_.Height, rs_.Round) // use nil for this special internal message signalling txs are available.
// no need to write this to the wal
// cs.handleMsg(msgInfo{nil, ""}, rs_)
case mi = <-cs.peerMsgQueue: case mi = <-cs.peerMsgQueue:
cs.wal.Save(mi) cs.wal.Save(mi)
// handles proposals, block parts, votes // handles proposals, block parts, votes
// may generate internal events (votes, complete proposals, 2/3 majorities) // may generate internal events (votes, complete proposals, 2/3 majorities)
cs.handleMsg(mi, rs) cs.handleMsg(mi)
case mi = <-cs.internalMsgQueue: case mi = <-cs.internalMsgQueue:
cs.wal.Save(mi) cs.wal.Save(mi)
// handles proposals, block parts, votes // handles proposals, block parts, votes
cs.handleMsg(mi, rs) cs.handleMsg(mi)
case ti := <-cs.timeoutTicker.Chan(): // tockChan: case ti := <-cs.timeoutTicker.Chan(): // tockChan:
cs.wal.Save(ti) cs.wal.Save(ti)
// if the timeout is relevant to the rs // if the timeout is relevant to the rs
@ -659,13 +662,16 @@ func (cs *ConsensusState) receiveRoutine(maxSteps int) {
} }
// state transitions on complete-proposal, 2/3-any, 2/3-one // state transitions on complete-proposal, 2/3-any, 2/3-one
func (cs *ConsensusState) handleMsg(mi msgInfo, rs RoundState) { func (cs *ConsensusState) handleMsg(mi msgInfo) {
cs.mtx.Lock() cs.mtx.Lock()
defer cs.mtx.Unlock() defer cs.mtx.Unlock()
var err error var err error
msg, peerKey := mi.Msg, mi.PeerKey msg, peerKey := mi.Msg, mi.PeerKey
switch msg := msg.(type) { switch msg := msg.(type) {
case nil:
// transactions are available, so enterPropose
// cs.enterPropose(rs.Height, rs.Round)
case *ProposalMessage: case *ProposalMessage:
// will not cause transition. // will not cause transition.
// once proposal is set, we can receive block parts // once proposal is set, we can receive block parts