mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 15:16:43 +00:00
eth/internal: add debug.peerStats for stats related to all connected peers (#1252)
* implement debug.peerStats for stats related to all connected peers * add identifier for ipc * display block number in peer stats * eth/downloader: log error while terminating sync
This commit is contained in:
parent
5db6fa7174
commit
e789b4e312
9 changed files with 68 additions and 1 deletions
|
|
@ -474,3 +474,7 @@ func (b *EthAPIBackend) GetWhitelistedMilestone() (bool, uint64, common.Hash) {
|
|||
func (b *EthAPIBackend) PurgeWhitelistedMilestone() {
|
||||
b.eth.Downloader().ChainValidator.PurgeWhitelistedMilestone()
|
||||
}
|
||||
|
||||
func (b *EthAPIBackend) PeerStats() interface{} {
|
||||
return b.eth.handler.GetPeerStats()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -512,7 +512,7 @@ func (d *Downloader) syncWithPeer(p *peerConnection, hash common.Hash, td, ttd *
|
|||
}
|
||||
|
||||
defer func(start time.Time) {
|
||||
log.Debug("Synchronisation terminated", "elapsed", common.PrettyDuration(time.Since(start)))
|
||||
log.Debug("Synchronisation terminated", "elapsed", common.PrettyDuration(time.Since(start)), "err", err)
|
||||
}(time.Now())
|
||||
|
||||
// Look up the sync boundaries: the common ancestor and the target block
|
||||
|
|
|
|||
|
|
@ -728,3 +728,40 @@ func (h *handler) enableSyncedFeatures() {
|
|||
h.chain.TrieDB().SetBufferSize(pathdb.DefaultBufferSize)
|
||||
}
|
||||
}
|
||||
|
||||
// PeerStats represents a short summary of the information known about a connected
|
||||
// peer. Specifically, it contains details about the head hash and total difficulty
|
||||
// of a peer which makes it a bit different from the PeerInfo.
|
||||
type PeerStats struct {
|
||||
Enode string `json:"enode"` // Node URL
|
||||
ID string `json:"id"` // Unique node identifier
|
||||
Name string `json:"name"` // Name of the node, including client type, version, OS, custom data
|
||||
Hash string `json:"hash"` // Head hash of the peer
|
||||
Number uint64 `json:"number"` // Head number of the peer
|
||||
Td uint64 `json:"td"` // Total difficulty of the peer
|
||||
}
|
||||
|
||||
// PeerStats returns the current head height and td of all the connected peers
|
||||
// along with few additional identifiers.
|
||||
func (h *handler) GetPeerStats() []*PeerStats {
|
||||
info := make([]*PeerStats, 0, len(h.peers.peers))
|
||||
|
||||
for _, peer := range h.peers.peers {
|
||||
hash, td := peer.Head()
|
||||
block := h.chain.GetBlockByHash(hash)
|
||||
number := uint64(0)
|
||||
if block != nil {
|
||||
number = block.NumberU64()
|
||||
}
|
||||
info = append(info, &PeerStats{
|
||||
Enode: peer.Node().URLv4(),
|
||||
ID: peer.ID(),
|
||||
Name: peer.Name(),
|
||||
Hash: hash.String(),
|
||||
Number: number,
|
||||
Td: td.Uint64(),
|
||||
})
|
||||
}
|
||||
|
||||
return info
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2729,6 +2729,12 @@ func (api *DebugAPI) GetTraceStack() string {
|
|||
}
|
||||
}
|
||||
|
||||
// PeerStats returns the current head height and td of all the connected peers
|
||||
// along with few additional identifiers.
|
||||
func (api *DebugAPI) PeerStats() interface{} {
|
||||
return api.b.PeerStats()
|
||||
}
|
||||
|
||||
// NetAPI offers network related RPC methods
|
||||
type NetAPI struct {
|
||||
net *p2p.Server
|
||||
|
|
|
|||
|
|
@ -644,6 +644,10 @@ func (b testBackend) SubscribeStateSyncEvent(ch chan<- core.StateSyncEvent) even
|
|||
panic("implement me")
|
||||
}
|
||||
|
||||
func (b testBackend) PeerStats() interface{} {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (b testBackend) GetBorBlockLogs(ctx context.Context, hash common.Hash) ([]*types.Log, error) {
|
||||
receipt, err := b.GetBorBlockReceipt(ctx, hash)
|
||||
if err != nil || receipt == nil {
|
||||
|
|
|
|||
|
|
@ -112,6 +112,9 @@ type Backend interface {
|
|||
PurgeWhitelistedCheckpoint()
|
||||
GetWhitelistedMilestone() (bool, uint64, common.Hash)
|
||||
PurgeWhitelistedMilestone()
|
||||
|
||||
// Networking related APIs
|
||||
PeerStats() interface{}
|
||||
}
|
||||
|
||||
func GetAPIs(apiBackend Backend) []rpc.API {
|
||||
|
|
|
|||
|
|
@ -412,3 +412,7 @@ func (b *backendMock) GetWhitelistedMilestone() (bool, uint64, common.Hash) {
|
|||
func (b *backendMock) PurgeWhitelistedCheckpoint() {}
|
||||
|
||||
func (b *backendMock) PurgeWhitelistedMilestone() {}
|
||||
|
||||
func (b backendMock) PeerStats() interface{} {
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -565,6 +565,11 @@ web3._extend({
|
|||
call: 'debug_getTrieFlushInterval',
|
||||
params: 0
|
||||
}),
|
||||
new web3._extend.Method({
|
||||
name: 'peerStats',
|
||||
call: 'debug_peerStats',
|
||||
params: 0
|
||||
}),
|
||||
],
|
||||
properties: []
|
||||
});
|
||||
|
|
|
|||
|
|
@ -376,3 +376,7 @@ func (b *LesApiBackend) GetWhitelistedMilestone() (bool, uint64, common.Hash) {
|
|||
|
||||
func (b *LesApiBackend) PurgeWhitelistedMilestone() {
|
||||
}
|
||||
|
||||
func (b *LesApiBackend) PeerStats() interface{} {
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue