Virtual Machine Runtime Engine (VMRE)
The VMRE handles the lifecycle, compatibility and logging IO of a managed VM process.
How it works
The runtime.Initializer interface could be implemented to manage local or remote VM processes.
This implementation is consumed by a gRPC server which serves the Runtime
service. The server interacts with the underlying process and allows for the VM
binary to communicate with AvalancheGo.
Subprocess VM management
The subprocess is currently the only supported Runtime implementation.
It works by starting the VM's as a subprocess of AvalancheGo by os.Exec.
Workflow
- VMRegistrycalls the RPC Chain VM- Factory.
- Factory Starts an instanace of a VMREserver that consumes aruntime.Initializerinterface implementation.
- The address of this server is passed as a ENV variable AVALANCHE_VM_RUNTIME_ENGINE_ADDRviaos.Execwhich starts the VM binary.
- The VM uses the address of the VMREserver to create a client.
- Client sends a InitializeRPC informing the server of theProtocol Versionand futureAddressof the RPC Chain VM server allowing it to perform a validationHandshake.
- After the Handshakeis complete the RPC Chain VM server is started which serves theChainVMimplementation.
- The connection details for the RPC Chain VM server are now used to create an RPC Chain VM client.
- ChainManageruses this VM client to bootstrap the chain powered by- Snowmanconsensus.
- To shutdown the VM runtime.Stop()sends aSIGTERMsignal to the VM process.
Debugging
Process Not Found
When runtime is Bootstrapped handshake success is observed during the Initialize RPC. Process not found means that the runtime Client in the VM binary could not communicate with the runtime Server on AvalancheGo. This could be the result of networking issues or other error in Serve().
failed to register VM {"vmID": "tGas3T58KzdjcJ2iKSyiYsWiqYctRXaPTqBCA11BqEkNg8kPc", "error": "handshake failed: timeout"}
Protocol Version Mismatch
To ensure RPC compatibility the protocol version of AvalancheGo must match the subnet VM. To correct this error update the subnet VM's dependencies to the latest version AvalancheGo.
failed to register VM {"vmID": "tGas3T58KzdjcJ2iKSyiYsWiqYctRXaPTqBCA11BqEkNg8kPc", "error": "handshake failed: protocol version mismatch avalanchego: 19 vm: 18"}