diff --git a/doc/historian.md b/doc/historian.md deleted file mode 100644 index f2cb23c581..0000000000 --- a/doc/historian.md +++ /dev/null @@ -1,65 +0,0 @@ -The Historian -=== - -Create a *Historian* and send it *events* to generate an *event log*, where each *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: - -![historian](https://user-images.githubusercontent.com/55449/36950845-459bdb58-1fb9-11e8-850e-894586f3729b.png) - -```rust -extern crate solana; - -use solana::historian::Historian; -use solana::ledger::{Block, Entry, Hash}; -use solana::event::{generate_keypair, get_pubkey, sign_claim_data, Event}; -use std::thread::sleep; -use std::time::Duration; -use std::sync::mpsc::SendError; - -fn create_ledger(hist: &Historian) -> Result<(), SendError>> { - sleep(Duration::from_millis(15)); - let tokens = 42; - let keypair = generate_keypair(); - let event0 = Event::new_claim(get_pubkey(&keypair), tokens, sign_claim_data(&tokens, &keypair)); - hist.sender.send(event0)?; - sleep(Duration::from_millis(10)); - Ok(()) -} - -fn main() { - let seed = Hash::default(); - let hist = Historian::new(&seed, Some(10)); - create_ledger(&hist).expect("send error"); - drop(hist.sender); - let entries: Vec> = hist.receiver.iter().collect(); - for entry in &entries { - println!("{:?}", entry); - } - // Proof-of-History: Verify the historian learned about the events - // in the same order they appear in the vector. - assert!(entries[..].verify(&seed)); -} -``` - -Running the program should produce a ledger similar to: - -```rust -Entry { num_hashes: 0, id: [0, ...], event: Tick } -Entry { num_hashes: 3, id: [67, ...], event: Transaction { tokens: 42 } } -Entry { num_hashes: 3, id: [123, ...], event: Tick } -``` - -Proof-of-History ---- - -Take note of the last line: - -```rust -assert!(entries[..].verify(&seed)); -``` - -[It's a proof!](https://en.wikipedia.org/wiki/Curry–Howard_correspondence) For each entry returned by the -historian, we can verify that `id` is the result of applying a sha256 hash to the previous `id` -exactly `num_hashes` times, and then hashing then event data on top of that. Because the event data is -included in the hash, the events cannot be reordered without regenerating all the hashes. diff --git a/doc/historian.msc b/doc/historian.msc deleted file mode 100644 index b9bc84bd49..0000000000 --- a/doc/historian.msc +++ /dev/null @@ -1,18 +0,0 @@ -msc { - client,historian,recorder; - - recorder=>historian [ label = "e0 = Entry{id: h0, n: 0, event: Tick}" ] ; - recorder=>recorder [ label = "h1 = hash(h0)" ] ; - recorder=>recorder [ label = "h2 = hash(h1)" ] ; - client=>historian [ label = "Transaction(d0)" ] ; - historian=>recorder [ label = "Transaction(d0)" ] ; - recorder=>recorder [ label = "h3 = hash(h2 + d0)" ] ; - recorder=>historian [ label = "e1 = Entry{id: hash(h3), n: 3, event: Transaction(d0)}" ] ; - recorder=>recorder [ label = "h4 = hash(h3)" ] ; - recorder=>recorder [ label = "h5 = hash(h4)" ] ; - recorder=>recorder [ label = "h6 = hash(h5)" ] ; - recorder=>historian [ label = "e2 = Entry{id: h6, n: 3, event: Tick}" ] ; - client=>historian [ label = "collect()" ] ; - historian=>client [ label = "entries = [e0, e1, e2]" ] ; - client=>client [ label = "entries.verify(h0)" ] ; -}