Here's a short overview of the avax-python Avalanche message pipeline.
We've followed the reference Go implementation as closely as possible, but the Python code is still in very early development, so it's lacking a lot of details. For example, right now the Python message pipeline is synchronous, whereas the Go implementation uses asynchronous channels and parallel goroutines.
If you're trying to learn how the Avalanche Go node implementation works, the avax-python code may actually be useful in this respect, because it's barebones and straight to the point. The ideas are the same. Since Avalanche is a multi-blockchain platform, where new chains and DAGs can be added dynamically, the system requires a routing system which delivers messages to the correct consensus engine and VM instance.
For example, messages to/from the P-Chain must go to the blockchain based consensus engine and VM, while X-Chain messages must go to the Avalanche DAG-based subsystem. But the network interface sends and receives all messages together - after all we usually only have one pathway to the Internet. So, most the work is performed in the routing part, which requires us to correctly decode binary network data, find the correct chain ID and route the message to the right consensus subsystem.
So here's a quick summary of the path taken by an Avalanche message arriving from the network and into the consensus sytem:
avaxpython.network.network.Networkobject reads messages from peers.
network_handler. You can implement different network handlers for different purposes. The default handler is
peer.net.routerwhich is a
ChainRouteris implemented in
avaxpython.snow.networking.router.chain_router.pyand will route messages to the correct blockchain using the chain's encoded 32 byte ID
avaxpython.snow.networking.router.handler.Handlerwhich then routes the message to the consensus engine.
avaxpython.vms.platformvmimplementation, while the Avalanche engine uses
So, this is a short summary of the path taken by network messages from the wire to the consensus engines and VM's.
If you're trying to learn the Go implementation, this summary is pretty close to what the Golang code does. Except the Go implementation is asynchronous and uses advanced multitasking constructs like channels and parallel goroutines to achieve high throughput.
X-avax1rlsj0xgvu85awrvkvjlvlqq37q8hmaq2rsraxz. Thank you! ❤