add getGossipSubPeers RPC (#2107)
This commit is contained in:
parent
e2d09fca23
commit
a2364ce1bc
|
@ -58,7 +58,7 @@ type
|
|||
|
||||
Eth2Node* = ref object of RootObj
|
||||
switch*: Switch
|
||||
pubsub*: PubSub
|
||||
pubsub*: GossipSub
|
||||
discovery*: Eth2DiscoveryProtocol
|
||||
discoveryEnabled*: bool
|
||||
wantedPeers*: int
|
||||
|
@ -1065,7 +1065,7 @@ proc onConnEvent(node: Eth2Node, peerId: PeerID, event: ConnEvent) {.async.} =
|
|||
peer.connectionState = Disconnected
|
||||
|
||||
proc init*(T: type Eth2Node, conf: BeaconNodeConf, enrForkId: ENRForkID,
|
||||
switch: Switch, pubsub: PubSub, ip: Option[ValidIpAddress],
|
||||
switch: Switch, pubsub: GossipSub, ip: Option[ValidIpAddress],
|
||||
tcpPort, udpPort: Port, privKey: keys.PrivateKey, discovery: bool,
|
||||
rng: ref BrHmacDrbgContext): T =
|
||||
new result
|
||||
|
@ -1565,7 +1565,7 @@ proc createEth2Node*(rng: ref BrHmacDrbgContext,
|
|||
sign = false,
|
||||
verifySignature = false,
|
||||
anonymize = true,
|
||||
parameters = params).PubSub
|
||||
parameters = params)
|
||||
|
||||
switch.mount(pubsub)
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
||||
|
||||
import
|
||||
std/[deques, sequtils, strutils],
|
||||
std/[deques, sequtils],
|
||||
chronos,
|
||||
stew/shims/macros,
|
||||
stew/byteutils,
|
||||
|
@ -14,7 +14,10 @@ import
|
|||
rpc_utils,
|
||||
../beacon_node_common, ../nimbus_binary_common, ../eth2_network,
|
||||
../eth1_monitor, ../validator_duties,
|
||||
../spec/[digest, datatypes, presets]
|
||||
../spec/[digest, datatypes, presets],
|
||||
|
||||
libp2p/protocols/pubsub/[gossipsub, pubsubpeer]
|
||||
|
||||
|
||||
logScope: topics = "nimbusapi"
|
||||
|
||||
|
@ -22,14 +25,12 @@ type
|
|||
RpcServer = RpcHttpServer
|
||||
Eth1Block = eth1_monitor.Eth1Block
|
||||
|
||||
when defined(chronosFutureTracking):
|
||||
type
|
||||
FutureInfo* = object
|
||||
id*: int
|
||||
procname*: string
|
||||
filename*: string
|
||||
line*: int
|
||||
state: string
|
||||
FutureInfo* = object
|
||||
id*: int
|
||||
procname*: string
|
||||
filename*: string
|
||||
line*: int
|
||||
state*: string
|
||||
|
||||
proc installNimbusApiHandlers*(rpcServer: RpcServer, node: BeaconNode) =
|
||||
## Install non-standard api handlers - some of these are used by 3rd-parties
|
||||
|
@ -98,8 +99,8 @@ proc installNimbusApiHandlers*(rpcServer: RpcServer, node: BeaconNode) =
|
|||
node.chainDag.withState(node.chainDag.tmpState, head.atSlot(wallSlot)):
|
||||
return node.getBlockProposalEth1Data(state)
|
||||
|
||||
when defined(chronosFutureTracking):
|
||||
rpcServer.rpc("getChronosFutures") do () -> seq[FutureInfo]:
|
||||
rpcServer.rpc("getChronosFutures") do () -> seq[FutureInfo]:
|
||||
when defined(chronosFutureTracking):
|
||||
var res: seq[FutureInfo]
|
||||
|
||||
for item in pendingFutures():
|
||||
|
@ -113,3 +114,42 @@ proc installNimbusApiHandlers*(rpcServer: RpcServer, node: BeaconNode) =
|
|||
)
|
||||
|
||||
return res
|
||||
else:
|
||||
raise (ref CatchableError)(
|
||||
msg: "Compile with '-d:chronosFutureTracking' to enable this request")
|
||||
|
||||
rpcServer.rpc("getGossipSubPeers") do () -> JsonNode:
|
||||
var res = newJObject()
|
||||
var gossipsub = newJObject()
|
||||
|
||||
proc toNode(v: PubSubPeer): JsonNode =
|
||||
%(
|
||||
peerId: $v.peerId,
|
||||
score: v.score,
|
||||
iWantBudget: v.iWantBudget,
|
||||
iHaveBudget: v.iHaveBudget,
|
||||
outbound: v.outbound,
|
||||
appScore: v.appScore,
|
||||
behaviourPenalty: v.behaviourPenalty
|
||||
)
|
||||
|
||||
for topic, v in node.network.pubsub.gossipsub:
|
||||
var peers = newJArray()
|
||||
for peer in v:
|
||||
peers.add(peer.toNode())
|
||||
|
||||
gossipsub.add(topic, peers)
|
||||
|
||||
res.add("gossipsub", gossipsub)
|
||||
|
||||
var mesh = newJObject()
|
||||
for topic, v in node.network.pubsub.mesh:
|
||||
var peers = newJArray()
|
||||
for peer in v:
|
||||
peers.add(peer.toNode())
|
||||
|
||||
mesh.add(topic, peers)
|
||||
|
||||
res.add("mesh", mesh)
|
||||
|
||||
return res
|
||||
|
|
|
@ -278,3 +278,11 @@ Get the current list of live async futures in the process - compile with `-d:chr
|
|||
```
|
||||
curl -d '{"jsonrpc":"2.0","id":"id","method":"getChronosFutures","params":[] }' -H 'Content-Type: application/json' localhost:9190 -s | jq '.result | (.[0] | keys_unsorted) as $keys | $keys, map([.[ $keys[] ]])[] | @csv'
|
||||
```
|
||||
|
||||
### getGossipSubPeers
|
||||
|
||||
Get the current list of live async futures in the process - compile with `-d:chronosFutureTracking` to enable.
|
||||
|
||||
```
|
||||
curl -d '{"jsonrpc":"2.0","id":"id","method":"getGossipSubPeers","params":[] }' -H 'Content-Type: application/json' localhost:9190 -s | jq '.result'
|
||||
```
|
||||
|
|
Loading…
Reference in New Issue