Companion for Substrate#9867 (#3938)

* Companion for Substrate#9867

* Fix finality_target_with_fallback()

* update substrate

Co-authored-by: André Silva <andrerfosilva@gmail.com>
This commit is contained in:
Liu-Cheng Xu
2021-09-29 22:16:50 +08:00
committed by GitHub
parent c752b5d61b
commit f9de0040c9
2 changed files with 174 additions and 173 deletions
+161 -161
View File
File diff suppressed because it is too large Load Diff
@@ -173,7 +173,7 @@ where
&self, &self,
target_hash: Hash, target_hash: Hash,
maybe_max_number: Option<BlockNumber>, maybe_max_number: Option<BlockNumber>,
) -> Result<Option<Hash>, ConsensusError> { ) -> Result<Hash, ConsensusError> {
let longest_chain_best = let longest_chain_best =
self.longest_chain.finality_target(target_hash, maybe_max_number).await?; self.longest_chain.finality_target(target_hash, maybe_max_number).await?;
@@ -316,9 +316,9 @@ where
pub(crate) async fn finality_target_with_longest_chain( pub(crate) async fn finality_target_with_longest_chain(
&self, &self,
target_hash: Hash, target_hash: Hash,
best_leaf: Option<Hash>, best_leaf: Hash,
maybe_max_number: Option<BlockNumber>, maybe_max_number: Option<BlockNumber>,
) -> Result<Option<Hash>, ConsensusError> { ) -> Result<Hash, ConsensusError> {
let mut overseer = self.overseer.clone(); let mut overseer = self.overseer.clone();
let subchain_head = if cfg!(feature = "disputes") { let subchain_head = if cfg!(feature = "disputes") {
@@ -337,13 +337,14 @@ where
match best { match best {
// No viable leaves containing the block. // No viable leaves containing the block.
None => return Ok(Some(target_hash)), None => return Ok(target_hash),
Some(best) => best, Some(best) => best,
} }
} else { } else {
match best_leaf { if best_leaf == target_hash {
None => return Ok(Some(target_hash)), return Ok(target_hash)
Some(best_leaf) => best_leaf, } else {
best_leaf
} }
}; };
@@ -362,7 +363,7 @@ where
"`finality_target` max number is less than target number", "`finality_target` max number is less than target number",
); );
} }
return Ok(Some(target_hash)) return Ok(target_hash)
} }
// find the current number. // find the current number.
let subchain_header = self.block_header(subchain_head)?; let subchain_header = self.block_header(subchain_head)?;
@@ -423,7 +424,7 @@ where
subchain_number, subchain_number,
"Mismatch of anticipated block descriptions and block number difference.", "Mismatch of anticipated block descriptions and block number difference.",
); );
return Ok(Some(target_hash)) return Ok(target_hash)
} }
// 3. Constrain according to disputes: // 3. Constrain according to disputes:
let (tx, rx) = oneshot::channel(); let (tx, rx) = oneshot::channel();
@@ -458,7 +459,7 @@ where
if safe_target <= target_number { if safe_target <= target_number {
// Minimal vote needs to be on the target number. // Minimal vote needs to be on the target number.
Ok(Some(target_hash)) Ok(target_hash)
} else { } else {
// Otherwise we're looking for a descendant. // Otherwise we're looking for a descendant.
let initial_leaf_header = self.block_header(initial_leaf)?; let initial_leaf_header = self.block_header(initial_leaf)?;
@@ -469,10 +470,10 @@ where
) )
.map_err(|e| ConsensusError::ChainLookup(format!("{:?}", e)))?; .map_err(|e| ConsensusError::ChainLookup(format!("{:?}", e)))?;
Ok(Some(forced_target)) Ok(forced_target)
} }
} else { } else {
Ok(Some(subchain_head)) Ok(subchain_head)
} }
} }
} }