Skip to content

Infinite loop on bc_5_heaviest_chain #24

@emochka2007

Description

@emochka2007

Description:

In the p4_batched_extrinsics module, we generate a valid header using the following code snippet:
It expects hash to be less than THRESHOLD

pub fn child(&self, extrinsics_root: Hash, state: u64) -> Self {
        let mut header = Self {
            parent: hash(self),
            height: self.height + 1,
            extrinsics_root,
            state,
            consensus_digest: 0,
        };
        let mut nonce = 0;
        while hash(&header) > THRESHOLD {
            nonce += 1;
            header.consensus_digest = nonce;
        }
        header
    }

However, in the p5_fork_choice module, the test appears to expect the header hash to be above the threshold:
it leads to an infinite loop since the condition hash(&header) > THRESHOLD continuously evaluates to false

fn bc_5_heaviest_chain() {
    println!("test");
    let g = Header::genesis();

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

Am I missing something here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions