// This file is part of Substrate.
// Copyright (C) 2017-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
//! Light client blockchain backend. Only stores headers and justifications of recent
//! blocks. CHT roots are stored for headers of ancient blocks.
use std::sync::Arc;
use sp_runtime::{Justifications, generic::BlockId};
use sp_runtime::traits::{Block as BlockT, Header as HeaderT, NumberFor, Zero};
use sp_blockchain::{
HeaderMetadata, CachedHeaderMetadata, Error as ClientError, Result as ClientResult,
};
pub use sc_client_api::{
backend::{
AuxStore, NewBlockState, ProvideChtRoots,
},
blockchain::{
Backend as BlockchainBackend, BlockStatus, Cache as BlockchainCache,
HeaderBackend as BlockchainHeaderBackend, Info as BlockchainInfo, ProvideCache,
well_known_cache_keys,
},
light::{
RemoteBlockchain, LocalOrRemote, Storage
},
cht,
};
use crate::fetcher::RemoteHeaderRequest;
/// Light client blockchain.
pub struct Blockchain {
storage: S,
}
impl Blockchain {
/// Create new light blockchain backed with given storage.
pub fn new(storage: S) -> Self {
Self {
storage,
}
}
/// Get storage reference.
pub fn storage(&self) -> &S {
&self.storage
}
}
impl BlockchainHeaderBackend for Blockchain where Block: BlockT, S: Storage {
fn header(&self, id: BlockId) -> ClientResult