From 4dd3fd4ac02b5d0208e53d68eb1967db2ea96560 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Fri, 14 Oct 2022 11:53:04 +0300 Subject: [PATCH] network: only call tx callback if we're waiting for transactions Until the consensus process starts for a new block and until it really needs some transactions we can spare some cycles by not delivering transactions to it. In tests this doesn't affect TPS, but makes block delays a bit more stable. Related to #2744, I think it also may cause timeouts during transaction processing (waiting on the consensus process channel while it does something dBFT-related). --- pkg/network/server.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/network/server.go b/pkg/network/server.go index 8ef0f6eea..a678888b8 100644 --- a/pkg/network/server.go +++ b/pkg/network/server.go @@ -107,6 +107,7 @@ type ( services map[string]Service extensHandlers map[string]func(*payload.Extensible) error txCallback func(*transaction.Transaction) + txCbHeight atomic.Uint32 txInLock sync.Mutex txInMap map[util.Uint256]struct{} @@ -1021,7 +1022,7 @@ func (s *Server) handleTxCmd(tx *transaction.Transaction) error { s.serviceLock.RLock() txCallback := s.txCallback s.serviceLock.RUnlock() - if txCallback != nil { + if txCallback != nil && s.chain.BlockHeight() <= s.txCbHeight.Load() { txCallback(tx) } if s.verifyAndPoolTX(tx) == nil { @@ -1321,6 +1322,8 @@ func (s *Server) RequestTx(hashes ...util.Uint256) { return } + s.txCbHeight.Store(s.chain.BlockHeight()) + for i := 0; i <= len(hashes)/payload.MaxHashesCount; i++ { start := i * payload.MaxHashesCount stop := (i + 1) * payload.MaxHashesCount