pub struct Block {
pub round: u64,
pub prev_hash: Hash,
pub proposer: NodeId,
pub seed: u64,
pub data_hashes: Vec<Hash>,
}Fields§
§round: u64§prev_hash: Hash§proposer: NodeId§seed: u64§data_hashes: Vec<Hash>Implementations§
Source§impl Block
impl Block
pub fn new(round: u64, prev_hash: Hash, proposer: NodeId, seed: u64) -> Self
Sourcepub fn hash(&self) -> Hash
pub fn hash(&self) -> Hash
Examples found in repository?
examples/single_round.rs (line 22)
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}pub fn genesis() -> Self
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Block
impl<'de> Deserialize<'de> for Block
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Block
impl RefUnwindSafe for Block
impl Send for Block
impl Sync for Block
impl Unpin for Block
impl UnsafeUnpin for Block
impl UnwindSafe for Block
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more