Skip to content

Commit fd6a5df

Browse files
eee-bytegguoss
authored andcommitted
Feature/pool (paritytech#27)
* 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
1 parent fecf128 commit fd6a5df

File tree

11 files changed

+342
-153
lines changed

11 files changed

+342
-153
lines changed

Cargo.lock

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

consensus/src/lib.rs

+15-13
Original file line numberDiff line numberDiff line change
@@ -32,29 +32,28 @@ mod evaluation;
3232
mod service;
3333
mod error;
3434

35+
use chainx_primitives::{CandidateReceipt, BlockId, Hash, Block, Header, AccountId, BlockNumber, Timestamp, SessionKey};
36+
use dynamic_inclusion::DynamicInclusion;
3537
use tokio::timer::{Delay, Interval};
3638
use std::time::{Duration, Instant};
3739
use tokio::runtime::TaskExecutor;
40+
use codec::{Decode, Encode};
41+
use primitives::AuthorityId;
42+
use chainx_api::ChainXApi;
3843
use parking_lot::RwLock;
3944
use futures::prelude::*;
4045
use futures::future;
4146
use std::sync::Arc;
4247

43-
use codec::{Decode, Encode};
44-
use primitives::AuthorityId;
45-
46-
use chainx_primitives::{CandidateReceipt, BlockId, Hash, Block, Header, AccountId, BlockNumber, Timestamp, SessionKey};
47-
use chainx_api::ChainXApi;
48-
48+
type TransactionPool<A> = substrate_extrinsic_pool::Pool<chainx_pool::PoolApi<A>>;
4949
pub use self::offline_tracker::OfflineTracker;
50-
use dynamic_inclusion::DynamicInclusion;
5150
pub use self::error::{ErrorKind, Error};
5251
pub use service::Service;
5352

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

56+
5857
// block size limit.
5958
const MAX_TRANSACTIONS_SIZE: usize = 4 * 1024 * 1024;
6059

@@ -83,7 +82,7 @@ where
8382
/// The client instance.
8483
pub client: Arc<P>,
8584
/// transaction pool,
86-
pub transaction_pool: Arc<TransactionPool>,
85+
pub transaction_pool: Arc<TransactionPool<P>>,
8786
/// The backing network handle.
8887
pub network: N,
8988
/// handle to remote task executor
@@ -146,15 +145,17 @@ where
146145
}
147146

