Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Conversation

@tau3
Copy link

@tau3 tau3 commented Jun 24, 2021

Hello!

I'd like to submit a fix for #9177
SelectChain::finality_target now returns Result<Block::Hash, ConsensusError>

@tau3 tau3 requested a review from andresilva as a code owner June 24, 2021 00:05
@cla-bot-2021
Copy link

cla-bot-2021 bot commented Jun 24, 2021

User @tau3, please sign the CLA here.

@tau3 tau3 changed the title Feature/9177/finality target return [9177] finality_target return a hash instead of an option Jun 24, 2021
@tau3 tau3 changed the title [9177] finality_target return a hash instead of an option [9177] finality_target returns a hash instead of an option Jun 24, 2021
Copy link
Contributor

@andresilva andresilva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution @tau3. This will also require a small PR on polkadot to adapt to the interface change, but I can prepare that. Overall LGTM, just some minor changes needed.

Comment on lines 80 to 82
where
B: backend::Backend<Block>,
Block: BlockT,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And these as well.

Comment on lines 49 to 51
where
B: backend::Backend<Block>,
Block: BlockT,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's drop these formatting changes.

self.backend
.blockchain()
.best_containing(target_hash, maybe_max_number, import_lock)
.map(|maybe_hash| { maybe_hash.unwrap_or(target_hash) })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.map(|maybe_hash| { maybe_hash.unwrap_or(target_hash) })
.map(|maybe_hash| maybe_hash.unwrap_or(target_hash))


assert_eq!(
None,
uninserted_block.hash(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should just remove this test now.

Ok(best_hash) => {
let best_header = client
.header(BlockId::Hash(best_hash))?
.expect("Header known to exist after `finality_target` call; qed");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this may no longer be true, there is a possibility that SelectChain::finality_target just returned the passed value without checking the DB at all (in practice it shouldn't happen as we can only have previously finalized something that already existed in the database). Either way we should not call expect here and instead handle the case where we get None from this call. Something like this should work:

let best_header = match client.header(BlockId::Hash(best_hash))? {
    Some(header) => header,
    None => {
        debug!(target: "afg", "Couldn't find target block from `finality_target`: {:?}", best_hash);
        return Ok(None);
    },
};

@andresilva
Copy link
Contributor

And sorry for the delay in review! 🙏

@andresilva andresilva added A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. labels Jul 6, 2021
@stale
Copy link

stale bot commented Aug 5, 2021

Hey, is anyone still working on this? Due to the inactivity this issue has been automatically marked as stale. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the A5-stale Pull request did not receive any updates in a long time. No review needed at this stage. Close it. label Aug 5, 2021
@stale stale bot removed the A5-stale Pull request did not receive any updates in a long time. No review needed at this stage. Close it. label Aug 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants