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

Commit

Permalink
Return target_hash for finality_target instead of an Option (#9867)
Browse files Browse the repository at this point in the history
* .

cargo +nightly fmt --all

* Fix test

* Simplify test

* They are already imported

* Needless clone()
  • Loading branch information
liuchengxu authored Sep 29, 2021
1 parent 83ced6b commit 4ecbb1f
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 379 deletions.
3 changes: 2 additions & 1 deletion client/consensus/common/src/longest_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,12 @@ 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
.blockchain()
.best_containing(target_hash, maybe_max_number, import_lock)
.map(|maybe_hash| maybe_hash.unwrap_or(target_hash))
.map_err(|e| ConsensusError::ChainLookup(e.to_string()).into())
}
}
6 changes: 1 addition & 5 deletions client/finality-grandpa/src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,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");
Expand Down Expand Up @@ -1223,10 +1223,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
Expand Down
4 changes: 2 additions & 2 deletions client/finality-grandpa/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ where
)
.await
} else {
Ok(Some(pending_change.canon_hash))
Ok(pending_change.canon_hash)
};

if let Ok(Some(hash)) = effective_block_hash {
if let Ok(hash) = effective_block_hash {
if let Ok(Some(header)) = self.inner.header(BlockId::Hash(hash)) {
if *header.number() == pending_change.effective_number() {
out.push((header.hash(), *header.number()));
Expand Down
Loading

0 comments on commit 4ecbb1f

Please sign in to comment.