mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 18:07:58 +00:00
Move client consensus parts out of primitives and into client/consensus/api (#9319)
* moved client code out of primitives * bump ci * Fixup from merge. * Removed unused deps thanks to review feedback * Removing unneeded deps * updating lock file * note about rustfmt * fixed typo to bump ci * Move lonely CacheKeyId to parent * cargo fmt * updating import style * Update docs/STYLE_GUIDE.md Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com> Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>
This commit is contained in:
@@ -36,10 +36,8 @@ use libp2p::{
|
||||
};
|
||||
use log::debug;
|
||||
use prost::Message;
|
||||
use sp_consensus::{
|
||||
import_queue::{IncomingBlock, Origin},
|
||||
BlockOrigin,
|
||||
};
|
||||
use sc_consensus::import_queue::{IncomingBlock, Origin};
|
||||
use sp_consensus::BlockOrigin;
|
||||
use sp_runtime::{
|
||||
traits::{Block as BlockT, NumberFor},
|
||||
Justifications,
|
||||
|
||||
@@ -19,7 +19,8 @@
|
||||
//! Blockchain access trait
|
||||
|
||||
use sc_client_api::{BlockBackend, ProofProvider};
|
||||
pub use sc_client_api::{ImportedState, StorageData, StorageKey};
|
||||
pub use sc_client_api::{StorageData, StorageKey};
|
||||
pub use sc_consensus::ImportedState;
|
||||
use sp_blockchain::{Error, HeaderBackend, HeaderMetadata};
|
||||
use sp_runtime::traits::{Block as BlockT, BlockIdTo};
|
||||
|
||||
|
||||
@@ -44,7 +44,8 @@ use libp2p::{
|
||||
multiaddr, wasm_ext, Multiaddr, PeerId,
|
||||
};
|
||||
use prometheus_endpoint::Registry;
|
||||
use sp_consensus::{block_validation::BlockAnnounceValidator, import_queue::ImportQueue};
|
||||
use sc_consensus::ImportQueue;
|
||||
use sp_consensus::block_validation::BlockAnnounceValidator;
|
||||
use sp_runtime::traits::Block as BlockT;
|
||||
use std::{
|
||||
borrow::Cow,
|
||||
|
||||
@@ -50,7 +50,7 @@ fn build_test_full_node(network_config: config::NetworkConfiguration)
|
||||
struct PassThroughVerifier(bool);
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl<B: BlockT> sp_consensus::import_queue::Verifier<B> for PassThroughVerifier {
|
||||
impl<B: BlockT> sc_consensus::Verifier<B> for PassThroughVerifier {
|
||||
async fn verify(
|
||||
&mut self,
|
||||
origin: sp_consensus::BlockOrigin,
|
||||
@@ -59,7 +59,7 @@ fn build_test_full_node(network_config: config::NetworkConfiguration)
|
||||
body: Option<Vec<B::Extrinsic>>,
|
||||
) -> Result<
|
||||
(
|
||||
sp_consensus::BlockImportParams<B, ()>,
|
||||
sc_consensus::BlockImportParams<B, ()>,
|
||||
Option<Vec<(sp_blockchain::well_known_cache_keys::Id, Vec<u8>)>>,
|
||||
),
|
||||
String,
|
||||
@@ -79,16 +79,16 @@ fn build_test_full_node(network_config: config::NetworkConfiguration)
|
||||
)]
|
||||
});
|
||||
|
||||
let mut import = sp_consensus::BlockImportParams::new(origin, header);
|
||||
let mut import = sc_consensus::BlockImportParams::new(origin, header);
|
||||
import.body = body;
|
||||
import.finalized = self.0;
|
||||
import.justifications = justifications;
|
||||
import.fork_choice = Some(sp_consensus::ForkChoiceStrategy::LongestChain);
|
||||
import.fork_choice = Some(sc_consensus::ForkChoiceStrategy::LongestChain);
|
||||
Ok((import, maybe_keys))
|
||||
}
|
||||
}
|
||||
|
||||
let import_queue = Box::new(sp_consensus::import_queue::BasicQueue::new(
|
||||
let import_queue = Box::new(sc_consensus::BasicQueue::new(
|
||||
PassThroughVerifier(false),
|
||||
Box::new(client.clone()),
|
||||
None,
|
||||
|
||||
@@ -48,12 +48,9 @@ use message::{
|
||||
use notifications::{Notifications, NotificationsOut};
|
||||
use prometheus_endpoint::{register, Gauge, GaugeVec, Opts, PrometheusError, Registry, U64};
|
||||
use prost::Message as _;
|
||||
use sc_consensus::import_queue::{BlockImportError, BlockImportStatus, IncomingBlock, Origin};
|
||||
use sp_arithmetic::traits::SaturatedConversion;
|
||||
use sp_consensus::{
|
||||
block_validation::BlockAnnounceValidator,
|
||||
import_queue::{BlockImportError, BlockImportResult, IncomingBlock, Origin},
|
||||
BlockOrigin,
|
||||
};
|
||||
use sp_consensus::{block_validation::BlockAnnounceValidator, BlockOrigin};
|
||||
use sp_runtime::{
|
||||
generic::BlockId,
|
||||
traits::{Block as BlockT, CheckedSub, Header as HeaderT, NumberFor, Zero},
|
||||
@@ -1048,7 +1045,7 @@ impl<B: BlockT> Protocol<B> {
|
||||
&mut self,
|
||||
imported: usize,
|
||||
count: usize,
|
||||
results: Vec<(Result<BlockImportResult<NumberFor<B>>, BlockImportError>, B::Hash)>,
|
||||
results: Vec<(Result<BlockImportStatus<NumberFor<B>>, BlockImportError>, B::Hash)>,
|
||||
) {
|
||||
let results = self.sync.on_blocks_processed(imported, count, results);
|
||||
for result in results {
|
||||
|
||||
@@ -39,11 +39,11 @@ use extra_requests::ExtraRequests;
|
||||
use futures::{stream::FuturesUnordered, task::Poll, Future, FutureExt, StreamExt};
|
||||
use libp2p::PeerId;
|
||||
use log::{debug, error, info, trace, warn};
|
||||
use sc_consensus::{BlockImportError, BlockImportStatus, IncomingBlock};
|
||||
use sp_arithmetic::traits::Saturating;
|
||||
use sp_blockchain::{Error as ClientError, HeaderMetadata};
|
||||
use sp_consensus::{
|
||||
block_validation::{BlockAnnounceValidator, Validation},
|
||||
import_queue::{BlockImportError, BlockImportResult, IncomingBlock},
|
||||
BlockOrigin, BlockStatus,
|
||||
};
|
||||
use sp_runtime::{
|
||||
@@ -1240,7 +1240,7 @@ impl<B: BlockT> ChainSync<B> {
|
||||
&'a mut self,
|
||||
imported: usize,
|
||||
count: usize,
|
||||
results: Vec<(Result<BlockImportResult<NumberFor<B>>, BlockImportError>, B::Hash)>,
|
||||
results: Vec<(Result<BlockImportStatus<NumberFor<B>>, BlockImportError>, B::Hash)>,
|
||||
) -> impl Iterator<Item = Result<(PeerId, BlockRequest<B>), BadPeer>> + 'a {
|
||||
trace!(target: "sync", "Imported {} of {}", imported, count);
|
||||
|
||||
@@ -1260,12 +1260,12 @@ impl<B: BlockT> ChainSync<B> {
|
||||
}
|
||||
|
||||
match result {
|
||||
Ok(BlockImportResult::ImportedKnown(number, who)) => {
|
||||
Ok(BlockImportStatus::ImportedKnown(number, who)) => {
|
||||
if let Some(peer) = who.and_then(|p| self.peers.get_mut(&p)) {
|
||||
peer.update_common_number(number);
|
||||
}
|
||||
},
|
||||
Ok(BlockImportResult::ImportedUnknown(number, aux, who)) => {
|
||||
Ok(BlockImportStatus::ImportedUnknown(number, aux, who)) => {
|
||||
if aux.clear_justification_requests {
|
||||
trace!(
|
||||
target: "sync",
|
||||
@@ -2454,7 +2454,7 @@ mod test {
|
||||
///
|
||||
/// The node is connected to multiple peers. Both of these peers are having a best block (1) that
|
||||
/// is below our best block (3). Now peer 2 announces a fork of block 3 that we will
|
||||
/// request from peer 2. After imporitng the fork, peer 2 and then peer 1 will announce block 4.
|
||||
/// request from peer 2. After importing the fork, peer 2 and then peer 1 will announce block 4.
|
||||
/// But as peer 1 in our view is still at block 1, we will request block 2 (which we already have)
|
||||
/// from it. In the meanwhile peer 2 sends us block 4 and 3 and we send another request for block
|
||||
/// 2 to peer 2. Peer 1 answers with block 2 and then peer 2. This will need to succeed, as we
|
||||
@@ -2777,7 +2777,7 @@ mod test {
|
||||
.rev()
|
||||
.map(|b| {
|
||||
(
|
||||
Ok(BlockImportResult::ImportedUnknown(
|
||||
Ok(BlockImportStatus::ImportedUnknown(
|
||||
b.header().number().clone(),
|
||||
Default::default(),
|
||||
Some(peer_id1.clone()),
|
||||
|
||||
@@ -68,8 +68,8 @@ use libp2p::{
|
||||
use log::{debug, error, info, trace, warn};
|
||||
use metrics::{Histogram, HistogramVec, MetricSources, Metrics};
|
||||
use parking_lot::Mutex;
|
||||
use sc_consensus::{BlockImportError, BlockImportStatus, ImportQueue, Link};
|
||||
use sc_peerset::PeersetHandle;
|
||||
use sp_consensus::import_queue::{BlockImportError, BlockImportResult, ImportQueue, Link};
|
||||
use sp_runtime::traits::{Block as BlockT, NumberFor};
|
||||
use sp_utils::mpsc::{tracing_unbounded, TracingUnboundedReceiver, TracingUnboundedSender};
|
||||
use std::{
|
||||
@@ -1265,7 +1265,7 @@ impl<'a, B: BlockT + 'static, H: ExHashT> sp_consensus::SyncOracle for &'a Netwo
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: BlockT, H: ExHashT> sp_consensus::JustificationSyncLink<B> for NetworkService<B, H> {
|
||||
impl<B: BlockT, H: ExHashT> sc_consensus::JustificationSyncLink<B> for NetworkService<B, H> {
|
||||
fn request_justification(&self, hash: &B::Hash, number: NumberFor<B>) {
|
||||
NetworkService::request_justification(self, hash, number);
|
||||
}
|
||||
@@ -2104,7 +2104,7 @@ impl<'a, B: BlockT> Link<B> for NetworkLink<'a, B> {
|
||||
&mut self,
|
||||
imported: usize,
|
||||
count: usize,
|
||||
results: Vec<(Result<BlockImportResult<NumberFor<B>>, BlockImportError>, B::Hash)>,
|
||||
results: Vec<(Result<BlockImportStatus<NumberFor<B>>, BlockImportError>, B::Hash)>,
|
||||
) {
|
||||
self.protocol
|
||||
.behaviour_mut()
|
||||
|
||||
@@ -47,7 +47,7 @@ fn build_test_full_node(
|
||||
struct PassThroughVerifier(bool);
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl<B: BlockT> sp_consensus::import_queue::Verifier<B> for PassThroughVerifier {
|
||||
impl<B: BlockT> sc_consensus::Verifier<B> for PassThroughVerifier {
|
||||
async fn verify(
|
||||
&mut self,
|
||||
origin: sp_consensus::BlockOrigin,
|
||||
@@ -56,7 +56,7 @@ fn build_test_full_node(
|
||||
body: Option<Vec<B::Extrinsic>>,
|
||||
) -> Result<
|
||||
(
|
||||
sp_consensus::BlockImportParams<B, ()>,
|
||||
sc_consensus::BlockImportParams<B, ()>,
|
||||
Option<Vec<(sp_blockchain::well_known_cache_keys::Id, Vec<u8>)>>,
|
||||
),
|
||||
String,
|
||||
@@ -75,16 +75,16 @@ fn build_test_full_node(
|
||||
vec![(sp_blockchain::well_known_cache_keys::AUTHORITIES, blob.to_vec())]
|
||||
});
|
||||
|
||||
let mut import = sp_consensus::BlockImportParams::new(origin, header);
|
||||
let mut import = sc_consensus::BlockImportParams::new(origin, header);
|
||||
import.body = body;
|
||||
import.finalized = self.0;
|
||||
import.justifications = justifications;
|
||||
import.fork_choice = Some(sp_consensus::ForkChoiceStrategy::LongestChain);
|
||||
import.fork_choice = Some(sc_consensus::ForkChoiceStrategy::LongestChain);
|
||||
Ok((import, maybe_keys))
|
||||
}
|
||||
}
|
||||
|
||||
let import_queue = Box::new(sp_consensus::import_queue::BasicQueue::new(
|
||||
let import_queue = Box::new(sc_consensus::BasicQueue::new(
|
||||
PassThroughVerifier(false),
|
||||
Box::new(client.clone()),
|
||||
None,
|
||||
|
||||
Reference in New Issue
Block a user