Skip to content

Commit

Permalink
Feature/pool (paritytech#27)
Browse files Browse the repository at this point in the history
* Add function 'verify_transaction'

* Add the transaction status function

* Add function 'verify_transaction'

* Add the transaction status function

* Add function 'verify_transaction'

* Add the transaction status function

* Add function 'verify_transaction'

* Adjust the format
  • Loading branch information
eee-byte authored and gguoss committed Sep 14, 2018
1 parent fecf128 commit fd6a5df
Show file tree
Hide file tree
Showing 11 changed files with 342 additions and 153 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 15 additions & 13 deletions consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,28 @@ mod evaluation;
mod service;
mod error;

use chainx_primitives::{CandidateReceipt, BlockId, Hash, Block, Header, AccountId, BlockNumber, Timestamp, SessionKey};
use dynamic_inclusion::DynamicInclusion;
use tokio::timer::{Delay, Interval};
use std::time::{Duration, Instant};
use tokio::runtime::TaskExecutor;
use codec::{Decode, Encode};
use primitives::AuthorityId;
use chainx_api::ChainXApi;
use parking_lot::RwLock;
use futures::prelude::*;
use futures::future;
use std::sync::Arc;

use codec::{Decode, Encode};
use primitives::AuthorityId;

use chainx_primitives::{CandidateReceipt, BlockId, Hash, Block, Header, AccountId, BlockNumber, Timestamp, SessionKey};
use chainx_api::ChainXApi;

type TransactionPool<A> = substrate_extrinsic_pool::Pool<chainx_pool::PoolApi<A>>;
pub use self::offline_tracker::OfflineTracker;
use dynamic_inclusion::DynamicInclusion;
pub use self::error::{ErrorKind, Error};
pub use service::Service;

pub type TransactionPool = substrate_extrinsic_pool::Pool<chainx_pool::PoolApi>;
/// Shared offline validator tracker.
pub type SharedOfflineTracker = Arc<RwLock<OfflineTracker>>;


// block size limit.
const MAX_TRANSACTIONS_SIZE: usize = 4 * 1024 * 1024;

Expand Down Expand Up @@ -83,7 +82,7 @@ where
/// The client instance.
pub client: Arc<P>,
/// transaction pool,
pub transaction_pool: Arc<TransactionPool>,
pub transaction_pool: Arc<TransactionPool<P>>,
/// The backing network handle.
pub network: N,
/// handle to remote task executor
Expand Down Expand Up @@ -146,15 +145,17 @@ where
}