148147
/// The ChainX proposer logic.
149-
pub struct Proposer<C: ChainXApi + Send + Sync> {
148+
pub struct Proposer<C: ChainXApi + Send + Sync> where
149+
C: ChainXApi + Send + Sync,
150+
{
150151
client: Arc<C>,
151152
dynamic_inclusion: DynamicInclusion,
152153
local_key: Arc<ed25519::Pair>,
153154
parent_hash: Hash,
154155
parent_id: BlockId,
155156
parent_number: BlockNumber,
156157
random_seed: Hash,
157-
transaction_pool: Arc<TransactionPool>,
158+
transaction_pool: Arc<TransactionPool<C>>,
158159
offline: SharedOfflineTracker,
159160
validators: Vec<AccountId>,
160161
}
@@ -384,12 +385,13 @@ impl ProposalTiming {
384385
}
385386

386387
/// Future which resolves upon the creation of a proposal.
387-
pub struct CreateProposal<C: ChainXApi + Send + Sync> {
388+
pub struct CreateProposal<C: ChainXApi + Send + Sync> where
389+
{
388390
parent_hash: Hash,
389391
parent_number: BlockNumber,
390392
parent_id: BlockId,
391393
client: Arc<C>,
392-
transaction_pool: Arc<TransactionPool>,
394+
transaction_pool: Arc<TransactionPool<C>>,
393395
timing: ProposalTiming,
394396
validators: Vec<AccountId>,
395397
offline: SharedOfflineTracker,

consensus/src/service.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl Service {
110110
client: Arc<C>,
111111
api: Arc<A>,
112112
network: N,
113-
transaction_pool: Arc<TransactionPool>,
113+
transaction_pool: Arc<TransactionPool<A>>,
114114
thread_pool: ThreadPoolHandle,
115115
key: ed25519::Pair,
116116
) -> Service

pool/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@ substrate-client-db = { git = "https://github.com/chainx-org/substrate" }
1919
chainx-primitives = { path = "../primitives" }
2020
chainx-runtime = { path = "../runtime" }
2121
chainx-executor = {path = "../executor"}
22+
chainx-api = { path = "../api" }
2223
triehash = { version = "0.2.3" }
2324
error-chain = "0.12"
2425
hex-literal = "0.1"
26+
log = "0.3"
27+
2528
[dev-dependencies]
2629
substrate-keyring = { git = "https://github.com/chainx-org/substrate" }
2730
substrate-runtime-primitives = { git = "https://github.com/chainx-org/substrate" }

pool/src/error.rs

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
use chainx_runtime::{Address, UncheckedExtrinsic};
2+
use chainx_primitives::Hash;
3+
use extrinsic_pool;
4+
use chainx_api;
5+
6+
7+
error_chain! {
8+
links {
9+
Pool(extrinsic_pool::Error, extrinsic_pool::ErrorKind);
10+
Api(chainx_api::Error, chainx_api::ErrorKind);
11+
}
12+
errors {
13+
/// Unexpected extrinsic format submitted
14+
InvalidExtrinsicFormat {
15+
description("Invalid extrinsic format."),
16+
display("Invalid extrinsic format."),
17+
}
18+
/// Attempted to queue an inherent transaction.
19+
IsInherent(xt: UncheckedExtrinsic) {
20+
description("Inherent transactions cannot be queued."),
21+
display("Inherent transactions cannot be queued."),
22+
}
23+
/// Attempted to queue a transaction with bad signature.
24+
BadSignature(e: &'static str) {
25+
description("Transaction had bad signature."),
26+
display("Transaction had bad signature: {}", e),
27+
}
28+
/// Attempted to queue a transaction that is already in the pool.
29+
AlreadyImported(hash: Hash) {
30+
description("Transaction is already in the pool."),
31+
display("Transaction {:?} is already in the pool.", hash),
32+
}
33+
/// Import error.
34+
Import(err: Box<::std::error::Error + Send>) {
35+
description("Error importing transaction"),
36+
display("Error importing transaction: {}", err.description()),
37+
}
38+
/// Runtime failure.
39+
UnrecognisedAddress(who: Address) {
40+
description("Unrecognised address in extrinsic"),
41+
display("Unrecognised address in extrinsic: {}", who),
42+
}
43+
/// Extrinsic too large
44+
TooLarge(got: usize, max: usize) {
45+
description("Extrinsic too large"),
46+
display("Extrinsic is too large ({} > {})", got, max),
47+
}
48+
}
49+
}
50+
51+
impl extrinsic_pool::IntoPoolError for Error {
52+
fn into_pool_error(self) -> ::std::result::Result<extrinsic_pool::Error, Self> {
53+
match self {
54+
Error(ErrorKind::Pool(e), c) => Ok(extrinsic_pool::Error(e, c)),
55+
e => Err(e),
56+
}
57+
}
58+
}

pool/src/lib.rs

+14-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
11
// Copyright 2018 Chainpool.
22

3-
extern crate substrate_codec as codec;
43
extern crate substrate_runtime_primitives as runtime_primitives;
54
extern crate substrate_primitives as substrate_primitives;
5+
extern crate substrate_extrinsic_pool as extrinsic_pool;
6+
extern crate substrate_codec as codec;
67
extern crate substrate_client_db;
7-
extern crate chainx_primitives;
8-
extern crate chainx_runtime;
9-
extern crate substrate_network;
10-
extern crate chainx_executor;
118
extern crate substrate_executor;
12-
extern crate substrate_extrinsic_pool as extrinsic_pool;
9+
extern crate substrate_network;
1310
extern crate substrate_client;
11+
extern crate chainx_primitives;
12+
extern crate chainx_executor;
13+
extern crate chainx_runtime;
14+
extern crate chainx_api;
1415
extern crate ed25519;
1516

17+
#[macro_use]
18+
extern crate error_chain;
19+
#[macro_use]
20+
extern crate log;
21+
1622
mod pool;
23+
mod error;
1724

1825
pub use pool::TransactionPool;
1926
pub use pool::PoolApi;
27+

0 commit comments

Comments
 (0)