mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-26 19:42:23 +00:00
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:
parent
0cd3493fa5
commit
1c89c192ac
1 changed files with 4 additions and 4 deletions
|
@ -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