mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 18:41:03 +00:00
Hook RPC extrinsic import into propagation (#158)
* call `on_new_transactions` when we import * fix trace * pass correct bytes to network * clean up * cull before repropagating; repropagate on timer * add a little tracing
This commit is contained in:
committed by
Gav Wood
parent
1283545b4b
commit
7c51525ad3
@@ -22,6 +22,7 @@ tokio-core = "0.1.12"
|
||||
futures = "0.1.17"
|
||||
ctrlc = { git = "https://github.com/paritytech/rust-ctrlc.git" }
|
||||
fdlimit = "0.1"
|
||||
parking_lot = "0.4"
|
||||
substrate-client = { path = "../../substrate/client" }
|
||||
substrate-network = { path = "../../substrate/network" }
|
||||
substrate-codec = { path = "../../substrate/codec" }
|
||||
@@ -29,8 +30,10 @@ substrate-runtime-support = { path = "../../substrate/runtime-support" }
|
||||
substrate-state-machine = { path = "../../substrate/state-machine" }
|
||||
substrate-executor = { path = "../../substrate/executor" }
|
||||
substrate-primitives = { path = "../../substrate/primitives" }
|
||||
substrate-rpc = { path = "../../substrate/rpc" }
|
||||
substrate-rpc-servers = { path = "../../substrate/rpc-servers" }
|
||||
polkadot-primitives = { path = "../primitives" }
|
||||
polkadot-executor = { path = "../executor" }
|
||||
polkadot-runtime = { path = "../runtime" }
|
||||
polkadot-service = { path = "../service" }
|
||||
polkadot-transaction-pool = { path = "../transaction-pool" }
|
||||
|
||||
+38
-1
@@ -30,17 +30,21 @@ extern crate ctrlc;
|
||||
extern crate fdlimit;
|
||||
extern crate ed25519;
|
||||
extern crate triehash;
|
||||
extern crate parking_lot;
|
||||
|
||||
extern crate substrate_codec as codec;
|
||||
extern crate substrate_state_machine as state_machine;
|
||||
extern crate substrate_client as client;
|
||||
extern crate substrate_primitives as primitives;
|
||||
extern crate substrate_network as network;
|
||||
extern crate substrate_rpc;
|
||||
extern crate substrate_rpc_servers as rpc;
|
||||
extern crate substrate_runtime_support as runtime_support;
|
||||
extern crate polkadot_primitives;
|
||||
extern crate polkadot_executor;
|
||||
extern crate polkadot_runtime;
|
||||
extern crate polkadot_service as service;
|
||||
extern crate polkadot_transaction_pool as txpool;
|
||||
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
@@ -57,10 +61,39 @@ mod informant;
|
||||
use std::io;
|
||||
use std::net::SocketAddr;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::Arc;
|
||||
|
||||
use futures::sync::mpsc;
|
||||
use futures::{Sink, Future, Stream};
|
||||
use tokio_core::reactor;
|
||||
use parking_lot::Mutex;
|
||||
use service::ChainSpec;
|
||||
use primitives::block::Extrinsic;
|
||||
|
||||
struct RpcTransactionPool {
|
||||
inner: Arc<Mutex<txpool::TransactionPool>>,
|
||||
network: Arc<network::Service>,
|
||||
}
|
||||
|
||||
impl substrate_rpc::author::AuthorApi for RpcTransactionPool {
|
||||
fn submit_extrinsic(&self, xt: Extrinsic) -> substrate_rpc::author::error::Result<()> {
|
||||
use primitives::hexdisplay::HexDisplay;
|
||||
use polkadot_runtime::UncheckedExtrinsic;
|
||||
use codec::Slicable;
|
||||
|
||||
info!("Extrinsic submitted: {}", HexDisplay::from(&xt.0));
|
||||
let decoded = xt.using_encoded(|ref mut s| UncheckedExtrinsic::decode(s))
|
||||
.ok_or(substrate_rpc::author::error::ErrorKind::InvalidFormat)?;
|
||||
|
||||
info!("Correctly formatted: {:?}", decoded);
|
||||
|
||||
self.inner.lock().import(decoded)
|
||||
.map_err(|_| substrate_rpc::author::error::ErrorKind::PoolError)?;
|
||||
|
||||
self.network.trigger_repropagate();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Parse command line arguments and start the node.
|
||||
///
|
||||
@@ -172,7 +205,11 @@ pub fn run<I, T>(args: I) -> error::Result<()> where
|
||||
|
||||
let handler = || {
|
||||
let chain = rpc::apis::chain::Chain::new(service.client(), core.remote());
|
||||
rpc::rpc_handler(service.client(), chain, service.transaction_pool())
|
||||
let pool = RpcTransactionPool {
|
||||
inner: service.transaction_pool(),
|
||||
network: service.network(),
|
||||
};
|
||||
rpc::rpc_handler(service.client(), chain, pool)
|
||||
};
|
||||
(
|
||||
start_server(http_address, |address| rpc::start_http(address, handler())),
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
extern crate ed25519;
|
||||
extern crate ethereum_types;
|
||||
extern crate substrate_codec as codec;
|
||||
extern crate substrate_rpc;
|
||||
extern crate substrate_primitives as substrate_primitives;
|
||||
extern crate substrate_runtime_primitives as substrate_runtime_primitives;
|
||||
extern crate polkadot_runtime as runtime;
|
||||
@@ -35,10 +34,8 @@ use std::collections::HashMap;
|
||||
use std::cmp::Ordering;
|
||||
use std::sync::Arc;
|
||||
|
||||
use codec::Slicable;
|
||||
use polkadot_api::PolkadotApi;
|
||||
use primitives::{AccountId, Timestamp};
|
||||
use substrate_primitives::block::Extrinsic;
|
||||
use runtime::{Block, UncheckedExtrinsic, TimestampCall, Call};
|
||||
use substrate_runtime_primitives::traits::Checkable;
|
||||
use transaction_pool::{Pool, Readiness};
|
||||
@@ -380,19 +377,6 @@ impl TransactionPool {
|
||||
}
|
||||
}
|
||||
|
||||
impl substrate_rpc::author::AsyncAuthorApi for TransactionPool {
|
||||
fn submit_extrinsic(&mut self, xt: Extrinsic) -> substrate_rpc::author::error::Result<()> {
|
||||
use substrate_primitives::hexdisplay::HexDisplay;
|
||||
info!("Extrinsic submitted: {}", HexDisplay::from(&xt.0));
|
||||
let xt = xt.using_encoded(|ref mut s| UncheckedExtrinsic::decode(s))
|
||||
.ok_or(substrate_rpc::author::error::ErrorKind::InvalidFormat)?;
|
||||
info!("Correctly formatted: {:?}", xt);
|
||||
self.import(xt)
|
||||
.map(|_| ())
|
||||
.map_err(|_| substrate_rpc::author::error::ErrorKind::PoolError.into())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user