diff options
author | Wei-Ning Huang <w@byzantine-lab.io> | 2019-06-23 17:02:35 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@byzantine-lab.io> | 2019-09-17 16:57:30 +0800 |
commit | fc8421afacee4c6e332bbb91606d58b9a11413cc (patch) | |
tree | 08c4dabe0d9ad16af293ae7a137e5af88eff840e | |
parent | e6f5201b178f40b516ffe7b98757df25f8aee028 (diff) | |
download | go-tangerine-fc8421afacee4c6e332bbb91606d58b9a11413cc.tar.gz go-tangerine-fc8421afacee4c6e332bbb91606d58b9a11413cc.tar.zst go-tangerine-fc8421afacee4c6e332bbb91606d58b9a11413cc.zip |
dex: gracefully shutdown when consensus core stops
-rw-r--r-- | dex/backend.go | 2 | ||||
-rw-r--r-- | dex/blockproposer.go | 24 | ||||
-rw-r--r-- | dex/handler.go | 6 |
3 files changed, 18 insertions, 14 deletions
diff --git a/dex/backend.go b/dex/backend.go index c76b9af85..24115b116 100644 --- a/dex/backend.go +++ b/dex/backend.go @@ -265,7 +265,7 @@ func (s *Tangerine) Start(srvr *p2p.Server) error { <-ch } - s.bp.Start() + s.bp.Start(s) }() } return nil diff --git a/dex/blockproposer.go b/dex/blockproposer.go index 64873ed21..0ba45b30a 100644 --- a/dex/blockproposer.go +++ b/dex/blockproposer.go @@ -3,6 +3,7 @@ package dex import ( "errors" "fmt" + "os" "sync" "sync/atomic" "time" @@ -15,6 +16,7 @@ import ( "github.com/tangerine-network/go-tangerine/core" "github.com/tangerine-network/go-tangerine/dex/db" "github.com/tangerine-network/go-tangerine/log" + "github.com/tangerine-network/go-tangerine/node" "github.com/tangerine-network/go-tangerine/rlp" ) @@ -43,7 +45,7 @@ func NewBlockProposer(dex *Tangerine, watchCat *syncer.WatchCat, dMoment time.Ti } } -func (b *blockProposer) Start() error { +func (b *blockProposer) Start(svc node.Service) error { b.mu.Lock() defer b.mu.Unlock() @@ -74,20 +76,22 @@ func (b *blockProposer) Start() error { return } - b.run(c) + log.Info("Start running consensus core") + go c.Run(b.stopCh) + atomic.StoreInt32(&b.proposing, 1) + + <-b.stopCh + log.Debug("Block proposer receive stop signal") + log.Info("Block proposer successfully stopped") + go func() { + svc.Stop() + os.Exit(1) + }() }() return nil } -func (b *blockProposer) run(c *dexCore.Consensus) { - log.Info("Start running consensus core") - go c.Run() - atomic.StoreInt32(&b.proposing, 1) - <-b.stopCh - log.Debug("Block proposer receive stop signal") -} - func (b *blockProposer) Stop() { log.Info("Stopping block proposer") b.mu.Lock() diff --git a/dex/handler.go b/dex/handler.go index 6ef3c3359..9ad35ed30 100644 --- a/dex/handler.go +++ b/dex/handler.go @@ -312,7 +312,7 @@ func (pm *ProtocolManager) Start(srvr p2pServer, maxPeers int) { } func (pm *ProtocolManager) Stop() { - log.Info("Stopping DEXON protocol") + log.Info("Stopping protocol manager") pm.txsSub.Unsubscribe() // quits txBroadcastLoop pm.chainHeadSub.Unsubscribe() @@ -337,7 +337,7 @@ func (pm *ProtocolManager) Stop() { // Wait for all peer handler goroutines and the loops to come down. pm.wg.Wait() - log.Info("DEXON protocol stopped") + log.Info("Protocol manager stopped") } func (pm *ProtocolManager) ReceiveChan() <-chan coreTypes.Msg { @@ -1372,7 +1372,7 @@ func (pm *ProtocolManager) peerSetLoop() { // NodeInfo represents a short summary of the Ethereum sub-protocol metadata // known about the host peer. type NodeInfo struct { - Network uint64 `json:"network"` // DEXON network ID (373=Mainnet, 374=Taiwan) + Network uint64 `json:"network"` // Network ID (373=Mainnet, 374=Testnet) Number uint64 `json:"number"` // Total difficulty of the host's blockchain Genesis common.Hash `json:"genesis"` // SHA3 hash of the host's genesis block Config *params.ChainConfig `json:"config"` // Chain configuration for the fork rules |