Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test in blockchain p5 bc_5_heaviest_chain #25

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 5 additions & 14 deletions src/c2_blockchain/p5_fork_choice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
//! Since we have nothing to add to the Block or Header data structures in this lesson,
//! we will import them from the previous lesson.

use super::p3_consensus::THRESHOLD;
use super::p4_batched_extrinsics::{Block, Header};
use crate::hash;
use super::p3_consensus::THRESHOLD;

/// Judge which blockchain is "best" when there are multiple candidates. There are several
/// meaningful notions of "best" which is why this is a trait instead of just a
Expand Down Expand Up @@ -167,24 +167,15 @@ fn bc_5_mine_to_custom_difficulty() {
fn bc_5_heaviest_chain() {
let g = Header::genesis();

let mut i = 0;
let h_a1 = loop {
let header = g.child(hash(&[i]), i);
// Extrinsics root hash must be higher than threshold (less work done)
if hash(&header) > THRESHOLD {
break header;
}
i += 1;
};
let h_a1 = g.child(hash(&[1]), 1);
let chain_1 = &[g.clone(), h_a1];

let h_b1 = loop {
let header = g.child(hash(&[i]), i);
// Extrinsics root hash must be lower than threshold (more work done)
if hash(&header) < THRESHOLD {
let header = g.child(hash(&[1]), 1);
// more work done - harder to find such a hash
if hash(&header) < THRESHOLD / 1000 {
break header;
}
i += 1;
};
let chain_2 = &[g, h_b1];

Expand Down