mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 02:51:08 +00:00
Refactor sr-api to not depend on client anymore (#4086)
* Refactor sr-api to not depend on client anymore * Fix benches * Apply suggestions from code review Co-Authored-By: Tomasz Drwięga <tomusdrw@users.noreply.github.com> * Apply suggestions from code review
This commit is contained in:
committed by
Benjamin Kampmann
parent
e26d1a0b3e
commit
2ecffa1cd0
@@ -21,6 +21,8 @@ substrate-telemetry = { path = "../../telemetry" }
|
||||
keystore = { package = "substrate-keystore", path = "../../keystore" }
|
||||
srml-babe = { path = "../../../srml/babe" }
|
||||
client = { package = "substrate-client", path = "../../client" }
|
||||
sr-api = { path = "../../sr-api" }
|
||||
block-builder-api = { package = "substrate-block-builder-runtime-api", path = "../../block-builder/runtime-api" }
|
||||
header-metadata = { package = "substrate-header-metadata", path = "../../client/header-metadata" }
|
||||
consensus-common = { package = "substrate-consensus-common", path = "../common" }
|
||||
uncles = { package = "substrate-consensus-uncles", path = "../uncles" }
|
||||
@@ -44,6 +46,7 @@ substrate-executor = { path = "../../executor" }
|
||||
network = { package = "substrate-network", path = "../../network", features = ["test-helpers"]}
|
||||
service = { package = "substrate-service", path = "../../service" }
|
||||
test-client = { package = "substrate-test-runtime-client", path = "../../test-runtime/client" }
|
||||
block-builder = { package = "substrate-block-builder", path = "../../block-builder" }
|
||||
tokio = "0.1.22"
|
||||
env_logger = "0.7.0"
|
||||
tempfile = "3.1.0"
|
||||
|
||||
@@ -6,7 +6,7 @@ description = "Primitives for BABE consensus"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
substrate-client = { path = "../../../client", default-features = false }
|
||||
sr-api = { path = "../../../sr-api", default-features = false }
|
||||
rstd = { package = "sr-std", path = "../../../sr-std", default-features = false }
|
||||
sr-primitives = { path = "../../../sr-primitives", default-features = false }
|
||||
app-crypto = { package = "substrate-application-crypto", path = "../../../application-crypto", default-features = false }
|
||||
@@ -19,7 +19,7 @@ default = ["std"]
|
||||
std = [
|
||||
"rstd/std",
|
||||
"sr-primitives/std",
|
||||
"substrate-client/std",
|
||||
"sr-api/std",
|
||||
"codec/std",
|
||||
"schnorrkel",
|
||||
"slots",
|
||||
|
||||
@@ -24,7 +24,6 @@ mod digest;
|
||||
use codec::{Encode, Decode};
|
||||
use rstd::vec::Vec;
|
||||
use sr_primitives::{ConsensusEngineId, RuntimeDebug};
|
||||
use substrate_client::decl_runtime_apis;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub use digest::{BabePreDigest, CompatibleDigestItem};
|
||||
@@ -165,7 +164,7 @@ impl slots::SlotData for BabeConfiguration {
|
||||
const SLOT_KEY: &'static [u8] = b"babe_configuration";
|
||||
}
|
||||
|
||||
decl_runtime_apis! {
|
||||
sr_api::decl_runtime_apis! {
|
||||
/// API necessary for block authorship with BABE.
|
||||
pub trait BabeApi {
|
||||
/// Return the configuration for BABE. Currently,
|
||||
|
||||
@@ -66,7 +66,7 @@ use consensus_common::ImportResult;
|
||||
use consensus_common::import_queue::{
|
||||
BoxJustificationImport, BoxFinalityProofImport,
|
||||
};
|
||||
use sr_primitives::{generic::{BlockId, OpaqueDigestItemId}, Justification, RuntimeString};
|
||||
use sr_primitives::{generic::{BlockId, OpaqueDigestItemId}, Justification};
|
||||
use sr_primitives::traits::{
|
||||
Block as BlockT, Header, DigestItemFor, ProvideRuntimeApi,
|
||||
Zero,
|
||||
@@ -75,11 +75,7 @@ use keystore::KeyStorePtr;
|
||||
use parking_lot::Mutex;
|
||||
use primitives::{Blake2Hasher, H256, Pair};
|
||||
use inherents::{InherentDataProviders, InherentData};
|
||||
use substrate_telemetry::{
|
||||
telemetry,
|
||||
CONSENSUS_TRACE,
|
||||
CONSENSUS_DEBUG,
|
||||
};
|
||||
use substrate_telemetry::{telemetry, CONSENSUS_TRACE, CONSENSUS_DEBUG};
|
||||
use consensus_common::{
|
||||
self, BlockImport, Environment, Proposer, BlockCheckParams,
|
||||
ForkChoiceStrategy, BlockImportParams, BlockOrigin, Error as ConsensusError,
|
||||
@@ -91,11 +87,13 @@ use srml_babe::{
|
||||
use consensus_common::SelectChain;
|
||||
use consensus_common::import_queue::{Verifier, BasicQueue, CacheKeyId};
|
||||
use client::{
|
||||
block_builder::api::BlockBuilder as BlockBuilderApi,
|
||||
blockchain::{self, HeaderBackend, ProvideCache}, BlockchainEvents, CallExecutor, Client,
|
||||
error::Result as ClientResult, error::Error as ClientError, backend::{AuxStore, Backend},
|
||||
ProvideUncles,
|
||||
};
|
||||
|
||||
use block_builder_api::BlockBuilder as BlockBuilderApi;
|
||||
|
||||
use slots::{CheckedHeader, check_equivocation};
|
||||
use futures::prelude::*;
|
||||
use log::{warn, debug, info, trace};
|
||||
@@ -104,6 +102,8 @@ use epoch_changes::descendent_query;
|
||||
use header_metadata::HeaderMetadata;
|
||||
use schnorrkel::SignatureError;
|
||||
|
||||
use sr_api::ApiExt;
|
||||
|
||||
mod aux_schema;
|
||||
mod verification;
|
||||
mod epoch_changes;
|
||||
@@ -167,7 +167,7 @@ enum Error<B: BlockT> {
|
||||
#[display(fmt = "Checking inherents failed: {}", _0)]
|
||||
CheckInherents(String),
|
||||
Client(client::error::Error),
|
||||
Runtime(RuntimeString),
|
||||
Runtime(inherents::Error),
|
||||
ForkTree(Box<fork_tree::Error<client::error::Error>>),
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ impl Config {
|
||||
/// Either fetch the slot duration from disk or compute it from the genesis
|
||||
/// state.
|
||||
pub fn get_or_compute<B: BlockT, C>(client: &C) -> ClientResult<Self> where
|
||||
C: AuxStore + ProvideRuntimeApi, C::Api: BabeApi<B>,
|
||||
C: AuxStore + ProvideRuntimeApi, C::Api: BabeApi<B, Error = client::error::Error>,
|
||||
{
|
||||
trace!(target: "babe", "Getting slot duration");
|
||||
match slots::SlotDuration::get_or_compute(client, |a, b| a.configuration(b)).map(Self) {
|
||||
@@ -554,7 +554,7 @@ impl<B, E, Block: BlockT, RA, PRA> BabeVerifier<B, E, Block, RA, PRA> {
|
||||
block_id: BlockId<Block>,
|
||||
inherent_data: InherentData,
|
||||
) -> Result<(), Error<Block>>
|
||||
where PRA: ProvideRuntimeApi, PRA::Api: BlockBuilderApi<Block>
|
||||
where PRA: ProvideRuntimeApi, PRA::Api: BlockBuilderApi<Block, Error = client::error::Error>
|
||||
{
|
||||
let inherent_res = self.api.runtime_api().check_inherents(
|
||||
&block_id,
|
||||
@@ -623,7 +623,8 @@ impl<B, E, Block, RA, PRA> Verifier<Block> for BabeVerifier<B, E, Block, RA, PRA
|
||||
E: CallExecutor<Block, Blake2Hasher> + 'static + Clone + Send + Sync,
|
||||
RA: Send + Sync,
|
||||
PRA: ProvideRuntimeApi + Send + Sync + AuxStore + ProvideCache<Block>,
|
||||
PRA::Api: BlockBuilderApi<Block> + BabeApi<Block>,
|
||||
PRA::Api: BlockBuilderApi<Block, Error = client::error::Error>
|
||||
+ BabeApi<Block, Error = client::error::Error>,
|
||||
{
|
||||
fn verify(
|
||||
&mut self,
|
||||
@@ -1141,7 +1142,7 @@ pub fn import_queue<B, E, Block: BlockT<Hash=H256>, I, RA, PRA>(
|
||||
E: CallExecutor<Block, Blake2Hasher> + Clone + Send + Sync + 'static,
|
||||
RA: Send + Sync + 'static,
|
||||
PRA: ProvideRuntimeApi + ProvideCache<Block> + Send + Sync + AuxStore + 'static,
|
||||
PRA::Api: BlockBuilderApi<Block> + BabeApi<Block>,
|
||||
PRA::Api: BlockBuilderApi<Block> + BabeApi<Block> + ApiExt<Block, Error = client::error::Error>,
|
||||
{
|
||||
register_babe_inherent_data_provider(&inherent_data_providers, babe_link.config.slot_duration)?;
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ use super::*;
|
||||
use authorship::claim_slot;
|
||||
|
||||
use babe_primitives::{AuthorityPair, SlotNumber};
|
||||
use client::block_builder::BlockBuilder;
|
||||
use block_builder::BlockBuilder;
|
||||
use consensus_common::NoNetwork as DummyOracle;
|
||||
use consensus_common::import_queue::{
|
||||
BoxBlockImport, BoxJustificationImport, BoxFinalityProofImport,
|
||||
|
||||
Reference in New Issue
Block a user