services: use buffered channels for block subscription
Add a tiny buffer where possible to avoid Blockchain's blocking on new block addition.
This commit is contained in:
parent
97c7023020
commit
ea46943815
3 changed files with 15 additions and 6 deletions
|
@ -89,7 +89,8 @@ type service struct {
|
||||||
messages chan Payload
|
messages chan Payload
|
||||||
transactions chan *transaction.Transaction
|
transactions chan *transaction.Transaction
|
||||||
// blockEvents is used to pass a new block event to the consensus
|
// blockEvents is used to pass a new block event to the consensus
|
||||||
// process.
|
// process. It has a tiny buffer in order to avoid Blockchain blocking
|
||||||
|
// on block addition under the high load.
|
||||||
blockEvents chan *coreb.Block
|
blockEvents chan *coreb.Block
|
||||||
lastProposal []util.Uint256
|
lastProposal []util.Uint256
|
||||||
wallet *wallet.Wallet
|
wallet *wallet.Wallet
|
||||||
|
|
|
@ -64,7 +64,12 @@ type (
|
||||||
|
|
||||||
mp *mempool.Pool
|
mp *mempool.Pool
|
||||||
// requests channel
|
// requests channel
|
||||||
reqCh chan mempoolevent.Event
|
reqCh chan mempoolevent.Event
|
||||||
|
// blocksCh is a channel used to receive block notifications from the
|
||||||
|
// Blockchain. It is not buffered intentionally, as it's important to keep
|
||||||
|
// the notary request pool in sync with the current blockchain heigh, thus,
|
||||||
|
// it's not recommended to use a large size of notary requests pool as it may
|
||||||
|
// slow down the block processing.
|
||||||
blocksCh chan *block.Block
|
blocksCh chan *block.Block
|
||||||
stopCh chan struct{}
|
stopCh chan struct{}
|
||||||
done chan struct{}
|
done chan struct{}
|
||||||
|
|
|
@ -63,9 +63,12 @@ type (
|
||||||
timePerBlock time.Duration
|
timePerBlock time.Duration
|
||||||
maxRetries int
|
maxRetries int
|
||||||
relayExtensible RelayCallback
|
relayExtensible RelayCallback
|
||||||
blockCh chan *block.Block
|
// blockCh is a channel used to receive block notifications from the
|
||||||
stopCh chan struct{}
|
// Blockchain. It has a tiny buffer in order to avoid Blockchain blocking
|
||||||
done chan struct{}
|
// on block addition under the high load.
|
||||||
|
blockCh chan *block.Block
|
||||||
|
stopCh chan struct{}
|
||||||
|
done chan struct{}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -84,7 +87,7 @@ func New(cfg config.StateRoot, sm *stateroot.Module, log *zap.Logger, bc Ledger,
|
||||||
chain: bc,
|
chain: bc,
|
||||||
log: log,
|
log: log,
|
||||||
incompleteRoots: make(map[uint32]*incompleteRoot),
|
incompleteRoots: make(map[uint32]*incompleteRoot),
|
||||||
blockCh: make(chan *block.Block),
|
blockCh: make(chan *block.Block, 1),
|
||||||
stopCh: make(chan struct{}),
|
stopCh: make(chan struct{}),
|
||||||
done: make(chan struct{}),
|
done: make(chan struct{}),
|
||||||
timePerBlock: bcConf.TimePerBlock,
|
timePerBlock: bcConf.TimePerBlock,
|
||||||
|
|
Loading…
Reference in a new issue