Remove client.backend (#2960)

* generalize tree_root to remove client.backend dependency

* replace client.backend.blockchain.header with client.header

* move used_state_cache_size into client info

* Create intermediate Setup State. Fixes #1134

* remove client.backend from finality proof

* update node-template

* move memory backend into test helper mode

* move test helper into client

* starting the big refactor, remove unused functions

* apply_finality

* apply_finality

* replacing more .backend from environment with client directly

* remove .backend from grandpa by using traits

* remove .backend from babe

* remove .backend from tests where it is not needed

* remove .backend from tests

* fixing tests

* fixing tests

* fixing more tests

* fixing tests

* fix all forks test

* fix style

* fixing unnecessary allocation

* remove old test.

* fix service docs

* apply suggestion

* minor clean ups

* turns out the test-helper features actually is being used!

* fixing line length.

* fix line length

* minor cleaning

* Apply suggestions from code review

thanks, @Basti

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

* address grumbles

* simplify finalize block on client

* move block back into inner function

* Apply suggestions from code review

Co-Authored-By: DemiMarie-parity <48690212+DemiMarie-parity@users.noreply.github.com>

* use as.ref instead of match

* Update core/client/src/backend.rs

Co-Authored-By: DemiMarie-parity <48690212+DemiMarie-parity@users.noreply.github.com>
This commit is contained in:
Benjamin Kampmann
2019-08-30 02:20:26 +02:00
committed by GitHub
parent 26202c66f7
commit 0cae7217d8
30 changed files with 626 additions and 571 deletions
+24 -10
View File
@@ -197,9 +197,16 @@ pub fn new_client<E, S, Block, RA>(
genesis_storage: S,
execution_strategies: ExecutionStrategies,
keystore: Option<primitives::traits::BareCryptoStorePtr>,
) -> Result<
client::Client<Backend<Block>,
client::LocalCallExecutor<Backend<Block>, E>, Block, RA>, client::error::Error
) -> Result<(
client::Client<
Backend<Block>,
client::LocalCallExecutor<Backend<Block>, E>,
Block,
RA,
>,
Arc<Backend<Block>>,
),
client::error::Error,
>
where
Block: BlockT<Hash=H256>,
@@ -208,7 +215,10 @@ pub fn new_client<E, S, Block, RA>(
{
let backend = Arc::new(Backend::new(settings, CANONICALIZATION_DELAY)?);
let executor = client::LocalCallExecutor::new(backend.clone(), executor, keystore);
Ok(client::Client::new(backend, executor, genesis_storage, execution_strategies)?)
Ok((
client::Client::new(backend.clone(), executor, genesis_storage, execution_strategies)?,
backend,
))
}
pub(crate) mod columns {
@@ -871,7 +881,9 @@ impl<Block: BlockT<Hash=H256>> Backend<Block> {
// cannot find tree route with empty DB.
if meta.best_hash != Default::default() {
let tree_route = ::client::blockchain::tree_route(
&self.blockchain,
|id| self.blockchain.header(id)?.ok_or_else(
|| client::error::Error::UnknownBlock(format!("{:?}", id))
),
BlockId::Hash(meta.best_hash),
BlockId::Hash(route_to),
)?;
@@ -2018,6 +2030,7 @@ mod tests {
#[test]
fn tree_route_works() {
let backend = Backend::<Block>::new_test(1000, 100);
let blockchain = backend.blockchain();
let block0 = insert_header(&backend, 0, Default::default(), Vec::new(), Default::default());
// fork from genesis: 3 prong.
@@ -2031,7 +2044,7 @@ mod tests {
{
let tree_route = ::client::blockchain::tree_route(
backend.blockchain(),
|id| blockchain.header(id)?.ok_or_else(|| client::error::Error::UnknownBlock(format!("{:?}", id))),
BlockId::Hash(a3),
BlockId::Hash(b2)
).unwrap();
@@ -2043,7 +2056,7 @@ mod tests {
{
let tree_route = ::client::blockchain::tree_route(
backend.blockchain(),
|id| blockchain.header(id)?.ok_or_else(|| client::error::Error::UnknownBlock(format!("{:?}", id))),
BlockId::Hash(a1),
BlockId::Hash(a3),
).unwrap();
@@ -2055,7 +2068,7 @@ mod tests {
{
let tree_route = ::client::blockchain::tree_route(
backend.blockchain(),
|id| blockchain.header(id)?.ok_or_else(|| client::error::Error::UnknownBlock(format!("{:?}", id))),
BlockId::Hash(a3),
BlockId::Hash(a1),
).unwrap();
@@ -2067,7 +2080,7 @@ mod tests {
{
let tree_route = ::client::blockchain::tree_route(
backend.blockchain(),
|id| blockchain.header(id)?.ok_or_else(|| client::error::Error::UnknownBlock(format!("{:?}", id))),
BlockId::Hash(a2),
BlockId::Hash(a2),
).unwrap();
@@ -2081,13 +2094,14 @@ mod tests {
#[test]
fn tree_route_child() {
let backend = Backend::<Block>::new_test(1000, 100);
let blockchain = backend.blockchain();
let block0 = insert_header(&backend, 0, Default::default(), Vec::new(), Default::default());
let block1 = insert_header(&backend, 1, block0, Vec::new(), Default::default());
{
let tree_route = ::client::blockchain::tree_route(
backend.blockchain(),
|id| blockchain.header(id)?.ok_or_else(|| client::error::Error::UnknownBlock(format!("{:?}", id))),
BlockId::Hash(block0),
BlockId::Hash(block1),
).unwrap();
+5 -5
View File
@@ -213,7 +213,7 @@ impl<Block: BlockT> LightStorage<Block> {
let meta = self.meta.read();
if meta.best_hash != Default::default() {
let tree_route = ::client::blockchain::tree_route(
self,
|id| self.header(id)?.ok_or_else(|| client::error::Error::UnknownBlock(format!("{:?}", id))),
BlockId::Hash(meta.best_hash),
BlockId::Hash(route_to),
)?;
@@ -780,7 +780,7 @@ pub(crate) mod tests {
{
let tree_route = ::client::blockchain::tree_route(
&db,
|id| db.header(id)?.ok_or_else(|| client::error::Error::UnknownBlock(format!("{:?}", id))),
BlockId::Hash(a3),
BlockId::Hash(b2)
).unwrap();
@@ -792,7 +792,7 @@ pub(crate) mod tests {
{
let tree_route = ::client::blockchain::tree_route(
&db,
|id| db.header(id)?.ok_or_else(|| client::error::Error::UnknownBlock(format!("{:?}", id))),
BlockId::Hash(a1),
BlockId::Hash(a3),
).unwrap();
@@ -804,7 +804,7 @@ pub(crate) mod tests {
{
let tree_route = ::client::blockchain::tree_route(
&db,
|id| db.header(id)?.ok_or_else(|| client::error::Error::UnknownBlock(format!("{:?}", id))),
BlockId::Hash(a3),
BlockId::Hash(a1),
).unwrap();
@@ -816,7 +816,7 @@ pub(crate) mod tests {
{
let tree_route = ::client::blockchain::tree_route(
&db,
|id| db.header(id)?.ok_or_else(|| client::error::Error::UnknownBlock(format!("{:?}", id))),
BlockId::Hash(a2),
BlockId::Hash(a2),
).unwrap();