some fixes

This commit is contained in:
Ethan Buchman 2017-08-03 13:25:26 -04:00
parent ab753abfa0
commit b8ac67e240
2 changed files with 19 additions and 20 deletions

View File

@ -1318,7 +1318,7 @@ func (m *VoteSetBitsMessage) String() string {
//-------------------------------------
// ProposalHeartbeatMessage is sent to signal that the proposer is alive and waiting for transactions
// ProposalHeartbeatMessage is sent to signal that a node is alive and waiting for transactions for a proposal.
type ProposalHeartbeatMessage struct {
Heartbeat *types.Heartbeat
}

View File

@ -788,7 +788,7 @@ func (cs *ConsensusState) enterNewRound(height int, round int) {
// we may need an empty "proof" block, and enterPropose immediately.
waitForTxs := cs.config.NoEmptyBlocks && round == 0 && !cs.needProofBlock(height)
if waitForTxs {
go cs.proposalHeartbeat()
go cs.proposalHeartbeat(height, round)
} else {
cs.enterPropose(height, round)
}
@ -808,7 +808,7 @@ func (cs *ConsensusState) needProofBlock(height int) bool {
return false
}
func (cs *ConsensusState) proposalHeartbeat() {
func (cs *ConsensusState) proposalHeartbeat(height, round int) {
counter := 0
addr := cs.privValidator.GetAddress()
valIndex, v := cs.Validators.GetByAddress(addr)
@ -817,24 +817,23 @@ func (cs *ConsensusState) proposalHeartbeat() {
valIndex = -1
}
for {
select {
default:
if cs.evsw != nil {
rs := cs.GetRoundState().RoundStateEvent()
heartbeat := &types.Heartbeat{
Height: rs.Height,
Round: rs.Round,
Sequence: counter,
ValidatorAddress: addr,
ValidatorIndex: valIndex,
}
cs.privValidator.SignHeartbeat(cs.state.ChainID, heartbeat)
heartbeatEvent := types.EventDataProposalHeartbeat{heartbeat}
types.FireEventProposalHeartbeat(cs.evsw, heartbeatEvent)
counter += 1
}
time.Sleep(time.Second)
rs := cs.GetRoundState()
// if we've already moved on, no need to send more heartbeats
if rs.Step > RoundStepNewRound || rs.Round > round || rs.Height > height {
return
}
heartbeat := &types.Heartbeat{
Height: rs.Height,
Round: rs.Round,
Sequence: counter,
ValidatorAddress: addr,
ValidatorIndex: valIndex,
}
cs.privValidator.SignHeartbeat(cs.state.ChainID, heartbeat)
heartbeatEvent := types.EventDataProposalHeartbeat{heartbeat}
types.FireEventProposalHeartbeat(cs.evsw, heartbeatEvent)
counter += 1
time.Sleep(time.Second)
}
}