Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove some substrate dependencies to improve compile time #194

Merged
merged 4 commits into from
Dec 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,10 @@ pallet-indices = { version = "2.0.0", package = "pallet-indices" }
hex = "0.4.2"
sp-std = "2.0.0"
application-crypto = { version = "2.0.0", package = "sp-application-crypto" }
sp-finality-grandpa = "2.0.0"
sp-consensus-babe = "0.8.0"
pallet-im-online = "2.0.0"
sp-authority-discovery = "2.0.0"
pallet-staking = "2.0.0"

sp-rpc = { version = "2.0.0", package = "sp-rpc" }
sp-core = { version = "2.0.0", package = "sp-core" }
sc-rpc-api = { version = "0.8.0", package = "sc-rpc-api" }
sp-transaction-pool = { version = "2.0.0", package = "sp-transaction-pool" }
substrate-subxt-client = { version = "0.5.0", path = "client", optional = true }
substrate-subxt-proc-macro = { version = "0.13.0", path = "proc-macro" }

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ pub use sp_runtime;
use codec::Decode;
use futures::future;
use jsonrpsee::client::Subscription;
use sc_rpc_api::state::ReadProof;
use sp_core::{
storage::{
StorageChangeSet,
Expand Down Expand Up @@ -94,6 +93,7 @@ pub use crate::{
rpc::{
BlockNumber,
ExtrinsicSuccess,
ReadProof,
SystemProperties,
},
runtimes::*,
Expand Down
61 changes: 55 additions & 6 deletions src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ use jsonrpsee::{
},
Client,
};
use sc_rpc_api::state::ReadProof;
use serde::Serialize;
use serde::{
Deserialize,
Serialize,
};
use sp_core::{
storage::{
StorageChangeSet,
Expand All @@ -59,7 +61,6 @@ use sp_runtime::{
},
traits::Hash,
};
use sp_transaction_pool::TransactionStatus;
use sp_version::RuntimeVersion;

use crate::{
Expand Down Expand Up @@ -96,9 +97,9 @@ impl From<u32> for BlockNumber {
}
}

#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq, Default)]
#[serde(rename_all = "camelCase")]
/// System properties for a Substrate-based runtime
#[derive(serde::Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Default)]
#[serde(rename_all = "camelCase")]
pub struct SystemProperties {
/// The address format
pub ss58_format: u8,
Expand All @@ -108,6 +109,54 @@ pub struct SystemProperties {
pub token_symbol: String,
}

/// Possible transaction status events.
///
/// # Note
///
/// This is copied from `sp-transaction-pool` to avoid a dependency on that crate. Therefore it
/// must be kept compatible with that type from the target substrate version.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum TransactionStatus<Hash, BlockHash> {
/// Transaction is part of the future queue.
Future,
/// Transaction is part of the ready queue.
Ready,
/// The transaction has been broadcast to the given peers.
Broadcast(Vec<String>),
/// Transaction has been included in block with given hash.
InBlock(BlockHash),
/// The block this transaction was included in has been retracted.
Retracted(BlockHash),
/// Maximum number of finality watchers has been reached,
/// old watchers are being removed.
FinalityTimeout(BlockHash),
/// Transaction has been finalized by a finality-gadget, e.g GRANDPA
Finalized(BlockHash),
/// Transaction has been replaced in the pool, by another transaction
/// that provides the same tags. (e.g. same (sender, nonce)).
Usurped(Hash),
/// Transaction has been dropped from the pool because of the limit.
Dropped,
/// Transaction is no longer valid in the current state.
Invalid,
}

/// ReadProof struct returned by the RPC
///
/// # Note
///
/// This is copied from `sc-rpc-api` to avoid a dependency on that crate. Therefore it
/// must be kept compatible with that type from the target substrate version.
#[derive(Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ReadProof<Hash> {
/// Block hash used to generate the proof
pub at: Hash,
/// A proof used to prove that storage entries are included in the storage trie
pub proof: Vec<Bytes>,
}

/// Client for substrate rpc interfaces
pub struct Rpc<T: Runtime> {
client: Client,
Expand Down Expand Up @@ -386,7 +435,7 @@ impl<T: Runtime> Rpc<T> {
let mut xt_sub = self.watch_extrinsic(extrinsic).await?;

while let status = xt_sub.next().await {
log::info!("received status {:?}", status);
// log::info!("received status {:?}", status);
match status {
// ignore in progress extrinsic for now
TransactionStatus::Future
Expand Down
63 changes: 47 additions & 16 deletions src/runtimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// along with substrate-subxt. If not, see <http://www.gnu.org/licenses/>.

use codec::Encode;
use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
use sp_runtime::{
generic::Header,
impl_opaque_keys,
Expand All @@ -32,47 +31,79 @@ use sp_std::prelude::*;
/// BABE marker struct
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct Babe;

/// Application specific crypto types
///
/// # Note
///
/// These are redefined here to avoid dependencies on the substrate creates where they are defined.
/// They must be identical to the definitions in the target substrate version.
pub mod app {
use application_crypto::{
app_crypto,
ed25519,
key_types,
sr25519,
};

/// Authority discovery app crypto types
pub mod authority_discovery {
use super::*;
app_crypto!(sr25519, key_types::AUTHORITY_DISCOVERY);
}
/// Babe app crypto types
pub mod babe {
use super::*;
app_crypto!(sr25519, key_types::BABE);
}
/// Im online discovery app crypto types
pub mod im_online {
use super::*;
app_crypto!(ed25519, key_types::IM_ONLINE);
}
/// Grandpa app crypto types
pub mod grandpa {
use super::*;
app_crypto!(ed25519, key_types::GRANDPA);
}
/// Validator app crypto types
pub mod validator {
use super::*;
app_crypto!(ed25519, sp_core::crypto::KeyTypeId(*b"para"));
}
}

impl sp_runtime::BoundToRuntimeAppPublic for Babe {
type Public = sp_consensus_babe::AuthorityId;
type Public = app::babe::Public;
}

/// ImOnline marker struct
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct ImOnline;
impl sp_runtime::BoundToRuntimeAppPublic for ImOnline {
type Public = ImOnlineId;
type Public = app::im_online::Public;
}

/// GRANDPA marker struct
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct Grandpa;
impl sp_runtime::BoundToRuntimeAppPublic for Grandpa {
type Public = sp_finality_grandpa::AuthorityId;
}

use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId;

mod validator_app {
use application_crypto::{
app_crypto,
sr25519,
};
app_crypto!(sr25519, sp_core::crypto::KeyTypeId(*b"para"));
type Public = app::grandpa::Public;
}

/// Parachain marker struct
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct Parachains;

impl sp_runtime::BoundToRuntimeAppPublic for Parachains {
type Public = validator_app::Public;
type Public = app::validator::Public;
}

/// Authority discovery marker struct
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct AuthorityDiscovery;
impl sp_runtime::BoundToRuntimeAppPublic for AuthorityDiscovery {
type Public = AuthorityDiscoveryId;
type Public = app::authority_discovery::Public;
}

impl_opaque_keys! {
Expand Down