Skip to content

Commit 936ec0c

Browse files
authored
feat(sensor): add RPC methods and broadcast improvements (#862)
1 parent 5641ed4 commit 936ec0c

File tree

12 files changed

+1396
-219
lines changed

12 files changed

+1396
-219
lines changed

cmd/p2p/sensor/api.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import (
1818
type peerData struct {
1919
Name string `json:"name"`
2020
ProtocolVersion uint `json:"protocol_version"`
21+
BlockHash string `json:"block_hash,omitempty"`
22+
BlockNumber uint64 `json:"block_number,omitempty"`
2123
Received p2p.MessageCount `json:"received"`
2224
Sent p2p.MessageCount `json:"sent"`
2325
PacketsReceived p2p.MessageCount `json:"packets_received"`
@@ -85,9 +87,18 @@ func handleAPI(server *ethp2p.Server, conns *p2p.Conns) {
8587
continue
8688
}
8789

90+
// Get latest block info for this peer
91+
blockHash, blockNumber := conns.GetPeerLatestBlock(peerID)
92+
var blockHashStr string
93+
if blockNumber > 0 {
94+
blockHashStr = blockHash.Hex()
95+
}
96+
8897
peers[url] = peerData{
8998
Name: conns.GetPeerName(peerID),
9099
ProtocolVersion: conns.GetPeerVersion(peerID),
100+
BlockHash: blockHashStr,
101+
BlockNumber: blockNumber,
91102
Received: messages.Received,
92103
Sent: messages.Sent,
93104
PacketsReceived: messages.PacketsReceived,

0 commit comments

Comments
 (0)