diff options
author | haoping-ku <haoping.ku@cobinhood.com> | 2019-01-18 14:43:41 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-03-12 12:19:09 +0800 |
commit | 5f6c2b5668b6b6f831441cfceb57af801a9e1a36 (patch) | |
tree | e7cea171c1a860c75d5dec239521d54b7622c628 | |
parent | 0826bd64ff765250ff5a4b2448eadc98d3285c03 (diff) | |
download | dexon-5f6c2b5668b6b6f831441cfceb57af801a9e1a36.tar.gz dexon-5f6c2b5668b6b6f831441cfceb57af801a9e1a36.tar.zst dexon-5f6c2b5668b6b6f831441cfceb57af801a9e1a36.zip |
dex: add block number gauge (#140)
-rw-r--r-- | dex/handler.go | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/dex/handler.go b/dex/handler.go index a3fbf2ba9..a745bbfc7 100644 --- a/dex/handler.go +++ b/dex/handler.go @@ -59,6 +59,7 @@ import ( "github.com/dexon-foundation/dexon/ethdb" "github.com/dexon-foundation/dexon/event" "github.com/dexon-foundation/dexon/log" + "github.com/dexon-foundation/dexon/metrics" "github.com/dexon-foundation/dexon/p2p" "github.com/dexon-foundation/dexon/p2p/enode" "github.com/dexon-foundation/dexon/p2p/enr" @@ -142,6 +143,9 @@ type ProtocolManager struct { finalizedBlockCh chan core.NewFinalizedBlockEvent finalizedBlockSub event.Subscription + + // metrics + blockNumberGauge metrics.Gauge } // NewProtocolManager returns a new Ethereum sub protocol manager. The Ethereum sub protocol manages peers capable @@ -154,23 +158,24 @@ func NewProtocolManager( tab := newNodeTable() // Create the protocol manager with the base fields manager := &ProtocolManager{ - networkID: networkID, - dMoment: dMoment, - eventMux: mux, - txpool: txpool, - nodeTable: tab, - gov: gov, - blockchain: blockchain, - cache: newCache(5120, dexDB.NewDatabase(chaindb)), - chainconfig: config, - newPeerCh: make(chan *peer), - noMorePeers: make(chan struct{}), - txsyncCh: make(chan *txsync), - recordsyncCh: make(chan *recordsync), - quitSync: make(chan struct{}), - receiveCh: make(chan interface{}, 1024), - isBlockProposer: isBlockProposer, - app: app, + networkID: networkID, + dMoment: dMoment, + eventMux: mux, + txpool: txpool, + nodeTable: tab, + gov: gov, + blockchain: blockchain, + cache: newCache(5120, dexDB.NewDatabase(chaindb)), + chainconfig: config, + newPeerCh: make(chan *peer), + noMorePeers: make(chan struct{}), + txsyncCh: make(chan *txsync), + recordsyncCh: make(chan *recordsync), + quitSync: make(chan struct{}), + receiveCh: make(chan interface{}, 1024), + isBlockProposer: isBlockProposer, + app: app, + blockNumberGauge: metrics.GetOrRegisterGauge("dex/blocknumber", nil), } // Figure out whether to allow fast sync or not @@ -1182,7 +1187,9 @@ func (pm *ProtocolManager) peerSetLoop() { for { select { - case <-pm.chainHeadCh: + case event := <-pm.chainHeadCh: + pm.blockNumberGauge.Update(int64(event.Block.NumberU64())) + if !pm.isBlockProposer { break } |