From d58bae177f2925b7fb2a34e7f160fecc8a2d945b Mon Sep 17 00:00:00 2001 From: Fabio Barone Date: Wed, 6 Mar 2019 16:43:22 -0500 Subject: [PATCH] p2p/protocols: fix race condition --- p2p/protocols/accounting_simulation_test.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/p2p/protocols/accounting_simulation_test.go b/p2p/protocols/accounting_simulation_test.go index e90a1d81d2..bd9b00f921 100644 --- a/p2p/protocols/accounting_simulation_test.go +++ b/p2p/protocols/accounting_simulation_test.go @@ -159,8 +159,9 @@ func TestAccountingSimulation(t *testing.T) { // (n entries in the array will not be filled - // the balance of a node with itself) type matrix struct { - n int //number of nodes - m []int64 //array of balances + n int //number of nodes + m []int64 //array of balances + lock sync.RWMutex } // create a new matrix @@ -177,7 +178,9 @@ func (m *matrix) add(i, j int, v int64) error { // i * number of nodes + remote node mi := i*m.n + j // register that balance + m.lock.Lock() m.m[mi] += v + m.lock.Unlock() return nil }