mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-23 13:38:35 +00:00
mempool: reverse the order of sorted slice
Chopping off the last element of the slice if way easier than doing it with the first one.
This commit is contained in:
parent
794027a90b
commit
35183b6dba
1 changed files with 4 additions and 5 deletions
|
@ -144,7 +144,7 @@ func (mp *Pool) Add(t *transaction.Transaction, fee Feer) error {
|
||||||
|
|
||||||
mp.verifiedMap[t.Hash()] = pItem
|
mp.verifiedMap[t.Hash()] = pItem
|
||||||
mp.verifiedTxes = append(mp.verifiedTxes, pItem)
|
mp.verifiedTxes = append(mp.verifiedTxes, pItem)
|
||||||
sort.Sort(mp.verifiedTxes)
|
sort.Sort(sort.Reverse(mp.verifiedTxes))
|
||||||
mp.lock.Unlock()
|
mp.lock.Unlock()
|
||||||
|
|
||||||
if mp.Count() > mp.capacity {
|
if mp.Count() > mp.capacity {
|
||||||
|
@ -201,13 +201,12 @@ func (mp *Pool) RemoveOverCapacity() {
|
||||||
// minItem belongs to the mp.sortedLowPrioTxn slice.
|
// minItem belongs to the mp.sortedLowPrioTxn slice.
|
||||||
// The corresponding unsorted pool is is mp.unsortedTxn.
|
// The corresponding unsorted pool is is mp.unsortedTxn.
|
||||||
delete(mp.verifiedMap, minItem.txn.Hash())
|
delete(mp.verifiedMap, minItem.txn.Hash())
|
||||||
mp.verifiedTxes = append(mp.verifiedTxes[:0], mp.verifiedTxes[1:]...)
|
mp.verifiedTxes = mp.verifiedTxes[:len(mp.verifiedTxes)-1]
|
||||||
} else {
|
} else {
|
||||||
// minItem belongs to the mp.unverifiedSortedLowPrioTxn slice.
|
// minItem belongs to the mp.unverifiedSortedLowPrioTxn slice.
|
||||||
// The corresponding unsorted pool is is mp.unverifiedTxn.
|
// The corresponding unsorted pool is is mp.unverifiedTxn.
|
||||||
delete(mp.unverifiedMap, minItem.txn.Hash())
|
delete(mp.unverifiedMap, minItem.txn.Hash())
|
||||||
mp.unverifiedTxes = append(mp.unverifiedTxes[:0], mp.unverifiedTxes[1:]...)
|
mp.unverifiedTxes = mp.unverifiedTxes[:len(mp.unverifiedTxes)-1]
|
||||||
|
|
||||||
}
|
}
|
||||||
updateMempoolMetrics(len(mp.verifiedTxes), len(mp.unverifiedTxes))
|
updateMempoolMetrics(len(mp.verifiedTxes), len(mp.unverifiedTxes))
|
||||||
mp.lock.Unlock()
|
mp.lock.Unlock()
|
||||||
|
@ -265,7 +264,7 @@ func min(sortedPool items) *item {
|
||||||
if len(sortedPool) == 0 {
|
if len(sortedPool) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return sortedPool[0]
|
return sortedPool[len(sortedPool)-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetVerifiedTransactions returns a slice of Input from all the transactions in the memory pool
|
// GetVerifiedTransactions returns a slice of Input from all the transactions in the memory pool
|
||||||
|
|
Loading…
Reference in a new issue