core: optimize some accesses to unsortedTxn in mempool

These don't need a full lock, they only read things from maps.
This commit is contained in:
Roman Khimov 2019-12-02 22:39:43 +03:00
parent 0cd3493fa5
commit 1c89c192ac

View file

@ -226,8 +226,8 @@ func NewMemPool(capacity int) MemPool {
// TryGetValue returns a transaction if it exists in the memory pool.
func (mp MemPool) TryGetValue(hash util.Uint256) (*transaction.Transaction, bool) {
mp.lock.Lock()
defer mp.lock.Unlock()
mp.lock.RLock()
defer mp.lock.RUnlock()
if pItem, ok := mp.unsortedTxn[hash]; ok {
return pItem.txn, ok
}
@ -271,8 +271,8 @@ func min(sortedPool PoolItems) *PoolItem {
func (mp *MemPool) GetVerifiedTransactions() []*transaction.Transaction {
var t []*transaction.Transaction
mp.lock.Lock()
defer mp.lock.Unlock()
mp.lock.RLock()
defer mp.lock.RUnlock()
for _, p := range mp.unsortedTxn {
t = append(t, p.txn)
}