consensus: drain block notification channel after each message

Make blockchain lock less possible.
This commit is contained in:
Anna Shaleva 2023-03-06 18:27:09 +03:00
parent ea46943815
commit e57e74692f

View file

@ -337,11 +337,16 @@ events:
case b := <-s.blockEvents: case b := <-s.blockEvents:
s.handleChainBlock(b) s.handleChainBlock(b)
} }
// Always process block event if there is any, we can add one above. // Always process block event if there is any, we can add one above or external
select { // services can add several blocks during message processing.
case b := <-s.blockEvents: syncLoop:
s.handleChainBlock(b) for {
default: select {
case b := <-s.blockEvents:
s.handleChainBlock(b)
default:
break syncLoop
}
} }
} }
drainLoop: drainLoop: