waddrmgr: fix concurrent map access

Fixes lightningnetwork/lnd#5864.
The loadAccountInfo does load an account as its name suggests. But after
loading it, the account is also added to a map to cache it. That map
write should be seen as a writing operation and therefore the _write_
lock must be held, not just the read lock.
This commit is contained in:
Oliver Gugger 2021-10-20 18:06:05 +02:00 committed by Roy Lee
parent 45a94de617
commit b4e83b1f8c

View file

@ -518,8 +518,8 @@ func (s *ScopedKeyManager) loadAccountInfo(ns walletdb.ReadBucket,
func (s *ScopedKeyManager) AccountProperties(ns walletdb.ReadBucket, func (s *ScopedKeyManager) AccountProperties(ns walletdb.ReadBucket,
account uint32) (*AccountProperties, error) { account uint32) (*AccountProperties, error) {
defer s.mtx.RUnlock() s.mtx.Lock()
s.mtx.RLock() defer s.mtx.Unlock()
props := &AccountProperties{ props := &AccountProperties{
AccountNumber: account, AccountNumber: account,