-
Notifications
You must be signed in to change notification settings - Fork 2.7k
[9177] finality_target returns a hash instead of an option #9192
Conversation
andresilva
left a comment
There was a problem hiding this 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.
| where | ||
| B: backend::Backend<Block>, | ||
| Block: BlockT, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And these as well.
| where | ||
| B: backend::Backend<Block>, | ||
| Block: BlockT, |
There was a problem hiding this comment.
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) }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| .map(|maybe_hash| { maybe_hash.unwrap_or(target_hash) }) | |
| .map(|maybe_hash| maybe_hash.unwrap_or(target_hash)) |
|
|
||
| assert_eq!( | ||
| None, | ||
| uninserted_block.hash(), |
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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);
},
};|
And sorry for the delay in review! 🙏 |
|
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. |
Hello!
I'd like to submit a fix for #9177
SelectChain::finality_targetnow returnsResult<Block::Hash, ConsensusError>