Merge pull request #2746 from nspcc-dev/optimize-tx-callbacks

network: only call tx callback if we're waiting for transactions
This commit is contained in:
Roman Khimov 2022-10-17 16:39:41 +07:00 committed by GitHub
commit 73079745ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -108,6 +108,7 @@ type (
services map[string]Service services map[string]Service
extensHandlers map[string]func(*payload.Extensible) error extensHandlers map[string]func(*payload.Extensible) error
txCallback func(*transaction.Transaction) txCallback func(*transaction.Transaction)
txCbHeight atomic.Uint32
txInLock sync.Mutex txInLock sync.Mutex
txInMap map[util.Uint256]struct{} txInMap map[util.Uint256]struct{}
@ -1044,7 +1045,7 @@ func (s *Server) handleTxCmd(tx *transaction.Transaction) error {
s.serviceLock.RLock() s.serviceLock.RLock()
txCallback := s.txCallback txCallback := s.txCallback
s.serviceLock.RUnlock() s.serviceLock.RUnlock()
if txCallback != nil { if txCallback != nil && s.chain.BlockHeight() <= s.txCbHeight.Load() {
txCallback(tx) txCallback(tx)
} }
if s.verifyAndPoolTX(tx) == nil { if s.verifyAndPoolTX(tx) == nil {
@ -1344,6 +1345,8 @@ func (s *Server) RequestTx(hashes ...util.Uint256) {
return return
} }
s.txCbHeight.Store(s.chain.BlockHeight())
for i := 0; i <= len(hashes)/payload.MaxHashesCount; i++ { for i := 0; i <= len(hashes)/payload.MaxHashesCount; i++ {
start := i * payload.MaxHashesCount start := i * payload.MaxHashesCount
stop := (i + 1) * payload.MaxHashesCount stop := (i + 1) * payload.MaxHashesCount