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

Broadcast dag block in any condition #4138

Merged

Conversation

jackzhhuang
Copy link
Collaborator

Pull request type

The dag block will not be broadcast if its block info's total difficulty is less than the header of the main, leading to an error: a new block that uses it as its one of parents will fail to be executed until the sync pull it.

  pub fn select_head(&mut self, new_branch: BlockChain) -> Result<()> {
        let executed_block = new_branch.head_block();
        let main_total_difficulty = self.main.get_total_difficulty()?;
        let branch_total_difficulty = new_branch.get_total_difficulty()?;
        let parent_is_main_head = self.is_main_head(&executed_block.header().parent_hash());

        if branch_total_difficulty > main_total_difficulty {
            let (enacted_count, enacted_blocks, retracted_count, retracted_blocks) =
                if !parent_is_main_head {
                    self.find_ancestors_from_accumulator(&new_branch)?
                } else {
                    (1, vec![executed_block.block.clone()], 0, vec![])
                };
            self.main = new_branch;

            self.do_new_head(
                executed_block,
                enacted_count,
                enacted_blocks,
                retracted_count,
                retracted_blocks,
            )?;
        } else {
            //send new branch event
            self.broadcast_new_branch(executed_block);
        }
        Ok(())
    }

The problem is in line: let executed_block = new_branch.head_block();. The executed_block will be the header not the latest mined block. This results that minded block will not be broadcast!

The solution is to broadcast any dag block in any condition. See the modified files.

@jackzhhuang jackzhhuang force-pushed the blue-work-as-total-difficulty branch from d3a7538 to 2a6c628 Compare June 18, 2024 10:56
@sanlee42 sanlee42 merged commit 8f65a0b into starcoinorg:dag-master Jun 18, 2024
2 of 4 checks passed
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 this pull request may close these issues.

2 participants