Crate timestampvm

source ·
Expand description

A minimal implementation of custom virtual machine (VM) for Avalanche subnet.

This project implements timestampvm that allows anyone to propose and read blocks, each of which is tagged with the proposed timestamp. It implements the snowman block.ChainVM interface in Rust, pluggable to AvalancheGo nodes.

See ava-labs/timestampvm for the original Go implementation.

Layout

The project is structured such that it can be used as a template to build more complex VMs (e.g., Ethereum VM, key-value store VM).

The major components are:

Example

A simple example that prepares an HTTP/1 connection over a Tokio TCP stream.

use avalanche_types::subnet;
use timestampvm::vm;
use tokio::sync::broadcast::{self, Receiver, Sender};

#[tokio::main]
async fn main() -> std::io::Result<()> {
    let (stop_ch_tx, stop_ch_rx): (Sender<()>, Receiver<()>) = broadcast::channel(1);
    let vm_server = subnet::rpc::vm::server::Server::new(vm::Vm::new(), stop_ch_tx);
    subnet::rpc::plugin::serve(vm_server, stop_ch_rx).await
}

Modules

Implementation of timestampvm APIs, to be registered via create_static_handlers and create_handlers in the vm crate.
Implementation of snowman.Block interface for timestampvm.
Implements client for timestampvm APIs.
Defines timestampvm genesis block.
Manages the virtual machine states.
Implementation of snowman.block.ChainVM interface for timestampvm.