|
@ -10,7 +10,6 @@ import ( |
|
|
|
|
|
|
|
|
. "github.com/tendermint/go-common" |
|
|
. "github.com/tendermint/go-common" |
|
|
cfg "github.com/tendermint/go-config" |
|
|
cfg "github.com/tendermint/go-config" |
|
|
"github.com/tendermint/go-events" |
|
|
|
|
|
"github.com/tendermint/go-wire" |
|
|
"github.com/tendermint/go-wire" |
|
|
bc "github.com/tendermint/tendermint/blockchain" |
|
|
bc "github.com/tendermint/tendermint/blockchain" |
|
|
mempl "github.com/tendermint/tendermint/mempool" |
|
|
mempl "github.com/tendermint/tendermint/mempool" |
|
@ -231,7 +230,7 @@ type ConsensusState struct { |
|
|
tockChan chan timeoutInfo // timeouts are relayed on tockChan to the receiveRoutine
|
|
|
tockChan chan timeoutInfo // timeouts are relayed on tockChan to the receiveRoutine
|
|
|
timeoutParams *TimeoutParams // parameters and functions for timeout intervals
|
|
|
timeoutParams *TimeoutParams // parameters and functions for timeout intervals
|
|
|
|
|
|
|
|
|
evsw *events.EventSwitch |
|
|
|
|
|
|
|
|
evsw types.EventSwitch |
|
|
|
|
|
|
|
|
wal *WAL |
|
|
wal *WAL |
|
|
replayMode bool // so we don't log signing errors during replay
|
|
|
replayMode bool // so we don't log signing errors during replay
|
|
@ -264,7 +263,7 @@ func NewConsensusState(config cfg.Config, state *sm.State, proxyAppConn proxy.Ap |
|
|
// Public interface
|
|
|
// Public interface
|
|
|
|
|
|
|
|
|
// implements events.Eventable
|
|
|
// implements events.Eventable
|
|
|
func (cs *ConsensusState) SetEventSwitch(evsw *events.EventSwitch) { |
|
|
|
|
|
|
|
|
func (cs *ConsensusState) SetEventSwitch(evsw types.EventSwitch) { |
|
|
cs.evsw = evsw |
|
|
cs.evsw = evsw |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -545,7 +544,7 @@ func (cs *ConsensusState) newStep() { |
|
|
cs.nSteps += 1 |
|
|
cs.nSteps += 1 |
|
|
// newStep is called by updateToStep in NewConsensusState before the evsw is set!
|
|
|
// newStep is called by updateToStep in NewConsensusState before the evsw is set!
|
|
|
if cs.evsw != nil { |
|
|
if cs.evsw != nil { |
|
|
cs.evsw.FireEvent(types.EventStringNewRoundStep(), rs) |
|
|
|
|
|
|
|
|
types.FireEventNewRoundStep(cs.evsw, rs) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -719,13 +718,13 @@ func (cs *ConsensusState) handleTimeout(ti timeoutInfo, rs RoundState) { |
|
|
// XXX: should we fire timeout here?
|
|
|
// XXX: should we fire timeout here?
|
|
|
cs.enterNewRound(ti.Height, 0) |
|
|
cs.enterNewRound(ti.Height, 0) |
|
|
case RoundStepPropose: |
|
|
case RoundStepPropose: |
|
|
cs.evsw.FireEvent(types.EventStringTimeoutPropose(), cs.RoundStateEvent()) |
|
|
|
|
|
|
|
|
types.FireEventTimeoutPropose(cs.evsw, cs.RoundStateEvent()) |
|
|
cs.enterPrevote(ti.Height, ti.Round) |
|
|
cs.enterPrevote(ti.Height, ti.Round) |
|
|
case RoundStepPrevoteWait: |
|
|
case RoundStepPrevoteWait: |
|
|
cs.evsw.FireEvent(types.EventStringTimeoutWait(), cs.RoundStateEvent()) |
|
|
|
|
|
|
|
|
types.FireEventTimeoutWait(cs.evsw, cs.RoundStateEvent()) |
|
|
cs.enterPrecommit(ti.Height, ti.Round) |
|
|
cs.enterPrecommit(ti.Height, ti.Round) |
|
|
case RoundStepPrecommitWait: |
|
|
case RoundStepPrecommitWait: |
|
|
cs.evsw.FireEvent(types.EventStringTimeoutWait(), cs.RoundStateEvent()) |
|
|
|
|
|
|
|
|
types.FireEventTimeoutWait(cs.evsw, cs.RoundStateEvent()) |
|
|
cs.enterNewRound(ti.Height, ti.Round+1) |
|
|
cs.enterNewRound(ti.Height, ti.Round+1) |
|
|
default: |
|
|
default: |
|
|
panic(Fmt("Invalid timeout step: %v", ti.Step)) |
|
|
panic(Fmt("Invalid timeout step: %v", ti.Step)) |
|
@ -777,7 +776,7 @@ func (cs *ConsensusState) enterNewRound(height int, round int) { |
|
|
} |
|
|
} |
|
|
cs.Votes.SetRound(round + 1) // also track next round (round+1) to allow round-skipping
|
|
|
cs.Votes.SetRound(round + 1) // also track next round (round+1) to allow round-skipping
|
|
|
|
|
|
|
|
|
cs.evsw.FireEvent(types.EventStringNewRound(), cs.RoundStateEvent()) |
|
|
|
|
|
|
|
|
types.FireEventNewRound(cs.evsw, cs.RoundStateEvent()) |
|
|
|
|
|
|
|
|
// Immediately go to enterPropose.
|
|
|
// Immediately go to enterPropose.
|
|
|
cs.enterPropose(height, round) |
|
|
cs.enterPropose(height, round) |
|
@ -942,7 +941,7 @@ func (cs *ConsensusState) enterPrevote(height int, round int) { |
|
|
|
|
|
|
|
|
// fire event for how we got here
|
|
|
// fire event for how we got here
|
|
|
if cs.isProposalComplete() { |
|
|
if cs.isProposalComplete() { |
|
|
cs.evsw.FireEvent(types.EventStringCompleteProposal(), cs.RoundStateEvent()) |
|
|
|
|
|
|
|
|
types.FireEventCompleteProposal(cs.evsw, cs.RoundStateEvent()) |
|
|
} else { |
|
|
} else { |
|
|
// we received +2/3 prevotes for a future round
|
|
|
// we received +2/3 prevotes for a future round
|
|
|
// TODO: catchup event?
|
|
|
// TODO: catchup event?
|
|
@ -1047,7 +1046,7 @@ func (cs *ConsensusState) enterPrecommit(height int, round int) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// At this point +2/3 prevoted for a particular block or nil
|
|
|
// At this point +2/3 prevoted for a particular block or nil
|
|
|
cs.evsw.FireEvent(types.EventStringPolka(), cs.RoundStateEvent()) |
|
|
|
|
|
|
|
|
types.FireEventPolka(cs.evsw, cs.RoundStateEvent()) |
|
|
|
|
|
|
|
|
// the latest POLRound should be this round
|
|
|
// the latest POLRound should be this round
|
|
|
if cs.Votes.POLRound() < round { |
|
|
if cs.Votes.POLRound() < round { |
|
@ -1063,7 +1062,7 @@ func (cs *ConsensusState) enterPrecommit(height int, round int) { |
|
|
cs.LockedRound = 0 |
|
|
cs.LockedRound = 0 |
|
|
cs.LockedBlock = nil |
|
|
cs.LockedBlock = nil |
|
|
cs.LockedBlockParts = nil |
|
|
cs.LockedBlockParts = nil |
|
|
cs.evsw.FireEvent(types.EventStringUnlock(), cs.RoundStateEvent()) |
|
|
|
|
|
|
|
|
types.FireEventUnlock(cs.evsw, cs.RoundStateEvent()) |
|
|
} |
|
|
} |
|
|
cs.signAddVote(types.VoteTypePrecommit, nil, types.PartSetHeader{}) |
|
|
cs.signAddVote(types.VoteTypePrecommit, nil, types.PartSetHeader{}) |
|
|
return |
|
|
return |
|
@ -1075,7 +1074,7 @@ func (cs *ConsensusState) enterPrecommit(height int, round int) { |
|
|
if cs.LockedBlock.HashesTo(hash) { |
|
|
if cs.LockedBlock.HashesTo(hash) { |
|
|
log.Notice("enterPrecommit: +2/3 prevoted locked block. Relocking") |
|
|
log.Notice("enterPrecommit: +2/3 prevoted locked block. Relocking") |
|
|
cs.LockedRound = round |
|
|
cs.LockedRound = round |
|
|
cs.evsw.FireEvent(types.EventStringRelock(), cs.RoundStateEvent()) |
|
|
|
|
|
|
|
|
types.FireEventRelock(cs.evsw, cs.RoundStateEvent()) |
|
|
cs.signAddVote(types.VoteTypePrecommit, hash, partsHeader) |
|
|
cs.signAddVote(types.VoteTypePrecommit, hash, partsHeader) |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
@ -1090,7 +1089,7 @@ func (cs *ConsensusState) enterPrecommit(height int, round int) { |
|
|
cs.LockedRound = round |
|
|
cs.LockedRound = round |
|
|
cs.LockedBlock = cs.ProposalBlock |
|
|
cs.LockedBlock = cs.ProposalBlock |
|
|
cs.LockedBlockParts = cs.ProposalBlockParts |
|
|
cs.LockedBlockParts = cs.ProposalBlockParts |
|
|
cs.evsw.FireEvent(types.EventStringLock(), cs.RoundStateEvent()) |
|
|
|
|
|
|
|
|
types.FireEventLock(cs.evsw, cs.RoundStateEvent()) |
|
|
cs.signAddVote(types.VoteTypePrecommit, hash, partsHeader) |
|
|
cs.signAddVote(types.VoteTypePrecommit, hash, partsHeader) |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
@ -1106,7 +1105,7 @@ func (cs *ConsensusState) enterPrecommit(height int, round int) { |
|
|
cs.ProposalBlock = nil |
|
|
cs.ProposalBlock = nil |
|
|
cs.ProposalBlockParts = types.NewPartSetFromHeader(partsHeader) |
|
|
cs.ProposalBlockParts = types.NewPartSetFromHeader(partsHeader) |
|
|
} |
|
|
} |
|
|
cs.evsw.FireEvent(types.EventStringUnlock(), cs.RoundStateEvent()) |
|
|
|
|
|
|
|
|
types.FireEventUnlock(cs.evsw, cs.RoundStateEvent()) |
|
|
cs.signAddVote(types.VoteTypePrecommit, nil, types.PartSetHeader{}) |
|
|
cs.signAddVote(types.VoteTypePrecommit, nil, types.PartSetHeader{}) |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
@ -1226,14 +1225,14 @@ func (cs *ConsensusState) finalizeCommit(height int) { |
|
|
|
|
|
|
|
|
// Fire off event for new block.
|
|
|
// Fire off event for new block.
|
|
|
// TODO: Handle app failure. See #177
|
|
|
// TODO: Handle app failure. See #177
|
|
|
cs.evsw.FireEvent(types.EventStringNewBlock(), types.EventDataNewBlock{block}) |
|
|
|
|
|
cs.evsw.FireEvent(types.EventStringNewBlockHeader(), types.EventDataNewBlockHeader{block.Header}) |
|
|
|
|
|
|
|
|
types.FireEventNewBlock(cs.evsw, types.EventDataNewBlock{block}) |
|
|
|
|
|
types.FireEventNewBlockHeader(cs.evsw, types.EventDataNewBlockHeader{block.Header}) |
|
|
|
|
|
|
|
|
// Create a copy of the state for staging
|
|
|
// Create a copy of the state for staging
|
|
|
stateCopy := cs.state.Copy() |
|
|
stateCopy := cs.state.Copy() |
|
|
|
|
|
|
|
|
// event cache for txs
|
|
|
// event cache for txs
|
|
|
eventCache := events.NewEventCache(cs.evsw) |
|
|
|
|
|
|
|
|
eventCache := types.NewEventCache(cs.evsw) |
|
|
|
|
|
|
|
|
// Run the block on the State:
|
|
|
// Run the block on the State:
|
|
|
// + update validator sets
|
|
|
// + update validator sets
|
|
@ -1423,7 +1422,7 @@ func (cs *ConsensusState) addVote(valIndex int, vote *types.Vote, peerKey string |
|
|
added, address, err = cs.LastCommit.AddByIndex(valIndex, vote) |
|
|
added, address, err = cs.LastCommit.AddByIndex(valIndex, vote) |
|
|
if added { |
|
|
if added { |
|
|
log.Info(Fmt("Added to lastPrecommits: %v", cs.LastCommit.StringShort())) |
|
|
log.Info(Fmt("Added to lastPrecommits: %v", cs.LastCommit.StringShort())) |
|
|
cs.evsw.FireEvent(types.EventStringVote(), types.EventDataVote{valIndex, address, vote}) |
|
|
|
|
|
|
|
|
types.FireEventVote(cs.evsw, types.EventDataVote{valIndex, address, vote}) |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
return |
|
|
return |
|
@ -1434,7 +1433,7 @@ func (cs *ConsensusState) addVote(valIndex int, vote *types.Vote, peerKey string |
|
|
height := cs.Height |
|
|
height := cs.Height |
|
|
added, address, err = cs.Votes.AddByIndex(valIndex, vote, peerKey) |
|
|
added, address, err = cs.Votes.AddByIndex(valIndex, vote, peerKey) |
|
|
if added { |
|
|
if added { |
|
|
cs.evsw.FireEvent(types.EventStringVote(), types.EventDataVote{valIndex, address, vote}) |
|
|
|
|
|
|
|
|
types.FireEventVote(cs.evsw, types.EventDataVote{valIndex, address, vote}) |
|
|
|
|
|
|
|
|
switch vote.Type { |
|
|
switch vote.Type { |
|
|
case types.VoteTypePrevote: |
|
|
case types.VoteTypePrevote: |
|
@ -1452,7 +1451,7 @@ func (cs *ConsensusState) addVote(valIndex int, vote *types.Vote, peerKey string |
|
|
cs.LockedRound = 0 |
|
|
cs.LockedRound = 0 |
|
|
cs.LockedBlock = nil |
|
|
cs.LockedBlock = nil |
|
|
cs.LockedBlockParts = nil |
|
|
cs.LockedBlockParts = nil |
|
|
cs.evsw.FireEvent(types.EventStringUnlock(), cs.RoundStateEvent()) |
|
|
|
|
|
|
|
|
types.FireEventUnlock(cs.evsw, cs.RoundStateEvent()) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
if cs.Round <= vote.Round && prevotes.HasTwoThirdsAny() { |
|
|
if cs.Round <= vote.Round && prevotes.HasTwoThirdsAny() { |
|
|