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::vm::serve(vm_server, stop_ch_rx).await
}

Modules§

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