mempool: move metrics out of removeInternal, simplify it

Metrics should be updated once per action, currently removeInternal is
used by Add and Remove, the first one updates them in the end anyway and
remove should do the same.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
This commit is contained in:
Roman Khimov 2024-07-30 17:42:10 +03:00
parent 6334192a95
commit a11e433754

View file

@ -299,12 +299,18 @@ func (mp *Pool) Add(t *transaction.Transaction, fee Feer, data ...any) error {
func (mp *Pool) Remove(hash util.Uint256) {
mp.lock.Lock()
mp.removeInternal(hash)
if mp.updateMetricsCb != nil {
mp.updateMetricsCb(len(mp.verifiedTxes))
}
mp.lock.Unlock()
}
// removeInternal is an internal unlocked representation of Remove.
func (mp *Pool) removeInternal(hash util.Uint256) {
if tx, ok := mp.verifiedMap[hash]; ok {
tx, ok := mp.verifiedMap[hash]
if !ok {
return
}
var num int
delete(mp.verifiedMap, hash)
for num = range mp.verifiedTxes {
@ -334,10 +340,6 @@ func (mp *Pool) removeInternal(hash util.Uint256) {
Data: itm.data,
}
}
}
if mp.updateMetricsCb != nil {
mp.updateMetricsCb(len(mp.verifiedTxes))
}
}
// RemoveStale filters verified transactions through the given function keeping