From bb9c6ccaa1624d55b85622dd4f6591aa199558e5 Mon Sep 17 00:00:00 2001 From: Rongjian Lan Date: Sat, 8 Sep 2018 12:36:19 -0700 Subject: [PATCH] Add locking on shard utxo map --- client/client.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/client/client.go b/client/client.go index 0a0d22b79..1a306cf15 100644 --- a/client/client.go +++ b/client/client.go @@ -19,8 +19,9 @@ type Client struct { Leaders *[]p2p.Peer // All the leaders for each shard UpdateBlocks func([]*blockchain.Block) // Closure function used to sync new block with the leader. Once the leader finishes the consensus on a new block, it will send it to the clients. Clients use this method to update their blockchain - ShardUtxoMap map[uint32]blockchain.UtxoMap - log log.Logger // Log utility + ShardUtxoMap map[uint32]blockchain.UtxoMap + ShardUtxoMapMutex sync.Mutex // Mutex for the UTXO maps + log log.Logger // Log utility } // The message handler for CLIENT/TRANSACTION messages. @@ -104,6 +105,8 @@ func (client *Client) handleProofOfLockMessage(proofs *[]blockchain.CrossShardTx } func (client *Client) handleFetchUtxoResponseMessage(utxoResponse client_proto.FetchUtxoResponseMessage) { + client.ShardUtxoMapMutex.Lock() + defer client.ShardUtxoMapMutex.Unlock() _, ok := client.ShardUtxoMap[utxoResponse.ShardId] if ok { return