Skip to content

Commit

Permalink
network: only call tx callback if we're waiting for transactions
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
roman-khimov committed Oct 14, 2022
1 parent c3001bc commit 4dd3fd4
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/network/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4dd3fd4

Please sign in to comment.