This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
[9177] finality_target returns a hash instead of an option #9192
Closed
Closed
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e034fad
make finality_target return target hash in case of absence
tau3 b69cf5d
revert changes affected by formatting
tau3 7b3cb50
refactor changed function; fix unit test
tau3 4f9c10d
fixes after code review
tau3 c175353
making linter happy
tau3 26f853e
Merge remote-tracking branch 'upstream/master' into feature/9177/fina…
tau3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
make finality_target return target hash in case of absence
- Loading branch information
commit e034fad05034357d51e180cd9d425a561341294f
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,23 +32,23 @@ use sp_runtime::{ | |
| /// where 'longest' is defined as the highest number of blocks | ||
| pub struct LongestChain<B, Block> { | ||
| backend: Arc<B>, | ||
| _phantom: PhantomData<Block> | ||
| _phantom: PhantomData<Block>, | ||
| } | ||
|
|
||
| impl<B, Block> Clone for LongestChain<B, Block> { | ||
| fn clone(&self) -> Self { | ||
| let backend = self.backend.clone(); | ||
| LongestChain { | ||
| backend, | ||
| _phantom: Default::default() | ||
| _phantom: Default::default(), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl<B, Block> LongestChain<B, Block> | ||
| where | ||
| B: backend::Backend<Block>, | ||
| Block: BlockT, | ||
| where | ||
| B: backend::Backend<Block>, | ||
| Block: BlockT, | ||
| { | ||
| /// Instantiate a new LongestChain for Backend B | ||
| pub fn new(backend: Arc<B>) -> Self { | ||
|
|
@@ -77,9 +77,9 @@ where | |
|
|
||
| #[async_trait::async_trait] | ||
| impl<B, Block> SelectChain<Block> for LongestChain<B, Block> | ||
| where | ||
| B: backend::Backend<Block>, | ||
| Block: BlockT, | ||
| where | ||
| B: backend::Backend<Block>, | ||
| Block: BlockT, | ||
|
||
| { | ||
| async fn leaves(&self) -> Result<Vec<<Block as BlockT>::Hash>, ConsensusError> { | ||
| LongestChain::leaves(self).map_err(|e| ConsensusError::ChainLookup(e.to_string()).into()) | ||
|
|
@@ -94,11 +94,16 @@ where | |
| &self, | ||
| target_hash: Block::Hash, | ||
| maybe_max_number: Option<NumberFor<Block>>, | ||
| ) -> Result<Option<Block::Hash>, ConsensusError> { | ||
| ) -> Result<Block::Hash, ConsensusError> { | ||
| let import_lock = self.backend.get_import_lock(); | ||
| self.backend | ||
| let x = self.backend | ||
| .blockchain() | ||
| .best_containing(target_hash, maybe_max_number, import_lock) | ||
| .map_err(|e| ConsensusError::ChainLookup(e.to_string()).into()) | ||
| .map_err(|e| ConsensusError::ChainLookup(e.to_string()).into()); | ||
| match x { | ||
| Err(e) => Err(e), | ||
| Ok(Some(h)) => Ok(h), | ||
| Ok(None) => Ok(target_hash), | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1173,7 +1173,7 @@ where | |
| debug!(target: "afg", "Finding best chain containing block {:?} with number limit {:?}", block, limit); | ||
|
|
||
| let result = match select_chain.finality_target(block, None).await { | ||
| Ok(Some(best_hash)) => { | ||
| Ok(best_hash) => { | ||
| let best_header = client | ||
| .header(BlockId::Hash(best_hash))? | ||
| .expect("Header known to exist after `finality_target` call; qed"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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);
},
}; |
||
|
|
@@ -1231,10 +1231,6 @@ where | |
| }) | ||
| .or_else(|| Some((target_header.hash(), *target_header.number()))) | ||
| } | ||
| Ok(None) => { | ||
| debug!(target: "afg", "Encountered error finding best chain containing {:?}: couldn't find target block", block); | ||
| None | ||
| } | ||
| Err(e) => { | ||
| debug!(target: "afg", "Encountered error finding best chain containing {:?}: {:?}", block, e); | ||
| None | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.