|
@ -46,6 +46,7 @@ type Reactor struct { |
|
|
mtx tmsync.RWMutex |
|
|
mtx tmsync.RWMutex |
|
|
waitSync bool |
|
|
waitSync bool |
|
|
eventBus *types.EventBus |
|
|
eventBus *types.EventBus |
|
|
|
|
|
rs *cstypes.RoundState |
|
|
|
|
|
|
|
|
Metrics *Metrics |
|
|
Metrics *Metrics |
|
|
} |
|
|
} |
|
@ -58,6 +59,7 @@ func NewReactor(consensusState *State, waitSync bool, options ...ReactorOption) |
|
|
conR := &Reactor{ |
|
|
conR := &Reactor{ |
|
|
conS: consensusState, |
|
|
conS: consensusState, |
|
|
waitSync: waitSync, |
|
|
waitSync: waitSync, |
|
|
|
|
|
rs: consensusState.GetRoundState(), |
|
|
Metrics: NopMetrics(), |
|
|
Metrics: NopMetrics(), |
|
|
} |
|
|
} |
|
|
conR.BaseReactor = *p2p.NewBaseReactor("Consensus", conR) |
|
|
conR.BaseReactor = *p2p.NewBaseReactor("Consensus", conR) |
|
@ -78,6 +80,7 @@ func (conR *Reactor) OnStart() error { |
|
|
go conR.peerStatsRoutine() |
|
|
go conR.peerStatsRoutine() |
|
|
|
|
|
|
|
|
conR.subscribeToBroadcastEvents() |
|
|
conR.subscribeToBroadcastEvents() |
|
|
|
|
|
go conR.updateRoundStateRoutine() |
|
|
|
|
|
|
|
|
if !conR.WaitSync() { |
|
|
if !conR.WaitSync() { |
|
|
err := conR.conS.Start() |
|
|
err := conR.conS.Start() |
|
@ -482,11 +485,35 @@ func makeRoundStepMessage(rs *cstypes.RoundState) (nrsMsg *NewRoundStepMessage) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (conR *Reactor) sendNewRoundStepMessage(peer p2p.Peer) { |
|
|
func (conR *Reactor) sendNewRoundStepMessage(peer p2p.Peer) { |
|
|
rs := conR.conS.GetRoundState() |
|
|
|
|
|
|
|
|
rs := conR.getRoundState() |
|
|
nrsMsg := makeRoundStepMessage(rs) |
|
|
nrsMsg := makeRoundStepMessage(rs) |
|
|
peer.Send(StateChannel, MustEncode(nrsMsg)) |
|
|
peer.Send(StateChannel, MustEncode(nrsMsg)) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (conR *Reactor) updateRoundStateRoutine() { |
|
|
|
|
|
for { |
|
|
|
|
|
if !conR.IsRunning() { |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
rs := conR.conS.GetRoundState() |
|
|
|
|
|
conR.mtx.Lock() |
|
|
|
|
|
conR.rs = rs |
|
|
|
|
|
conR.mtx.Unlock() |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (conR *Reactor) setRoundState(rs *cstypes.RoundState) { |
|
|
|
|
|
conR.mtx.Lock() |
|
|
|
|
|
defer conR.mtx.Unlock() |
|
|
|
|
|
conR.rs = rs |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (conR *Reactor) getRoundState() *cstypes.RoundState { |
|
|
|
|
|
conR.mtx.RLock() |
|
|
|
|
|
defer conR.mtx.RUnlock() |
|
|
|
|
|
return conR.rs |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
func (conR *Reactor) gossipDataRoutine(peer p2p.Peer, ps *PeerState) { |
|
|
func (conR *Reactor) gossipDataRoutine(peer p2p.Peer, ps *PeerState) { |
|
|
logger := conR.Logger.With("peer", peer) |
|
|
logger := conR.Logger.With("peer", peer) |
|
|
|
|
|
|
|
@ -496,7 +523,7 @@ OUTER_LOOP: |
|
|
if !peer.IsRunning() || !conR.IsRunning() { |
|
|
if !peer.IsRunning() || !conR.IsRunning() { |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
rs := conR.conS.GetRoundState() |
|
|
|
|
|
|
|
|
rs := conR.getRoundState() |
|
|
prs := ps.GetRoundState() |
|
|
prs := ps.GetRoundState() |
|
|
|
|
|
|
|
|
// Send proposal Block parts?
|
|
|
// Send proposal Block parts?
|
|
@ -639,7 +666,7 @@ OUTER_LOOP: |
|
|
if !peer.IsRunning() || !conR.IsRunning() { |
|
|
if !peer.IsRunning() || !conR.IsRunning() { |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
rs := conR.conS.GetRoundState() |
|
|
|
|
|
|
|
|
rs := conR.getRoundState() |
|
|
prs := ps.GetRoundState() |
|
|
prs := ps.GetRoundState() |
|
|
|
|
|
|
|
|
switch sleeping { |
|
|
switch sleeping { |
|
@ -771,7 +798,7 @@ OUTER_LOOP: |
|
|
|
|
|
|
|
|
// Maybe send Height/Round/Prevotes
|
|
|
// Maybe send Height/Round/Prevotes
|
|
|
{ |
|
|
{ |
|
|
rs := conR.conS.GetRoundState() |
|
|
|
|
|
|
|
|
rs := conR.getRoundState() |
|
|
prs := ps.GetRoundState() |
|
|
prs := ps.GetRoundState() |
|
|
if rs.Height == prs.Height { |
|
|
if rs.Height == prs.Height { |
|
|
if maj23, ok := rs.Votes.Prevotes(prs.Round).TwoThirdsMajority(); ok { |
|
|
if maj23, ok := rs.Votes.Prevotes(prs.Round).TwoThirdsMajority(); ok { |
|
@ -788,7 +815,7 @@ OUTER_LOOP: |
|
|
|
|
|
|
|
|
// Maybe send Height/Round/Precommits
|
|
|
// Maybe send Height/Round/Precommits
|
|
|
{ |
|
|
{ |
|
|
rs := conR.conS.GetRoundState() |
|
|
|
|
|
|
|
|
rs := conR.getRoundState() |
|
|
prs := ps.GetRoundState() |
|
|
prs := ps.GetRoundState() |
|
|
if rs.Height == prs.Height { |
|
|
if rs.Height == prs.Height { |
|
|
if maj23, ok := rs.Votes.Precommits(prs.Round).TwoThirdsMajority(); ok { |
|
|
if maj23, ok := rs.Votes.Precommits(prs.Round).TwoThirdsMajority(); ok { |
|
@ -805,7 +832,7 @@ OUTER_LOOP: |
|
|
|
|
|
|
|
|
// Maybe send Height/Round/ProposalPOL
|
|
|
// Maybe send Height/Round/ProposalPOL
|
|
|
{ |
|
|
{ |
|
|
rs := conR.conS.GetRoundState() |
|
|
|
|
|
|
|
|
rs := conR.getRoundState() |
|
|
prs := ps.GetRoundState() |
|
|
prs := ps.GetRoundState() |
|
|
if rs.Height == prs.Height && prs.ProposalPOLRound >= 0 { |
|
|
if rs.Height == prs.Height && prs.ProposalPOLRound >= 0 { |
|
|
if maj23, ok := rs.Votes.Prevotes(prs.ProposalPOLRound).TwoThirdsMajority(); ok { |
|
|
if maj23, ok := rs.Votes.Prevotes(prs.ProposalPOLRound).TwoThirdsMajority(); ok { |
|
|