From 849abde253fbebcef7f3b77aa7defe3b3b2197fc Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Sat, 11 Nov 2017 15:05:52 -0800 Subject: [PATCH] htlcswitch: fix mockInvoiceRegistry implementation of SettleInvoice In this commit we fix the implementation of SettleInvoice by ensuring the lock is held for the duration of the method. --- htlcswitch/mock.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/htlcswitch/mock.go b/htlcswitch/mock.go index 3eb868213..a8508f7bf 100644 --- a/htlcswitch/mock.go +++ b/htlcswitch/mock.go @@ -419,15 +419,15 @@ func (i *mockInvoiceRegistry) LookupInvoice(rHash chainhash.Hash) (*channeldb.In } func (i *mockInvoiceRegistry) SettleInvoice(rhash chainhash.Hash) error { + i.Lock() + defer i.Unlock() - invoice, err := i.LookupInvoice(rhash) - if err != nil { - return err + invoice, ok := i.invoices[rhash] + if !ok { + return errors.New("can't find mock invoice") } - i.Lock() invoice.Terms.Settled = true - i.Unlock() return nil }