From 645afad9c6b1cdc2162512a93098d9a1d4c85405 Mon Sep 17 00:00:00 2001 From: Cassandra Heart Date: Sat, 2 Dec 2023 02:37:39 -0600 Subject: [PATCH] fix: mutex locking around entire dependencyMap logic --- node/consensus/ceremony/broadcast_messaging.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/node/consensus/ceremony/broadcast_messaging.go b/node/consensus/ceremony/broadcast_messaging.go index 0c6e9eb..b79c4a0 100644 --- a/node/consensus/ceremony/broadcast_messaging.go +++ b/node/consensus/ceremony/broadcast_messaging.go @@ -439,8 +439,9 @@ func (e *CeremonyDataClockConsensusEngine) handleProvingKey( zap.Binary("proving_key", provingKey), ) - if e.dependencyMap[string(provingKey)] != nil { - go func() { + go func() { + e.dependencyMapMx.Lock() + if e.dependencyMap[string(provingKey)] != nil { keyBundleAnnouncement := &protobufs.KeyBundleAnnouncement{} if err := proto.Unmarshal( e.dependencyMap[string(provingKey)].Value, @@ -450,6 +451,7 @@ func (e *CeremonyDataClockConsensusEngine) handleProvingKey( "could not unmarshal key bundle announcement", zap.Error(err), ) + e.dependencyMapMx.Unlock() return } if err := keyBundleAnnouncement.Verify( @@ -459,16 +461,16 @@ func (e *CeremonyDataClockConsensusEngine) handleProvingKey( "could not verify key bundle announcement", zap.Error(err), ) + e.dependencyMapMx.Unlock() return } e.pendingCommits <- e.dependencyMap[string(provingKey)] - e.dependencyMapMx.Lock() delete(e.dependencyMap, string(provingKey)) - e.dependencyMapMx.Unlock() - }() - } + } + e.dependencyMapMx.Unlock() + }() return nil }