Merge pull request #535 from nspcc-dev/mempool-locking-fixes
Mempool locking fixes
This commit is contained in:
commit
8e9cabe1eb
1 changed files with 7 additions and 7 deletions
|
@ -104,13 +104,13 @@ func (mp MemPool) ContainsKey(hash util.Uint256) bool {
|
||||||
func (mp MemPool) TryAdd(hash util.Uint256, pItem *PoolItem) bool {
|
func (mp MemPool) TryAdd(hash util.Uint256, pItem *PoolItem) bool {
|
||||||
var pool PoolItems
|
var pool PoolItems
|
||||||
|
|
||||||
mp.lock.RLock()
|
mp.lock.Lock()
|
||||||
if _, ok := mp.unsortedTxn[hash]; ok {
|
if _, ok := mp.unsortedTxn[hash]; ok {
|
||||||
mp.lock.RUnlock()
|
mp.lock.Unlock()
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
mp.unsortedTxn[hash] = pItem
|
mp.unsortedTxn[hash] = pItem
|
||||||
mp.lock.RUnlock()
|
mp.lock.Unlock()
|
||||||
|
|
||||||
if pItem.fee.IsLowPriority(pItem.txn) {
|
if pItem.fee.IsLowPriority(pItem.txn) {
|
||||||
pool = mp.sortedLowPrioTxn
|
pool = mp.sortedLowPrioTxn
|
||||||
|
@ -226,8 +226,8 @@ func NewMemPool(capacity int) MemPool {
|
||||||
|
|
||||||
// TryGetValue returns a transaction if it exists in the memory pool.
|
// TryGetValue returns a transaction if it exists in the memory pool.
|
||||||
func (mp MemPool) TryGetValue(hash util.Uint256) (*transaction.Transaction, bool) {
|
func (mp MemPool) TryGetValue(hash util.Uint256) (*transaction.Transaction, bool) {
|
||||||
mp.lock.Lock()
|
mp.lock.RLock()
|
||||||
defer mp.lock.Unlock()
|
defer mp.lock.RUnlock()
|
||||||
if pItem, ok := mp.unsortedTxn[hash]; ok {
|
if pItem, ok := mp.unsortedTxn[hash]; ok {
|
||||||
return pItem.txn, ok
|
return pItem.txn, ok
|
||||||
}
|
}
|
||||||
|
@ -271,8 +271,8 @@ func min(sortedPool PoolItems) *PoolItem {
|
||||||
func (mp *MemPool) GetVerifiedTransactions() []*transaction.Transaction {
|
func (mp *MemPool) GetVerifiedTransactions() []*transaction.Transaction {
|
||||||
var t []*transaction.Transaction
|
var t []*transaction.Transaction
|
||||||
|
|
||||||
mp.lock.Lock()
|
mp.lock.RLock()
|
||||||
defer mp.lock.Unlock()
|
defer mp.lock.RUnlock()
|
||||||
for _, p := range mp.unsortedTxn {
|
for _, p := range mp.unsortedTxn {
|
||||||
t = append(t, p.txn)
|
t = append(t, p.txn)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue