From 8256f7099af6c73b0fbf54df7c3bf9b6ca2d373e Mon Sep 17 00:00:00 2001 From: tycho garen Date: Fri, 11 Mar 2022 11:56:23 -0500 Subject: [PATCH] more locking gpt --- internal/consensus/state.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/internal/consensus/state.go b/internal/consensus/state.go index b42190eeb..77ba1780e 100644 --- a/internal/consensus/state.go +++ b/internal/consensus/state.go @@ -1427,7 +1427,11 @@ func (cs *State) createProposalBlock(ctx context.Context) (*types.Block, error) return nil, nil } - proposerAddr := cs.privValidatorPubKey.Address() + proposerAddr := func() []byte { + cs.mtx.RLock() + defer cs.mtx.RUnlock() + return cs.privValidatorPubKey.Address() + }() return cs.blockExec.CreateProposalBlock(ctx, cs.Height, cs.state, commit, proposerAddr, cs.LastCommit.GetVotes()) } @@ -2668,7 +2672,12 @@ func (cs *State) updatePrivValidatorPubKey(rctx context.Context) error { if err != nil { return err } - cs.privValidatorPubKey = pubKey + func() { + cs.mtx.Lock() + defer cs.mtx.Unlock() + + cs.privValidatorPubKey = pubKey + }() return nil }