From ecb3a50b47dbdf7b036d5e794d3db77d9247d8aa Mon Sep 17 00:00:00 2001 From: tycho garen Date: Wed, 9 Mar 2022 08:15:47 -0500 Subject: [PATCH] avoid deadlock --- internal/consensus/common_test.go | 1 - internal/consensus/state.go | 9 +++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/consensus/common_test.go b/internal/consensus/common_test.go index dc2f8fa23..95b719cda 100644 --- a/internal/consensus/common_test.go +++ b/internal/consensus/common_test.go @@ -224,7 +224,6 @@ func sortVValidatorStubsByPower(ctx context.Context, t *testing.T, vss []*valida func startTestRound(ctx context.Context, cs *State, height int64, round int32) { cs.enterNewRound(ctx, height, round) - cs.startRoutines(ctx, 0) } // Create proposal block from cs1 but sign it with vs. diff --git a/internal/consensus/state.go b/internal/consensus/state.go index 05bde7d7f..abdb2bffb 100644 --- a/internal/consensus/state.go +++ b/internal/consensus/state.go @@ -931,9 +931,6 @@ func (cs *State) receiveRoutine(ctx context.Context, maxSteps int) { // state transitions on complete-proposal, 2/3-any, 2/3-one func (cs *State) handleMsg(ctx context.Context, mi msgInfo) { - cs.mtx.Lock() - defer cs.mtx.Unlock() - var ( added bool err error @@ -2079,7 +2076,11 @@ func (cs *State) defaultSetProposal(proposal *types.Proposal, recvTime time.Time // TODO: We can check if Proposal is for a different block as this is a sign of misbehavior! if cs.ProposalBlockParts == nil { cs.metrics.MarkBlockGossipStarted() - cs.ProposalBlockParts = types.NewPartSetFromHeader(proposal.BlockID.PartSetHeader) + func() { + cs.mtx.Lock() + defer cs.mtx.Unlock() + cs.ProposalBlockParts = types.NewPartSetFromHeader(proposal.BlockID.PartSetHeader) + }() } cs.logger.Info("received proposal", "proposal", proposal)