p2p api provides methods for interacting with Kona’s P2P stack.
Peer Information Methods
opp2p_self
Returns information about the local node in the form of PeerInfo. A node running without discovery returns no ENR.
Example
opp2p_peerCount
Returns the count of connected peers for both discovery and gossip networks. A node running without discovery returns null for connectedDiscovery.
Example
opp2p_peers
Returns information about peers. If connected parameter is true, only returns connected peers. A node running without discovery returns no ENR and a chainID of 0 for its peers.
Parameters
connected(boolean): If true, only returns connected peers
Example
opp2p_peerStats
Returns statistical information about peers including connection counts and topic subscriptions. A node running without discovery returns a table of 0.
Example
opp2p_discoveryTable
Returns the discovery table entries as a list of ENR strings. A node running without discovery returns the error discovery disabled, as op-node does.
Example
Peer Blocking Methods
opp2p_blockPeer
Blocks a specific peer by peer ID, preventing any connections to or from that peer. The peer’s open connections are closed, and new ones are refused in both directions until it is unblocked, or until the node restarts: blocks aren’t kept across restarts yet (#23768).
This applies to protected and static peers too: a blocked static peer isn’t dialed again until it is unblocked, or until the node restarts and dials it again from its configuration. op-node, by contrast, leaves a blocked peer’s open connections in place.
Parameters
peerID(string): The peer ID to block
Example
opp2p_unblockPeer
Unblocks a previously blocked peer by peer ID, and lifts its ban if it is banned for its score, as in op-node. A static peer is dialed again within a minute; call opp2p_connectPeer to connect it at once.
Parameters
peerID(string): The peer ID to unblock
Example
opp2p_listBlockedPeers
Returns a list of all blocked peer IDs. Peers banned for their score aren’t listed, as in op-node.
Example
Address Blocking Methods
opp2p_blockAddr
Blocks connections to and from a specific IP address, whichever peer they belong to. Open connections are closed, and new ones are refused in both directions until the address is unblocked, or until the node restarts (#23768). op-node, by contrast, leaves open connections in place.
Parameters
address(string): The IP address to block (IPv4 or IPv6)
Example
opp2p_unblockAddr
Unblocks a previously blocked IP address.
Parameters
address(string): The IP address to unblock (IPv4 or IPv6)
Example
opp2p_listBlockedAddrs
Returns a list of all blocked IP addresses.
Example
Subnet Blocking Methods
opp2p_blockSubnet
Blocks connections to and from an entire IP subnet using CIDR notation, whichever peers they belong to. Open connections are closed, and new ones are refused in both directions until the subnet is unblocked, or until the node restarts (#23768). op-node, by contrast, leaves open connections in place.
Parameters
subnet(string): The subnet to block in CIDR notation (e.g., “192.168.1.0/24”)
Example
opp2p_unblockSubnet
Unblocks a previously blocked IP subnet.
Parameters
subnet(string): The subnet to unblock in CIDR notation
Example
opp2p_listBlockedSubnets
Returns a list of all blocked IP subnets.
Example
Peer Protection Methods
opp2p_protectPeer
Protects a peer from being disconnected due to connection limits or other automatic pruning mechanisms.
Parameters
peerID(string): The peer ID to protect
Example
opp2p_unprotectPeer
Removes protection from a peer, allowing it to be disconnected by automatic pruning mechanisms. A static peer stays protected.
Parameters
peerID(string): The peer ID to unprotect
Example
Connection Management Methods
opp2p_connectPeer
Connects to a specific peer using a multiaddress, and returns once the peer is connected.
It respects blocks and bans: if the peer, its IP address or its subnet is blocked, or the peer is banned for its score, the call fails at once with the reason, and nothing is dialed. To connect such a peer, unblock it first; opp2p_unblockPeer lifts a ban too. The call also fails at once if the peer has reached its redial limit. A dial that fails, for example because nothing listens at the address, returns the dial’s error, and one that doesn’t finish within 30 seconds times out.
Parameters
multiaddr(string): The multiaddress of the peer to connect to
Example
opp2p_disconnectPeer
Disconnects from a specific peer by peer ID, and returns once its connections have closed. A static peer is dialed again about a second later.
Parameters
peerID(string): The peer ID to disconnect from