Go to file
Greg Fitzgerald d88d1b2a09 Reset historian's hasher between events
Hasher will generate different hashes for the same input if it
had already generated a hash.

Also add a binary to ensure the example in the README works.
2018-02-19 12:03:06 -07:00
src Reset historian's hasher between events 2018-02-19 12:03:06 -07:00
.gitignore cargo init 2018-02-14 07:23:59 -07:00
.travis.yml Try running kcov within docker 2018-02-16 08:55:25 -07:00
Cargo.toml Reset historian's hasher between events 2018-02-19 12:03:06 -07:00
LICENSE Prep for ownership transfer and rename 2018-02-16 11:53:14 -07:00
README.md Reset historian's hasher between events 2018-02-19 12:03:06 -07:00

README.md

Silk crate Silk documentation Build Status codecov

Silk, a silky smooth implementation of the Loom specification

Loom is a new achitecture for a high performance blockchain. Its whitepaper boasts a theoretical throughput of 710k transactions per second on a 1 gbps network. The specification is implemented in two git repositories. Reserach is performed in the loom repository. That work drives the Loom specification forward. This repository, on the other hand, aims to implement the specification as-is. We care a great deal about quality, clarity and short learning curve. We avoid the use of unsafe Rust and write tests for everything. Optimizations are only added when corresponding benchmarks are also added that demonstrate real performance boots. We expect the feature set here will always be a ways behind the loom repo, but that this is an implementation you can take to the bank, literally.

Usage

Add the latest [silk package] (https://crates.io/crates/silk) to the [dependencies] section of your Cargo.toml.

Create a Historian and send it events to generate an event log, where each log entry is tagged with the historian's latest hash. Then ensure the order of events was not tampered with by verifying each entry's hash can be generated from the hash in the previous entry:

extern crate silk;

use silk::historian::Historian;
use silk::log::{verify_slice, Entry, Event};
use std::{thread, time};

fn create_log(hist: &Historian) -> Vec<Entry> {
    hist.sender.send(Event::Tick).unwrap();
    thread::sleep(time::Duration::new(0, 100_000));
    hist.sender.send(Event::UserDataKey(0xdeadbeef)).unwrap();
    thread::sleep(time::Duration::new(0, 100_000));
    hist.sender.send(Event::Tick).unwrap();

    let entry0 = hist.receiver.recv().unwrap();
    let entry1 = hist.receiver.recv().unwrap();
    let entry2 = hist.receiver.recv().unwrap();
    vec![entry0, entry1, entry2]
}

fn main() {
    let seed = 0;
    let hist = Historian::new(seed);
    let entries = create_log(&hist);
    for entry in &entries {
        println!("{:?}", entry);
    }
    assert!(verify_slice(&entries, seed));
}

Running the program should produce a log similar to:

Entry { num_hashes: 0, end_hash: 0, event: Tick }
Entry { num_hashes: 245, end_hash: 11504657626326377539, event: UserDataKey(3735928559) }
Entry { num_hashes: 154, end_hash: 13410333856574024888, event: Tick }

Developing

Building

Install rustc, cargo and rustfmt:

$ curl https://sh.rustup.rs -sSf | sh
$ source $HOME/.cargo/env
$ rustup component add rustfmt-preview

Download the source code:

$ git clone https://github.com/loomprotocol/silk.git
$ cd silk

Testing

Run the test suite:

cargo test

Benchmarking

First install the nightly build of rustc. cargo bench requires unstable features:

$ rustup install nightly

Run the benchmarks:

$ cargo +nightly bench --features="unstable"