mirror of
https://github.com/LBRYFoundation/lbcwallet.git
synced 2025-08-27 07:23:25 +00:00
Smarter locking for recording mined txs.
This commit is contained in:
parent
3ab33bafd7
commit
d0b942d414
1 changed files with 11 additions and 2 deletions
|
@ -130,7 +130,9 @@ func (store *AccountStore) RecordMinedTx(txid *btcwire.ShaHash,
|
||||||
defer store.RUnlock()
|
defer store.RUnlock()
|
||||||
|
|
||||||
for _, account := range store.accounts {
|
for _, account := range store.accounts {
|
||||||
account.TxStore.Lock()
|
// The tx stores will be searched through while holding the
|
||||||
|
// reader lock, and the writer will only be grabbed if necessary.
|
||||||
|
account.TxStore.RLock()
|
||||||
|
|
||||||
// Search in reverse order. Since more recently-created
|
// Search in reverse order. Since more recently-created
|
||||||
// transactions are appended to the end of the store, it's
|
// transactions are appended to the end of the store, it's
|
||||||
|
@ -139,18 +141,25 @@ func (store *AccountStore) RecordMinedTx(txid *btcwire.ShaHash,
|
||||||
sendtx, ok := account.TxStore.s[i].(*tx.SendTx)
|
sendtx, ok := account.TxStore.s[i].(*tx.SendTx)
|
||||||
if ok {
|
if ok {
|
||||||
if bytes.Equal(txid.Bytes(), sendtx.TxID[:]) {
|
if bytes.Equal(txid.Bytes(), sendtx.TxID[:]) {
|
||||||
|
// Unlock the held reader lock and wait for
|
||||||
|
// the writer lock.
|
||||||
|
account.TxStore.RUnlock()
|
||||||
|
account.TxStore.Lock()
|
||||||
|
|
||||||
copy(sendtx.BlockHash[:], blkhash.Bytes())
|
copy(sendtx.BlockHash[:], blkhash.Bytes())
|
||||||
sendtx.BlockHeight = blkheight
|
sendtx.BlockHeight = blkheight
|
||||||
sendtx.BlockIndex = int32(blkindex)
|
sendtx.BlockIndex = int32(blkindex)
|
||||||
sendtx.BlockTime = blktime
|
sendtx.BlockTime = blktime
|
||||||
account.MarkDirtyTxStore()
|
account.MarkDirtyTxStore()
|
||||||
|
|
||||||
|
// Release writer lock and return.
|
||||||
account.TxStore.Unlock()
|
account.TxStore.Unlock()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
account.TxStore.Unlock()
|
account.TxStore.RUnlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
return errors.New("txid does not match any recorded sent transaction")
|
return errors.New("txid does not match any recorded sent transaction")
|
||||||
|
|
Loading…
Add table
Reference in a new issue