mempool: swap checks in Add, fail fast

Checking for duplicates is easier than checking the balance, so it should be
done first.
This commit is contained in:
Roman Khimov 2020-08-19 18:36:57 +03:00
parent e998c102ca
commit 0d8cc437fe

View file

@ -136,14 +136,14 @@ func (mp *Pool) Add(t *transaction.Transaction, fee Feer) error {
timeStamp: time.Now().UTC(), timeStamp: time.Now().UTC(),
} }
mp.lock.Lock() mp.lock.Lock()
if !mp.checkTxConflicts(t, fee) {
mp.lock.Unlock()
return ErrConflict
}
if mp.containsKey(t.Hash()) { if mp.containsKey(t.Hash()) {
mp.lock.Unlock() mp.lock.Unlock()
return ErrDup return ErrDup
} }
if !mp.checkTxConflicts(t, fee) {
mp.lock.Unlock()
return ErrConflict
}
mp.verifiedMap[t.Hash()] = pItem mp.verifiedMap[t.Hash()] = pItem
// Insert into sorted array (from max to min, that could also be done // Insert into sorted array (from max to min, that could also be done