Server & Application
There are two main templates for deploying the application and P2P logic. The ServerBase and the ApplicationBase. With these base templates, you will build a Server and an Application class that inherits the bases. The server class you create will deploy the application class.
The server base automatically handles all peer discovery and has options to deploy the GossipSub.
Create Application
This is the logic the peer deploys and can be role-dependentrole dependant based on the needs of the subnet.
Example
class MyApplication(ApplicationBase):
def __init__(
self,
*,
role: "trainer" | "validator",
key_pair: KeyPair,
db: RocksDB,
subnet_id: int,
subnet_node_id: int,
is_bootstrap: bool,
telemetry: Telemetry | None = None,
) -> None:
super().__init__()
self.role= role
self.key_pair = key_pair
self.db = db
self.subnet_id = subnet_id
self.subnet_node_id = subnet_node_id
self.is_bootstrap = is_bootstrap
self.telemetry = telemetry
async def setup(self, context: P2PNetworkContext) -> None:
"""
Called once after the host, DHT, and optional pubsub are ready.
The custom P2P logic should deploy from here, such as the custom P2P
protocols, the API protocol. As well as non-application-based logic,
such as the Network API.
"""
async def start_application(self, context: P2PNetworkContext) -> None:
"""
Called after the bootstrap and optional connection maintenance startup.
Deploy all of the application logic for the peer
"""
async def cleanup(self, context: P2PNetworkContext) -> None:
"""
Called once while the network context is still available.
Cleanup any processes created.
"""Create Server
The server will initialize all of the P2P logic, such as peer discovery, and deploy the application logic
Example
Last updated