mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-23 03:41:34 +00:00
services: move blockchain/mempool subscriptions to separate routine
Start of some services is bound to blockchain subscriptions, and thus, can't be run before the blockchain notifications dispatcher. Signed-off-by: Ekaterina Pavlova <ekt@morphbits.io>
This commit is contained in:
parent
f8dc5ec44f
commit
4715e523e0
3 changed files with 11 additions and 4 deletions
|
@ -281,7 +281,6 @@ func (s *service) Start() {
|
|||
b, _ := s.Chain.GetBlock(s.Chain.CurrentBlockHash()) // Can't fail, we have some current block!
|
||||
s.lastTimestamp = b.Timestamp
|
||||
s.dbft.Start(s.lastTimestamp * nsInMs)
|
||||
s.Chain.SubscribeForBlocks(s.blockEvents)
|
||||
go s.eventLoop()
|
||||
}
|
||||
}
|
||||
|
@ -299,6 +298,14 @@ func (s *service) Shutdown() {
|
|||
}
|
||||
|
||||
func (s *service) eventLoop() {
|
||||
s.Chain.SubscribeForBlocks(s.blockEvents)
|
||||
|
||||
// Manually sync up with potentially missed fresh blocks that may be added by blockchain
|
||||
// before the subscription.
|
||||
b, _ := s.Chain.GetBlock(s.Chain.CurrentBlockHash()) // Can't fail, we have some current block!
|
||||
if b.Timestamp >= s.lastTimestamp {
|
||||
s.handleChainBlock(b)
|
||||
}
|
||||
events:
|
||||
for {
|
||||
select {
|
||||
|
|
|
@ -175,13 +175,13 @@ func (n *Notary) Start() {
|
|||
return
|
||||
}
|
||||
n.Config.Log.Info("starting notary service")
|
||||
n.Config.Chain.SubscribeForBlocks(n.blocksCh)
|
||||
n.mp.SubscribeForTransactions(n.reqCh)
|
||||
go n.newTxCallbackLoop()
|
||||
go n.mainLoop()
|
||||
}
|
||||
|
||||
func (n *Notary) mainLoop() {
|
||||
n.Config.Chain.SubscribeForBlocks(n.blocksCh)
|
||||
n.mp.SubscribeForTransactions(n.reqCh)
|
||||
mainloop:
|
||||
for {
|
||||
select {
|
||||
|
|
|
@ -29,11 +29,11 @@ func (s *service) Start() {
|
|||
return
|
||||
}
|
||||
s.log.Info("starting state validation service")
|
||||
s.chain.SubscribeForBlocks(s.blockCh)
|
||||
go s.run()
|
||||
}
|
||||
|
||||
func (s *service) run() {
|
||||
s.chain.SubscribeForBlocks(s.blockCh)
|
||||
runloop:
|
||||
for {
|
||||
select {
|
||||
|
|
Loading…
Reference in a new issue