runtime

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 26, 2024 License: BSD-3-Clause Imports: 4 Imported by: 0

README

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 OdysseyGo.

Subprocess VM management

The subprocess is currently the only supported Runtime implementation. It works by starting the VM's as a subprocess of OdysseyGo by os.Exec.

Workflow

  • VMRegistry calls the RPC Chain VM Factory.
  • Factory Starts an instanace of a VMRE server that consumes a runtime.Initializer interface implementation.
  • The address of this server is passed as a ENV variable ODYSSEY_VM_RUNTIME_ENGINE_ADDR via os.Exec which starts the VM binary.
  • The VM uses the address of the VMRE server to create a client.
  • Client sends a Initialize RPC informing the server of the Protocol Version and future Address of the RPC Chain VM server allowing it to perform a validation Handshake.
  • After the Handshake is complete the RPC Chain VM server is started which serves the ChainVM implementation.
  • The connection details for the RPC Chain VM server are now used to create an RPC Chain VM client.
  • ChainManager uses this VM client to bootstrap the chain powered by Snowman consensus.
  • To shutdown the VM runtime.Stop() sends a SIGTERM signal 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 OdysseyGo. 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 OdysseyGo must match the subnet VM. To correct this error update the subnet VM's dependencies to the latest version OdysseyGo.

failed to register VM {"vmID": "tGas3T58KzdjcJ2iKSyiYsWiqYctRXaPTqBCA11BqEkNg8kPc", "error": "handshake failed: protocol version mismatch odysseygo: 19 vm: 18"}

Documentation

Index

Constants

View Source
const (
	// Address of the runtime engine server.
	EngineAddressKey = "ODYSSEY_VM_RUNTIME_ENGINE_ADDR"

	// Duration before handshake timeout during bootstrap.
	DefaultHandshakeTimeout = 5 * time.Second

	// Duration of time to wait for graceful termination to complete.
	DefaultGracefulTimeout = 5 * time.Second
)

Variables

View Source
var (
	ErrProtocolVersionMismatch = errors.New("RPCChainVM protocol version mismatch between OdysseyGo and Virtual Machine plugin")
	ErrHandshakeFailed         = errors.New("handshake failed")
	ErrInvalidConfig           = errors.New("invalid config")
	ErrProcessNotFound         = errors.New("vm process not found")
)

Functions

This section is empty.

Types

type Initializer

type Initializer interface {
	// Initialize provides OdysseyGo with compatibility, networking and
	// process information of a VM.
	Initialize(ctx context.Context, protocolVersion uint, vmAddr string) error
}

type Manager

type Manager interface {
	Tracker
	// Stop all managed VMs.
	Stop(ctx context.Context)
}

func NewManager

func NewManager() Manager

NewManager returns manager of VM runtimes.

TODO: If a runtime exits before the call to `manager.Stop`, it would be nice to remove it from the current set.

type Stopper

type Stopper interface {
	// Stop begins shutdown of a VM. This method must not block
	// and multiple calls to this method will result in no-op.
	Stop(ctx context.Context)
}

type Tracker

type Tracker interface {
	// TrackRuntime adds a VM stopper to the manager.
	TrackRuntime(runtime Stopper)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL