Skip to main content

hex

Function hex 

Source
pub fn hex(h: &Hash) -> String
Examples found in repository?
examples/single_round.rs (line 21)
3fn main() {
4    let config = Config::new(1); // f=1, needs 4 nodes
5    let mut engine = ConsensusEngine::new(config);
6
7    for i in 1..=4 {
8        let node = Node::new(i, 1000).expect("failed to create node");
9        engine.add_node(node);
10    }
11
12    println!("Running VRF-PBFT with 4 nodes (f=1)...\n");
13
14    // VRF selection is probabilistic, so retry until a round succeeds
15    loop {
16        match engine.run_round() {
17            Ok(block) => {
18                println!("Consensus reached on round {}!", engine.round());
19                println!("  Proposer:  node {}", block.proposer);
20                println!("  Seed:      {}", block.seed);
21                println!("  Prev hash: {}...", &hex(&block.prev_hash)[..16]);
22                println!("  Hash:      {}...", &hex(&block.hash())[..16]);
23                println!("\nMessages exchanged: {}", engine.messages().len());
24                break;
25            }
26            Err(vrf_pbft::Error::NoProposer(r)) => {
27                println!("Round {}: no proposer elected, retrying...", r);
28            }
29            Err(vrf_pbft::Error::InsufficientVotes { needed, got }) => {
30                println!(
31                    "Round {}: not enough votes ({}/{}), retrying...",
32                    engine.round(),
33                    got,
34                    needed
35                );
36            }
37            Err(e) => {
38                eprintln!("Fatal error: {}", e);
39                std::process::exit(1);
40            }
41        }
42    }
43}