Skip to content

tashigit/tashi-vertex-rs

Repository files navigation

Tashi Vertex

Crates.io docs.rs License

Rust bindings for Tashi Vertex, an embedded Byzantine fault-tolerant consensus engine based on the Hashgraph algorithm.

Tashi Vertex uses a DAG (Directed Acyclic Graph) of cryptographically signed events and virtual voting to achieve consensus finality in under 100 milliseconds — without exchanging explicit vote messages. For a detailed explanation, see the Vertex whitepaper.

Features

  • Fast BFT Consensus — sub-100ms finality with tolerance up to f = ⌊(n-1)/3⌋ Byzantine participants
  • Async-first — socket binding and message receiving are Future-based
  • Zero runtime dependencies — only links dynamically to the tashi-vertex C library
  • Safe FFI — opaque pointer wrappers with automatic cleanup via Drop
  • Configurable — 15+ tunable engine parameters (heartbeat, latency thresholds, epoch sizing, etc.)
  • Base58 utilities — encode/decode keys and binary data

Installation

Add the crate to your project:

cargo add tashi-vertex

Build Requirements

  • CMake >= 4.0
  • The Tashi Vertex shared library (libtashi-vertex.so / .dylib / .dll), fetched automatically by the build script

Quick Start

Generate a keypair for your node:

use tashi_vertex::KeySecret;

let secret = KeySecret::generate();
let public = secret.public();

println!("Secret: {secret}"); // Base58-encoded DER
println!("Public: {public}");

Run a minimal consensus network:

use tashi_vertex::{Context, Engine, KeySecret, Message, Options, Peers, Socket, Transaction};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let key: KeySecret = "BASE58_SECRET_KEY".parse()?;

    // Configure peers in the network
    let mut peers = Peers::new()?;
    peers.insert("127.0.0.1:9001", &"BASE58_PEER_PUBLIC_KEY".parse()?, Default::default())?;
    peers.insert("127.0.0.1:9000", &key.public(), Default::default())?;

    // Initialize the runtime and bind a socket
    let context = Context::new()?;
    let socket = Socket::bind(&context, "127.0.0.1:9000").await?;

    // Start the consensus engine
    let options = Options::default();
    let engine = Engine::start(&context, socket, options, &key, peers)?;

    // Send a transaction
    let data = b"hello world";
    let mut tx = Transaction::allocate(data.len());
    tx.copy_from_slice(data);
    engine.send_transaction(tx)?;

    // Receive consensus-ordered messages
    while let Some(message) = engine.recv_message().await? {
        match message {
            Message::Event(event) => {
                for tx in event.transactions() {
                    println!("tx: {:?}", tx);
                }
            }
            Message::SyncPoint(_) => { /* session management */ }
        }
    }

    Ok(())
}

API Overview

Type Description
[Engine] Starts and drives the consensus engine — send transactions and receive ordered messages
[Context] Runtime context managing async operations and resources
[Socket] Async network socket bound to a local address
[Options] Engine configuration (heartbeat, latency, epoch size, threading, etc.)
[Message] Received message — either an Event or a SyncPoint
[Event] A finalized event carrying consensus-ordered transactions
[Transaction] Allocated buffer for submitting data to the network
[KeySecret] Ed25519 secret key for signing (Base58/DER serializable)
[KeyPublic] Ed25519 public key for verification (Base58/DER serializable)
[Peers] Set of network participants with addresses and capabilities
[SyncPoint] Session management decision from the consensus layer
[base58] Base58 encoding/decoding utilities

Examples

The examples/ directory contains runnable demos:

  • key-generate — Generate a new keypair
  • key-parse — Parse Base58-encoded keys
  • pingback — Full multi-peer consensus network with transaction exchange
cargo run --example key-generate

Running the Pingback Example

The pingback example runs a 3-node consensus network where each node sends a PING transaction. First, generate a keypair for each node:

cargo run --example key-generate  # run 3 times, save each secret/public key

Then start each node in a separate terminal, passing the other two nodes as peers:

cargo run --example pingback -- \
  -B 127.0.0.1:8001 \
  -K <secret_key> \
  -P <peer2_public_key>@127.0.0.1:8002 \
  -P <peer3_public_key>@127.0.0.1:8003

Once all three nodes are running, each will reach consensus and print the ordered events:

 :: Configured network for 3 peers
 :: Initialized runtime
 :: Bound local socket
 :: Started the consensus engine
 > Received SYNC POINT
 > Received EVENT
    - From: aSq9DsNNvGhY...
    - Created: 1770174202473826258
    - Consensus: 1770174208954261963
    - Transactions: 1
    - >> PING
 > Received EVENT
    - From: aSq9DsNNvGhY...
    - Created: 1770174208954261966
    - Consensus: 1770174208954261964
    - Transactions: 1
    - >> PING
 > Received EVENT
    - From: aSq9DsNNvGhY...
    - Created: 1770174216230094057
    - Consensus: 1770174208954261965
    - Transactions: 1
    - >> PING

License

This project is licensed under the Apache License, Version 2.0 (LICENSE).

Dynamic Linking to Tashi Vertex

This project dynamically links to the Tashi Vertex binary library (proprietary). Its origin and licensing details are provided in the NOTICE file.

Disclaimer: The Apache 2.0 license applies only to the source code of this project. The Tashi Vertex binary is not part of this open-source distribution and is governed by its own commercial license.

About

Provides access to Tashi Vertex through a Rust interface.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors