From 60d9ae02c7f4f8be09947ced25b964a46a74d7c8 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Sat, 2 Jun 2018 10:02:20 +0200 Subject: [PATCH] mock: protect mockSpendNotifier map by mutex --- mock.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mock.go b/mock.go index 35154ab9..5caf5136 100644 --- a/mock.go +++ b/mock.go @@ -118,6 +118,7 @@ func (m *mockNotfier) RegisterSpendNtfn(outpoint *wire.OutPoint, type mockSpendNotifier struct { *mockNotfier spendMap map[wire.OutPoint][]chan *chainntnfs.SpendDetail + mtx sync.Mutex } func makeMockSpendNotifier() *mockSpendNotifier { @@ -131,6 +132,8 @@ func makeMockSpendNotifier() *mockSpendNotifier { func (m *mockSpendNotifier) RegisterSpendNtfn(outpoint *wire.OutPoint, heightHint uint32, _ bool) (*chainntnfs.SpendEvent, error) { + m.mtx.Lock() + defer m.mtx.Unlock() spendChan := make(chan *chainntnfs.SpendDetail) m.spendMap[*outpoint] = append(m.spendMap[*outpoint], spendChan) @@ -145,6 +148,8 @@ func (m *mockSpendNotifier) RegisterSpendNtfn(outpoint *wire.OutPoint, // will include the transaction and height provided by the caller. func (m *mockSpendNotifier) Spend(outpoint *wire.OutPoint, height int32, txn *wire.MsgTx) { + m.mtx.Lock() + defer m.mtx.Unlock() if spendChans, ok := m.spendMap[*outpoint]; ok { delete(m.spendMap, *outpoint)