Refactor to use only chain info (#4516)

This commit is contained in:
Nikolay Volf
2020-01-02 14:46:07 +03:00
committed by Bastian Köcher
parent 8ecc450fd9
commit 6d06a19f41
30 changed files with 178 additions and 175 deletions
+5 -5
View File
@@ -17,8 +17,8 @@
//! Blockchain access trait
use sc_client::Client as SubstrateClient;
use sp_blockchain::Error;
use sc_client_api::{ChangesProof, StorageProof, ClientInfo, CallExecutor};
use sp_blockchain::{Error, Info as BlockchainInfo};
use sc_client_api::{ChangesProof, StorageProof, CallExecutor};
use sp_consensus::{BlockImport, BlockStatus, Error as ConsensusError};
use sp_runtime::traits::{Block as BlockT, Header as HeaderT};
use sp_runtime::generic::{BlockId};
@@ -29,7 +29,7 @@ use sp_core::storage::{StorageKey, ChildInfo};
/// Local client abstraction for the network.
pub trait Client<Block: BlockT>: Send + Sync {
/// Get blockchain info.
fn info(&self) -> ClientInfo<Block>;
fn info(&self) -> BlockchainInfo<Block>;
/// Get block status.
fn block_status(&self, id: &BlockId<Block>) -> Result<BlockStatus, Error>;
@@ -99,8 +99,8 @@ impl<B, E, Block, RA> Client<Block> for SubstrateClient<B, E, Block, RA> where
Block: BlockT<Hash=H256>,
RA: Send + Sync
{
fn info(&self) -> ClientInfo<Block> {
(self as &SubstrateClient<B, E, Block, RA>).info()
fn info(&self) -> BlockchainInfo<Block> {
(self as &SubstrateClient<B, E, Block, RA>).chain_info()
}
fn block_status(&self, id: &BlockId<Block>) -> Result<BlockStatus, Error> {
+6 -6
View File
@@ -473,7 +473,7 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
chain,
},
light_dispatch: LightDispatch::new(checker),
genesis_hash: info.chain.genesis_hash,
genesis_hash: info.genesis_hash,
sync,
specialization,
handshaking_peers: HashMap::new(),
@@ -1010,7 +1010,7 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
.context_data
.chain
.info()
.chain.best_number;
.best_number;
let blocks_difference = self_best_block
.checked_sub(&status.best_number)
.unwrap_or_else(Zero::zero)
@@ -1232,7 +1232,7 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
return;
}
let is_best = self.context_data.chain.info().chain.best_hash == hash;
let is_best = self.context_data.chain.info().best_hash == hash;
debug!(target: "sync", "Reannouncing block {:?}", hash);
self.send_announcement(&header, data, is_best, true)
}
@@ -1278,10 +1278,10 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
let status = message::generic::Status {
version: CURRENT_VERSION,
min_supported_version: MIN_VERSION,
genesis_hash: info.chain.genesis_hash,
genesis_hash: info.genesis_hash,
roles: self.config.roles.into(),
best_number: info.chain.best_number,
best_hash: info.chain.best_hash,
best_number: info.best_number,
best_hash: info.best_hash,
chain_status: self.specialization.status(),
};
@@ -28,8 +28,7 @@
//!
use blocks::BlockCollection;
use sc_client_api::ClientInfo;
use sp_blockchain::Error as ClientError;
use sp_blockchain::{Error as ClientError, Info as BlockchainInfo};
use sp_consensus::{BlockOrigin, BlockStatus,
block_validation::{BlockAnnounceValidator, Validation},
import_queue::{IncomingBlock, BlockImportResult, BlockImportError}
@@ -291,7 +290,7 @@ impl<B: BlockT> ChainSync<B> {
pub fn new(
role: Roles,
client: Arc<dyn crate::chain::Client<B>>,
info: &ClientInfo<B>,
info: &BlockchainInfo<B>,
request_builder: Option<BoxFinalityProofRequestBuilder<B>>,
block_announce_validator: Box<dyn BlockAnnounceValidator<B> + Send>,
max_parallel_downloads: u32,
@@ -306,9 +305,9 @@ impl<B: BlockT> ChainSync<B> {
client,
peers: HashMap::new(),
blocks: BlockCollection::new(),
best_queued_hash: info.chain.best_hash,
best_queued_number: info.chain.best_number,
best_imported_number: info.chain.best_number,
best_queued_hash: info.best_hash,
best_queued_number: info.best_number,
best_imported_number: info.best_number,
extra_finality_proofs: ExtraRequests::new(),
extra_justifications: ExtraRequests::new(),
role,
@@ -579,7 +578,7 @@ impl<B: BlockT> ChainSync<B> {
let attrs = &self.required_block_attributes;
let fork_targets = &mut self.fork_targets;
let mut have_requests = false;
let last_finalized = self.client.info().chain.finalized_number;
let last_finalized = self.client.info().finalized_number;
let best_queued = self.best_queued_number;
let client = &self.client;
let queue = &self.queue_blocks;
@@ -1142,8 +1141,8 @@ impl<B: BlockT> ChainSync<B> {
self.queue_blocks.clear();
self.blocks.clear();
let info = self.client.info();
self.best_queued_hash = info.chain.best_hash;
self.best_queued_number = std::cmp::max(info.chain.best_number, self.best_imported_number);
self.best_queued_hash = info.best_hash;
self.best_queued_number = std::cmp::max(info.best_number, self.best_imported_number);
self.is_idle = false;
debug!(target:"sync", "Restarted with {} ({})", self.best_queued_number, self.best_queued_hash);
let old_peers = std::mem::replace(&mut self.peers, HashMap::new());