Optimize tree route to sync faster (#3665)

* Introduce HeaderMetadata and use it for tree_route. Add lowest_common_ancestor.
* Add tests.
This commit is contained in:
Marcio Diaz
2019-10-02 20:30:43 +02:00
committed by GitHub
parent 8646cd158e
commit f6bd58ac1f
22 changed files with 677 additions and 280 deletions
+2 -8
View File
@@ -153,14 +153,8 @@ impl<B, E, Block, RA> Client<Block> for SubstrateClient<B, E, Block, RA> where
return Ok(false);
}
let tree_route = ::client::blockchain::tree_route(
|id| self.header(&id)?.ok_or_else(||
client::error::Error::UnknownBlock(format!("{:?}", id))
),
BlockId::Hash(*block),
BlockId::Hash(*base),
)?;
let ancestor = header_metadata::lowest_common_ancestor(self, *block, *base)?;
Ok(tree_route.common_block().hash == *base)
Ok(ancestor.hash == *base)
}
}