mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-23 03:41:34 +00:00
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:
parent
6334192a95
commit
a11e433754
1 changed files with 33 additions and 31 deletions
|
@ -299,44 +299,46 @@ func (mp *Pool) Add(t *transaction.Transaction, fee Feer, data ...any) error {
|
||||||
func (mp *Pool) Remove(hash util.Uint256) {
|
func (mp *Pool) Remove(hash util.Uint256) {
|
||||||
mp.lock.Lock()
|
mp.lock.Lock()
|
||||||
mp.removeInternal(hash)
|
mp.removeInternal(hash)
|
||||||
|
if mp.updateMetricsCb != nil {
|
||||||
|
mp.updateMetricsCb(len(mp.verifiedTxes))
|
||||||
|
}
|
||||||
mp.lock.Unlock()
|
mp.lock.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
// removeInternal is an internal unlocked representation of Remove.
|
// removeInternal is an internal unlocked representation of Remove.
|
||||||
func (mp *Pool) removeInternal(hash util.Uint256) {
|
func (mp *Pool) removeInternal(hash util.Uint256) {
|
||||||
if tx, ok := mp.verifiedMap[hash]; ok {
|
tx, ok := mp.verifiedMap[hash]
|
||||||
var num int
|
if !ok {
|
||||||
delete(mp.verifiedMap, hash)
|
return
|
||||||
for num = range mp.verifiedTxes {
|
}
|
||||||
if hash.Equals(mp.verifiedTxes[num].txn.Hash()) {
|
var num int
|
||||||
break
|
delete(mp.verifiedMap, hash)
|
||||||
}
|
for num = range mp.verifiedTxes {
|
||||||
}
|
if hash.Equals(mp.verifiedTxes[num].txn.Hash()) {
|
||||||
itm := mp.verifiedTxes[num]
|
break
|
||||||
if num < len(mp.verifiedTxes)-1 {
|
|
||||||
mp.verifiedTxes = append(mp.verifiedTxes[:num], mp.verifiedTxes[num+1:]...)
|
|
||||||
} else if num == len(mp.verifiedTxes)-1 {
|
|
||||||
mp.verifiedTxes = mp.verifiedTxes[:num]
|
|
||||||
}
|
|
||||||
payer := itm.txn.Signers[mp.payerIndex].Account
|
|
||||||
senderFee := mp.fees[payer]
|
|
||||||
senderFee.feeSum.SubUint64(&senderFee.feeSum, uint64(tx.SystemFee+tx.NetworkFee))
|
|
||||||
mp.fees[payer] = senderFee
|
|
||||||
// remove all conflicting hashes from mp.conflicts list
|
|
||||||
mp.removeConflictsOf(tx)
|
|
||||||
if attrs := tx.GetAttributes(transaction.OracleResponseT); len(attrs) != 0 {
|
|
||||||
delete(mp.oracleResp, attrs[0].Value.(*transaction.OracleResponse).ID)
|
|
||||||
}
|
|
||||||
if mp.subscriptionsOn.Load() {
|
|
||||||
mp.events <- mempoolevent.Event{
|
|
||||||
Type: mempoolevent.TransactionRemoved,
|
|
||||||
Tx: itm.txn,
|
|
||||||
Data: itm.data,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if mp.updateMetricsCb != nil {
|
itm := mp.verifiedTxes[num]
|
||||||
mp.updateMetricsCb(len(mp.verifiedTxes))
|
if num < len(mp.verifiedTxes)-1 {
|
||||||
|
mp.verifiedTxes = append(mp.verifiedTxes[:num], mp.verifiedTxes[num+1:]...)
|
||||||
|
} else if num == len(mp.verifiedTxes)-1 {
|
||||||
|
mp.verifiedTxes = mp.verifiedTxes[:num]
|
||||||
|
}
|
||||||
|
payer := itm.txn.Signers[mp.payerIndex].Account
|
||||||
|
senderFee := mp.fees[payer]
|
||||||
|
senderFee.feeSum.SubUint64(&senderFee.feeSum, uint64(tx.SystemFee+tx.NetworkFee))
|
||||||
|
mp.fees[payer] = senderFee
|
||||||
|
// remove all conflicting hashes from mp.conflicts list
|
||||||
|
mp.removeConflictsOf(tx)
|
||||||
|
if attrs := tx.GetAttributes(transaction.OracleResponseT); len(attrs) != 0 {
|
||||||
|
delete(mp.oracleResp, attrs[0].Value.(*transaction.OracleResponse).ID)
|
||||||
|
}
|
||||||
|
if mp.subscriptionsOn.Load() {
|
||||||
|
mp.events <- mempoolevent.Event{
|
||||||
|
Type: mempoolevent.TransactionRemoved,
|
||||||
|
Tx: itm.txn,
|
||||||
|
Data: itm.data,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue