From c6a648fad74179ddd8bae8cd8da705b4c51e6ea5 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Wed, 16 Nov 2016 16:47:31 -0500 Subject: [PATCH] consensus: lock before loading commit --- consensus/reactor.go | 7 +------ consensus/state.go | 9 +++++++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/consensus/reactor.go b/consensus/reactor.go index 0ece82ce1..60d5a8f5d 100644 --- a/consensus/reactor.go +++ b/consensus/reactor.go @@ -658,12 +658,7 @@ OUTER_LOOP: { prs := ps.GetRoundState() if prs.CatchupCommitRound != -1 && 0 < prs.Height && prs.Height <= conR.conS.blockStore.Height() { - var commit *types.Commit - if prs.Height == conR.conS.blockStore.Height() { - commit = conR.conS.blockStore.LoadSeenCommit(prs.Height) - } else { - commit = conR.conS.blockStore.LoadBlockCommit(prs.Height) - } + commit := conR.conS.LoadCommit(prs.Height) peer.TrySend(StateChannel, struct{ ConsensusMessage }{&VoteSetMaj23Message{ Height: prs.Height, Round: commit.Round(), diff --git a/consensus/state.go b/consensus/state.go index 59bea2315..85d4d1679 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -319,6 +319,15 @@ func (cs *ConsensusState) SetPrivValidator(priv PrivValidator) { cs.privValidator = priv } +func (cs *ConsensusState) LoadCommit(height int) *types.Commit { + cs.mtx.Lock() + defer cs.mtx.Unlock() + if height == cs.blockStore.Height() { + return cs.blockStore.LoadSeenCommit(height) + } + return cs.blockStore.LoadBlockCommit(height) +} + func (cs *ConsensusState) OnStart() error { cs.BaseService.OnStart()