aboutsummaryrefslogtreecommitdiffstats
path: root/dex
diff options
context:
space:
mode:
authorhaoping-ku <haoping.ku@cobinhood.com>2019-01-18 14:43:41 +0800
committerWei-Ning Huang <w@dexon.org>2019-03-12 12:19:09 +0800
commit5f6c2b5668b6b6f831441cfceb57af801a9e1a36 (patch)
treee7cea171c1a860c75d5dec239521d54b7622c628 /dex
parent0826bd64ff765250ff5a4b2448eadc98d3285c03 (diff)
downloaddexon-5f6c2b5668b6b6f831441cfceb57af801a9e1a36.tar.gz
dexon-5f6c2b5668b6b6f831441cfceb57af801a9e1a36.tar.zst
dexon-5f6c2b5668b6b6f831441cfceb57af801a9e1a36.zip
dex: add block number gauge (#140)
Diffstat (limited to 'dex')
-rw-r--r--dex/handler.go43
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
}