/// The ChainX proposer logic.
pub struct Proposer<C: ChainXApi + Send + Sync> {
pub struct Proposer<C: ChainXApi + Send + Sync> where
C: ChainXApi + Send + Sync,
{
client: Arc<C>,
dynamic_inclusion: DynamicInclusion,
local_key: Arc<ed25519::Pair>,
parent_hash: Hash,
parent_id: BlockId,
parent_number: BlockNumber,
random_seed: Hash,
transaction_pool: Arc<TransactionPool>,
transaction_pool: Arc<TransactionPool<C>>,
offline: SharedOfflineTracker,
validators: Vec<AccountId>,
}
Expand Down Expand Up @@ -384,12 +385,13 @@ impl ProposalTiming {
}

/// Future which resolves upon the creation of a proposal.
pub struct CreateProposal<C: ChainXApi + Send + Sync> {
pub struct CreateProposal<C: ChainXApi + Send + Sync> where
{
parent_hash: Hash,
parent_number: BlockNumber,
parent_id: BlockId,
client: Arc<C>,
transaction_pool: Arc<TransactionPool>,
transaction_pool: Arc<TransactionPool<C>>,
timing: ProposalTiming,
validators: Vec<AccountId>,
offline: SharedOfflineTracker,
Expand Down
2 changes: 1 addition & 1 deletion consensus/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl Service {
client: Arc<C>,
api: Arc<A>,
network: N,
transaction_pool: Arc<TransactionPool>,
transaction_pool: Arc<TransactionPool<A>>,
thread_pool: ThreadPoolHandle,
key: ed25519::Pair,
) -> Service
Expand Down
3 changes: 3 additions & 0 deletions pool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ substrate-client-db = { git = "https://github.com/chainx-org/substrate" }
chainx-primitives = { path = "../primitives" }
chainx-runtime = { path = "../runtime" }
chainx-executor = {path = "../executor"}
chainx-api = { path = "../api" }
triehash = { version = "0.2.3" }
error-chain = "0.12"
hex-literal = "0.1"
log = "0.3"

[dev-dependencies]
substrate-keyring = { git = "https://github.com/chainx-org/substrate" }
substrate-runtime-primitives = { git = "https://github.com/chainx-org/substrate" }
Expand Down
58 changes: 58 additions & 0 deletions pool/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
use chainx_runtime::{Address, UncheckedExtrinsic};
use chainx_primitives::Hash;
use extrinsic_pool;
use chainx_api;


error_chain! {
links {
Pool(extrinsic_pool::Error, extrinsic_pool::ErrorKind);
Api(chainx_api::Error, chainx_api::ErrorKind);
}
errors {
/// Unexpected extrinsic format submitted
InvalidExtrinsicFormat {
description("Invalid extrinsic format."),
display("Invalid extrinsic format."),
}
/// Attempted to queue an inherent transaction.
IsInherent(xt: UncheckedExtrinsic) {
description("Inherent transactions cannot be queued."),
display("Inherent transactions cannot be queued."),
}
/// Attempted to queue a transaction with bad signature.
BadSignature(e: &'static str) {
description("Transaction had bad signature."),
display("Transaction had bad signature: {}", e),
}
/// Attempted to queue a transaction that is already in the pool.
AlreadyImported(hash: Hash) {
description("Transaction is already in the pool."),
display("Transaction {:?} is already in the pool.", hash),
}
/// Import error.
Import(err: Box<::std::error::Error + Send>) {
description("Error importing transaction"),
display("Error importing transaction: {}", err.description()),
}
/// Runtime failure.
UnrecognisedAddress(who: Address) {
description("Unrecognised address in extrinsic"),
display("Unrecognised address in extrinsic: {}", who),
}
/// Extrinsic too large
TooLarge(got: usize, max: usize) {
description("Extrinsic too large"),
display("Extrinsic is too large ({} > {})", got, max),
}
}
}

impl extrinsic_pool::IntoPoolError for Error {
fn into_pool_error(self) -> ::std::result::Result<extrinsic_pool::Error, Self> {
match self {
Error(ErrorKind::Pool(e), c) => Ok(extrinsic_pool::Error(e, c)),
e => Err(e),
}
}
}
20 changes: 14 additions & 6 deletions pool/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
// Copyright 2018 Chainpool.

extern crate substrate_codec as codec;
extern crate substrate_runtime_primitives as runtime_primitives;
extern crate substrate_primitives as substrate_primitives;
extern crate substrate_extrinsic_pool as extrinsic_pool;
extern crate substrate_codec as codec;
extern crate substrate_client_db;
extern crate chainx_primitives;
extern crate chainx_runtime;
extern crate substrate_network;
extern crate chainx_executor;
extern crate substrate_executor;
extern crate substrate_extrinsic_pool as extrinsic_pool;
extern crate substrate_network;
extern crate substrate_client;
extern crate chainx_primitives;
extern crate chainx_executor;
extern crate chainx_runtime;
extern crate chainx_api;
extern crate ed25519;

#[macro_use]
extern crate error_chain;
#[macro_use]
extern crate log;

mod pool;
mod error;

pub use pool::TransactionPool;
pub use pool::PoolApi;

Loading

0 comments on commit fd6a5df

Please sign in to comment.