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

Infinite loop on bc_5_heaviest_chain #24

Open
emochka2007 opened this issue Sep 30, 2024 · 0 comments · May be fixed by #25
Open

Infinite loop on bc_5_heaviest_chain #24

emochka2007 opened this issue Sep 30, 2024 · 0 comments · May be fixed by #25

Comments

@emochka2007
Copy link

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?

@Zebedeusz Zebedeusz linked a pull request Oct 16, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant